-
Notifications
You must be signed in to change notification settings - Fork 16.8k
[VPlan] Prevent uses of materialized VPSymbolicValues. (NFC) #182318
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
Changes from all commits
b6c2030
b7a78ee
01c677f
101f318
eaeeb05
4abbf16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,11 +101,24 @@ class LLVM_ABI_FOR_TEST VPValue { | |
| void dump() const; | ||
| #endif | ||
|
|
||
| unsigned getNumUsers() const { return Users.size(); } | ||
| void addUser(VPUser &User) { Users.push_back(&User); } | ||
| /// Assert that this VPValue has not been materialized, if it is a | ||
| /// VPSymbolicValue. | ||
| void assertNotMaterialized() const; | ||
|
|
||
| unsigned getNumUsers() const { | ||
| if (Users.empty()) | ||
| return 0; | ||
| assertNotMaterialized(); | ||
| return Users.size(); | ||
| } | ||
| void addUser(VPUser &User) { | ||
| assertNotMaterialized(); | ||
| Users.push_back(&User); | ||
| } | ||
|
|
||
| /// Remove a single \p User from the list of users. | ||
| void removeUser(VPUser &User) { | ||
| assertNotMaterialized(); | ||
| // The same user can be added multiple times, e.g. because the same VPValue | ||
| // is used twice by the same VPUser. Remove a single one. | ||
| auto *I = find(Users, &User); | ||
|
|
@@ -118,10 +131,22 @@ class LLVM_ABI_FOR_TEST VPValue { | |
| typedef iterator_range<user_iterator> user_range; | ||
| typedef iterator_range<const_user_iterator> const_user_range; | ||
|
|
||
| user_iterator user_begin() { return Users.begin(); } | ||
| const_user_iterator user_begin() const { return Users.begin(); } | ||
| user_iterator user_end() { return Users.end(); } | ||
| const_user_iterator user_end() const { return Users.end(); } | ||
| user_iterator user_begin() { | ||
| assertNotMaterialized(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will these asserts ever be hit if we're already asserting in addUser/removeUser? We also allow calling getNumUsers() post-materialization without asserting.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added them just to have extra guards. |
||
| return Users.begin(); | ||
| } | ||
| const_user_iterator user_begin() const { | ||
| assertNotMaterialized(); | ||
| return Users.begin(); | ||
| } | ||
| user_iterator user_end() { | ||
| assertNotMaterialized(); | ||
| return Users.end(); | ||
| } | ||
| const_user_iterator user_end() const { | ||
| assertNotMaterialized(); | ||
| return Users.end(); | ||
| } | ||
| user_range users() { return user_range(user_begin(), user_end()); } | ||
| const_user_range users() const { | ||
| return const_user_range(user_begin(), user_end()); | ||
|
|
@@ -226,6 +251,20 @@ struct VPSymbolicValue : public VPValue { | |
| static bool classof(const VPValue *V) { | ||
| return V->getVPValueID() == VPVSymbolicSC; | ||
| } | ||
|
|
||
| /// Returns true if this symbolic value has been materialized. | ||
| bool isMaterialized() const { return Materialized; } | ||
|
|
||
| /// Mark this symbolic value as materialized. | ||
| void markMaterialized() { | ||
| assert(!Materialized && "VPSymbolicValue already materialized"); | ||
| Materialized = true; | ||
| } | ||
|
|
||
| private: | ||
| /// Track whether this symbolic value has been materialized (replaced). | ||
| /// After materialization, accessing users should trigger an assertion. | ||
| bool Materialized = false; | ||
| }; | ||
|
|
||
| /// A VPValue defined by a recipe that produces one or more values. | ||
|
|
@@ -427,6 +466,12 @@ class VPDef { | |
| unsigned getNumDefinedValues() const { return DefinedValues.size(); } | ||
| }; | ||
|
|
||
| inline void VPValue::assertNotMaterialized() const { | ||
| assert((!isa<VPSymbolicValue>(this) || | ||
| !cast<VPSymbolicValue>(this)->isMaterialized()) && | ||
| "accessing materialized symbolic value"); | ||
| } | ||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H | ||
Uh oh!
There was an error while loading. Please reload this page.