17#ifndef MIDEND_FLATTENUNIONS_H_
18#define MIDEND_FLATTENUNIONS_H_
20#include "./frontends/p4/parserControlFlow.h"
21#include "./frontends/p4/simplifyDefUse.h"
22#include "./frontends/p4/unusedDeclarations.h"
23#include "frontends/p4/typeChecking/typeChecker.h"
52 std::map<cstring, std::map<cstring, cstring>> replacementMap;
54 std::map<IR::Declaration_Variable *, IR::IndexedVector<IR::Declaration>> replaceDVMap;
58 : refMap(refMap), typeMap(typeMap) {}
59 const IR::Node *postorder(IR::Type_Struct *sf)
override;
60 const IR::Node *postorder(IR::Declaration_Variable *dv)
override;
61 const IR::Node *postorder(IR::Member *m)
override;
62 const IR::Node *postorder(IR::P4Parser *parser)
override;
63 const IR::Node *postorder(IR::P4Control *control)
override;
64 const IR::Node *postorder(IR::P4Action *action)
override;
65 bool hasHeaderUnionField(IR::Type_Struct *s);
95 std::map<cstring, std::vector<cstring>> stackMap;
100 setName(
"DoFlattenHeaderUnionStack");
102 const IR::Node *postorder(IR::Type_Struct *sf)
override;
103 const IR::Node *postorder(IR::ArrayIndex *e)
override;
104 const IR::Node *postorder(IR::Declaration_Variable *dv)
override;
105 bool hasHeaderUnionStackField(IR::Type_Struct *s);
147 : refMap(refMap), typeMap(typeMap) {
148 setName(
"HandleValidityHeaderUnion");
150 const IR::Node *postorder(IR::AssignmentStatement *assn)
override;
151 const IR::Node *postorder(IR::IfStatement *a)
override;
152 const IR::Node *postorder(IR::SwitchStatement *a)
override;
153 const IR::Node *postorder(IR::MethodCallStatement *mcs)
override;
154 const IR::Node *postorder(IR::P4Parser *parser)
override;
155 const IR::Node *postorder(IR::P4Control *control)
override;
156 const IR::Node *postorder(IR::P4Action *action)
override;
157 const IR::MethodCallStatement *processValidityForStr(
const IR::Statement *s,
158 const IR::Member *m,
cstring headerElement,
160 const IR::Node *setInvalidforRest(
const IR::Statement *s,
const IR::Member *m,
161 const IR::Type_HeaderUnion *hu,
cstring exclude,
162 bool setValidforCurrMem);
163 const IR::Node *expandIsValid(
const IR::Statement *a,
const IR::MethodCallExpression *mce,
173 const IR::Node *preorder(IR::Type_HeaderUnion *type)
override {
174 if (!used.
isUsed(getOriginal<IR::IDeclaration>()))
return nullptr;
188 setName(
"RemoveAllUnusedHUDDeclarations");
189 setStopOnError(
true);
Definition typeChecker.h:32
Collects all used declarations into @used set.
Definition unusedDeclarations.h:57
Definition flattenUnions.h:140
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Iterates RemoveUnusedDeclarations until convergence.
Definition unusedDeclarations.h:189
Definition flattenUnions.h:179
Definition parserControlFlow.h:114
Definition flattenUnions.h:167
Definition unusedDeclarations.h:48
Definition typeChecker.h:55
Definition typeChecker.h:483
Definition unusedDeclarations.h:29
bool isUsed(const IR::IDeclaration *decl) const
Definition unusedDeclarations.h:45
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24