Author: Jeremy Morse Date: 2025-01-24T13:27:56Z New Revision: 6292a808b3524d9ba6f4ce55bc5b9e547b088dd8
URL: https://github.com/llvm/llvm-project/commit/6292a808b3524d9ba6f4ce55bc5b9e547b088dd8 DIFF: https://github.com/llvm/llvm-project/commit/6292a808b3524d9ba6f4ce55bc5b9e547b088dd8.diff LOG: [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 <melam...@gmail.com> Added: Modified: clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp llvm/include/llvm/IR/BasicBlock.h llvm/include/llvm/Transforms/Utils/Instrumentation.h llvm/lib/Analysis/Loads.cpp llvm/lib/Analysis/LoopNestAnalysis.cpp llvm/lib/Analysis/MustExecute.cpp llvm/lib/Analysis/ValueTracking.cpp llvm/lib/CodeGen/AsmPrinter/WinException.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/GlobalMerge.cpp llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectOptimize.cpp llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp llvm/lib/CodeGen/WasmEHPrepare.cpp llvm/lib/CodeGen/WinEHPrepare.cpp llvm/lib/IR/EHPersonalities.cpp llvm/lib/IR/Instructions.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/BPF/BPFAdjustOpt.cpp llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp llvm/lib/Target/X86/X86WinEHState.cpp llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp llvm/lib/Transforms/IPO/IROutliner.cpp llvm/lib/Transforms/IPO/PartialInlining.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp llvm/lib/Transforms/ObjCARC/ObjCARC.cpp llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp llvm/lib/Transforms/Scalar/GVN.cpp llvm/lib/Transforms/Scalar/GVNSink.cpp llvm/lib/Transforms/Scalar/LICM.cpp llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp llvm/lib/Transforms/Scalar/LoopInterchange.cpp llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp llvm/lib/Transforms/Scalar/SCCP.cpp llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/Local.cpp llvm/lib/Transforms/Utils/LoopSimplify.cpp llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp llvm/lib/Transforms/Utils/MoveAutoInit.cpp llvm/lib/Transforms/Utils/SSAUpdater.cpp llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/lib/Transforms/Vectorize/VPlan.cpp llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp llvm/unittests/Analysis/MemorySSATest.cpp llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp llvm/unittests/IR/DebugInfoTest.cpp llvm/unittests/IR/InstructionsTest.cpp llvm/unittests/Transforms/Scalar/LICMTest.cpp polly/lib/CodeGen/BlockGenerators.cpp polly/lib/CodeGen/LoopGenerators.cpp polly/lib/Transform/MaximalStaticExpansion.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index 5dc1686e7914c1..5a395c924333e7 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -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; } @@ -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); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 90651c3bafe26e..0d53e8cb45fe77 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -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 diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h index f85b221a211b91..e22fe1e7e7dc8f 100644 --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -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. /// diff --git a/llvm/include/llvm/Transforms/Utils/Instrumentation.h b/llvm/include/llvm/Transforms/Utils/Instrumentation.h index 4f67d079d14696..0e2c0d9bfa605a 100644 --- a/llvm/include/llvm/Transforms/Utils/Instrumentation.h +++ b/llvm/include/llvm/Transforms/Utils/Instrumentation.h @@ -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 diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index 11ccfa33821cad..9279f19b72a3f1 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -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. diff --git a/llvm/lib/Analysis/LoopNestAnalysis.cpp b/llvm/lib/Analysis/LoopNestAnalysis.cpp index fe6d270b9ac53c..ead5cf610d9e11 100644 --- a/llvm/lib/Analysis/LoopNestAnalysis.cpp +++ b/llvm/lib/Analysis/LoopNestAnalysis.cpp @@ -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 || diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index d5c665753075ce..fde6bbf9eb1817 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -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. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 38f88850be0f18..264fedd6b66b98 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -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; diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp index 6d6432b61f2d7d..97b4a6a42d81db 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -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); diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index f668e41094bbc8..21622ea43724c1 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -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. @@ -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 @@ -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); diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 9d4547df046d46..7b76155b175d1d 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -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)) diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index e4824183e8dfcf..ab3609b6141b8e 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -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. diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index 57488a90e7a4ab..b7600a3b7fba7a 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -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) { diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index 3e89b18585f153..33c63417444780 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -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 @@ -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); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index ecaa61fdc86a4d..428e7a316d247b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -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); @@ -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. diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 3b1abf7f3d994f..899f83bbc60647 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -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. @@ -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. @@ -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; diff --git a/llvm/lib/CodeGen/WasmEHPrepare.cpp b/llvm/lib/CodeGen/WasmEHPrepare.cpp index 1701b0d04425d2..d18196b2217f58 100644 --- a/llvm/lib/CodeGen/WasmEHPrepare.cpp +++ b/llvm/lib/CodeGen/WasmEHPrepare.cpp @@ -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)) @@ -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 && @@ -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())) { @@ -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()); diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp index c58c67b70fe3c2..6d85f078290337 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -201,7 +201,7 @@ static void calculateStateNumbersForInvokes(const Function *Fn, BasicBlock *FuncletUnwindDest; auto *FuncletPad = - dyn_cast<FuncletPadInst>(FuncletEntryBB->getFirstNonPHI()); + dyn_cast<FuncletPadInst>(FuncletEntryBB->getFirstNonPHIIt()); assert(FuncletPad || FuncletEntryBB == &Fn->getEntryBlock()); if (!FuncletPad) FuncletUnwindDest = nullptr; @@ -223,7 +223,7 @@ static void calculateStateNumbersForInvokes(const Function *Fn, if (BaseState != -1) { FuncInfo.InvokeStateMap[II] = BaseState; } else { - Instruction *PadInst = InvokeUnwindDest->getFirstNonPHI(); + Instruction *PadInst = &*InvokeUnwindDest->getFirstNonPHIIt(); assert(FuncInfo.EHPadStateMap.count(PadInst) && "EH Pad has no state!"); FuncInfo.InvokeStateMap[II] = FuncInfo.EHPadStateMap[PadInst]; } @@ -254,10 +254,10 @@ void llvm::calculateCXXStateForAsynchEH(const BasicBlock *BB, int State, if (EHInfo.BlockToStateMap.count(BB) && EHInfo.BlockToStateMap[BB] <= State) continue; // skip blocks already visited by lower State - const llvm::Instruction *I = BB->getFirstNonPHI(); + BasicBlock::const_iterator It = BB->getFirstNonPHIIt(); const llvm::Instruction *TI = BB->getTerminator(); - if (I->isEHPad()) - State = EHInfo.EHPadStateMap[I]; + if (It->isEHPad()) + State = EHInfo.EHPadStateMap[&*It]; EHInfo.BlockToStateMap[BB] = State; // Record state, also flag visiting if ((isa<CleanupReturnInst>(TI) || isa<CatchReturnInst>(TI)) && State > 0) { @@ -315,15 +315,15 @@ void llvm::calculateSEHStateForAsynchEH(const BasicBlock *BB, int State, if (EHInfo.BlockToStateMap.count(BB) && EHInfo.BlockToStateMap[BB] <= State) continue; // skip blocks already visited by lower State - const llvm::Instruction *I = BB->getFirstNonPHI(); + BasicBlock::const_iterator It = BB->getFirstNonPHIIt(); const llvm::Instruction *TI = BB->getTerminator(); - if (I->isEHPad()) - State = EHInfo.EHPadStateMap[I]; + if (It->isEHPad()) + State = EHInfo.EHPadStateMap[&*It]; EHInfo.BlockToStateMap[BB] = State; // Record state - if (isa<CatchPadInst>(I) && isa<CatchReturnInst>(TI)) { + if (isa<CatchPadInst>(It) && isa<CatchReturnInst>(TI)) { const Constant *FilterOrNull = cast<Constant>( - cast<CatchPadInst>(I)->getArgOperand(0)->stripPointerCasts()); + cast<CatchPadInst>(It)->getArgOperand(0)->stripPointerCasts()); const Function *Filter = dyn_cast<Function>(FilterOrNull); if (!Filter || !Filter->getName().starts_with("__IsLocalUnwind")) State = EHInfo.SEHUnwindMap[State].ToState; // Retrive next State @@ -385,7 +385,7 @@ static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo, SmallVector<const CatchPadInst *, 2> Handlers; for (const BasicBlock *CatchPadBB : CatchSwitch->handlers()) { - auto *CatchPad = cast<CatchPadInst>(CatchPadBB->getFirstNonPHI()); + auto *CatchPad = cast<CatchPadInst>(CatchPadBB->getFirstNonPHIIt()); Handlers.push_back(CatchPad); } int TryLow = addUnwindMapEntry(FuncInfo, ParentState, nullptr); @@ -393,7 +393,7 @@ static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo, for (const BasicBlock *PredBlock : predecessors(BB)) if ((PredBlock = getEHPadFromPredecessor(PredBlock, CatchSwitch->getParentPad()))) - calculateCXXStateNumbers(FuncInfo, PredBlock->getFirstNonPHI(), + calculateCXXStateNumbers(FuncInfo, &*PredBlock->getFirstNonPHIIt(), TryLow); int CatchLow = addUnwindMapEntry(FuncInfo, ParentState, nullptr); @@ -456,7 +456,7 @@ static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo, for (const BasicBlock *PredBlock : predecessors(BB)) { if ((PredBlock = getEHPadFromPredecessor(PredBlock, CleanupPad->getParentPad()))) { - calculateCXXStateNumbers(FuncInfo, PredBlock->getFirstNonPHI(), + calculateCXXStateNumbers(FuncInfo, &*PredBlock->getFirstNonPHIIt(), CleanupState); } } @@ -509,7 +509,7 @@ static void calculateSEHStateNumbers(WinEHFuncInfo &FuncInfo, assert(CatchSwitch->getNumHandlers() == 1 && "SEH doesn't have multiple handlers per __try"); const auto *CatchPad = - cast<CatchPadInst>((*CatchSwitch->handler_begin())->getFirstNonPHI()); + cast<CatchPadInst>((*CatchSwitch->handler_begin())->getFirstNonPHIIt()); const BasicBlock *CatchPadBB = CatchPad->getParent(); const Constant *FilterOrNull = cast<Constant>(CatchPad->getArgOperand(0)->stripPointerCasts()); @@ -526,7 +526,7 @@ static void calculateSEHStateNumbers(WinEHFuncInfo &FuncInfo, for (const BasicBlock *PredBlock : predecessors(BB)) if ((PredBlock = getEHPadFromPredecessor(PredBlock, CatchSwitch->getParentPad()))) - calculateSEHStateNumbers(FuncInfo, PredBlock->getFirstNonPHI(), + calculateSEHStateNumbers(FuncInfo, &*PredBlock->getFirstNonPHIIt(), TryState); // Everything in the __except block unwinds to ParentState, just like code @@ -562,7 +562,7 @@ static void calculateSEHStateNumbers(WinEHFuncInfo &FuncInfo, for (const BasicBlock *PredBlock : predecessors(BB)) if ((PredBlock = getEHPadFromPredecessor(PredBlock, CleanupPad->getParentPad()))) - calculateSEHStateNumbers(FuncInfo, PredBlock->getFirstNonPHI(), + calculateSEHStateNumbers(FuncInfo, &*PredBlock->getFirstNonPHIIt(), CleanupState); for (const User *U : CleanupPad->users()) { const auto *UserI = cast<Instruction>(U); @@ -594,7 +594,7 @@ void llvm::calculateSEHStateNumbers(const Function *Fn, for (const BasicBlock &BB : *Fn) { if (!BB.isEHPad()) continue; - const Instruction *FirstNonPHI = BB.getFirstNonPHI(); + const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt(); if (!isTopLevelPadForMSVC(FirstNonPHI)) continue; ::calculateSEHStateNumbers(FuncInfo, FirstNonPHI, -1); @@ -618,7 +618,7 @@ void llvm::calculateWinCXXEHStateNumbers(const Function *Fn, for (const BasicBlock &BB : *Fn) { if (!BB.isEHPad()) continue; - const Instruction *FirstNonPHI = BB.getFirstNonPHI(); + const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt(); if (!isTopLevelPadForMSVC(FirstNonPHI)) continue; calculateCXXStateNumbers(FuncInfo, FirstNonPHI, -1); @@ -678,7 +678,7 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn, // Seed a worklist with pads that have no parent. SmallVector<std::pair<const Instruction *, int>, 8> Worklist; for (const BasicBlock &BB : *Fn) { - const Instruction *FirstNonPHI = BB.getFirstNonPHI(); + const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt(); const Value *ParentPad; if (const auto *CPI = dyn_cast<CleanupPadInst>(FirstNonPHI)) ParentPad = CPI->getParentPad(); @@ -725,7 +725,7 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn, for (const BasicBlock *CatchBlock : llvm::reverse(CatchBlocks)) { // Create the entry for this catch with the appropriate handler // properties. - const auto *Catch = cast<CatchPadInst>(CatchBlock->getFirstNonPHI()); + const auto *Catch = cast<CatchPadInst>(CatchBlock->getFirstNonPHIIt()); uint32_t TypeToken = static_cast<uint32_t>( cast<ConstantInt>(Catch->getArgOperand(0))->getZExtValue()); CatchState = @@ -751,7 +751,7 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn, // so visit pads in descendant-most to ancestor-most order. for (ClrEHUnwindMapEntry &Entry : llvm::reverse(FuncInfo.ClrEHUnwindMap)) { const Instruction *Pad = - cast<const BasicBlock *>(Entry.Handler)->getFirstNonPHI(); + &*cast<const BasicBlock *>(Entry.Handler)->getFirstNonPHIIt(); // For most pads, the TryParentState is the state associated with the // unwind dest of exceptional exits from it. const BasicBlock *UnwindDest; @@ -800,7 +800,7 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn, // Now we have an unwind dest for the user, but we need to see if it // unwinds all the way out of the cleanup or if it stays within it. - const Instruction *UserUnwindPad = UserUnwindDest->getFirstNonPHI(); + const Instruction *UserUnwindPad = &*UserUnwindDest->getFirstNonPHIIt(); const Value *UserUnwindParent; if (auto *CSI = dyn_cast<CatchSwitchInst>(UserUnwindPad)) UserUnwindParent = CSI->getParentPad(); @@ -835,7 +835,8 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn, if (!UnwindDest) { UnwindDestState = -1; } else { - UnwindDestState = FuncInfo.EHPadStateMap[UnwindDest->getFirstNonPHI()]; + UnwindDestState = + FuncInfo.EHPadStateMap[&*UnwindDest->getFirstNonPHIIt()]; } Entry.TryParentState = UnwindDestState; @@ -863,7 +864,8 @@ void WinEHPrepareImpl::demotePHIsOnFunclets(Function &F, for (BasicBlock &BB : make_early_inc_range(F)) { if (!BB.isEHPad()) continue; - if (DemoteCatchSwitchPHIOnly && !isa<CatchSwitchInst>(BB.getFirstNonPHI())) + if (DemoteCatchSwitchPHIOnly && + !isa<CatchSwitchInst>(BB.getFirstNonPHIIt())) continue; for (Instruction &I : make_early_inc_range(BB)) { @@ -898,7 +900,7 @@ void WinEHPrepareImpl::cloneCommonBlocks(Function &F) { if (FuncletPadBB == &F.getEntryBlock()) FuncletToken = ConstantTokenNone::get(F.getContext()); else - FuncletToken = FuncletPadBB->getFirstNonPHI(); + FuncletToken = &*FuncletPadBB->getFirstNonPHIIt(); std::vector<std::pair<BasicBlock *, BasicBlock *>> Orig2Clone; ValueToValueMapTy VMap; @@ -1094,7 +1096,7 @@ void WinEHPrepareImpl::removeImplausibleInstructions(Function &F) { for (auto &Funclet : FuncletBlocks) { BasicBlock *FuncletPadBB = Funclet.first; std::vector<BasicBlock *> &BlocksInFunclet = Funclet.second; - Instruction *FirstNonPHI = FuncletPadBB->getFirstNonPHI(); + Instruction *FirstNonPHI = &*FuncletPadBB->getFirstNonPHIIt(); auto *FuncletPad = dyn_cast<FuncletPadInst>(FirstNonPHI); auto *CatchPad = dyn_cast_or_null<CatchPadInst>(FuncletPad); auto *CleanupPad = dyn_cast_or_null<CleanupPadInst>(FuncletPad); @@ -1228,7 +1230,7 @@ bool WinEHPrepareImpl::prepareExplicitEH(Function &F) { AllocaInst *WinEHPrepareImpl::insertPHILoads(PHINode *PN, Function &F) { BasicBlock *PHIBlock = PN->getParent(); AllocaInst *SpillSlot = nullptr; - Instruction *EHPad = PHIBlock->getFirstNonPHI(); + Instruction *EHPad = &*PHIBlock->getFirstNonPHIIt(); if (!EHPad->isTerminator()) { // If the EHPad isn't a terminator, then we can insert a load in this block @@ -1303,7 +1305,7 @@ void WinEHPrepareImpl::insertPHIStore( BasicBlock *PredBlock, Value *PredVal, AllocaInst *SpillSlot, SmallVectorImpl<std::pair<BasicBlock *, Value *>> &Worklist) { - if (PredBlock->isEHPad() && PredBlock->getFirstNonPHI()->isTerminator()) { + if (PredBlock->isEHPad() && PredBlock->getFirstNonPHIIt()->isTerminator()) { // Pred is unsplittable, so we need to queue it on the worklist. Worklist.push_back({PredBlock, PredVal}); return; diff --git a/llvm/lib/IR/EHPersonalities.cpp b/llvm/lib/IR/EHPersonalities.cpp index 7c32601b8a83ea..575130bff7a345 100644 --- a/llvm/lib/IR/EHPersonalities.cpp +++ b/llvm/lib/IR/EHPersonalities.cpp @@ -129,7 +129,7 @@ DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) { DEBUG_WITH_TYPE("win-eh-prepare-coloring", dbgs() << "Visiting " << Visiting->getName() << ", " << Color->getName() << "\n"); - Instruction *VisitingHead = Visiting->getFirstNonPHI(); + BasicBlock::iterator VisitingHead = Visiting->getFirstNonPHIIt(); if (VisitingHead->isEHPad()) { // Mark this funclet head as a member of itself. Color = Visiting; diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index b585d8cfbf2e2b..c9f5807765e400 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -832,7 +832,7 @@ InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB, } LandingPadInst *InvokeInst::getLandingPadInst() const { - return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI()); + return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHIIt()); } void InvokeInst::updateProfWeight(uint64_t S, uint64_t T) { diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 00280dbe5300b2..54de812517438b 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2726,7 +2726,7 @@ static Instruction *getSuccPad(Instruction *Terminator) { UnwindDest = CSI->getUnwindDest(); else UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest(); - return UnwindDest->getFirstNonPHI(); + return &*UnwindDest->getFirstNonPHIIt(); } void Verifier::verifySiblingFuncletUnwinds() { @@ -4585,7 +4585,7 @@ void Verifier::visitCatchPadInst(CatchPadInst &CPI) { // The catchpad instruction must be the first non-PHI instruction in the // block. - Check(BB->getFirstNonPHI() == &CPI, + Check(&*BB->getFirstNonPHIIt() == &CPI, "CatchPadInst not the first non-PHI instruction in the block.", &CPI); visitEHPadPredecessors(CPI); @@ -4609,7 +4609,7 @@ void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { // The cleanuppad instruction must be the first non-PHI instruction in the // block. - Check(BB->getFirstNonPHI() == &CPI, + Check(&*BB->getFirstNonPHIIt() == &CPI, "CleanupPadInst not the first non-PHI instruction in the block.", &CPI); auto *ParentPad = CPI.getParentPad(); @@ -4664,7 +4664,7 @@ void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { Value *UnwindPad; bool ExitsFPI; if (UnwindDest) { - UnwindPad = UnwindDest->getFirstNonPHI(); + UnwindPad = &*UnwindDest->getFirstNonPHIIt(); if (!cast<Instruction>(UnwindPad)->isEHPad()) continue; Value *UnwindParent = getParentPad(UnwindPad); @@ -4767,7 +4767,7 @@ void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest(); Value *SwitchUnwindPad; if (SwitchUnwindDest) - SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI(); + SwitchUnwindPad = &*SwitchUnwindDest->getFirstNonPHIIt(); else SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext()); Check(SwitchUnwindPad == FirstUnwindPad, @@ -4790,7 +4790,7 @@ void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { // The catchswitch instruction must be the first non-PHI instruction in the // block. - Check(BB->getFirstNonPHI() == &CatchSwitch, + Check(&*BB->getFirstNonPHIIt() == &CatchSwitch, "CatchSwitchInst not the first non-PHI instruction in the block.", &CatchSwitch); @@ -4799,14 +4799,14 @@ void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { "CatchSwitchInst has an invalid parent.", ParentPad); if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) { - Instruction *I = UnwindDest->getFirstNonPHI(); + BasicBlock::iterator I = UnwindDest->getFirstNonPHIIt(); Check(I->isEHPad() && !isa<LandingPadInst>(I), "CatchSwitchInst must unwind to an EH block which is not a " "landingpad.", &CatchSwitch); // Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds - if (getParentPad(I) == ParentPad) + if (getParentPad(&*I) == ParentPad) SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch; } @@ -4814,7 +4814,7 @@ void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { "CatchSwitchInst cannot have empty handler list", &CatchSwitch); for (BasicBlock *Handler : CatchSwitch.handlers()) { - Check(isa<CatchPadInst>(Handler->getFirstNonPHI()), + Check(isa<CatchPadInst>(Handler->getFirstNonPHIIt()), "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler); } @@ -4828,7 +4828,7 @@ void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { CRI.getOperand(0)); if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { - Instruction *I = UnwindDest->getFirstNonPHI(); + BasicBlock::iterator I = UnwindDest->getFirstNonPHIIt(); Check(I->isEHPad() && !isa<LandingPadInst>(I), "CleanupReturnInst must unwind to an EH block which is not a " "landingpad.", diff --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp index 1b2558d2e40092..afc47968bf657f 100644 --- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp +++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp @@ -222,7 +222,7 @@ bool BPFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) { if (!BI || !BI->isConditional()) return false; auto *Cond = dyn_cast<ICmpInst>(BI->getCondition()); - if (!Cond || B2->getFirstNonPHI() != Cond) + if (!Cond || &*B2->getFirstNonPHIIt() != Cond) return false; Value *B2Op0 = Cond->getOperand(0); auto Cond2Op = Cond->getPredicate(); diff --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp index 991ee5b1cbaa53..d2ae2ef7bd7ff3 100644 --- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp +++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp @@ -1097,8 +1097,7 @@ bool PolynomialMultiplyRecognize::promoteTypes(BasicBlock *LoopB, promoteTo(In, DestTy, LoopB); // Fix up the PHI nodes in the exit block. - Instruction *EndI = ExitB->getFirstNonPHI(); - BasicBlock::iterator End = EndI ? EndI->getIterator() : ExitB->end(); + BasicBlock::iterator End = ExitB->getFirstNonPHIIt(); for (auto I = ExitB->begin(); I != End; ++I) { PHINode *P = dyn_cast<PHINode>(I); if (!P) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index 839a206033a0c6..c60cf69c301047 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -1199,7 +1199,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) { // Look for orphan landingpads, can occur in blocks with no predecessors for (BasicBlock &BB : F) { - Instruction *I = BB.getFirstNonPHI(); + BasicBlock::iterator I = BB.getFirstNonPHIIt(); if (auto *LPI = dyn_cast<LandingPadInst>(I)) LandingPads.insert(LPI); } @@ -1739,7 +1739,7 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj( SmallVector<Instruction *, 16> ToErase; for (auto &BB : F) { - if (auto *CSI = dyn_cast<CatchSwitchInst>(BB.getFirstNonPHI())) { + if (auto *CSI = dyn_cast<CatchSwitchInst>(BB.getFirstNonPHIIt())) { if (CSI != CatchSwitchLongjmp && CSI->unwindsToCaller()) { IRB.SetInsertPoint(CSI); ToErase.push_back(CSI); diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp index 35b7d7f508b02f..7d6d3f8d21f252 100644 --- a/llvm/lib/Target/X86/X86WinEHState.cpp +++ b/llvm/lib/Target/X86/X86WinEHState.cpp @@ -513,7 +513,7 @@ int WinEHStatePass::getBaseStateForBB( assert(BBColors.size() == 1 && "multi-color BB not removed by preparation"); BasicBlock *FuncletEntryBB = BBColors.front(); if (auto *FuncletPad = - dyn_cast<FuncletPadInst>(FuncletEntryBB->getFirstNonPHI())) { + dyn_cast<FuncletPadInst>(FuncletEntryBB->getFirstNonPHIIt())) { auto BaseStateI = FuncInfo.FuncletBaseStateMap.find(FuncletPad); if (BaseStateI != FuncInfo.FuncletBaseStateMap.end()) BaseState = BaseStateI->second; @@ -741,7 +741,7 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) { for (BasicBlock *BB : RPOT) { auto &BBColors = BlockColors[BB]; BasicBlock *FuncletEntryBB = BBColors.front(); - if (isa<CleanupPadInst>(FuncletEntryBB->getFirstNonPHI())) + if (isa<CleanupPadInst>(FuncletEntryBB->getFirstNonPHIIt())) continue; int PrevState = getPredState(FinalStates, F, ParentBaseState, BB); @@ -783,7 +783,7 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) { for (CallBase *Call : SetJmp3Calls) { auto &BBColors = BlockColors[Call->getParent()]; BasicBlock *FuncletEntryBB = BBColors.front(); - bool InCleanup = isa<CleanupPadInst>(FuncletEntryBB->getFirstNonPHI()); + bool InCleanup = isa<CleanupPadInst>(FuncletEntryBB->getFirstNonPHIIt()); IRBuilder<> Builder(Call); Value *State; diff --git a/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp b/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp index cc462011a62423..3686c7c153999c 100644 --- a/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp +++ b/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp @@ -180,12 +180,12 @@ static void rewriteMaterializableInstructions( // insert the remats into the end of the predecessor (there should only be // one). This is so that suspend blocks always have the suspend instruction // as the first instruction. - auto InsertPoint = &*Use->getParent()->getFirstInsertionPt(); + BasicBlock::iterator InsertPoint = Use->getParent()->getFirstInsertionPt(); if (isa<AnyCoroSuspendInst>(Use)) { BasicBlock *SuspendPredecessorBlock = Use->getParent()->getSinglePredecessor(); assert(SuspendPredecessorBlock && "malformed coro suspend instruction"); - InsertPoint = SuspendPredecessorBlock->getTerminator(); + InsertPoint = SuspendPredecessorBlock->getTerminator()->getIterator(); } // Note: skip the first instruction as this is the actual use that we're @@ -197,7 +197,7 @@ static void rewriteMaterializableInstructions( CurrentMaterialization = D->clone(); CurrentMaterialization->setName(D->getName()); CurrentMaterialization->insertBefore(InsertPoint); - InsertPoint = CurrentMaterialization; + InsertPoint = CurrentMaterialization->getIterator(); // Replace all uses of Def in the instructions being added as part of this // rematerialization group diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index 6cc218e63a0129..3f54106bd09fe9 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -1754,7 +1754,7 @@ findOrCreatePHIInBlock(PHINode &PN, OutlinableRegion &Region, // If we've made it here, it means we weren't able to replace the PHINode, so // we must insert it ourselves. PHINode *NewPN = cast<PHINode>(PN.clone()); - NewPN->insertBefore(&*OverallPhiBlock->begin()); + NewPN->insertBefore(OverallPhiBlock->begin()); for (unsigned Idx = 0, Edx = NewPN->getNumIncomingValues(); Idx < Edx; Idx++) { Value *IncomingVal = NewPN->getIncomingValue(Idx); diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp index 28c81465a09489..cead7b84c3fc85 100644 --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -1039,7 +1039,7 @@ void PartialInlinerImpl::FunctionCloner::normalizeReturnBlock() const { }; ClonedOI->ReturnBlock = ClonedOI->ReturnBlock->splitBasicBlock( - ClonedOI->ReturnBlock->getFirstNonPHI()->getIterator()); + ClonedOI->ReturnBlock->getFirstNonPHIIt()); BasicBlock::iterator I = PreReturn->begin(); BasicBlock::iterator Ins = ClonedOI->ReturnBlock->begin(); SmallVector<Instruction *, 4> DeadPhis; diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index cca6f78084b468..e5f3b7f24bca7a 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -689,11 +689,11 @@ class RuntimeCallInserter { } BasicBlock *Color = Colors.front(); - Instruction *EHPad = Color->getFirstNonPHI(); + BasicBlock::iterator EHPadIt = Color->getFirstNonPHIIt(); - if (EHPad && EHPad->isEHPad()) { + if (EHPadIt != Color->end() && EHPadIt->isEHPad()) { // Replace CI with a clone with an added funclet OperandBundle - OperandBundleDef OB("funclet", EHPad); + OperandBundleDef OB("funclet", &*EHPadIt); auto *NewCall = CallBase::addOperandBundle(CI, LLVMContext::OB_funclet, OB, CI->getIterator()); NewCall->copyMetadata(*CI); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 8e9b85c8d68579..56d3eb10d73e95 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1205,8 +1205,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { removeUnreachableBlocks(F); MS.initializeCallbacks(*F.getParent(), TLI); - FnPrologueEnd = IRBuilder<>(F.getEntryBlock().getFirstNonPHI()) - .CreateIntrinsic(Intrinsic::donothing, {}, {}); + FnPrologueEnd = + IRBuilder<>(&F.getEntryBlock(), F.getEntryBlock().getFirstNonPHIIt()) + .CreateIntrinsic(Intrinsic::donothing, {}, {}); if (MS.CompileKernel) { IRBuilder<> IRB(FnPrologueEnd); diff --git a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp index 57e39c4eae9668..d396dbf75eebc6 100644 --- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp @@ -760,7 +760,7 @@ void NumericalStabilitySanitizer::createShadowArguments( })) return; - IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHI()); + IRBuilder<> Builder(&F.getEntryBlock(), F.getEntryBlock().getFirstNonPHIIt()); // The function has shadow args if the shadow args tag matches the function // address. Value *HasShadowArgs = Builder.CreateICmpEQ( diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index db4d62ec36751a..5ad07e83d12736 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -910,9 +910,9 @@ populateEHOperandBundle(VPCandidateInfo &Cand, if (!BlockColors.empty()) { const ColorVector &CV = BlockColors.find(OrigCall->getParent())->second; assert(CV.size() == 1 && "non-unique color for block!"); - Instruction *EHPad = CV.front()->getFirstNonPHI(); - if (EHPad->isEHPad()) - OpBundles.emplace_back("funclet", EHPad); + BasicBlock::iterator EHPadIt = CV.front()->getFirstNonPHIIt(); + if (EHPadIt->isEHPad()) + OpBundles.emplace_back("funclet", &*EHPadIt); } } } diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp index dc51c564fbe0d4..f6780c0f06b185 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp @@ -386,7 +386,7 @@ bool MemOPSizeOpt::perform(MemOp MO) { PHINode *PHI = nullptr; if (!MemOpTy->isVoidTy()) { // Insert a phi for the return values at the merge block. - IRBuilder<> IRBM(MergeBB->getFirstNonPHI()); + IRBuilder<> IRBM(MergeBB, MergeBB->getFirstNonPHIIt()); PHI = IRBM.CreatePHI(MemOpTy, SizeIds.size() + 1, "MemOP.RVMerge"); MO.I->replaceAllUsesWith(PHI); PHI->addIncoming(MO.I, DefaultBB); diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index e0070e583b6812..7deaac5e59a28e 100644 --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -479,7 +479,8 @@ static bool isTsanAtomic(const Instruction *I) { } void ThreadSanitizer::InsertRuntimeIgnores(Function &F) { - InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI()); + InstrumentationIRBuilder IRB(&F.getEntryBlock(), + F.getEntryBlock().getFirstNonPHIIt()); IRB.CreateCall(TsanIgnoreBegin); EscapeEnumerator EE(F, "tsan_ignore_cleanup", ClHandleCxxExceptions); while (IRBuilder<> *AtExit = EE.Next()) { @@ -569,7 +570,8 @@ bool ThreadSanitizer::sanitizeFunction(Function &F, // Instrument function entry/exit points if there were instrumented accesses. if ((Res || HasCalls) && ClInstrumentFuncEntryExit) { - InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI()); + InstrumentationIRBuilder IRB(&F.getEntryBlock(), + F.getEntryBlock().getFirstNonPHIIt()); Value *ReturnAddress = IRB.CreateIntrinsic(Intrinsic::returnaddress, {}, IRB.getInt32(0)); IRB.CreateCall(TsanFuncEntry, ReturnAddress); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp index 33870d7ea192a3..b6ade1c29a2b58 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp @@ -32,9 +32,9 @@ CallInst *objcarc::createCallInstWithColors( if (!BlockColors.empty()) { const ColorVector &CV = BlockColors.find(InsertBefore->getParent())->second; assert(CV.size() == 1 && "non-unique color for block!"); - Instruction *EHPad = CV.front()->getFirstNonPHI(); + BasicBlock::iterator EHPad = CV.front()->getFirstNonPHIIt(); if (EHPad->isEHPad()) - OpBundles.emplace_back("funclet", EHPad); + OpBundles.emplace_back("funclet", &*EHPad); } return CallInst::Create(FTy, Callee, Args, OpBundles, NameStr, InsertBefore); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index b020591c203dbd..8407726a69c0ba 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -627,7 +627,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) { // block with a catchswitch has no insertion point. Keep going up // the dominator tree until we find a non-catchswitch. BasicBlock *InsertBB = IncomingBB; - while (isa<CatchSwitchInst>(InsertBB->getFirstNonPHI())) { + while (isa<CatchSwitchInst>(InsertBB->getFirstNonPHIIt())) { InsertBB = DT->getNode(InsertBB)->getIDom()->getBlock(); } diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 340d55190a5e6c..9d7f5e64f98683 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -583,7 +583,8 @@ class ObjCARCOpt { const ColorVector &CV = BlockEHColors.find(BB)->second; assert(CV.size() > 0 && "Uncolored block"); for (BasicBlock *EHPadBB : CV) - if (auto *EHPad = dyn_cast<FuncletPadInst>(EHPadBB->getFirstNonPHI())) { + if (auto *EHPad = + dyn_cast<FuncletPadInst>(EHPadBB->getFirstNonPHIIt())) { OpBundles.emplace_back("funclet", EHPad); return; } diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index def4add46e5ba1..21eb7f741d7c82 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1720,7 +1720,8 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock, // to speculatively execute the load at that points. if (MustEnsureSafetyOfSpeculativeExecution) { if (CriticalEdgePredSplit.size()) - if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), AC, DT)) + if (!isSafeToSpeculativelyExecute(Load, &*LoadBB->getFirstNonPHIIt(), AC, + DT)) return false; for (auto &PL : PredLoads) if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(), AC, diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp index 730f5cd0f8d0d7..6651281ff2d011 100644 --- a/llvm/lib/Transforms/Scalar/GVNSink.cpp +++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp @@ -906,7 +906,7 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks, // and move it to the start of the successor block. for (unsigned O = 0, E = I0->getNumOperands(); O != E; ++O) I0->getOperandUse(O).set(NewOperands[O]); - I0->moveBefore(&*BBEnd->getFirstInsertionPt()); + I0->moveBefore(BBEnd->getFirstInsertionPt()); // Update metadata and IR flags. for (auto *I : Insts) diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 658187ed745059..1a65154ae5936b 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1448,9 +1448,9 @@ static Instruction *cloneInstructionInExitBlock( const ColorVector &CV = BlockColors.find(&ExitBlock)->second; assert(CV.size() == 1 && "non-unique color for exit block!"); BasicBlock *BBColor = CV.front(); - Instruction *EHPad = BBColor->getFirstNonPHI(); + BasicBlock::iterator EHPad = BBColor->getFirstNonPHIIt(); if (EHPad->isEHPad()) - OpBundles.emplace_back("funclet", EHPad); + OpBundles.emplace_back("funclet", &*EHPad); } New = CallInst::Create(CI, OpBundles); @@ -1549,7 +1549,8 @@ static bool canSplitPredecessors(PHINode *PN, LoopSafetyInfo *SafetyInfo) { // it require updating BlockColors for all offspring blocks accordingly. By // skipping such corner case, we can make updating BlockColors after splitting // predecessor fairly simple. - if (!SafetyInfo->getBlockColors().empty() && BB->getFirstNonPHI()->isEHPad()) + if (!SafetyInfo->getBlockColors().empty() && + BB->getFirstNonPHIIt()->isEHPad()) return false; for (BasicBlock *BBPred : predecessors(BB)) { if (isa<IndirectBrInst>(BBPred->getTerminator())) diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 3c82eeda548382..c5091e731444ef 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -1641,8 +1641,8 @@ static bool detectShiftUntilLessThanIdiom(Loop *CurLoop, const DataLayout &DL, // plus "cnt0". Currently it is not optimized. // This step could be used to detect POPCNT instruction: // cnt.next = cnt + (x.next & 1) - for (Instruction &Inst : llvm::make_range( - LoopEntry->getFirstNonPHI()->getIterator(), LoopEntry->end())) { + for (Instruction &Inst : + llvm::make_range(LoopEntry->getFirstNonPHIIt(), LoopEntry->end())) { if (Inst.getOpcode() != Instruction::Add) continue; @@ -1745,8 +1745,8 @@ static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB, // step 4: Find the instruction which count the population: cnt2 = cnt1 + 1 { CountInst = nullptr; - for (Instruction &Inst : llvm::make_range( - LoopEntry->getFirstNonPHI()->getIterator(), LoopEntry->end())) { + for (Instruction &Inst : + llvm::make_range(LoopEntry->getFirstNonPHIIt(), LoopEntry->end())) { if (Inst.getOpcode() != Instruction::Add) continue; @@ -1869,8 +1869,8 @@ static bool detectShiftUntilZeroIdiom(Loop *CurLoop, const DataLayout &DL, // plus "cnt0". Currently it is not optimized. // This step could be used to detect POPCNT instruction: // cnt.next = cnt + (x.next & 1) - for (Instruction &Inst : llvm::make_range( - LoopEntry->getFirstNonPHI()->getIterator(), LoopEntry->end())) { + for (Instruction &Inst : + llvm::make_range(LoopEntry->getFirstNonPHIIt(), LoopEntry->end())) { if (Inst.getOpcode() != Instruction::Add) continue; diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index ed80040aa4236b..38fc682698c53e 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1350,7 +1350,7 @@ bool LoopInterchangeTransform::transform() { // Duplicate instruction and move it the new latch. Update uses that // have been moved. Instruction *NewI = WorkList[i]->clone(); - NewI->insertBefore(NewLatch->getFirstNonPHI()); + NewI->insertBefore(NewLatch->getFirstNonPHIIt()); assert(!NewI->mayHaveSideEffects() && "Moving instructions with side-effects may change behavior of " "the loop nest!"); @@ -1388,8 +1388,9 @@ bool LoopInterchangeTransform::transform() { // Ensure the inner loop phi nodes have a separate basic block. BasicBlock *InnerLoopHeader = InnerLoop->getHeader(); - if (InnerLoopHeader->getFirstNonPHI() != InnerLoopHeader->getTerminator()) { - SplitBlock(InnerLoopHeader, InnerLoopHeader->getFirstNonPHI(), DT, LI); + if (&*InnerLoopHeader->getFirstNonPHIIt() != + InnerLoopHeader->getTerminator()) { + SplitBlock(InnerLoopHeader, InnerLoopHeader->getFirstNonPHIIt(), DT, LI); LLVM_DEBUG(dbgs() << "splitting InnerLoopHeader done\n"); } @@ -1526,12 +1527,12 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader, // InnerLatch, which will become the new exit block for the innermost // loop after interchanging. for (PHINode *P : LcssaInnerExit) - P->moveBefore(InnerLatch->getFirstNonPHI()); + P->moveBefore(InnerLatch->getFirstNonPHIIt()); // If the inner loop latch contains LCSSA PHIs, those come from a child loop // and we have to move them to the new inner latch. for (PHINode *P : LcssaInnerLatch) - P->moveBefore(InnerExit->getFirstNonPHI()); + P->moveBefore(InnerExit->getFirstNonPHIIt()); // Deal with LCSSA PHI nodes in the loop nest exit block. For PHIs that have // incoming values defined in the outer loop, we have to add a new PHI @@ -1557,7 +1558,7 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader, continue; NewPhi->addIncoming(P.getIncomingValue(0), Pred); } - NewPhi->insertBefore(InnerLatch->getFirstNonPHI()); + NewPhi->insertBefore(InnerLatch->getFirstNonPHIIt()); P.setIncomingValue(0, NewPhi); } } @@ -1697,12 +1698,12 @@ bool LoopInterchangeTransform::adjustLoopBranches() { // outer loop and all the remains to do is and updating the incoming blocks. for (PHINode *PHI : OuterLoopPHIs) { LLVM_DEBUG(dbgs() << "Outer loop reduction PHIs:\n"; PHI->dump();); - PHI->moveBefore(InnerLoopHeader->getFirstNonPHI()); + PHI->moveBefore(InnerLoopHeader->getFirstNonPHIIt()); assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); } for (PHINode *PHI : InnerLoopPHIs) { LLVM_DEBUG(dbgs() << "Inner loop reduction PHIs:\n"; PHI->dump();); - PHI->moveBefore(OuterLoopHeader->getFirstNonPHI()); + PHI->moveBefore(OuterLoopHeader->getFirstNonPHIIt()); assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); } diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp index ae9103d0608a11..765b76e54068c7 100644 --- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -365,7 +365,7 @@ class ConstantTerminatorFoldingImpl { for (auto &PN : BB->phis()) DeadInstructions.push_back(&PN); - if (auto *LandingPad = dyn_cast<LandingPadInst>(BB->getFirstNonPHI())) + if (auto *LandingPad = dyn_cast<LandingPadInst>(BB->getFirstNonPHIIt())) DeadInstructions.emplace_back(LandingPad); for (Instruction *I : DeadInstructions) { diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 7ec1949c1c10f4..8be2f78187a0c6 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -102,7 +102,7 @@ static bool runSCCP(Function &F, const DataLayout &DL, // Remove unreachable blocks and non-feasible edges. for (BasicBlock *DeadBB : BlocksToErase) - NumInstRemoved += changeToUnreachable(DeadBB->getFirstNonPHI(), + NumInstRemoved += changeToUnreachable(&*DeadBB->getFirstNonPHIIt(), /*PreserveLCSSA=*/false, &DTU); BasicBlock *NewUnreachableBB = nullptr; diff --git a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp index 4606514cbc7175..62b4b545f29bb8 100644 --- a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -366,8 +366,8 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F, continue; // Don't even think about ehpads/landingpads. - Instruction *FirstNonPHI = Target->getFirstNonPHI(); - if (FirstNonPHI->isEHPad() || Target->isLandingPad()) + auto FirstNonPHIIt = Target->getFirstNonPHIIt(); + if (FirstNonPHIIt->isEHPad() || Target->isLandingPad()) continue; // Remember edge probabilities if needed. @@ -380,7 +380,7 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F, BPI->eraseBlock(Target); } - BasicBlock *BodyBlock = Target->splitBasicBlock(FirstNonPHI, ".split"); + BasicBlock *BodyBlock = Target->splitBasicBlock(FirstNonPHIIt, ".split"); if (ShouldUpdateAnalysis) { // Copy the BFI/BPI from Target to BodyBlock. BPI->setEdgeProbability(BodyBlock, EdgeProbabilities); diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 33b3e4aea12d33..526132f5e5332e 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -410,8 +410,8 @@ CodeExtractor::findOrCreateBlockForHoisting(BasicBlock *CommonExitBlock) { assert(!getFirstPHI(CommonExitBlock) && "Phi not expected"); #endif - BasicBlock *NewExitBlock = CommonExitBlock->splitBasicBlock( - CommonExitBlock->getFirstNonPHI()->getIterator()); + BasicBlock *NewExitBlock = + CommonExitBlock->splitBasicBlock(CommonExitBlock->getFirstNonPHIIt()); for (BasicBlock *Pred : llvm::make_early_inc_range(predecessors(CommonExitBlock))) { @@ -701,7 +701,7 @@ void CodeExtractor::severSplitPHINodesOfEntry(BasicBlock *&Header) { // containing PHI nodes merging values from outside of the region, and a // second that contains all of the code for the block and merges back any // incoming values from inside of the region. - BasicBlock *NewBB = SplitBlock(Header, Header->getFirstNonPHI(), DT); + BasicBlock *NewBB = SplitBlock(Header, Header->getFirstNonPHIIt(), DT); // We only want to code extract the second block now, and it becomes the new // header of the region. diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index aa5e04d71657a7..6a8a468ebcae2b 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; diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 94cf1185bc2cb7..d5cf62e52cca39 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2108,7 +2108,7 @@ insertDbgVariableRecordsForPHIs(BasicBlock *BB, for (auto PHI : InsertedPHIs) { BasicBlock *Parent = PHI->getParent(); // Avoid inserting a debug-info record into an EH block. - if (Parent->getFirstNonPHI()->isEHPad()) + if (Parent->getFirstNonPHIIt()->isEHPad()) continue; for (auto VI : PHI->operand_values()) { auto V = DbgValueMap.find(VI); @@ -2174,7 +2174,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB, for (auto *PHI : InsertedPHIs) { BasicBlock *Parent = PHI->getParent(); // Avoid inserting an intrinsic into an EH block. - if (Parent->getFirstNonPHI()->isEHPad()) + if (Parent->getFirstNonPHIIt()->isEHPad()) continue; for (auto *VI : PHI->operand_values()) { auto V = DbgValueMap.find(VI); @@ -3206,7 +3206,7 @@ static bool markAliveBlocks(Function &F, BasicBlock *HandlerBB = *I; if (DTU) ++NumPerSuccessorCases[HandlerBB]; - auto *CatchPad = cast<CatchPadInst>(HandlerBB->getFirstNonPHI()); + auto *CatchPad = cast<CatchPadInst>(HandlerBB->getFirstNonPHIIt()); if (!HandlerSet.insert({CatchPad, Empty}).second) { if (DTU) --NumPerSuccessorCases[HandlerBB]; diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp index b3f9f76274d30a..61ffb49a8c0105 100644 --- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp +++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp @@ -382,7 +382,7 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader, BasicBlock *BEBlock = BasicBlock::Create(Header->getContext(), Header->getName() + ".backedge", F); BranchInst *BETerminator = BranchInst::Create(Header, BEBlock); - BETerminator->setDebugLoc(Header->getFirstNonPHI()->getDebugLoc()); + BETerminator->setDebugLoc(Header->getFirstNonPHIIt()->getDebugLoc()); LLVM_DEBUG(dbgs() << "LoopSimplify: Inserting unique backedge block " << BEBlock->getName() << "\n"); diff --git a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp index 91291b429ea434..dbab56a6996cec 100644 --- a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp +++ b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp @@ -109,8 +109,9 @@ void llvm::createMemCpyLoopKnownSize( uint64_t BytesCopied = LoopEndCount; uint64_t RemainingBytes = CopyLen->getZExtValue() - BytesCopied; if (RemainingBytes) { - IRBuilder<> RBuilder(PostLoopBB ? PostLoopBB->getFirstNonPHI() - : InsertBefore); + BasicBlock::iterator InsertIt = PostLoopBB ? PostLoopBB->getFirstNonPHIIt() + : InsertBefore->getIterator(); + IRBuilder<> RBuilder(InsertIt->getParent(), InsertIt); SmallVector<Type *, 5> RemainingOps; TTI.getMemcpyLoopResidualLoweringType(RemainingOps, Ctx, RemainingBytes, @@ -735,14 +736,16 @@ static void createMemMoveLoopKnownSize(Instruction *InsertBefore, // the same way, except that we change the IRBuilder insert point for each // load/store pair so that each one is inserted before the previous one // instead of after it. - IRBuilder<> BwdResBuilder(CopyBackwardsBB->getFirstNonPHI()); + IRBuilder<> BwdResBuilder(CopyBackwardsBB, + CopyBackwardsBB->getFirstNonPHIIt()); SmallVector<Type *, 5> RemainingOps; TTI.getMemcpyLoopResidualLoweringType(RemainingOps, Ctx, RemainingBytes, SrcAS, DstAS, PartSrcAlign, PartDstAlign); for (auto *OpTy : RemainingOps) { // reverse the order of the emitted operations - BwdResBuilder.SetInsertPoint(CopyBackwardsBB->getFirstNonPHI()); + BwdResBuilder.SetInsertPoint(CopyBackwardsBB, + CopyBackwardsBB->getFirstNonPHIIt()); GenerateResidualLdStPair(OpTy, BwdResBuilder, BytesCopied); } } diff --git a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp index 9b1b09bb3d8f29..ad105f5a57b497 100644 --- a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp +++ b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp @@ -179,7 +179,7 @@ static bool runMoveAutoInit(Function &F, DominatorTree &DT, MemorySSA &MSSA) { // CatchSwitchInst blocks can only have one instruction, so they are not // good candidates for insertion. - while (isa<CatchSwitchInst>(UsersDominator->getFirstNonPHI())) { + while (isa<CatchSwitchInst>(UsersDominator->getFirstNonPHIIt())) { for (BasicBlock *Pred : predecessors(UsersDominator)) if (DT.isReachableFromEntry(Pred)) UsersDominator = DT.findNearestCommonDominator(UsersDominator, Pred); diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 229b1d9f07f8c7..48d9528f0c3df2 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -173,8 +173,8 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) { // Set the DebugLoc of the inserted PHI, if available. DebugLoc DL; - if (const Instruction *I = BB->getFirstNonPHI()) - DL = I->getDebugLoc(); + if (BasicBlock::iterator It = BB->getFirstNonPHIIt(); It != BB->end()) + DL = It->getDebugLoc(); InsertedPHI->setDebugLoc(DL); // If the client wants to know about all new instructions, tell it. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index e4e87704c1c97a..49694eb68e25bc 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7959,7 +7959,7 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton( PhisInBlock.push_back(&Phi); for (PHINode *Phi : PhisInBlock) { - Phi->moveBefore(LoopVectorPreHeader->getFirstNonPHI()); + Phi->moveBefore(LoopVectorPreHeader->getFirstNonPHIIt()); Phi->replaceIncomingBlockWith( VecEpilogueIterationCountCheck->getSinglePredecessor(), VecEpilogueIterationCountCheck); @@ -10291,8 +10291,8 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L, // VPReductionPHIRecipes for AnyOf reductions expect a boolean as // start value; compare the final value from the main vector loop // to the start value. - IRBuilder<> Builder( - cast<Instruction>(ResumeV)->getParent()->getFirstNonPHI()); + BasicBlock *PBB = cast<Instruction>(ResumeV)->getParent(); + IRBuilder<> Builder(PBB, PBB->getFirstNonPHIIt()); ResumeV = Builder.CreateICmpNE(ResumeV, RdxDesc.getRecurrenceStartValue()); } else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) { diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 9d973d200662d6..4159a71469bd12 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -316,10 +316,9 @@ Value *VPTransformState::get(VPValue *Def, bool NeedsScalar) { // last PHI, if LastInst is a PHI. This ensures the insertelement sequence // will directly follow the scalar definitions. auto OldIP = Builder.saveIP(); - auto NewIP = - isa<PHINode>(LastInst) - ? BasicBlock::iterator(LastInst->getParent()->getFirstNonPHI()) - : std::next(BasicBlock::iterator(LastInst)); + auto NewIP = isa<PHINode>(LastInst) + ? LastInst->getParent()->getFirstNonPHIIt() + : std::next(BasicBlock::iterator(LastInst)); Builder.SetInsertPoint(&*NewIP); // However, if we are vectorizing, we need to construct the vector values. diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp index 41e3ffd963f5ba..da363df77d0c07 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -52,7 +52,7 @@ static void replaceBranchTerminator(BasicBlock &BB, bool IsBranch = isa<BranchInst>(Term); if (InvokeInst *Invoke = dyn_cast<InvokeInst>(Term)) { BasicBlock *UnwindDest = Invoke->getUnwindDest(); - Instruction *LP = UnwindDest->getFirstNonPHI(); + BasicBlock::iterator LP = UnwindDest->getFirstNonPHIIt(); // Remove landingpad instruction if the containing block isn't used by other // invokes. diff --git a/llvm/unittests/Analysis/MemorySSATest.cpp b/llvm/unittests/Analysis/MemorySSATest.cpp index 1fb3f46b9240f2..ad4393ccd53155 100644 --- a/llvm/unittests/Analysis/MemorySSATest.cpp +++ b/llvm/unittests/Analysis/MemorySSATest.cpp @@ -1578,7 +1578,7 @@ TEST_F(MemorySSATest, TestLoopInvariantEntryBlockPointer) { for (auto &BB : *F) { if (BB.getName() == "exit") { // Get the store instruction - auto *SI = BB.getFirstNonPHI(); + auto *SI = &*BB.getFirstNonPHIIt(); // Get the memory access and location MemoryAccess *MA = MSSA.getMemoryAccess(SI); MemoryLocation ML = MemoryLocation::get(SI); diff --git a/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp b/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp index f36d3ba99775b4..519389d8e0b19b 100644 --- a/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp +++ b/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp @@ -146,7 +146,7 @@ TEST_F(ProfileSummaryInfoTest, TestNoProfile) { EXPECT_FALSE(PSI.isHotBlock(&BB0, &BFI)); EXPECT_FALSE(PSI.isColdBlock(&BB0, &BFI)); - CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHI()); + CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHIIt()); EXPECT_FALSE(PSI.isHotCallSite(CS1, &BFI)); EXPECT_FALSE(PSI.isColdCallSite(CS1, &BFI)); } @@ -240,8 +240,8 @@ TEST_F(ProfileSummaryInfoTest, InstrProf) { EXPECT_TRUE(PSI.isColdBlockNthPercentile(10000, BB2, &BFI)); EXPECT_TRUE(PSI.isColdBlockNthPercentile(10000, BB3, &BFI)); - CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHI()); - auto *CI2 = BB2->getFirstNonPHI(); + CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHIIt()); + BasicBlock::iterator CI2 = BB2->getFirstNonPHIIt(); CallBase &CS2 = cast<CallBase>(*CI2); EXPECT_TRUE(PSI.isHotCallSite(CS1, &BFI)); @@ -336,8 +336,8 @@ TEST_F(ProfileSummaryInfoTest, SampleProf) { EXPECT_TRUE(PSI.isColdBlockNthPercentile(10000, BB2, &BFI)); EXPECT_TRUE(PSI.isColdBlockNthPercentile(10000, BB3, &BFI)); - CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHI()); - auto *CI2 = BB2->getFirstNonPHI(); + CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHIIt()); + BasicBlock::iterator CI2 = BB2->getFirstNonPHIIt(); // Manually attach branch weights metadata to the call instruction. SmallVector<uint32_t, 1> Weights; Weights.push_back(1000); diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index f620d2c968b3f0..42616155f0cc32 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -6434,7 +6434,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { // Check entry block auto &EntryBlock = OutlinedFn->getEntryBlock(); - Instruction *Alloca1 = EntryBlock.getFirstNonPHI(); + Instruction *Alloca1 = &*EntryBlock.getFirstNonPHIIt(); EXPECT_NE(Alloca1, nullptr); EXPECT_TRUE(isa<AllocaInst>(Alloca1)); @@ -6469,7 +6469,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { // Check user code block auto *UserCodeBlock = EntryBlockBranch->getSuccessor(0); EXPECT_EQ(UserCodeBlock->getName(), "user_code.entry"); - auto *Load1 = UserCodeBlock->getFirstNonPHI(); + Instruction *Load1 = &*UserCodeBlock->getFirstNonPHIIt(); EXPECT_TRUE(isa<LoadInst>(Load1)); auto *Load2 = Load1->getNextNode(); EXPECT_TRUE(isa<LoadInst>(Load2)); @@ -6480,7 +6480,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { auto *OutlinedBlock = OutlinedBlockBr->getSuccessor(0); EXPECT_EQ(OutlinedBlock->getName(), "outlined.body"); - auto *Value1 = OutlinedBlock->getFirstNonPHI(); + Instruction *Value1 = &*OutlinedBlock->getFirstNonPHIIt(); EXPECT_EQ(Value1, Value); EXPECT_EQ(Value1->getNextNode(), TargetStore); auto *Deinit = TargetStore->getNextNode(); @@ -6496,7 +6496,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { // Check exit block auto *ExitBlock = EntryBlockBranch->getSuccessor(1); EXPECT_EQ(ExitBlock->getName(), "worker.exit"); - EXPECT_TRUE(isa<ReturnInst>(ExitBlock->getFirstNonPHI())); + EXPECT_TRUE(isa<ReturnInst>(ExitBlock->getFirstNonPHIIt())); // Check global exec_mode. GlobalVariable *Used = M->getGlobalVariable("llvm.compiler.used"); @@ -6804,7 +6804,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) { // Check that we have moved our alloca created in the // BodyGenCB function, to the top of the function. - Instruction *Alloca1 = EntryBlock.getFirstNonPHI(); + Instruction *Alloca1 = &*EntryBlock.getFirstNonPHIIt(); EXPECT_NE(Alloca1, nullptr); EXPECT_TRUE(isa<AllocaInst>(Alloca1)); EXPECT_EQ(Alloca1, RaiseAlloca); @@ -6840,7 +6840,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) { // Check user code block auto *UserCodeBlock = EntryBlockBranch->getSuccessor(0); EXPECT_EQ(UserCodeBlock->getName(), "user_code.entry"); - auto *Load1 = UserCodeBlock->getFirstNonPHI(); + BasicBlock::iterator Load1 = UserCodeBlock->getFirstNonPHIIt(); EXPECT_TRUE(isa<LoadInst>(Load1)); auto *OutlinedBlockBr = Load1->getNextNode(); @@ -6849,7 +6849,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) { auto *OutlinedBlock = OutlinedBlockBr->getSuccessor(0); EXPECT_EQ(OutlinedBlock->getName(), "outlined.body"); - auto *Load2 = OutlinedBlock->getFirstNonPHI(); + Instruction *Load2 = &*OutlinedBlock->getFirstNonPHIIt(); EXPECT_TRUE(isa<LoadInst>(Load2)); EXPECT_EQ(Load2, Value); EXPECT_EQ(Load2->getNextNode(), TargetStore); @@ -6866,7 +6866,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) { // Check exit block auto *ExitBlock = EntryBlockBranch->getSuccessor(1); EXPECT_EQ(ExitBlock->getName(), "worker.exit"); - EXPECT_TRUE(isa<ReturnInst>(ExitBlock->getFirstNonPHI())); + EXPECT_TRUE(isa<ReturnInst>(ExitBlock->getFirstNonPHIIt())); } TEST_F(OpenMPIRBuilderTest, CreateTask) { diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index ea20c87d6b09b4..4283ba7a8f8236 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -134,7 +134,7 @@ TEST(StripTest, LoopMetadata) { // we update the terminator's metadata correctly, we should be able to // observe the change in emission kind for the CU. auto getEmissionKind = [&]() { - Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); + Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); MDNode *LoopMD = I.getMetadata(LLVMContext::MD_loop); return cast<DILocation>(LoopMD->getOperand(1)) ->getScope() @@ -183,7 +183,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgRecord) { )"); // Find %b = add ... - Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); + Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); // Find the dbg.value using %b. SmallVector<DbgValueInst *, 1> DVIs; @@ -268,7 +268,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) { !11 = !DILocation(line: 1, column: 1, scope: !6) )"); - Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); + Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); // Find the DbgVariableRecords using %b. SmallVector<DbgValueInst *, 2> DVIs; @@ -319,7 +319,7 @@ TEST(MetadataTest, OrderingOfDbgVariableRecords) { !12 = !DILocalVariable(name: "bar", scope: !6, file: !1, line: 1, type: !10) )"); - Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); + Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); SmallVector<DbgValueInst *, 2> DVIs; SmallVector<DbgVariableRecord *, 2> DVRs; @@ -902,7 +902,7 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) { )"); // Find the first dbg.value, - Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); + Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); const DILocalVariable *Var = nullptr; const DIExpression *Expr = nullptr; const DILocation *Loc = nullptr; diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index c1d3279688858e..386a60702d0da2 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -1716,7 +1716,7 @@ TEST(InstructionsTest, DropLocation) { cast<Function>(M->getNamedValue("no_parent_scope")); BasicBlock &BB = NoParentScopeF->front(); - auto *I1 = BB.getFirstNonPHI(); + auto *I1 = &*BB.getFirstNonPHIIt(); auto *I2 = I1->getNextNode(); auto *I3 = BB.getTerminator(); @@ -1738,7 +1738,7 @@ TEST(InstructionsTest, DropLocation) { cast<Function>(M->getNamedValue("with_parent_scope")); BasicBlock &BB = WithParentScopeF->front(); - auto *I2 = BB.getFirstNonPHI()->getNextNode(); + auto *I2 = BB.getFirstNonPHIIt()->getNextNode(); MDNode *Scope = cast<MDNode>(WithParentScopeF->getSubprogram()); EXPECT_EQ(I2->getDebugLoc().getLine(), 2U); diff --git a/llvm/unittests/Transforms/Scalar/LICMTest.cpp b/llvm/unittests/Transforms/Scalar/LICMTest.cpp index 5a986b067700ce..98a69bbb47de17 100644 --- a/llvm/unittests/Transforms/Scalar/LICMTest.cpp +++ b/llvm/unittests/Transforms/Scalar/LICMTest.cpp @@ -63,7 +63,7 @@ TEST(LICMTest, TestSCEVInvalidationOnHoisting) { BasicBlock *LoopBB = EntryBB.getUniqueSuccessor(); // Select `load i64, i64* %ptr`. - Instruction *IBefore = LoopBB->getFirstNonPHI(); + Instruction *IBefore = &*LoopBB->getFirstNonPHIIt(); // Make sure the right instruction was selected. ASSERT_TRUE(isa<LoadInst>(IBefore)); // Upon this query SCEV caches disposition of <load i64, i64* %ptr> SCEV. @@ -73,7 +73,7 @@ TEST(LICMTest, TestSCEVInvalidationOnHoisting) { MPM.run(*M, MAM); // Select `load i64, i64* %ptr` after it was hoisted. - Instruction *IAfter = EntryBB.getFirstNonPHI(); + Instruction *IAfter = &*EntryBB.getFirstNonPHIIt(); // Make sure the right instruction was selected. ASSERT_TRUE(isa<LoadInst>(IAfter)); diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 1293e4c921c9d1..b2e3b5d32fbe2d 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -508,7 +508,7 @@ Value *BlockGenerator::getOrCreateAlloca(const ScopArrayInfo *Array) { new AllocaInst(Ty, DL.getAllocaAddrSpace(), nullptr, DL.getPrefTypeAlign(Ty), ScalarBase->getName() + NameExt); BasicBlock *EntryBB = &Builder.GetInsertBlock()->getParent()->getEntryBlock(); - Addr->insertBefore(&*EntryBB->getFirstInsertionPt()); + Addr->insertBefore(EntryBB->getFirstInsertionPt()); return Addr; } @@ -869,7 +869,7 @@ void BlockGenerator::createScalarFinalization(Scop &S) { // Create the merge PHI that merges the optimized and unoptimized version. PHINode *MergePHI = PHINode::Create(EscapeInst->getType(), 2, EscapeInst->getName() + ".merge"); - MergePHI->insertBefore(&*MergeBB->getFirstInsertionPt()); + MergePHI->insertBefore(MergeBB->getFirstInsertionPt()); // Add the respective values to the merge PHI. MergePHI->addIncoming(EscapeInstReload, OptExitBB); @@ -950,7 +950,7 @@ void BlockGenerator::createExitPHINodeMerges(Scop &S) { cast<Instruction>(OriginalValue)->getParent() != MergeBB) && "Original value must no be one we just generated."); auto *MergePHI = PHINode::Create(PHI->getType(), 2, Name + ".ph.merge"); - MergePHI->insertBefore(&*MergeBB->getFirstInsertionPt()); + MergePHI->insertBefore(MergeBB->getFirstInsertionPt()); MergePHI->addIncoming(Reload, OptExitBB); MergePHI->addIncoming(OriginalValue, ExitBB); int Idx = PHI->getBasicBlockIndex(MergeBB); @@ -1384,7 +1384,7 @@ void RegionGenerator::copyPHIInstruction(ScopStmt &Stmt, PHINode *PHI, unsigned NumIncoming = PHI->getNumIncomingValues(); PHINode *PHICopy = Builder.CreatePHI(PHI->getType(), NumIncoming, "polly." + PHI->getName()); - PHICopy->moveBefore(PHICopy->getParent()->getFirstNonPHI()); + PHICopy->moveBefore(PHICopy->getParent()->getFirstNonPHIIt()); BBMap[PHI] = PHICopy; for (BasicBlock *IncomingBB : PHI->blocks()) diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index 5f772170d96282..f3975ccee44fa3 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -185,7 +185,7 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, DT.changeImmediateDominator(ExitBB, HeaderBB); // The loop body should be added here. - Builder.SetInsertPoint(HeaderBB->getFirstNonPHI()); + Builder.SetInsertPoint(HeaderBB->getFirstNonPHIIt()); return IV; } diff --git a/polly/lib/Transform/MaximalStaticExpansion.cpp b/polly/lib/Transform/MaximalStaticExpansion.cpp index e32a69d47f69c1..c9227ac0bfd10f 100644 --- a/polly/lib/Transform/MaximalStaticExpansion.cpp +++ b/polly/lib/Transform/MaximalStaticExpansion.cpp @@ -169,7 +169,7 @@ class MaximalStaticExpansionImpl { } else if (SAI->isExitPHIKind()) { // For now, we are not able to expand ExitPhi. emitRemark(SAI->getName() + " is a ExitPhi node.", - S.getEnteringBlock()->getFirstNonPHI()); + &*S.getEnteringBlock()->getFirstNonPHIIt()); return false; } @@ -270,7 +270,7 @@ class MaximalStaticExpansionImpl { // No need to expand SAI with no write. if (NumberWrites == 0) { emitRemark(SAI->getName() + " has 0 write access.", - S.getEnteringBlock()->getFirstNonPHI()); + &*S.getEnteringBlock()->getFirstNonPHIIt()); return false; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits