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"
57 CHECK_NULL(insertion);
76 const IR::IContainer *container,
const IR::Node *insertion,
85 const IR::IContainer *container,
const IR::Node *insertion,
90 auto s = ::P4::get(specializations, insertion);
91 if (s ==
nullptr)
return nullptr;
94 void clear() { specializations.clear(); }
107 setName(
"FindSpecializations");
110 const IR::Node *findInsertionPoint()
const;
111 bool isSimpleConstant(
const IR::Expression *expression)
const;
113 auto rv = Inspector::init_apply(node);
116 node->apply(nameGen);
125 bool preorder(
const IR::P4Parser *parser)
override {
return noParameters(parser); }
126 bool preorder(
const IR::P4Control *control)
override {
return noParameters(control); }
127 void postorder(
const IR::ConstructorCallExpression *expression)
override;
128 void postorder(
const IR::Declaration_Instance *decl)
override;
130 bool preorder(
const IR::Parameter *)
override {
180 setName(
"Specialize");
182 const IR::Node *postorder(IR::P4Parser *parser)
override {
183 return instantiate(parser, getContext());
186 const IR::Node *preorder(IR::Type_Package *package)
override {
190 const IR::Node *postorder(IR::P4Control *control)
override {
191 return instantiate(control, getContext());
193 const IR::Node *postorder(IR::ConstructorCallExpression *expression)
override;
194 const IR::Node *postorder(IR::Declaration_Instance *)
override;
Definition referenceMap.h:57
Definition specialize.h:100
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:63
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:221
Specializes each Parser and Control with constant constructor arguments by substituting type argument...
Definition specialize.h:173
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
IR::IndexedVector< IR::Declaration > * declarations
Declarations to insert in the list of locals.
Definition specialize.h:41
const IR::Node * invocation
Invocation which causes this specialization.
Definition specialize.h:43
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