Skip to content

Commit 9dcd124

Browse files
committed
add inst combine rule for inst_aggr
1 parent f128222 commit 9dcd124

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ void combine_worker::visit_binary(lir::binary* node) {
241241
}
242242
}
243243

244+
void combine_worker::visit_aggregator(lir::aggregator* node) {
245+
const auto& tgt = node->get_target();
246+
if (is_single_ref_ssa_temp(tgt.content)) {
247+
const auto& ref = get_single_ref(tgt.content);
248+
node->get_mutable_target().content = ref.first;
249+
ref.second->set_flag_eliminated(true);
250+
}
251+
}
252+
244253
void combine_worker::mark(souffle_rule_impl* b) {
245254
b->get_block()->accept(this);
246255
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class combine_worker: public lir::inst_visitor {
5353
void visit_record(lir::record*) override;
5454
void visit_unary(lir::unary*) override;
5555
void visit_binary(lir::binary*) override;
56+
void visit_aggregator(lir::aggregator*) override;
5657

5758
public:
5859
combine_worker(const inst_combine_pass::ref_graph& g): vg(g) {}

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,19 @@ void not_operand::dump(std::ostream& os, const std::string& indent) const {
359359
// only one statement in the block
360360
if (body->get_content().size()==1) {
361361
os << indent << "!(";
362-
body->get_content()[0]->dump(os, "");
362+
switch(body->get_content()[0]->get_kind()) {
363+
case inst_kind::inst_not:
364+
case inst_kind::inst_and:
365+
case inst_kind::inst_or:
366+
case inst_kind::inst_aggr:
367+
os << "\n";
368+
body->get_content()[0]->dump(os, indent + " ");
369+
os << "\n" << indent;
370+
break;
371+
default:
372+
body->get_content()[0]->dump(os, "");
373+
break;
374+
}
363375
os << ")";
364376
return;
365377
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ class aggregator: public inst {
666666
void accept(inst_visitor* v) override {
667667
v->visit_aggregator(this);
668668
}
669+
670+
public:
671+
const auto& get_target() const { return destination; }
672+
auto& get_mutable_target() { return destination; }
669673
};
670674

671675
}

0 commit comments

Comments
 (0)