17#ifndef FRONTENDS_P4_SPECIALIZEGENERICFUNCTIONS_H_
18#define FRONTENDS_P4_SPECIALIZEGENERICFUNCTIONS_H_
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/common/resolveReferences/resolveReferences.h"
22#include "frontends/p4/typeChecking/typeChecker.h"
41 const IR::Function *function,
const IR::Node *insert)
58 std::set<FunctionSpecialization *> inserted;
60 void add(
const IR::MethodCallExpression *mce,
const IR::Function *func,
const IR::Node *insert,
62 cstring name = nameGen->newName(func->name.string_view());
66 return ::P4::get(map, mce);
71 if (inserted.find(s.second) != inserted.end())
continue;
72 if (s.second->insertBefore == insertionPoint) {
74 LOG2(
"Will insert " << dbp(s.second->specialized) <<
" before "
75 << dbp(insertionPoint));
76 result->push_back(s.second->specialized);
77 inserted.emplace(s.second);
94 setName(
"FindFunctionSpecializations");
97 bool preorder(
const IR::MethodCallExpression *call)
override;
126 setName(
"SpecializeFunctions");
128 const IR::Node *postorder(IR::Function *function)
override;
129 const IR::Node *postorder(IR::MethodCallExpression *)
override;
131 const IR::Node *preorder(IR::P4Control *control)
override {
return insert(control); }
132 const IR::Node *preorder(IR::P4Parser *parser)
override {
return insert(parser); }
133 const IR::Node *preorder(IR::Function *function)
override {
return insert(function); }
141 passes.emplace_back(
new TypeChecking(
nullptr, typeMap));
144 specMap.typeMap = typeMap;
145 setName(
"SpecializeGenericFunctions");
Definition specializeGenericFunctions.h:87
Definition referenceMap.h:36
Definition referenceMap.h:29
Definition ir/pass_manager.h:40
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
Specializes each generic function by substituting type parameters.
Definition specializeGenericFunctions.h:120
Definition specializeGenericFunctions.h:136
Definition typeChecker.h:55
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Describes how a generic function is specialized.
Definition specializeGenericFunctions.h:28
const IR::Function * specialized
Result of specialization.
Definition specializeGenericFunctions.h:34
const IR::Node * insertBefore
Point in IR tree where to insert the function.
Definition specializeGenericFunctions.h:38
const IR::Function * original
Function that is being specialized.
Definition specializeGenericFunctions.h:32
const IR::MethodCallExpression * invocation
Invocation which causes this specialization.
Definition specializeGenericFunctions.h:36
cstring name
Name to use for specialized function.
Definition specializeGenericFunctions.h:30
Definition specializeGenericFunctions.h:53