diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp b/contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp index 9cd74689ba10..b85526cfb380 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp @@ -406,11 +406,11 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) { return true; } -void LiveVariables::HandleRegMask(const MachineOperand &MO) { +void LiveVariables::HandleRegMask(const MachineOperand &MO, unsigned NumRegs) { // Call HandlePhysRegKill() for all live registers clobbered by Mask. // Clobbered registers are always dead, sp there is no need to use // HandlePhysRegDef(). - for (unsigned Reg = 1, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg) { + for (unsigned Reg = 1; Reg != NumRegs; ++Reg) { // Skip dead regs. if (!PhysRegDef[Reg] && !PhysRegUse[Reg]) continue; @@ -421,7 +421,8 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO) { // This avoids needless implicit operands. unsigned Super = Reg; for (MCPhysReg SR : TRI->superregs(Reg)) - if ((PhysRegDef[SR] || PhysRegUse[SR]) && MO.clobbersPhysReg(SR)) + if (SR < NumRegs && (PhysRegDef[SR] || PhysRegUse[SR]) && + MO.clobbersPhysReg(SR)) Super = SR; HandlePhysRegKill(Super, nullptr); } @@ -478,7 +479,8 @@ void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI, } void LiveVariables::runOnInstr(MachineInstr &MI, - SmallVectorImpl<unsigned> &Defs) { + SmallVectorImpl<unsigned> &Defs, + unsigned NumRegs) { assert(!MI.isDebugOrPseudoInstr()); // Process all of the operands of the instruction... unsigned NumOperandsToProcess = MI.getNumOperands(); @@ -527,7 +529,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI, // Process all masked registers. (Call clobbers). for (unsigned Mask : RegMasks) - HandleRegMask(MI.getOperand(Mask)); + HandleRegMask(MI.getOperand(Mask), NumRegs); // Process all defs. for (unsigned MOReg : DefRegs) { @@ -539,7 +541,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI, UpdatePhysRegDefs(MI, Defs); } -void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) { +void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) { // Mark live-in registers as live-in. SmallVector<unsigned, 4> Defs; for (const auto &LI : MBB->liveins()) { @@ -556,7 +558,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) { continue; DistanceMap.insert(std::make_pair(&MI, Dist++)); - runOnInstr(MI, Defs); + runOnInstr(MI, Defs, NumRegs); } // Handle any virtual assignments from PHI nodes which might be at the @@ -597,11 +599,10 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) { MRI = &mf.getRegInfo(); TRI = MF->getSubtarget().getRegisterInfo(); - const unsigned NumRegs = TRI->getNumRegs(); + const unsigned NumRegs = TRI->getNumSupportedRegs(mf); PhysRegDef.assign(NumRegs, nullptr); PhysRegUse.assign(NumRegs, nullptr); PHIVarInfo.resize(MF->getNumBlockIDs()); - PHIJoins.clear(); // FIXME: LiveIntervals will be updated to remove its dependence on // LiveVariables to improve compilation time and eliminate bizarre pass @@ -661,22 +662,18 @@ void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) { MachineInstr &DefMI = *MRI->getUniqueVRegDef(Reg); MachineBasicBlock &DefBB = *DefMI.getParent(); - // Handle the case where all uses have been removed. - if (MRI->use_nodbg_empty(Reg)) { - VI.Kills.push_back(&DefMI); - DefMI.addRegisterDead(Reg, nullptr); - return; - } - DefMI.clearRegisterDeads(Reg); - // Initialize a worklist of BBs that Reg is live-to-end of. (Here // "live-to-end" means Reg is live at the end of a block even if it is only // live because of phi uses in a successor. This is different from isLiveOut() // which does not consider phi uses.) SmallVector<MachineBasicBlock *> LiveToEndBlocks; SparseBitVector<> UseBlocks; + unsigned NumRealUses = 0; for (auto &UseMO : MRI->use_nodbg_operands(Reg)) { UseMO.setIsKill(false); + if (!UseMO.readsReg()) + continue; + ++NumRealUses; MachineInstr &UseMI = *UseMO.getParent(); MachineBasicBlock &UseBB = *UseMI.getParent(); UseBlocks.set(UseBB.getNumber()); @@ -693,6 +690,14 @@ void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) { } } + // Handle the case where all uses have been removed. + if (NumRealUses == 0) { + VI.Kills.push_back(&DefMI); + DefMI.addRegisterDead(Reg, nullptr); + return; + } + DefMI.clearRegisterDeads(Reg); + // Iterate over the worklist adding blocks to AliveBlocks. bool LiveToEndOfDefBB = false; while (!LiveToEndBlocks.empty()) { @@ -721,7 +726,7 @@ void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) { continue; if (MI.isPHI()) break; - if (MI.readsRegister(Reg)) { + if (MI.readsVirtualRegister(Reg)) { assert(!MI.killsRegister(Reg)); MI.addRegisterKilled(Reg, nullptr); VI.Kills.push_back(&MI); |
