[pypy-svn] r30183 - in pypy/dist/pypy/translator: c goal tool
ericvrp at codespeak.net
ericvrp at codespeak.net
Tue Jul 18 22:12:46 CEST 2006
Author: ericvrp
Date: Tue Jul 18 22:12:41 2006
New Revision: 30183
Modified:
pypy/dist/pypy/translator/c/genc.py
pypy/dist/pypy/translator/goal/bench-cronjob.py
pypy/dist/pypy/translator/goal/translate.py
pypy/dist/pypy/translator/tool/cbuild.py
Log:
Add support for profile based optimization to translate.py and nightly cronjob
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Tue Jul 18 22:12:41 2006
@@ -212,11 +212,15 @@
cc = self.translator.driver_options.cc
else:
cc = None
+ if self.translator.driver_options:
+ profopt = self.translator.driver_options.profopt
+ else:
+ profopt = None
return CCompiler(
[self.c_source_filename] + self.extrafiles,
include_dirs = [autopath.this_dir, python_inc] + extra_includes,
libraries = self.libraries,
- compiler_exe = cc)
+ compiler_exe = cc, profopt = profopt)
def compile(self):
assert self.c_source_filename
@@ -255,6 +259,11 @@
else:
cc = 'gcc'
+ if self.translator.driver_options and self.translator.driver_options.profopt:
+ profopt = self.translator.driver_options.profopt
+ else:
+ profopt = ''
+
f = targetdir.join('Makefile').open('w')
print >> f, '# automatically generated Makefile'
print >> f
@@ -271,10 +280,11 @@
args = ['-I'+path for path in compiler.include_dirs]
write_list(args, 'INCLUDEDIRS =')
print >> f
- print >> f, 'CFLAGS =', ' '.join(compiler.compile_extra)
+ print >> f, 'CFLAGS =', ' '.join(compiler.compile_extra)
print >> f, 'LDFLAGS =', ' '.join(compiler.link_extra)
- print >> f, 'TFLAGS = ' + ('', '-pthread')[self.thread_enabled]
- print >> f, 'CC = ' + cc
+ print >> f, 'TFLAGS = ' + ('', '-pthread')[self.thread_enabled]
+ print >> f, 'PROFOPT = ' + profopt
+ print >> f, 'CC = ' + cc
print >> f
print >> f, MAKEFILE.strip()
f.close()
@@ -813,7 +823,7 @@
MAKEFILE = '''
$(TARGET): $(OBJECTS)
-\t$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS)
+\t$(CC) $(LDFLAGS) $(TFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS)
%.o: %.c
\t$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEDIRS)
@@ -822,8 +832,14 @@
\trm -f $(OBJECTS) $(TARGET)
debug:
-\tmake CFLAGS="-g $(TFLAGS)"
+\tmake CFLAGS="-g $(CFLAGS)"
profile:
\tmake CFLAGS="-pg $(CFLAGS)" LDFLAGS="-pg $(LDFLAGS)"
+
+profopt:
+\tmake CFLAGS="-fprofile-generate $(CFLAGS)" LDFLAGS="-fprofile-generate $(LDFLAGS)"
+\t./$(TARGET) $(PROFOPT)
+\trm -f $(OBJECTS) $(TARGET)
+\tmake CFLAGS="-fprofile-use $(CFLAGS)" LDFLAGS="-fprofile-use $(LDFLAGS)"
'''
Modified: pypy/dist/pypy/translator/goal/bench-cronjob.py
==============================================================================
--- pypy/dist/pypy/translator/goal/bench-cronjob.py (original)
+++ pypy/dist/pypy/translator/goal/bench-cronjob.py Tue Jul 18 22:12:41 2006
@@ -134,7 +134,7 @@
def main(backends=[]):
if backends == []: #_ prefix means target specific option
- backends = 'llvm c c--gc=framework c--_thread c--stackless c--gc=framework--cc=c++'.split()
+ backends = """llvm at c@c--gc=framework at c--_thread@c--stackless at c--gc=framework--cc=c++ at c--cc=c++ at c--profopt='-c "from richards import *;main(iterations=1)"'""".split('@')
#backends = 'llvm c c--gc=framework c--_thread c--stackless'.split()
#backends = 'llvm c c--gc=framework c--new-stackless c--_thread'.split()
#backends = 'llvm c c--stackless c--_thread c--stackless--_thread'.split()
Modified: pypy/dist/pypy/translator/goal/translate.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate.py (original)
+++ pypy/dist/pypy/translator/goal/translate.py Tue Jul 18 22:12:41 2006
@@ -59,6 +59,7 @@
'_compile': [OPT(('-c', '--compile'), "Compile generated source", GOAL),
OPT(('--no-compile',), "Don't compile", SKIP_GOAL)],
'2_cc': [OPT(('--cc',), "Set compiler", str)],
+ '3_profopt': [OPT(('--profopt',), "Set profile based optimization script", str)],
},
'5_Run options': {
@@ -113,6 +114,7 @@
'graphserve': None,
'huge': 100,
'cc': None,
+ 'profopt': None,
'fork_before': None
}
Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py (original)
+++ pypy/dist/pypy/translator/tool/cbuild.py Tue Jul 18 22:12:41 2006
@@ -262,7 +262,8 @@
class CCompiler:
def __init__(self, cfilenames, outputfilename=None, include_dirs=[],
- libraries=[], library_dirs=[], compiler_exe=None):
+ libraries=[], library_dirs=[], compiler_exe=None,
+ profopt=None):
self.cfilenames = cfilenames
ext = ''
self.compile_extra = []
@@ -271,6 +272,7 @@
self.include_dirs = list(include_dirs)
self.library_dirs = list(library_dirs)
self.compiler_exe = compiler_exe
+ self.profopt = profopt
if not sys.platform in ('win32', 'darwin'): # xxx
if 'm' not in self.libraries:
self.libraries.append('m')
@@ -301,7 +303,26 @@
try:
try:
c = stdoutcapture.Capture(mixed_out_err = True)
- self._build()
+ log.profopt(str(self.profopt))
+ if self.profopt is None:
+ self._build()
+ else: #XXX assuming gcc style flags for now
+ self.compile_extra.append('-fprofile-generate')
+ self.link_extra.append('-fprofile-generate')
+ self._build()
+ self.compile_extra.pop()
+ self.link_extra.pop()
+
+ log.profopt('Gathering profile data from: %s %s' % (
+ str(self.outputfilename), self.profopt))
+ import subprocess
+ subprocess.call([str(self.outputfilename), self.profopt])
+
+ self.compile_extra.append('-fprofile-use')
+ self.link_extra.append('-fprofile-use')
+ self._build()
+ self.compile_extra.pop()
+ self.link_extra.pop()
finally:
foutput, foutput = c.done()
data = foutput.read()
@@ -316,7 +337,7 @@
def _build(self):
from distutils.ccompiler import new_compiler
- compiler = new_compiler()
+ compiler = new_compiler(force=1)
if self.compiler_exe is not None:
for c in '''compiler compiler_so compiler_cxx
linker_exe linker_so'''.split():
More information about the Pypy-commit
mailing list