@@ -87,25 +87,35 @@ void inst_combine_pass::visit_compare(lir::compare* c) {
87
87
}
88
88
89
89
bool inst_combine_pass::run () {
90
- for (auto impl : ctx->rule_impls ) {
91
- scan (impl);
92
- inst_elimination_worker ().copy (impl);
90
+ for (auto impl : ctx->rule_impls ) {
91
+ run_on_single_impl (impl);
93
92
}
94
- for (auto impl : ctx->database_get_table ) {
95
- scan (impl);
96
- inst_elimination_worker ().copy (impl);
93
+ for (auto impl : ctx->database_get_table ) {
94
+ run_on_single_impl (impl);
97
95
}
98
- for (auto impl : ctx->schema_get_field ) {
99
- scan (impl);
100
- inst_elimination_worker ().copy (impl);
96
+ for (auto impl : ctx->schema_get_field ) {
97
+ run_on_single_impl (impl);
101
98
}
102
- for (auto impl : ctx->schema_data_constraint_impls ) {
103
- scan (impl);
104
- inst_elimination_worker ().copy (impl);
99
+ for (auto impl : ctx->schema_data_constraint_impls ) {
100
+ run_on_single_impl (impl);
105
101
}
106
102
return true ;
107
103
}
108
104
105
+ void inst_combine_pass::run_on_single_impl (souffle_rule_impl* b) {
106
+ auto worker = inst_elimination_worker ();
107
+ size_t pass_run_count = 0 ;
108
+ const size_t max_pass_run_count = 16 ;
109
+ scan (b);
110
+ worker.copy (b);
111
+ ++ pass_run_count;
112
+ while (worker.get_eliminated_count () && pass_run_count < max_pass_run_count) {
113
+ scan (b);
114
+ worker.copy (b);
115
+ ++ pass_run_count;
116
+ }
117
+ }
118
+
109
119
void inst_combine_pass::scan (souffle_rule_impl* b) {
110
120
variable_reference_graph.clear ();
111
121
b->get_block ()->accept (this );
@@ -265,6 +275,7 @@ void inst_elimination_worker::visit_block(lir::block* node) {
265
275
for (auto i : node->get_content ()) {
266
276
// skip eliminated instruction
267
277
if (i->get_flag_eliminated ()) {
278
+ ++ eliminated_count;
268
279
continue ;
269
280
}
270
281
@@ -338,6 +349,8 @@ void inst_elimination_worker::visit_aggregator(lir::aggregator* node) {
338
349
}
339
350
340
351
void inst_elimination_worker::copy (souffle_rule_impl* impl) {
352
+ eliminated_count = 0 ;
353
+ blk.clear ();
341
354
auto impl_blk = new lir::block (impl->get_block ()->get_location ());
342
355
343
356
blk.push_back (impl_blk);
0 commit comments