[Mlir-commits] [mlir] 350b4d0 - [mlir][IR] Hash nesting structure in OperationFingerPrint

Matthias Springer llvmlistbot at llvm.org
Wed May 24 06:02:11 PDT 2023


Author: Matthias Springer
Date: 2023-05-24T15:01:56+02:00
New Revision: 350b4d05e85ece30bd9f02be410b4bcb90af7a42

URL: https://github.com/llvm/llvm-project/commit/350b4d05e85ece30bd9f02be410b4bcb90af7a42
DIFF: https://github.com/llvm/llvm-project/commit/350b4d05e85ece30bd9f02be410b4bcb90af7a42.diff

LOG: [mlir][IR] Hash nesting structure in OperationFingerPrint

The following ops currently have the same finger print, even though they are different:
```
func.func @test() {
  "test.foo"() ({
    "test.bar"() : () -> ()
  }) : () -> ()
}
```
And:
```
func.func @test() {
  "test.bar"() : () -> ()
  "test.foo"() ({ }) : () -> ()
}
```

The SHA1 hash used in OperationFingerPrint is order-sensitive, but the ops are hashed in the same order (post-order traversal), so the hash is the same. Switching to pre-order traversal does not solve the issue; a similar example, where IR differs just in its nesting structure, can be constructed.

The problem is solved by hashing the parent op pointer. (Alternatively, a traversal over the IR that hashes scope markers (`{}`) could be used.)

Differential Revision: https://reviews.llvm.org/D151306

Added: 
    

Modified: 
    mlir/lib/IR/OperationSupport.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index 716239af863c9..0a4a19dbf2c69 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -877,6 +877,9 @@ OperationFingerPrint::OperationFingerPrint(Operation *topOp) {
   topOp->walk([&](Operation *op) {
     //   - Operation pointer
     addDataToHash(hasher, op);
+    //   - Parent operation pointer (to take into account the nesting structure)
+    if (op != topOp)
+      addDataToHash(hasher, op->getParentOp());
     //   - Attributes
     addDataToHash(hasher, op->getDiscardableAttrDictionary());
     //   - Properties


        


More information about the Mlir-commits mailing list