瀏覽代碼

Added dict_add_fast as an intrinsic and add use in transform.alc

Yentl Van Tendeloo 8 年之前
父節點
當前提交
17da720962
共有 2 個文件被更改,包括 22 次插入4 次删除
  1. 4 4
      bootstrap/transform.alc
  2. 18 0
      kernel/modelverse_jit/intrinsics.py

+ 4 - 4
bootstrap/transform.alc

@@ -283,7 +283,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 			while (read_nr_out(options) > 0):
 				option = set_pop(options)
 				new_map = dict_copy(map)
-				dict_add(new_map, read_attribute(schedule_model, current_element, "label"), option)
+				dict_add_fast(new_map, read_attribute(schedule_model, current_element, "label"), option)
 				set_add(new_mappings, new_map)
 
 		mappings = new_mappings
@@ -343,7 +343,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 		tmp = set_pop(RHS_elements)
 		label = read_attribute(schedule_model, tmp, "label")
 		set_add(RHS_labels, label)
-		dict_add(RHS_map, label, tmp)
+		dict_add_fast(RHS_map, label, tmp)
 
 	remaining = set_overlap(LHS_labels, RHS_labels)
 	original_RHS_labels = set_copy(RHS_labels)
@@ -370,7 +370,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 				typename = read_type(schedule_model, RHS_map[label])
 				original_typename = string_substr(typename, 5, string_len(typename))
 				new_name = instantiate_link(host_model, original_typename, "", new_mapping[src], new_mapping[dst])
-				dict_add(new_mapping, label, new_name)
+				dict_add_fast(new_mapping, label, new_name)
 			else:
 				// Delay this a bit, until all are bound
 				list_insert(labels_to_add, label, 0)
@@ -380,7 +380,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 			typename = read_type(schedule_model, RHS_map[label])
 			original_typename = string_substr(typename, 5, string_len(typename))
 			new_name = instantiate_node(host_model, original_typename, "")
-			dict_add(new_mapping, label, new_name)
+			dict_add_fast(new_mapping, label, new_name)
 
 	Element attributes
 	String attribute

+ 18 - 0
kernel/modelverse_jit/intrinsics.py

@@ -79,6 +79,23 @@ def __dict_add(a, b, c):
             load_b),
         load_a)
 
+def __dict_add_fast(a, b, c):
+    # TODO This might be possible to optimize slightly?
+    store_a, load_a = tree_ir.evaluate_and_load(a)
+    b_val = tree_ir.StoreLocalInstruction(
+        None,
+        tree_ir.ReadValueInstruction(b))
+    store_c, load_c = tree_ir.evaluate_and_load(c)
+    return tree_ir.create_block(
+        store_a,
+        b_val,
+        store_c,
+        tree_ir.CreateDictionaryEdgeInstruction(
+            load_a,
+            b_val.create_load(),
+            load_c),
+        load_a)
+
 def __list_read(a, b):
     # The statements in this function generate the following code:
     #
@@ -277,6 +294,7 @@ MISC_INTRINSICS = {
             a, tree_ir.ReadValueInstruction(b)),
 
     'dict_add' : __dict_add,
+    'dict_add_fast' : __dict_add_fast,
     'dict_len' : __read_nr_out,
 
     # Set operations