ソースを参照

Fix a bug with the loop-favoring heuristic's initial temperature

jonathanvdc 8 年 前
コミット
ec9ad22ae2
2 ファイル変更11 行追加7 行削除
  1. 8 6
      kernel/modelverse_jit/bytecode_ir.py
  2. 3 1
      kernel/modelverse_jit/jit.py

+ 8 - 6
kernel/modelverse_jit/bytecode_ir.py

@@ -11,9 +11,9 @@ class Instruction(object):
            next instruction."""
         raise NotImplementedError()
 
-    def get_reachable(self):
+    def get_reachable(self, filter_children=lambda _: True):
         """Gets the set of all instructions that are reachable from the given instruction, including
-           this instruction."""
+           this instruction. A function can be used to filter out certain instructions' children."""
         results = set()
         stack = [self]
         while len(stack) > 0:
@@ -22,10 +22,12 @@ class Instruction(object):
             next_instr = instr.next_instruction
             if next_instr is not None and next_instr not in results:
                 stack.append(next_instr)
-            for other in instr.get_directly_reachable():
-                if other not in results:
-                    assert other is not None
-                    stack.append(other)
+
+            if filter_children(instr):
+                for other in instr.get_directly_reachable():
+                    if other not in results:
+                        assert other is not None
+                        stack.append(other)
 
         return results
 

+ 3 - 1
kernel/modelverse_jit/jit.py

@@ -824,7 +824,9 @@ def favor_loops(body_bytecode):
             # Then increase the temperature by the number of instructions reachable
             # from loop bodies. Note that the algorithm will count nested loops twice.
             # This is actually by design.
-            loop_body_instructions = instruction.body.get_reachable()
+            loop_body_instructions = instruction.body.get_reachable(
+                lambda x: not isinstance(
+                    x, (bytecode_ir.BreakInstruction, bytecode_ir.ContinueInstruction)))
             temperature += ADAPTIVE_JIT_LOOP_INSTRUCTION_MULTIPLIER * len(loop_body_instructions)
 
     return (