73 bool equiv(
const IR::MethodCallExpression *mc,
const IR::MAU::Action *ac) {
75 if (
auto path = mc->method->to<IR::PathExpression>()) {
76 if (path->path->name == ac->name) {
84 bool preorder(IR::MAU::Instruction *instr)
override {
85 auto table = findContext<IR::MAU::Table>();
86 if (table->is_compiler_generated || table->entries_list ==
nullptr)
return false;
88 auto action = findContext<IR::MAU::Action>();
90 for (
unsigned i = 0; i < instr->operands.size(); i++) {
94 if ((i == 1) && (instr->name ==
"conditionally-set")) {
98 auto op = phv.field(instr->operands[i]);
101 for (
unsigned j = 0; j < table->match_key.size(); j++) {
102 if (table->match_key[j]->match_type.name !=
"exact")
continue;
104 auto key = phv.field(table->match_key[j]->expr);
106 bool can_const_prop =
false;
107 const IR::Expression *match =
nullptr;
110 for (
auto &ent : table->entries_list->entries) {
111 if (equiv(ent->action->to<IR::MethodCallExpression>(), action) &&
112 (action->init_default ==
false)) {
113 if (can_const_prop ==
false) {
115 match = ent->keys->components.at(j);
116 can_const_prop =
true;
119 auto cval = ent->keys->components.at(j);
120 if (!match->equiv(*cval)) {
121 can_const_prop =
false;
128 if (can_const_prop) {
129 LOG4(
"rewrite " << instr);
130 if (
auto b = match->to<IR::BoolLiteral>()) {
131 instr->operands[i] =
new IR::Constant(IR::Type::Bits::get(1), b->value);
132 }
else if (
auto c = match->to<IR::Constant>()) {
133 instr->operands[i] = c;
135 LOG4(
"unknown static entry match type");
137 LOG4(
"as " << instr);
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24