[pypy-svn] r15798 - in pypy/dist/pypy/translator/llvm2: . module

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Aug 9 09:58:50 CEST 2005


Author: ericvrp
Date: Tue Aug  9 09:58:48 2005
New Revision: 15798

Modified:
   pypy/dist/pypy/translator/llvm2/codewriter.py
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/module/ll_time.py
   pypy/dist/pypy/translator/llvm2/module/support.py
   pypy/dist/pypy/translator/llvm2/opwriter.py
Log:
- refactored casts
- storing missing functions and operation error message in .ll file
- XXX there is still an issue with the pyrex wrapper code.
  It does not know how to handle a list of rpy_strings.
- after translating entire PyPy (86Mb .ll file) these were the messages:

;; XXX: Error: _generic_pow: Variable has no value
;; XXX: Error: exception raising operation invoke:float_add not found
;; XXX: Error: exception raising operation invoke:float_mul not found
;; XXX: Error: exception raising operation invoke:float_pow not found
;; XXX: Error: exception raising operation invoke:float_sub not found
;; XXX: Error: exception raising operation invoke:float_truediv not found
;; XXX: Error: exception raising operation invoke:int_add not found
;; XXX: Error: exception raising operation invoke:int_add_ovf not found
;; XXX: Error: exception raising operation invoke:int_floordiv_ovf_zer not found
;; XXX: Error: exception raising operation invoke:int_lshift_ovf_val not found
;; XXX: Error: exception raising operation invoke:int_mod_ovf_zer not found
;; XXX: Error: exception raising operation invoke:int_mul_ovf not found
;; XXX: Error: exception raising operation invoke:int_neg_ovf not found
;; XXX: Error: exception raising operation invoke:int_sub not found
;; XXX: Error: exception raising operation invoke:int_sub_ovf not found
;; XXX: Error: operation float_abs not found
;; XXX: Error: operation int_abs not found
;; XXX: Error: primitive function %float_add has no implementation
;; XXX: Error: primitive function %float_mul has no implementation
;; XXX: Error: primitive function %float_pow has no implementation
;; XXX: Error: primitive function %float_sub has no implementation
;; XXX: Error: primitive function %float_truediv has no implementation
;; XXX: Error: primitive function %int_add has no implementation
;; XXX: Error: primitive function %int_add_ovf has no implementation
;; XXX: Error: primitive function %int_floordiv_ovf_zer has no implementation
;; XXX: Error: primitive function %int_lshift_ovf_val has no implementation
;; XXX: Error: primitive function %int_mod_ovf_zer has no implementation
;; XXX: Error: primitive function %int_mul_ovf has no implementation
;; XXX: Error: primitive function %int_sub has no implementation
;; XXX: Error: primitive function %int_sub_ovf has no implementation
;; XXX: Error: primitive function %ll_math_frexp has no implementation
;; XXX: Error: primitive function %ll_math_hypot has no implementation
;; XXX: Error: primitive function %ll_math_ldexp has no implementation
;; XXX: Error: primitive function %ll_math_modf has no implementation
;; XXX: Error: primitive function %ll_os_ftruncate has no implementation
;; XXX: Error: primitive function %ll_os_lseek has no implementation
;; XXX: Error: primitive function %ll_os_stat has no implementation



Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Tue Aug  9 09:58:48 2005
@@ -15,7 +15,8 @@
         self.n_lines += 1
         if self.show_line_numbers:
             line = "%-75s; %d" % (line, self.n_lines)
-        print >> self.f, line
+        #print >> self.f, line
+        self.f.write(line + '\n')
 
     def comment(self, line, indent=True):
         line = ";; " + line

Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Tue Aug  9 09:58:48 2005
@@ -18,6 +18,8 @@
 
 from pypy.translator.translator import Translator
 
+import time
+
 function_count = {}
 
 class GenLLVM(object):
@@ -37,6 +39,7 @@
         self.debug = debug
         
     def gen_llvm_source(self, func=None):
+        print 'gen_llvm_source begin) ' + time.ctime()
         if func is None:
             func = self.translator.entrypoint
         self.entrypoint = func
@@ -54,7 +57,12 @@
         self.db.prepare_repr_arg(c)
         assert c in self.db.obj2node
 
+        print 'gen_llvm_source db.setup_all) ' + time.ctime()
+        #7 minutes
         self.db.setup_all()
+        print 'gen_llvm_source typ_decl.writedatatypedecl) ' + time.ctime()
+        print 'gen_llvm_source n_nodes) %d' % len(self.db.getnodes())
+        #3 seconds
         if self.debug:
             log.gen_llvm_source(self.db.dump_pbcs())
 
@@ -77,26 +85,34 @@
         for typ_decl in self.db.getnodes():
             typ_decl.writedatatypedecl(codewriter)
 
+        print 'gen_llvm_source typ_decl.writeglobalconstants) ' + time.ctime()
+        #20 minutes
         nl(); comment("Global Data") ; nl()
         for typ_decl in self.db.getnodes():
             typ_decl.writeglobalconstants(codewriter)
 
