Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mlir/IR/ValueRange.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/DebugLog.h"
Expand Down Expand Up @@ -505,12 +506,21 @@ AbstractSparseBackwardDataFlowAnalysis::visitOperation(Operation *op) {
// If the call invokes an external function (or a function treated as
// external due to config), defer to the corresponding extension hook.
// By default, it just does `visitCallOperand` for all operands.
//
// If callable is a public function, treat it as external.
// This is because a public function has potential callers we can't
// visit, and thus we need to be conservative and consider all
// arguments live.
OperandRange argOperands = call.getArgOperands();
MutableArrayRef<OpOperand> argOpOperands =
operandsToOpOperands(argOperands);
Region *region = callable.getCallableRegion();
if (!region || region->empty() ||
!getSolverConfig().isInterprocedural()) {
auto isPublicFunction = [&]() {
auto funcOp = dyn_cast<FunctionOpInterface>(callableOp);
return funcOp && funcOp.isPublic();
};
if (!getSolverConfig().isInterprocedural() || !region ||
region->empty() || isPublicFunction()) {
visitExternalCallImpl(call, operandLattices, resultLattices);
return success();
}
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Transforms/remove-dead-values.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,18 @@ module @return_void_with_unused_argument {
call @fn_return_void_with_unused_argument(%arg0, %unused) : (i32, memref<4xi32>) -> ()
return %unused : memref<4xi32>
}
// the function signature is immutable because it is public.
func.func public @public_fn_with_unused_argument(%unused: i32) -> () {
return
}
// CHECK-LABEL: func.func @main2
// CHECK: %[[UNUSED:.*]] = arith.constant 0 : i32
// CHECK: call @public_fn_with_unused_argument(%[[UNUSED]]) : (i32) -> ()
func.func @main2() -> () {
%zero = arith.constant 0 : i32
call @public_fn_with_unused_argument(%zero) : (i32) -> ()
return
}
}

// -----
Expand Down