P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/tofino/bf-p4c/common/alias.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_ALIAS_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_ALIAS_H_
21
22#include "bf-p4c/bf-p4c-options.h"
23#include "bf-p4c/logging/pass_manager.h"
24#include "bf-p4c/phv/phv_fields.h"
25#include "bf-p4c/phv/pragma/pa_alias.h"
26#include "bf-p4c/phv/transforms/auto_alias.h"
27#include "ir/ir.h"
28
29using namespace P4;
30
35 private:
37 ordered_map<cstring, const IR::Member *> &fieldNameToExpressionsMap;
38
39 profile_t init_apply(const IR::Node *root) override;
40 bool preorder(const IR::HeaderOrMetadata *h) override;
41
42 public:
44 : fieldNameToExpressionsMap(f) {}
45};
46
52 private:
54 const PhvInfo &phv;
56 const PragmaAlias &pragmaAlias;
58 const ordered_map<cstring, const IR::Member *> &fieldExpressions;
59
60 profile_t init_apply(const IR::Node *root) override;
61 IR::Node *preorder(IR::BFN::Pipe *) override;
62 IR::Node *preorder(IR::Expression *expr) override;
63
64 public:
65 ReplaceAllAliases(const PhvInfo &p, const PragmaAlias &pragmaAlias,
67 : phv(p), pragmaAlias(pragmaAlias), fieldExpressions(f) {}
68};
69
75 private:
76 const PhvInfo &phv;
77 const PragmaAlias &pragmaAlias;
78
81
82 inline cstring getFieldValidityName(cstring origName);
83
84 profile_t init_apply(const IR::Node *root) override;
85 IR::Node *preorder(IR::MAU::Instruction *inst) override;
86 IR::Node *postorder(IR::MAU::Action *action) override;
87
88 public:
89 explicit AddValidityBitSets(const PhvInfo &p, const PragmaAlias &pa)
90 : phv(p), pragmaAlias(pa) {}
91};
92
102 private:
104 const PragmaAlias &pragmaAlias;
105
106 public:
107 explicit Alias(PhvInfo &phv, const PragmaAlias &pa)
108 : Logging::PassManager("pragmas"_cs, Logging::Mode::AUTO), pragmaAlias(pa) {
109 addPasses({new FindExpressionsForFields(phv, fieldExpressions),
110 new AddValidityBitSets(phv, pragmaAlias),
111 new ReplaceAllAliases(phv, pragmaAlias, fieldExpressions),
112 new VisitFunctor([this]() {
113 if (LOGGING(1)) {
114 LOG1(pragmaAlias.pretty_print());
115 }
116 })});
117 }
118};
119
122 PhvInfo &phv;
123
124 IR::Node *preorder(IR::BFN::AliasMember *alias) override {
125 const PHV::Field *aliasSource = phv.field(alias->source);
126 const PHV::Field *aliasDestination = phv.field(alias);
127 BUG_CHECK(aliasSource, "Field %1% not found", alias->source);
128 BUG_CHECK(aliasDestination, "Field %1% not found", alias);
129 phv.addAliasMapEntry(aliasSource, aliasDestination);
130 return alias->source->apply(ReinstateAliasSources(phv))->clone();
131 }
132
133 IR::Node *preorder(IR::BFN::AliasSlice *alias) override {
134 const PHV::Field *aliasSource = phv.field(alias->source);
135 const PHV::Field *aliasDestination = phv.field(alias);
136 BUG_CHECK(aliasSource, "Field %1% not found", alias->source);
137 BUG_CHECK(aliasDestination, "Field %1% not found", alias);
138 phv.addAliasMapEntry(aliasSource, aliasDestination);
139 return alias->source->apply(ReinstateAliasSources(phv))->clone();
140 }
141
142 public:
143 explicit ReinstateAliasSources(PhvInfo &p) : phv(p) {}
144};
145
146#endif /* BACKENDS_TOFINO_BF_P4C_COMMON_ALIAS_H_ */
Definition backends/tofino/bf-p4c/common/alias.h:74
Definition backends/tofino/bf-p4c/common/alias.h:101
Definition backends/tofino/bf-p4c/common/alias.h:34
Definition backends/tofino/bf-p4c/logging/pass_manager.h:36
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:424
Definition ir/pass_manager.h:184
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition phv_fields.h:154
Definition phv_fields.h:1095
void addAliasMapEntry(const PHV::Field *f1, const PHV::Field *f2)
Adds an entry to the aliasMap.
Definition phv_fields.h:1634
Definition pa_alias.h:38
Replace AliasMember and AliasSlice nodes with their alias sources.
Definition backends/tofino/bf-p4c/common/alias.h:121
Definition backends/tofino/bf-p4c/common/alias.h:51
@ AUTO
Creates if this is the first time writing to the log; otherwise, appends.
Definition filelog.h:43
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24