diff options
author | Sam Parker <sam.parker@arm.com> | 2020-08-07 09:49:09 +0100 |
---|---|---|
committer | Sam Parker <sam.parker@arm.com> | 2020-08-11 09:03:09 +0100 |
commit | 8f92f3c2eab02fe17a03fc39fefa0082b1c4b72f (patch) | |
tree | 990484e03c626829800e10766fb2c97402e870b8 /llvm/lib/CodeGen/ReachingDefAnalysis.cpp | |
parent | 8a5e296975b3da5d5d849ae8185ef3d98ca77795 (diff) | |
download | llvm-8f92f3c2eab02fe17a03fc39fefa0082b1c4b72f.zip llvm-8f92f3c2eab02fe17a03fc39fefa0082b1c4b72f.tar.gz llvm-8f92f3c2eab02fe17a03fc39fefa0082b1c4b72f.tar.bz2 |
[RDA] Fix DBG_VALUE issues
We skip debug instructions in RDA so we cannot attempt to look them
up in our instruction map without causing a crash. But some of the
methods select the last instruction in the block and this
instruction may be a debug instruction... So, use getLastNonDebugInstr
instead of calling back on a MachineBasicBlock.
MachineBasicBlock iterators have also been updated to use
instructionsWithoutDebug so we can avoid the manual checks for debug
instructions.
Differential Revision: https://reviews.llvm.org/D85658
Diffstat (limited to 'llvm/lib/CodeGen/ReachingDefAnalysis.cpp')
-rw-r--r-- | llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp index 5bd8b4b..dd70f91 100644 --- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -143,10 +143,9 @@ void ReachingDefAnalysis::reprocessBasicBlock(MachineBasicBlock *MBB) { "Unexpected basic block number."); // Count number of non-debug instructions for end of block adjustment. - int NumInsts = 0; - for (const MachineInstr &MI : *MBB) - if (!MI.isDebugInstr()) - NumInsts++; + auto NonDbgInsts = + instructionsWithoutDebug(MBB->instr_begin(), MBB->instr_end()); + int NumInsts = std::distance(NonDbgInsts.begin(), NonDbgInsts.end()); // When reprocessing a block, the only thing we need to do is check whether // there is now a more recent incoming reaching definition from a predecessor. @@ -197,10 +196,9 @@ void ReachingDefAnalysis::processBasicBlock( } enterBasicBlock(MBB); - for (MachineInstr &MI : *MBB) { - if (!MI.isDebugInstr()) - processDefs(&MI); - } + for (MachineInstr &MI : + instructionsWithoutDebug(MBB->instr_begin(), MBB->instr_end())) + processDefs(&MI); leaveBasicBlock(MBB); } @@ -345,9 +343,8 @@ void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg, bool ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg, InstSet &Uses) const { - for (auto &MI : *MBB) { - if (MI.isDebugInstr()) - continue; + for (MachineInstr &MI : + instructionsWithoutDebug(MBB->instr_begin(), MBB->instr_end())) { for (auto &MO : MI.operands()) { if (!isValidRegUseOf(MO, PhysReg)) continue; @@ -356,7 +353,8 @@ ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg, Uses.insert(&MI); } } - return isReachingDefLiveOut(&MBB->back(), PhysReg); + MachineInstr *Last = &*MBB->getLastNonDebugInstr(); + return isReachingDefLiveOut(Last, PhysReg); } void @@ -459,10 +457,11 @@ bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) const { // Walk backwards through the block to see if the register is live at some // point. - for (auto Last = MBB->rbegin(), End = MBB->rend(); Last != End; ++Last) { - LiveRegs.stepBackward(*Last); + for (MachineInstr &Last : + instructionsWithoutDebug(MBB->instr_rbegin(), MBB->instr_rend())) { + LiveRegs.stepBackward(Last); if (LiveRegs.contains(PhysReg)) - return InstIds.lookup(&*Last) > InstIds.lookup(MI); + return InstIds.lookup(&Last) > InstIds.lookup(MI); } return false; } @@ -470,7 +469,8 @@ bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) const { bool ReachingDefAnalysis::isRegDefinedAfter(MachineInstr *MI, int PhysReg) const { MachineBasicBlock *MBB = MI->getParent(); - if (getReachingDef(MI, PhysReg) != getReachingDef(&MBB->back(), PhysReg)) + MachineInstr *Last = &*MBB->getLastNonDebugInstr(); + if (getReachingDef(MI, PhysReg) != getReachingDef(Last, PhysReg)) return true; if (auto *Def = getLocalLiveOutMIDef(MBB, PhysReg)) @@ -487,7 +487,7 @@ ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) const { if (!LiveRegs.contains(PhysReg)) return false; - MachineInstr *Last = &MBB->back(); + MachineInstr *Last = &*MBB->getLastNonDebugInstr(); int Def = getReachingDef(MI, PhysReg); if (getReachingDef(Last, PhysReg) != Def) return false; @@ -507,7 +507,7 @@ MachineInstr* ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB, if (!LiveRegs.contains(PhysReg)) return nullptr; - MachineInstr *Last = &MBB->back(); + MachineInstr *Last = &*MBB->getLastNonDebugInstr(); int Def = getReachingDef(Last, PhysReg); for (auto &MO : Last->operands()) if (isValidRegDefOf(MO, PhysReg)) |