@@ -87,25 +87,35 @@ void inst_combine_pass::visit_compare(lir::compare* c) {
8787}
8888
8989bool 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);
9392 }
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);
9795 }
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);
10198 }
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);
105101 }
106102 return true ;
107103}
108104
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+
109119void inst_combine_pass::scan (souffle_rule_impl* b) {
110120 variable_reference_graph.clear ();
111121 b->get_block ()->accept (this );
@@ -265,6 +275,7 @@ void inst_elimination_worker::visit_block(lir::block* node) {
265275 for (auto i : node->get_content ()) {
266276 // skip eliminated instruction
267277 if (i->get_flag_eliminated ()) {
278+ ++ eliminated_count;
268279 continue ;
269280 }
270281
@@ -338,6 +349,8 @@ void inst_elimination_worker::visit_aggregator(lir::aggregator* node) {
338349}
339350
340351void inst_elimination_worker::copy (souffle_rule_impl* impl) {
352+ eliminated_count = 0 ;
353+ blk.clear ();
341354 auto impl_blk = new lir::block (impl->get_block ()->get_location ());
342355
343356 blk.push_back (impl_blk);
0 commit comments