P4C
The P4 Compiler
Loading...
Searching...
No Matches
header_stack.h
1
19#ifndef BF_P4C_COMMON_HEADER_STACK_H_
20#define BF_P4C_COMMON_HEADER_STACK_H_
21
22#include "ir/ir.h"
23#include "ir/pass_manager.h"
24#include "lib/map.h"
25
26using namespace P4;
27
28class PhvInfo;
29
38
39 private:
40 Visitor::profile_t init_apply(const IR::Node *root) override;
41 void postorder(IR::HeaderStack *stack) override;
42 void postorder(IR::MAU::Primitive *primitive) override;
43 void postorder(IR::BFN::Pipe *pipe) override;
44
46};
47
52
53 // Find unused headers.
54 struct Find : public Inspector {
56 const BFN::HeaderStackInfo *stacks = nullptr;
58
59 explicit Find(ElimUnusedHeaderStackInfo &self) : self(self) {}
60
61 Visitor::profile_t init_apply(const IR::Node *root) override {
62 self.unused.clear();
63 used.clear();
64 return Inspector::init_apply(root);
65 }
66
67 bool preorder(const IR::BFN::Pipe *pipe) override {
68 BUG_CHECK(pipe->headerStackInfo != nullptr,
69 "Running ElimUnusedHeaderStackInfo without running "
70 "CollectHeaderStackInfo first?");
71 stacks = pipe->headerStackInfo;
72 return true;
73 }
74
75 void postorder(const IR::HeaderStack *stack) override;
76 void end_apply() override;
77 };
78
79 // Remove from pipe->headerStackInfo.
80 struct Elim : public Modifier {
82 explicit Elim(ElimUnusedHeaderStackInfo &self) : self(self) {}
83
84 void postorder(IR::BFN::Pipe *pipe) override;
85 };
86
87 public:
88 ElimUnusedHeaderStackInfo() { addPasses({new Find(*this), new Elim(*this)}); }
89};
90
91namespace BFN {
92
95 struct Info {
98
102 bool inThread[2] = {true, true};
103
105 int size = 0;
106
109 int maxpush = 0;
110
113 int maxpop = 0;
114 };
115
116 private:
117 friend struct ::CollectHeaderStackInfo;
118 friend class ::ElimUnusedHeaderStackInfo;
120
121 public:
122 auto begin() const -> decltype(Values(info).begin()) { return Values(info).begin(); }
123 auto begin() -> decltype(Values(info).begin()) { return Values(info).begin(); }
124 auto end() const -> decltype(Values(info).end()) { return Values(info).end(); }
125 auto end() -> decltype(Values(info).end()) { return Values(info).end(); }
126 auto at(cstring n) const -> decltype(info.at(n)) { return info.at(n); }
127 auto at(cstring n) -> decltype(info.at(n)) { return info.at(n); }
128 auto count(cstring n) const -> decltype(info.count(n)) { return info.count(n); }
129 const Info *get(cstring n) const {
130 if (auto it = info.find(n); it != info.end()) return &it->second;
131 return nullptr;
132 }
133};
134} // namespace BFN
135
149 IR::Node *preorder(IR::MAU::Action *act) override;
150
151 public:
153};
154
161 struct BFN::HeaderStackInfo *stack_info_ = nullptr;
162
163 // Populate stack_info_.
164 IR::Node *preorder(IR::BFN::Pipe *pipe) override;
165
166 // Replace uses of stk[x].$valid with stk.$stkvalid[y:y], where the latter
167 // corresponds to the validity bit in $stkvalid of element x of stk.
168 IR::Node *postorder(IR::Member *member) override;
169
170 // Replace extractions to slices of $stkvalid with equivalent extractions
171 // to the entire field. Eg. extract(stk.$stkvalid, 0x4) instead of
172 // extract(stk.$stkvalid[2:2], 0x1).
173 //
174 // TODO: This is because Brig doesn't currently support extracting
175 // constants to field slices in the parser (see BRIG-584). As a result,
176 // this removes the AliasSlice node and hence loses the aliasing
177 // information. However, as parser extracts aren't exposed to the control
178 // plane, this should be fine.
179 IR::Node *postorder(IR::BFN::Extract *extract) override;
180
181 public:
182 explicit ValidToStkvalid(PhvInfo &) {}
183};
184
185#endif /* BF_P4C_COMMON_HEADER_STACK_H_ */
Definition header_stack.h:50
Definition node.h:94
Definition visitor.h:400
Definition visitor.h:372
Definition ir/pass_manager.h:40
Definition visitor.h:424
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:1095
Definition header_stack.h:148
Definition header_stack.h:160
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
@ Info
Take no action and continue compilation.
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:148
Metadata about how header stacks are used in the program.
Definition header_stack.h:94
bool inThread[2]
Definition header_stack.h:102
int size
How many elements are in this header stack?
Definition header_stack.h:105
int maxpop
Definition header_stack.h:113
int maxpush
Definition header_stack.h:109
cstring name
The name of the header stack this metadata describes.
Definition header_stack.h:97
Definition header_stack.h:95
Definition header_stack.h:36