[pypy-svn] r33882 - in pypy/dist/pypy/jit/codegen: . i386 llgraph ppc

mwh at codespeak.net mwh at codespeak.net
Mon Oct 30 14:36:04 CET 2006


Author: mwh
Date: Mon Oct 30 14:36:03 2006
New Revision: 33882

Modified:
   pypy/dist/pypy/jit/codegen/i386/rgenop.py
   pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
   pypy/dist/pypy/jit/codegen/model.py
   pypy/dist/pypy/jit/codegen/ppc/rgenop.py
Log:
(arigo, mwh)
more docstrings and a little light renaming of classes.


Modified: pypy/dist/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/rgenop.py	Mon Oct 30 14:36:03 2006
@@ -3,7 +3,7 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.jit.codegen.i386.ri386 import *
 from pypy.jit.codegen.i386.codebuf import InMemoryCodeBuilder, CodeBlockOverflow
-from pypy.jit.codegen.model import AbstractRGenOp, CodeGenBlock, CodeGenerator
+from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
 from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
 from pypy.rpython import objectmodel
 from pypy.rpython.annlowlevel import llhelper
@@ -137,7 +137,7 @@
         return "const=<0x%x>" % (llmemory.cast_adr_to_int(self.addr),)
 
 
-class Block(CodeGenBlock):
+class Label(GenLabel):
 
     def __init__(self, startaddr, arg_positions, stackdepth):
         self.startaddr = startaddr
@@ -216,7 +216,7 @@
         mc.done()
         return targetbuilder
 
-class Builder(CodeGenerator):
+class Builder(GenBuilder):
 
     def __init__(self, rgenop, mc, stackdepth):
         self.rgenop = rgenop
@@ -375,7 +375,7 @@
             # remember the var's position in the stack
             arg_positions.append(gv.stackpos)
             seen[gv.stackpos] = None
-        return Block(self.mc.tell(), arg_positions, self.stackdepth)
+        return Label(self.mc.tell(), arg_positions, self.stackdepth)
 
     def jump_if_false(self, gv_condition):
         targetbuilder = self._fork()
@@ -397,9 +397,9 @@
         self.mc.RET()
         self._close()
 
-    def finish_and_goto(self, outputargs_gv, targetblock):
-        remap_stack_layout(self, outputargs_gv, targetblock)
-        self.mc.JMP(rel32(targetblock.startaddr))
+    def finish_and_goto(self, outputargs_gv, target):
+        remap_stack_layout(self, outputargs_gv, target)
+        self.mc.JMP(rel32(target.startaddr))
         self._close()
 
     def flexswitch(self, gv_exitswitch):
@@ -688,24 +688,24 @@
 
 # ____________________________________________________________
 
-def remap_stack_layout(builder, outputargs_gv, targetblock):
+def remap_stack_layout(builder, outputargs_gv, target):
 ##    import os
 ##    s = ', '.join([gv.repr() for gv in outputargs_gv])
 ##    os.write(2, "writing at %d (stack=%d, [%s])\n  --> %d (stack=%d, %s)\n"
 ##     % (builder.mc.tell(),
 ##        builder.stackdepth,
 ##        s,
-##        targetblock.startaddr,
-##        targetblock.stackdepth,
-##        targetblock.arg_positions))
+##        target.startaddr,
+##        target.stackdepth,
+##        target.arg_positions))
 
-    N = targetblock.stackdepth
+    N = target.stackdepth
     if builder.stackdepth < N:
         builder.mc.SUB(esp, imm(WORD * (N - builder.stackdepth)))
         builder.stackdepth = N
 
     M = len(outputargs_gv)
-    arg_positions = targetblock.arg_positions
+    arg_positions = target.arg_positions
     assert M == len(arg_positions)
     targetlayout = [None] * N
     srccount = [-N] * N
@@ -784,7 +784,7 @@
     def add_default(self):
         return self.replay_builder
 
-class ReplayBuilder(CodeGenerator):
+class ReplayBuilder(GenBuilder):
 
     def __init__(self, rgenop):
         self.rgenop = rgenop
