[Mlir-commits] [mlir] 63e8c0a - [mlir] Fix liveness analysis for block arguments (#88848)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu May 23 15:09:48 PDT 2024


Author: Ivan Kulagin
Date: 2024-05-23T15:09:45-07:00
New Revision: 63e8c0a0e48939371652f907bb868d74869ae00a

URL: https://github.com/llvm/llvm-project/commit/63e8c0a0e48939371652f907bb868d74869ae00a
DIFF: https://github.com/llvm/llvm-project/commit/63e8c0a0e48939371652f907bb868d74869ae00a.diff

LOG: [mlir] Fix liveness analysis for block arguments (#88848)

The current implementation does not take into account definitions
created by arguments of nested blocks. This leads to an incorrect
construction of the live-in set of an outer block. Arguments of nested
blocks are added to the live-in set of an outer block.

---------

Signed-off-by: ikulagin <i.kulagin at ispras.ru>
Co-authored-by: ikulagin <i.kulagin at ispras.ru>

Added: 
    

Modified: 
    mlir/lib/Analysis/Liveness.cpp
    mlir/test/Analysis/test-liveness.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Liveness.cpp b/mlir/lib/Analysis/Liveness.cpp
index a8e0daeabf406..e3245d68b3699 100644
--- a/mlir/lib/Analysis/Liveness.cpp
+++ b/mlir/lib/Analysis/Liveness.cpp
@@ -72,6 +72,10 @@ struct BlockInfoBuilder {
         defValues.insert(result);
       for (Value operand : op->getOperands())
         useValues.insert(operand);
+      for (Region &region : op->getRegions())
+        for (Block &child : region.getBlocks())
+          for (BlockArgument arg : child.getArguments())
+            defValues.insert(arg);
     });
     llvm::set_subtract(useValues, defValues);
   }

diff  --git a/mlir/test/Analysis/test-liveness.mlir b/mlir/test/Analysis/test-liveness.mlir
index 8ae3d09a6cd12..61a1e5fffa888 100644
--- a/mlir/test/Analysis/test-liveness.mlir
+++ b/mlir/test/Analysis/test-liveness.mlir
@@ -493,3 +493,27 @@ func.func @nested_region3(
   }
   return %1 : i32
 }
+
+// -----
+
+// CHECK-LABEL: Testing : nested_region4
+
+func.func @nested_region4(%arg0: index, %arg1: index, %arg2: index) {
+  // CHECK: Block: 0
+  // CHECK-NEXT: LiveIn:{{ *$}}
+  // CHECK-NEXT: LiveOut:{{ *$}}
+
+  // CHECK: {{^// +}}[[VAL3:[a-z0-9_]+]]{{ *:}}
+  // CHECK: {{^// +}}[[VAL4:[a-z0-9_]+]]{{ *:}}
+  %c0_i32 = arith.constant 0 : i32
+  %c1_i32 = arith.constant 1 : i32
+
+  %0 = scf.for %arg3 = %arg0 to %arg1 step %arg2 iter_args(%arg4 = %c0_i32) -> (i32) {
+    // CHECK: Block: 1
+    // CHECK-NEXT: LiveIn: [[VAL4]]{{ *$}}
+    // CHECK-NEXT: LiveOut:{{ *$}}
+    %1 = arith.addi %arg4, %c1_i32 : i32
+    scf.yield %1 : i32
+  }
+  return
+}


        


More information about the Mlir-commits mailing list