Skip to content

[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites #123737

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
Jan 24, 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
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,11 +1251,12 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
llvm::BasicBlock *WasmCatchStartBlock = nullptr;
if (EHPersonality::get(*this).isWasmPersonality()) {
auto *CatchSwitch =
cast<llvm::CatchSwitchInst>(DispatchBlock->getFirstNonPHI());
cast<llvm::CatchSwitchInst>(DispatchBlock->getFirstNonPHIIt());
WasmCatchStartBlock = CatchSwitch->hasUnwindDest()
? CatchSwitch->getSuccessor(1)
: CatchSwitch->getSuccessor(0);
auto *CPI = cast<llvm::CatchPadInst>(WasmCatchStartBlock->getFirstNonPHI());
auto *CPI =
cast<llvm::CatchPadInst>(WasmCatchStartBlock->getFirstNonPHIIt());
CurrentFuncletPad = CPI;
}

Expand Down Expand Up @@ -2252,7 +2253,7 @@ void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {
// __except blocks don't get outlined into funclets, so immediately do a
// catchret.
llvm::CatchPadInst *CPI =
cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHIIt());
llvm::BasicBlock *ExceptBB = createBasicBlock("__except");
Builder.CreateCatchRet(CPI, ExceptBB);
EmitBlock(ExceptBB);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/MicrosoftCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
VarDecl *CatchParam = S->getExceptionDecl();
llvm::BasicBlock *CatchPadBB = CGF.Builder.GetInsertBlock();
llvm::CatchPadInst *CPI =
cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHIIt());
CGF.CurrentFuncletPad = CPI;

// If this is a catch-all or the catch parameter is unnamed, we don't need to
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
void replaceSuccessorsPhiUsesWith(BasicBlock *New);

/// Return true if this basic block is an exception handling block.
bool isEHPad() const { return getFirstNonPHI()->isEHPad(); }
bool isEHPad() const { return getFirstNonPHIIt()->isEHPad(); }

/// Return true if this basic block is a landing pad.
///
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/Transforms/Utils/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ struct InstrumentationIRBuilder : IRBuilder<> {
explicit InstrumentationIRBuilder(Instruction *IP) : IRBuilder<>(IP) {
ensureDebugInfo(*this, *IP->getFunction());
}

explicit InstrumentationIRBuilder(BasicBlock *BB, BasicBlock::iterator It)
: IRBuilder<>(BB, It) {
ensureDebugInfo(*this, *BB->getParent());
}
};
} // end namespace llvm

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/Loads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool llvm::isDereferenceableAndAlignedInLoop(
DL.getTypeStoreSize(LI->getType()).getFixedValue());
const Align Alignment = LI->getAlign();

Instruction *HeaderFirstNonPHI = L->getHeader()->getFirstNonPHI();
Instruction *HeaderFirstNonPHI = &*L->getHeader()->getFirstNonPHIIt();

