Ver código fonte

Make cast intrinsics CFG intrinsics too

jonathanvdc 8 anos atrás
pai
commit
f8a767f479
1 arquivos alterados com 16 adições e 4 exclusões
  1. 16 4
      kernel/modelverse_jit/jit.py

+ 16 - 4
kernel/modelverse_jit/jit.py

@@ -377,10 +377,22 @@ class ModelverseJit(object):
 
     def register_cast_intrinsic(self, name, target_type):
         """Registers an intrinsic with the JIT that represents a unary conversion operator."""
-        self.register_intrinsic(name, lambda a: tree_ir.CreateNodeWithValueInstruction(
-            tree_ir.CallInstruction(
-                tree_ir.LoadGlobalInstruction(target_type.__name__),
-                [tree_ir.ReadValueInstruction(a)])))
+        self.register_intrinsic(
+            name,
+            lambda a:
+            tree_ir.CreateNodeWithValueInstruction(
+                tree_ir.CallInstruction(
+                    tree_ir.LoadGlobalInstruction(target_type.__name__),
+                    [tree_ir.ReadValueInstruction(a)])),
+            lambda original_def, a:
+            original_def.redefine(
+                cfg_ir.CreateNode(
+                    original_def.insert_before(
+                        cfg_ir.DirectFunctionCall(
+                            target_type.__name__,
+                            [('value', original_def.insert_before(cfg_ir.Read(a)))],
+                            calling_convention=cfg_ir.SIMPLE_POSITIONAL_CALLING_CONVENTION,
+                            has_value=True, has_side_effects=False)))))
 
     def jit_signature(self, body_id):
         """Acquires the signature for the given body id node, which consists of the