[pypy-svn] r67456 - pypy/branch/no-recompilation/pypy/jit/backend/x86

fijal at codespeak.net fijal at codespeak.net
Thu Sep 3 19:12:25 CEST 2009


Author: fijal
Date: Thu Sep  3 19:12:24 2009
New Revision: 67456

Modified:
   pypy/branch/no-recompilation/pypy/jit/backend/x86/assembler.py
   pypy/branch/no-recompilation/pypy/jit/backend/x86/regalloc.py
   pypy/branch/no-recompilation/pypy/jit/backend/x86/runner.py
Log:
this is enough to make test_recompilation pass. Although test_recompilation
needs adaptation as not always we really overflow the number of registers


Modified: pypy/branch/no-recompilation/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/no-recompilation/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/no-recompilation/pypy/jit/backend/x86/assembler.py	Thu Sep  3 19:12:24 2009
@@ -15,9 +15,13 @@
 from pypy.jit.backend.x86.ri386 import *
 from pypy.jit.metainterp.resoperation import rop
 
+
+
 # our calling convention - we pass first 6 args in registers
 # and the rest stays on the stack
 
+RET_BP = 5 # ret ip + bp + bx + esi + edi = 5 words
+
 MAX_FAIL_BOXES = 1000
 if sys.platform == 'darwin':
     # darwin requires the stack to be 16 bytes aligned on calls
@@ -165,20 +169,17 @@
             inputargs = tree.inputargs
             self.logger.log_loop(tree)
             regalloc.walk_operations(tree)
-            stack_words = regalloc.max_stack_depth
         else:
             inputargs = regalloc.inputargs
             self.logger.log_operations
             mc = self.mc._mc
-            adr_sub = mc.tell()
-            mc.SUB(esp, imm32(0))
+            adr_lea = mc.tell()
+            mc.LEA(esp, addr_add(imm32(0), ebp, 0))
             regalloc._walk_operations(operations)
-            stack_words = max(regalloc.max_stack_depth,
-                              tree._x86_stack_depth)
+        stack_words = regalloc.max_stack_depth
         self.mc.done()
         self.mc2.done()
         # possibly align, e.g. for Mac OS X
-        RET_BP = 5 # ret ip + bp + bx + esi + edi = 5 words
         stack_words = align_stack_words(stack_words + RET_BP)
         stack_depth = stack_words - RET_BP
         if guard_op is None:
@@ -186,9 +187,9 @@
         else:
             guard_op._x86_stack_depth = stack_words
             if stack_words - RET_BP != tree._x86_stack_depth:
-                mc = codebuf.InMemoryCodeBuilder(adr_sub, adr_sub + 128)
-                mc.SUB(esp, imm32((stack_words - RET_BP -
-                                   tree._x86_stack_depth) * WORD))
+                mc = codebuf.InMemoryCodeBuilder(adr_lea, adr_lea + 128)
+                mc.LEA(esp, addr_add(imm32(0), ebp,
+                                  -(stack_words - 1) * WORD))
                 mc.done()
         if we_are_translated():
             self._regalloc = None   # else keep it around for debugging
@@ -617,7 +618,6 @@
         targetmp = op.jump_target
         # don't break the following code sequence!
         mc = self.mc._mc
-        #mc.SUB(esp, targetmp._x86_compiled - xxx)
         mc.JMP(rel32(targetmp._x86_compiled))
 
     def genop_guard_guard_true(self, op, ign_1, addr, locs, ign_2):
@@ -698,7 +698,7 @@
             self.generate_exception_handling(mc, eax)
         # don't break the following code sequence!
         mc = mc._mc
-        mc.LEA(esp, addr_add(imm(0), ebp, -3 * WORD))
+        mc.LEA(esp, addr_add(imm(0), ebp, (-RET_BP + 2) * WORD))
         guard_index = self.cpu.make_guard_index(op)
         mc.MOV(eax, imm(guard_index))
         mc.POP(edi)

Modified: pypy/branch/no-recompilation/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/no-recompilation/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/no-recompilation/pypy/jit/backend/x86/regalloc.py	Thu Sep  3 19:12:24 2009
@@ -83,6 +83,11 @@
             self.free_regs = REGS[:]
 
     def _update_bindings(self, locs, args):
+        newlocs = []
+        for loc in locs:
+            if not isinstance(loc, IMM8) and not isinstance(loc, IMM32):
+                newlocs.append(loc)
+        locs = newlocs
         assert len(locs) == len(args)
         used = {}
         for i in range(len(locs)):
@@ -211,7 +216,8 @@
             i += 1
         assert not self.reg_bindings
         jmp = operations[-1]
-        self.max_stack_depth = self.current_stack_depth
+        self.max_stack_depth = max(self.current_stack_depth,
+                                   self.max_stack_depth)
 
     def _compute_vars_longevity(self, inputargs, operations):
         # compute a dictionary that maps variables to index in
@@ -923,6 +929,7 @@
                                            dst_locations, tmploc)
         self.eventually_free_var(box)
         self.eventually_free_vars(op.args)
+        self.max_stack_depth = op.jump_target._x86_stack_depth    
         self.PerformDiscard(op, [])
 
     def consider_debug_merge_point(self, op, ignored):

Modified: pypy/branch/no-recompilation/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/no-recompilation/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/no-recompilation/pypy/jit/backend/x86/runner.py	Thu Sep  3 19:12:24 2009
@@ -10,7 +10,7 @@
 
 history.TreeLoop._x86_compiled = 0
 history.TreeLoop._x86_bootstrap_code = 0
-
+history.TreeLoop._x86_stack_depth = 0
 
 class CPU386(AbstractLLCPU):
     debug = True



More information about the Pypy-commit mailing list