Skip to content

Commit

Permalink
add inst combine rule for inst_aggr
Browse files Browse the repository at this point in the history
  • Loading branch information
ValKmjolnir committed Jan 9, 2025
1 parent f128222 commit 9dcd124
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions godel-script/godel-frontend/src/ir/inst_combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ void combine_worker::visit_binary(lir::binary* node) {
}
}

void combine_worker::visit_aggregator(lir::aggregator* node) {
const auto& tgt = node->get_target();
if (is_single_ref_ssa_temp(tgt.content)) {
const auto& ref = get_single_ref(tgt.content);
node->get_mutable_target().content = ref.first;
ref.second->set_flag_eliminated(true);
}
}

void combine_worker::mark(souffle_rule_impl* b) {
b->get_block()->accept(this);
}
Expand Down
1 change: 1 addition & 0 deletions godel-script/godel-frontend/src/ir/inst_combine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class combine_worker: public lir::inst_visitor {
void visit_record(lir::record*) override;
void visit_unary(lir::unary*) override;
void visit_binary(lir::binary*) override;
void visit_aggregator(lir::aggregator*) override;

public:
combine_worker(const inst_combine_pass::ref_graph& g): vg(g) {}
Expand Down
14 changes: 13 additions & 1 deletion godel-script/godel-frontend/src/ir/lir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,19 @@ void not_operand::dump(std::ostream& os, const std::string& indent) const {
// only one statement in the block
if (body->get_content().size()==1) {
os << indent << "!(";
body->get_content()[0]->dump(os, "");
switch(body->get_content()[0]->get_kind()) {
case inst_kind::inst_not:
case inst_kind::inst_and:
case inst_kind::inst_or:
case inst_kind::inst_aggr:
os << "\n";
body->get_content()[0]->dump(os, indent + " ");
os << "\n" << indent;
break;
default:
body->get_content()[0]->dump(os, "");
break;
}
os << ")";
return;
}
Expand Down
4 changes: 4 additions & 0 deletions godel-script/godel-frontend/src/ir/lir.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ class aggregator: public inst {
void accept(inst_visitor* v) override {
v->visit_aggregator(this);
}

public:
const auto& get_target() const { return destination; }
auto& get_mutable_target() { return destination; }
};

}
Expand Down

0 comments on commit 9dcd124

Please sign in to comment.