[pypy-svn] r16474 - in pypy/dist/pypy/translator/llvm2: . module
rxe at codespeak.net
rxe at codespeak.net
Thu Aug 25 13:34:19 CEST 2005
Author: rxe
Date: Thu Aug 25 13:34:17 2005
New Revision: 16474
Modified:
pypy/dist/pypy/translator/llvm2/build_llvm_module.py
pypy/dist/pypy/translator/llvm2/genllvm.py
pypy/dist/pypy/translator/llvm2/module/genexterns.c
pypy/dist/pypy/translator/llvm2/module/ll_math.py
pypy/dist/pypy/translator/llvm2/module/ll_time.py
pypy/dist/pypy/translator/llvm2/module/support.py
Log:
ericvrp/rxe
Fix in failing tests to sync up.
* Some refactoring and cleaning up build_llvm_module.py
Modified: pypy/dist/pypy/translator/llvm2/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/build_llvm_module.py (original)
+++ pypy/dist/pypy/translator/llvm2/build_llvm_module.py Thu Aug 25 13:34:17 2005
@@ -14,129 +14,7 @@
from pypy.translator.llvm2.log import log
EXCEPTIONS_SWITCHES = "-enable-correct-eh-support"
-#--regalloc iterativescan" #unstable (http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html)
-
-OPTIMIZATION_SWITCHES = (" ".join([
-
- # call %malloc -> malloc inst
- "-raiseallocs",
-
- # clean up disgusting code
- "-simplifycfg",
-
- # kill useless allocas
- "-mem2reg",
-
- # optimize out global vars
- "-globalopt",
-
- # remove unused fns and globs
- "-globaldce",
-
- # interprocedural constant propagation
- "-ipconstprop",
-
- # dead argument elimination
- "-deadargelim",
-
- # clean up after
- # (interprocedural constant propagation) & (dead argument elimination)
- "-instcombine ", "-simplifycfg ",
-
- # clean up after
- # (interprocedural constant propagation) & (dead argument elimination)
- "-instcombine ", "-simplifycfg ",
-
- # remove dead EH info
- "-prune-eh",
-
- # inline small functions
- "-inline",
-
- # simplify well-known library calls
- "-simplify-libcalls",
-
- # promote 'by reference' arguments to scalars
- "-argpromotion",
-
- # recover type information
- "--raise",
-
- # simplify cfg by copying code
- "-tailduplicate",
-
- # merge & remove bacic blocks
- "--simplifycfg",
-
- # break up aggregate allocas
- "-scalarrepl",
-
- # combine silly seq's
- "-instcombine",
-
- # propagate conditionals
- "-condprop",
-
- # eliminate tail calls
- '-tailcallelim',
-
- # merge & remove BBs
- "-simplifycfg",
-
- # reassociate expressions
- "-reassociate",
-
- # hoist loop invariants (LICM - Loop Invariant Code Motion)
- "-licm",
-
- # clean up after LICM/reassoc
- "-instcombine",
-
- # canonicalize indvars
- "-indvars",
-
- # unroll small loops
- "-loop-unroll",
-
- # clean up after the unroller
- "-instcombine",
-
- # GVN for load instructions
- "-load-vn",
-
- # remove common subexprs (Global Common Subexpression Elimination)
- "-gcse",
-
- # constant prop with SCCP (Sparse Conditional Constant Propagation)
- "-sccp",
-
-
- # Run instcombine after redundancy elimination to exploit opportunities
- # opened up by them
- "-instcombine",
-
- # propagate conditionals
- "-condprop",
-
- # Delete dead stores
- "-dse",
-
- # SSA based 'Aggressive DCE'
- "-adce",
-
- # merge & remove BBs
- "-simplifycfg",
-
- # eliminate dead types
- "-deadtypeelim",
-
- # merge dup global constants
- "-constmerge",
- ]))
-
-
-# XXX Tmp for debugging
-OPTIMIZATION_SWITCHES = (" ".join([
+SIMPLE_OPTIMIZATION_SWITCHES = (" ".join([
# call %malloc -> malloc inst
"-raiseallocs",
@@ -151,7 +29,6 @@
"-simplifycfg",
]))
-
# suggested by: gccas /dev/null -o /dev/null -debug-pass=Arguments
OPTIMIZATION_SWITCHES = (" ".join([
"-verify -lowersetjmp -funcresolve -raiseallocs -simplifycfg -mem2reg -globalopt -globaldce -ipconstprop -deadargelim -instcombine -simplifycfg -prune-eh -inline -simplify-libcalls -argpromotion -raise -tailduplicate -simplifycfg -scalarrepl -instcombine -break-crit-edges -condprop -tailcallelim -simplifycfg -reassociate -loopsimplify -licm -instcombine -indvars -loop-unroll -instcombine -load-vn -gcse -sccp -instcombine -break-crit-edges -condprop -dse -mergereturn -adce -simplifycfg -deadtypeelim -constmerge -verify"
@@ -193,11 +70,18 @@
gc_libs = ''
if optimize:
- cmds = ["llvm-as < %s.ll | opt %s > %s.bc" % (b, OPTIMIZATION_SWITCHES, b)]
+ optimization_switches = OPTIMIZATION_SWITCHES
else:
- cmds = ["llvm-as < %s.ll > %s.bc" % (b, b)]
+ optimization_switches = SIMPLE_OPTIMIZATION_SWITCHES
+
+ cmds = ["llvm-as %s.ll" % b]
- if sys.maxint == 2147483647: #32 bit platform
+ bcfile = dirpath.join("externs", "externs_linked.bc")
+ cmds.append("llvm-link %s.bc %s -o %s_all.bc" % (b, str(bcfile), b))
+ ball = str(dirpath.join('%s_all.bc' % b))
+ cmds.append("opt %s %s -f -o %s.bc" % (OPTIMIZATION_SWITCHES, ball, b))
+
+ if False and sys.maxint == 2147483647: #32 bit platform
cmds.append("llc %s %s.bc -f -o %s.s" % (EXCEPTIONS_SWITCHES, b, b))
cmds.append("as %s.s -o %s.o" % (b, b))
if exe_name:
@@ -219,7 +103,7 @@
try:
try:
for cmd in cmds:
- log.build(cmd)
+ #log.build(cmd)
cmdexec(cmd)
if pyxfile:
make_c_from_pyxfile(pyxfile)
@@ -249,14 +133,3 @@
return testmodule
if exe_name:
return exe_name
-
-if __name__ == "__main__":
-
- # TMP - Conveinence during debugging
- b = "entry_point"
- print "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES, b, b)
- print "llc %s %s_optimized.bc -f -o %s.s" % (EXCEPTIONS_SWITCHES, b, b)
- print "as %s.s -o %s.o" % (b, b)
- gc_libs = '-lgc -lpthread'
- exe_name = "pypy"
- print "gcc %s.o -static %s -lm -o %s" % (b, gc_libs, exe_name)
Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py Thu Aug 25 13:34:17 2005
@@ -27,7 +27,8 @@
function_count = {}
-def get_ll(ccode, functions=[]):
+def get_ll(ccode, extern_dir, functions=[]):
+
# goto codespeak and compile our c code
request = urllib.urlencode({'ccode':ccode})
llcode = urllib.urlopen('http://codespeak.net/pypy/llvm-gcc.cgi', request).read()
@@ -72,7 +73,6 @@
llcode = '\n'.join(ll_lines2)
# create file
- extern_dir = udir.join("externs").mkdir()
llfilename = extern_dir.join("externs").new(ext='.ll')
f = open(str(llfilename), 'w')
f.write(llcode)
@@ -142,7 +142,11 @@
return decls
def generate_llfile(self, extern_decls):
- # hack to get file
+
+ extern_dir = udir.join("externs")
+ if extern_dir.check(dir=1):
+ return
+ extern_dir.mkdir()
genllcode = ""
@@ -166,7 +170,7 @@
j = os.path.join
p = j(j(os.path.dirname(__file__), "module"), "genexterns.c")
- return get_ll(open(p).read(), ['ll_math_frexp', 'll_math_is_error'])
+ return get_ll(open(p).read(), extern_dir, ['ll_math_frexp', 'll_math_is_error'])
def replace_with_machine_words(self, s):
return s.replace('UINT',self.db.get_machine_uword()).replace('INT',self.db.get_machine_word())
Modified: pypy/dist/pypy/translator/llvm2/module/genexterns.c
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/genexterns.c (original)
+++ pypy/dist/pypy/translator/llvm2/module/genexterns.c Thu Aug 25 13:34:17 2005
@@ -5,11 +5,17 @@
#define LL_MATH_SET_ERANGE_IF_MATH_ERROR Py_SET_ERANGE_IF_OVERFLOW
+// c forward declarations
+double frexp(double, int*);
+
struct RPyFREXP_RESULT;
+struct RPyMODF_RESULT;
+
struct RPyFREXP_RESULT *ll_frexp_result__Float_Signed(double, int);
+struct RPyMODF_RESULT *ll_frexp_result__Float_Float(double, double);
-void prepare_and_raise_ValueError(char *);
void prepare_and_raise_OverflowError(char *);
+void prepare_and_raise_ValueError(char *);
int ll_math_is_error(double x) {
if (errno == ERANGE) {
@@ -31,6 +37,184 @@
} while(0)
+double ll_math_pow(double x, double y) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = pow(x, y);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_atan2(double x, double y) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = atan2(x, y);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_fmod(double x, double y) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = fmod(x, y);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_ldexp(double x, long y) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = ldexp(x, (int) y);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_hypot(double x, double y) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = hypot(x, y);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+struct RPyMODF_RESULT* ll_math_modf(double x) {
+ double intpart, fracpart;
+ LL_MATH_ERROR_RESET;
+ fracpart = modf(x, &intpart);
+ LL_MATH_CHECK_ERROR(fracpart, NULL);
+ return ll_modf_result(fracpart, intpart);
+}
+
+/* simple math function */
+
+double ll_math_acos(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = acos(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_asin(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = asin(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_atan(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = atan(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_ceil(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = ceil(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_cos(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = cos(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_cosh(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = cosh(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_exp(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = exp(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_fabs(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = fabs(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_floor(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = floor(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_log(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = log(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_log10(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = log10(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_sin(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = sin(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_sinh(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = sinh(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_sqrt(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = sqrt(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_tan(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = tan(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
+double ll_math_tanh(double x) {
+ double r;
+ LL_MATH_ERROR_RESET;
+ r = tanh(x);
+ LL_MATH_CHECK_ERROR(r, -1.0);
+ return r;
+}
+
struct RPyFREXP_RESULT* ll_math_frexp(double x) {
int expo;
double m;
Modified: pypy/dist/pypy/translator/llvm2/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_math.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_math.py Thu Aug 25 13:34:17 2005
@@ -47,13 +47,6 @@
for function in functions:
extfunctions["%ll_math_" + function] = ((), simple_function_template % locals())
-#extfunctions["%ll_math_frexp"] = (("%__debug",), """
-#internal fastcc %RPyFREXP_RESULT* %ll_math_frexp(double %x) {
-# call fastcc void %__debug([12 x sbyte]* %__ll_math_frexp) ; XXX: TODO: ll_math_frexp
-# ret %RPyFREXP_RESULT* null
-#}
-#""")
-
extfunctions["%ll_math_hypot"] = (("%__debug",), """
internal fastcc double %ll_math_hypot(double %x, double %y) {
call fastcc void %__debug([12 x sbyte]* %__ll_math_hypot) ; XXX: TODO: ll_math_hypot
@@ -86,117 +79,6 @@
extfunctions["%ll_math_frexp"] = (("%prepare_and_raise_OverflowError",
"%prepare_and_raise_ValueError"), """
-declare int* %__errno_location()
-
-internal fastcc int %ll_math_is_error(double %x) {
-entry:
- %x_addr = alloca double ; ty=double*
- %result = alloca int ; ty=int*
- store double %x, double* %x_addr
- %tmp.0 = call int* ()* %__errno_location() ; ty=int*
- %tmp.1 = load int* %tmp.0 ; ty=int
- %tmp.2 = seteq int %tmp.1, 34 ; ty=bool
- %tmp.3 = cast bool %tmp.2 to int ; ty=int
- br bool %tmp.2, label %then.0, label %else
-then.0:
- %tmp.4 = load double* %x_addr ; ty=double
- %tmp.5 = seteq double %tmp.4, 0x0000000000000000 ; ty=bool
- %tmp.6 = cast bool %tmp.5 to int ; ty=int
- br bool %tmp.5, label %then.1, label %endif.1
-then.1:
- store int 0, int* %result
- br label %return
-after_ret.0:
- br label %endif.1
-endif.1:
- call fastcc void (sbyte*)* %prepare_and_raise_OverflowError(sbyte* getelementptr ([17 x sbyte]* %.str_1, int 0, int 0))
- br label %endif.0
-else:
- call fastcc void (sbyte*)* %prepare_and_raise_ValueError(sbyte* getelementptr ([18 x sbyte]* %.str_2, int 0, int 0))
- br label %endif.0
-endif.0:
- store int 1, int* %result
- br label %return
-after_ret.1:
- br label %return
-return:
- %tmp.9 = load int* %result ; ty=int
- ret int %tmp.9
-}
-
-internal fastcc %RPyFREXP_RESULT* %ll_math_frexp(double %x) {
-entry:
- %x_addr = alloca double ; ty=double*
- %result = alloca %RPyFREXP_RESULT* ; ty=%RPyFREXP_RESULT**
- %expo = alloca int ; ty=int*
- %m = alloca double ; ty=double*
- store double %x, double* %x_addr
- %tmp.0 = call int* ()* %__errno_location() ; ty=int*
- store int 0, int* %tmp.0
- %tmp.2 = load double* %x_addr ; ty=double
- %tmp.1 = call double (double, int*)* %frexp(double %tmp.2, int* %expo) ; ty=double
- store double %tmp.1, double* %m
- %tmp.3 = call int* ()* %__errno_location() ; ty=int*
- %tmp.4 = load int* %tmp.3 ; ty=int
- %tmp.5 = seteq int %tmp.4, 0 ; ty=bool
- %tmp.6 = cast bool %tmp.5 to int ; ty=int
- br bool %tmp.5, label %shortcirc_next.0, label %shortcirc_done.0
-shortcirc_next.0:
- %tmp.7 = load double* %m ; ty=double
- %tmp.8 = setgt double %tmp.7, 0x7FEFFFFFFFFFFFFF ; ty=bool
- %tmp.9 = cast bool %tmp.8 to int ; ty=int
- br bool %tmp.8, label %shortcirc_done.1, label %shortcirc_next.1
-shortcirc_next.1:
- %tmp.10 = load double* %m ; ty=double
- %tmp.11 = setlt double %tmp.10, 0xFFEFFFFFFFFFFFFF ; ty=bool
- %tmp.12 = cast bool %tmp.11 to int ; ty=int
- br label %shortcirc_done.1
-shortcirc_done.1:
- %shortcirc_val.0 = phi bool [ true, %shortcirc_next.0 ], [ %tmp.11, %shortcirc_next.1 ] ; ty=bool
- %tmp.13 = cast bool %shortcirc_val.0 to int ; ty=int
- br label %shortcirc_done.0
-shortcirc_done.0:
- %shortcirc_val.1 = phi bool [ false, %entry ], [ %shortcirc_val.0, %shortcirc_done.1 ] ; ty=bool
- %tmp.14 = cast bool %shortcirc_val.1 to int ; ty=int
- br bool %shortcirc_val.1, label %then.0, label %endif.0
-then.0:
- %tmp.15 = call int* ()* %__errno_location() ; ty=int*
- store int 34, int* %tmp.15
- br label %endif.0
-endif.0:
- %tmp.16 = call int* ()* %__errno_location() ; ty=int*
- %tmp.17 = load int* %tmp.16 ; ty=int
- %tmp.18 = setne int %tmp.17, 0 ; ty=bool
- %tmp.19 = cast bool %tmp.18 to int ; ty=int
- br bool %tmp.18, label %shortcirc_next.2, label %shortcirc_done.2
-shortcirc_next.2:
- %tmp.21 = load double* %m ; ty=double
- %tmp.20 = call fastcc int (double)* %ll_math_is_error(double %tmp.21) ; ty=int
- %tmp.22 = setne int %tmp.20, 0 ; ty=bool
- %tmp.23 = cast bool %tmp.22 to int ; ty=int
- br label %shortcirc_done.2
-shortcirc_done.2:
- %shortcirc_val.2 = phi bool [ false, %endif.0 ], [ %tmp.22, %shortcirc_next.2 ] ; ty=bool
- %tmp.24 = cast bool %shortcirc_val.2 to int ; ty=int
- br bool %shortcirc_val.2, label %then.1, label %endif.1
-then.1:
- store %RPyFREXP_RESULT* null, %RPyFREXP_RESULT** %result
- br label %return
-after_ret.0:
- br label %endif.1
-endif.1:
- %tmp.26 = load double* %m ; ty=double
- %tmp.27 = load int* %expo ; ty=int
- %tmp.25 = call fastcc %RPyFREXP_RESULT* (double, int)* %ll_frexp_result__Float_Signed(double %tmp.26, int %tmp.27) ; ty=%RPyFREXP_RESULT*
- store %RPyFREXP_RESULT* %tmp.25, %RPyFREXP_RESULT** %result
- br label %return
-after_ret.1:
- br label %return
-return:
- %tmp.28 = load %RPyFREXP_RESULT** %result ; ty=%RPyFREXP_RESULT*
- ret %RPyFREXP_RESULT* %tmp.28
-}
-
""")
Modified: pypy/dist/pypy/translator/llvm2/module/ll_time.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_time.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_time.py Thu Aug 25 13:34:17 2005
@@ -5,7 +5,7 @@
%struct.timezone = type { INT, INT }
%typedef.fd_set = type { [32 x INT] }
-%.str_1 = internal constant [16 x sbyte] c"select() failed\\00" ; <[16 x sbyte]*> [#uses=1]
+%.str_xxx1 = internal constant [16 x sbyte] c"select() failed\\00" ; <[16 x sbyte]*> [#uses=1]
declare ccc double %floor(double)
declare ccc double %fmod(double, double)
@@ -75,7 +75,7 @@
br bool %tmp.12, label %then.1, label %return
then.1: ; preds = %entry
- ; XXX disabled for now: call void %RaiseSimpleException( INT 1, sbyte* getelementptr ([16 x sbyte]* %.str_1, INT 0, INT 0) )
+ ; XXX disabled for now: call void %RaiseSimpleException( INT 1, sbyte* getelementptr ([16 x sbyte]* %.str_xxx1, INT 0, INT 0) )
ret void
return: ; preds = %entry
Modified: pypy/dist/pypy/translator/llvm2/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/support.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/support.py Thu Aug 25 13:34:17 2005
@@ -5,12 +5,9 @@
declare ccc INT %strlen(sbyte*)
declare ccc INT %strcmp(sbyte*, sbyte*)
declare ccc sbyte* %memset(sbyte*, INT, UINT)
-declare ccc double %frexp(double, int*)
%__print_debug_info = internal global bool false
%__print_debug_info_option = internal constant [19 x sbyte] c"--print-debug-info\\00"
-%.str_1 = internal constant [17 x sbyte] c"math range error\\00"
-%.str_2 = internal constant [18 x sbyte] c"math domain error\\00"
"""
More information about the Pypy-commit
mailing list