@@ -842,7 +842,7 @@
     def finish_and_return(self, sigtoken, gv_returnvar):
         pass
 
-    def finish_and_goto(self, outputargs_gv, targetblock):
+    def finish_and_goto(self, outputargs_gv, target):
         pass
 
     def flexswitch(self, gv_exitswitch):
@@ -883,7 +883,7 @@
         inputargs_gv = builder._write_prologue(sigtoken)
         return builder, entrypoint, inputargs_gv
 
-    def replay(self, block, kinds):
+    def replay(self, label, kinds):
         return ReplayBuilder(self), [dummy_var] * len(kinds)
 
     @specialize.genconst(1)

Modified: pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	Mon Oct 30 14:36:03 2006
@@ -1,6 +1,6 @@
 from pypy.rpython.objectmodel import specialize
 from pypy.rpython.lltypesystem import lltype
-from pypy.jit.codegen.model import AbstractRGenOp, CodeGenBlock, CodeGenerator
+from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
 from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
 from pypy.jit.codegen.llgraph import llimpl
 from pypy.rpython.lltypesystem.rclass import fishllattr
@@ -29,7 +29,7 @@
 gv_dummy_placeholder = LLConst(llimpl.dummy_placeholder)
 
 
-class LLBlock(CodeGenBlock):
+class LLLabel(GenLabel):
     def __init__(self, b, g):
         self.b = b
         self.g = g
@@ -54,7 +54,7 @@
         builder.lnk = l_default
         return builder
 
-class LLBuilder(CodeGenerator):
+class LLBuilder(GenBuilder):
     lnk = llimpl.nulllink
 
     def __init__(self, g):
@@ -140,12 +140,12 @@
         llimpl.closelink(lnk, args_gv, self.b)
         for i in range(len(args_gv)):
             args_gv[i] = newb_args_gv[i]
-        return LLBlock(self.b, self.g)
+        return LLLabel(self.b, self.g)
 
-    def finish_and_goto(self, args_gv, targetblock):
+    def finish_and_goto(self, args_gv, target):
         lnk = self.lnk or llimpl.closeblock1(self.b)
         self.lnk = llimpl.nulllink
-        llimpl.closelink(lnk, args_gv, targetblock.b)
+        llimpl.closelink(lnk, args_gv, target.b)
 
     def finish_and_return(self, sigtoken, gv_returnvar):
         gv_returnvar = gv_returnvar or gv_dummy_placeholder
@@ -243,8 +243,8 @@
 
     constPrebuiltGlobal = genconst
 
-    def replay(self, block, kinds):
-        builder = LLBuilder(block.g)
+    def replay(self, label, kinds):
+        builder = LLBuilder(label.g)
         args_gv = builder._newblock(kinds)
         return builder, args_gv
 

Modified: pypy/dist/pypy/jit/codegen/model.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/model.py	(original)
+++ pypy/dist/pypy/jit/codegen/model.py	Mon Oct 30 14:36:03 2006
@@ -39,12 +39,17 @@
 # allocToken, varsizeAllocToken, kindToken and sigToken.  See their
 # docstrings for more.
 
-class CodeGenerator(object):
-
-    '''Instances of CodeGenerator are responsible for actually
-    generating machine code.  One instance is responsible for one
-    chunk of memory, and when it is filled or the generated code jumps
-    away the code generator is thrown away.'''
+# as they are memo-specialized, these methods can be full Python
+# inside, but each method must always return the same type so the jit
+# can store the results in a list, for example (each backend can
+# decide what this type is independently, though)
+
+class GenBuilder(object):
+    '''Instances of GenBuilder -- generally referred to as "builders"
+    -- are responsible for actually generating machine code.  One
+    instance is responsible for one chunk of memory, and when it is
+    filled or the generated code jumps away the builder is
+    thrown away.'''
 
     # the genop methods should emit the machine code for a single llop.
     # for most llops, the genop1 and genop2 methods suffice, but some
@@ -87,33 +92,32 @@
         different locations (registers, places on the stack) in
         different basic blocks.
 
