Browse Source

Minor movement of code to improve performance slightly

Yentl Van Tendeloo 7 years ago
parent
commit
db4a2db1a6
2 changed files with 18 additions and 16 deletions
  1. 17 15
      kernel/modelverse_kernel/main.py
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 17 - 15
kernel/modelverse_kernel/main.py

@@ -328,7 +328,6 @@ class ModelverseKernel(object):
         initial_instruction = inst
 
         (params, _, is_mutable), = yield [("CALL_ARGS", [self.jit.jit_signature, (inst,)])]
-        #if suggested_name is None or is_mutable:
         if is_mutable:
             print("Ignoring mutable or unreadable: %s" % suggested_name)
             raise jit.JitCompilationFailedException("FAIL")
@@ -356,26 +355,29 @@ class ModelverseKernel(object):
 
     def jit_compile(self, task_root, inst):
         # Try to retrieve the suggested name.
-        suggested_name = self.jit.get_global_name(inst)
-        if suggested_name is None:
-            suggested_name = "func_%s" % str(inst)
-        #print("Exec function " + str(suggested_name))
-
         # Have the JIT compile the function.
         if inst is None:
+            suggested_name = self.jit.get_global_name(inst)
+            if suggested_name is None:
+                suggested_name = "func_%s" % str(inst)
             raise ValueError('body_id cannot be None: ' + str(suggested_name))
+
         elif inst in self.jit.jitted_entry_points:
             raise primitive_functions.PrimitiveFinished(
                 self.jit.jit_globals[self.jit.jitted_entry_points[inst]])
-
-        compiled_func = self.jit.lookup_compiled_body(inst)
-        if compiled_func is None:
-            compiled_func, = yield [("CALL_ARGS", [self.read_function, (inst, suggested_name)])]
-            exec(str(compiled_func), self.jit.jit_globals)
-            compiled_func = self.jit.jit_globals[suggested_name]
-            self.jit.register_compiled(inst, compiled_func, suggested_name)
-
-        raise primitive_functions.PrimitiveFinished(compiled_func)
+        else:
+            compiled_func = self.jit.lookup_compiled_body(inst)
+
+            if compiled_func is None:
+                suggested_name = self.jit.get_global_name(inst)
+                if suggested_name is None:
+                    suggested_name = "func_%s" % str(inst)
+                compiled_func, = yield [("CALL_ARGS", [self.read_function, (inst, suggested_name)])]
+                exec(compiled_func, self.jit.jit_globals)
+                compiled_func = self.jit.jit_globals[suggested_name]
+                self.jit.register_compiled(inst, compiled_func, suggested_name)
+
+            raise primitive_functions.PrimitiveFinished(compiled_func)
 
     def execute_jit(self, task_root, inst, taskname, params = {}, store=False):
         # execute_jit

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Thu Apr 26 16:21:07 2018
+Date:   Thu Apr 26 16:40:53 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server