diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/autodebugger.py | 37 | ||||
-rwxr-xr-x | tools/exec_llvm.py | 2 | ||||
-rw-r--r-- | tools/shared.py | 37 |
3 files changed, 57 insertions, 19 deletions
diff --git a/tools/autodebugger.py b/tools/autodebugger.py index 9b51ebc9..0b75d055 100644 --- a/tools/autodebugger.py +++ b/tools/autodebugger.py @@ -7,14 +7,17 @@ compare that to the output when compiled using emscripten. import os, sys, re +ALLOW_POINTERS = False + POSTAMBLE = ''' @.emscripten.autodebug.str = private constant [10 x i8] c"AD:%d,%d\\0A\\00", align 1 ; [#uses=1] +@.emscripten.autodebug.str.f = private constant [11 x i8] c"AD:%d,%lf\\0A\\00", align 1 ; [#uses=1] ; [#uses=1] define void @emscripten_autodebug_i64(i32 %line, i64 %value) { entry: %0 = sitofp i64 %value to double ; [#uses=1] - %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %0) ; [#uses=0] + %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %0) ; [#uses=0] br label %return return: ; preds = %entry @@ -57,7 +60,7 @@ return: ; preds = %entry define void @emscripten_autodebug_float(i32 %line, float %value) { entry: %0 = fpext float %value to double ; [#uses=1] - %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %0) ; [#uses=0] + %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %0) ; [#uses=0] br label %return return: ; preds = %entry @@ -67,7 +70,7 @@ return: ; preds = %entry ; [#uses=1] define void @emscripten_autodebug_double(i32 %line, double %value) { entry: - %0 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %value) ; [#uses=0] + %0 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %value) ; [#uses=0] br label %return return: ; preds = %entry @@ -77,11 +80,12 @@ return: ; preds = %entry POSTAMBLE_NEW = ''' @.emscripten.autodebug.str = private constant [10 x i8] c"AD:%d,%d\\0A\\00", align 1 ; [#uses=1] +@.emscripten.autodebug.str.f = private constant [11 x i8] c"AD:%d,%lf\\0A\\00", align 1 ; [#uses=1] ; [#uses=1] define void @emscripten_autodebug_i64(i32 %line, i64 %value) { %1 = sitofp i64 %value to double - %2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %1) ; [#uses=0] + %2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %1) ; [#uses=0] ret void } @@ -108,13 +112,13 @@ define void @emscripten_autodebug_i8(i32 %line, i8 %value) { ; [#uses=1] define void @emscripten_autodebug_float(i32 %line, float %value) { %1 = fpext float %value to double ; [#uses=1] - %2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %1) ; [#uses=0] + %2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %1) ; [#uses=0] ret void } ; [#uses=1] define void @emscripten_autodebug_double(i32 %line, double %value) { - %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.emscripten.autodebug.str, i32 0, i32 0), i32 %line, double %value) ; [#uses=0] + %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.emscripten.autodebug.str.f, i32 0, i32 0), i32 %line, double %value) ; [#uses=0] ret void } ''' @@ -138,12 +142,21 @@ if not LLVM_STYLE_OLD: lines_added = 0 lines = data.split('\n') for i in range(len(lines)): - #if i == 5: - # lines[i] += '\n - - m = re.match(' store (?P<type>i64|i32|i16|i8|float|double) %(?P<var>[\w.]+), .*', lines[i]) - if m and m.group('type') in ['i8', 'i16', 'i32', 'i64', 'float', 'double']: - lines[i] += '\n call void @emscripten_autodebug_%s(i32 %d, %s %%%s)' % (m.group('type'), i+1+lines_added, m.group('type'), m.group('var')) + m = re.match(' store (?P<type>i64|i32|i16|i8|float|double|%?[\w\.\*]+) (?P<var>%?[\w.+_]+), .*', lines[i]) + if m: + index = i+1+lines_added + if m.group('type') in ['i8', 'i16', 'i32', 'i64', 'float', 'double']: + lines[i] += '\n call void @emscripten_autodebug_%s(i32 %d, %s %s)' % (m.group('type'), index, m.group('type'), m.group('var')) + lines_added += 1 + elif ALLOW_POINTERS and m.group('type').endswith('*') and m.group('type').count('*') == 1: + lines[i] += '\n %%ead.%d = ptrtoint %s %%%s to i32' % (index, m.group('type'), m.group('var')) + lines[i] += '\n call void @emscripten_autodebug_i32(i32 %d, i32 %%ead.%d)' % (index, index) + lines_added += 2 + continue + m = re.match(' %(?P<var>[\w_.]+) = load (?P<type>i64|i32|i16|i8|float|double+)\* [^(].*.*', lines[i]) + if m: + index = i+1+lines_added + lines[i] += '\n call void @emscripten_autodebug_%s(i32 %d, %s %%%s)' % (m.group('type'), index, m.group('type'), m.group('var')) lines_added += 1 f = open(ofilename, 'w') diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py index aa18aa2b..3b08111a 100755 --- a/tools/exec_llvm.py +++ b/tools/exec_llvm.py @@ -41,8 +41,6 @@ def path_from_root(*pathelems): return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems))) exec(open(path_from_root('tools', 'shared.py'), 'r').read()) -print '// EXEC_LLVM: ', sys.argv - Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0] # Execute with empty environment - just like the JS script will have diff --git a/tools/shared.py b/tools/shared.py index 83c921da..029ca2f4 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -23,6 +23,7 @@ LLVM_INTERPRETER=os.path.expanduser(os.path.join(LLVM_ROOT, 'lli')) LLVM_COMPILER=os.path.expanduser(os.path.join(LLVM_ROOT, 'llc')) BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py') +EXEC_LLVM = path_from_root('tools', 'exec_llvm.py') # Engine tweaks @@ -72,13 +73,13 @@ def limit_size(string, MAX=80*20): if len(string) < MAX: return string return string[0:MAX/2] + '\n[..]\n' + string[-MAX/2:] -def pick_llvm_opts(optimization_level, optimize_size, allow_nonportable=False, use_aa=False): +def pick_llvm_opts(optimization_level, optimize_size, allow_nonportable=False, quantum_size=4, use_aa=False): opts = [] if optimization_level > 0: if allow_nonportable: opts.append('-O%d' % optimization_level) else: - # createStandardAliasAnalysisPasses + # PassManagerBuilder::populateModulePassManager if allow_nonportable and use_aa: # ammo.js results indicate this can be nonportable opts.append('-tbaa') opts.append('-basicaa') # makes fannkuch slow but primes fast @@ -114,11 +115,12 @@ def pick_llvm_opts(optimization_level, optimize_size, allow_nonportable=False, u opts.append('-licm') opts.append('-loop-unswitch') # XXX should depend on optimize_size if allow_nonportable: opts.append('-instcombine') - opts.append('-indvars') + if quantum_size == 4: opts.append('-indvars') # XXX this infinite-loops raytrace on q1 (loop in |new node_t[count]| has 68 hardcoded ¬ fixed) if allow_nonportable: opts.append('-loop-idiom') # ? opts.append('-loop-deletion') opts.append('-loop-unroll') - if allow_nonportable: opts.append('-instcombine') + + ##### not in llvm-3.0. but have | #addExtensionsToPM(EP_LoopOptimizerEnd, MPM);| if allow_nonportable: opts.append('-instcombine') # XXX Danger: Messes up Lua output for unknown reasons # Note: this opt is of minor importance for raytrace... @@ -131,14 +133,39 @@ def pick_llvm_opts(optimization_level, optimize_size, allow_nonportable=False, u opts.append('-jump-threading') opts.append('-correlated-propagation') opts.append('-dse') + #addExtensionsToPM(EP_ScalarOptimizerLate, MPM); + opts.append('-adce') opts.append('-simplifycfg') + if allow_nonportable: opts.append('-instcombine') opts.append('-strip-dead-prototypes') - opts.append('-deadtypeelim') if optimization_level > 2: opts.append('-globaldce') if optimization_level > 1: opts.append('-constmerge') return opts + +def read_auto_optimize_data(filename): + ''' + Reads the output of AUTO_OPTIMIZE and generates proper information for CORRECT_* == 2 's *_LINES options + ''' + signs_lines = [] + overflows_lines = [] + + for line in open(filename, 'r'): + if line.rstrip() == '': continue + if '%0 failures' in line: continue + left, right = line.split(' : ') + signature = left.split('|')[1] + if 'Sign' in left: + signs_lines.append(signature) + elif 'Overflow' in left: + overflows_lines.append(signature) + + return { + 'signs_lines': signs_lines, + 'overflows_lines': overflows_lines + } + |