[pypy-commit] pypy resume-refactor: shuffle stuff around

fijal noreply at buildbot.pypy.org
Sun Jan 12 15:56:53 CET 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: resume-refactor
Changeset: r68615:19684fcbfad9
Date: 2014-01-12 15:04 +0100
http://bitbucket.org/pypy/pypy/changeset/19684fcbfad9/

Log:	shuffle stuff around

diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -1,7 +1,7 @@
 import py, weakref
 from rpython.jit.backend import model
 from rpython.jit.backend.llgraph import support
-from rpython.jit.backend.llsupport.resumebuilder import ResumeBuilder,\
+from rpython.jit.backend.resumebuilder import ResumeBuilder,\
      LivenessAnalyzer
 from rpython.jit.metainterp.history import AbstractDescr
 from rpython.jit.metainterp.history import Const, getkind
diff --git a/rpython/jit/backend/llsupport/regalloc.py b/rpython/jit/backend/llsupport/regalloc.py
--- a/rpython/jit/backend/llsupport/regalloc.py
+++ b/rpython/jit/backend/llsupport/regalloc.py
@@ -2,7 +2,7 @@
 from rpython.jit.metainterp.history import Const, Box, REF, JitCellToken
 from rpython.rlib.objectmodel import we_are_translated, specialize
 from rpython.jit.metainterp.resoperation import rop
-from rpython.jit.backend.llsupport.resumebuilder import LivenessAnalyzer
+
 
 try:
     from collections import OrderedDict
@@ -691,83 +691,6 @@
         else:
             return [self.loc(op.getarg(0))]
 
-def flatten(inputframes):
-    count = 0
-    for frame in inputframes:
-        count += len(frame)
-    inputargs = [None] * count
-    i = 0
-    for frame in inputframes:
-        inputargs[i:i + len(frame)] = frame
-        i += len(frame)
-    return inputargs
-
-def compute_vars_longevity(inputframes, operations, descr=None):
-    # compute a dictionary that maps variables to index in
-    # operations that is a "last-time-seen"
-
-    # returns a pair longevity/useful. Non-useful variables are ones that
-    # never appear in the assembler or it does not matter if they appear on
-    # stack or in registers. Main example is loop arguments that go
-    # only to guard operations or to jump or to finish
-    produced = {}
-    last_used = {}
-    last_real_usage = {}
-    frontend_alive = {}
-    if descr is None:
-        inputargs = inputframes[0]
-        liveness_analyzer = LivenessAnalyzer()
-    else:
-        inputargs = flatten(inputframes)
-        liveness_analyzer = LivenessAnalyzer(inputframes)
-    start_pos = 0
-    for position, op in enumerate(operations):
-        if op.is_guard():
-            liveness_analyzer.interpret_until(operations, position, start_pos)
-            start_pos = position
-            framestack = liveness_analyzer.get_live_info()
-            for frame in framestack:
-                for item in liveness_analyzer.all_boxes_from(frame):
-                    if item is not None:
-                        last_used[item] = position
-                        frontend_alive[item] = position
-
-    for i in range(len(operations)-1, -1, -1):
-        op = operations[i]
-        if op.result:
-            if op.result not in last_used and op.has_no_side_effect():
-                continue
-            assert op.result not in produced
-            produced[op.result] = i
-        opnum = op.getopnum()
-        for j in range(op.numargs()):
-            arg = op.getarg(j)
-            if not isinstance(arg, Box):
-                continue
-            if arg not in last_used:
-                last_used[arg] = i
-            else:
-                last_used[arg] = max(last_used[arg], i)
-            if opnum != rop.JUMP and opnum != rop.LABEL:
-                if arg not in last_real_usage:
-                    last_real_usage[arg] = i
-    #
-    longevity = {}
-    for arg in produced:
-        if arg in last_used:
-            assert isinstance(arg, Box)
-            assert produced[arg] < last_used[arg]
-            longevity[arg] = (produced[arg], last_used[arg])
-            del last_used[arg]
-    for arg in inputargs:
-        assert isinstance(arg, Box)
-        if arg not in last_used:
-            longevity[arg] = (-1, -1)
-        else:
-            longevity[arg] = (0, last_used[arg])
-            del last_used[arg]
-    assert len(last_used) == 0
-    return longevity, last_real_usage, frontend_alive
 
 def is_comparison_or_ovf_op(opnum):
     from rpython.jit.metainterp.resoperation import opclasses
diff --git a/rpython/jit/backend/llsupport/resumebuilder.py b/rpython/jit/backend/resumebuilder.py
rename from rpython/jit/backend/llsupport/resumebuilder.py
rename to rpython/jit/backend/resumebuilder.py
--- a/rpython/jit/backend/llsupport/resumebuilder.py
+++ b/rpython/jit/backend/resumebuilder.py
@@ -1,6 +1,6 @@
 
 from rpython.jit.metainterp.resoperation import rop, ResOperation
