P4C
The P4 Compiler
Loading...
Searching...
No Matches
instruction_adjustment.h
1
19#ifndef BF_P4C_MAU_INSTRUCTION_ADJUSTMENT_H_
20#define BF_P4C_MAU_INSTRUCTION_ADJUSTMENT_H_
21
22#include <fstream>
23
24#include "backends/tofino/bf-p4c/ir/tofino_write_context.h"
25#include "backends/tofino/bf-p4c/mau/action_analysis.h"
26#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
27#include "backends/tofino/bf-p4c/mau/resource.h"
28#include "backends/tofino/bf-p4c/mau/tofino/input_xbar.h"
29#include "backends/tofino/bf-p4c/phv/phv.h"
30#include "lib/safe_vector.h"
31
32using namespace P4;
33
34namespace PHV {
35class Field;
36} // namespace PHV
37
68 const PhvInfo &phv;
69
70 const IR::Node *preorder(IR::MAU::Instruction *) override;
71 // ignore stuff related to stateful alus
72 const IR::Node *preorder(IR::MAU::AttachedOutput *ao) override {
73 prune();
74 return ao;
75 }
76 const IR::Node *preorder(IR::MAU::StatefulAlu *salu) override {
77 prune();
78 return salu;
79 }
80 const IR::Node *preorder(IR::MAU::HashDist *hd) override {
81 prune();
82 return hd;
83 }
84
85 public:
86 explicit AdjustShiftInstructions(const PhvInfo &p) : phv(p) {}
87};
88
137 const PhvInfo &phv;
138
139 const IR::Node *preorder(IR::MAU::Instruction *) override;
140 // ignore stuff related to stateful alus
141 const IR::Node *preorder(IR::MAU::AttachedOutput *ao) override {
142 prune();
143 return ao;
144 }
145 const IR::Node *preorder(IR::MAU::StatefulAlu *salu) override {
146 prune();
147 return salu;
148 }
149 const IR::Node *preorder(IR::MAU::HashDist *hd) override {
150 prune();
151 return hd;
152 }
153
154 public:
155 explicit SplitInstructions(const PhvInfo &p) : phv(p) {}
156};
157
163 const PhvInfo &phv;
164 const ReductionOrInfo &red_info;
165 ActionAnalysis::ContainerActionsMap container_actions_map;
166
167 const IR::MAU::Action *preorder(IR::MAU::Action *) override;
168 const IR::MAU::Instruction *preorder(IR::MAU::Instruction *) override;
169 const IR::MAU::ActionArg *preorder(IR::MAU::ActionArg *) override;
170 const IR::Expression *preorder(IR::Expression *) override;
171 const IR::Constant *preorder(IR::Constant *) override;
172 const IR::Slice *preorder(IR::Slice *) override;
173 void analyze_phv_field(IR::Expression *);
174 const IR::MAU::Primitive *preorder(IR::MAU::Primitive *) override;
175 const IR::MAU::Instruction *postorder(IR::MAU::Instruction *) override;
176 const IR::MAU::Action *postorder(IR::MAU::Action *) override;
177
178 const IR::MAU::AttachedOutput *preorder(IR::MAU::AttachedOutput *) override;
179 const IR::MAU::StatefulAlu *preorder(IR::MAU::StatefulAlu *) override;
180 const IR::MAU::HashDist *preorder(IR::MAU::HashDist *) override;
181 const IR::Node *preorder(IR::Node *) override;
182 bool has_constant = false;
183 bool write_found = false;
184 ordered_set<PHV::Container> constant_containers;
185 // ActionFormat::ArgKey constant_renames_key;
186 ActionData::UniqueLocationKey constant_rename_key;
187 cstring action_name;
188
189 public:
190 ConstantsToActionData(const PhvInfo &p, const ReductionOrInfo &ri) : phv(p), red_info(ri) {
191 visitDagOnce = false;
192 }
193};
194
196 const PhvInfo &phv;
197 const ReductionOrInfo &red_info;
198 ActionAnalysis::ContainerActionsMap container_actions_map;
199 ordered_set<PHV::Container> expr_to_hash_containers;
200
201 const IR::MAU::Action *preorder(IR::MAU::Action *) override;
202 const IR::MAU::Instruction *preorder(IR::MAU::Instruction *) override;
203 const IR::Node *preorder(IR::Node *n) override {
204 visitOnce();
205 return n;
206 }
207 const IR::MAU::StatefulAlu *preorder(IR::MAU::StatefulAlu *s) override {
208 prune();
209 return s;
210 }
211
212 public:
213 ExpressionsToHash(const PhvInfo &p, const ReductionOrInfo &ri) : phv(p), red_info(ri) {
214 visitDagOnce = false;
215 }
216};
217
232 private:
233 struct ByteRotateMergeInfo {
234 int src1_shift = 0;
235 int src2_shift = 0;
236 bitvec src1_byte_mask;
237 };
238
239 bool saturationArith = false;
240
241 const PhvInfo &phv;
242 const ReductionOrInfo &red_info;
243 ActionAnalysis::ContainerActionsMap container_actions_map;
244
245 const IR::MAU::Action *preorder(IR::MAU::Action *) override;
246 const IR::MAU::Instruction *preorder(IR::MAU::Instruction *) override;
247 const IR::Expression *preorder(IR::Expression *) override;
248 const IR::Slice *preorder(IR::Slice *) override;
249 void analyze_phv_field(IR::Expression *);
250 const IR::MAU::ActionDataConstant *preorder(IR::MAU::ActionDataConstant *) override;
251 const IR::MAU::ActionArg *preorder(IR::MAU::ActionArg *) override;
252 const IR::Constant *preorder(IR::Constant *) override;
253 const IR::MAU::Primitive *preorder(IR::MAU::Primitive *) override;
254
255 const IR::MAU::AttachedOutput *preorder(IR::MAU::AttachedOutput *ao) override;
256 const IR::MAU::StatefulAlu *preorder(IR::MAU::StatefulAlu *salu) override;
257 const IR::MAU::HashDist *preorder(IR::MAU::HashDist *hd) override;
258
259 const IR::Node *preorder(IR::Node *) override;
260 const IR::MAU::Instruction *postorder(IR::MAU::Instruction *) override;
261 const IR::MAU::Action *postorder(IR::MAU::Action *) override;
262
263 ordered_set<PHV::Container> merged_fields;
264
265 bool write_found = false;
266 ordered_set<PHV::Container>::iterator merged_location;
267
268 IR::MAU::Instruction *dest_slice_to_container(PHV::Container container,
270
271 void build_actiondata_source(ActionAnalysis::ContainerAction &cont_action,
272 const IR::Expression **src1_p, bitvec &src1_writebits,
273 ByteRotateMergeInfo &brm_info, PHV::Container container);
274 void build_phv_source(ActionAnalysis::ContainerAction &cont_action,
275 const IR::Expression **src1_p, const IR::Expression **src2_p,
276 bitvec &src1_writebits, bitvec &src2_writebits,
277 ByteRotateMergeInfo &brm_info, PHV::Container container);
278
279 IR::MAU::Instruction *build_merge_instruction(PHV::Container container,
281 void fill_out_write_multi_operand(ActionAnalysis::ContainerAction &cont_action,
282 IR::MAU::MultiOperand *mo);
283 void fill_out_read_multi_operand(ActionAnalysis::ContainerAction &cont_action,
284 ActionAnalysis::ActionParam::type_t type, cstring match_name,
285 IR::MAU::MultiOperand *mo);
286 const IR::Expression *fill_out_hash_operand(PHV::Container container,
288 const IR::Expression *fill_out_rand_operand(PHV::Container container,
290 const IR::Constant *find_field_action_constant(ActionAnalysis::ContainerAction &cont_action);
291
292 public:
293 MergeInstructions(const PhvInfo &p, const ReductionOrInfo &ri) : phv(p), red_info(ri) {
294 visitDagOnce = false;
295 }
296};
297
299 private:
300 const PhvInfo &phv;
301 const IR::Expression *preorder(IR::Expression *expr) override;
302 const IR::Annotation *preorder(IR::Annotation *) override;
303 const IR::MAU::IXBarExpression *preorder(IR::MAU::IXBarExpression *) override;
304
305 bool check_bit_positions(std::map<int, le_bitrange> &salu_inputs, le_bitrange field_bits,
306 int starting_bit);
307 bool verify_on_search_bus(const IR::MAU::StatefulAlu *, const Tofino::IXBar::Use &salu_ixbar,
308 const PHV::Field *field, le_bitrange &bits, bool &is_hi);
309 bool verify_on_hash_bus(const IR::MAU::StatefulAlu *salu,
310 const Tofino::IXBar::Use::MeterAluHash &mah, const IR::Expression *expr,
311 le_bitrange &bits, bool &is_hi);
312
313 public:
314 explicit AdjustStatefulInstructions(const PhvInfo &p) : phv(p) {}
315};
316
317// Remove instructions which are effectively Noops in the code
318// This class is when run post phv allocation can determine if an instruction is not performing an
319// actual operation e.g. OR A, A, A / AND A, A, A
321 private:
322 enum OP_TYPE { DST = 0, SRC1 = 1, SRC2 = 2 };
323 const PhvInfo &phv;
324 typedef std::set<std::pair<PHV::Container, le_bitrange>> AllocContainerSlice;
325 bool get_alloc_slice(IR::MAU::Instruction *ins, OP_TYPE type,
326 AllocContainerSlice &op_alloc) const;
327 const IR::MAU::Instruction *preorder(IR::MAU::Instruction *) override;
328 const IR::MAU::Synth2Port *preorder(IR::MAU::Synth2Port *s) override;
329 cstring toString(OP_TYPE ot) const {
330 if (ot == DST)
331 return "DST"_cs;
332 else if (ot == SRC1)
333 return "SRC1"_cs;
334 else if (ot == SRC2)
335 return "SRC2"_cs;
336 return "-"_cs;
337 }
338
339 public:
340 explicit EliminateNoopInstructions(const PhvInfo &p) : phv(p) {}
341};
342
344 public:
345 InstructionAdjustment(const PhvInfo &p, const ReductionOrInfo &ri);
346};
347
348#endif /* BF_P4C_MAU_INSTRUCTION_ADJUSTMENT_H_ */
Definition instruction_adjustment.h:67
Definition instruction_adjustment.h:298
Definition instruction_adjustment.h:162
Definition instruction_adjustment.h:320
Definition instruction_adjustment.h:195
Definition instruction_adjustment.h:343
InstructionAdjustment(const PhvInfo &p, const ReductionOrInfo &ri)
Definition instruction_adjustment.cpp:1805
Definition mau_visitor.h:55
Definition instruction_adjustment.h:231
Definition node.h:94
Definition ir/pass_manager.h:40
Definition bitvec.h:120
Definition cstring.h:85
Definition ordered_set.h:32
Definition phv.h:176
Definition phv_fields.h:154
Definition phv_fields.h:1095
Definition instruction_adjustment.h:136
Definition tofino_write_context.h:24
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
Definition action_analysis.h:346
Definition action_format.h:454
Definition reduction_or.h:47
Definition tofino/input_xbar.h:225
Definition tofino/input_xbar.h:192