17#ifndef FRONTENDS_P4_SPECIALIZE_H_
18#define FRONTENDS_P4_SPECIALIZE_H_
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/common/resolveReferences/resolveReferences.h"
22#include "frontends/p4/typeMap.h"
24#include "ir/pass_manager.h"
56 CHECK_NULL(insertion);
75 const IR::IContainer *container,
const IR::Node *insertion,
84 const IR::IContainer *container,
const IR::Node *insertion,
89 auto s = ::P4::get(specializations, insertion);
90 if (s ==
nullptr)
return nullptr;
93 void clear() { specializations.clear(); }
106 setName(
"FindSpecializations");
109 const IR::Node *findInsertionPoint()
const;
110 bool isSimpleConstant(
const IR::Expression *expression)
const;
112 auto rv = Inspector::init_apply(node);
115 node->apply(nameGen);
124 bool preorder(
const IR::P4Parser *parser)
override {
return noParameters(parser); }
125 bool preorder(
const IR::P4Control *control)
override {
return noParameters(control); }
126 void postorder(
const IR::ConstructorCallExpression *expression)
override;
127 void postorder(
const IR::Declaration_Instance *decl)
override;
129 bool preorder(
const IR::Parameter *)
override {
179 setName(
"Specialize");
181 const IR::Node *postorder(IR::P4Parser *parser)
override {
182 return instantiate(parser, getContext());
185 const IR::Node *preorder(IR::Type_Package *package)
override {
189 const IR::Node *postorder(IR::P4Control *control)
override {
190 return instantiate(control, getContext());
192 const IR::Node *postorder(IR::ConstructorCallExpression *expression)
override;
193 const IR::Node *postorder(IR::Declaration_Instance *)
override;
Definition referenceMap.h:57
Definition specialize.h:99
bool noParameters(const IR::IContainer *container)
Definition specialize.cpp:196
Definition frontends/p4/frontend.h:32
Definition referenceMap.h:36
Definition referenceMap.h:29
Definition ir/pass_manager.h:145
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
Maintains a map from invocation to a SpecializationInfo object.
Definition specialize.h:62
void addSpecialization(const IR::ConstructorCallExpression *invocation, const IR::IContainer *container, const IR::Node *insertion, DeclarationLookup *declLookup, NameGenerator *nameGen)
Definition specialize.cpp:83
Specializes each Parser and Control by substituting type arguments and constructor parameters.
Definition specialize.h:220
Specializes each Parser and Control with constant constructor arguments by substituting type argument...
Definition specialize.h:172
Definition ordered_map.h:32
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Describes how a parser or control is specialized.
Definition specialize.h:31
const IR::IContainer * specialized
Actual parser or control that is being specialized.
Definition specialize.h:35
cstring name
Name to use for specialized object.
Definition specialize.h:33
const IR::Node * insertBefore
Where in the program should the specialization be inserted.
Definition specialize.h:45
const IR::Node * invocation
Invocation which causes this specialization.
Definition specialize.h:43
IR::IndexedVector< IR::Declaration > declarations
Declarations to insert in the list of locals.
Definition specialize.h:41
const IR::Vector< IR::Type > * typeArguments
Values to substitute for type arguments.
Definition specialize.h:37
IR::Vector< IR::Argument > * constructorArguments
Values to substitute for constructor arguments.
Definition specialize.h:39