[pypy-svn] r49190 - in pypy/dist/pypy/translator/llvm: . module

rxe at codespeak.net rxe at codespeak.net
Wed Nov 28 13:57:15 CET 2007


Author: rxe
Date: Wed Nov 28 13:57:14 2007
New Revision: 49190

Modified:
   pypy/dist/pypy/translator/llvm/buildllvm.py
   pypy/dist/pypy/translator/llvm/codewriter.py
   pypy/dist/pypy/translator/llvm/database.py
   pypy/dist/pypy/translator/llvm/externs2ll.py
   pypy/dist/pypy/translator/llvm/extfuncnode.py
   pypy/dist/pypy/translator/llvm/gc.py
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/llvm/module/support.py
   pypy/dist/pypy/translator/llvm/opwriter.py
Log:
kill and fix calling convention mess, as llvm inserts with opt anyways. (thanks AntonK and xorAxAx)

Modified: pypy/dist/pypy/translator/llvm/buildllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/buildllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/buildllvm.py	Wed Nov 28 13:57:14 2007
@@ -80,17 +80,24 @@
         opts = self.optimizations()
         self.cmds.append("llvm-as < %s.ll | opt %s -f -o %s.bc" % (base, opts, base))
 
-    def cmds_objects(self, base):
+    def cmds_objects(self, base, standalone):
         use_gcc = self.genllvm.config.translation.llvm_via_c
         if use_gcc:
             self.cmds.append("llc %s.bc -march=c -f -o %s.c" % (base, base))
             self.cmds.append("gcc %s.c -c -O3 -fomit-frame-pointer" % base)
         else:
-            self.cmds.append("llc -relocation-model=pic %s.bc -f -o %s.s" % (base, base))
+            model = ''
+            if not standalone:
+                model = ' -relocation-model=pic'
+                
+            self.cmds.append("llc %s %s.bc -f -o %s.s" % (model, base, base))
             self.cmds.append("as %s.s -o %s.o" % (base, base))
 
         include_opts = get_incdirs(self.genllvm.eci)
+
         # compile separate files
+        # XXX rxe: why do we want to run a c compiler, when we run llvm
+        # compiler - these seems a step backwards IMHO ?????
         libraries = set()
         for filename in self.genllvm.eci.separate_module_files:
             assert filename.endswith(".c")
@@ -128,11 +135,7 @@
 
         return self.genllvm.entry_name
  
-    def setup_linker_command(self, exename):
-        base = self.setup()
-        self.cmds_bytecode(base)
-        self.cmds_objects(base)
-
+    def setup_linker_command(self, base, exename=None):
         eci = self.genllvm.eci
         library_files = self.genllvm.db.gcpolicy.gc_libraries()
         library_files = list(library_files) + list(eci.libraries)
@@ -165,11 +168,12 @@
         if exename:
             out = exename
         self.cmds.append("gcc -O3 %s.o %s -o %s" % (base, " ".join(compiler_opts), out))
-        return base
-
 
     def make_module(self):
-        base = self.setup_linker_command(False)
+        base = self.setup()
+        self.cmds_bytecode(base)
+        self.cmds_objects(base, False)
+        self.setup_linker_command(base)
         try:
             self.execute_cmds()
             modname = CtypesModule(self.genllvm, "%s.so" % base).create()
@@ -179,7 +183,10 @@
         return modname, str(self.dirpath)
 
     def make_standalone(self, exename):
-        base = self.setup_linker_command(exename)
+        base = self.setup()
+        self.cmds_bytecode(base)
+        self.cmds_objects(base, True)
+        self.setup_linker_command(base, exename)
 
         try:
             self.execute_cmds()

Modified: pypy/dist/pypy/translator/llvm/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/codewriter.py	Wed Nov 28 13:57:14 2007
@@ -4,40 +4,18 @@
 log = log.codewriter 
 
 class CodeWriter(object): 
-    tail = ''       #/tail
-    cconv = 'ccc'    #ccc/fastcc
     linkage = 'internal '       #/internal (disabled for now because of the JIT)
 
