diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2024-07-27 23:34:35 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2024-10-23 18:26:01 +0000 |
commit | 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583 (patch) | |
tree | 6cf5ab1f05330c6773b1f3f64799d56a9c7a1faa /contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp | |
parent | 6b9f7133aba44189d9625c352bc2c2a59baf18ef (diff) | |
parent | ac9a064cb179f3425b310fa2847f8764ac970a4d (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp index 4410fb7ecd23..d681d00b5d8c 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -80,10 +80,11 @@ MCSymbol *MachineBasicBlock::getSymbol() const { } CachedMCSymbol = Ctx.getOrCreateSymbol(MF->getName() + Suffix); } else { - const StringRef Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix(); - CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" + - Twine(MF->getFunctionNumber()) + - "_" + Twine(getNumber())); + // If the block occurs as label in inline assembly, parsing the assembly + // needs an actual label name => set AlwaysEmit in these cases. + CachedMCSymbol = Ctx.createBlockSymbol( + "BB" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()), + /*AlwaysEmit=*/hasLabelMustBeEmitted()); } } return CachedMCSymbol; @@ -104,10 +105,9 @@ MCSymbol *MachineBasicBlock::getEndSymbol() const { if (!CachedEndMCSymbol) { const MachineFunction *MF = getParent(); MCContext &Ctx = MF->getContext(); - auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix(); - CachedEndMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB_END" + - Twine(MF->getFunctionNumber()) + - "_" + Twine(getNumber())); + CachedEndMCSymbol = Ctx.createBlockSymbol( + "BB_END" + Twine(MF->getFunctionNumber()) + "_" + Twine(getNumber()), + /*AlwaysEmit=*/false); } return CachedEndMCSymbol; } @@ -315,6 +315,12 @@ bool MachineBasicBlock::isLegalToHoistInto() const { return true; } +bool MachineBasicBlock::hasName() const { + if (const BasicBlock *LBB = getBasicBlock()) + return LBB->hasName(); + return false; +} + StringRef MachineBasicBlock::getName() const { if (const BasicBlock *LBB = getBasicBlock()) return LBB->getName(); @@ -1129,15 +1135,24 @@ public: } }; +#define GET_RESULT(RESULT, GETTER, INFIX) \ + [MF, P, MFAM]() { \ + if (P) { \ + auto *Wrapper = P->getAnalysisIfAvailable<RESULT##INFIX##WrapperPass>(); \ + return Wrapper ? &Wrapper->GETTER() : nullptr; \ + } \ + return MFAM->getCachedResult<RESULT##Analysis>(*MF); \ + }() + MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( - MachineBasicBlock *Succ, Pass &P, + MachineBasicBlock *Succ, Pass *P, MachineFunctionAnalysisManager *MFAM, std::vector<SparseBitVector<>> *LiveInSets) { + assert((P || MFAM) && "Need a way to get analysis results!"); if (!canSplitCriticalEdge(Succ)) return nullptr; MachineFunction *MF = getParent(); MachineBasicBlock *PrevFallthrough = getNextNode(); - DebugLoc DL; // FIXME: this is nowhere MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock(); NMBB->setCallFrameSize(Succ->getCallFrameSize()); @@ -1156,8 +1171,8 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( << " -- " << printMBBReference(*NMBB) << " -- " << printMBBReference(*Succ) << '\n'); - LiveIntervals *LIS = P.getAnalysisIfAvailable<LiveIntervals>(); - SlotIndexes *Indexes = P.getAnalysisIfAvailable<SlotIndexes>(); + LiveIntervals *LIS = GET_RESULT(LiveIntervals, getLIS, ); + SlotIndexes *Indexes = GET_RESULT(SlotIndexes, getSI, ); if (LIS) LIS->insertMBBInMaps(NMBB); else if (Indexes) @@ -1166,7 +1181,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( // On some targets like Mips, branches may kill virtual registers. Make sure // that LiveVariables is properly updated after updateTerminator replaces the // terminators. - LiveVariables *LV = P.getAnalysisIfAvailable<LiveVariables>(); + LiveVariables *LV = GET_RESULT(LiveVariables, getLV, ); // Collect a list of virtual registers killed by the terminators. SmallVector<Register, 4> KilledRegs; @@ -1218,6 +1233,15 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( SlotIndexUpdateDelegate SlotUpdater(*MF, Indexes); SmallVector<MachineOperand, 4> Cond; const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); + + // In original 'this' BB, there must be a branch instruction targeting at + // Succ. We can not find it out since currently getBranchDestBlock was not + // implemented for all targets. However, if the merged DL has column or line + // number, the scope and non-zero column and line number is same with that + // branch instruction so we can safely use it. + DebugLoc DL, MergedDL = findBranchDebugLoc(); + if (MergedDL && (MergedDL.getLine() || MergedDL.getCol())) + DL = MergedDL; TII->insertBranch(*NMBB, Succ, nullptr, Cond, DL); } @@ -1322,24 +1346,23 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( LIS->repairIntervalsInRange(this, getFirstTerminator(), end(), UsedRegs); } - if (MachineDominatorTree *MDT = - P.getAnalysisIfAvailable<MachineDominatorTree>()) + if (auto *MDT = GET_RESULT(MachineDominatorTree, getDomTree, )) MDT->recordSplitCriticalEdge(this, Succ, NMBB); - if (MachineLoopInfo *MLI = P.getAnalysisIfAvailable<MachineLoopInfo>()) + if (MachineLoopInfo *MLI = GET_RESULT(MachineLoop, getLI, Info)) if (MachineLoop *TIL = MLI->getLoopFor(this)) { // If one or the other blocks were not in a loop, the new block is not // either, and thus LI doesn't need to be updated. if (MachineLoop *DestLoop = MLI->getLoopFor(Succ)) { if (TIL == DestLoop) { // Both in the same loop, the NMBB joins loop. - DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase()); + DestLoop->addBasicBlockToLoop(NMBB, *MLI); } else if (TIL->contains(DestLoop)) { // Edge from an outer loop to an inner loop. Add to the outer loop. - TIL->addBasicBlockToLoop(NMBB, MLI->getBase()); + TIL->addBasicBlockToLoop(NMBB, *MLI); } else if (DestLoop->contains(TIL)) { // Edge from an inner loop to an outer loop. Add to the outer loop. - DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase()); + DestLoop->addBasicBlockToLoop(NMBB, *MLI); } else { // Edge from two loops with no containment relation. Because these // are natural loops, we know that the destination block must be the @@ -1348,7 +1371,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( assert(DestLoop->getHeader() == Succ && "Should not create irreducible loops!"); if (MachineLoop *P = DestLoop->getParentLoop()) - P->addBasicBlockToLoop(NMBB, MLI->getBase()); + P->addBasicBlockToLoop(NMBB, *MLI); } } } @@ -1466,10 +1489,9 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old, // Scan the operands of this machine instruction, replacing any uses of Old // with New. - for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (I->getOperand(i).isMBB() && - I->getOperand(i).getMBB() == Old) - I->getOperand(i).setMBB(New); + for (MachineOperand &MO : I->operands()) + if (MO.isMBB() && MO.getMBB() == Old) + MO.setMBB(New); } // Update the successor information. @@ -1720,6 +1742,12 @@ void MachineBasicBlock::clearLiveIns() { LiveIns.clear(); } +void MachineBasicBlock::clearLiveIns( + std::vector<RegisterMaskPair> &OldLiveIns) { + assert(OldLiveIns.empty() && "Vector must be empty"); + std::swap(LiveIns, OldLiveIns); +} + MachineBasicBlock::livein_iterator MachineBasicBlock::livein_begin() const { assert(getParent()->getProperties().hasProperty( MachineFunctionProperties::Property::TracksLiveness) && |