-        Returns an instance of CodeGenBlock that serves as a label
-        that can later be jumped to.
+        Returns an instance of GenLabel that can later be jumped to.
         '''
 
     def jump_if_false(self, gv_condition):
-        '''Make a fresh CodeGenerator, insert in the current block a
+        '''Make a fresh builder, insert in the current block a
         check of gv_condition and a conditional jump to the new block
         that is taken if gv_condition is false and return the new
-        CodeGenerator.'''
+        builder.'''
 
     def jump_if_true(self, gv_condition):
         '''See above, with the obvious difference :)'''
 
     def finish_and_return(self, sigtoken, gv_returnvar):
         '''Emit the epilogue code for the function, and the code to
-        return gv_returnvar.  This "closes" the current CodeGenerator.'''
+        return gv_returnvar.  This "closes" the current builder.'''
 
-    def finish_and_goto(self, outputargs_gv, targetblock):
-        '''Insert an unconditional jump to targetblock.
+    def finish_and_goto(self, outputargs_gv, target):
+        '''Insert an unconditional jump to target.
 
         outputargs_gv is a list of GenVarOrConsts which corresponds to Link.args
-        targetblock is an instance of CodeGenBlock.
+        target is an instance of GenLabel.
 
         This must insert code to make sure that the values in
-        outputargs_gv go where the targetblock expects them to be.
+        outputargs_gv go where the target block expects them to be.
 
-        This "closes" the current CodeGenerator.
+        This "closes" the current builder.
         '''
 
     def flexswitch(self, gv_exitswitch):
@@ -125,7 +129,7 @@
 
         Returns an instance of CodeGenSwitch, see below.
 
-        This "closes" the current CodeGenerator.
+        This "closes" the current builder.
         '''
 
     def show_incremental_progress(self):
@@ -134,7 +138,7 @@
         So far, the machine code backends don\'t actually do anything for this.
         '''
 
-class CodeGenBlock(object):
+class GenLabel(object):
     '''A "smart" label.  Represents an address of the start of a basic
     block and the location of the inputargs on entry to that block.'''
 
@@ -150,31 +154,54 @@
 
     def newgraph(self, sigtoken):
         """Begin code generation for a new function, which signature
-        described by sigtoken.  Returns builder, entrypoint,
-        inputargs_gv where builder is an instance of CodeGenerator,
+        described by sigtoken.  Returns a new builder, entrypoint,
+        inputargs_gv where the new builder is for the startblock,
         entrypoint is the address of the new function and inputargs_gv
         is the location of each argument on entry to the function."""
 
     # all staticmethods commented out for the sake of the annotator
 
-   #@staticmethod
     #@specialize.genconst(0)
-    #def genconst(llvalue):
-    #    """Convert an llvalue to an instance of (a subclass of) GenConst."""
-    #    raise NotImplementedError
-
-    #constPrebuiltGlobal = genconst
-
-    #def gencallableconst(self, sigtoken, name, entrypointaddr):
-    #    """"""
+    #def genconst(self, llvalue):
+    #    """Convert an llvalue to an instance of (a subclass of)
+    #    GenConst.  The difference between this and
+    #    constPrebuiltGlobal is that this method can use storage
+    #    associated with the current RGenOp, i.e. self.  If self is
+    #    thrown away, it's safe for anything that this method has
+    #    returned to disappear too."""
     #    raise NotImplementedError
 
-    # the "token" methods render non-RPython data structures
-    # (instances of LowLevelType) into RPython data structures.  they
-    # are memo-specialized, so they can be full Python inside, but
-    # each method must always return the same type, so the jit can
-    # store the results in a list, for example (each backend can
-    # decide what this type is independently, though)
+    #@staticmethod
+    #@specialize.genconst(0)
+    #def constPrebuiltGlobal(llvalue):
+    #    """Convert an llvalue to an instance of (a subclass of) GenConst.
+    #    This is for immortal prebuilt data."""
+    #    raise NotImplementedError
+
+    #def gencallableconst(self, sigtoken, name, entrypoint):
+    #    """Returns a GenConst that contains a function pointer.  This
+    #    might be the time to do some further optimization of the
+    #    generated code.
+    #
+    #    sigtoken describes the signature, name is for debugging
+    #    purposes and entrypoint is what was returned from
+    #    newgraph."""
+    #    raise NotImplementedError
+
+    def replay(self, label, kinds):
+        '''Return a builder that will "generate" exactly the same code
+        as was already generated, starting from label.  kinds is a
+        list of kindTokens for the inputargs associated with label.
+
+        The purpose of this is to reconstruct the knowledge of the
+        locations of the GenVars at some later point in the code, any
+        code actually generated during replaying is thrown away.'''
+
+    #@staticmethod
+    #def erasedType(T):
+    #    '''Return the canonical type T2 such that kindToken(T) == kindToken(T2).
+    #    For example, it\'s common to erase all Ptrs to llmemory.GCREF.
+    #    '''
 
     #@staticmethod
     #@specialize.memo()