-    def __init__(self, file, db, tail=None, cconv=None, linkage=None): 
+    def __init__(self, file, db, linkage=None): 
         self.db = db
         self.file = file
         self.word_repr = db.get_machine_word()
-        if tail is not None:
-            self.tail = tail
-        if cconv is not None:
-            self.cconv = cconv
         if linkage is not None:
             self.linkage = linkage
 
     def close(self): 
         self.file.close()
 
-    def _resolvetail(self, tail, cconv):
-        # from: http://llvm.org/docs/LangRef.html
-        # The optional "tail" marker indicates whether the callee function
-        # accesses any allocas or varargs in the caller. If the "tail" marker
-        # is present, the function call is eligible for tail call
-        # optimization. Note that calls may be marked "tail" even if they do
-        # not occur before a ret instruction.
-
-        if cconv is not 'fastcc':
-            tail_ = ''
-        else:
-            tail_ = tail
-        if tail_:
-            tail_ += ' '
-        return tail_
-
     # keep these two internal for now - incase we try a different API
     def _append(self, line): 
         self.file.write(line + '\n')
@@ -50,7 +28,6 @@
             if patch:
                 l = l.replace('WORD', self.word_repr)
                 l = l.replace('POSTFIX', postfix())
-                l = l.replace('CC', self.cconv)
             self._append(l)
     
     def comment(self, line, indent=True):
@@ -82,10 +59,8 @@
     def typedef(self, name, type_):
         self._append("%s = type %s" % (name, type_))
 
-    def declare(self, decl, cconv=None):
-        if cconv is None:
-            cconv = self.cconv
-        self._append("declare %s %s" %(cconv, decl,))
+    def declare(self, decl):
+        self._append("declare %s" % decl)
 
     def br_uncond(self, blockname): 
         self._indent("br label %%%s" %(blockname,))
@@ -101,13 +76,11 @@
         self._indent("switch %s %s, label %%%s [%s ]"
                      % (intty, cond, defaultdest, labels))
 
-    def openfunc(self, decl, cconv=None, linkage=None): 
-        if cconv is None:
-            cconv = self.cconv
+    def openfunc(self, decl, linkage=None): 
         if linkage is None:
             linkage = self.linkage
         self.newline()
-        self._append("define %s%s %s {" % (linkage, cconv, decl,))
+        self._append("define %s %s {" % (linkage, decl,))
 
     def closefunc(self): 
         self._append("}") 
@@ -166,14 +139,7 @@
     def unwind(self):
         self._indent("unwind")
 
-    def call(self, targetvar, returntype, functionref, argtypes, argrefs,
-             tail=None, cconv=None, ret_type_attrs=""):
-        if tail is None:
-            tail = self.tail
-        if cconv is None:
-            cconv = self.cconv
-            
-        tail = self._resolvetail(tail, cconv)        
+    def call(self, targetvar, returntype, functionref, argtypes, argrefs, ret_type_attrs=""):
         args = ", ".join(["%s %s" % item for item in zip(argtypes, argrefs)])
 
         if returntype == 'void':
@@ -181,13 +147,11 @@
         else:
             return_str = '%s = ' % targetvar
 
-        self._indent("%s%scall %s %s %s(%s) %s" % (return_str,
-                                                tail,
-                                                cconv,
-                                                returntype,
-                                                functionref,
-                                                args,
-                                                ret_type_attrs))
+        self._indent("%s call %s %s(%s) %s" % (return_str,
+                                               returntype,
+                                               functionref,
+                                               args,
+                                               ret_type_attrs))
 
     def alloca(self, targetvar, vartype):
         self._indent("%s = alloca %s" % (targetvar, vartype))
@@ -212,4 +176,4 @@
         node = self.db.create_debug_string(s)
         self.call(var, "i32", "@write",
                   ['i32', 'i8*', 'i32'],
-                  ['2', node.get_childref(0), '%d' % node.get_length()], cconv='ccc')
+                  ['2', node.get_childref(0), '%d' % node.get_length()])

