P4C
The P4 Compiler
Loading...
Searching...
No Matches
extract_maupipe.h
1
19#ifndef BF_P4C_COMMON_EXTRACT_MAUPIPE_H_
20#define BF_P4C_COMMON_EXTRACT_MAUPIPE_H_
21
22#include <optional>
23
24#include "backends/tofino/bf-p4c/arch/arch.h"
25#include "backends/tofino/bf-p4c/arch/fromv1.0/mirror.h"
26#include "backends/tofino/bf-p4c/arch/fromv1.0/resubmit.h"
27#include "backends/tofino/bf-p4c/device.h"
28#include "backends/tofino/bf-p4c/lib/assoc.h"
29#include "backends/tofino/bf-p4c/logging/source_info_logging.h"
30#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
31#include "backends/tofino/bf-p4c/midend/param_binding.h"
32#include "frontends/common/options.h"
33#include "frontends/common/resolveReferences/referenceMap.h"
34#include "frontends/p4/externInstance.h"
35#include "frontends/p4/typeMap.h"
36#include "ir/ir.h"
37
38class BFN_Options;
40
41namespace BFN {
42
43using namespace P4;
44
45const IR::BFN::Pipe *extract_maupipe(const IR::P4Program *, BFN_Options &options);
46
66// a mapping from Registers to the (converted) ActionSelectors that are bound to them
68
69class AttachTables : public PassManager {
70 P4::ReferenceMap *refMap;
71 P4::TypeMap *typeMap;
72 // Have to keep all non StatefulAlus separate from other Declaration_Instances, because
73 // selectors and StatefulAlus may have the same Declaration
74 DeclarationConversions &converted;
75 assoc::map<const IR::Declaration_Instance *,
76 IR::MAU::StatefulAlu *>
77 salu_inits; // Register -> StatefulAlu
78 StatefulSelectors stateful_selectors;
79
95 class InitializeStatefulAlus : public MauInspector {
96 AttachTables &self;
97 void postorder(const IR::Expression *) override { visitAgain(); }
98 void postorder(const IR::GlobalRef *) override;
99 void updateAttachedSalu(const IR::Declaration_Instance *, const IR::GlobalRef *);
100
101 public:
102 explicit InitializeStatefulAlus(AttachTables &s) : self(s) {}
103 };
104
124 class InitializeRegisterParams : public MauInspector {
125 AttachTables &self;
126 ordered_map<const IR::Declaration_Instance *,
127 IR::MAU::StatefulAlu *>
128 param_salus; // RegisterParam -> StatefulAlu
129 bool preorder(const IR::MAU::Primitive *prim) override;
130 void end_apply() override;
131
132 public:
133 explicit InitializeRegisterParams(AttachTables &s) : self(s) {}
134 };
135
148 class InitializeStatefulInstructions : public MauInspector {
149 AttachTables &self;
152
153 void postorder(const IR::Expression *) override { visitAgain(); }
154 void postorder(const IR::GlobalRef *gref) override;
155
156 public:
157 explicit InitializeStatefulInstructions(AttachTables &s) : self(s) {}
158 };
159
167 class DefineGlobalRefs : public MauModifier {
168 AttachTables &self;
169 P4::ReferenceMap *refMap;
170 P4::TypeMap *typeMap;
171
173 bool preorder(IR::MAU::Table *) override;
174 bool preorder(IR::MAU::Action *) override;
175 void postorder(IR::MAU::Table *) override;
176 void postorder(IR::Expression *) override { visitAgain(); }
177 void postorder(IR::GlobalRef *) override;
178
179 const IR::MAU::StatefulAlu *findAttachedSalu(const IR::Declaration_Instance *ext);
180
181 public:
182 explicit DefineGlobalRefs(AttachTables &s, P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
183 : self(s), refMap(refMap), typeMap(typeMap) {}
184 };
185 bool findSaluDeclarations(const IR::Declaration_Instance *ext,
186 const IR::Declaration_Instance **reg_ptr,
187 const IR::Type_Specialized **regtype_ptr = nullptr,
188 const IR::Type_Extern **seltype_ptr = nullptr);
189 profile_t init_apply(const IR::Node *root) override;
190
191 static bool isSaluActionType(const IR::Type *);
192
193 public:
196 : refMap(rm), typeMap(tm), converted(con), stateful_selectors(ss) {
197 addPasses({new InitializeStatefulAlus(*this), new InitializeRegisterParams(*this),
198 new InitializeStatefulInstructions(*this),
199 new DefineGlobalRefs(*this, refMap, typeMap)});
200 stop_on_error = false;
201 }
202};
203
206 public:
207 ProcessBackendPipe(P4::ReferenceMap *refMap, P4::TypeMap *typeMap, IR::BFN::Pipe *rv,
209 ParamBinding *bindings);
210};
211
213 P4::ReferenceMap *refMap;
214 P4::TypeMap *typeMap;
215 ParamBinding *bindings;
216 ParseTna *arch;
217 const IR::ToplevelBlock *toplevel = nullptr;
218 StatefulSelectors stateful_selectors;
221 CollectSourceInfoLogging &sourceInfoLogging;
222
223 public:
224 BackendConverter(P4::ReferenceMap *refMap, P4::TypeMap *typeMap, ParamBinding *bindings,
227 CollectSourceInfoLogging &sourceInfoLogging)
228 : refMap(refMap),
229 typeMap(typeMap),
230 bindings(bindings),
231 pipe(pipe),
232 pipes(pipes),
233 sourceInfoLogging(sourceInfoLogging) {
234 arch = new ParseTna(refMap, typeMap);
235 }
236
237 ordered_map<int, const IR::BFN::Pipe *> &getPipes() { return pipes; }
238 cstring getPipelineName(const IR::P4Program *program, int index);
239 const ProgramPipelines &getPipelines() const { return arch->pipelines; }
240 bool preorder(const IR::P4Program *program) override;
241};
242
243} // namespace BFN
244
245#endif /* BF_P4C_COMMON_EXTRACT_MAUPIPE_H_ */
Definition extract_maupipe.h:69
Definition extract_maupipe.h:212
bool preorder(const IR::P4Program *program) override
Definition extract_maupipe.cpp:1975
must be applied to IR::BFN::Pipe
Definition extract_maupipe.h:205
ProcessBackendPipe(P4::ReferenceMap *refMap, P4::TypeMap *typeMap, IR::BFN::Pipe *rv, DeclarationConversions &converted, StatefulSelectors ss, ParamBinding *bindings)
Definition extract_maupipe.cpp:1925
Definition arch.h:294
Definition bf-p4c-options.h:28
Definition mau_visitor.h:29
Definition mau_visitor.h:45
Definition node.h:94
Definition vector.h:59
Definition visitor.h:400
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition param_binding.h:32
Definition assoc.h:300
Definition assoc.h:355
Definition arch.h:327
Pass that collects source information.
Definition source_info_logging.h:39
The pass creates SALU VLIW instructions.
Definition mau/stateful_alu.h:161
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
assoc::map< const IR::Declaration_Instance *, const IR::MAU::AttachedMemory * > DeclarationConversions
Definition extract_maupipe.h:65
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24