+        print 'gen_llvm_source typ_decl.writecomments) ' + time.ctime()
+        #0 minutes
         if self.debug:
             nl(); comment("Comments") ; nl()
             for typ_decl in self.db.getnodes():
                 typ_decl.writecomments(codewriter)
             
+        print 'gen_llvm_source extdeclarations) ' + time.ctime()
         nl(); comment("Function Prototypes") ; nl()
         if self.embedexterns:
             for extdecl in extdeclarations.split('\n'):
                 codewriter.append(extdecl)
 
+        print 'gen_llvm_source self._debug_prototype) ' + time.ctime()
         if self.debug:
             self._debug_prototype(codewriter)
             
+        print 'gen_llvm_source typ_decl.writedecl) ' + time.ctime()
         for typ_decl in self.db.getnodes():
             typ_decl.writedecl(codewriter)
 
+        print 'gen_llvm_source boehm_gc) ' + time.ctime()
         nl(); comment("Function Implementation") 
         codewriter.startimpl()
         if use_boehm_gc:
@@ -106,9 +122,12 @@
         for gc_func in gc_funcs.split('\n'):
             codewriter.append(gc_func)
 
+        print 'gen_llvm_source typ_decl.writeimpl) ' + time.ctime()
+        #XXX ? minutes
         for typ_decl in self.db.getnodes():
             typ_decl.writeimpl(codewriter)
 
+        print 'gen_llvm_source used_external_functions) ' + time.ctime()
         depdone = {}
         for funcname,value in ExternalFuncNode.used_external_functions.iteritems():
             deps = dependencies(funcname,[])
@@ -118,11 +137,15 @@
                     try:
                         llvm_code = extfunctions[dep][1]
                     except KeyError:
-                        raise Exception('primitive function %s has no implementation' %(dep,))
+                        msg = 'primitive function %s has no implementation' % dep
+                        codewriter.comment('XXX: Error: ' + msg)
+                        #raise Exception('primitive function %s has no implementation' %(dep,))
+                        continue
                     for extfunc in llvm_code.split('\n'):
                         codewriter.append(extfunc)
                     depdone[dep] = True
 
+        print 'gen_llvm_source entrypoint) ' + time.ctime()
         #XXX use codewriter methods here
         decl = self.entrynode.getdecl()
         t = decl.split('%', 1)
@@ -152,6 +175,7 @@
         codewriter.newline()
 
         comment("End of file") ; nl()
+        print 'gen_llvm_source return) ' + time.ctime()
         return filename
 
     def create_module(self, filename, exe_name=None):

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	Tue Aug  9 09:58:48 2005
@@ -76,7 +76,7 @@
 	br bool %tmp.12, label %then.1, label %return
 
 then.1:		; preds = %entry
-	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_1, 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	Tue Aug  9 09:58:48 2005
@@ -1,4 +1,8 @@
-extdeclarations = ""
+extdeclarations = """
+declare ccc double %pow(double, double)
+declare ccc double %fmod(double, double)
+"""
+
 
 extfunctions = {}
 
@@ -107,6 +111,45 @@
 
 #XXX TODO
 
+#extfunctions["%float_pow"] = ((), """
+#fastcc double %float_pow(double %x, double %y) {
+#    ; XXX ERROR float_pow exception raising not implemented
+#    %r = call ccc double %pow(double %x, double %y)
+#    ret double %r
+#}
+#
+#""")
+#
+#extfunctions["%float_mod"] = ((), """
+#fastcc double %float_mod(double %x, double %y) {
+#    ; XXX ERROR float_mod exception raising not implemented
+#    %r = call ccc double %fmod(double %x, double %y)
+#    ret double %r
+#}
+#
+#""")
+#
+#for func in 'float_abs float_sub float_add float_mul float_div'.split():
+#    extfunctions["%" + func] = ((), """
+#fastcc double %%%(func)s(double %%x, double %%y) {
+#    ; XXX ERROR %(func)s exception raising not implemented
+#    ret double 0.0
+#}
+#
+#""" % locals())
+#
+#for func in 'int_abs int_sub int_add int_mul int_div int_mod int_add_ovf int_sub_ovf int_mul_ovf int_floordiv_ovf int_mod_ovf int_floordiv_ovf_zer int_mod_ovf_zer int_lshift_ovf int_lshift_ovf_val int_rshift_val int_lshift_val'.split():
+#    extfunctions["%" + func] = ((), """
+#fastcc int %%%(func)s(int %%x, int %%y) {
+#    ; XXX ERROR %(func)s exception raising not implemented
+#    ret int 0
+#}
+#
+#""" % locals())
+
+
+#XXX TODO
+
 #overflow: normal operation, ...if ((x) >= 0 || (x) != -(x)) ok else _OVF()
 
 #binary with overflow