Modified: pypy/dist/pypy/translator/llvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/database.py	(original)
+++ pypy/dist/pypy/translator/llvm/database.py	Wed Nov 28 13:57:14 2007
@@ -39,9 +39,6 @@
 
         self.debugstringnodes = []
 
-        # call back into rpython code from c code
-        self.extern_to_funcnodes = []
-
 
     #_______debuggging______________________________________
 
@@ -320,9 +317,6 @@
         self._tmpcount += 1
         return "%tmp_" + str(count) 
 
-    def add_extern_to_funcnode(self, name): 
-        self.extern_to_funcnodes.append(name)
-
     # __________________________________________________________
     # Other helpers
 

Modified: pypy/dist/pypy/translator/llvm/externs2ll.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/externs2ll.py	(original)
+++ pypy/dist/pypy/translator/llvm/externs2ll.py	Wed Nov 28 13:57:14 2007
@@ -37,17 +37,7 @@
 
 # call boehm finalizers need to be fastcc
 
-def generate_ll(ccode, default_cconv, eci, call_funcnames=[]):
-    call_funcnames = ['@LLVM_RPython_StartupCode'] + call_funcnames
-    define_funcnames = ['@pypy_malloc',
-                        '@pypy_malloc_atomic',
-                        '@pypy_gc__collect',
-                        '@pypy_register_finalizer',
-                        '@raw_malloc',
-                        '@raw_free',
-                        ]
-    declare_funcnames = call_funcnames
-
+def generate_ll(ccode, eci):
     filename = str(udir.join("ccode.c"))
     f = open(filename, "w")
     f.write(ccode)
@@ -65,47 +55,7 @@
 
     # strip lines
     lines = []
-
-    calltag, declaretag, definetag = 'call ', 'declare ', 'define '
-    
     for line in llcode.split('\n'):
-
-        # get rid of any of the structs that llvm-gcc introduces to struct types
-        line = line.replace("%struct.", "%")
-
-        # strip comments
-        comment = line.find(';')
-        if comment >= 0:
-            line = line[:comment]
-        line = line.rstrip()
-
-        # patch calls (upgrade to default_cconv)
-        i = line.find(calltag)
-        if i >= 0:
-            for funcname in call_funcnames:
-                if line.find(funcname) >= 0:
-                    line = "%scall %s %s" % (line[:i], default_cconv, line[i+len(calltag):])
-                    break
-
-        if line[:len(declaretag)] == declaretag:
-            xline = line[len(declaretag):] 
-            for funcname in declare_funcnames: 
-                if xline.find(funcname) != -1:
-                    line = "declare %s %s %s" % (internal, default_cconv, xline)
-                    break
-                    
-        if line[:len(definetag)] == definetag:
-            xline = line[len(definetag):] 
-            internal = ''
-            if xline.startswith('internal '):
-                internal = 'internal '
-                xline = xline.replace('internal ', '')
-
-            for funcname in define_funcnames: 
-                if xline.find(funcname) != -1:
-                    line = "define %s %s %s" % (internal, default_cconv, xline)
-                    break
-
         lines.append(line)
 
     lines.append("declare ccc void @abort()")

Modified: pypy/dist/pypy/translator/llvm/extfuncnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/extfuncnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/extfuncnode.py	Wed Nov 28 13:57:14 2007
@@ -29,5 +29,5 @@
         return "%s %s(%s) %s" % (rettype, self.ref, ", ".join(argtypes), rettype_attrs)
 
     def writedecl(self, codewriter):
-        codewriter.declare(self.getdecl(), cconv="ccc")
+        codewriter.declare(self.getdecl())
 

Modified: pypy/dist/pypy/translator/llvm/gc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/gc.py	(original)
+++ pypy/dist/pypy/translator/llvm/gc.py	Wed Nov 28 13:57:14 2007
@@ -77,8 +77,7 @@
         codewriter.malloc(targetvar, "i8", size)
         codewriter.call(None, 'void', '@llvm.memset' + postfix(),
                         ['i8*', 'i8', word, word],
-                        [targetvar, 0, size, boundary_size],
-                        cconv='ccc')               
+                        [targetvar, 0, size, boundary_size])
 
 class BoehmGcPolicy(GcPolicy):
 
