Explorar o código

Make list_len a CFG JIT intrinsic

jonathanvdc %!s(int64=8) %!d(string=hai) anos
pai
achega
96e730638f

+ 11 - 0
kernel/modelverse_jit/cfg_ir.py

@@ -510,6 +510,9 @@ NOP_MACRO_NAME = 'nop'
 READ_DICT_KEYS_MACRO_NAME = 'read_dict_keys'
 """The name of the macro that reads all keys from a dictionary."""
 
+READ_OUTGOING_EDGES_MACRO_NAME = 'read_outgoing_edges'
+"""The name of the macro that reads a node's outgoing edges as a list."""
+
 REVERSE_LIST_MACRO_NAME = 'reverse_list'
 """The name of the list reversal macro."""
 
@@ -939,6 +942,14 @@ def create_pure_simple_call(target_name, argument):
         calling_convention=SIMPLE_POSITIONAL_CALLING_CONVENTION,
         has_value=True, has_side_effects=False)
 
+def create_read_outgoing_edges(source_node):
+    """Creates a call that reads all of the given source node's outgoing edges."""
+    return DirectFunctionCall(
+        READ_OUTGOING_EDGES_MACRO_NAME,
+        [('source_node', source_node)],
+        calling_convention=MACRO_POSITIONAL_CALLING_CONVENTION,
+        has_value=True, has_side_effects=False)
+
 def create_gc_protect(protected_value, root):
     """Creates a value that protects the first from the GC by drawing an
        edge between it and the given root."""

+ 1 - 0
kernel/modelverse_jit/cfg_to_tree.py

@@ -996,6 +996,7 @@ class LoweringState(object):
 
     macro_lowerings = {
         cfg_ir.PRINT_MACRO_NAME: tree_ir.PrintInstruction,
+        cfg_ir.READ_OUTGOING_EDGES_MACRO_NAME: tree_ir.ReadOutgoingEdgesInstruction,
         cfg_ir.READ_DICT_KEYS_MACRO_NAME: tree_ir.ReadDictionaryKeysInstruction,
         cfg_ir.INDEX_MACRO_NAME: tree_ir.LoadIndexInstruction,
         cfg_ir.REVERSE_LIST_MACRO_NAME:

+ 12 - 1
kernel/modelverse_jit/intrinsics.py

@@ -349,7 +349,18 @@ MISC_CFG_INTRINSICS = {
     'create_value' :
         lambda original_def, a:
         original_def.redefine(
-            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Read(a))))
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Read(a)))),
+
+    # List operations
+    'list_len' :
+        lambda original_def, a:
+        original_def.redefine(
+            cfg_ir.CreateNode(
+                original_def.insert_before(
+                    cfg_ir.create_pure_simple_call(
+                        'len',
+                        original_def.insert_before(
+                            cfg_ir.create_read_outgoing_edges(a))))))
 }
 
 def register_time_intrinsic(target_jit):