Index: llvm/lib/CodeGen/BranchFolding.cpp =================================================================== --- llvm/lib/CodeGen/BranchFolding.cpp +++ llvm/lib/CodeGen/BranchFolding.cpp @@ -169,8 +169,9 @@ TriedMerging.erase(MBB); // Update call site info. - std::for_each(MBB->begin(), MBB->end(), [MF](const MachineInstr &MI) { - if (MI.isCall(MachineInstr::IgnoreBundle)) + const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); + std::for_each(MBB->begin(), MBB->end(), [MF, TII](const MachineInstr &MI) { + if (TII->isCandidateForCallSiteEntry(MI, /* IgnoreBundle = */ true)) MF->eraseCallSiteInfo(&MI); }); // Remove the block. Index: llvm/lib/CodeGen/IfConversion.cpp =================================================================== --- llvm/lib/CodeGen/IfConversion.cpp +++ llvm/lib/CodeGen/IfConversion.cpp @@ -1851,7 +1851,7 @@ while (NumDups1 != 0) { // Since this instruction is going to be deleted, update call // site info state if the instruction is call instruction. - if (DI2->isCall(MachineInstr::IgnoreBundle)) + if (TII->isCandidateForCallSiteEntry(*DI2, /* IgnoreBundle = */ true)) MBB2.getParent()->eraseCallSiteInfo(&*DI2); ++DI2; @@ -1900,7 +1900,7 @@ // Since this instruction is going to be deleted, update call // site info state if the instruction is call instruction. - if (DI1->isCall(MachineInstr::IgnoreBundle)) + if (TII->isCandidateForCallSiteEntry(*DI1, /* IgnoreBundle = */ true)) MBB1.getParent()->eraseCallSiteInfo(&*DI1); // skip dbg_value instructions @@ -2188,8 +2188,12 @@ MachineInstr *MI = MF.CloneMachineInstr(&I); // Make a copy of the call site info. - if (MI->isCall(MachineInstr::IgnoreBundle)) - MF.copyCallSiteInfo(&I,MI); + if (TII->isCandidateForCallSiteEntry(I, /* IgnoreBundle = */ true)) { + if (TII->isCandidateForCallSiteEntry(*MI, /* IgnoreBundle = */ true)) + MF.copyCallSiteInfo(&I, MI); + else + MF.eraseCallSiteInfo(&I); + } ToBBI.BB->insert(ToBBI.BB->end(), MI); ToBBI.NonPredSize++; Index: llvm/lib/CodeGen/InlineSpiller.cpp =================================================================== --- llvm/lib/CodeGen/InlineSpiller.cpp +++ llvm/lib/CodeGen/InlineSpiller.cpp @@ -864,8 +864,14 @@ HSpiller.rmFromMergeableSpills(*MI, FI)) --NumSpills; LIS.ReplaceMachineInstrInMaps(*MI, *FoldMI); - if (MI->isCall()) - MI->getMF()->moveCallSiteInfo(MI, FoldMI); + // Update the call site info. + if (TII.isCandidateForCallSiteEntry(*MI)) { + MachineFunction *MF = MI->getMF(); + if (TII.isCandidateForCallSiteEntry(*FoldMI)) + MF->moveCallSiteInfo(MI, FoldMI); + else + MF->eraseCallSiteInfo(MI); + } MI->eraseFromParent(); // Insert any new instructions other than FoldMI into the LIS maps. Index: llvm/lib/CodeGen/LiveRangeEdit.cpp =================================================================== --- llvm/lib/CodeGen/LiveRangeEdit.cpp +++ llvm/lib/CodeGen/LiveRangeEdit.cpp @@ -231,8 +231,14 @@ return false; LLVM_DEBUG(dbgs() << " folded: " << *FoldMI); LIS.ReplaceMachineInstrInMaps(*UseMI, *FoldMI); - if (UseMI->isCall()) - UseMI->getMF()->moveCallSiteInfo(UseMI, FoldMI); + // Update the call site info. + if (TII.isCandidateForCallSiteEntry(*UseMI)) { + MachineFunction *MF = UseMI->getMF(); + if (TII.isCandidateForCallSiteEntry(*FoldMI)) + MF->moveCallSiteInfo(UseMI, FoldMI); + else + MF->eraseCallSiteInfo(UseMI); + } UseMI->eraseFromParent(); DefMI->addRegisterDead(LI->reg, nullptr); Dead.push_back(DefMI); Index: llvm/lib/CodeGen/MachineFunction.cpp =================================================================== --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -33,6 +33,7 @@ #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/TargetFrameLowering.h" +#include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" @@ -863,7 +864,10 @@ MachineFunction::CallSiteInfoMap::iterator MachineFunction::getCallSiteInfo(const MachineInstr *MI) { - assert(MI->isCall() && "Call site info refers only to call instructions!"); + const TargetInstrInfo *TII = getSubtarget().getInstrInfo(); + (void)TII; + assert(TII->isCandidateForCallSiteEntry(*MI) && + "Call site info refers only to call (MI) candidates"); if (!Target.Options.EnableDebugEntryValues) return CallSitesInfo.end(); @@ -872,7 +876,11 @@ void MachineFunction::moveCallSiteInfo(const MachineInstr *Old, const MachineInstr *New) { - assert(New->isCall() && "Call site info refers only to call instructions!"); + const TargetInstrInfo *TII = getSubtarget().getInstrInfo(); + (void)TII; + assert(TII->isCandidateForCallSiteEntry(*Old) && + TII->isCandidateForCallSiteEntry(*New) && + "Call site info refers only to call (MI) candidates"); CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old); if (CSIt == CallSitesInfo.end()) @@ -884,6 +892,10 @@ } void MachineFunction::eraseCallSiteInfo(const MachineInstr *MI) { + const TargetInstrInfo *TII = getSubtarget().getInstrInfo(); + (void)TII; + assert(TII->isCandidateForCallSiteEntry(*MI) && + "Call site info refers only to call (MI) candidates"); CallSiteInfoMap::iterator CSIt = getCallSiteInfo(MI); if (CSIt == CallSitesInfo.end()) return; @@ -892,7 +904,11 @@ void MachineFunction::copyCallSiteInfo(const MachineInstr *Old, const MachineInstr *New) { - assert(New->isCall() && "Call site info refers only to call instructions!"); + const TargetInstrInfo *TII = getSubtarget().getInstrInfo(); + (void)TII; + assert(TII->isCandidateForCallSiteEntry(*Old) && + TII->isCandidateForCallSiteEntry(*New) && + "Call site info refers only to call (MI) candidates"); CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old); if (CSIt == CallSitesInfo.end()) Index: llvm/lib/CodeGen/MachineOutliner.cpp =================================================================== --- llvm/lib/CodeGen/MachineOutliner.cpp +++ llvm/lib/CodeGen/MachineOutliner.cpp @@ -1248,7 +1248,7 @@ // Helper lambda for adding implicit def operands to the call // instruction. It also updates call site information for moved // code. - auto CopyDefsAndUpdateCalls = [&CallInst](MachineInstr &MI) { + auto CopyDefsAndUpdateCalls = [&CallInst, &TII](MachineInstr &MI) { for (MachineOperand &MOP : MI.operands()) { // Skip over anything that isn't a register. if (!MOP.isReg()) @@ -1260,7 +1260,7 @@ MOP.getReg(), true, /* isDef = true */ true /* isImp = true */)); } - if (MI.isCall()) + if (TII.isCandidateForCallSiteEntry(MI)) MI.getMF()->eraseCallSiteInfo(&MI); }; // Copy over the defs in the outlined range. Index: llvm/lib/CodeGen/PeepholeOptimizer.cpp =================================================================== --- llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -1776,8 +1776,14 @@ LocalMIs.erase(MI); LocalMIs.erase(DefMI); LocalMIs.insert(FoldMI); - if (MI->isCall()) - MI->getMF()->moveCallSiteInfo(MI, FoldMI); + // Update the call site info. + if (TII->isCandidateForCallSiteEntry(*MI)) { + MachineFunction *MF = MI->getMF(); + if (TII->isCandidateForCallSiteEntry(*FoldMI)) + MF->moveCallSiteInfo(MI, FoldMI); + else + MF->eraseCallSiteInfo(MI); + } MI->eraseFromParent(); DefMI->eraseFromParent(); MRI->markUsesInDebugValueAsUndef(FoldedReg); Index: llvm/lib/CodeGen/TargetInstrInfo.cpp =================================================================== --- llvm/lib/CodeGen/TargetInstrInfo.cpp +++ llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -143,7 +143,7 @@ // from the end of MBB. while (Tail != MBB->end()) { auto MI = Tail++; - if (MI->isCall()) + if (isCandidateForCallSiteEntry(*MI)) MBB->getParent()->eraseCallSiteInfo(&*MI); MBB->erase(MI); } Index: llvm/lib/CodeGen/UnreachableBlockElim.cpp =================================================================== --- llvm/lib/CodeGen/UnreachableBlockElim.cpp +++ llvm/lib/CodeGen/UnreachableBlockElim.cpp @@ -108,6 +108,7 @@ MMI = MMIWP ? &MMIWP->getMMI() : nullptr; MachineDominatorTree *MDT = getAnalysisIfAvailable(); MachineLoopInfo *MLI = getAnalysisIfAvailable(); + const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo(); // Mark all reachable blocks. for (MachineBasicBlock *BB : depth_first_ext(&F, Reachable)) @@ -151,7 +152,7 @@ for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) { // Remove any call site information for calls in the block. for (auto &I : DeadBlocks[i]->instrs()) - if (I.isCall(MachineInstr::IgnoreBundle)) + if (TII->isCandidateForCallSiteEntry(I, /* IgnoreBundle = */ true)) DeadBlocks[i]->getParent()->eraseCallSiteInfo(&I); DeadBlocks[i]->eraseFromParent(); @@ -192,7 +193,6 @@ // constrained to the proper register class or it is undef: // insert a COPY instead of simply replacing the output // with the input. - const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo(); BuildMI(*BB, BB->getFirstNonPHI(), phi->getDebugLoc(), TII->get(TargetOpcode::COPY), OutputReg) .addReg(InputReg, getRegState(Input), InputSub); Index: llvm/lib/CodeGen/XRayInstrumentation.cpp =================================================================== --- llvm/lib/CodeGen/XRayInstrumentation.cpp +++ llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -111,7 +111,7 @@ for (auto &MO : T.operands()) MIB.add(MO); Terminators.push_back(&T); - if (T.isCall()) + if (TII->isCandidateForCallSiteEntry(T)) MF.eraseCallSiteInfo(&T); } } Index: llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp =================================================================== --- llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -1207,7 +1207,13 @@ // Update call site info and delete the pseudo instruction TCRETURN. - MBB.getParent()->moveCallSiteInfo(&MI, &*NewMI); + if (TII.isCandidateForCallSiteEntry(MI)) { + MachineFunction *MF = MI.getMF(); + if (TII.isCandidateForCallSiteEntry(*NewMI)) + MF->moveCallSiteInfo(&MI, &*NewMI); + else + MF->eraseCallSiteInfo(&MI); + } MBB.erase(MBBI); MBBI = NewMI; @@ -1410,8 +1416,8 @@ const bool Thumb = Opcode == ARM::tTPsoft; MachineInstrBuilder MIB; + MachineFunction *MF = MBB.getParent(); if (STI->genLongCalls()) { - MachineFunction *MF = MBB.getParent(); MachineConstantPool *MCP = MF->getConstantPool(); unsigned PCLabelID = AFI->createPICLabelUId(); MachineConstantPoolValue *CPV = @@ -1440,7 +1446,13 @@ MIB.cloneMemRefs(MI); TransferImpOps(MI, MIB, MIB); - MI.getMF()->moveCallSiteInfo(&MI, &*MIB); + // Update the call site info. + if (TII->isCandidateForCallSiteEntry(MI)) { + if (TII->isCandidateForCallSiteEntry(*MIB)) + MF->moveCallSiteInfo(&MI, &*MIB); + else + MF->eraseCallSiteInfo(&MI); + } MI.eraseFromParent(); return true; } Index: llvm/lib/Target/X86/X86ExpandPseudo.cpp =================================================================== --- llvm/lib/Target/X86/X86ExpandPseudo.cpp +++ llvm/lib/Target/X86/X86ExpandPseudo.cpp @@ -275,7 +275,15 @@ MachineInstr &NewMI = *std::prev(MBBI); NewMI.copyImplicitOps(*MBBI->getParent()->getParent(), *MBBI); - MBB.getParent()->moveCallSiteInfo(&*MBBI, &NewMI); + + // Update the call site info. + if (TII->isCandidateForCallSiteEntry(*MBBI)) { + MachineFunction *MF = MBB.getParent(); + if (TII->isCandidateForCallSiteEntry(NewMI)) + MF->moveCallSiteInfo(&*MBBI, &NewMI); + else + MF->eraseCallSiteInfo(&*MBBI); + } // Delete the pseudo instruction TCRETURN. MBB.erase(MBBI);