P4C
The P4 Compiler
Loading...
Searching...
No Matches
parser_packing_validator.h
1
19#ifndef BF_P4C_PHV_V2_PARSER_PACKING_VALIDATOR_H_
20#define BF_P4C_PHV_V2_PARSER_PACKING_VALIDATOR_H_
21
22#include "backends/tofino/bf-p4c/common/field_defuse.h"
23#include "backends/tofino/bf-p4c/lib/assoc.h"
24#include "backends/tofino/bf-p4c/parde/parser_info.h"
25#include "backends/tofino/bf-p4c/phv/parser_packing_validator_interface.h"
26#include "backends/tofino/bf-p4c/phv/phv_fields.h"
27#include "backends/tofino/bf-p4c/phv/pragma/phv_pragmas.h"
28#include "backends/tofino/bf-p4c/phv/v2/utils_v2.h"
29#include "ir/ir.h"
30
31namespace PHV {
32namespace v2 {
33
43 private:
44 using StateExtract = std::pair<const IR::BFN::ParserState *, const IR::BFN::Extract *>;
45 using StatePrimitiveMap =
47 const PhvInfo &phv_i;
48 const MapFieldToParserStates &parser_i;
49 const CollectParserInfo &parser_info_i;
50 const FieldDefUse &defuse_i;
51 const PragmaNoInit &pa_no_init_i;
52 mutable bool is_trivial_pass = false;
53 mutable bool is_trivial_alloc = false;
54 std::set<FieldRange> &mauInitFields;
55
56 // The cache does not affect behaviour, only speed. Therefore we make it mutable to make it
57 // possible to use it from a (semantically) const method.
59 std::vector<const IR::BFN::ParserPrimitive *>>
60 state_extracts_cache;
61
63 StatePrimitiveMap get_primitives(const FieldSlice &fs) const;
64
67 bool parser_zero_init(const Field *f) const {
68 return (defuse_i.hasUninitializedRead(f->id) && !pa_no_init_i.getFields().count(f));
69 }
70
72 bool allow_clobber(const Field *f) const;
73
75 bool is_parser_error(const Field *f) const;
76
78 const AllocError *will_buf_extract_clobber_the_other(
79 const FieldSlice &fs, const StateExtract &state_extract, const int cont_idx,
80 const FieldSlice &other_fs, const StatePrimitiveMap &other_extracts,
81 const int other_cont_idx, bool add_mau_inits) const;
82
84 const AllocError *will_a_extracts_clobber_b(const FieldSliceStart &a, const FieldSliceStart &b,
85 bool add_mau_inits) const;
86
87 public:
88 explicit ParserPackingValidator(const PhvInfo &phv, const MapFieldToParserStates &parser,
89 const CollectParserInfo &parser_info, const FieldDefUse &defuse,
90 const PragmaNoInit &pa_no_init,
91 std::set<FieldRange> &mauInitFields)
92 : phv_i(phv),
93 parser_i(parser),
94 parser_info_i(parser_info),
95 defuse_i(defuse),
96 pa_no_init_i(pa_no_init),
97 mauInitFields(mauInitFields) {}
98
101 const AllocError *can_pack(const FieldSliceStart &a, const FieldSliceStart &b,
102 bool add_mau_inits = false) const;
103
106 const AllocError *can_pack(const FieldSliceAllocStartMap &alloc,
107 bool add_mau_inits = false) const override;
108
109 // Marks current iteration as trivial allocation iteration
110 void set_trivial_pass(bool trivial) const;
111 // Marks the allocation part of a trivial allocation
112 void set_trivial_alloc(bool trivial) const;
113};
114} // namespace v2
115} // namespace PHV
116
117#endif /* BF_P4C_PHV_V2_PARSER_PACKING_VALIDATOR_H_ */
Definition ordered_map.h:32
Definition phv_fields.h:154
int id
Unique field ID.
Definition phv_fields.h:164
Definition phv_fields.h:898
Definition parser_packing_validator_interface.h:26
Definition parser_packing_validator.h:42
const AllocError * can_pack(const FieldSliceStart &a, const FieldSliceStart &b, bool add_mau_inits=false) const
Definition parser_packing_validator.cpp:260
Definition phv_fields.h:1095
Definition assoc.h:403
const ordered_set< const PHV::Field * > & getFields() const
Definition pa_no_init.h:61
Adds the no_init pragma to the specified fields with the specified gress.
Definition pa_no_init.h:35
Definition field_defuse.h:77
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Map field to the parser states in which they are extracted or assigned from checksums.
Definition phv_fields.h:1755
Definition utils_v2.h:92