Skip to content

Commit 153e6e6

Browse files
committed
Update the comment and also add lit test.
1 parent ed25cb7 commit 153e6e6

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

mlir/include/mlir/Analysis/DataFlow/LivenessAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace mlir::dataflow {
3636
///
3737
/// A value is considered "live" iff it:
3838
/// (1) has memory effects OR
39-
/// (2) is an argument of or is returned by a public function OR
39+
/// (2) is returned by a public function OR
4040
/// (3) is used to compute a value of type (1) or (2).
4141
/// It is also to be noted that a value could be of multiple types (1/2/3) at
4242
/// the same time.

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ChangeResult Liveness::meet(const AbstractSparseLattice &other) {
5252
///
5353
/// A value is considered "live" iff it:
5454
/// (1) has memory effects OR
55-
/// (2) is an argument of or is returned by a public function OR
55+
/// (2) is returned by a public function OR
5656
/// (3) is used to compute a value of type (1) or (2) OR
5757
/// (4) is returned by a return-like op whose parent isn't a callable
5858
/// nor a RegionBranchOpInterface (e.g.: linalg.yield, gpu.yield,...)

mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,18 @@ AbstractSparseBackwardDataFlowAnalysis::visitOperation(Operation *op) {
507507
// external due to config), defer to the corresponding extension hook.
508508
// By default, it just does `visitCallOperand` for all operands.
509509
//
510-
// If callable is a public function, treat it as an external function.
511-
// Transforms like RemoveDeadValues cannot change the arguments or returns
512-
// of it.
510+
// If callable is a public function, the signature is immutable.
511+
// We need to be conservative and consider all arguments Live.
513512
OperandRange argOperands = call.getArgOperands();
514513
MutableArrayRef<OpOperand> argOpOperands =
515514
operandsToOpOperands(argOperands);
516515
Region *region = callable.getCallableRegion();
517-
bool isPublicFunc = isa<FunctionOpInterface>(callableOp) &&
518-
cast<FunctionOpInterface>(callableOp).isPublic();
519-
if (!region || region->empty() ||
520-
!getSolverConfig().isInterprocedural() || isPublicFunc) {
516+
auto isPublicFunction = [&]() {
517+
auto funcOp = dyn_cast<FunctionOpInterface>(callableOp);
518+
return funcOp && funcOp.isPublic();
519+
};
520+
if (!getSolverConfig().isInterprocedural() || !region ||
521+
region->empty() || isPublicFunction()) {
521522
visitExternalCallImpl(call, operandLattices, resultLattices);
522523
return success();
523524
}

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,23 @@ module @return_void_with_unused_argument {
569569
call @fn_return_void_with_unused_argument(%arg0, %unused) : (i32, memref<4xi32>) -> ()
570570
return %unused : memref<4xi32>
571571
}
572+
// the function is immutable because it is public.
573+
func.func public @immutable_fn_return_void_with_unused_argument(%arg0: i32, %unused: i32) -> () {
574+
%sum = arith.addi %arg0, %arg0 : i32
575+
%c0 = arith.constant 0 : index
576+
%buf = memref.alloc() : memref<1xi32>
577+
memref.store %sum, %buf[%c0] : memref<1xi32>
578+
return
579+
}
580+
// CHECK-LABEL: func.func @main2
581+
// CHECK-SAME: (%[[ARG0_MAIN:.*]]: i32)
582+
// CHECK: %[[UNUSED:.*]] = arith.constant 0 : i32
583+
// CHECK: call @immutable_fn_return_void_with_unused_argument(%[[ARG0_MAIN]], %[[UNUSED]]) : (i32, i32) -> ()
584+
func.func @main2(%arg0: i32) -> () {
585+
%zero = arith.constant 0 : i32
586+
call @immutable_fn_return_void_with_unused_argument(%arg0, %zero) : (i32, i32) -> ()
587+
return
588+
}
572589
}
573590

574591
// -----

0 commit comments

Comments
 (0)