|
@@ -53,13 +53,19 @@ class ModelverseJit(object):
|
|
|
def __init__(self, max_instructions=None, compiled_function_lookup=None):
|
|
|
self.todo_entry_points = set()
|
|
|
self.no_jit_entry_points = set()
|
|
|
- self.jitted_entry_points = {}
|
|
|
self.jitted_parameters = {}
|
|
|
self.jit_globals = {
|
|
|
'PrimitiveFinished' : primitive_functions.PrimitiveFinished,
|
|
|
jit_runtime.CALL_FUNCTION_NAME : jit_runtime.call_function,
|
|
|
jit_runtime.GET_INPUT_FUNCTION_NAME : jit_runtime.get_input
|
|
|
}
|
|
|
+ # jitted_entry_points maps body ids to values in jit_globals.
|
|
|
+ self.jitted_entry_points = {}
|
|
|
+ # global_functions maps global value names to body ids.
|
|
|
+ self.global_functions = {}
|
|
|
+ # global_functions_inv maps body ids to global value names.
|
|
|
+ self.global_functions_inv = {}
|
|
|
+ # bytecode_graphs maps body ids to their parsed bytecode graphs.
|
|
|
self.bytecode_graphs = {}
|
|
|
self.jit_count = 0
|
|
|
self.max_instructions = max_instructions
|
|
@@ -156,15 +162,39 @@ class ModelverseJit(object):
|
|
|
self.jit_count += 1
|
|
|
return function_name
|
|
|
|
|
|
- def generate_function_name(self, suggested_name=None):
|
|
|
+ def generate_function_name(self, body_id, suggested_name=None):
|
|
|
"""Generates a new function name or picks the suggested name if it is still
|
|
|
available."""
|
|
|
+ if suggested_name is None:
|
|
|
+ suggested_name = self.get_global_name(body_id)
|
|
|
+
|
|
|
return self.generate_name('func', suggested_name)
|
|
|
|
|
|
+ def register_global(self, body_id, global_name):
|
|
|
+ """Associates the given body id with the given global name."""
|
|
|
+ self.global_functions[global_name] = body_id
|
|
|
+ self.global_functions_inv[body_id] = global_name
|
|
|
+
|
|
|
+ def get_global_name(self, body_id):
|
|
|
+ """Gets the name of the global function with the given body id.
|
|
|
+ Returns None if no known global exists with the given id."""
|
|
|
+ if body_id in self.global_functions_inv:
|
|
|
+ return self.global_functions_inv[body_id]
|
|
|
+ else:
|
|
|
+ return None
|
|
|
+
|
|
|
+ def get_global_body_id(self, global_name):
|
|
|
+ """Gets the body id of the global function with the given name.
|
|
|
+ Returns None if no known global exists with the given name."""
|
|
|
+ if global_name in self.global_functions:
|
|
|
+ return self.global_functions[global_name]
|
|
|
+ else:
|
|
|
+ return None
|
|
|
+
|
|
|
def register_compiled(self, body_id, compiled_function, function_name=None):
|
|
|
"""Registers a compiled entry point with the JIT."""
|
|
|
# Get the function's name.
|
|
|
- function_name = self.generate_function_name(function_name)
|
|
|
+ function_name = self.generate_function_name(body_id, function_name)
|
|
|
# Map the body id to the given parameter list.
|
|
|
self.jitted_entry_points[body_id] = function_name
|
|
|
self.jit_globals[function_name] = compiled_function
|
|
@@ -280,7 +310,7 @@ class ModelverseJit(object):
|
|
|
|
|
|
# Generate a name for the function we're about to analyze, and pretend that
|
|
|
# it already exists. (we need to do this for recursive functions)
|
|
|
- function_name = self.generate_function_name(suggested_name)
|
|
|
+ function_name = self.generate_function_name(body_id, suggested_name)
|
|
|
self.jitted_entry_points[body_id] = function_name
|
|
|
self.jit_globals[function_name] = None
|
|
|
|