5454#include " llvm/ADT/STLExtras.h"
5555#include " llvm/Support/Debug.h"
5656#include " llvm/Support/DebugLog.h"
57+ #include " llvm/Support/LogicalResult.h"
5758#include < cassert>
5859#include < cstddef>
5960#include < memory>
@@ -887,12 +888,12 @@ struct RemoveDeadValues : public impl::RemoveDeadValuesBase<RemoveDeadValues> {
887888// / }
888889// /
889890// / Returns true if any IR changes were made, false otherwise.
890- static bool processCallOp (CallOpInterface callOp, ModuleOp moduleOp,
891- RunLivenessAnalysis &la) {
891+ static LogicalResult processCallOp (CallOpInterface callOp, ModuleOp moduleOp,
892+ RunLivenessAnalysis &la, bool &changed ) {
892893 Operation *callableOp = callOp.resolveCallable ();
893894 auto funcOp = dyn_cast<FunctionOpInterface>(callableOp);
894895 if (!funcOp || !funcOp.isPublic ())
895- return false ;
896+ return LogicalResult::success () ;
896897
897898 LDBG () << " Processing callOp " << callOp << " target is a public function: "
898899 << funcOp.getOperation ()->getName ();
@@ -924,8 +925,10 @@ static bool processCallOp(CallOpInterface callOp, ModuleOp moduleOp,
924925 funcOp, clonedFunc.getNameAttr (), moduleOp);
925926
926927 if (result.failed ()) {
927- LDBG () << " Failed to replace all symbol uses for " << funcOp.getName ();
928- return false ;
928+ callOp.emitError (
929+ " Failed to replace all symbol uses when privatizing function " )
930+ << funcOp.getName ();
931+ return result;
929932 }
930933
931934 LDBG () << " Redirected all callsites from " << funcOp.getName () << " to "
@@ -980,25 +983,30 @@ static bool processCallOp(CallOpInterface callOp, ModuleOp moduleOp,
980983 newReturnOp->setLoc (funcOp.getLoc ());
981984 rewriter.insert (newReturnOp);
982985 }
983- return true ; // Changes were made
986+ changed = true ; // Changes were made
984987 }
985988
986- return false ;
989+ return LogicalResult::success () ;
987990}
988991
989992void RemoveDeadValues::runOnOperation () {
990993 AnalysisManager am = getAnalysisManager ();
991994 RunLivenessAnalysis *la = &am.getAnalysis <RunLivenessAnalysis>();
992995 Operation *module = getOperation ();
993996
994- // Only privatize public functions if liveness analysis is inter-procedural.
995- if (la->getSolverConfig ().isInterprocedural ()) {
997+ // In a module, only privatize public functions if liveness analysis is
998+ // inter-procedural.
999+ if (la->getSolverConfig ().isInterprocedural () && isa<ModuleOp>(module )) {
9961000 bool changed = false ;
997- module ->walk ([&](CallOpInterface callOp) {
998- if (processCallOp (callOp, cast<ModuleOp>(module ), *la)) {
999- changed = true ;
1000- }
1001- });
1001+ WalkResult walkResult =
1002+ module ->walk ([&](CallOpInterface callOp) -> WalkResult {
1003+ return processCallOp (callOp, cast<ModuleOp>(module ), *la, changed);
1004+ });
1005+
1006+ if (walkResult.wasInterrupted ()) {
1007+ signalPassFailure ();
1008+ return ;
1009+ }
10021010
10031011 if (changed) {
10041012 LDBG () << " IR has changed, invalidate RunLivenessAnalysis only" ;
@@ -1009,9 +1017,8 @@ void RemoveDeadValues::runOnOperation() {
10091017 la = &am.getAnalysis <RunLivenessAnalysis>();
10101018 // If RunLivenessAnalysis was previously preserved, preserved the updated
10111019 // results.
1012- if (preserved) {
1020+ if (preserved)
10131021 pa.preserve <RunLivenessAnalysis>();
1014- }
10151022 }
10161023 }
10171024
0 commit comments