160 static constexpr int NUM_LOGICAL_TABLES_PER_STAGE = 16;
161 static constexpr int FIRST_ALT_RETRY_ENHANCED_TP_INVOCATION = 2;
180 int entries_req = -1;
187 bool gateway_only =
false;
193 PlacedTable(
const IR::MAU::Table *t, State::state_t state,
const DependencyGraph &dg);
194 void add(
const IR::MAU::Table *t, State::state_t state);
196 friend std::ostream &operator<<(std::ostream &out,
const PlacedTable &pl);
204 friend std::ostream &operator<<(std::ostream &out, PlacementResult result) {
207 else if (result == FAIL)
209 else if (result == FAIL_ON_ADB)
210 out <<
"FAIL_ON_ADB";
211 else if (result == FAIL_ON_MEM)
212 out <<
"FAIL_ON_MEM";
214 out <<
"FAIL_ON_IXBAR";
219 static constexpr int CRITICAL_PATH_THRESHOLD = 2;
220 static constexpr int ALT_PHV_ALLOC_TABLE_FIX_THRESHOLD = 3;
223 bool firstRoundFit =
false;
224 Logging::FileLog *tsLog =
nullptr;
226 State::state_t prev_state = State::INITIAL;
231 bool ingressDone =
false;
232 bool egressDone =
false;
237 ordered_map<cstring, bool> tablePlacementErrors;
239 bool no_errors_before_summary =
true;
241 int alt_phv_alloc_table_fixed = 0;
244 const DependencyGraph &deps;
246 State::state_t &state;
250 ordered_map<cstring, ordered_set<int>> tableAlloc;
254 ordered_map<cstring, ordered_set<int>> internalTableAlloc;
256 ordered_map<cstring, std::pair<cstring, cstring>> mergedGateways;
258 ordered_map<cstring, cstring> tableNames;
260 ordered_map<cstring, cstring> tableINames;
262 static ordered_map<cstring, std::set<const IR::MAU::Table *>> tblName2IRptr;
265 std::map<int, PlacedTable *> placedTables;
273 ordered_map<cstring, ordered_set<int>> trivial_tableAlloc;
274 ordered_map<cstring, ordered_set<int>> trivial_internalTableAlloc;
275 ordered_map<cstring, std::pair<cstring, cstring>> trivial_mergedGateways;
276 std::map<int, PlacedTable *> trivial_placedTables;
278 ordered_map<int, ordered_map<cstring, int>> trivial_table_sram_alloc;
280 PlacementResult table_replay_result = FAIL;
282 ordered_map<int, const IR::MAU::Table *> trivial_table_info;
284 std::map<int, const IR::MAU::Table *> order;
286 std::map<int, std::set<const IR::MAU::Table *>> tables;
302 std::map<cstring, std::map<le_bitrange, std::map<int, int>>> ixbarBytes;
306 std::map<int, std::unique_ptr<IXBar>> ixbar[2];
308 std::map<int, std::unique_ptr<Memories>> memory[2];
310 std::map<int, std::unique_ptr<ActionDataBus>> action_data_bus[2];
312 std::map<int, std::unique_ptr<InstructionMemory>> imems[2];
314 std::map<cstring, unsigned> logical_ids;
317 StageUseEstimate allStages;
321 ordered_set<const IR::MAU::Table *> table_replay_fix_candidates;
322 const IR::MAU::Table *table_replay_problematic_table =
nullptr;
324 profile_t init_apply(
const IR::Node *root)
override;
325 bool preorder(
const IR::MAU::Table *t)
override;
326 void postorder(
const IR::BFN::Pipe *pipe)
override;
327 void end_apply()
override;
330 void printTablePlacement();
336 void generateIxbarBytesInfo();
341 bool find_problematic_table();
343 ordered_map<int, ordered_map<cstring, int>> collect_table_sram_alloc_info();
346 explicit TableSummary(
int pipe_id,
const DependencyGraph &dg,
const PhvInfo &phv,
347 State::state_t &state);
365 static void addTablePtr(
const IR::MAU::Table *ptr);
373 int maxStages(gress_t gress)
const {
return max_stages[gress]; }
375 const ordered_map<cstring, ordered_set<int>> &getTableAlloc(
void)
const {
return tableAlloc; }
378 void addPlacementError(cstring msg) { tablePlacementErrors[msg] =
true; }
379 void addPlacementWarnError(cstring msg) { tablePlacementErrors[msg] |=
false; }
380 void clearPlacementErrors() { tablePlacementErrors.clear(); }
381 int placementErrorCount() {
return tablePlacementErrors.size(); }
384 const ordered_map<cstring, bool> &getPlacementError() {
return tablePlacementErrors; }
385 void setPlacementError(
const ordered_map<cstring, bool> &tpe) { tablePlacementErrors = tpe; }
388 State::state_t getActualState()
const {
return state; }
389 void setPrevState() { state = prev_state; }
390 cstring getActualStateStr()
const;
391 void setAllStagesResources(
const StageUseEstimate &use) { allStages = use; }
392 StageUseEstimate getAllStagesResources()
const {
return allStages; }
394 std::map<int, PlacedTable *> &getPlacedTables() {
return placedTables; }
396 const IR::MAU::Table *get_table_replay_problematic_table()
const {
397 return table_replay_problematic_table;
399 int getNumInvoked()
const {
return numInvoked; }
416 std::map<int, int> findBytesOnIxbar(
const PHV::FieldSlice &slice)
const;
417 cstring ixbarUsagesStr(
const PhvInfo *phv =
nullptr)
const;
418 void printPlacedTables()
const;
419 void set_table_replay_result(PlacementResult result) { table_replay_result = result; }
421 PlacementResult get_table_replay_result()
const {
return table_replay_result; }
423 friend std::ostream &operator<<(std::ostream &out,
const TableSummary &ts);
424 friend std::ostream &operator<<(std::ostream &out,
425 ordered_map<int, const IR::MAU::Table *> &order);
428 void stop_table_replay_fitting()
const {
429 BUG_CHECK(state == State::ALT_FINALIZE_TABLE_SAME_ORDER_TABLE_FIXED,
430 "state is not intened for table replay fitting");
431 throw PHVTrigger::failure(trivial_tableAlloc, trivial_internalTableAlloc,
432 trivial_mergedGateways, firstRoundFit,
false,
false,
true);
436 void clear_table_alloc_info() {
438 internalTableAlloc.clear();
439 placedTables.clear();
442 bool is_table_replay() {
443 return state == State::ALT_FINALIZE_TABLE_SAME_ORDER ||
444 state == State::ALT_FINALIZE_TABLE_SAME_ORDER_TABLE_FIXED;