Modified: pypy/dist/pypy/translator/llvm2/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/opwriter.py	Tue Aug  9 09:58:48 2005
@@ -89,16 +89,27 @@
                 self.binaryop(op)
             elif op.opname in self.shift_operations:
                 self.shiftop(op)
+            elif op.opname.startswith('cast_'):
+                self.cast_primitive(op)
             else:
                 meth = getattr(self, op.opname, None)
-                assert meth is not None, "operation %s not found" %(op.opname,)
+                if not meth:
+                    msg = "operation %s not found" %(op.opname,)
+                    self.codewriter.comment('XXX: Error: ' + msg)
+                    #assert meth is not None, msg
+                    return
                 meth(op)    
 
     def _generic_pow(self, op, onestr): 
         mult_type = self.db.repr_arg_type(op.args[0])
         mult_val = self.db.repr_arg(op.args[0])
         last_val = mult_val
-        operand = int(op.args[1].value)
+        try:
+            operand = int(op.args[1].value)
+        except:
+            msg = 'XXX: Error: _generic_pow: Variable has no value'
+            self.codewriter.comment(msg)
+            return
         if operand < 1:
             res_val = onestr
         else:
@@ -130,6 +141,7 @@
                                  )
     def int_neg(self, op):
         self._generic_neg(op, "0") 
+    uint_neg = int_neg  #this is really generates, don't know why
 
     def float_neg(self, op):
         self._generic_neg(op, "0.0") 
@@ -141,12 +153,13 @@
                                  self.db.repr_arg(op.args[0]), 
                                  "true")
 
-    def uint_invert(self, op):
+    def int_invert(self, op):  #XXX do we have a test for this, it doesn't look right?
         self.codewriter.binaryop("xor",
                                  self.db.repr_arg(op.result),
                                  self.db.repr_arg_type(op.args[0]),
                                  self.db.repr_arg(op.args[0]), 
                                  1)
+    uint_invert = int_invert
 
     def binaryop(self, op):
         name = self.binary_operations[op.opname]
@@ -178,16 +191,16 @@
         fromvar = self.db.repr_arg(op.args[0])
         fromtype = self.db.repr_arg_type(op.args[0])
         self.codewriter.cast(targetvar, fromtype, fromvar, targettype)
-
-    cast_bool_to_char = cast_bool_to_int  = cast_bool_to_uint = cast_primitive
-    cast_char_to_bool = cast_char_to_int  = cast_char_to_uint = cast_primitive
-    cast_int_to_bool  = cast_int_to_char  = cast_int_to_uint  = cast_primitive
-    cast_uint_to_bool = cast_uint_to_char = cast_uint_to_int  = cast_primitive
-    cast_int_to_float = cast_float_to_int = cast_primitive
-    cast_unichar_to_int = cast_int_to_unichar = cast_primitive
-    cast_pointer = cast_primitive
     same_as = cast_primitive
 
+    #cast_bool_to_char  = cast_bool_to_int  = cast_bool_to_uint = cast_bool_to_float = cast_bool_to_unichar  = cast_primitive
+    #cast_char_to_bool  = cast_char_to_int  = cast_char_to_uint = cast_char_to_float = cast_char_to_unichar  = cast_primitive
+    #cast_int_to_bool   = cast_int_to_char  = cast_int_to_uint  = cast_int_to_float  = cast_int_to_unichar   = cast_primitive
+    #cast_uint_to_bool  = cast_uint_to_char = cast_uint_to_int  = cast_uint_to_float = cast_uint_to_unichar  = cast_primitive
+    #cast_float_to_bool = cast_float_to_char= cast_float_to_int = cast_float_to_uint = cast_float_to_unichar = cast_primitive
+    #cast_unichar_to_bool=cast_unichar_to_char=cast_unichar_to_int=cast_unichar_to_uint=cast_unichar_to_float= cast_primitive
+    #cast_pointer = cast_primitive
+
     def int_is_true(self, op):
         self.codewriter.binaryop("setne",
                                  self.db.repr_arg(op.result),
@@ -246,8 +259,9 @@
             op_args = ['%' + opname] + op_args
             functionref = op_args[0]
             ExternalFuncNode.used_external_functions[functionref] = True
-            assert functionref in extfunctions, \
-                   "exception raising operation %(opname)s has no implementation" % locals()
+            msg = "exception raising operation %s not found" %(op.opname,)
+            self.codewriter.comment('XXX: Error: ' + msg)
+            #assert functionref in extfunctions, msg
         
         assert len(op_args) >= 1
         assert len(self.block.exits) >= 2   #at least one label and one exception label
@@ -392,7 +406,7 @@
                                           ("uint", index))        
             self.codewriter.load(targetvar, targettype, tmpvar)
         else:
-            self.codewriter.comment("***Skipping operation getfield()***")
+            self.codewriter.comment("***Skipping operation getfield()***")  #XXX what if this the last operation of the exception block?
  
     def getsubstruct(self, op): 
         struct, structtype = self.db.repr_argwithtype(op.args[0])



More information about the Pypy-commit mailing list