@@ -367,4 +367,69 @@ void inst_elimination_worker::copy(souffle_rule_impl* impl) {
367
367
delete impl_blk;
368
368
}
369
369
370
+ void replace_find_call::visit_block (lir::block* node) {
371
+ bool has_find_call = false ;
372
+ for (auto i : node->get_content ()) {
373
+ if (i->get_kind () != lir::inst_kind::inst_call) {
374
+ continue ;
375
+ }
376
+ auto call = reinterpret_cast <lir::call*>(i);
377
+ if (call->get_func_kind () == lir::call::kind::find &&
378
+ call->get_function_name () == " find" ) {
379
+ has_find_call = true ;
380
+ break ;
381
+ }
382
+ }
383
+
384
+ if (has_find_call) {
385
+ std::vector<lir::inst*> new_content;
386
+ for (auto i : node->get_content ()) {
387
+ if (i->get_kind () != lir::inst_kind::inst_call) {
388
+ new_content.push_back (i);
389
+ continue ;
390
+ }
391
+
392
+ auto call = reinterpret_cast <lir::call*>(i);
393
+ if (call->get_func_kind () != lir::call::kind::find ||
394
+ call->get_function_name () != " find" ) {
395
+ new_content.push_back (i);
396
+ continue ;
397
+ }
398
+
399
+ auto dst = call->get_return ();
400
+ auto arg0 = call->get_arguments ()[0 ];
401
+ auto arg1 = call->get_arguments ()[1 ];
402
+ auto new_block = new lir::block (call->get_location ());
403
+ new_block->set_use_comma ();
404
+ new_content.push_back (new_block);
405
+
406
+ new_block->add_new_content (new lir::store (arg0, dst, call->get_location ()));
407
+ new_block->add_new_content (new lir::store (arg1, arg0, call->get_location ()));
408
+
409
+ delete i;
410
+ }
411
+ node->get_mutable_content ().swap (new_content);
412
+ } else {
413
+ for (auto i : node->get_content ()) {
414
+ i->accept (this );
415
+ }
416
+ }
417
+ }
418
+
419
+ bool replace_find_call::run () {
420
+ for (auto impl : ctx->rule_impls ) {
421
+ impl->get_block ()->accept (this );
422
+ }
423
+ for (auto impl : ctx->database_get_table ) {
424
+ impl->get_block ()->accept (this );
425
+ }
426
+ for (auto impl : ctx->schema_get_field ) {
427
+ impl->get_block ()->accept (this );
428
+ }
429
+ for (auto impl : ctx->schema_data_constraint_impls ) {
430
+ impl->get_block ()->accept (this );
431
+ }
432
+ return true ;
433
+ }
434
+
370
435
}
0 commit comments