@@ -114,11 +113,9 @@
         codewriter.call(targetvar, 'i8*', fnname, [word], [size])
 
         if atomic:
-            # XXX uses own cconv
             codewriter.call(None, 'void', '@llvm.memset' + postfix(),
                             ['i8*', 'i8', word, word],
-                            [targetvar, 0, size, boundary_size],
-                            cconv='ccc')        
+                            [targetvar, 0, size, boundary_size])
 
 
     def op_set_max_heap_size(self, codewriter, opr):

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Wed Nov 28 13:57:14 2007
@@ -181,7 +181,6 @@
         else:
             self.function_count[name] = 1
 
-        self.db.add_extern_to_funcnode(name)
         self.entry_name = name[6:]
         return c.value._obj 
 
@@ -194,7 +193,7 @@
         self.eci = self.eci.merge(*all)
 
         ccode = generate_c(self.db, self.entrynode, self.eci, self.standalone)
-        self.llcode = generate_ll(ccode, codewriter.cconv, self.eci, self.db.extern_to_funcnodes)
+        self.llcode = generate_ll(ccode, self.eci)
         self.eci = self.eci.convert_sources_to_files(being_main=True)
         
     def create_codewriter(self):
@@ -204,7 +203,7 @@
         if self.standalone:
             return CodeWriter(f, self.db), filename
         else:
-            return CodeWriter(f, self.db, cconv='ccc', linkage=''), filename
+            return CodeWriter(f, self.db, linkage=''), filename
                 
     def write_startup_impl(self, codewriter):
         open_decl =  "i8* @LLVM_RPython_StartupCode()"

Modified: pypy/dist/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/support.py	(original)
+++ pypy/dist/pypy/translator/llvm/module/support.py	Wed Nov 28 13:57:14 2007
@@ -1,5 +1,5 @@
 extfunctions = """
-define internal CC double @pypyop_float_abs(double %x) {
+define internal double @pypyop_float_abs(double %x) {
 block0:
     %cond1 = fcmp ugt double %x, 0.0
     br i1 %cond1, label %return_block, label %block1
@@ -11,7 +11,7 @@
     ret double %result
 }
 
-define internal CC i32 @pypyop_int_abs(i32 %x) {
+define internal i32 @pypyop_int_abs(i32 %x) {
 block0:
     %cond1 = icmp sge i32 %x, 0
     br i1 %cond1, label %return_block, label %block1
@@ -23,7 +23,7 @@
     ret i32 %result
 }
 
-define internal CC i64 @pypyop_llong_abs(i64 %x) {
+define internal i64 @pypyop_llong_abs(i64 %x) {
 block0:
     %cond1 = icmp sge i64 %x, 0
     br i1 %cond1, label %return_block, label %block1

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Wed Nov 28 13:57:14 2007
@@ -296,7 +296,6 @@
                                  opr.argrefs[0], "null")
 
     def direct_call(self, opr):
-        cconv = None
         rettype_attrs = ""
 
         # XXX aargh - more illegal fishing
@@ -308,15 +307,10 @@
             assert isinstance(T, lltype.FuncType)
             value = opr.op.args[0].value._obj        
             if getattr(value, 'external', None) == 'C':
-                cconv = 'ccc'
                 rettype_attrs = self.db.primitives.get_attrs_for_type(T.RESULT)
-
-
-        #self.codewriter.debug_print(str(opr.op) + "\n")
-        #self.codewriter.debug_print(str(cconv) + "\n")
             
         self.codewriter.call(opr.retref, opr.rettype, opr.argrefs[0],
-                             opr.argtypes[1:], opr.argrefs[1:], cconv=cconv, ret_type_attrs=rettype_attrs)
+                             opr.argtypes[1:], opr.argrefs[1:], ret_type_attrs=rettype_attrs)
 
     # the following works since the extra arguments that indirect_call has
     # is of type Void, which is removed by direct_call



More information about the Pypy-commit mailing list