[pypy-svn] r18101 - in pypy/dist/pypy/translator/llvm: . backendopt

ericvrp at codespeak.net ericvrp at codespeak.net
Mon Oct 3 13:36:33 CEST 2005


Author: ericvrp
Date: Mon Oct  3 13:36:31 2005
New Revision: 18101

Added:
   pypy/dist/pypy/translator/llvm/backendopt/support.py
Modified:
   pypy/dist/pypy/translator/llvm/backendopt/mergemallocs.py
   pypy/dist/pypy/translator/llvm/backendopt/removeexcmallocs.py
   pypy/dist/pypy/translator/llvm/build_llvm_module.py
   pypy/dist/pypy/translator/llvm/exception.py
   pypy/dist/pypy/translator/llvm/funcnode.py
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/llvm/varsize.py
Log:
using log instead of print.


Modified: pypy/dist/pypy/translator/llvm/backendopt/mergemallocs.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/backendopt/mergemallocs.py	(original)
+++ pypy/dist/pypy/translator/llvm/backendopt/mergemallocs.py	Mon Oct  3 13:36:31 2005
@@ -1,8 +1,9 @@
 from pypy.objspace.flow.model import Block, flatten, SpaceOperation, Constant, Variable
 from pypy.rpython.lltype import Struct, GcStruct, Void, Ptr
+from pypy.translator.llvm.backendopt.support import log
 
 
-def merge_mallocs(translator, graph):
+def merge_mallocs(translator, graph, ref):
     """Merge all mallocs of identical in a block into one.
     Thus all mallocs of atomic data are merged and all mallocs of
     non-atomic data are also merged into one. This reasoning behind this is
@@ -17,19 +18,19 @@
     for block in blocks:
         mallocs = [[], []]
         for i, op in enumerate(block.operations):
-            if op.opname == 'malloc' and op.args[0].value._arrayfld:
-                print 'merge_mallocs: skip varsize', op.args[0]
             if op.opname != 'malloc' or op.args[0].value._arrayfld:
                 continue
             is_atomic = op.args[0].value._is_atomic()
             mallocs[is_atomic].append( (i,op.args[0].value) )
 
+        n_operations_added = 0
         for a in range(2):
             if len(mallocs[a]) >= 2:
                 indices     = [m[0] for m in mallocs[a]]
                 gcstructs   = [m[1] for m in mallocs[a]]
                 merged_name = 'mergedstructs__' + '_'.join([s._name+str(n) for n, s in enumerate(gcstructs)])
 
+                #add malloc for mergedstruct
                 x = [(gcstruct._name+str(n), gcstruct) for n, gcstruct in enumerate(gcstructs)]
                 mergedstruct= GcStruct(merged_name, *x)
                 c = Constant(mergedstruct, Void)
@@ -37,16 +38,15 @@
                 ptr_merged.concretetype = Ptr(c.value)
                 merged_op  = SpaceOperation('malloc', [c], ptr_merged)
                 block.operations.insert(0, merged_op)
+                n_operations_added += 1
 
+                #replace old mallocs with getsubstruct of mergedstruct
                 for n, i in enumerate(indices):
-                    op = block.operations[i+1]
+                    op = block.operations[i + n_operations_added]
                     field = Constant(x[n][0], Void)
-                    block.operations[i+1] = SpaceOperation('getsubstruct', [ptr_merged, field], op.result)
+                    block.operations[i + n_operations_added] = SpaceOperation('getsubstruct', [ptr_merged, field], op.result)
 
-                for m in mallocs[a]:
-                    index, type_ = m
-                    print 'merge_malloc: OLD %d, %s' % (index, type(type_))
-                print 'merge_mallocs: NEW %s, %s' % (c, c.concretetype)
+                log.mergemallocs('%s in function %s' % (c, ref))
                 n_times_merged += 1
 
     return n_times_merged

Modified: pypy/dist/pypy/translator/llvm/backendopt/removeexcmallocs.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/backendopt/removeexcmallocs.py	(original)
+++ pypy/dist/pypy/translator/llvm/backendopt/removeexcmallocs.py	Mon Oct  3 13:36:31 2005
@@ -1,7 +1,8 @@
 from pypy.objspace.flow.model import Block, Constant, flatten
+from pypy.translator.llvm.backendopt.support import log
 
 
-def remove_exception_mallocs(translator, graph):
+def remove_exception_mallocs(translator, graph, ref):
     """Remove mallocs that occur because an exception is raised.
     Typically this data is shortlived and occuring often in highlevel
     languages like Python. So it would be preferable if we would not need
@@ -27,7 +28,8 @@
         name = str(ops[0].args[0])
         if 'Exception' not in name and 'Error' not in name: #XXX better to look at the actual structure
             continue
-        print 'remove_exception_malloc: ', name
+        log.removeexceptionmallocs('%s from function %s' % (name, ref))
         ops[0].opname = 'malloc_exception'  #XXX refactor later to not use a new operationtype
         n_removed += 1
+
     return n_removed

Added: pypy/dist/pypy/translator/llvm/backendopt/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/backendopt/support.py	Mon Oct  3 13:36:31 2005
@@ -0,0 +1,6 @@
+# logging
+
+import py
+from pypy.tool.ansi_print import ansi_log
+log = py.log.Producer("llvmbackendopt")
+py.log.setconsumer("llvmbackendopt", ansi_log)

