83 module.walk([&](func::CallOp callOp) {
84 if (func::FuncOp calledFunc =
85 dyn_cast_or_null<func::FuncOp>(callOp.resolveCallable())) {
86 if (calledFunc.isPublic() && !options.modifyPublicFunctions)
87 return WalkResult::advance();
88 if (!calledFunc.isExternal())
89 callerMap[calledFunc].insert(callOp);
94 for (
auto funcOp : module.getOps<
func::FuncOp>()) {
95 if (funcOp.isPublic() && !
options.modifyPublicFunctions)
97 if (funcOp.isExternal())
100 if (returnOps.empty())
104 size_t numReturnOps = returnOps.size();
105 size_t numReturnValues = funcOp.getFunctionType().getNumResults();
107 BitVector erasedResultIndices(numReturnValues);
109 for (
size_t i = 0; i < numReturnValues; ++i) {
115 resultToArgs[i] = bbArg.getArgNumber();
122 erasedResultIndices.set(i);
124 for (
auto [newReturnValue, operand] :
125 llvm::zip(newReturnValues, returnOperands)) {
126 newReturnValue.push_back(operand);
132 if (
failed(funcOp.eraseResults(erasedResultIndices)))
135 for (
auto [returnOp, newReturnValue] :
136 llvm::zip(returnOps, newReturnValues))
137 returnOp.getOperandsMutable().assign(newReturnValue);
140 for (func::CallOp callOp : callerMap[funcOp]) {
141 rewriter.setInsertionPoint(callOp);
142 auto newCallOp = func::CallOp::create(rewriter, callOp.getLoc(), funcOp,
143 callOp.getOperands());
146 for (
int64_t i = 0; i < callOp.getNumResults(); ++i) {
147 if (!resultToArgs.count(i)) {
149 newResults.push_back(newCallOp.getResult(nextResult++));
155 Type expectedType = callOp.getResult(i).getType();
158 replacement = memref::CastOp::create(rewriter, callOp.getLoc(),
163 rewriter.replaceOp(callOp, newResults);