P4C
The P4 Compiler
Loading...
Searching...
No Matches
clot.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_CLOT_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_CLOT_H_
21
22#include <map>
23#include <set>
24#include <vector>
25
26#include "bf-p4c/ir/gress.h"
27#include "bf-p4c/lib/cmp.h"
28#include "lib/exceptions.h"
29#include "lib/ordered_map.h"
30
31using namespace P4;
32
33namespace P4 {
34namespace IR {
35namespace BFN {
36class ParserState;
37class FieldLVal;
38} // namespace BFN
39} // namespace IR
40} // namespace P4
41
42namespace PHV {
43class Field;
44class FieldSlice;
45} // namespace PHV
46
47namespace P4 {
48class cstring;
49class JSONGenerator;
50class JSONLoader;
51} // namespace P4
52
53class PhvInfo;
54
55using namespace P4;
56
57class Clot final : public LiftCompare<Clot> {
58 friend class ClotInfo;
59 friend class GreedyClotAllocator;
60
61 public:
63 Clot() : tag(0), gress(INGRESS) {}
64
65 explicit Clot(gress_t gress) : tag(tag_count[gress]++), gress(gress) {
66 BUG_CHECK(gress != GHOST, "Cannot assign CLOTs to ghost gress.");
67 }
68
69 explicit Clot(gress_t gress, unsigned tag) : tag(tag), gress(gress) {
70 BUG_CHECK(gress != GHOST, "Cannot assign CLOTs to ghost gress.");
71 }
72
73 explicit Clot(cstring);
74
75 cstring toString() const;
76
78 bool operator==(const Clot &clot) const { return tag == clot.tag && gress == clot.gress; }
79
81 bool operator<(const Clot &clot) const {
82 if (gress != clot.gress) return gress < clot.gress;
83 return tag < clot.tag;
84 }
85
87 void toJSON(JSONGenerator &json) const;
88 static Clot *fromJSON(JSONLoader &json);
89
91 unsigned tag;
92
94 gress_t gress;
95
96 const IR::BFN::FieldLVal *pov_bit = nullptr;
97
98 std::optional<unsigned> stack_depth = std::nullopt;
99
100 std::optional<unsigned> stack_inc = std::nullopt;
101
102 unsigned length_in_bytes(cstring parser_state) const;
103
107 unsigned bit_offset(cstring parser_state, const PHV::FieldSlice *slice) const;
108
112 unsigned byte_offset(cstring parser_state, const PHV::FieldSlice *slice) const;
113
116 bool is_phv_field(const PHV::Field *field) const;
117
119 bool is_checksum_field(const PHV::Field *field) const;
120
122 bool has_slice(const PHV::FieldSlice *slice) const;
123
125 bool is_first_field_in_clot(const PHV::Field *field) const;
126
128 std::optional<unsigned> csum_unit;
129
130 private:
131 void set_slices(cstring parser_state, const std::vector<const PHV::FieldSlice *> &slices);
132
133 enum FieldKind {
134 // Designates a modified field.
135 MODIFIED,
136
137 // Designates an unmodified field with a PHV allocation.
138 READONLY,
139
140 // Designates a field that is replaced with a checksum when deparsed.
141 CHECKSUM,
142
143 UNUSED
144 };
145
147 void add_slice(cstring parser_state, FieldKind kind, const PHV::FieldSlice *slice);
148
152 std::map<cstring, std::vector<const PHV::FieldSlice *>> parser_state_to_slices_;
153
154 std::map<const PHV::FieldSlice *, cstring> slice_to_parser_state_;
155
158
161 std::set<const PHV::Field *> phv_fields_;
162
164 std::set<const PHV::Field *> checksum_fields_;
165
166 public:
169 const std::map<cstring, std::vector<const PHV::FieldSlice *>> &parser_state_to_slices() const {
170 return parser_state_to_slices_;
171 }
172
175 return fields_to_slices_;
176 }
177
179 const std::set<const PHV::Field *> &checksum_fields() const { return checksum_fields_; }
180
181 std::map<const PHV::Field *, unsigned> checksum_field_to_checksum_id;
182
183 static std::map<gress_t, int> tag_count;
184};
185
186std::ostream &operator<<(std::ostream &out, const Clot &clot);
187std::ostream &operator<<(std::ostream &out, const Clot *clot);
188P4::JSONGenerator &operator<<(P4::JSONGenerator &out, const Clot &clot);
189P4::JSONGenerator &operator<<(P4::JSONGenerator &out, const Clot *clot);
190
191#endif /* BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_CLOT_H_ */
Definition clot.h:57
bool is_phv_field(const PHV::Field *field) const
Definition parde/clot/clot.cpp:125
const std::map< cstring, std::vector< const PHV::FieldSlice * > > & parser_state_to_slices() const
Definition clot.h:169
std::optional< unsigned > csum_unit
Indicates the checksum engine (if any) that will deposit in this CLOT.
Definition clot.h:128
gress_t gress
The gress to which this CLOT is assigned.
Definition clot.h:94
void toJSON(JSONGenerator &json) const
JSON serialization/deserialization.
Definition parde/clot/clot.cpp:196
Clot()
JSON deserialization constructor.
Definition clot.h:63
bool is_checksum_field(const PHV::Field *field) const
Definition parde/clot/clot.cpp:127
unsigned byte_offset(cstring parser_state, const PHV::FieldSlice *slice) const
Definition parde/clot/clot.cpp:121
bool operator==(const Clot &clot) const
Equality based on gress and tag.
Definition clot.h:78
const ordered_map< const PHV::Field *, const PHV::FieldSlice * > & fields_to_slices() const
Returns all fields that have slices in this CLOT, mapped to their corresponding slice.
Definition clot.h:174
static std::map< gress_t, int > tag_count
Definition clot.h:183
bool has_slice(const PHV::FieldSlice *slice) const
Definition parde/clot/clot.cpp:131
const std::set< const PHV::Field * > & checksum_fields() const
Returns all fields that need to be replaced by a checksum when deparsed.
Definition clot.h:179
unsigned bit_offset(cstring parser_state, const PHV::FieldSlice *slice) const
Definition parde/clot/clot.cpp:108
unsigned tag
Identifies the hardware CLOT associated with this object.
Definition clot.h:91
bool operator<(const Clot &clot) const
Lexicographic ordering according to (gress, tag).
Definition clot.h:81
bool is_first_field_in_clot(const PHV::Field *field) const
Definition parde/clot/clot.cpp:137
Definition clot_info.h:41
Definition cmp.h:84
Definition json_generator.h:36
Definition json_loader.h:38
Definition cstring.h:85
Definition ordered_map.h:32
Definition phv_fields.h:154
Definition phv_fields.h:898
Definition phv_fields.h:1095
Definition allocate_clot.cpp:40
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32