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

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Aug 18 14:38:39 CEST 2005


Author: ericvrp
Date: Thu Aug 18 14:38:38 2005
New Revision: 16134

Modified:
   pypy/dist/pypy/translator/llvm2/build_llvm_module.py
   pypy/dist/pypy/translator/llvm2/codewriter.py
   pypy/dist/pypy/translator/llvm2/module/extfunction.py
   pypy/dist/pypy/translator/llvm2/varsize.py
Log:
* added optional cconv to codewriter calls and invokes

* attempt to do less zero-initialization after mallocs,
  by only initing array of chars.

* attempt to speed up llvm compilation and getting rid
  of the ..._optimized.bc file



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 18 14:38:38 2005
@@ -191,28 +191,21 @@
         library_files.append('gc')
     else:
         gc_libs = ''
-    
+
+    if optimize:
+        cmds = ["llvm-as < %s.ll | opt %s > %s.bc" % (b, OPTIMIZATION_SWITCHES, b)]
+    else:
+        cmds = ["llvm-as < %s.ll > %s.bc" % (b, b)]
+
     if sys.maxint == 2147483647:        #32 bit platform
-        if optimize:
-            cmds = ["llvm-as %s.ll -f -o %s.bc" % (b, b),
-                    "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES, b, b),
-                    "llc %s %s_optimized.bc -f -o %s.s" % (EXCEPTIONS_SWITCHES, b, b)]
-        else:
-            cmds = ["llvm-as %s.ll -f -o %s.bc" % (b, b),
-                    "llc %s %s.bc -f -o %s.s" % (EXCEPTIONS_SWITCHES, b, b)]
+        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:
             cmds.append("gcc %s.o -static %s -lm -o %s" % (b, gc_libs, exe_name))
         object_files.append("%s.o" % b)
     else:       #assume 64 bit platform (x86-64?)
         #this special case for x86-64 (called ia64 in llvm) can go as soon as llc supports ia64 assembly output!
-        if optimize:
-            cmds = ["llvm-as %s.ll -f -o %s.bc" % (b, b), 
-                    "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES, b, b),
-                    "llc %s %s_optimized.bc -march=c -f -o %s.c" % (EXCEPTIONS_SWITCHES, b, b)]
-        else:
-            cmds = ["llvm-as %s.ll -f -o %s.bc" % (b, b),
-                    "llc %s %s.bc -march=c -f -o %s.c" % (EXCEPTIONS_SWITCHES, b, b)]
+        cmds.append("llc %s %s.bc -march=c -f -o %s.c" % (EXCEPTIONS_SWITCHES, b, b))
         source_files.append("%s.c" % b)
 
     try:

Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Thu Aug 18 14:38:38 2005
@@ -46,8 +46,8 @@
         self.append("%s = type %s (%s)" % (name, rettyperepr,
                                            ", ".join(argtypereprs)))
 
-    def declare(self, decl):
-        self.append("declare fastcc %s" %(decl,))
+    def declare(self, decl, cconv='fastcc'):
+        self.append("declare %s %s" %(cconv, decl,))
 
     def startimpl(self):
         self.newline()
@@ -68,14 +68,14 @@
         self.indent("switch %s %s, label %%%s [%s ]"
                     % (intty, cond, defaultdest, labels))
 
-    def openfunc(self, decl, is_entrynode=False): 
+    def openfunc(self, decl, is_entrynode=False, cconv='fastcc'): 
         self.malloc_count = count(0).next
         self.newline()
         if is_entrynode:
             linkage_type = ''
         else:
             linkage_type = 'internal '
-        self.append("%sfastcc %s {" % (linkage_type, decl,))
+        self.append("%s%s %s {" % (linkage_type, cconv, decl,))
 
     def closefunc(self): 
         self.append("}") 
@@ -104,29 +104,29 @@
     def shiftop(self, name, targetvar, type_, ref1, ref2):
         self.indent("%s = %s %s %s, ubyte %s" % (targetvar, name, type_, ref1, ref2))
 
-    def call(self, targetvar, returntype, functionref, argrefs, argtypes):
+    def call(self, targetvar, returntype, functionref, argrefs, argtypes, cconv='fastcc'):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%s = call fastcc %s %s(%s)" % (targetvar, returntype, functionref,
+        self.indent("%s = call %s %s %s(%s)" % (targetvar, cconv, returntype, functionref,
                                              ", ".join(arglist)))
 
-    def call_void(self, functionref, argrefs, argtypes):
+    def call_void(self, functionref, argrefs, argtypes, cconv='fastcc'):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("call fastcc void %s(%s)" % (functionref, ", ".join(arglist)))
+        self.indent("call %s void %s(%s)" % (cconv, functionref, ", ".join(arglist)))
 
