diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/autodebugger.py | 97 | ||||
-rwxr-xr-x | tools/emmaken.py | 14 | ||||
-rwxr-xr-x | tools/emmakenxx.py | 3 | ||||
-rwxr-xr-x | tools/exec_llvm.py | 2 | ||||
-rw-r--r-- | tools/shared.py | 53 |
5 files changed, 141 insertions, 28 deletions
diff --git a/tools/autodebugger.py b/tools/autodebugger.py index 9b51ebc9..f4c580a2 100644 --- a/tools/autodebugger.py +++ b/tools/autodebugger.py @@ -7,14 +7,18 @@ compare that to the output when compiled using emscripten. import os, sys, re +ALLOW_POINTERS = False +MEMCPY = 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 +61,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 +71,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 +81,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 +113,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 } ''' @@ -135,15 +140,83 @@ LLVM_STYLE_OLD = '<label>' not in data and 'entry:' in data if not LLVM_STYLE_OLD: POSTAMBLE = POSTAMBLE_NEW +if MEMCPY: + POSTAMBLE = ''' +@.emscripten.memcpy.str = private constant [7 x i8] c"MC:%d\\0A\\00", align 1 ; [#uses=1] + +''' + POSTAMBLE + ''' +; [#uses=1] +define void @emscripten_memcpy(i8* %destination, i8* %source, i32 %num, i32 %whati, i1 %sthis) nounwind { +entry: + %destination.addr = alloca i8*, align 4 ; [#uses=3] + %source.addr = alloca i8*, align 4 ; [#uses=2] + %num.addr = alloca i32, align 4 ; [#uses=3] + %i = alloca i32, align 4 ; [#uses=5] + %src = alloca i8*, align 4 ; [#uses=5] + %dst = alloca i8*, align 4 ; [#uses=4] + store i8* %destination, i8** %destination.addr, align 4 + store i8* %source, i8** %source.addr, align 4 + store i32 %num, i32* %num.addr, align 4 + %tmp = load i8** %source.addr, align 4 ; [#uses=1] + store i8* %tmp, i8** %src, align 4 + %tmp2 = load i8** %destination.addr, align 4 ; [#uses=1] + store i8* %tmp2, i8** %dst, align 4 + store i32 0, i32* %i, align 4 + %tmp31 = load i32* %i, align 4 ; [#uses=1] + %tmp42 = load i32* %num.addr, align 4 ; [#uses=1] + %cmp3 = icmp ult i32 %tmp31, %tmp42 ; [#uses=1] + br i1 %cmp3, label %for.body, label %for.end + +for.body: ; preds = %for.body, %entry + %tmp5 = load i8** %src, align 4 ; [#uses=1] + %tmp6 = load i8* %tmp5 ; [#uses=1] + %conv = zext i8 %tmp6 to i32 ; [#uses=1] + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([7 x i8]* @.emscripten.memcpy.str, i32 0, i32 0), i32 %conv); [#uses=0] + %tmp7 = load i8** %src, align 4 ; [#uses=1] + %tmp8 = load i8* %tmp7 ; [#uses=1] + %tmp9 = load i8** %dst, align 4 ; [#uses=1] + store i8 %tmp8, i8* %tmp9 + %tmp10 = load i32* %i, align 4 ; [#uses=1] + %inc = add i32 %tmp10, 1 ; [#uses=1] + store i32 %inc, i32* %i, align 4 + %tmp11 = load i8** %src, align 4 ; [#uses=1] + %incdec.ptr = getelementptr inbounds i8* %tmp11, i32 1 ; [#uses=1] + store i8* %incdec.ptr, i8** %src, align 4 + %tmp12 = load i8** %dst, align 4 ; [#uses=1] + %incdec.ptr13 = getelementptr inbounds i8* %tmp12, i32 1 ; [#uses=1] + store i8* %incdec.ptr13, i8** %dst, align 4 + %tmp3 = load i32* %i, align 4 ; [#uses=1] + %tmp4 = load i32* %num.addr, align 4 ; [#uses=1] + %cmp = icmp ult i32 %tmp3, %tmp4 ; [#uses=1] + br i1 %cmp, label %for.body, label %for.end + +for.end: ; preds = %for.body, %entry + %tmp14 = load i8** %destination.addr, align 4 ; [#uses=1] + ret void +} +''' + 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')) + if MEMCPY: + if not lines[i].startswith('declare void'): + lines[i] = lines[i].replace('@llvm.memcpy.p0i8.p0i8.i32', '@emscripten_memcpy') + 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/emmaken.py b/tools/emmaken.py index c04aaf30..29268ae2 100755 --- a/tools/emmaken.py +++ b/tools/emmaken.py @@ -17,7 +17,7 @@ Example uses: * With configure, do something like - EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emmaken.py AR=PATH/emmaken.py CXX=PATH/emmaken.py CC=PATH/emmaken.py ./configure [options] + EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emmaken.py AR=PATH/emmaken.py CXX=PATH/emmakenxx.py CC=PATH/emmaken.py ./configure [options] where PATH is the path to this file. @@ -68,7 +68,7 @@ exec(open(path_from_root('tools', 'shared.py'), 'r').read()) CONFIGURE_CONFIG = os.environ.get('EMMAKEN_JUST_CONFIGURE') CMAKE_CONFIG = 'CMakeFiles/cmTryCompileExec.dir' in ' '.join(sys.argv)# or 'CMakeCCompilerId' in ' '.join(sys.argv) if CONFIGURE_CONFIG or CMAKE_CONFIG: - compiler = 'g++' if 'CXXCompiler' in ' '.join(sys.argv) else 'gcc' + compiler = 'g++' if 'CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX') else 'gcc' exit(os.execvp(compiler, [compiler] + sys.argv[1:])) try: @@ -85,12 +85,11 @@ try: CC = to_cc(CXX) # If we got here from a redirection through emmakenxx.py, then force a C++ compiler here - if sys.argv[-1] == '-EMMAKEN_CXX': + if os.environ.get('EMMAKEN_CXX'): CC = CXX - sys.argv = sys.argv[:-1] CC_ARG_SKIP = ['-O1', '-O2', '-O3'] - CC_ADDITIONAL_ARGS = ['-m32', '-g', '-U__i386__', '-U__x86_64__', '-U__i386', '-U__x86_64', '-U__SSE__', '-U__SSE2__', '-UX87_DOUBLE_ROUNDING', '-UHAVE_GCC_ASM_FOR_X87'] + CC_ADDITIONAL_ARGS = COMPILER_OPTS # + ['-g']? ALLOWED_LINK_ARGS = ['-f', '-help', '-o', '-print-after', '-print-after-all', '-print-before', '-print-before-all', '-time-passes', '-v', '-verify-dom-info', '-version' ] TWO_PART_DISALLOWED_LINK_ARGS = ['-L'] # Ignore thingsl like |-L .| @@ -113,7 +112,8 @@ try: opts = [] files = [] - for arg in sys.argv[1:]: + for i in range(1, len(sys.argv)): + arg = sys.argv[i] if arg.startswith('-'): opts.append(arg) else: @@ -122,7 +122,7 @@ try: use_cxx = False if arg.endswith(('.c', '.cc', '.cpp', '.dT')): use_linker = False - if arg.endswith('.h'): + if arg.endswith('.h') and sys.argv[i-1] != '-include': header = True use_linker = False diff --git a/tools/emmakenxx.py b/tools/emmakenxx.py index f473a8bf..0fd01d62 100755 --- a/tools/emmakenxx.py +++ b/tools/emmakenxx.py @@ -12,5 +12,6 @@ def path_from_root(*pathelems): exec(open(path_from_root('tools', 'shared.py'), 'r').read()) emmaken = path_from_root('tools', 'emmaken.py') -exit(os.execvp('python', ['python', emmaken] + sys.argv[1:] + ['-EMMAKEN_CXX'])) +os.environ['EMMAKEN_CXX'] = '1' +exit(os.execvp('python', ['python', emmaken] + sys.argv[1:])) diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py index 840966e6..04801649 100755 --- a/tools/exec_llvm.py +++ b/tools/exec_llvm.py @@ -41,8 +41,6 @@ def path_from_root(*pathelems): return os.path.join(rootpath, *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 4b68555a..86569e73 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -23,6 +23,21 @@ 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') + +# Additional compiler options + +USE_EMSDK = True + +COMPILER_OPTS = COMPILER_OPTS + ['-m32', '-v', '-U__i386__', '-U__x86_64__', '-U__i386', '-U__x86_64', '-U__SSE__', '-U__SSE2__', '-UX87_DOUBLE_ROUNDING', '-UHAVE_GCC_ASM_FOR_X87'] + +if USE_EMSDK: + COMPILER_OPTS += [ '-nostdinc', + '-I' + path_from_root('system', 'include'), + '-I' + path_from_root('system', 'include', 'freebsd'), # posix stuff + '-I' + path_from_root('system', 'include', 'libc'), + '-I' + path_from_root('system', 'include', 'libcxx'), +] # Engine tweaks @@ -68,17 +83,17 @@ def line_splitter(data): return out -def limit_size(string, MAX=80*20): +def limit_size(string, MAX=800*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 +129,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 +147,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 + } + |