66 ALL_ATTACHED = 01111111110,
71 bool operator<(
FormatType_t a)
const {
return value < a.value; }
72 bool operator==(
const FormatType_t &a)
const {
return value == a.value; }
73 bool operator!=(
const FormatType_t &a)
const {
return !(*
this == a); }
74 bool valid()
const {
return value != 0; }
75 void invalidate() { value = 0; }
76 void check_valid(
const IR::MAU::Table *tbl =
nullptr)
const;
80 return (value & ~(ALL_ATTACHED * THIS_STAGE)) == THIS_STAGE || (value > 0 && value <= MASK);
83 bool matchEarlierStage()
const {
return value & EARLIER_STAGE; }
84 bool matchThisStage()
const {
return value & THIS_STAGE; }
85 bool matchLaterStage()
const {
return value & LATER_STAGE; }
87 int num_attached()
const {
return floor_log2(value) / 3; }
88 bool attachedEarlierStage(
int idx)
const {
return (value >> 3 * (idx + 1)) & EARLIER_STAGE; }
89 bool attachedThisStage(
int idx)
const {
return (value >> 3 * (idx + 1)) & THIS_STAGE; }
90 bool attachedLaterStage(
int idx)
const {
return (value >> 3 * (idx + 1)) & LATER_STAGE; }
91 bool anyAttachedEarlierStage()
const {
return (value & (ALL_ATTACHED * EARLIER_STAGE)) != 0; }
92 bool anyAttachedThisStage()
const {
return (value & (ALL_ATTACHED * THIS_STAGE)) != 0; }
93 bool anyAttachedLaterStage()
const {
return (value & (ALL_ATTACHED * LATER_STAGE)) != 0; }
96 void initialize(
const IR::MAU::Table *tbl,
int entries,
bool prev_stages,
99 static bool track(
const IR::MAU::AttachedMemory *at);
100 static std::vector<const IR::MAU::AttachedMemory *> tracking(
const IR::MAU::Table *);
101 static FormatType_t default_for_table(
const IR::MAU::Table *);
102 friend std::ostream &operator<<(std::ostream &,
FormatType_t);
103 std::string toString()
const;
109 enum addr_type_t { STATS, METER, ACTIONDATA, TYPES };
110 using TypeToAddressMap = std::map<addr_type_t, IR::MAU::Table::IndirectAddress>;
113 const IR::MAU::Table *tbl;
114 TypeToAddressMap &ind_addrs;
116 std::map<addr_type_t, const IR::MAU::BackendAttached *> users;
118 cstring addr_type_name(addr_type_t type) {
131 bool compatible(
const IR::MAU::BackendAttached *,
const IR::MAU::BackendAttached *);
132 void free_address(
const IR::MAU::AttachedMemory *am, addr_type_t type);
134 bool preorder(
const IR::MAU::Counter *cnt)
override;
135 bool preorder(
const IR::MAU::Meter *mtr)
override;
136 bool preorder(
const IR::MAU::StatefulAlu *salu)
override;
137 bool preorder(
const IR::MAU::Selector *as)
override;
138 bool preorder(
const IR::MAU::TernaryIndirect *)
override {
139 BUG(
"No ternary indirect should exist before table placement");
142 bool preorder(
const IR::MAU::ActionData *ad)
override;
143 bool preorder(
const IR::MAU::IdleTime *)
override {
return false; }
144 bool preorder(
const IR::Attached *att)
override {
145 BUG(
"Unknown attached table type %s",
typeid(*att).name());
150 : tbl(t), ind_addrs(ia) {}
189 std::vector<unsigned> _found;
190 unsigned _found_all = 0U;
193 auto rv = MauInspector::init_apply(node);
196 _found.resize(am_match.size());
200 bool preorder(
const IR::MAU::AttachedMemory *am) {
203 if (findContext<IR::MAU::Primitive>(ctxt)) {
204 BUG_CHECK(ctxt->child_index >= 0 && ctxt->child_index < 32,
"mask overflow");
205 mask <<= ctxt->child_index;
207 if (am_match.count(am)) {
208 _found[am_match.at(am)] |= mask;
216 void add(
const IR::MAU::AttachedMemory *am) {
217 if (!am_match.count(am)) {
218 unsigned idx = am_match.size();
223 for (
auto *a : am) add(a);
225 unsigned found()
const {
return _found_all; }
226 unsigned found(
const IR::MAU::AttachedMemory *am)
const {
return _found[am_match.at(am)]; }
227 auto begin()
const ->
decltype(Keys(am_match).begin()) {
return Keys(am_match).begin(); }
228 auto end()
const ->
decltype(Keys(am_match).end()) {
return Keys(am_match).end(); }
247 const IR::TempVar *index =
nullptr;
248 const IR::TempVar *enable =
nullptr;
249 const IR::TempVar *type =
nullptr;
251 std::map<cstring, IndexTemp> index_tempvars;
256 bool always_run_on_hit =
true;
258 bool always_run_on_miss =
true;
260 int address_bits = 0;
274 auto rv = PassManager::init_apply(node);
275 attached_to_table_map.clear();
276 address_info_per_table.clear();
286 bool preorder(
const IR::MAU::Table *)
override;
299 bool preorder(
const IR::MAU::Action *)
override;
305 class ValidateAttachedOfAllTables :
public MauInspector {
307 bool preorder(
const IR::MAU::Table *)
override;
315 addPasses({
new BuildSplitMaps(*
this),
new ValidateAttachedOfAllTables(*
this),
316 new EnableAndTypesOnActions(*
this)});
320 return attached_to_table_map.at(att->name);
324 int addr_bits_to_phv_on_split(
const IR::MAU::Table *tbl,
325 const IR::MAU::AttachedMemory *at)
const;
326 bool enable_to_phv_on_split(
const IR::MAU::Table *tbl,
const IR::MAU::AttachedMemory *at)
const;
327 int type_bits_to_phv_on_split(
const IR::MAU::Table *tbl,
328 const IR::MAU::AttachedMemory *at)
const;
330 const IR::MAU::Instruction *pre_split_addr_instr(
const IR::MAU::Action *act,
331 const IR::MAU::Table *tbl,
332 const IR::MAU::AttachedMemory *at);
333 const IR::MAU::Instruction *pre_split_enable_instr(
const IR::MAU::Action *act,
334 const IR::MAU::Table *tbl,
335 const IR::MAU::AttachedMemory *at);
336 const IR::MAU::Instruction *pre_split_type_instr(
const IR::MAU::Action *act,
337 const IR::MAU::Table *tbl,
338 const IR::MAU::AttachedMemory *at);
342 std::map<memo_key, const IR::MAU::Action *> cache;
345 const IR::Expression *split_enable(
const IR::MAU::AttachedMemory *,
const IR::MAU::Table *);
346 const IR::Expression *split_index(
const IR::MAU::AttachedMemory *,
const IR::MAU::Table *);
347 const IR::Expression *split_type(
const IR::MAU::AttachedMemory *,
const IR::MAU::Table *);
349 const IR::MAU::Action *get_split_action(
const IR::MAU::Action *act,
const IR::MAU::Table *tbl,
353 const IR::MAU::Action *create_split_action(
const IR::MAU::Action *act,
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24