P4C
The P4 Compiler
Loading...
Searching...
No Matches
alpm.h
1
24#ifndef BF_P4C_MIDEND_ALPM_H_
25#define BF_P4C_MIDEND_ALPM_H_
26
27#include "frontends/common/resolveReferences/resolveReferences.h"
28#include "frontends/p4/externInstance.h"
29#include "frontends/p4/methodInstance.h"
30#include "frontends/p4/typeMap.h"
31#include "ir/ir.h"
32#include "ir/pass_manager.h"
33#include "lib/cstring.h"
34
35namespace BFN {
36
40class CollectAlpmInfo : public Inspector {
41 public:
42 std::set<cstring> alpm_actions;
43 std::set<cstring> alpm_table;
44 P4::ReferenceMap *refMap;
45 P4::TypeMap *typeMap;
46
47 public:
49 : refMap(refMap), typeMap(typeMap) {}
50
51 void postorder(const IR::P4Table *tbl) override;
52};
53
57class HasTableApply : public Inspector {
58 P4::ReferenceMap *refMap;
59 P4::TypeMap *typeMap;
60
61 public:
62 const IR::P4Table *table;
63 const IR::MethodCallExpression *call;
65 : refMap(refMap), typeMap(typeMap), table(nullptr), call(nullptr) {
66 CHECK_NULL(refMap);
67 CHECK_NULL(typeMap);
68 setName("HasTableApply");
69 }
70 void postorder(const IR::MethodCallExpression *expression) override {
71 auto mi = P4::MethodInstance::resolve(expression, refMap, typeMap);
72 if (!mi->isApply()) return;
73 auto am = mi->to<P4::ApplyMethod>();
74 if (!am->object->is<IR::P4Table>()) return;
75 BUG_CHECK(table == nullptr, "%1% and %2%: multiple table applications in one expression",
76 table, am->object);
77 table = am->object->to<IR::P4Table>();
78 call = expression;
79 LOG3("Invoked table is " << dbp(table));
80 }
81 bool preorder(const IR::Member *member) override {
82 if (member->member == "hit" || member->member == "miss") return true;
83 return false;
84 }
85};
86
142class SplitAlpm : public Transform {
143 CollectAlpmInfo *alpm_info;
144 P4::ReferenceMap *refMap;
145 P4::TypeMap *typeMap;
146 static const std::set<unsigned> valid_partition_values;
147 std::set<cstring> alpm_tables;
148 std::map<cstring, cstring> preclassifier_tables;
149
150 const IR::MAU::Table *create_pre_classifier_tcam(IR::MAU::Table *tbl, IR::TempVar *tv,
151 IR::TempVar *tk, unsigned partition_index_bits,
152 unsigned pre_classifer_number_entries,
153 unsigned pre_classifer_number_actions);
154 bool values_through_pragmas(const IR::P4Table *tbl, int &number_of_partitions,
155 int &number_subtrees_par_partition);
156 bool values_through_impl(const IR::P4Table *tbl, int &number_of_partitions,
157 int &number_subtrees_per_partition, int &atcam_subset_width,
158 int &shift_granularity);
159 bool pragma_exclude_msbs(const IR::P4Table *tbl, ordered_map<cstring, int> &fields_to_exclude);
160
161 const IR::Node *postorder(IR::P4Table *tbl) override;
162 const IR::Node *postorder(IR::MethodCallStatement *) override;
163 const IR::Node *postorder(IR::IfStatement *) override;
164 const IR::Node *postorder(IR::SwitchStatement *) override;
165
166 const IR::IndexedVector<IR::Declaration> *create_temp_var(const IR::P4Table *, unsigned,
167 unsigned, unsigned, unsigned,
168 const IR::Expression *);
169 const IR::IndexedVector<IR::Declaration> *create_preclassifer_actions(const IR::P4Table *,
170 unsigned, unsigned,
171 unsigned, unsigned,
172 unsigned,
173 const IR::Expression *);
174 const IR::P4Table *create_preclassifier_table(const IR::P4Table *, unsigned, unsigned, unsigned,
175 unsigned);
176 const IR::P4Table *create_atcam_table(const IR::P4Table *, unsigned, unsigned, unsigned, int,
177 int, ordered_map<cstring, int> &fields_to_exclude,
178 const IR::Expression *);
179 void apply_pragma_exclude_msbs(const IR::P4Table *tbl,
180 const ordered_map<cstring, int> *fields_to_exclude,
182 const IR::StatOrDecl *synth_funnel_shift_ops(const IR::P4Table *, const IR::Expression *, int);
183 bool use_funnel_shift(int);
184
185 public:
186 static const cstring ALGORITHMIC_LPM_PARTITIONS;
187 static const cstring ALGORITHMIC_LPM_SUBTREES_PER_PARTITION;
188 static const cstring ALGORITHMIC_LPM_ATCAM_EXCLUDE_FIELD_MSBS;
189
191 : alpm_info(info), refMap(refMap), typeMap(typeMap) {}
192};
193
199 public:
201};
202
203} // namespace BFN
204
205#endif /* BF_P4C_MIDEND_ALPM_H_ */
Definition methodInstance.h:129
Checks to see whether an IR node includes a table.apply() sub-expression.
Definition sideEffects.h:31
Definition node.h:52
Definition node.h:95
Definition vector.h:59
Definition visitor.h:400
static MethodInstance * resolve(const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
Definition methodInstance.cpp:27
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition visitor.h:424
Definition typeMap.h:41
Definition cstring.h:85
Definition ordered_map.h:32
Top level PassManager that governs the ALPM implementation.
Definition alpm.h:198
Definition alpm.h:40
Pass that splits ALPM table into pre-classifier TCAM and TCAM.
Definition alpm.h:142
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
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