Browse Source

Avoid generating thunks for recursive functions

jonathanvdc 8 years ago
parent
commit
d6ea282cdd
1 changed files with 13 additions and 5 deletions
  1. 13 5
      kernel/modelverse_jit/jit.py

+ 13 - 5
kernel/modelverse_jit/jit.py

@@ -196,7 +196,10 @@ class ModelverseJit(object):
     def get_compiled_name(self, body_id):
     def get_compiled_name(self, body_id):
         """Gets the name of the compiled version of the given body node in the JIT
         """Gets the name of the compiled version of the given body node in the JIT
            global state."""
            global state."""
-        return self.jitted_entry_points[body_id]
+        if body_id in self.jitted_entry_points:
+            return self.jitted_entry_points[body_id]
+        else:
+            return None
 
 
     def mark_no_jit(self, body_id):
     def mark_no_jit(self, body_id):
         """Informs the JIT that the node with the given identifier is a function entry
         """Informs the JIT that the node with the given identifier is a function entry
@@ -562,11 +565,13 @@ class ModelverseJit(object):
         """Creates a thunk from given body id.
         """Creates a thunk from given body id.
            This thunk is a function that will invoke the function whose body id is given.
            This thunk is a function that will invoke the function whose body id is given.
            The thunk's name in the JIT's global context is returned."""
            The thunk's name in the JIT's global context is returned."""
-        if self.lookup_compiled_body(body_id) is not None:
+        self.lookup_compiled_body(body_id)
+        compiled_name = self.get_compiled_name(body_id)
+        if compiled_name is not None:
             # We might have compiled the function with the given body id already. In that case,
             # We might have compiled the function with the given body id already. In that case,
             # we need not bother with constructing the thunk; we can return the compiled function
             # we need not bother with constructing the thunk; we can return the compiled function
             # right away.
             # right away.
-            return self.get_compiled_name(body_id)
+            return compiled_name
         else:
         else:
             # Looks like we'll just have to build that thunk after all.
             # Looks like we'll just have to build that thunk after all.
             return self.jit_thunk(tree_ir.LiteralInstruction(body_id))
             return self.jit_thunk(tree_ir.LiteralInstruction(body_id))
@@ -579,8 +584,11 @@ class ModelverseJit(object):
         # we need not bother with constructing the thunk; we can return the compiled function
         # we need not bother with constructing the thunk; we can return the compiled function
         # right away.
         # right away.
         body_id = self.get_global_body_id(global_name)
         body_id = self.get_global_body_id(global_name)
-        if body_id is not None and self.lookup_compiled_body(body_id) is not None:
-            return self.get_compiled_name(body_id)
+        if body_id is not None:
+            self.lookup_compiled_body(body_id)
+            compiled_name = self.get_compiled_name(body_id)
+            if compiled_name is not None:
+                return compiled_name
 
 
         # Looks like we'll just have to build that thunk after all.
         # Looks like we'll just have to build that thunk after all.
         # We want to look up the global function like so
         # We want to look up the global function like so