59 const IR::Expression *val =
nullptr;
62 std::set<cstring> keyreads, actions;
64 std::map<cstring, const IR::Expression *> key_remap;
67 std::set<cstring> reads, writes;
74 bool is_first_write_insert =
false;
76 std::map<cstring, VarInfo> available;
77 std::map<cstring, TableInfo> &tables;
78 std::map<cstring, FuncInfo> &actions;
79 std::map<cstring, FuncInfo> &methods;
80 std::map<cstring, FuncInfo> &states;
81 TableInfo *inferForTable =
nullptr;
82 FuncInfo *inferForFunc =
nullptr;
83 bool need_key_rewrite =
false;
84 std::function<bool(
const Context *,
const IR::Expression *)> policy;
85 bool elimUnusedTables =
false;
89 DoLocalCopyPropagation *clone()
const override {
90 auto *rv =
new DoLocalCopyPropagation(*
this);
92 LOG8(
"flow_clone(" << uid <<
") = " << rv->uid);
95 void flow_merge(
Visitor &)
override;
96 void flow_copy(ControlFlowVisitor &)
override;
97 bool operator==(
const ControlFlowVisitor &)
const override;
99 void forOverlapAvail(
cstring, std::function<
void(
cstring, VarInfo *)>);
101 bool hasSideEffects(
const IR::Expression *e) {
104 bool isHeaderUnionIsValid(
const IR::Expression *e);
107 DoLocalCopyPropagation &self;
108 void postorder(
const IR::AssignmentStatement *)
override;
109 void postorder(
const IR::MethodCallExpression *)
override;
110 void apply_table(TableInfo *tbl);
111 void apply_function(FuncInfo *tbl);
114 explicit LoopPrepass(DoLocalCopyPropagation &s) : self(s) {}
117 void visit_local_decl(
const IR::Declaration_Variable *);
118 const IR::Node *postorder(IR::Declaration_Variable *)
override;
119 IR::Expression *preorder(IR::Expression *m)
override;
121 const IR::Expression *postorder(IR::PathExpression *)
override;
122 const IR::Expression *preorder(IR::Member *)
override;
123 const IR::Expression *preorder(IR::ArrayIndex *)
override;
124 IR::Statement *preorder(IR::Statement *)
override;
125 IR::AssignmentStatement *preorder(IR::AssignmentStatement *)
override;
126 IR::AssignmentStatement *postorder(IR::AssignmentStatement *)
override;
127 IR::IfStatement *postorder(IR::IfStatement *)
override;
128 IR::ForStatement *preorder(IR::ForStatement *)
override;
129 IR::ForInStatement *preorder(IR::ForInStatement *)
override;
130 IR::MethodCallExpression *postorder(IR::MethodCallExpression *)
override;
131 IR::P4Action *preorder(IR::P4Action *)
override;
132 IR::P4Action *postorder(IR::P4Action *)
override;
133 IR::Function *preorder(IR::Function *)
override;
134 IR::Function *postorder(IR::Function *)
override;
135 IR::P4Control *preorder(IR::P4Control *)
override;
136 void apply_table(TableInfo *tbl);
137 void apply_function(FuncInfo *tbl);
138 IR::P4Table *preorder(IR::P4Table *)
override;
139 IR::P4Table *postorder(IR::P4Table *)
override;
140 const IR::P4Parser *postorder(IR::P4Parser *)
override;
141 IR::ParserState *preorder(IR::ParserState *)
override;
142 IR::ParserState *postorder(IR::ParserState *)
override;
147 DoLocalCopyPropagation(
const DoLocalCopyPropagation &) =
default;
151 std::function<
bool(
const Context *,
const IR::Expression *)> policy,
155 tables(*
new std::map<cstring, TableInfo>),
156 actions(*
new std::map<cstring, FuncInfo>),
157 methods(*
new std::map<cstring, FuncInfo>),
158 states(*
new std::map<cstring, FuncInfo>),
160 elimUnusedTables(eut) {}