P4C
The P4 Compiler
Loading...
Searching...
No Matches
mau/table_mutex.h
1
19#ifndef BF_P4C_MAU_TABLE_MUTEX_H_
20#define BF_P4C_MAU_TABLE_MUTEX_H_
21
22#include <map>
23
24#include "bf-p4c/mau/action_mutex.h"
25#include "bf-p4c/mau/mau_visitor.h"
26#include "bf-p4c/mau/resource.h"
27#include "bf-p4c/mau/table_layout.h"
28#include "lib/ordered_map.h"
29#include "lib/safe_vector.h"
30#include "lib/symbitmatrix.h"
31
32using namespace P4;
33
37 using TablePair = std::pair<const IR::MAU::Table *, const IR::MAU::Table *>;
38
43
44 // Auxiliary data structures for end_apply().
45 std::map<cstring, const IR::MAU::Table *> internal_name_to_table;
46 std::map<cstring, const IR::MAU::Table *> external_name_to_table;
47
51
52 profile_t init_apply(const IR::Node *node) override {
53 auto rv = MauTableInspector::init_apply(node);
54 ignore_dep_map.clear();
55 internal_name_to_table.clear();
56 external_name_to_table.clear();
57 table_to_pragmas.clear();
58 return rv;
59 }
60
62 bool preorder(const IR::MAU::Table *) override;
63
65 void end_apply() override;
66
67 public:
69
71 bool ignore_deps(const IR::MAU::Table *t1, const IR::MAU::Table *t2) const;
72
75};
76
112 std::map<int, const IR::MAU::Table *> rev_table_ids;
113
114 public:
115 // public for gtests
116 std::map<cstring, const IR::MAU::Table *> name_to_tables;
117
118 private:
123
127 SymBitMatrix non_mutex;
128
129 // If a table is present as an key, it means that one of its sucessor is an exit table.
130 // The bit vec represents the exit table and tables before the exit table in a tableSeq
132
133 void postorder(const IR::MAU::Table *tbl) override;
134 void postorder(const IR::MAU::TableSeq *seq) override;
135 bool miss_mutex_action_chain(const IR::MAU::Table *tbl, const IR::MAU::Action *default_act,
136 cstring &name);
137
138 profile_t init_apply(const IR::Node *root) override {
139 profile_t rv = MauTableInspector::init_apply(root);
140
141 table_ids.clear();
142 rev_table_ids.clear();
143 non_mutex.clear();
144 name_to_tables.clear();
145
146 // Populate auxiliary data structures.
147 forAllMatching<IR::MAU::Table>(root, [this](const IR::MAU::Table *t) {
148 assert(!table_ids.count(t));
149 rev_table_ids.emplace(table_ids.size(), t);
150 table_ids.emplace(t, table_ids.size());
151 name_to_tables.emplace(t->externalName(), t);
152 });
153 return rv;
154 }
155
156 public:
157 bool operator()(const IR::MAU::Table *a, const IR::MAU::Table *b) const;
158};
159
163 const TablesMutuallyExclusive &mutex;
164 const IgnoreTableDeps &ignore;
165 const ActionMutuallyExclusive &action_mutex;
166 LayoutChoices &lc;
167 SymBitMatrix _mutex_through_ignore;
168
169 std::map<const IR::MAU::Table *, int> table_ids;
170 std::map<int, const IR::MAU::Table *> rev_table_ids;
171
172 profile_t init_apply(const IR::Node *root) override {
173 profile_t rv = MauInspector::init_apply(root);
174 backend_users.clear();
175 table_sharing_attached.clear();
176 table_ids.clear();
177 rev_table_ids.clear();
178 _mutex_through_ignore.clear();
179 forAllMatching<IR::MAU::Table>(root, [this](const IR::MAU::Table *t) {
180 assert(!table_ids.count(t));
181 rev_table_ids.emplace(table_ids.size(), t);
182 table_ids.emplace(t, table_ids.size());
183 });
184 return rv;
185 }
186 bool preorder(const IR::MAU::AttachedMemory *) override;
187 bool check_if_can_share(const IR::MAU::Table *a, const IR::MAU::Table *b,
188 const IR::MAU::AttachedMemory *am);
189 std::vector<const IR::MAU::Action *> get_indirect_actions(const IR::MAU::Table *a,
190 const IR::MAU::AttachedMemory *am);
191
192 public:
193 bool mutex_through_ignore(const IR::MAU::Table *a, const IR::MAU::Table *b) const;
194 // for gtest
195 bool if_table_share_attach(const IR::MAU::Table *a, const IR::MAU::Table *b) const;
197 const IgnoreTableDeps &i,
199 : mutex(m), ignore(i), action_mutex(a), lc(lc) {}
200};
201#endif /* BF_P4C_MAU_TABLE_MUTEX_H_ */
Definition action_mutex.h:29
Definition mau/table_mutex.h:36
safe_vector< TablePair > pairwise_deps_to_ignore() const
In the returned list, each pair of tables should have their dependencies ignored.
Definition mau/table_mutex.cpp:76
bool ignore_deps(const IR::MAU::Table *t1, const IR::MAU::Table *t2) const
Determines whether dependencies between the two given tables should be ignored.
Definition mau/table_mutex.cpp:23
Definition table_layout.h:83
Definition mau_visitor.h:29
Definition mau_visitor.h:39
Definition node.h:95
Definition symbitmatrix.h:27
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition safe_vector.h:27
Definition mau/table_mutex.h:160
Definition mau/table_mutex.h:110
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void forAllMatching(const IR::Node *root, Func &&function)
Definition visitor.h:801