[Mlir-commits] [mlir] [mlir] Fix liveness analysis (PR #88848)

Ivan Kulagin llvmlistbot at llvm.org
Fri Apr 19 07:13:42 PDT 2024


================
@@ -67,11 +67,18 @@ struct BlockInfoBuilder {
     // Mark all nested operation results as defined, and nested operation
     // operands as used. All defined value will be removed from the used set
     // at the end.
-    block->walk([&](Operation *op) {
-      for (Value result : op->getResults())
-        defValues.insert(result);
-      for (Value operand : op->getOperands())
-        useValues.insert(operand);
+    block->walk([&](Block *nestedBlock) {
+      if (block != nestedBlock) {
+        for (BlockArgument arg : nestedBlock->getArguments()) {
+          defValues.insert(arg);
+        }
+      }
+      for (Operation &op : *nestedBlock) {
----------------
ikulagin wrote:

Yes, of course, I suggest the following option, but it will require an additional set:
```cpp
    SmallPtrSet<Block *, 32> visited;
    block->walk([&](Operation *op) {
      for (Value result : op->getResults())
          defValues.insert(result);
        for (Value operand : op->getOperands())
          useValues.insert(operand);
      
      Block *parent = op->getBlock();
      if (visited.contains(parent))
        return;
      visited.insert(parent);
      for (BlockArgument arg : parent->getArguments()) {
        defValues.insert(arg);
      }
    });
```

https://github.com/llvm/llvm-project/pull/88848


More information about the Mlir-commits mailing list