P4C
The P4 Compiler
Loading...
Searching...
No Matches
field_slice_extract_info.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_SLICE_EXTRACT_INFO_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_SLICE_EXTRACT_INFO_H_
21
22#include "backends/tofino/bf-p4c/parde/parser_info.h"
23#include "backends/tofino/bf-p4c/phv/phv_fields.h"
24#include "clot_candidate.h"
25#include "lib/ordered_map.h"
26
27using StatePair = std::pair<const IR::BFN::ParserState *, const IR::BFN::ParserState *>;
29
32 friend class GreedyClotAllocator;
33
36 // Invariant: all offsets here are congruent, modulo 8.
38
41 // Invariant: all offsets here are congruent, modulo 8.
42 std::map<unsigned, ordered_map<const IR::BFN::ParserState *, unsigned>>
43 stack_offset_state_bit_offsets_;
44
46 int min_packet_bit_offset_;
47
49 int max_packet_bit_offset_;
50
52 const PHV::FieldSlice *slice_;
53
54 public:
58 &stack_offset_state_bit_offsets,
60 : FieldSliceExtractInfo(state_bit_offsets, stack_offset_state_bit_offsets,
62 new PHV::FieldSlice(field)) {}
63
67 &stack_offset_state_bit_offsets,
69 : state_bit_offsets_(state_bit_offsets),
70 stack_offset_state_bit_offsets_(stack_offset_state_bit_offsets),
71 min_packet_bit_offset_(min_packet_bit_offset),
72 max_packet_bit_offset_(max_packet_bit_offset),
73 slice_(slice) {}
74
89 void update(const IR::BFN::ParserState *state, unsigned stack_offset, unsigned state_bit_offset,
91
94
97 int min_packet_bit_offset() const { return min_packet_bit_offset_; }
98
101 int max_packet_bit_offset() const { return max_packet_bit_offset_; }
102
106 return state_bit_offsets_;
107 }
108
110 unsigned state_bit_offset(const IR::BFN::ParserState *state) const {
111 return state_bit_offsets_.at(state);
112 }
113
115 unsigned bit_in_byte_offset() const {
116 auto offset = *Values(state_bit_offsets_).begin();
117 return offset % 8;
118 }
119
121 const PHV::FieldSlice *slice() const { return slice_; }
122
125
128
131
134
135 private:
137 const FieldSliceExtractInfo *trim_tail_bits(int size) const;
138
139 public:
148 const FieldSliceExtractInfo *trim(int lo_idx, int bits) const;
149
160 std::vector<const FieldSliceExtractInfo *> *remove_conflicts(
161 const CollectParserInfo &parserInfo, int preGapBits, const ClotCandidate *candidate,
162 int postGapBits) const;
163
172 const std::map<unsigned, StatePairSet> byte_gaps(const CollectParserInfo &parserInfo,
173 const FieldSliceExtractInfo *other) const;
174
182 const std::map<unsigned, StatePairSet> bit_gaps(const CollectParserInfo &parserInfo,
183 const FieldSliceExtractInfo *other) const;
184
185 friend bool operator==(const FieldSliceExtractInfo &, const FieldSliceExtractInfo &);
186
187 private:
188 friend std::ostream &operator<<(std::ostream &, const FieldSliceExtractInfo &);
189 friend std::ostream &operator<<(std::ostream &, const FieldSliceExtractInfo *);
190};
191
194 public:
195 typedef std::map<const Pseudoheader *, ordered_map<const PHV::Field *, FieldSliceExtractInfo *>,
196 Pseudoheader::Less>
197 PseudoheaderMap;
199 typedef std::map<cstring, std::map<const IR::BFN::ParserState *, std::set<unsigned>>>
200 HeaderStackMap;
201
203 PseudoheaderMap pseudoheaderMap;
204
207
209 // FIXME: Don't need to make sure that all or none of the indices extracted in a state
210 // are covered by CLOTs. If multiple are extracted in a single iteration, then potentionally
211 // only those at the same offset across all iterationsd need to be CLOTed/not CLOTed.
212 // e.g., if a state extracts 0 & 1, or 2 & 3, then it's probably okay if only 0 and 2 are
213 // CLOTed because they are both the first offset in the state being processed.
214 HeaderStackMap headerStackMap;
215
216 void updateFieldMap(const PHV::Field *field, const IR::BFN::ParserState *state,
217 unsigned stack_offset, unsigned state_bit_offset, int min_packet_bit_offset,
218 int max_packet_bit_offset) {
219 if (fieldMap.count(field)) {
220 fieldMap.at(field)->update(state, stack_offset, state_bit_offset, min_packet_bit_offset,
221 max_packet_bit_offset);
222 } else {
224 state_bit_offsets[state] = state_bit_offset;
225 std::map<unsigned, ordered_map<const IR::BFN::ParserState *, unsigned>>
226 stack_offset_state_bit_offsets;
227 stack_offset_state_bit_offsets[stack_offset][state] = state_bit_offset;
228 fieldMap[field] =
229 new FieldSliceExtractInfo(state_bit_offsets, stack_offset_state_bit_offsets,
230 min_packet_bit_offset, max_packet_bit_offset, field);
231 }
232 }
233
234 void updatePseudoheaderMap(const Pseudoheader *pseudoheader, const PHV::Field *field,
235 const IR::BFN::ParserState *state, unsigned stack_offset,
236 unsigned state_bit_offset, int min_packet_bit_offset,
237 int max_packet_bit_offset) {
238 if (pseudoheaderMap.count(pseudoheader) && pseudoheaderMap.at(pseudoheader).count(field)) {
239 auto *fei = pseudoheaderMap.at(pseudoheader).at(field);
240 fei->update(state, stack_offset, state_bit_offset, min_packet_bit_offset,
241 max_packet_bit_offset);
242 } else {
244 state_bit_offsets[state] = state_bit_offset;
245 std::map<unsigned, ordered_map<const IR::BFN::ParserState *, unsigned>>
246 stack_offset_state_bit_offsets;
247 stack_offset_state_bit_offsets[stack_offset][state] = state_bit_offset;
248 auto fei =
249 new FieldSliceExtractInfo(state_bit_offsets, stack_offset_state_bit_offsets,
250 min_packet_bit_offset, max_packet_bit_offset, field);
251
252 pseudoheaderMap[pseudoheader][field] = fei;
253 }
254 }
255
256 void updateHeaderStackMap(cstring header_stack, const IR::BFN::ParserState *state,
257 const std::set<unsigned> indices) {
258 headerStackMap[header_stack][state].insert(indices.begin(), indices.end());
259 }
260};
261
262#endif /* BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_SLICE_EXTRACT_INFO_H_ */
Definition clot_candidate.h:31
Summarizes parser extracts for all fields.
Definition field_slice_extract_info.h:193
HeaderStackMap headerStackMap
Maps all header stacks to the sets of indicies that could be extracted in each state.
Definition field_slice_extract_info.h:214
PseudoheaderMap pseudoheaderMap
Maps pseudoheaders to fields to their FieldSliceExtractInfo instances.
Definition field_slice_extract_info.h:203
FieldMap fieldMap
Maps all extracted fields to their FieldSliceExtractInfo instances.
Definition field_slice_extract_info.h:206
Holds information relating to a field slice's extract.
Definition field_slice_extract_info.h:31
const FieldSliceExtractInfo * trim_tail_to_max_clot_pos() const
Trims the end of the extract so that it does not extend past the maximum CLOT position.
Definition field_slice_extract_info.cpp:78
unsigned state_bit_offset(const IR::BFN::ParserState *state) const
Definition field_slice_extract_info.h:110
void update(const IR::BFN::ParserState *state, unsigned stack_offset, unsigned state_bit_offset, int min_packet_bit_offset, int max_packet_bit_offset)
Definition field_slice_extract_info.cpp:21
int min_packet_bit_offset() const
Definition field_slice_extract_info.h:97
std::vector< const FieldSliceExtractInfo * > * remove_conflicts(const CollectParserInfo &parserInfo, int preGapBits, const ClotCandidate *candidate, int postGapBits) const
Definition field_slice_extract_info.cpp:126
const PHV::FieldSlice * slice() const
Definition field_slice_extract_info.h:121
const FieldSliceExtractInfo * trim_tail_to_byte() const
Trims the end of the extract so that it is byte-aligned.
Definition field_slice_extract_info.cpp:73
const std::map< unsigned, StatePairSet > bit_gaps(const CollectParserInfo &parserInfo, const FieldSliceExtractInfo *other) const
Definition field_slice_extract_info.cpp:232
const std::map< unsigned, StatePairSet > byte_gaps(const CollectParserInfo &parserInfo, const FieldSliceExtractInfo *other) const
Definition field_slice_extract_info.cpp:212
const FieldSliceExtractInfo * trim(int lo_idx, int bits) const
Definition field_slice_extract_info.cpp:93
ordered_set< const IR::BFN::ParserState * > states() const
Definition field_slice_extract_info.cpp:49
unsigned bit_in_byte_offset() const
Definition field_slice_extract_info.h:115
const FieldSliceExtractInfo * trim_head_to_min_clot_pos() const
Trims the start of the extract so that it does not extend past the minimum CLOT position.
Definition field_slice_extract_info.cpp:62
const FieldSliceExtractInfo * trim_head_to_byte() const
Trims the start of the extract so that it is byte-aligned.
Definition field_slice_extract_info.cpp:55
int max_packet_bit_offset() const
Definition field_slice_extract_info.h:101
const ordered_map< const IR::BFN::ParserState *, unsigned > & state_bit_offsets() const
Definition field_slice_extract_info.h:105
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:154
Definition phv_fields.h:898
Definition pseudoheader.h:27
Definition allocate_clot.cpp:40