Skip to content

[DebugInfo] Remove getPrevNonDebugInstruction #148859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2025
Merged
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
11 changes: 0 additions & 11 deletions llvm/include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,6 @@ class Instruction : public User,
/// Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
LLVM_ABI bool isDebugOrPseudoInst() const LLVM_READONLY;

/// Return a pointer to the previous non-debug instruction in the same basic
/// block as 'this', or nullptr if no such instruction exists. Skip any pseudo
/// operations if \c SkipPseudoOp is true.
LLVM_ABI const Instruction *
getPrevNonDebugInstruction(bool SkipPseudoOp = false) const;
Instruction *getPrevNonDebugInstruction(bool SkipPseudoOp = false) {
return const_cast<Instruction *>(
static_cast<const Instruction *>(this)->getPrevNonDebugInstruction(
SkipPseudoOp));
}

/// Create a copy of 'this' instruction that is identical in all ways except
/// the following:
/// * The instruction has no parent
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/LockstepReverseIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class LockstepReverseIterator
}
Insts.clear();
for (BasicBlock *BB : Blocks) {
Instruction *Prev = BB->getTerminator()->getPrevNonDebugInstruction();
Instruction *Prev = BB->getTerminator()->getPrevNode();
if (!Prev) {
// Block wasn't big enough - only contained a terminator.
if constexpr (EarlyFailure) {
Expand Down Expand Up @@ -108,7 +108,7 @@ class LockstepReverseIterator
return *this;
SmallVector<Instruction *, 4> NewInsts;
for (Instruction *Inst : Insts) {
Instruction *Prev = Inst->getPrevNonDebugInstruction();
Instruction *Prev = Inst->getPrevNode();
if (!Prev) {
if constexpr (!EarlyFailure) {
this->ActiveBlocks.remove(Inst->getParent());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3015,7 +3015,7 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB,
// %phi = phi ptr [ %0, %bb0 ], [ %2, %entry ]
if (PredBB && PredBB->getSingleSuccessor() == BB)
CI = dyn_cast_or_null<CallInst>(
PredBB->getTerminator()->getPrevNonDebugInstruction(true));
PredBB->getTerminator()->getPrevNode());

if (CI && CI->use_empty() &&
isIntrinsicOrLFToBeTailCalled(TLInfo, CI) &&
Expand All @@ -3032,7 +3032,7 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB,
for (BasicBlock *Pred : predecessors(BB)) {
if (!VisitedBBs.insert(Pred).second)
continue;
if (Instruction *I = Pred->rbegin()->getPrevNonDebugInstruction(true)) {
if (Instruction *I = Pred->rbegin()->getPrevNode()) {
CallInst *CI = dyn_cast<CallInst>(I);
if (CI && CI->use_empty() && TLI->mayBeEmittedAsTailCall(CI) &&
attributesPermitTailCall(F, CI, RetI, *TLI)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/StackProtector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ bool InsertStackProtectors(const TargetMachine *TM, Function *F,

// If we're instrumenting a block with a tail call, the check has to be
// inserted before the call rather than between it and the return.
Instruction *Prev = CheckLoc->getPrevNonDebugInstruction();
Instruction *Prev = CheckLoc->getPrevNode();
if (auto *CI = dyn_cast_if_present<CallInst>(Prev))
if (CI->isTailCall() && isInTailCallPosition(*CI, *TM))
CheckLoc = Prev;
Expand Down
8 changes: 0 additions & 8 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,6 @@ bool Instruction::isDebugOrPseudoInst() const {
return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
}

const Instruction *
Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {
for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
return I;
return nullptr;
}

const DebugLoc &Instruction::getStableDebugLoc() const {
return getDebugLoc();
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,7 @@ struct AAExecutionDomainFunction : public AAExecutionDomain {
if (It->getSecond().IsReachedFromAlignedBarrierOnly)
break;
return false;
} while ((CurI = CurI->getPrevNonDebugInstruction()));
} while ((CurI = CurI->getPrevNode()));

// Delayed decision on the forward pass to allow aligned barrier detection
// in the backwards traversal.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,7 @@ Instruction *InstCombinerImpl::visitFenceInst(FenceInst &FI) {
if (NFI && isIdenticalOrStrongerFence(NFI, &FI))
return eraseInstFromFunction(FI);

if (auto *PFI = dyn_cast_or_null<FenceInst>(FI.getPrevNonDebugInstruction()))
if (auto *PFI = dyn_cast_or_null<FenceInst>(FI.getPrevNode()))
if (isIdenticalOrStrongerFence(PFI, &FI))
return eraseInstFromFunction(FI);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,7 @@ bool InstCombinerImpl::removeInstructionsBeforeUnreachable(Instruction &I) {
// This includes instructions like stores and "llvm.assume" that may not get
// removed by simple dead code elimination.
bool Changed = false;
while (Instruction *Prev = I.getPrevNonDebugInstruction()) {
while (Instruction *Prev = I.getPrevNode()) {
// While we theoretically can erase EH, that would result in a block that
// used to start with an EH no longer starting with EH, which is invalid.
// To make it valid, we'd need to fixup predecessors to no longer refer to
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@ static void findStoresToUninstrumentedArgAllocas(
isa<Argument>(cast<CastInst>(Val)->getOperand(0)) &&
// Check that the cast appears directly before the store. Otherwise
// moving the cast before InsBefore may break the IR.
Val == It->getPrevNonDebugInstruction();
Val == It->getPrevNode();
bool IsArgInit = IsDirectArgInit || IsArgInitViaCast;
if (!IsArgInit)
continue;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ static Value *findDominatingValue(const MemoryLocation &Loc, Type *LoadTy,
BatchAAResults BatchAA(*AA);
for (BasicBlock *BB = FromBB; BB; BB = BB->getSinglePredecessor())
for (auto *Inst = BB == FromBB ? From : BB->getTerminator();
Inst != nullptr; Inst = Inst->getPrevNonDebugInstruction()) {
Inst != nullptr; Inst = Inst->getPrevNode()) {
// Stop the search if limit is reached.
if (++NumVisitedInsts > MaxNumVisitedInsts)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/GVNSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks,
BasicBlock *BBEnd) {
SmallVector<Instruction *, 4> Insts;
for (BasicBlock *BB : Blocks)
Insts.push_back(BB->getTerminator()->getPrevNonDebugInstruction());
Insts.push_back(BB->getTerminator()->getPrevNode());
Instruction *I0 = Insts.front();

SmallVector<Value *, 4> NewOperands;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ static bool tailMergeBlocksWithSimilarFunctionTerminators(Function &F,
// Calls to experimental_deoptimize must be followed by a return
// of the value computed by experimental_deoptimize.
// I.e., we can not change `ret` to `br` for this block.
if (auto *CI =
dyn_cast_or_null<CallInst>(Term->getPrevNonDebugInstruction())) {
if (auto *CI = dyn_cast_or_null<CallInst>(Term->getPrevNode())) {
if (Function *F = CI->getCalledFunction())
if (Intrinsic::ID ID = F->getIntrinsicID())
if (ID == Intrinsic::experimental_deoptimize)
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2736,8 +2736,8 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
EXPECT_EQ(OrigUpperBound->getValue(), 21);
EXPECT_EQ(OrigStride->getValue(), 1);

CallInst *FiniCall = dyn_cast<CallInst>(
&*(LatchBlock->getTerminator()->getPrevNonDebugInstruction(true)));
CallInst *FiniCall =
dyn_cast<CallInst>(&*(LatchBlock->getTerminator()->getPrevNode()));
EXPECT_EQ(FiniCall, nullptr);

// The original loop iterator should only be used in the condition, in the
Expand Down Expand Up @@ -2840,8 +2840,8 @@ TEST_F(OpenMPIRBuilderTest, DynamicWorkShareLoopOrdered) {
EXPECT_EQ(SchedVal->getValue(),
static_cast<uint64_t>(OMPScheduleType::OrderedStaticChunked));

CallInst *FiniCall = dyn_cast<CallInst>(
&*(LatchBlock->getTerminator()->getPrevNonDebugInstruction(true)));
CallInst *FiniCall =
dyn_cast<CallInst>(&*(LatchBlock->getTerminator()->getPrevNode()));
ASSERT_NE(FiniCall, nullptr);
EXPECT_EQ(FiniCall->getCalledFunction()->getName(),
"__kmpc_dispatch_fini_4u");
Expand Down
Loading