P4C
The P4 Compiler
Loading...
Searching...
No Matches
table_injected_deps.h
1
19#ifndef BF_P4C_MAU_TABLE_INJECTED_DEPS_H_
20#define BF_P4C_MAU_TABLE_INJECTED_DEPS_H_
21
22#include <map>
23#include <stack>
24
25#include "bf-p4c/common/field_defuse.h"
26#include "bf-p4c/ir/control_flow_visitor.h"
27#include "bf-p4c/mau/table_flow_graph.h"
28#include "bf-p4c/mau/table_mutex.h"
29#include "bf-p4c/mau/table_summary.h"
30#include "bf-p4c/phv/phv_fields.h"
31#include "lib/ordered_map.h"
32#include "lib/ordered_set.h"
33#include "mau_visitor.h"
34#include "table_dependency_graph.h"
35
36using namespace P4;
37
39 bool preorder(const IR::MAU::TableSeq *seq) override;
40
41 private:
43
44 public:
45 explicit InjectControlDependencies(DependencyGraph &out) : dg(out) { visitDagOnce = false; }
46};
47
50 const ControlPathwaysToTable &ctrl_paths;
52
53 public:
54 std::map<cstring, const IR::MAU::Table *> name_to_table;
55
56 bool edge(const IR::MAU::Table *a, const IR::MAU::Table *b) const {
57 if (edges_to_add.count(a) == 0) return false;
58 return edges_to_add.at(a).count(b);
59 }
60
62 : dg(d), ctrl_paths(cp) {}
63
64 private:
65 profile_t init_apply(const IR::Node *node) override {
66 auto rv = MauInspector::init_apply(node);
67 edges_to_add.clear();
68 return rv;
69 }
70
71 void postorder(const IR::MAU::Table *tbl) override;
72 void end_apply() override;
73};
74
77 protected:
78 bool tables_placed = false;
80 const ControlPathwaysToTable &ctrl_paths;
81
82 Visitor::profile_t init_apply(const IR::Node *node) override {
83 auto rv = MauInspector::init_apply(node);
84 tables_placed = false;
85 return rv;
86 }
87
88 bool preorder(const IR::MAU::Table *table) override {
89 tables_placed |= table->is_placed();
90 return true;
91 }
92
93 public:
95 : dg(dg), ctrl_paths(cp) {}
96};
97
104 const PhvInfo &phv;
105 const FlowGraph &fg;
106 std::map<cstring, const IR::MAU::Table *> name_to_table;
107
108 Visitor::profile_t init_apply(const IR::Node *node) override {
109 auto rv = AbstractDependencyInjector::init_apply(node);
110 name_to_table.clear();
111 return rv;
112 }
113
114 bool preorder(const IR::MAU::Table *t) override {
115 auto rv = AbstractDependencyInjector::preorder(t);
116 name_to_table[t->name] = t;
117 return rv;
118 }
119
120 void end_apply() override;
121
122 public:
124 const ControlPathwaysToTable &cp)
125 : AbstractDependencyInjector(g, cp), phv(p), fg(f) {}
126};
127
129 const CalculateNextTableProp &cntp;
130
131 void postorder(const IR::MAU::Table *table) override;
132
133 public:
135 const ControlPathwaysToTable &cp)
136 : AbstractDependencyInjector(g, cp), cntp(cntp) {}
137};
138
140 std::map<gress_t, std::vector<const IR::MAU::Table *>> run_before_exit_tables;
141
142 Visitor::profile_t init_apply(const IR::Node *node) override {
143 LOG3("InjectControlExitDependencies begins");
144 auto rv = AbstractDependencyInjector::init_apply(node);
145 run_before_exit_tables.clear();
146 return rv;
147 }
148
149 void end_apply(const IR::Node *node) override {
150 Visitor::end_apply(node);
151 link_run_before_exit_tables();
152 LOG3("InjectControlExitDependencies ends");
153 }
154
155 bool preorder(const IR::MAU::Table *table) override;
156 void postorder(const IR::MAU::Table *table) override;
157
158 void collect_run_before_exit_table(const IR::MAU::Table *table);
159 void inject_dependencies_from_gress_root_tables_to_first_rbe_table(
160 const IR::MAU::Table *first_rbe_table);
161 bool is_first_run_before_exit_table_in_gress(const IR::MAU::Table *rbe_table);
162 const IR::MAU::TableSeq *get_gress_root_table_seq(const IR::MAU::Table *table);
163 void link_run_before_exit_tables();
164 void inject_control_exit_dependency(const IR::MAU::Table *source,
165 const IR::MAU::Table *destination);
166
167 public:
169 : AbstractDependencyInjector(dg, cp) {}
170};
171
173 const PhvInfo &phv;
174 bool placed = false;
175 std::map<UniqueId, const IR::MAU::Table *> id_to_table;
176
177 profile_t init_apply(const IR::Node *node) override {
178 auto rv = AbstractDependencyInjector::init_apply(node);
179 placed = false;
180 id_to_table.clear();
181 return rv;
182 }
183
184 bool preorder(const IR::MAU::Table *) override;
185 void end_apply() override;
186 // Get table corresponding to uid from id_to_table map
187 // - handle case where @uid may not exists in id_to_table
188 const IR::MAU::Table *getTable(UniqueId uid);
189
190 public:
192 const ControlPathwaysToTable &cp)
193 : AbstractDependencyInjector(g, cp), phv(p) {}
194};
195
197 const PhvInfo &phv;
198 DependencyGraph &dg;
199 FlowGraph &fg;
200 ControlPathwaysToTable ctrl_paths;
202 const FieldDefUse *defuse;
203 const TableSummary *summary;
204
205 profile_t init_apply(const IR::Node *root) override {
206 auto rv = PassManager::init_apply(root);
207 fg.clear();
208 return rv;
209 }
210
211 public:
213 const BFN_Options *options = nullptr,
214 const TableSummary *summary = nullptr);
215
216 private:
217 // Duplicates to dominators
219};
220
221// During alt-phv-alloc, the ALT_FINALIZE_TABLE round during table placement
222// needs to have additional dependencies injected between overlayed fields which
223// are disjoint. This ensures the tables are placed in the correct order to
224// not violate read / write dependencies
226 const PhvInfo &phv;
227 DependencyGraph &dg;
228 const FieldDefUse &defuse;
229 const TablesMutuallyExclusive &mutex;
230
231 void end_apply() override;
232
233 public:
235 const TablesMutuallyExclusive &mu)
236 : phv(p), dg(g), defuse(du), mutex(mu) {}
237};
238
239#endif /* BF_P4C_MAU_TABLE_INJECTED_DEPS_H_ */
Common functionality for injecting dependencies into a DependencyGraph.
Definition table_injected_deps.h:76
Definition bf-p4c-options.h:28
Definition table_dependency_graph.h:938
Definition table_dependency_graph.h:972
Definition table_injected_deps.h:128
Definition table_injected_deps.h:38
Definition table_injected_deps.h:139
Definition table_injected_deps.h:172
Definition table_injected_deps.h:225
Definition table_injected_deps.h:103
Definition mau_visitor.h:29
Definition node.h:95
Definition ir/pass_manager.h:40
Definition unique_id.h:168
Definition visitor.h:78
Definition ordered_map.h:32
Definition phv_fields.h:1095
Definition table_injected_deps.h:48
Definition table_injected_deps.h:196
Definition table_summary.h:158
Definition mau/table_mutex.h:110
Definition field_defuse.h:77
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition table_dependency_graph.h:52
Definition table_flow_graph.h:45
void clear()
Clears the state in this FlowGraph.
Definition table_flow_graph.h:191