@@ -225,10 +252,10 @@
     to it "later", i.e. after it has been executed a few times.'''
 
     def add_case(self, gv_case):
-        '''Make a new CodeGenerator that will be jumped to when the
+        '''Make a new builder that will be jumped to when the
         switched-on GenVar takes the value of the GenConst gv_case.'''
 
     def add_default(self):
-        '''Make a new CodeGenerator that will be jumped to when the
+        '''Make a new builder that will be jumped to when the
         switched-on GenVar does not take the value of any case.'''
 

Modified: pypy/dist/pypy/jit/codegen/ppc/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/rgenop.py	Mon Oct 30 14:36:03 2006
@@ -1,4 +1,4 @@
-from pypy.jit.codegen.model import AbstractRGenOp, CodeGenBlock, CodeGenerator
+from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
 from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.objectmodel import specialize, we_are_translated
@@ -98,15 +98,15 @@
     self.mc.write(value)
 RPPCAssembler.emit = emit
 
-def prepare_for_jump(builder, outputargs_gv, targetblock):
-    assert len(targetblock.arg_locations) == len(outputargs_gv)
+def prepare_for_jump(builder, outputargs_gv, target):
+    assert len(target.arg_locations) == len(outputargs_gv)
     outregs = []
     targetregs = []
     for gv in outputargs_gv:
         assert isinstance(gv, Var)
         assert isinstance(gv.location, RegisterLocation)
         outregs.append(gv.location.reg)
-    for loc in targetblock.arg_locations:
+    for loc in target.arg_locations:
         assert isinstance(loc, RegisterLocation)
         targetregs.append(loc.reg)
     for i in range(len(outregs)):
@@ -154,7 +154,7 @@
 
 ## binaryfn = CFUNCTYPE(c_int, c_int, c_int)    # for testing
 
-class Block(CodeGenBlock):
+class Label(GenLabel):
 
     def __init__(self, startaddr, arg_locations):
         self.startaddr = startaddr
@@ -195,7 +195,7 @@
 ##     def add_case(self, gv_case):
 ##     def add_default(self):
 
-class Builder(CodeGenerator):
+class Builder(GenBuilder):
 
     def __init__(self, rgenop, mc, parent):
         self.rgenop = rgenop
@@ -227,10 +227,10 @@
         self.asm.blr()
         self._close()
 
-    def finish_and_goto(self, outputargs_gv, targetblock):
-        prepare_for_jump(self, outputargs_gv, targetblock)
+    def finish_and_goto(self, outputargs_gv, target):
+        prepare_for_jump(self, outputargs_gv, target)
         gv = self.newvar()
-        self.asm.load_word(gv.reg(), targetblock.startaddr)
+        self.asm.load_word(gv.reg(), target.startaddr)
         self.asm.mtctr(gv.reg())
         self.asm.bctr()
         self._close()
@@ -255,7 +255,7 @@
             # remember the var's location
             arg_locations.append(gv.location)
             seen[gv.location] = None
-        return Block(self.asm.mc.tell(), arg_locations)
+        return Label(self.asm.mc.tell(), arg_locations)
 
     def newvar(self):
         d = self.curreg



More information about the Pypy-commit mailing list