Skip to content

Commit d54a007

Browse files
committed
[MLIR][LivenessAnalysis] Treat a public function as an external
This change treats a public function as an external function in the inter-procedural liveness analysis. This prohibits NonLive arguments from propagating to caller. RemoveDeadValues deletes unused values based on the results of liveness Analysis. On the other side, it can not change the signature of a public function.
1 parent 6634148 commit d54a007

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
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 returned by a public function OR
39+
/// (2) is an argument of or 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 returned by a public function OR
55+
/// (2) is an argument of or 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/IR/ValueRange.h"
1818
#include "mlir/Interfaces/CallInterfaces.h"
1919
#include "mlir/Interfaces/ControlFlowInterfaces.h"
20+
#include "mlir/Interfaces/FunctionInterfaces.h"
2021
#include "mlir/Support/LLVM.h"
2122
#include "llvm/ADT/STLExtras.h"
2223
#include "llvm/Support/DebugLog.h"
@@ -505,12 +506,18 @@ AbstractSparseBackwardDataFlowAnalysis::visitOperation(Operation *op) {
505506
// If the call invokes an external function (or a function treated as
506507
// external due to config), defer to the corresponding extension hook.
507508
// By default, it just does `visitCallOperand` for all operands.
509+
//
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.
508513
OperandRange argOperands = call.getArgOperands();
509514
MutableArrayRef<OpOperand> argOpOperands =
510515
operandsToOpOperands(argOperands);
511516
Region *region = callable.getCallableRegion();
517+
bool isPublicFunc = isa<FunctionOpInterface>(callableOp)
518+
&& cast<FunctionOpInterface>(callableOp).isPublic();
512519
if (!region || region->empty() ||
513-
!getSolverConfig().isInterprocedural()) {
520+
!getSolverConfig().isInterprocedural() || isPublicFunc) {
514521
visitExternalCallImpl(call, operandLattices, resultLattices);
515522
return success();
516523
}

0 commit comments

Comments
 (0)