Skip to content

Commit 1a5c931

Browse files
committed
replace lir find call with 2 lir::store
1 parent e40d630 commit 1a5c931

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

godel-script/godel-frontend/src/ir/inst_combine.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,69 @@ void inst_elimination_worker::copy(souffle_rule_impl* impl) {
367367
delete impl_blk;
368368
}
369369

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+
370435
}

godel-script/godel-frontend/src/ir/inst_combine.h

+12
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,16 @@ class inst_elimination_worker: public lir::inst_visitor {
118118
}
119119
};
120120

121+
class replace_find_call: public pass {
122+
private:
123+
void visit_block(lir::block*) override;
124+
125+
public:
126+
replace_find_call(ir_context& c): pass(pass_kind::ps_replace_find_call, c) {}
127+
const char* get_name() const override {
128+
return "[Transform] Replace Find Call";
129+
}
130+
bool run() override;
131+
};
132+
121133
}

godel-script/godel-frontend/src/ir/pass.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum class pass_kind {
1313
ps_remove_unused,
1414
ps_remove_unused_type,
1515
ps_inst_combine,
16+
ps_replace_find_call,
1617
ps_flatten_nested_block,
1718
ps_aggregator_inline_remark,
1819
ps_ungrounded_check,

godel-script/godel-frontend/src/ir/pass_manager.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void pass_manager::run(ir_context& ctx, const cli::configure& conf) {
2929
ordered_pass_list.push_back(new unused_type_alias_remove_pass(ctx));
3030
}
3131
if (!conf.count(cli::option::cli_disable_inst_combine)) {
32+
ordered_pass_list.push_back(new replace_find_call(ctx));
3233
ordered_pass_list.push_back(new inst_combine_pass(ctx));
3334
}
3435
ordered_pass_list.push_back(new flatten_nested_block(ctx));

0 commit comments

Comments
 (0)