[pypy-svn] r55388 - in pypy/dist/pypy/translator: c tool

arigo at codespeak.net arigo at codespeak.net
Thu May 29 14:01:15 CEST 2008


Author: arigo
Date: Thu May 29 14:01:10 2008
New Revision: 55388

Modified:
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/tool/cbuild.py
Log:
- handling config.translation.profopt is a bit messy
- try a workaround for a gcc profile bug


Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Thu May 29 14:01:10 2008
@@ -288,22 +288,32 @@
     standalone = True
     executable_name = None
 
-    def getentrypointptr(self):
-        # XXX check that the entrypoint has the correct
-        # signature:  list-of-strings -> int
-        bk = self.translator.annotator.bookkeeper
-        return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
-
-    def getccompiler(self):            
-        cc = self.config.translation.cc
+    def getprofbased(self):
         profbased = None
         if self.config.translation.instrumentctl is not None:
             profbased = self.config.translation.instrumentctl
         else:
+            # xxx handling config.translation.profopt is a bit messy, because
+            # it could be an empty string (not to be confused with None) and
+            # because noprofopt can be used as an override.
             profopt = self.config.translation.profopt
             if profopt is not None and not self.config.translation.noprofopt:
                 profbased = (ProfOpt, profopt)
+        return profbased
+
+    def has_profopt(self):
+        profbased = self.getprofbased()
+        return (profbased and isinstance(profbased, tuple)
+                and profbased[0] is ProfOpt)
 
+    def getentrypointptr(self):
+        # XXX check that the entrypoint has the correct
+        # signature:  list-of-strings -> int
+        bk = self.translator.annotator.bookkeeper
+        return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
+
+    def getccompiler(self):            
+        cc = self.config.translation.cc
         # Copy extrafiles to target directory, if needed
         extrafiles = []
         for fn in self.extrafiles:
@@ -316,7 +326,7 @@
 
         return CCompiler(
             [self.c_source_filename] + extrafiles,
-            self.eci, compiler_exe = cc, profbased = profbased)
+            self.eci, compiler_exe = cc, profbased = self.getprofbased())
 
     def compile(self):
         assert self.c_source_filename
@@ -389,7 +399,7 @@
             cc = self.config.translation.cc
         else:
             cc = 'gcc'
-        if self.config.translation.profopt:
+        if self.has_profopt():
             profopt = self.config.translation.profopt
             default_target = 'profopt'
         else:
@@ -855,11 +865,14 @@
 $(TARGET): $(OBJECTS)
 \t$(CC) $(LDFLAGS) $(TFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS)
 
+# -frandom-seed is an attempted workaround for a gcc bug with -fprofile-*
+# (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20815)
+
 %.o: %.c
-\t$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEDIRS)
+\t$(CC) $(CFLAGS) -frandom-seed=$< -o $@ -c $< $(INCLUDEDIRS)
 
 %.s: %.c
-\t$(CC) $(CFLAGS) -o $@ -S $< $(INCLUDEDIRS)
+\t$(CC) $(CFLAGS) -frandom-seed=$< -o $@ -S $< $(INCLUDEDIRS)
 
 %.gcmap: %.s
 \t$(PYPYDIR)/translator/c/gcc/trackgcroot.py -t $< > $@ || (rm -f $@ && exit 1)
@@ -868,7 +881,7 @@
 \t$(PYPYDIR)/translator/c/gcc/trackgcroot.py $(GCMAPFILES) > $@ || (rm -f $@ && exit 1)
 
 clean:
-\trm -f $(OBJECTS) $(TARGET) $(GCMAPFILES) *.gc??
+\trm -f $(OBJECTS) $(TARGET) $(GCMAPFILES) ../*/*.gc??
 
 clean_noprof:
 \trm -f $(OBJECTS) $(TARGET) $(GCMAPFILES)

Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Thu May 29 14:01:10 2008
@@ -467,6 +467,7 @@
 
     def build(self, option):
         compiler = self.compiler
+        compiler.fix_gcc_random_seed = True
         compiler.compile_extra.append(option)
         compiler.link_extra.append(option)
         try:
@@ -479,6 +480,7 @@
     pass
 
 class CCompiler:
+    fix_gcc_random_seed = False
 
     def __init__(self, cfilenames, eci, outputfilename=None,
                  compiler_exe=None, profbased=None):
@@ -575,11 +577,16 @@
         objects = []
         for cfile in self.cfilenames: 
             cfile = py.path.local(cfile)
+            compile_extra = self.compile_extra[:]
+            # -frandom-seed is an attempted workaround for a bug with
+            # -fprofile-generate and -fprofile-use
+            if self.fix_gcc_random_seed:
+                compile_extra.append('-frandom-seed=%s' % (cfile.basename,))
             old = cfile.dirpath().chdir() 
             try: 
                 res = compiler.compile([cfile.basename], 
                                        include_dirs=self.eci.include_dirs,
-                                       extra_preargs=self.compile_extra)
+                                       extra_preargs=compile_extra)
                 assert len(res) == 1
                 cobjfile = py.path.local(res[0]) 
                 assert cobjfile.check()



More information about the Pypy-commit mailing list