53 LOG8(
"ComputeDefUse::clone " << rv->uid);
56 void flow_merge(
Visitor &)
override;
60 enum { SKIPPING, NORMAL, READ_ONLY, WRITE_ONLY } state = SKIPPING;
69 mutable size_t computedHash = 0;
70 bool operator<(
const loc_t &a)
const {
71 if (node != a.node)
return node->id < a.node->id;
72 if (!parent || !a.parent)
return parent !=
nullptr;
73 return *parent < *a.parent;
75 bool operator==(
const loc_t &a)
const {
76 if (node != a.node)
return false;
77 if (parent == a.parent)
return true;
78 if (!parent || !a.parent)
return false;
79 return *parent == *a.parent;
81 std::size_t hash()
const {
86 computedHash =
Util::Hash{}(node->id, parent->hash());
92 const T *find()
const {
93 for (
auto *p =
this; p; p = p->parent) {
94 if (
auto *t = p->node->to<T>())
return t;
103 std::unordered_set<loc_t> &cached_locs;
105 const loc_t *getLoc() {
return getLoc(getChildContext()); }
107 const loc_t *getLoc(
const IR::Node *n) {
return getLoc(n, getChildContext()); }
118 def_info_t *parent =
nullptr;
120 locset_t valid_bit_defs;
122 std::map<cstring, def_info_t> fields;
123 std::map<le_bitrange, def_info_t> slices;
125 void slices_sanity();
126 std::map<le_bitrange, def_info_t>::iterator slices_overlap_begin(le_bitrange);
127 void erase_slice(le_bitrange);
128 void split_slice(le_bitrange);
129 void flow_merge(def_info_t &);
130 bool operator==(
const def_info_t &)
const;
131 bool operator!=(
const def_info_t &a)
const {
return !(*
this == a); }
132 def_info_t() =
default;
133 def_info_t(
const def_info_t &);
134 def_info_t(def_info_t &&);
135 def_info_t &operator=(
const def_info_t &);
136 def_info_t &operator=(def_info_t &&);
138 hvec_map<const IR::IDeclaration *, def_info_t> def_info;
139 void add_uses(
const loc_t *, def_info_t &);
140 void set_live_from_type(def_info_t &di,
const IR::Type *type);
147 hvec_map<const IR::Node *, locset_t> defs;
148 hvec_map<const IR::Node *, locset_t> uses;
150 static const locset_t empty;
152 profile_t init_apply(
const IR::Node *root)
override {
153 auto rv = Inspector::init_apply(root);
154 LOG3(
"## Midend ComputeDefUse");
160 bool preorder(
const IR::P4Control *)
override;
161 bool preorder(
const IR::P4Table *)
override;
162 bool preorder(
const IR::P4Action *)
override;
163 bool preorder(
const IR::P4Parser *)
override;
164 bool preorder(
const IR::Function *)
override;
165 bool preorder(
const IR::ParserState *)
override;
166 void revisit(
const IR::ParserState *)
override;
167 void loop_revisit(
const IR::ParserState *)
override;
168 void postorder(
const IR::ParserState *)
override;
169 bool preorder(
const IR::Type *)
override {
return false; }
170 bool preorder(
const IR::Annotations *)
override {
return false; }
171 bool preorder(
const IR::KeyElement *)
override;
172 bool preorder(
const IR::AssignmentStatement *)
override;
173 const IR::Expression *do_read(def_info_t &,
const IR::Expression *,
const Context *);
174 const IR::Expression *do_write(def_info_t &,
const IR::Expression *,
const Context *);
175 bool preorder(
const IR::PathExpression *)
override;
176 void loop_revisit(
const IR::PathExpression *)
override;
177 bool preorder(
const IR::MethodCallExpression *)
override;
178 void end_apply()
override;
180 class SetupJoinPoints;
181 void applySetupJoinPoints(
const IR::Node *root)
override;
182 bool filter_join_point(
const IR::Node *)
override;
188 const locset_t &getDefs(
const IR::Node *n)
const {
189 auto it = defuse.defs.find(n);
190 return it == defuse.defs.end() ? empty : it->second;
192 const locset_t &getUses(
const IR::Node *n)
const {
193 auto it = defuse.uses.find(n);
194 return it == defuse.uses.end() ? empty : it->second;
198 friend std::ostream &operator<<(std::ostream &,
const loc_t &);
199 friend std::ostream &operator<<(std::ostream &,
const defuse_t &);
200 friend std::ostream &operator<<(std::ostream &out,
const ComputeDefUse &cdu) {
201 return out << cdu.defuse;
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24