[mlir][IR] Hash nesting structure in OperationFingerPrint
authorMatthias Springer <me@m-sp.org>
Wed, 24 May 2023 12:55:09 +0000 (14:55 +0200)
committerMatthias Springer <me@m-sp.org>
Wed, 24 May 2023 13:01:56 +0000 (15:01 +0200)
commit350b4d05e85ece30bd9f02be410b4bcb90af7a42
treead44ebc2ce870266d1a6151e126641e239e32b9b
parent8c6b83dcfdc333c72793cf0cdbfcf4325be39cde
[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
mlir/lib/IR/OperationSupport.cpp