File tree 2 files changed +33
-1
lines changed
godel-script/godel-frontend/src/ir
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ void inst_combine_pass::visit_store(lir::store* s) {
12
12
//
13
13
// (
14
14
// ssa_temp_0 = a,
15
- // b = ssa_temp_1 ,
15
+ // ssa_temp_1 = b ,
16
16
// call(ssa_temp_2, ssa_temp_0, ssa_temp_1)
17
17
// )
18
18
//
@@ -86,6 +86,37 @@ void inst_combine_pass::visit_compare(lir::compare* c) {
86
86
}
87
87
}
88
88
89
+ void inst_combine_pass::visit_call (lir::call* c) {
90
+ if (c->get_func_kind () != lir::call::kind::key_cmp) {
91
+ return ;
92
+ }
93
+ if (c->get_function_name () != " key_eq" ) {
94
+ return ;
95
+ }
96
+
97
+ const auto & left = c->get_arguments ()[0 ];
98
+ const auto & right = c->get_arguments ()[1 ];
99
+
100
+ // record this case:
101
+ //
102
+ // a.key_eq(b.getParent())
103
+ // -->
104
+ // (
105
+ // getParent(ssa_temp_0, b),
106
+ // a = ssa_temp_0
107
+ // )
108
+ //
109
+ // and optimize this case to:
110
+ //
111
+ // getParent(a, b)
112
+ //
113
+ if (left.kind ==lir::inst_value_kind::variable &&
114
+ right.kind ==lir::inst_value_kind::variable) {
115
+ variable_reference_graph[left.content ].insert ({right.content , c});
116
+ variable_reference_graph[right.content ].insert ({left.content , c});
117
+ }
118
+ }
119
+
89
120
bool inst_combine_pass::run () {
90
121
for (auto impl : ctx->rule_impls ) {
91
122
run_on_single_impl (impl);
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class inst_combine_pass: public pass {
20
20
private:
21
21
void visit_store (lir::store*) override ;
22
22
void visit_compare (lir::compare*) override ;
23
+ void visit_call (lir::call*) override ;
23
24
24
25
private:
25
26
void scan (souffle_rule_impl*);
You can’t perform that action at this time.
0 commit comments