aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2025-01-24 13:27:56 +0000
committerGitHub <noreply@github.com>2025-01-24 13:27:56 +0000
commit6292a808b3524d9ba6f4ce55bc5b9e547b088dd8 (patch)
tree75d8253ec7b5085328930a26daf1f20c39682f80 /llvm/lib/Transforms/Utils/InlineFunction.cpp
parenta5cc897cdedfdca018a83fac5734ebe086acb817 (diff)
downloadllvm-6292a808b3524d9ba6f4ce55bc5b9e547b088dd8.zip
llvm-6292a808b3524d9ba6f4ce55bc5b9e547b088dd8.tar.gz
llvm-6292a808b3524d9ba6f4ce55bc5b9e547b088dd8.tar.bz2
[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (#123737)
As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to getFirstNonPHI use the iterator-returning version. This patch changes a bunch of call-sites calling getFirstNonPHI to use getFirstNonPHIIt, which returns an iterator. All these call sites are where it's obviously safe to fetch the iterator then dereference it. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, but not before adding concise documentation of what considerations are needed (very few). --------- Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index aa5e04d..6a8a468 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -276,7 +276,7 @@ static Value *getUnwindDestTokenHelper(Instruction *EHPad,
Value *UnwindDestToken = nullptr;
if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(CurrentPad)) {
if (CatchSwitch->hasUnwindDest()) {
- UnwindDestToken = CatchSwitch->getUnwindDest()->getFirstNonPHI();
+ UnwindDestToken = &*CatchSwitch->getUnwindDest()->getFirstNonPHIIt();
} else {
// Catchswitch doesn't have a 'nounwind' variant, and one might be
// annotated as "unwinds to caller" when really it's nounwind (see
@@ -288,7 +288,8 @@ static Value *getUnwindDestTokenHelper(Instruction *EHPad,
HE = CatchSwitch->handler_end();
HI != HE && !UnwindDestToken; ++HI) {
BasicBlock *HandlerBlock = *HI;
- auto *CatchPad = cast<CatchPadInst>(HandlerBlock->getFirstNonPHI());
+ auto *CatchPad =
+ cast<CatchPadInst>(&*HandlerBlock->getFirstNonPHIIt());
for (User *Child : CatchPad->users()) {
// Intentionally ignore invokes here -- since the catchswitch is
// marked "unwind to caller", it would be a verifier error if it
@@ -326,14 +327,14 @@ static Value *getUnwindDestTokenHelper(Instruction *EHPad,
for (User *U : CleanupPad->users()) {
if (auto *CleanupRet = dyn_cast<CleanupReturnInst>(U)) {
if (BasicBlock *RetUnwindDest = CleanupRet->getUnwindDest())
- UnwindDestToken = RetUnwindDest->getFirstNonPHI();
+ UnwindDestToken = &*RetUnwindDest->getFirstNonPHIIt();
else
UnwindDestToken = ConstantTokenNone::get(CleanupPad->getContext());
break;
}
Value *ChildUnwindDestToken;
if (auto *Invoke = dyn_cast<InvokeInst>(U)) {
- ChildUnwindDestToken = Invoke->getUnwindDest()->getFirstNonPHI();
+ ChildUnwindDestToken = &*Invoke->getUnwindDest()->getFirstNonPHIIt();
} else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U)) {
Instruction *ChildPad = cast<Instruction>(U);
auto Memo = MemoMap.find(ChildPad);
@@ -522,14 +523,13 @@ static Value *getUnwindDestToken(Instruction *EHPad,
if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(UselessPad)) {
assert(CatchSwitch->getUnwindDest() == nullptr && "Expected useless pad");
for (BasicBlock *HandlerBlock : CatchSwitch->handlers()) {
- auto *CatchPad = HandlerBlock->getFirstNonPHI();
+ auto *CatchPad = &*HandlerBlock->getFirstNonPHIIt();
for (User *U : CatchPad->users()) {
- assert(
- (!isa<InvokeInst>(U) ||
- (getParentPad(
- cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHI()) ==
- CatchPad)) &&
- "Expected useless pad");
+ assert((!isa<InvokeInst>(U) ||
+ (getParentPad(&*cast<InvokeInst>(U)
+ ->getUnwindDest()
+ ->getFirstNonPHIIt()) == CatchPad)) &&
+ "Expected useless pad");
if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
Worklist.push_back(cast<Instruction>(U));
}
@@ -538,11 +538,12 @@ static Value *getUnwindDestToken(Instruction *EHPad,
assert(isa<CleanupPadInst>(UselessPad));
for (User *U : UselessPad->users()) {
assert(!isa<CleanupReturnInst>(U) && "Expected useless pad");
- assert((!isa<InvokeInst>(U) ||
- (getParentPad(
- cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHI()) ==
- UselessPad)) &&
- "Expected useless pad");
+ assert(
+ (!isa<InvokeInst>(U) ||
+ (getParentPad(
+ &*cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHIIt()) ==
+ UselessPad)) &&
+ "Expected useless pad");
if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
Worklist.push_back(cast<Instruction>(U));
}
@@ -678,7 +679,7 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
BasicBlock *UnwindDest = II->getUnwindDest();
Function *Caller = FirstNewBlock->getParent();
- assert(UnwindDest->getFirstNonPHI()->isEHPad() && "unexpected BasicBlock!");
+ assert(UnwindDest->getFirstNonPHIIt()->isEHPad() && "unexpected BasicBlock!");
// If there are PHI nodes in the unwind destination block, we need to keep
// track of which values came into them from the invoke before removing the
@@ -723,7 +724,7 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
}
}
- Instruction *I = BB->getFirstNonPHI();
+ BasicBlock::iterator I = BB->getFirstNonPHIIt();
if (!I->isEHPad())
continue;
@@ -772,7 +773,7 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
}
if (Replacement) {
- Replacement->takeName(I);
+ Replacement->takeName(&*I);
I->replaceAllUsesWith(Replacement);
I->eraseFromParent();
UpdatePHINodes(&*BB);
@@ -2288,7 +2289,7 @@ remapIndices(Function &Caller, BasicBlock *StartBB,
// this may be the entryblock from the inlined callee, coming into a BB
// that didn't have instrumentation because of MST decisions. Let's make
// sure it's placed accordingly. This is a noop elsewhere.
- BBID->moveBefore(&*BB->getFirstInsertionPt());
+ BBID->moveBefore(BB->getFirstInsertionPt());
}
for (auto &I : llvm::make_early_inc_range(*BB)) {
if (auto *Inc = dyn_cast<InstrProfIncrementInst>(&I)) {
@@ -2581,7 +2582,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Ok, the call site is within a cleanuppad. Let's check the callee
// for catchpads.
for (const BasicBlock &CalledBB : *CalledFunc) {
- if (isa<CatchSwitchInst>(CalledBB.getFirstNonPHI()))
+ if (isa<CatchSwitchInst>(CalledBB.getFirstNonPHIIt()))
return InlineResult::failure("catch in cleanup funclet");
}
}
@@ -3029,7 +3030,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// rewriting the "parent pad" links.
if (auto *II = dyn_cast<InvokeInst>(&CB)) {
BasicBlock *UnwindDest = II->getUnwindDest();
- Instruction *FirstNonPHI = UnwindDest->getFirstNonPHI();
+ BasicBlock::iterator FirstNonPHI = UnwindDest->getFirstNonPHIIt();
if (isa<LandingPadInst>(FirstNonPHI)) {
HandleInlinedLandingPad(II, &*FirstNewBlock, InlinedFunctionInfo);
} else {
@@ -3055,7 +3056,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
if (CleanupRet->unwindsToCaller() && EHPadForCallUnwindsLocally)
changeToUnreachable(CleanupRet);
- Instruction *I = BB->getFirstNonPHI();
+ BasicBlock::iterator I = BB->getFirstNonPHIIt();
if (!I->isEHPad())
continue;