Modified: pypy/dist/pypy/translator/llvm/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/build_llvm_module.py	(original)
+++ pypy/dist/pypy/translator/llvm/build_llvm_module.py	Mon Oct  3 13:36:31 2005
@@ -35,7 +35,6 @@
 #    flags.insert(flags.index("-inline")+1, "-heap2stack -debug")
 
 OPTIMIZATION_SWITCHES = " ".join(flags)
-#print OPTIMIZATION_SWITCHES
 
 def compile_module(module, source_files, object_files, library_files):
     open("%s_setup.py" % module, "w").write(str(py.code.Source(

Modified: pypy/dist/pypy/translator/llvm/exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/exception.py	(original)
+++ pypy/dist/pypy/translator/llvm/exception.py	Mon Oct  3 13:36:31 2005
@@ -46,7 +46,6 @@
         decl = node.getdecl()
         returntype, name = decl.split(' ', 1)
         noresult = self._noresult(returntype)
-        #print 'XXX decl=%s -> returntype=%s -> noresult=ret %s' % (decl, returntype, noresult)
         return noresult
 
     def new(exceptionpolicy=None):  #factory

Modified: pypy/dist/pypy/translator/llvm/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/funcnode.py	Mon Oct  3 13:36:31 2005
@@ -40,16 +40,10 @@
         self.value = value
         self.ref   = self.make_ref('%pypy_', value.graph.name)
         self.graph = value.graph
+
         self.db.genllvm.exceptionpolicy.transform(self.db.translator, self.graph)
-        if remove_exception_mallocs(self.db.translator, self.graph):
-            print '            from function', self.ref
-            sys.stdout.flush()
-            #if self.ref not in ('%pypy_ll_raise_OSError__Signed', '%pypy_getitem'):
-            #    self.db.translator.view()
-        #if merge_mallocs(self.db.translator, self.graph):
-        #    print '            in function', self.ref
-        #    sys.stdout.flush()
-        #    #self.db.translator.view()
+        remove_exception_mallocs(self.db.translator, self.graph, self.ref)
+        #merge_mallocs(self.db.translator, self.graph, self.ref)
 
         remove_double_links(self.db.translator, self.graph)
 

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Mon Oct  3 13:36:31 2005
@@ -8,7 +8,6 @@
 from pypy.translator.llvm import build_llvm_module
 from pypy.translator.llvm.database import Database 
 from pypy.translator.llvm.pyxwrapper import write_pyx_wrapper 
-from pypy.translator.llvm.log import log
 from pypy.rpython.rmodel import inputconst, getfunctionptr
 from pypy.rpython import lltype
 from pypy.tool.udir import udir
@@ -24,6 +23,9 @@
 from pypy.translator.llvm.exception import ExceptionPolicy
 from pypy.translator.translator import Translator
 
+from pypy.tool.ansi_print import ansi_log
+log = py.log.Producer("llvm")
+log.setconsumer("llvm", ansi_log)
 
 function_count = {}
 llexterns_header = llexterns_functions = None
@@ -48,9 +50,9 @@
         if self.debug:
             if msg:
                 t = (time.time() - self.starttime)
-                print '\t%s took %02dm%02ds' % (msg, t/60, t%60)
+                log('\t%s took %02dm%02ds' % (msg, t/60, t%60))
             else:
-                print 'GenLLVM:'
+                log('GenLLVM:')
             self.starttime = time.time()
 
     def _print_node_stats(self):
@@ -85,7 +87,7 @@
         stats = [(count, str(typ)) for typ, count in nodecount.iteritems()]
         stats.sort()
         for s in stats:
-            print 'STATS', s
+            log('STATS %s' % str(s))
 
     def gen_llvm_source(self, func=None):
         """
@@ -245,7 +247,7 @@
     gen = GenLLVM(translator, GcPolicy.new(gcpolicy), ExceptionPolicy.new(exceptionpolicy))
     filename = gen.gen_llvm_source()
     if log_source:
-        log.genllvm(open(filename).read())
+        log(open(filename).read())
     return gen.create_module(filename, **kwds)
 
 def compile_module(function, annotation, view=False, **kwds):

Modified: pypy/dist/pypy/translator/llvm/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/varsize.py	(original)
+++ pypy/dist/pypy/translator/llvm/varsize.py	Mon Oct  3 13:36:31 2005
@@ -26,12 +26,6 @@
     codewriter.malloc("%ptr", "sbyte", "%usize", atomic=ARRAY._is_atomic())
     codewriter.cast("%result", "sbyte*", "%ptr", ref + "*")
 
-    if ARRAY is STR.chars:
-        #XXX instead of memset we could probably just zero the hash and string terminator
-        codewriter.call('%dummy', 'void', '%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
-    else:
-        codewriter.call('%dummy', 'void', '%llvm.memset', ['%ptr', '0', '%usize', '0'], ['sbyte*', 'ubyte', 'uint', 'uint'], cconv='ccc')
-
     indices_to_arraylength = tuple(indices_to_array) + (("uint", 0),)
     # the following accesses the length field of the array 
     codewriter.getelementptr("%arraylength", ref + "*", 



More information about the Pypy-commit mailing list