19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_CLOT_INFO_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_CLOT_INFO_H_
24#include "bf-p4c/lib/assoc.h"
25#include "bf-p4c/lib/cmp.h"
26#include "bf-p4c/logging/filelog.h"
27#include "bf-p4c/parde/clot/pragma/do_not_use_clot.h"
28#include "bf-p4c/parde/dump_parser.h"
29#include "bf-p4c/parde/parde_visitor.h"
30#include "bf-p4c/phv/phv_parde_mau_use.h"
32#include "deparse_graph.h"
33#include "field_slice_set.h"
34#include "lib/ordered_map.h"
35#include "pseudoheader.h"
54 parser_state_to_fields_;
59 parser_state_to_header_stacks_;
64 header_stack_elements_;
69 std::unordered_map<const IR::BFN::ParserState *, const IR::BFN::ParserRVal *>>
70 field_to_parser_states_;
82 std::set<const PHV::Field *> checksum_dests_;
83 std::map<const PHV::Field *, std::vector<const IR::BFN::EmitChecksum *>>
84 field_to_checksum_updates_;
86 std::vector<Clot *> clots_;
87 std::map<const Clot *, std::pair<gress_t, std::set<cstring>>, Clot::Less>
88 clot_to_parser_states_;
91 std::map<gress_t, std::map<cstring, std::set<const Clot *>>> parser_state_to_clots_;
93 std::map<const IR::BFN::ParserState *, ordered_map<const PHV::Field *, nw_bitrange>>
96 std::map<const Clot *, std::vector<const IR::BFN::EmitChecksum *>> clot_to_emit_checksum_;
99 std::map<const PHV::Field *, std::set<const PHV::Field *> *> field_aliases_;
102 std::set<cstring> headers_added_by_mau_;
105 std::map<const PHV::Field *, std::set<const Pseudoheader *>> field_to_pseudoheaders_;
107 std::map<gress_t, DeparseGraph> deparse_graph_;
110 std::map<const PHV::Field *, PovBitSet> fields_to_pov_bits_;
116 unsigned num_clots_allocated(gress_t gress)
const {
return Clot::tag_count.at(gress); }
119 std::optional<nw_bitrange> field_range(
const IR::BFN::ParserState *state,
123 std::optional<unsigned> offset(
const IR::BFN::ParserState *state,
138 parser_state_to_fields()
const {
139 return parser_state_to_fields_;
143 parser_state_to_header_stacks()
const {
144 return parser_state_to_header_stacks_;
148 std::set<unsigned>> &
149 header_stack_elements() {
150 return header_stack_elements_;
157 const std::map<const Clot *, std::pair<gress_t, std::set<cstring>>, Clot::Less> &
158 clot_to_parser_states()
const {
159 return clot_to_parser_states_;
162 std::map<cstring, std::set<const Clot *>> &parser_state_to_clots(gress_t gress) {
163 return parser_state_to_clots_.at(gress);
166 const std::map<cstring, std::set<const Clot *>> &parser_state_to_clots(gress_t gress)
const {
167 return parser_state_to_clots_.at(gress);
170 const std::set<const Clot *> parser_state_to_clots(
171 const IR::BFN::LoweredParserState *state)
const;
173 const Clot *parser_state_to_clot(
const IR::BFN::LoweredParserState *state,
unsigned tag)
const;
175 const std::vector<Clot *> &clots() {
return clots_; }
177 const std::map<const PHV::Field *, std::vector<const IR::BFN::EmitChecksum *>> &
178 field_to_checksum_updates() {
179 return field_to_checksum_updates_;
189 std::map<const Clot *, std::vector<const IR::BFN::EmitChecksum *>> &clot_to_emit_checksum() {
190 return clot_to_emit_checksum_;
193 const std::map<const Clot *, std::vector<const IR::BFN::EmitChecksum *>> &
194 clot_to_emit_checksum()
const {
195 return clot_to_emit_checksum_;
207 void add_field(
const PHV::Field *f,
const IR::BFN::ParserRVal *source,
208 const IR::BFN::ParserState *state);
210 void add_stack(
const IR::HeaderStack *hs,
const IR::BFN::ParserState *state,
int index = -1);
213 void compute_byte_maps();
226 bool is_used_in_multiple_checksum_update_sets(
const PHV::Field *field)
const;
229 bool is_extracted_in_multiple_non_mutex_states(
const PHV::Field *f)
const;
232 bool extracted_with_pov(
const PHV::Field *field)
const;
236 bool has_consistent_bit_in_byte_offset(
const PHV::Field *field)
const;
240 bool can_be_in_clot(
const PHV::Field *field)
const;
251 bool extracts_full_width(
const PHV::Field *field)
const;
254 mutable std::map<const PHV::Field *, bool> is_modified_;
344 void crop(
Clot *clot,
cstring parser_state,
unsigned start_bits,
unsigned end_bits);
346 void crop(
Clot *clot,
cstring parser_state,
unsigned num_bits,
bool from_start);
374 template <Endian Order = Endian::Network>
384 template <Endian Order = Endian::Network>
411 std::string print(
const PhvInfo *phvInfo =
nullptr)
const;
427 std::pair<unsigned, ordered_set<const IR::BFN::ParserState *> *> *find_largest_paths(
428 const std::map<
cstring, std::set<const Clot *>> &parser_state_to_clots,
430 std::map<
const IR::BFN::ParserState *,
447 : phv(phv), clotInfo(clotInfo), pragmaDoNotUseClot(pragmaDoNotUseClot) {}
453 bool preorder(
const IR::BFN::Extract *extract)
override;
454 bool preorder(
const IR::BFN::ParserZeroInit *zero_init)
override;
457 bool preorder(
const IR::HeaderStackItemRef *hs)
override;
460 bool preorder(
const IR::BFN::EmitField *emit)
override;
464 bool preorder(
const IR::BFN::EmitChecksum *emit)
override;
467 void postorder(
const IR::BFN::Deparser *deparser)
override;
473 void add_pseudoheader(
474 const PovBitSet pov_bits,
const std::vector<const PHV::Field *> fields,
475 std::map<std::pair<
const PovBitSet,
const std::vector<const PHV::Field *>>,
479 bool preorder(
const IR::BFN::AliasMember *alias)
override {
480 add_alias_field(alias);
485 bool preorder(
const IR::BFN::AliasSlice *alias)
override {
486 add_alias_field(alias);
490 void add_alias_field(
const IR::Expression *alias);
493 bool preorder(
const IR::MAU::Instruction *instruction)
override;
495 void end_apply(
const IR::Node *root)
override;
Definition allocate_clot.h:26
Definition clot_candidate.h:31
static std::map< gress_t, int > tag_count
Definition clot.h:183
Definition clot_info.h:41
bool clot_covers_slice(const Clot *clot, const PHV::FieldSlice *slice) const
Definition clot_info.cpp:931
assoc::map< const PHV::FieldSlice *, Clot *, PHV::FieldSlice::Greater > * allocated_slices(const PHV::FieldSlice *slice) const
Definition clot_info.h:297
bool is_slice_below_min_offset(const PHV::FieldSlice *slice, int max_packet_bit_offset) const
Definition clot_info.cpp:420
bool is_added_by_mau(cstring h) const
Determines whether h is a header that might be added by MAU.
Definition clot_info.cpp:908
std::set< const Clot *, Clot::Less > * fully_allocated(const PHV::FieldSlice &slice) const
Definition clot_info.h:313
assoc::map< const PHV::FieldSlice *, Clot *, PHV::FieldSlice::Greater > * slice_clots(const PHV::FieldSlice *slice) const
Definition clot_info.cpp:910
const std::set< const PHV::Field * > * clot_eligible_fields() const
Produces the set of CLOT-eligible fields.
Definition clot_info.cpp:589
bool allocated_unmodified_undigested(const PHV::Field *field) const
Definition clot_info.h:327
cstring sanitize_state_name(cstring state_name, gress_t gress) const
Definition clot_info.cpp:59
const Clot * fully_allocated(const PHV::Field *field) const
Definition clot_info.h:304
bool is_modified(const PHV::Field *field) const
Definition clot_info.cpp:526
bool slice_overwritten(const PhvInfo &phvInfo, const Clot *clot, const PHV::FieldSlice *f) const
Definition clot_info.cpp:796
bool slice_overwritten_by_phv(const PhvInfo &phvInfo, const Clot *clot, const PHV::FieldSlice *f) const
Definition clot_info.cpp:801
bool is_checksum(const PHV::Field *field) const
Determines whether a field is a checksum field.
Definition clot_info.cpp:520
std::map< int, PHV::Container > get_overwrite_containers(const Clot *clot, const PhvInfo &phv) const
Definition clot_info.cpp:108
bool is_readonly(const PHV::Field *field) const
Definition clot_info.cpp:575
std::map< int, const PHV::Field * > get_csum_fields(const Clot *clot) const
Definition clot_info.cpp:159
std::set< const PHV::Field * > pov_extracted_without_fields
Definition clot_info.h:155
assoc::map< const PHV::FieldSlice *, Clot *, PHV::FieldSlice::Greater > * allocated_slices(const PHV::Field *field) const
Definition clot_info.h:282
void adjust_clots(const PhvInfo &phv)
Definition clot_info.cpp:626
Clot * whole_field_clot(const PHV::Field *field) const
Definition clot_info.cpp:925
bool is_unused(const PHV::Field *field) const
Definition clot_info.cpp:583
assoc::map< const PHV::FieldSlice *, Clot *, PHV::FieldSlice::Greater > * slice_clots(const PHV::Field *field) const
Definition clot_info.h:399
void merge_parser_states(gress_t gress, cstring dst_state_name, cstring src_state_name)
Definition clot_info.cpp:180
Implements comparisons correctly.
Definition field_slice_set.h:25
A FileLog is used to redirect the logging output of a visitor pass to a file.
Definition filelog.h:48
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:154
Definition phv_fields.h:898
const PHV::Field * field() const override
Definition phv_fields.h:977
Definition phv_fields.h:1095
Definition phv_parde_mau_use.h:154
do_not_use_clot pragma support.
Definition do_not_use_clot.h:37
Definition clot_info.h:438
Definition allocate_clot.cpp:40
Definition parser_info.h:186