44 public ControlFlowVisitor,
45 public P4WriteContext,
48 void flow_merge(Visitor &)
override;
49 void flow_copy(ControlFlowVisitor &)
override;
50 enum { SKIPPING, NORMAL, READ_ONLY, WRITE_ONLY } state = SKIPPING;
59 bool operator<(
const loc_t &a)
const {
60 if (node != a.node)
return node->id < a.node->id;
61 if (!a.parent)
return parent !=
nullptr;
62 return *parent < *a.parent;
65 const T *find()
const {
66 for (
auto *p =
this; p; p = p->parent) {
67 if (
auto *t = p->node->to<T>())
return t;
74 std::set<loc_t> &cached_locs;
75 const loc_t *getLoc(
const Visitor::Context *ctxt);
76 const loc_t *getLoc() {
return getLoc(getChildContext()); }
77 const loc_t *getLoc(
const IR::Node *,
const Visitor::Context *);
78 const loc_t *getLoc(
const IR::Node *n) {
return getLoc(n, getChildContext()); }
85 ordered_set<const loc_t *> defs;
87 def_info_t *parent =
nullptr;
89 ordered_set<const loc_t *> valid_bit_defs;
91 std::map<cstring, def_info_t> fields;
92 std::map<le_bitrange, def_info_t> slices;
95 std::map<le_bitrange, def_info_t>::iterator slices_overlap_begin(le_bitrange);
96 void erase_slice(le_bitrange);
97 void split_slice(le_bitrange);
98 void flow_merge(def_info_t &);
99 def_info_t() =
default;
100 def_info_t(
const def_info_t &);
101 def_info_t(def_info_t &&);
103 ordered_map<const IR::IDeclaration *, def_info_t> def_info;
104 void add_uses(
const loc_t *, def_info_t &);
111 ordered_map<const IR::Node *, ordered_set<const loc_t *>> defs;
112 ordered_map<const IR::Node *, ordered_set<const loc_t *>> uses;
114 static const ordered_set<const loc_t *> empty;
116 profile_t init_apply(
const IR::Node *root)
override {
117 auto rv = Inspector::init_apply(root);
122 bool preorder(
const IR::P4Control *)
override;
123 bool preorder(
const IR::P4Table *)
override;
124 bool preorder(
const IR::P4Action *)
override;
125 bool preorder(
const IR::P4Parser *)
override;
126 bool preorder(
const IR::ParserState *)
override;
127 void revisit(
const IR::ParserState *)
override;
128 void loop_revisit(
const IR::ParserState *)
override;
129 void postorder(
const IR::ParserState *)
override;
130 bool preorder(
const IR::Type *)
override {
return false; }
131 bool preorder(
const IR::Annotation *)
override {
return false; }
132 bool preorder(
const IR::KeyElement *)
override;
133 const IR::Expression *do_read(def_info_t &,
const IR::Expression *,
const Context *);
134 const IR::Expression *do_write(def_info_t &,
const IR::Expression *,
const Context *);
135 bool preorder(
const IR::PathExpression *)
override;
136 void loop_revisit(
const IR::PathExpression *)
override;
137 bool preorder(
const IR::MethodCallExpression *)
override;
138 void end_apply()
override;
140 class SetupJoinPoints;
141 void applySetupJoinPoints(
const IR::Node *root)
override;
142 bool filter_join_point(
const IR::Node *)
override;
146 : ResolutionContext(true), cached_locs(*new
std::set<loc_t>), defuse(*new defuse_t) {
156 const ordered_set<const loc_t *> &getDefs(
const IR::Node *n)
const {
157 auto it = defuse.defs.find(n);
158 return it == defuse.defs.end() ? empty : it->second;
160 const ordered_set<const loc_t *> &getUses(
const IR::Node *n)
const {
161 auto it = defuse.uses.find(n);
162 return it == defuse.uses.end() ? empty : it->second;
166 friend std::ostream &operator<<(std::ostream &,
const defuse_t &);
167 friend std::ostream &operator<<(std::ostream &out,
const ComputeDefUse &cdu) {
168 return out << cdu.defuse;
171 friend void dump(
const def_info_t &);
172 friend void dump(
const ordered_map<const IR::IDeclaration *, def_info_t> &);
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35