54class DoLocalCopyPropagation :
public ControlFlowVisitor,
63 const IR::Expression *val =
nullptr;
66 std::set<cstring> keyreads, actions;
68 std::map<cstring, const IR::Expression *> key_remap;
71 std::set<cstring> reads, writes;
78 bool is_first_write_insert =
false;
80 std::map<cstring, VarInfo> available;
81 std::shared_ptr<std::map<cstring, TableInfo>> tables;
82 std::shared_ptr<std::map<cstring, FuncInfo>> actions;
83 std::shared_ptr<std::map<cstring, FuncInfo>> methods;
84 std::shared_ptr<std::map<cstring, FuncInfo>> states;
85 TableInfo *inferForTable =
nullptr;
86 FuncInfo *inferForFunc =
nullptr;
87 bool need_key_rewrite =
false;
88 LocalCopyPropPolicyCallbackFn policy;
89 bool elimUnusedTables =
false;
93 DoLocalCopyPropagation *clone()
const override {
94 auto *rv =
new DoLocalCopyPropagation(*
this);
96 LOG8(
"flow_clone(" << uid <<
") = " << rv->uid);
99 void flow_merge(
Visitor &)
override;
100 void flow_copy(ControlFlowVisitor &)
override;
101 bool operator==(
const ControlFlowVisitor &)
const override;
103 void forOverlapAvail(
cstring, std::function<
void(
cstring, VarInfo *)>);
105 bool hasSideEffects(
const IR::Expression *e,
const Visitor::Context *ctxt) {
108 bool isHeaderUnionIsValid(
const IR::Expression *e);
111 DoLocalCopyPropagation &self;
112 void postorder(
const IR::BaseAssignmentStatement *)
override;
113 void postorder(
const IR::MethodCallExpression *)
override;
114 void apply_table(TableInfo *tbl);
115 void apply_function(FuncInfo *tbl);
118 explicit LoopPrepass(DoLocalCopyPropagation &s) : self(s) {}
121 void visit_local_decl(
const IR::Declaration_Variable *);
122 const IR::Node *postorder(IR::Declaration_Variable *)
override;
123 IR::Expression *preorder(IR::Expression *m)
override;
125 const IR::Expression *postorder(IR::PathExpression *)
override;
126 const IR::Expression *preorder(IR::Member *)
override;
127 const IR::Expression *preorder(IR::ArrayIndex *)
override;
128 IR::Statement *preorder(IR::Statement *)
override;
129 const IR::Node *preorder(IR::BaseAssignmentStatement *)
override;
130 IR::AssignmentStatement *postorder(IR::AssignmentStatement *)
override;
131 IR::IfStatement *postorder(IR::IfStatement *)
override;
132 IR::ForStatement *preorder(IR::ForStatement *)
override;
133 IR::ForInStatement *preorder(IR::ForInStatement *)
override;
134 IR::MethodCallExpression *postorder(IR::MethodCallExpression *)
override;
135 IR::P4Action *preorder(IR::P4Action *)
override;
136 IR::P4Action *postorder(IR::P4Action *)
override;
137 IR::Function *preorder(IR::Function *)
override;
138 IR::Function *postorder(IR::Function *)
override;
139 IR::P4Control *preorder(IR::P4Control *)
override;
140 void apply_table(TableInfo *tbl);
141 void apply_function(FuncInfo *tbl);
142 IR::P4Table *preorder(IR::P4Table *)
override;
143 IR::P4Table *postorder(IR::P4Table *)
override;
144 const IR::P4Parser *postorder(IR::P4Parser *)
override;
145 IR::ParserState *preorder(IR::ParserState *)
override;
146 IR::ParserState *postorder(IR::ParserState *)
override;
147 void end_apply(
const IR::Node *node)
override;
151 DoLocalCopyPropagation(
const DoLocalCopyPropagation &) =
default;
154 DoLocalCopyPropagation(
TypeMap *typeMap, LocalCopyPropPolicyCallbackFn policy,
bool eut)
156 tables(std::make_shared<std::map<cstring, TableInfo>>()),
157 actions(std::make_shared<std::map<cstring, FuncInfo>>()),
158 methods(std::make_shared<std::map<cstring, FuncInfo>>()),
159 states(std::make_shared<std::map<cstring, FuncInfo>>()),
161 elimUnusedTables(eut) {}