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

ericvrp at codespeak.net ericvrp at codespeak.net
Mon Aug 22 14:05:56 CEST 2005


Author: ericvrp
Date: Mon Aug 22 14:05:55 2005
New Revision: 16195

Modified:
   pypy/dist/pypy/translator/llvm2/codewriter.py
   pypy/dist/pypy/translator/llvm2/module/extfunction.py
   pypy/dist/pypy/translator/llvm2/module/support.py
Log:
* adding tail tag to calls, since we are not using alloca at all at the moment.

* cleaning up




Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Mon Aug 22 14:05:55 2005
@@ -4,6 +4,9 @@
 
 log = log.codewriter 
 
+DEFAULT_TAIL  = 'tail'      #or ''
+DEFAULT_CCONV = 'fastcc'    #or 'ccc'
+
 class CodeWriter(object): 
     def __init__(self, f, show_line_number=False): 
         self.f = f
@@ -46,7 +49,7 @@
         self.append("%s = type %s (%s)" % (name, rettyperepr,
                                            ", ".join(argtypereprs)))
 
-    def declare(self, decl, cconv='fastcc'):
+    def declare(self, decl, cconv=DEFAULT_CCONV):
         self.append("declare %s %s" %(cconv, decl,))
 
     def startimpl(self):
@@ -68,7 +71,7 @@
         self.indent("switch %s %s, label %%%s [%s ]"
                     % (intty, cond, defaultdest, labels))
 
-    def openfunc(self, decl, is_entrynode=False, cconv='fastcc'): 
+    def openfunc(self, decl, is_entrynode=False, cconv=DEFAULT_CCONV): 
         self.malloc_count = count(0).next
         self.newline()
         if is_entrynode:
@@ -104,21 +107,30 @@
     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, cconv='fastcc'):
+    #from: http://llvm.cs.uiuc.edu/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. 
+    def call(self, targetvar, returntype, functionref, argrefs, argtypes, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
+        if cconv is not 'fastcc':
+            tail = ''
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("%s = call %s %s %s(%s)" % (targetvar, cconv, returntype, functionref,
+        self.indent("%s = %s call %s %s %s(%s)" % (targetvar, tail, cconv, returntype, functionref,
                                              ", ".join(arglist)))
 
-    def call_void(self, functionref, argrefs, argtypes, cconv='fastcc'):
+    def call_void(self, functionref, argrefs, argtypes, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
+        if cconv is not 'fastcc':
+            tail = ''
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
-        self.indent("call %s void %s(%s)" % (cconv, functionref, ", ".join(arglist)))
+        self.indent("%s call %s void %s(%s)" % (tail, cconv, functionref, ", ".join(arglist)))
 
-    def invoke(self, targetvar, returntype, functionref, argrefs, argtypes, label, except_label, cconv='fastcc'):
+    def invoke(self, targetvar, returntype, functionref, argrefs, argtypes, label, except_label, cconv=DEFAULT_CCONV):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
         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, cconv='fastcc'):
+    def invoke_void(self, functionref, argrefs, argtypes, label, except_label, cconv=DEFAULT_CCONV):
         arglist = ["%s %s" % item for item in zip(argtypes, argrefs)]
         self.indent("invoke %s void %s(%s) to label %%%s except label %%%s" % (cconv, functionref, ", ".join(arglist), label, except_label))
 
@@ -126,7 +138,7 @@
         self.indent("%(targetvar)s = cast %(fromtype)s "
                         "%(fromvar)s to %(targettype)s" % locals())
 
-    def malloc(self, targetvar, type_, size=1, atomic=False, cconv='fastcc'):
+    def malloc(self, targetvar, type_, size=1, atomic=False, cconv=DEFAULT_CCONV):
         n = self.malloc_count()
         if n:
             cnt = ".%d" % n

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	Mon Aug 22 14:05:55 2005
@@ -12,19 +12,13 @@
 gc_boehm = """declare ccc sbyte* %GC_malloc(uint)
 declare ccc sbyte* %GC_malloc_atomic(uint)
 
-;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)
-
 internal fastcc sbyte* %gc_malloc(uint %n) {
     %ptr = call ccc sbyte* %GC_malloc(uint %n)
-    ;call ccc sbyte* %memset(sbyte* %ptr, int 0, uint %n)
     ret sbyte* %ptr
 }
 
 internal fastcc sbyte* %gc_malloc_atomic(uint %n) {
     %ptr = call ccc sbyte* %GC_malloc_atomic(uint %n)
-    ;call ccc sbyte* %memset(sbyte* %ptr, int 0, uint %n)
     ret sbyte* %ptr
 }
 """

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	Mon Aug 22 14:05:55 2005
@@ -4,6 +4,7 @@
 declare ccc int %puts(sbyte*)
 declare ccc int %strlen(sbyte*)
 declare ccc int %strcmp(sbyte*, sbyte*)
+declare ccc sbyte* %memset(sbyte*, int, uint)
 
 %__print_debug_info         = internal global bool false
 %__print_debug_info_option  = internal constant [19 x sbyte] c"--print-debug-info\\00"



More information about the Pypy-commit mailing list