P4C
The P4 Compiler
Loading...
Searching...
No Matches
auto_alias.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_
21
22#include "backends/tofino/bf-p4c/phv/phv_fields.h"
23#include "backends/tofino/bf-p4c/phv/pragma/pa_alias.h"
24#include "backends/tofino/bf-p4c/phv/pragma/pa_no_overlay.h"
25#include "lib/bitvec.h"
26
28 private:
29 const PhvInfo &phv;
31 ordered_set<cstring> headersValidatedInParser;
33 ordered_set<cstring> allHeaders;
34
35 profile_t init_apply(const IR::Node *root) override;
36 bool preorder(const IR::BFN::Extract *extract) override;
37 bool preorder(const IR::MAU::Instruction *inst) override;
38 void end_apply() override;
39
40 public:
41 explicit DetermineCandidateHeaders(const PhvInfo &p) : phv(p) {}
42
43 const ordered_set<cstring> getCandidateHeaders() const {
44 ordered_set<cstring> headerSet;
45 for (auto &kv : headers) headerSet.insert(kv.first);
46 return headerSet;
47 }
48
49 bool isCandidateHeader(cstring header) const { return headers.count(header); }
50
51 const ordered_set<const IR::MAU::Action *> &getActionsForCandidateHeader(cstring header) const {
53 if (!isCandidateHeader(header)) return actions;
54 return headers.at(header);
55 }
56};
57
60
61 const PhvInfo &phv;
62
63 bool preorder(const IR::MAU::Instruction *inst) override {
64 if (inst->operands.empty()) return true;
65 auto dest = phv.field(inst->operands[0]);
66 if (!dest) return true;
67 dest_to_inst[dest].insert(inst);
68 return true;
69 }
70
71 explicit MapDestToInstruction(const PhvInfo &p) : phv(p) {}
72};
73
75 private:
76 const PhvInfo &phv;
77 const DetermineCandidateHeaders &headers;
78 PragmaAlias &pragma;
79 PragmaNoOverlay &no_overlay;
80 const MapDestToInstruction &d2i;
81
82 ordered_set<const PHV::Field *> initialCandidateSet;
83 ordered_map<const PHV::Field *,
85 candidateSources;
86
87 inline void dropFromCandidateSet(const PHV::Field *field);
88 bool multipleSourcesFound(const PHV::Field *dest, const PHV::Field *src) const;
89 bool incompatibleConstraints(const PHV::Field *dest, const PHV::Field *src) const;
90
91 profile_t init_apply(const IR::Node *root) override;
92 bool preorder(const IR::MAU::Instruction *inst) override;
93 void end_apply() override;
94
95 public:
97 PragmaAlias &pa, PragmaNoOverlay &no_ovrl,
98 const MapDestToInstruction &d)
99 : phv(p), headers(h), pragma(pa), no_overlay(no_ovrl), d2i(d) {}
100};
101
102class AutoAlias : public PassManager {
103 private:
105
108
109 public:
110 explicit AutoAlias(const PhvInfo &phv, PragmaAlias &pa, PragmaNoOverlay &no_ovrl)
111 : d2i(phv), headers(phv), fields(phv, headers, pa, no_ovrl, d2i) {
112 addPasses({&d2i, &headers, &fields});
113 }
114};
115
116#endif /* BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_ */
Definition auto_alias.h:102
Definition auto_alias.h:74
Definition auto_alias.h:27
Definition node.h:94
Definition visitor.h:400
Definition ir/pass_manager.h:40
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:154
Definition phv_fields.h:1095
Definition pa_alias.h:38
Definition pa_no_overlay.h:33
Definition auto_alias.h:58