-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[MLIR][Affine] Add affine value map difference operator #127163
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
[MLIR][Affine] Add affine value map difference operator #127163
Conversation
Add affine value map difference operator. NFC otherwise.
@llvm/pr-subscribers-mlir-affine @llvm/pr-subscribers-mlir Author: Uday Bondhugula (bondhugula) ChangesAdd affine value map difference operator. NFC otherwise. Full diff: https://github.com/llvm/llvm-project/pull/127163.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h b/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
index 7ad0e4a1e5ea0..ac480d6997ef4 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
@@ -84,6 +84,13 @@ class AffineValueMap {
/// and/or operands have been modified.
LogicalResult canonicalize();
+ /// Checks if the application of this map to its operands is semantically
+ /// equal to `other`'s.
+ bool operator==(const AffineValueMap &other) const;
+ bool operator!=(const AffineValueMap &other) const {
+ return !(*this == other);
+ }
+
private:
// A mutable affine map.
MutableAffineMap map;
diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index b829633252fdd..93d8bffdcd8a4 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -2001,9 +2001,7 @@ bool MemRefAccess::operator==(const MemRefAccess &rhs) const {
AffineValueMap diff, thisMap, rhsMap;
getAccessMap(&thisMap);
rhs.getAccessMap(&rhsMap);
- AffineValueMap::difference(thisMap, rhsMap, &diff);
- return llvm::all_of(diff.getAffineMap().getResults(),
- [](AffineExpr e) { return e == 0; });
+ return thisMap == rhsMap;
}
void mlir::affine::getAffineIVs(Operation &op, SmallVectorImpl<Value> &ivs) {
diff --git a/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp b/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
index 6a52849186872..6d2d3212c696b 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
@@ -109,4 +109,12 @@ ArrayRef<Value> AffineValueMap::getOperands() const {
AffineMap AffineValueMap::getAffineMap() const { return map.getAffineMap(); }
+bool AffineValueMap::operator==(const AffineValueMap &other) const {
+ AffineValueMap diff;
+ AffineValueMap::difference(*this, other, &diff);
+ return llvm::all_of(diff.getAffineMap().getResults(), [](AffineExpr e) {
+ return e == getAffineConstantExpr(0, e.getContext());
+ });
+}
+
AffineValueMap::~AffineValueMap() = default;
|
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
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
Add affine value map difference operator. NFC otherwise.
Add affine value map difference operator. NFC otherwise.
Add affine value map difference operator. NFC otherwise.