[pypy-commit] pypy framestate: move graph.pos_index init into the main loop of build_flow()

rlamy noreply at buildbot.pypy.org
Mon Nov 24 17:30:09 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: framestate
Changeset: r74696:0cd515a70a90
Date: 2014-11-23 02:58 +0000
http://bitbucket.org/pypy/pypy/changeset/0cd515a70a90/

Log:	move graph.pos_index init into the main loop of build_flow()

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -137,7 +137,6 @@
         self.offset = 0
         i = 0
         while self.offset < len(code.co_code):
-            self.pos_map[self.offset] = i
             if self.offset in self.pending_cuts:
                 self.new_block()
             next_offset, instr = self.read(code, self.offset)
@@ -163,26 +162,29 @@
     def _add_jump(self, target):
         if target <= self.offset:
             i_block, i_instr = self.find_position(target)
-            self.blocks[i_block:i_block + 1] = self.blocks[i_block].split_at(i_instr)
+            split = self.blocks[i_block].split_at(i_instr)
+            if len(split) == 2:
+                new_block = split[1]
+                for i, instr in enumerate(new_block.operations):
+                    self.graph.pos_index[instr.offset] = new_block, i
+            self.blocks[i_block:i_block + 1] = split
         else:
             self.pending_cuts.add(target)
 
     def build_flow(self, code):
         offsets = []
         self.pending_cuts = set()
-        self.pos_map = {}
         self.blocks = [SimpleBlock([])]
+        self.graph = graph = BytecodeGraph(self.blocks[0])
         for instr in self._iter_instr(code):
             offsets.append(self.offset)
-            self.blocks[-1].operations.append(instr)
+            block = self.blocks[-1]
+            graph.pos_index[self.offset] = block, len(block.operations)
+            block.operations.append(instr)
             if instr.has_jump():
                 self.new_block()
                 self._add_jump(instr.arg)
 
-        graph = BytecodeGraph(self.blocks[0])
-        for block in self.blocks:
-            for i, op in enumerate(block.operations):
-                graph.pos_index[op.offset] = block, i
         graph._next_pos = dict([(offsets[i], offsets[i + 1])
             for i in range(len(offsets) - 1)])
         graph._next_pos[offsets[-1]] = len(code.co_code)


More information about the pypy-commit mailing list