Skip to content

Commit 63e8c0a

Browse files
authored
[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 <[email protected]> Co-authored-by: ikulagin <[email protected]>
1 parent fafc627 commit 63e8c0a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mlir/lib/Analysis/Liveness.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ struct BlockInfoBuilder {
7272
defValues.insert(result);
7373
for (Value operand : op->getOperands())
7474
useValues.insert(operand);
75+
for (Region &region : op->getRegions())
76+
for (Block &child : region.getBlocks())
77+
for (BlockArgument arg : child.getArguments())
78+
defValues.insert(arg);
7579
});
7680
llvm::set_subtract(useValues, defValues);
7781
}

mlir/test/Analysis/test-liveness.mlir

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,27 @@ func.func @nested_region3(
493493
}
494494
return %1 : i32
495495
}
496+
497+
// -----
498+
499+
// CHECK-LABEL: Testing : nested_region4
500+
501+
func.func @nested_region4(%arg0: index, %arg1: index, %arg2: index) {
502+
// CHECK: Block: 0
503+
// CHECK-NEXT: LiveIn:{{ *$}}
504+
// CHECK-NEXT: LiveOut:{{ *$}}
505+
506+
// CHECK: {{^// +}}[[VAL3:[a-z0-9_]+]]{{ *:}}
507+
// CHECK: {{^// +}}[[VAL4:[a-z0-9_]+]]{{ *:}}
508+
%c0_i32 = arith.constant 0 : i32
509+
%c1_i32 = arith.constant 1 : i32
510+
511+
%0 = scf.for %arg3 = %arg0 to %arg1 step %arg2 iter_args(%arg4 = %c0_i32) -> (i32) {
512+
// CHECK: Block: 1
513+
// CHECK-NEXT: LiveIn: [[VAL4]]{{ *$}}
514+
// CHECK-NEXT: LiveOut:{{ *$}}
515+
%1 = arith.addi %arg4, %c1_i32 : i32
516+
scf.yield %1 : i32
517+
}
518+
return
519+
}

0 commit comments

Comments
 (0)