[pypy-svn] r52123 - in pypy/dist/pypy/translator/c: . gcc

arigo at codespeak.net arigo at codespeak.net
Mon Mar 3 21:20:25 CET 2008


Author: arigo
Date: Mon Mar  3 21:20:25 2008
New Revision: 52123

Modified:
   pypy/dist/pypy/translator/c/gcc/trackgcroot.py
   pypy/dist/pypy/translator/c/genc.py
Log:
For fun and profits, make trackgcroot parallelizable
in "make -j" builds.


Modified: pypy/dist/pypy/translator/c/gcc/trackgcroot.py
==============================================================================
--- pypy/dist/pypy/translator/c/gcc/trackgcroot.py	(original)
+++ pypy/dist/pypy/translator/c/gcc/trackgcroot.py	Mon Mar  3 21:20:25 2008
@@ -27,11 +27,28 @@
 class GcRootTracker(object):
 
     def __init__(self, verbose=0, shuffle=False):
-        self.gcmaptable = []
         self.verbose = verbose
+        self.shuffle = shuffle     # to debug the sorting logic in asmgcroot.py
+        self.clear()
+
+    def clear(self):
+        self.gcmaptable = []
         self.seen_main = False
         self.files_seen = 0
-        self.shuffle = shuffle     # to debug the sorting logic in asmgcroot.py
+
+    def dump_raw_table(self, output):
+        print >> output, "seen_main = %d" % (self.seen_main,)
+        for entry in self.gcmaptable:
+            print >> output, entry
+
+    def reload_raw_table(self, input):
+        firstline = input.readline()
+        assert firstline.startswith("seen_main = ")
+        self.seen_main |= bool(int(firstline[len("seen_main = "):].strip()))
+        for line in input:
+            entry = eval(line)
+            assert type(entry) is tuple
+            self.gcmaptable.append(entry)
 
     def dump(self, output):
         assert self.seen_main
@@ -975,6 +992,7 @@
 if __name__ == '__main__':
     verbose = 1
     shuffle = False
+    output_raw_table = False
     while len(sys.argv) > 1:
         if sys.argv[1] == '-v':
             del sys.argv[1]
@@ -982,16 +1000,29 @@
         elif sys.argv[1] == '-r':
             del sys.argv[1]
             shuffle = True
+        elif sys.argv[1] == '-t':
+            del sys.argv[1]
+            output_raw_table = True
         else:
             break
     tracker = GcRootTracker(verbose=verbose, shuffle=shuffle)
     for fn in sys.argv[1:]:
         tmpfn = fn + '.TMP'
         f = open(fn, 'r')
-        g = open(tmpfn, 'w')
-        tracker.process(f, g, filename=fn)
-        f.close()
-        g.close()
-        os.unlink(fn)
-        os.rename(tmpfn, fn)
-    tracker.dump(sys.stdout)
+        firstline = f.readline()
+        f.seek(0)
+        if firstline.startswith('seen_main = '):
+            tracker.reload_raw_table(f)
+            f.close()
+        else:
+            g = open(tmpfn, 'w')
+            tracker.process(f, g, filename=fn)
+            f.close()
+            g.close()
+            os.unlink(fn)
+            os.rename(tmpfn, fn)
+            if output_raw_table:
+                tracker.dump_raw_table(sys.stdout)
+                tracker.clear()
+    if not output_raw_table:
+        tracker.dump(sys.stdout)

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Mon Mar  3 21:20:25 2008
@@ -354,6 +354,7 @@
         assert self.config.translation.gcrootfinder != "llvmgc"
         cfiles = []
         ofiles = []
+        gcmapfiles = []
         for fn in compiler.cfilenames:
             fn = py.path.local(fn)
             if fn.dirpath() == targetdir:
@@ -364,6 +365,7 @@
             cfiles.append(name)
             if self.config.translation.gcrootfinder == "asmgcc":
                 ofiles.append(name[:-2] + '.s')
+                gcmapfiles.append(name[:-2] + '.gcmap')
             else:
                 ofiles.append(name[:-2] + '.o')
 
@@ -387,8 +389,10 @@
         print >> f
         if self.config.translation.gcrootfinder == "asmgcc":
             write_list(ofiles, 'ASMFILES =')
+            write_list(gcmapfiles, 'GCMAPFILES =')
             print >> f, 'OBJECTS = $(ASMFILES) gcmaptable.s'
         else:
+            print >> f, 'GCMAPFILES ='
             write_list(ofiles, 'OBJECTS =')
         print >> f
         def makerel(path):
@@ -835,11 +839,14 @@
 %.s: %.c
 \t$(CC) $(CFLAGS) -o $@ -S $< $(INCLUDEDIRS)
 
-gcmaptable.s: $(ASMFILES)
-\t$(PYPYDIR)/translator/c/gcc/trackgcroot.py $(ASMFILES) > $@ || (rm -f $@ && exit 1)
+%.gcmap: %.s
+\t$(PYPYDIR)/translator/c/gcc/trackgcroot.py -t $< > $@ || (rm -f $@ && exit 1)
+
+gcmaptable.s: $(GCMAPFILES)
+\t$(PYPYDIR)/translator/c/gcc/trackgcroot.py $(GCMAPFILES) > $@ || (rm -f $@ && exit 1)
 
 clean:
-\trm -f $(OBJECTS) $(TARGET)
+\trm -f $(OBJECTS) $(TARGET) $(GCMAPFILES)
 
 debug:
 \t$(MAKE) CFLAGS="-g -DRPY_ASSERT"
@@ -868,6 +875,6 @@
 profopt:
 \t$(MAKE) CFLAGS="-fprofile-generate $(CFLAGS)" LDFLAGS="-fprofile-generate $(LDFLAGS)"
 \tcd $(PYPYDIR)/translator/goal && $(abspath $(TARGET)) $(PROFOPT)
-\trm -f $(OBJECTS) $(TARGET)
+\t$(MAKE) clean
 \t$(MAKE) CFLAGS="-fprofile-use $(CFLAGS)" LDFLAGS="-fprofile-use $(LDFLAGS)"
 '''



More information about the Pypy-commit mailing list