[pypy-svn] r50019 - in pypy/branch/llvmgcroot/pypy: rpython/lltypesystem rpython/memory/gctransform translator/llvm translator/llvm/module

arigo at codespeak.net arigo at codespeak.net
Sat Dec 22 21:34:13 CET 2007


Author: arigo
Date: Sat Dec 22 21:34:12 2007
New Revision: 50019

Modified:
   pypy/branch/llvmgcroot/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/llvmgcroot/pypy/rpython/memory/gctransform/llvmgcroot.py
   pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py
   pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py
   pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py
Log:
Use the "gcrootsingle" gc plugin.


Modified: pypy/branch/llvmgcroot/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/llvmgcroot/pypy/rpython/lltypesystem/lloperation.py	Sat Dec 22 21:34:12 2007
@@ -409,8 +409,9 @@
     'gc_x_become':          LLOp(canraise=(RuntimeError,), canunwindgc=True),
 
     # for llvm.gcroot() support.  can change at any time
-    'llvm_frameaddress':    LLOp(),
-    'llvm_gcmap_table':     LLOp(),
+    'llvm_frameaddress':    LLOp(sideeffects=False),
+    'llvm_gcmapstart':      LLOp(sideeffects=False),
+    'llvm_gcmapend':        LLOp(sideeffects=False),
     'llvm_store_gcroot':    LLOp(),
     'llvm_load_gcroot':     LLOp(),
 

Modified: pypy/branch/llvmgcroot/pypy/rpython/memory/gctransform/llvmgcroot.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/rpython/memory/gctransform/llvmgcroot.py	(original)
+++ pypy/branch/llvmgcroot/pypy/rpython/memory/gctransform/llvmgcroot.py	Sat Dec 22 21:34:12 2007
@@ -84,19 +84,16 @@
 
             def walk_to_parent_frame(self):
                 #
-                # XXX assumes a 32-bit machine for simplicity.
-                #
-                # The gcmap table is a list of pointers to gcmap_t
-                # structures, where the shape of each gcmap_t is:
-                #     struct {
-                #       int32_t FrameSize;
-                #       int32_t PointCount;
-                #       struct {
-                #         void *SafePointAddress;
-                #         int32_t LiveCount;
-                #         int32_t LiveOffsets[LiveCount];
-                #       } Points[PointCount];
-                #     } gcmap_t;
+                # The gcmap table is a list of pairs of pointers:
+                #     void *SafePointAddress;
+                #     void *Shape;
+                #
+                # A "safe point" is the return address of a call.
+                # The "shape" of a safe point records the size of the
+                # frame of the function containing it, as well as a
+                # list of the variables that contain gc roots at that
+                # time.  Each variable is described by its offset in
+                # the frame.
                 #
                 callee_frame = self.stack_current
                 #
@@ -126,35 +123,31 @@
                 # XXX this is just a linear scan for now, that's
                 # incredibly bad.
                 #
-                gcmaptbl = llop.llvm_gcmap_table(llmemory.Address)
-                i = 0
-                while True:
-                    gcmap = gcmaptbl.address[i]
-                    if not gcmap:              # function not found
-                        return False           # => assume end of stack
-                    framesize = gcmap.signed[0]
-                    pointcount = gcmap.signed[1]
-                    gcmap += 8
-                    j = 0
-                    while j < pointcount:
-                        safepointaddr = gcmap.address[0]
-                        livecount = gcmap.signed[1]
-                        if safepointaddr == retaddr:
-                            #
-                            # found!  Setup pointers allowing us to
-                            # parse the caller's frame structure...
-                            #
-                            caller_frame = callee_frame + 4 + framesize
-                            self.stack_current = caller_frame
-                            self.frame_data_base = callee_frame + 8
-                            self.remaining_roots_in_current_frame = livecount
-                            self.liveoffsets = gcmap + 8
-                            return True
-
-                        # not found
-                        gcmap += 8 + livecount * 4
-                        j += 1
-                    i += 1
+                gcmapstart = llop.llvm_gcmapstart(llmemory.Address)
+                gcmapend   = llop.llvm_gcmapend(llmemory.Address)
+                while gcmapstart != gcmapend:
+                    if gcmapstart.address[0] == retaddr:
+                        #
+                        # found!  Setup pointers allowing us to
+                        # parse the caller's frame structure...
+                        #
+                        shape = gcmapstart.address[1]
+                        # XXX assumes that .signed is 32-bit
+                        framesize = shape.signed[0]
+                        livecount = shape.signed[1]
+                        caller_frame = callee_frame + 4 + framesize
+                        self.stack_current = caller_frame
+                        self.frame_data_base = callee_frame + 8
+                        self.remaining_roots_in_current_frame = livecount
+                        self.liveoffsets = shape + 8
+                        return True
+
+                    gcmapstart += 2 * sizeofaddr
+
+                # retaddr not found.  Assume that this is the system function
+                # that called the original entry point, i.e. it's the end of
+                # the stack for us
+                return False
 
             def next_gcroot_from_current_frame(self):
                 i = self.remaining_roots_in_current_frame - 1

Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py	Sat Dec 22 21:34:12 2007
@@ -105,7 +105,6 @@
                 node.writeimpl(codewriter)
 
         self._debug(codewriter)
-        self.write_gcroot_table(codewriter)
         
         codewriter.comment("End of file")
         codewriter.close()
@@ -277,29 +276,3 @@
             print "Start"
             print self.db.dump_pbcs()
             print "End"
-
-    def write_gcroot_table(self, codewriter):
-        # Special support for llvm.gcroot
-        if self.config.translation.llvmgcroot:
-            from pypy.translator.llvm.funcnode import FuncImplNode
-            entries = []
-            for node in self.db.getnodes():
-                if isinstance(node, FuncImplNode):
-                    ref = node.ref
-                    assert ref.startswith('@')
-                    entries.append('@__gcmap_' + ref[1:])
-
-            codewriter.header_comment("The global gcmap table")
-            data = []
-            for entry in entries:
-                codewriter._append('%s = extern_weak constant i32' % entry)
-                data.append('i32* %s' % entry)
-            codewriter._append(
-                '@__gcmaptable1 = internal constant [%d x i32*] [ %s ]' %
-                (len(data), ", ".join(data)))
-            codewriter._append(
-                '@__gcmaptable = internal constant '
-                'i8* bitcast([%d x i32*]* @__gcmaptable1 to i8*)'
-                % len(data))
-            codewriter._append(
-                '@__gcmaptablelen = internal constant i32 %d' % len(data))

Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py	(original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py	Sat Dec 22 21:34:12 2007
@@ -37,5 +37,8 @@
 
 declare void @llvm.gcroot(i8**, i8*) nounwind
 declare i8* @llvm.frameaddress(i32) nounwind
+
+ at __gcmapstart = external constant i8*
+ at __gcmapend   = external constant i8*
 """
 

Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py	Sat Dec 22 21:34:12 2007
@@ -607,5 +607,8 @@
         self.codewriter.call(opr.retref, opr.rettype,
                              "@llvm.frameaddress", ['i32'], ['0'])
 
-    def llvm_gcmap_table(self, opr):
-        self.codewriter.load(opr.retref, opr.rettype, '@__gcmaptable')
+    def llvm_gcmapstart(self, opr):
+        self.codewriter.load(opr.retref, opr.rettype, '@__gcmapstart')
+
+    def llvm_gcmapend(self, opr):
+        self.codewriter.load(opr.retref, opr.rettype, '@__gcmapend')



More information about the Pypy-commit mailing list