-    def invoke(self, targetvar, returntype, functionref, argrefs, argtypes, label, except_label):
+    def invoke(self, targetvar, returntype, functionref, argrefs, argtypes, label, except_label, cconv='fastcc'):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%s = invoke fastcc %s %s(%s) to label %%%s except label %%%s" % (targetvar, returntype, functionref,
+        self.indent("%s = invoke %s %s %s(%s) to label %%%s except label %%%s" % (targetvar, cconv, returntype, functionref,
                                              ", ".join(arglist), label, except_label))
 
-    def invoke_void(self, functionref, argrefs, argtypes, label, except_label):
+    def invoke_void(self, functionref, argrefs, argtypes, label, except_label, cconv='fastcc'):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("invoke fastcc void %s(%s) to label %%%s except label %%%s" % (functionref, ", ".join(arglist), label, except_label))
+        self.indent("invoke %s void %s(%s) to label %%%s except label %%%s" % (cconv, functionref, ", ".join(arglist), label, except_label))
 
     def cast(self, targetvar, fromtype, fromvar, targettype):
         self.indent("%(targetvar)s = cast %(fromtype)s "
                         "%(fromvar)s to %(targettype)s" % locals())
 
-    def malloc(self, targetvar, type_, size=1, atomic=False):
+    def malloc(self, targetvar, type_, size=1, atomic=False, cconv='fastcc'):
         n = self.malloc_count()
         if n:
             cnt = ".%d" % n
@@ -135,7 +135,7 @@
         postfix = ('', '_atomic')[atomic]
         self.indent("%%malloc.Size%(cnt)s = getelementptr %(type_)s* null, uint %(size)s" % locals())
         self.indent("%%malloc.SizeU%(cnt)s = cast %(type_)s* %%malloc.Size%(cnt)s to uint" % locals())
-        self.indent("%%malloc.Ptr%(cnt)s = call fastcc sbyte* %%gc_malloc%(postfix)s(uint %%malloc.SizeU%(cnt)s)" % locals())
+        self.indent("%%malloc.Ptr%(cnt)s = call %(cconv)s sbyte* %%gc_malloc%(postfix)s(uint %%malloc.SizeU%(cnt)s)" % locals())
         self.indent("%(targetvar)s = cast sbyte* %%malloc.Ptr%(cnt)s to %(type_)s*" % locals())
 
     def getelementptr(self, targetvar, type, typevar, *indices):

Modified: pypy/dist/pypy/translator/llvm2/module/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/extfunction.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/extfunction.py	Thu Aug 18 14:38:38 2005
@@ -14,7 +14,7 @@
 
 ;XXX now trying to set only null terminator of varsize array for chars!
 ;    might need to clear the hash value of rpystrings too.
-;declare ccc sbyte* %memset(sbyte*, int, uint)
+declare ccc sbyte* %memset(sbyte*, int, uint)
 
 internal fastcc sbyte* %gc_malloc(uint %n) {
     %ptr = call ccc sbyte* %GC_malloc(uint %n)

Modified: pypy/dist/pypy/translator/llvm2/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/varsize.py	(original)
+++ pypy/dist/pypy/translator/llvm2/varsize.py	Thu Aug 18 14:38:38 2005
@@ -40,6 +40,9 @@
     codewriter.cast("%usize", elemtype + "*", "%size", "uint")
     codewriter.malloc("%ptr", "sbyte", "%usize", atomic=atomicmalloc)
     codewriter.cast("%result", "sbyte*", "%ptr", ref + "*")
+
+    if ARRAY is STR.chars:
+        codewriter.call('%memset_result', 'sbyte*', '%memset', ['%ptr', '0', '%usize',], ['sbyte*', 'int', 'uint'], cconv='ccc')
  
     indices_to_arraylength = tuple(indices_to_array) + (("uint", 0),)
     # the following accesses the length field of the array 
@@ -47,15 +50,15 @@
                              "%result", 
                              *indices_to_arraylength)
     codewriter.store(lentype, "%len", "%arraylength")
-
-    if ARRAY is STR.chars:
-        # NUL the last element
-        lastelemindices = list(indices_to_array) + [("uint", 1), (lentype, "%len")]
-        codewriter.getelementptr("%terminator",
-                                 ref + "*",
-                                 "%result", 
-                                 *lastelemindices)
-        codewriter.store(elemtype, 0, "%terminator")
+    
+    #if ARRAY is STR.chars: #(temp. disabled because we are moving memset from gc_malloc to here)
+    #    # NUL the last element 
+    #    #lastelemindices = list(indices_to_array) + [("uint", 1), (lentype, "%len")]
+    #    #codewriter.getelementptr("%terminator",
+    #    #                         ref + "*",
+    #    #                         "%result", 
+    #    #                         *lastelemindices)
+    #    #codewriter.store(elemtype, 0, "%terminator")
     
     codewriter.ret(ref + "*", "%result")
     codewriter.closefunc()



More information about the Pypy-commit mailing list