Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code/comments cleanup in SimplifyDefUse #4963

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions frontends/p4/simplifyDefUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,26 +969,25 @@ class FindUninitialized : public Inspector {
return false;
}

// Check whether the expression the child of a Member or
// ArrayIndex. I.e., for and expression such as a.x within a
// Check whether the expression is the child of a Member or
// ArrayIndex. I.e., for an expression such as a.x within a
// larger expression a.x.b it returns "false". This is because
// the expression is not reading a.x, it is reading just a.x.b.
// ctx must be the context of the current expression in the
// visitor.
bool isFinalRead(const Visitor::Context *ctx, const IR::Expression *expression) {
if (ctx == nullptr) return true;

// If this expression is a child of a Member of a left
// If this expression is a child of a Member or a left
// child of an ArrayIndex then we don't report it here, only
// in the parent.
auto parentexp = ctx->node->to<IR::Expression>();
if (parentexp != nullptr) {
if (parentexp->is<IR::Member>()) return false;
if (parentexp->is<IR::ArrayIndex>()) {
if (const auto *ai = parentexp->to<IR::ArrayIndex>()) {
// Since we are doing the visit using a custom order,
// ctx->child_index is not accurate, so we check
// manually whether this is the left child.
auto ai = parentexp->to<IR::ArrayIndex>();
if (ai->left == expression) return false;
}
}
Expand Down
Loading