Browse Source

Make baseline JIT conform to fast-jit's CC when adaptive-jit is enabled

jonathanvdc 8 years ago
parent
commit
5efabf4c21
2 changed files with 24 additions and 6 deletions
  1. 11 5
      kernel/modelverse_jit/jit.py
  2. 13 1
      kernel/modelverse_jit/tree_ir.py

+ 11 - 5
kernel/modelverse_jit/jit.py

@@ -62,7 +62,8 @@ def create_bare_function(function_name, parameter_list, function_body):
 
 def create_function(
         function_name, parameter_list, param_dict,
-        body_param_dict, function_body, source_map_name=None):
+        body_param_dict, function_body, source_map_name=None,
+        compatible_temporary_protects=False):
     """Creates a function from the given function name, parameter list,
        variable-to-parameter name map, variable-to-local name map and
        function body. An optional source map can be included, too."""
@@ -101,7 +102,9 @@ def create_function(
 
     # Shield temporaries from the GC.
     constructed_body = tree_ir.protect_temporaries_from_gc(
-        constructed_body, tree_ir.LoadLocalInstruction(jit_runtime.LOCALS_NODE_NAME))
+        constructed_body,
+        tree_ir.LoadLocalInstruction(jit_runtime.LOCALS_NODE_NAME),
+        compatible_temporary_protects)
 
     return create_bare_function(function_name, parameter_list, constructed_body)
 
@@ -745,7 +748,9 @@ def compile_function_body_interpret(jit, function_name, body_id, task_root, head
     jit.jit_globals[function_name] = __interpret_function
     raise primitive_functions.PrimitiveFinished(__interpret_function)
 
-def compile_function_body_baseline(jit, function_name, body_id, task_root, header=None):
+def compile_function_body_baseline(
+        jit, function_name, body_id, task_root,
+        header=None, compatible_temporary_protects=False):
     """Have the baseline JIT compile the function with the given name and body id."""
     (parameter_ids, parameter_list, _), = yield [
         ("CALL_ARGS", [jit.jit_signature, (body_id,)])]
@@ -766,7 +771,8 @@ def compile_function_body_baseline(jit, function_name, body_id, task_root, heade
     # Wrap the tree IR in a function definition.
     constructed_function = create_function(
         function_name, parameter_list, param_dict,
-        body_param_dict, constructed_body, jit.get_source_map_name(function_name))
+        body_param_dict, constructed_body, jit.get_source_map_name(function_name),
+        compatible_temporary_protects)
 
     # Convert the function definition to Python code, and compile it.
     raise primitive_functions.PrimitiveFinished(
@@ -972,7 +978,7 @@ class AdaptiveJitState(object):
         yield [
             ("TAIL_CALL_ARGS",
              [compile_function_body_baseline,
-              (jit, function_name, body_id, task_root, header)])]
+              (jit, function_name, body_id, task_root, header, True)])]
 
 def compile_function_body_adaptive(
         jit, function_name, body_id, task_root,

+ 13 - 1
kernel/modelverse_jit/tree_ir.py

@@ -1796,6 +1796,8 @@ def iterate_as_stack(instruction, stack_iterator):
         for child in children:
             # Push all children onto the stack.
             iterate_as_stack(child, stack_iterator)
+
+        stack_iterator.before_pop_args(instruction)
         for child in children:
             # Pop all children from the stack.
             stack_iterator.pop()
@@ -1807,6 +1809,10 @@ class StackIterator(object):
     def __init__(self, stack=None):
         self.stack = [] if stack is None else stack
 
+    def before_pop_args(self, instruction):
+        """Performs an action before the given instruction's arguments are popped."""
+        pass
+
     def pop(self):
         """Pops an instruction from the stack."""
         self.stack.pop()
@@ -1843,7 +1849,7 @@ class StackIterator(object):
 
         return results
 
-def protect_temporaries_from_gc(instruction, connected_node):
+def protect_temporaries_from_gc(instruction, connected_node, fast_jit_compat=False):
     """Protects temporaries from the garbage collector by connecting them to the given node."""
     # # The reasoning behind this function
     #
@@ -1867,6 +1873,12 @@ def protect_temporaries_from_gc(instruction, connected_node):
             StackIterator.__init__(self, stack)
             self.gc_temporaries = set() if gc_temporaries is None else gc_temporaries
 
+        def before_pop_args(self, instruction):
+            """Performs an action before the given instruction's arguments are popped."""
+            if fast_jit_compat and isinstance(instruction, DictionaryLiteralInstruction):
+                for instruction_set in self.stack:
+                    self.gc_temporaries.update(instruction_set)
+
         def push(self, instruction):
             """Pushes an instruction onto the stack."""
             if isinstance(instruction, (