// If given a uniform (i.e. non-varying) address, see if we can prove the
// access is safe within the loop w/o needing predication.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LoopNestAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static bool checkLoopsStructure(const Loop &OuterLoop, const Loop &InnerLoop,
// "guarded" inner loop which contains "only" Phi nodes corresponding to the
// LCSSA Phi nodes in the exit block.
auto IsExtraPhiBlock = [&](const BasicBlock &BB) {
return BB.getFirstNonPHI() == BB.getTerminator() &&
return &*BB.getFirstNonPHIIt() == BB.getTerminator() &&
all_of(BB.phis(), [&](const PHINode &PN) {
return all_of(PN.blocks(), [&](const BasicBlock *IncomingBlock) {
return IncomingBlock == InnerLoopExit ||
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/MustExecute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool SimpleLoopSafetyInfo::isGuaranteedToExecute(const Instruction &Inst,
// exit. At the moment, we use a (cheap) hack for the common case where
// the instruction of interest is the first one in the block.
return !HeaderMayThrow ||
Inst.getParent()->getFirstNonPHIOrDbg() == &Inst;
&*Inst.getParent()->getFirstNonPHIOrDbg() == &Inst;

// If there is a path from header to exit or latch that doesn't lead to our
// instruction's block, return false.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8246,7 +8246,7 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
if (!BB || !Visited.insert(BB).second)
break;

Begin = BB->getFirstNonPHI()->getIterator();
Begin = BB->getFirstNonPHIIt();
End = BB->end();
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/WinException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ void WinException::computeIP2StateTable(
BaseState = NullState;
StartLabel = Asm->getFunctionBegin();
} else {
auto *FuncletPad =
cast<FuncletPadInst>(FuncletStart->getBasicBlock()->getFirstNonPHI());
auto *FuncletPad = cast<FuncletPadInst>(
FuncletStart->getBasicBlock()->getFirstNonPHIIt());
assert(FuncInfo.FuncletBaseStateMap.count(FuncletPad) != 0);
BaseState = FuncInfo.FuncletBaseStateMap.find(FuncletPad)->second;
StartLabel = getMCSymbolForMBB(Asm, &*FuncletStart);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,7 @@ bool IRTranslator::findUnwindDestinations(
}

while (EHPadBB) {
const Instruction *Pad = EHPadBB->getFirstNonPHI();
BasicBlock::const_iterator Pad = EHPadBB->getFirstNonPHIIt();
BasicBlock *NewEHPadBB = nullptr;
if (isa<LandingPadInst>(Pad)) {
// Stop on landingpads. They are not funclets.
Expand Down Expand Up @@ -2927,7 +2927,7 @@ bool IRTranslator::translateInvoke(const User &U,
return false;

// FIXME: support Windows exception handling.
if (!isa<LandingPadInst>(EHPadBB->getFirstNonPHI()))
if (!isa<LandingPadInst>(EHPadBB->getFirstNonPHIIt()))
return false;

// FIXME: support Windows dllimport function calls and calls through
Expand Down Expand Up @@ -4031,7 +4031,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
MF->push_back(EntryBB);
EntryBuilder->setMBB(*EntryBB);

DebugLoc DbgLoc = F.getEntryBlock().getFirstNonPHI()->getDebugLoc();
DebugLoc DbgLoc = F.getEntryBlock().getFirstNonPHIIt()->getDebugLoc();
SwiftError.setFunction(CurMF);
SwiftError.createEntriesInEntryBlock(DbgLoc);

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ void GlobalMergeImpl::setMustKeepGlobalVariables(Module &M) {

for (Function &F : M) {
for (BasicBlock &BB : F) {
Instruction *Pad = BB.getFirstNonPHI();
BasicBlock::iterator Pad = BB.getFirstNonPHIIt();
auto *II = dyn_cast<IntrinsicInst>(Pad);
if (!Pad->isEHPad() &&
!(II && II->getIntrinsicID() == Intrinsic::eh_typeid_for))
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) {
LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
LP.LandingPadLabel = LandingPadLabel;

const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
BasicBlock::const_iterator FirstI =
LandingPad->getBasicBlock()->getFirstNonPHIIt();
if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
// If there's no typeid list specified, then "cleanup" is implicit.
// Otherwise, id 0 is reserved for the cleanup action.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ bool SelectOptimizeImpl::checkLoopHeuristics(const Loop *L,
return true;

OptimizationRemarkMissed ORmissL(DEBUG_TYPE, "SelectOpti",
L->getHeader()->getFirstNonPHI());
&*L->getHeader()->getFirstNonPHIIt());

if (LoopCost[0].NonPredCost > LoopCost[0].PredCost ||
LoopCost[1].NonPredCost >= LoopCost[1].PredCost) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
// Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks
// are really data, and no instructions can live here.
if (BB.isEHPad()) {
const Instruction *PadInst = BB.getFirstNonPHI();
BasicBlock::const_iterator PadInst = BB.getFirstNonPHIIt();
// If this is a non-landingpad EH pad, mark this function as using
// funclets.
// FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid
Expand All @@ -261,13 +261,13 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
}
if (isa<CatchSwitchInst>(PadInst)) {
assert(&*BB.begin() == PadInst &&
assert(BB.begin() == PadInst &&
"WinEHPrepare failed to remove PHIs from imaginary BBs");
continue;
}
if (isa<FuncletPadInst>(PadInst) &&
Personality != EHPersonality::Wasm_CXX)
assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
assert(BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
}

MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(&BB);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ static void findWasmUnwindDestinations(
SmallVectorImpl<std::pair<MachineBasicBlock *, BranchProbability>>
&UnwindDests) {
while (EHPadBB) {
const Instruction *Pad = EHPadBB->getFirstNonPHI();
BasicBlock::const_iterator Pad = EHPadBB->getFirstNonPHIIt();
if (isa<CleanupPadInst>(Pad)) {
// Stop on cleanup pads.
UnwindDests.emplace_back(FuncInfo.getMBB(EHPadBB), Prob);
Expand Down Expand Up @@ -2111,7 +2111,7 @@ static void findUnwindDestinations(
}

while (EHPadBB) {
const Instruction *Pad = EHPadBB->getFirstNonPHI();
BasicBlock::const_iterator Pad = EHPadBB->getFirstNonPHIIt();
BasicBlock *NewEHPadBB = nullptr;
if (isa<LandingPadInst>(Pad)) {
// Stop on landingpads. They are not funclets.
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ bool SelectionDAGISel::PrepareEHLandingPad() {
// Catchpads have one live-in register, which typically holds the exception
// pointer or code.
if (isFuncletEHPersonality(Pers)) {
if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHI())) {
if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHIIt())) {
if (hasExceptionPointerOrCodeUser(CPI)) {
// Get or create the virtual register to hold the pointer or code. Mark
// the live in physreg and copy into the vreg.
Expand Down Expand Up @@ -1452,7 +1452,7 @@ bool SelectionDAGISel::PrepareEHLandingPad() {
MF->getRegInfo().addPhysRegsUsedFromRegMask(RegMask);

if (Pers == EHPersonality::Wasm_CXX) {
if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHI()))
if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHIIt()))
mapWasmLandingPadIndex(MBB, CPI);
} else {
// Assign the call site to the landing pad's begin label.
Expand Down Expand Up @@ -1721,13 +1721,12 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
// use anything def'd by or after the tail call.
{
BasicBlock::iterator BBStart =
const_cast<BasicBlock *>(LLVMBB)->getFirstNonPHI()->getIterator();
const_cast<BasicBlock *>(LLVMBB)->getFirstNonPHIIt();
BasicBlock::iterator BBEnd = const_cast<BasicBlock *>(LLVMBB)->end();
preserveFakeUses(BBStart, BBEnd);
}

BasicBlock::const_iterator const Begin =
LLVMBB->getFirstNonPHI()->getIterator();
BasicBlock::const_iterator const Begin = LLVMBB->getFirstNonPHIIt();
BasicBlock::const_iterator const End = LLVMBB->end();
BasicBlock::const_iterator BI = End;

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/WasmEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
for (BasicBlock &BB : F) {
if (!BB.isEHPad())
continue;
auto *Pad = BB.getFirstNonPHI();
BasicBlock::iterator Pad = BB.getFirstNonPHIIt();
if (isa<CatchPadInst>(Pad))
CatchPads.push_back(&BB);
else if (isa<CleanupPadInst>(Pad))
Expand Down Expand Up @@ -284,7 +284,7 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {

unsigned Index = 0;
for (auto *BB : CatchPads) {
auto *CPI = cast<CatchPadInst>(BB->getFirstNonPHI());
auto *CPI = cast<CatchPadInst>(BB->getFirstNonPHIIt());
// In case of a single catch (...), we don't need to emit a personalify
// function call
if (CPI->arg_size() == 1 &&
Expand All @@ -309,7 +309,7 @@ void WasmEHPrepareImpl::prepareEHPad(BasicBlock *BB, bool NeedPersonality,
IRBuilder<> IRB(BB->getContext());
IRB.SetInsertPoint(BB, BB->getFirstInsertionPt());

auto *FPI = cast<FuncletPadInst>(BB->getFirstNonPHI());
auto *FPI = cast<FuncletPadInst>(BB->getFirstNonPHIIt());
Instruction *GetExnCI = nullptr, *GetSelectorCI = nullptr;
for (auto &U : FPI->uses()) {
if (auto *CI = dyn_cast<CallInst>(U.getUser())) {
Expand Down Expand Up @@ -388,13 +388,13 @@ void llvm::calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo) {
for (const auto &BB : *F) {
if (!BB.isEHPad())
continue;
const Instruction *Pad = BB.getFirstNonPHI();
const Instruction *Pad = &*BB.getFirstNonPHIIt();

if (const auto *CatchPad = dyn_cast<CatchPadInst>(Pad)) {
const auto *UnwindBB = CatchPad->getCatchSwitch()->getUnwindDest();
if (!UnwindBB)
continue;
const Instruction *UnwindPad = UnwindBB->getFirstNonPHI();
const Instruction *UnwindPad = &*UnwindBB->getFirstNonPHIIt();
if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(UnwindPad))
// Currently there should be only one handler per a catchswitch.
EHInfo.setUnwindDest(&BB, *CatchSwitch->handlers().begin());
Expand Down
Loading
Loading