32 key_hash_bits_masked = 0;
33 for (
auto &table_key : tbl->match_key) {
34 for (
auto &a : table_key->annotations->annotations) {
35 if (a->name ==
"hash_mask") {
36 bitvec hash_mask = getBitvec(a);
39 const PHV::Field *field = phv.field(table_key->expr, &bits);
41 int masked = hash_mask.popcount();
42 if (masked > bits.
size()) masked = bits.
size();
43 key_hash_bits_masked += (bits.
size() - masked);
46 const IR::Member *m = table_key->expr->to<IR::Member>();
47 if (m !=
nullptr) key_hash_masks[m->toString()] = hash_mask;
53 LOG5(
"Hash mask annotations for table " << tbl->name <<
":");
54 for (
auto &m : key_hash_masks) LOG5(
" " << m.first <<
" : 0x" << std::hex << m.second);
58 std::map<cstring, bitvec> hash_masks() {
return key_hash_masks; }
60 int hash_bits_masked() {
return key_hash_bits_masked; }
63 bitvec getBitvec(
const IR::Annotation *annotation) {
65 if (annotation->expr.size() != 1) {
66 error(
"%1% should contain a constant", annotation);
69 auto constant = annotation->expr[0]->to<IR::Constant>();
70 if (constant ==
nullptr) {
71 error(
"%1% should contain a constant", annotation);
74 int64_t c = constant->asUint64();
81 std::map<cstring, bitvec> key_hash_masks;
85 int key_hash_bits_masked;
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51