-from rpython.jit.metainterp.history import ConstInt
+from rpython.jit.metainterp.history import ConstInt, Box
 from rpython.jit.metainterp.resume2 import ResumeBytecode, AbstractResumeReader
 
 class LivenessAnalyzer(AbstractResumeReader):
@@ -121,3 +121,82 @@
     def finish(self, parent, parent_position, clt):
         return ResumeBytecode(self.newops, parent, parent_position, clt)
 
+
+def flatten(inputframes):
+    count = 0
+    for frame in inputframes:
+        count += len(frame)
+    inputargs = [None] * count
+    i = 0
+    for frame in inputframes:
+        inputargs[i:i + len(frame)] = frame
+        i += len(frame)
+    return inputargs
+
+
+def compute_vars_longevity(inputframes, operations, descr=None):
+    # compute a dictionary that maps variables to index in
+    # operations that is a "last-time-seen"
+
+    # returns a pair longevity/useful. Non-useful variables are ones that
+    # never appear in the assembler or it does not matter if they appear on
+    # stack or in registers. Main example is loop arguments that go
+    # only to guard operations or to jump or to finish
+    produced = {}
+    last_used = {}
+    last_real_usage = {}
+    frontend_alive = {}
+    if descr is None:
+        inputargs = inputframes[0]
+        liveness_analyzer = LivenessAnalyzer()
+    else:
+        inputargs = flatten(inputframes)
+        liveness_analyzer = LivenessAnalyzer(inputframes)
+    start_pos = 0
+    for position, op in enumerate(operations):
+        if op.is_guard():
+            liveness_analyzer.interpret_until(operations, position, start_pos)
+            start_pos = position
+            framestack = liveness_analyzer.get_live_info()
+            for frame in framestack:
+                for item in liveness_analyzer.all_boxes_from(frame):
+                    if item is not None:
+                        last_used[item] = position
+                        frontend_alive[item] = position
+
+    for i in range(len(operations)-1, -1, -1):
+        op = operations[i]
+        if op.result:
+            if op.result not in last_used and op.has_no_side_effect():
+                continue
+            assert op.result not in produced
+            produced[op.result] = i
+        opnum = op.getopnum()
+        for j in range(op.numargs()):
+            arg = op.getarg(j)
+            if not isinstance(arg, Box):
+                continue
+            if arg not in last_used:
+                last_used[arg] = i
+            else:
+                last_used[arg] = max(last_used[arg], i)
+            if opnum != rop.JUMP and opnum != rop.LABEL:
+                if arg not in last_real_usage:
+                    last_real_usage[arg] = i
+    #
+    longevity = {}
+    for arg in produced:
+        if arg in last_used:
+            assert isinstance(arg, Box)
+            assert produced[arg] < last_used[arg]
+            longevity[arg] = (produced[arg], last_used[arg])
+            del last_used[arg]
+    for arg in inputargs:
+        assert isinstance(arg, Box)
+        if arg not in last_used:
+            longevity[arg] = (-1, -1)
+        else:
+            longevity[arg] = (0, last_used[arg])
+            del last_used[arg]
+    assert len(last_used) == 0
+    return longevity, last_real_usage, frontend_alive
diff --git a/rpython/jit/backend/x86/assembler.py b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -5,7 +5,7 @@
 from rpython.jit.backend.llsupport.assembler import (GuardToken, BaseAssembler,
                                                      debug_bridge)
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
-from rpython.jit.backend.llsupport.regalloc import flatten
+from rpython.jit.backend.resumebuilder import flatten
 from rpython.jit.metainterp.history import Const, Box, VOID
 from rpython.jit.metainterp.history import AbstractFailDescr, INT, REF, FLOAT
 from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory
diff --git a/rpython/jit/backend/x86/regalloc.py b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -7,10 +7,10 @@
 from rpython.jit.backend.llsupport.descr import (ArrayDescr, CallDescr,
     unpack_arraydescr, unpack_fielddescr, unpack_interiorfielddescr)
 from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
-from rpython.jit.backend.llsupport.resumebuilder import ResumeBuilder
+from rpython.jit.backend.resumebuilder import ResumeBuilder,\
+     compute_vars_longevity, flatten
 from rpython.jit.backend.llsupport.regalloc import (FrameManager, BaseRegalloc,
-     RegisterManager, TempBox, compute_vars_longevity, is_comparison_or_ovf_op,
-    flatten)
+     RegisterManager, TempBox, is_comparison_or_ovf_op)
 from rpython.jit.backend.x86 import rx86
 from rpython.jit.backend.x86.arch import (WORD, JITFRAME_FIXED_SIZE, IS_X86_32,
     IS_X86_64)


More information about the pypy-commit mailing list