Skip to content

Commit c1b7037

Browse files
authored
[MLIR][Affine] Add affine value map difference operator (llvm#127163)
Add affine value map difference operator. NFC otherwise.
1 parent bd860f9 commit c1b7037

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class AffineValueMap {
8484
/// and/or operands have been modified.
8585
LogicalResult canonicalize();
8686

87+
/// Checks if the application of this map to its operands is semantically
88+
/// equal to `other`'s.
89+
bool operator==(const AffineValueMap &other) const;
90+
bool operator!=(const AffineValueMap &other) const {
91+
return !(*this == other);
92+
}
93+
8794
private:
8895
// A mutable affine map.
8996
MutableAffineMap map;

mlir/lib/Dialect/Affine/Analysis/Utils.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -2001,9 +2001,7 @@ bool MemRefAccess::operator==(const MemRefAccess &rhs) const {
20012001
AffineValueMap diff, thisMap, rhsMap;
20022002
getAccessMap(&thisMap);
20032003
rhs.getAccessMap(&rhsMap);
2004-
AffineValueMap::difference(thisMap, rhsMap, &diff);
2005-
return llvm::all_of(diff.getAffineMap().getResults(),
2006-
[](AffineExpr e) { return e == 0; });
2004+
return thisMap == rhsMap;
20072005
}
20082006

20092007
void mlir::affine::getAffineIVs(Operation &op, SmallVectorImpl<Value> &ivs) {

mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,12 @@ ArrayRef<Value> AffineValueMap::getOperands() const {
109109

110110
AffineMap AffineValueMap::getAffineMap() const { return map.getAffineMap(); }
111111

112+
bool AffineValueMap::operator==(const AffineValueMap &other) const {
113+
AffineValueMap diff;
114+
AffineValueMap::difference(*this, other, &diff);
115+
return llvm::all_of(diff.getAffineMap().getResults(), [](AffineExpr e) {
116+
return e == getAffineConstantExpr(0, e.getContext());
117+
});
118+
}
119+
112120
AffineValueMap::~AffineValueMap() = default;

0 commit comments

Comments
 (0)