-
Notifications
You must be signed in to change notification settings - Fork 25
[water] harden WaveIndexMappingAttr #665
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
Conversation
13fbc76 to
75a1d75
Compare
| llvm::sort(symbolVector, [](Attribute lhs, Attribute rhs) { | ||
| auto lhsSymbol = dyn_cast<WaveSymbolAttr>(lhs); | ||
| auto lhsIndexSymbol = dyn_cast<WaveIndexSymbolAttr>(lhs); | ||
| auto lhsIterSymbol = dyn_cast<WaveIterSymbolAttr>(lhs); | ||
| auto rhsSymbol = dyn_cast<WaveSymbolAttr>(rhs); | ||
| auto rhsIndexSymbol = dyn_cast<WaveIndexSymbolAttr>(rhs); | ||
| auto rhsIterSymbol = dyn_cast<WaveIterSymbolAttr>(rhs); | ||
| // For different kinds of symbols, index symbols come before iter symbols, | ||
| // which come before regular symbols. | ||
| if (lhsIndexSymbol && !rhsIndexSymbol) | ||
| return true; | ||
| if (!lhsIndexSymbol && rhsIndexSymbol) | ||
| return false; | ||
| if (lhsIterSymbol && rhsSymbol) | ||
| return true; | ||
| if (lhsSymbol && !rhsSymbol) | ||
| return false; | ||
| if (lhsSymbol && rhsSymbol) | ||
| return lhsSymbol.getName() < rhsSymbol.getName(); | ||
| if (lhsIndexSymbol && rhsIndexSymbol) | ||
| return lhsIndexSymbol.getValue() < rhsIndexSymbol.getValue(); | ||
| if (lhsIterSymbol && rhsIterSymbol) | ||
| return lhsIterSymbol.getName() < rhsIterSymbol.getName(); | ||
| assert(false && "unhandled symbol comparison"); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be easier to read.
| llvm::sort(symbolVector, [](Attribute lhs, Attribute rhs) { | |
| auto lhsSymbol = dyn_cast<WaveSymbolAttr>(lhs); | |
| auto lhsIndexSymbol = dyn_cast<WaveIndexSymbolAttr>(lhs); | |
| auto lhsIterSymbol = dyn_cast<WaveIterSymbolAttr>(lhs); | |
| auto rhsSymbol = dyn_cast<WaveSymbolAttr>(rhs); | |
| auto rhsIndexSymbol = dyn_cast<WaveIndexSymbolAttr>(rhs); | |
| auto rhsIterSymbol = dyn_cast<WaveIterSymbolAttr>(rhs); | |
| // For different kinds of symbols, index symbols come before iter symbols, | |
| // which come before regular symbols. | |
| if (lhsIndexSymbol && !rhsIndexSymbol) | |
| return true; | |
| if (!lhsIndexSymbol && rhsIndexSymbol) | |
| return false; | |
| if (lhsIterSymbol && rhsSymbol) | |
| return true; | |
| if (lhsSymbol && !rhsSymbol) | |
| return false; | |
| if (lhsSymbol && rhsSymbol) | |
| return lhsSymbol.getName() < rhsSymbol.getName(); | |
| if (lhsIndexSymbol && rhsIndexSymbol) | |
| return lhsIndexSymbol.getValue() < rhsIndexSymbol.getValue(); | |
| if (lhsIterSymbol && rhsIterSymbol) | |
| return lhsIterSymbol.getName() < rhsIterSymbol.getName(); | |
| assert(false && "unhandled symbol comparison"); | |
| }); | |
| auto cmp = [](Attribute x) { | |
| return TypeSwitch<Attribute, std::pair<int, StringRef>>(x) | |
| .Case([](WaveIndexSymbolAttr a) { | |
| return std::make_pair(1, a.getValue()); | |
| }) | |
| .Case( | |
| [](WaveIterSymbolAttr a) { return std::make_pair(2, a.getName()); }) | |
| .Case([](WaveSymbolAttr a) { return std::make_pair(3, a.getName()); }) | |
| .DefaultUnreachable("unhandled symbol comparison"); | |
| }; | |
| llvm::sort(symbolVector, | |
| [&](Attribute lhs, Attribute rhs) { return cmp(lhs) < cmp(rhs); }); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, I did it a bit differently since getValue on index symbols is not a string.
tyb0807
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
75a1d75 to
99a425a
Compare
|
There actually was a bug in indexing ;) PTAL |
99a425a to
2a65b2e
Compare
Add multiple verifiers on the invariants we always had but did not enforce (potentially dropped by accident during refactoring). Sort symbols on construction to ensure symbolically equal maps with different positions compare as equal. Systematically drop unused symbols on construction. Signed-off-by: Alex Zinenko <[email protected]>
11fa9b0 to
90e49eb
Compare
Add multiple verifiers on the invariants we always had but did not enforce
(potentially dropped by accident during refactoring). Sort symbols on
construction to ensure symbolically equal maps with different positions compare
as equal.
Signed-off-by: Alex Zinenko [email protected]