diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
commit | 344a3780b2e33f6ca763666c380202b18aab72a3 (patch) | |
tree | f0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/CodeGen/MachineBasicBlock.cpp | |
parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) |
vendor/llvm-project/llvmorg-13-init-16847-g88e66fa60ae5vendor/llvm-project/llvmorg-12.0.1-rc2-0-ge7dac564cd0evendor/llvm-project/llvmorg-12.0.1-0-gfed41342a82f
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index b4187af02975..c6914dcd0e54 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -21,6 +21,7 @@ #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/TargetInstrInfo.h" +#include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/Config/llvm-config.h" @@ -87,6 +88,17 @@ MCSymbol *MachineBasicBlock::getSymbol() const { return CachedMCSymbol; } +MCSymbol *MachineBasicBlock::getEHCatchretSymbol() const { + if (!CachedEHCatchretMCSymbol) { + const MachineFunction *MF = getParent(); + SmallString<128> SymbolName; + raw_svector_ostream(SymbolName) + << "$ehgcr_" << MF->getFunctionNumber() << '_' << getNumber(); + CachedEHCatchretMCSymbol = MF->getContext().getOrCreateSymbol(SymbolName); + } + return CachedEHCatchretMCSymbol; +} + MCSymbol *MachineBasicBlock::getEndSymbol() const { if (!CachedEndMCSymbol) { const MachineFunction *MF = getParent(); @@ -210,11 +222,13 @@ MachineBasicBlock::SkipPHIsAndLabels(MachineBasicBlock::iterator I) { } MachineBasicBlock::iterator -MachineBasicBlock::SkipPHIsLabelsAndDebug(MachineBasicBlock::iterator I) { +MachineBasicBlock::SkipPHIsLabelsAndDebug(MachineBasicBlock::iterator I, + bool SkipPseudoOp) { const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); iterator E = end(); while (I != E && (I->isPHI() || I->isPosition() || I->isDebugInstr() || + (SkipPseudoOp && I->isPseudoProbe()) || TII->isBasicBlockPrologue(*I))) ++I; // FIXME: This needs to change if we wish to bundle labels / dbg_values @@ -243,12 +257,14 @@ MachineBasicBlock::instr_iterator MachineBasicBlock::getFirstInstrTerminator() { return I; } -MachineBasicBlock::iterator MachineBasicBlock::getFirstNonDebugInstr() { +MachineBasicBlock::iterator +MachineBasicBlock::getFirstNonDebugInstr(bool SkipPseudoOp) { // Skip over begin-of-block dbg_value instructions. - return skipDebugInstructionsForward(begin(), end()); + return skipDebugInstructionsForward(begin(), end(), SkipPseudoOp); } -MachineBasicBlock::iterator MachineBasicBlock::getLastNonDebugInstr() { +MachineBasicBlock::iterator +MachineBasicBlock::getLastNonDebugInstr(bool SkipPseudoOp) { // Skip over end-of-block dbg_value instructions. instr_iterator B = instr_begin(), I = instr_end(); while (I != B) { @@ -256,6 +272,8 @@ MachineBasicBlock::iterator MachineBasicBlock::getLastNonDebugInstr() { // Return instruction that starts a bundle. if (I->isDebugInstr() || I->isInsideBundle()) continue; + if (SkipPseudoOp && I->isPseudoProbe()) + continue; return I; } // The block is all debug values. @@ -1075,10 +1093,9 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( I != E; ++I) NewTerminators.push_back(&*I); - for (SmallVectorImpl<MachineInstr*>::iterator I = Terminators.begin(), - E = Terminators.end(); I != E; ++I) { - if (!is_contained(NewTerminators, *I)) - Indexes->removeMachineInstrFromMaps(**I); + for (MachineInstr *Terminator : Terminators) { + if (!is_contained(NewTerminators, Terminator)) + Indexes->removeMachineInstrFromMaps(*Terminator); } } @@ -1361,6 +1378,14 @@ MachineBasicBlock::findDebugLoc(instr_iterator MBBI) { return {}; } +DebugLoc MachineBasicBlock::rfindDebugLoc(reverse_instr_iterator MBBI) { + // Skip debug declarations, we don't want a DebugLoc from them. + MBBI = skipDebugInstructionsBackward(MBBI, instr_rbegin()); + if (!MBBI->isDebugInstr()) + return MBBI->getDebugLoc(); + return {}; +} + /// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE /// instructions. Return UnknownLoc if there is none. DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) { @@ -1371,6 +1396,16 @@ DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) { return {}; } +DebugLoc MachineBasicBlock::rfindPrevDebugLoc(reverse_instr_iterator MBBI) { + if (MBBI == instr_rend()) + return {}; + // Skip debug declarations, we don't want a DebugLoc from them. + MBBI = next_nodbg(MBBI, instr_rend()); + if (MBBI != instr_rend()) + return MBBI->getDebugLoc(); + return {}; +} + /// Find and return the merged DebugLoc of the branch instructions of the block. /// Return UnknownLoc if there is none. DebugLoc @@ -1455,7 +1490,7 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, // Try searching forwards from Before, looking for reads or defs. const_iterator I(Before); for (; I != end() && N > 0; ++I) { - if (I->isDebugInstr()) + if (I->isDebugOrPseudoInstr()) continue; --N; @@ -1493,7 +1528,7 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, do { --I; - if (I->isDebugInstr()) + if (I->isDebugOrPseudoInstr()) continue; --N; @@ -1527,7 +1562,7 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, // If all the instructions before this in the block are debug instructions, // skip over them. - while (I != begin() && std::prev(I)->isDebugInstr()) + while (I != begin() && std::prev(I)->isDebugOrPseudoInstr()) --I; // Did we get to the start of the block? @@ -1569,6 +1604,23 @@ MachineBasicBlock::livein_iterator MachineBasicBlock::livein_begin() const { return LiveIns.begin(); } +MachineBasicBlock::liveout_iterator MachineBasicBlock::liveout_begin() const { + const MachineFunction &MF = *getParent(); + assert(MF.getProperties().hasProperty( + MachineFunctionProperties::Property::TracksLiveness) && + "Liveness information is accurate"); + + const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering(); + MCPhysReg ExceptionPointer = 0, ExceptionSelector = 0; + if (MF.getFunction().hasPersonalityFn()) { + auto PersonalityFn = MF.getFunction().getPersonalityFn(); + ExceptionPointer = TLI.getExceptionPointerRegister(PersonalityFn); + ExceptionSelector = TLI.getExceptionSelectorRegister(PersonalityFn); + } + + return liveout_iterator(*this, ExceptionPointer, ExceptionSelector, false); +} + const MBBSectionID MBBSectionID::ColdSectionID(MBBSectionID::SectionType::Cold); const MBBSectionID MBBSectionID::ExceptionSectionID(MBBSectionID::SectionType::Exception); |