19#ifndef BF_P4C_PHV_V2_UTILS_V2_H_
20#define BF_P4C_PHV_V2_UTILS_V2_H_
28#include "backends/tofino/bf-p4c/phv/phv.h"
29#include "backends/tofino/bf-p4c/phv/phv_fields.h"
30#include "backends/tofino/bf-p4c/phv/utils/utils.h"
31#include "backends/tofino/bf-p4c/phv/v2/tx_score.h"
32#include "backends/tofino/bf-p4c/phv/v2/types.h"
33#include "lib/cstring.h"
34#include "lib/exceptions.h"
53 ACTION_CANNOT_BE_SYNTHESIZED,
55 CONTAINER_TYPE_MISMATCH,
57 CONTAINER_GRESS_MISMATCH,
59 CONTAINER_PARSER_WRITE_MODE_MISMATCH,
61 CONTAINER_PARSER_PACKING_INVALID,
63 FIELD_MAX_CONTAINER_BYTES_EXCEEDED,
65 ALIGNED_CLUSTER_NO_VALID_START,
67 ALIGNED_CLUSTER_CANNOT_BE_ALLOCATED,
69 NO_VALID_CONTAINER_SIZE,
71 NO_VALID_SC_ALLOC_ALIGNMENT,
73 WIDE_ARITH_ALLOC_FAILED,
78 INVALID_ALLOC_FOUND_BY_COPACKER,
82 CANNOT_APPLY_REQUIRED_COPACK_HINTS,
86cstring to_str(
const ErrorCode &e);
105 std::string str()
const;
109AllocError &operator<<(AllocError &e,
const T &v) {
110 std::stringstream ss;
116std::ostream &operator<<(std::ostream &out,
const AllocError &e);
122 std::optional<PHV::Transaction> tx;
125 bool ok()
const {
return err ==
nullptr; }
126 std::string err_str()
const;
127 std::string tx_str(
cstring prefix =
""_cs)
const;
155std::vector<ScAllocAlignment> make_sc_alloc_alignment(
157 const std::list<const SuperCluster::SliceList *> *sl_order =
nullptr);
186 const std::vector<const SuperCluster::SliceList *> *alloc_order_i = {};
201 std::ostream *tracer =
nullptr;
204 static constexpr const char *tab_table[] = {
205 "",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
207 static constexpr int max_log_level =
sizeof(tab_table) /
sizeof(tab_table[0]) - 1;
213 BUG_CHECK(sc_i,
"sc not added in ctx.");
223 BUG_CHECK(cont_group_i,
"container group not added in ctx.");
228 cloned.cont_group_i = cont_group;
232 const std::vector<const SuperCluster::SliceList *> *alloc_order()
const {
233 BUG_CHECK(alloc_order_i,
"sl alloc order not added in ctx.");
234 return alloc_order_i;
236 ScoreContext with_alloc_order(
const std::vector<const SuperCluster::SliceList *> *order)
const {
238 cloned.alloc_order_i = order;
243 BUG_CHECK(alloc_alignment_i,
"alloc alignment not added in ctx.");
244 return alloc_alignment_i;
248 cloned.alloc_alignment_i = alignment;
253 BUG_CHECK(score_i,
"score not added in ctx.");
258 cloned.score_i = score;
262 int t()
const {
return t_i; }
263 std::string t_tabs()
const {
return tab_table[t_i]; }
265 if (t > max_log_level) t = max_log_level;
271 const SearchConfig *search_config()
const {
return search_config_i; }
274 cloned.search_config_i = c;
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv/utils/utils.h:789
Definition phv/utils/utils.h:37
Definition phv/utils/utils.h:1049
Definition phv/utils/utils.h:561
ScoreContext is the allocation context that is updated and passed down during allocation.
Definition utils_v2.h:178
TxScoreMaker is the interface of the factory class of TxScore.
Definition tx_score.h:35
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Size
all possible PHV container sizes in BFN devices
Definition phv.h:110
ErrorCode
ErrorCode is the specific reason of failure of function invoke.
Definition backends/tofino/bf-p4c/phv/error.h:27
const ordered_set< const SuperCluster::SliceList * > * reslice_required
Definition utils_v2.h:102
const std::vector< AllocSlice > * invalid_packing
Definition utils_v2.h:97
Definition utils_v2.h:120
Definition utils_v2.h:134
std::optional< ScAllocAlignment > merge(const ScAllocAlignment &other) const
Definition utils_v2.cpp:163
cstring pretty_print(cstring prefix, const SuperCluster *sc) const
Definition utils_v2.cpp:237
ordered_map< const AlignedCluster *, int > cluster_starts
a cluster_alignment maps aligned cluster to start bit location in a container.
Definition utils_v2.h:136
bool empty() const
Definition utils_v2.h:147
bool ok(const AlignedCluster *aligned, int start) const
Definition utils_v2.h:143
a collection of allocation configurations that balances speed and performance of allocation.
Definition utils_v2.h:160
bool stop_first_succ_empty_normal_container
Definition utils_v2.h:171
int n_best_of_sc_alloc
Allocator will find the best score out of this number of allocation for a super cluster.
Definition utils_v2.h:167
bool try_byte_aligned_starts_first_for_table_keys
For table match key fields, try byte-aligned container starts first.
Definition utils_v2.h:174
int n_dfs_steps_sc_alloc
Definition utils_v2.h:164
Definition common/field_defuse.cpp:590