46class DoLocalCopyPropagation :
public ControlFlowVisitor,
55 const IR::Expression *val =
nullptr;
58 std::set<cstring> keyreads, actions;
60 std::map<cstring, const IR::Expression *> key_remap;
63 std::set<cstring> reads, writes;
70 bool is_first_write_insert =
false;
72 std::map<cstring, VarInfo> available;
73 std::shared_ptr<std::map<cstring, TableInfo>> tables;
74 std::shared_ptr<std::map<cstring, FuncInfo>> actions;
75 std::shared_ptr<std::map<cstring, FuncInfo>> methods;
76 std::shared_ptr<std::map<cstring, FuncInfo>> states;
77 TableInfo *inferForTable =
nullptr;
78 FuncInfo *inferForFunc =
nullptr;
79 bool need_key_rewrite =
false;
80 LocalCopyPropPolicyCallbackFn policy;
81 bool elimUnusedTables =
false;
85 DoLocalCopyPropagation *clone()
const override {
86 auto *rv =
new DoLocalCopyPropagation(*
this);
88 LOG8(
"flow_clone(" << uid <<
") = " << rv->uid);
91 void flow_merge(
Visitor &)
override;
92 void flow_copy(ControlFlowVisitor &)
override;
93 bool operator==(
const ControlFlowVisitor &)
const override;
95 void forOverlapAvail(
cstring, std::function<
void(
cstring, VarInfo *)>);
97 bool hasSideEffects(
const IR::Expression *e,
const Visitor::Context *ctxt) {
100 bool isHeaderUnionIsValid(
const IR::Expression *e);
103 DoLocalCopyPropagation &self;
104 void postorder(
const IR::BaseAssignmentStatement *)
override;
105 void postorder(
const IR::MethodCallExpression *)
override;
106 void apply_table(TableInfo *tbl);
107 void apply_function(FuncInfo *tbl);
110 explicit LoopPrepass(DoLocalCopyPropagation &s) : self(s) {}
113 void visit_local_decl(
const IR::Declaration_Variable *);
114 const IR::Node *postorder(IR::Declaration_Variable *)
override;
115 IR::Expression *preorder(IR::Expression *m)
override;
117 const IR::Expression *postorder(IR::PathExpression *)
override;
118 const IR::Expression *preorder(IR::Member *)
override;
119 const IR::Expression *preorder(IR::ArrayIndex *)
override;
120 IR::Statement *preorder(IR::Statement *)
override;
121 const IR::Node *preorder(IR::BaseAssignmentStatement *)
override;
122 IR::AssignmentStatement *postorder(IR::AssignmentStatement *)
override;
123 IR::IfStatement *postorder(IR::IfStatement *)
override;
124 IR::ForStatement *preorder(IR::ForStatement *)
override;
125 IR::ForInStatement *preorder(IR::ForInStatement *)
override;
126 IR::MethodCallExpression *postorder(IR::MethodCallExpression *)
override;
127 IR::P4Action *preorder(IR::P4Action *)
override;
128 IR::P4Action *postorder(IR::P4Action *)
override;
129 IR::Function *preorder(IR::Function *)
override;
130 IR::Function *postorder(IR::Function *)
override;
131 IR::P4Control *preorder(IR::P4Control *)
override;
132 void apply_table(TableInfo *tbl);
133 void apply_function(FuncInfo *tbl);
134 IR::P4Table *preorder(IR::P4Table *)
override;
135 IR::P4Table *postorder(IR::P4Table *)
override;
136 const IR::P4Parser *postorder(IR::P4Parser *)
override;
137 IR::ParserState *preorder(IR::ParserState *)
override;
138 IR::ParserState *postorder(IR::ParserState *)
override;
139 void end_apply(
const IR::Node *node)
override;
143 DoLocalCopyPropagation(
const DoLocalCopyPropagation &) =
default;
146 DoLocalCopyPropagation(
TypeMap *typeMap, LocalCopyPropPolicyCallbackFn policy,
bool eut)
148 tables(std::make_shared<std::map<cstring, TableInfo>>()),
149 actions(std::make_shared<std::map<cstring, FuncInfo>>()),
150 methods(std::make_shared<std::map<cstring, FuncInfo>>()),
151 states(std::make_shared<std::map<cstring, FuncInfo>>()),
153 elimUnusedTables(eut) {}