diff --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp --- a/llvm/lib/CodeGen/LiveDebugVariables.cpp +++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp @@ -98,36 +98,36 @@ /// Describes a debug variable value by location number and expression along /// with some flags about the original usage of the location. -class DbgValueLocation { +class DbgVariableValue { public: - DbgValueLocation(unsigned LocNo, bool WasIndirect, + DbgVariableValue(unsigned LocNo, bool WasIndirect, const DIExpression &Expression) : LocNo(LocNo), WasIndirect(WasIndirect), Expression(&Expression) { - assert(locNo() == LocNo && "location truncation"); + assert(getLocNo() == LocNo && "location truncation"); } - DbgValueLocation() : LocNo(0), WasIndirect(0) {} + DbgVariableValue() : LocNo(0), WasIndirect(0) {} const DIExpression *getExpression() const { return Expression; } - unsigned locNo() const { + unsigned getLocNo() const { // Fix up the undef location number, which gets truncated. return LocNo == INT_MAX ? UndefLocNo : LocNo; } - bool wasIndirect() const { return WasIndirect; } - bool isUndef() const { return locNo() == UndefLocNo; } + bool getWasIndirect() const { return WasIndirect; } + bool isUndef() const { return getLocNo() == UndefLocNo; } - DbgValueLocation changeLocNo(unsigned NewLocNo) const { - return DbgValueLocation(NewLocNo, WasIndirect, *Expression); + DbgVariableValue changeLocNo(unsigned NewLocNo) const { + return DbgVariableValue(NewLocNo, WasIndirect, *Expression); } - friend inline bool operator==(const DbgValueLocation &LHS, - const DbgValueLocation &RHS) { + friend inline bool operator==(const DbgVariableValue &LHS, + const DbgVariableValue &RHS) { return LHS.LocNo == RHS.LocNo && LHS.WasIndirect == RHS.WasIndirect && LHS.Expression == RHS.Expression; } - friend inline bool operator!=(const DbgValueLocation &LHS, - const DbgValueLocation &RHS) { + friend inline bool operator!=(const DbgVariableValue &LHS, + const DbgVariableValue &RHS) { return !(LHS == RHS); } @@ -137,8 +137,8 @@ const DIExpression *Expression = nullptr; }; -/// Map of where a user value is live, and its location. -using LocMap = IntervalMap; +/// Map of where a user value is live to that value. +using LocMap = IntervalMap; /// Map of stack slot offsets for spilled locations. /// Non-spilled locations are not added to the map. @@ -177,10 +177,10 @@ /// lexical scope. SmallSet trimmedDefs; - /// Insert a DBG_VALUE into MBB at Idx for LocNo. + /// Insert a DBG_VALUE into MBB at Idx for DbgValue. void insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx, - SlotIndex StopIdx, DbgValueLocation Loc, bool Spilled, - unsigned SpillOffset, LiveIntervals &LIS, + SlotIndex StopIdx, DbgVariableValue DbgValue, + bool Spilled, unsigned SpillOffset, LiveIntervals &LIS, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI); @@ -282,34 +282,34 @@ void removeLocationIfUnused(unsigned LocNo) { // Bail out if LocNo still is used. for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) { - DbgValueLocation Loc = I.value(); - if (Loc.locNo() == LocNo) + DbgVariableValue DbgValue = I.value(); + if (DbgValue.getLocNo() == LocNo) return; } // Remove the entry in the locations vector, and adjust all references to // location numbers above the removed entry. locations.erase(locations.begin() + LocNo); for (LocMap::iterator I = locInts.begin(); I.valid(); ++I) { - DbgValueLocation Loc = I.value(); - if (!Loc.isUndef() && Loc.locNo() > LocNo) - I.setValueUnchecked(Loc.changeLocNo(Loc.locNo() - 1)); + DbgVariableValue DbgValue = I.value(); + if (!DbgValue.isUndef() && DbgValue.getLocNo() > LocNo) + I.setValueUnchecked(DbgValue.changeLocNo(DbgValue.getLocNo() - 1)); } } /// Ensure that all virtual register locations are mapped. void mapVirtRegs(LDVImpl *LDV); - /// Add a definition point to this value. + /// Add a definition point to this user value. void addDef(SlotIndex Idx, const MachineOperand &LocMO, bool IsIndirect, const DIExpression &Expr) { - DbgValueLocation Loc(getLocationNo(LocMO), IsIndirect, Expr); - // Add a singular (Idx,Idx) -> Loc mapping. + DbgVariableValue DbgValue(getLocationNo(LocMO), IsIndirect, Expr); + // Add a singular (Idx,Idx) -> value mapping. LocMap::iterator I = locInts.find(Idx); if (!I.valid() || I.start() != Idx) - I.insert(Idx, Idx.getNextSlot(), Loc); + I.insert(Idx, Idx.getNextSlot(), DbgValue); else // A later DBG_VALUE at the same SlotIndex overrides the old location. - I.setValue(Loc); + I.setValue(DbgValue); } /// Extend the current definition as far as possible down. @@ -321,28 +321,27 @@ /// data-flow analysis to propagate them beyond basic block boundaries. /// /// \param Idx Starting point for the definition. - /// \param Loc Location number to propagate. + /// \param DbgValue value to propagate. /// \param LR Restrict liveness to where LR has the value VNI. May be null. /// \param VNI When LR is not null, this is the value to restrict to. /// \param [out] Kills Append end points of VNI's live range to Kills. /// \param LIS Live intervals analysis. - void extendDef(SlotIndex Idx, DbgValueLocation Loc, - LiveRange *LR, const VNInfo *VNI, - SmallVectorImpl *Kills, + void extendDef(SlotIndex Idx, DbgVariableValue DbgValue, LiveRange *LR, + const VNInfo *VNI, SmallVectorImpl *Kills, LiveIntervals &LIS); - /// The value in LI/LocNo may be copies to other registers. Determine if + /// The value in LI may be copies to other registers. Determine if /// any of the copies are available at the kill points, and add defs if /// possible. /// /// \param LI Scan for copies of the value in LI->reg. - /// \param Loc Location number of LI->reg. - /// \param Kills Points where the range of LocNo could be extended. - /// \param [in,out] NewDefs Append (Idx, LocNo) of inserted defs here. + /// \param DbgValue Location number of LI->reg, and DIExpression. + /// \param Kills Points where the range of DbgValue could be extended. + /// \param [in,out] NewDefs Append (Idx, DbgValue) of inserted defs here. void addDefsFromCopies( - LiveInterval *LI, DbgValueLocation Loc, + LiveInterval *LI, DbgVariableValue DbgValue, const SmallVectorImpl &Kills, - SmallVectorImpl> &NewDefs, + SmallVectorImpl> &NewDefs, MachineRegisterInfo &MRI, LiveIntervals &LIS); /// Compute the live intervals of all locations after collecting all their @@ -559,8 +558,8 @@ if (I.value().isUndef()) OS << "undef"; else { - OS << I.value().locNo(); - if (I.value().wasIndirect()) + OS << I.value().getLocNo(); + if (I.value().getWasIndirect()) OS << " ind"; } } @@ -745,7 +744,7 @@ return Changed; } -void UserValue::extendDef(SlotIndex Idx, DbgValueLocation Loc, LiveRange *LR, +void UserValue::extendDef(SlotIndex Idx, DbgVariableValue DbgValue, LiveRange *LR, const VNInfo *VNI, SmallVectorImpl *Kills, LiveIntervals &LIS) { SlotIndex Start = Idx; @@ -772,7 +771,7 @@ if (I.valid() && I.start() <= Start) { // Stop when meeting a different location or an already extended interval. Start = Start.getNextSlot(); - if (I.value() != Loc || I.stop() != Start) + if (I.value() != DbgValue || I.stop() != Start) return; // This is a one-slot placeholder. Just skip it. ++I; @@ -786,13 +785,13 @@ Kills->push_back(Stop); if (Start < Stop) - I.insert(Start, Stop, Loc); + I.insert(Start, Stop, DbgValue); } void UserValue::addDefsFromCopies( - LiveInterval *LI, DbgValueLocation Loc, + LiveInterval *LI, DbgVariableValue DbgValue, const SmallVectorImpl &Kills, - SmallVectorImpl> &NewDefs, + SmallVectorImpl> &NewDefs, MachineRegisterInfo &MRI, LiveIntervals &LIS) { if (Kills.empty()) return; @@ -816,11 +815,11 @@ if (!Register::isVirtualRegister(DstReg)) continue; - // Is LocNo extended to reach this copy? If not, another def may be blocking - // it, or we are looking at a wrong value of LI. + // Is the value extended to reach this copy? If not, another def may be + // blocking it, or we are looking at a wrong value of LI. SlotIndex Idx = LIS.getInstructionIndex(*MI); LocMap::iterator I = locInts.find(Idx.getRegSlot(true)); - if (!I.valid() || I.value() != Loc) + if (!I.valid() || I.value() != DbgValue) continue; if (!LIS.hasInterval(DstReg)) @@ -854,9 +853,9 @@ MachineInstr *CopyMI = LIS.getInstructionFromIndex(DstVNI->def); assert(CopyMI && CopyMI->isCopy() && "Bad copy value"); unsigned LocNo = getLocationNo(CopyMI->getOperand(0)); - DbgValueLocation NewLoc = Loc.changeLocNo(LocNo); - I.insert(Idx, Idx.getNextSlot(), NewLoc); - NewDefs.push_back(std::make_pair(Idx, NewLoc)); + DbgVariableValue NewValue = DbgValue.changeLocNo(LocNo); + I.insert(Idx, Idx.getNextSlot(), NewValue); + NewDefs.push_back(std::make_pair(Idx, NewValue)); break; } } @@ -865,7 +864,7 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, LiveIntervals &LIS, LexicalScopes &LS) { - SmallVector, 16> Defs; + SmallVector, 16> Defs; // Collect all defs to be extended (Skipping undefs). for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) @@ -875,11 +874,11 @@ // Extend all defs, and possibly add new ones along the way. for (unsigned i = 0; i != Defs.size(); ++i) { SlotIndex Idx = Defs[i].first; - DbgValueLocation Loc = Defs[i].second; - const MachineOperand &LocMO = locations[Loc.locNo()]; + DbgVariableValue DbgValue = Defs[i].second; + const MachineOperand &LocMO = locations[DbgValue.getLocNo()]; if (!LocMO.isReg()) { - extendDef(Idx, Loc, nullptr, nullptr, nullptr, LIS); + extendDef(Idx, DbgValue, nullptr, nullptr, nullptr, LIS); continue; } @@ -892,7 +891,7 @@ VNI = LI->getVNInfoAt(Idx); } SmallVector Kills; - extendDef(Idx, Loc, LI, VNI, &Kills, LIS); + extendDef(Idx, DbgValue, LI, VNI, &Kills, LIS); // FIXME: Handle sub-registers in addDefsFromCopies. The problem is that // if the original location for example is %vreg0:sub_hi, and we find a // full register copy in addDefsFromCopies (at the moment it only handles @@ -902,7 +901,7 @@ // sub-register in that regclass). For now, simply skip handling copies if // a sub-register is involved. if (LI && !LocMO.getSubReg()) - addDefsFromCopies(LI, Loc, Kills, Defs, MRI, LIS); + addDefsFromCopies(LI, DbgValue, Kills, Defs, MRI, LIS); continue; } @@ -944,7 +943,7 @@ // I.stop() >= PrevEnd. Check for overlap. if (PrevEnd && I.start() < PrevEnd) { SlotIndex IStop = I.stop(); - DbgValueLocation Loc = I.value(); + DbgVariableValue DbgValue = I.value(); // Stop overlaps previous end - trim the end of the interval to // the scope range. @@ -955,7 +954,7 @@ // current) range create a new interval for the remainder (which // may be further trimmed). if (RStart < IStop) - I.insert(RStart, IStop, Loc); + I.insert(RStart, IStop, DbgValue); } // Advance I so that I.stop() >= RStart, and check for overlap. @@ -1082,7 +1081,8 @@ break; // Now LII->end > LocMapI.start(). Do we have an overlap? - if (LocMapI.value().locNo() == OldLocNo && LII->start < LocMapI.stop()) { + if (LocMapI.value().getLocNo() == OldLocNo && + LII->start < LocMapI.stop()) { // Overlapping correct location. Allocate NewLocNo now. if (NewLocNo == UndefLocNo) { MachineOperand MO = MachineOperand::CreateReg(LI->reg, false); @@ -1092,8 +1092,8 @@ } SlotIndex LStart = LocMapI.start(); - SlotIndex LStop = LocMapI.stop(); - DbgValueLocation OldLoc = LocMapI.value(); + SlotIndex LStop = LocMapI.stop(); + DbgVariableValue OldDbgValue = LocMapI.value(); // Trim LocMapI down to the LII overlap. if (LStart < LII->start) @@ -1102,17 +1102,17 @@ LocMapI.setStopUnchecked(LII->end); // Change the value in the overlap. This may trigger coalescing. - LocMapI.setValue(OldLoc.changeLocNo(NewLocNo)); + LocMapI.setValue(OldDbgValue.changeLocNo(NewLocNo)); - // Re-insert any removed OldLocNo ranges. + // Re-insert any removed OldDbgValue ranges. if (LStart < LocMapI.start()) { - LocMapI.insert(LStart, LocMapI.start(), OldLoc); + LocMapI.insert(LStart, LocMapI.start(), OldDbgValue); ++LocMapI; assert(LocMapI.valid() && "Unexpected coalescing"); } if (LStop > LocMapI.stop()) { ++LocMapI; - LocMapI.insert(LII->end, LStop, OldLoc); + LocMapI.insert(LII->end, LStop, OldDbgValue); --LocMapI; } } @@ -1138,6 +1138,9 @@ // register to the spill slot). So for a while we can have locations that map // to virtual registers that have been removed from both the MachineFunction // and from LiveIntervals. + // + // We may also just be using the location for a value with a different + // expression. removeLocationIfUnused(OldLocNo); LLVM_DEBUG({ @@ -1256,13 +1259,13 @@ // DBG_VALUE intervals with different vregs that were allocated to the same // physical register. for (LocMap::iterator I = locInts.begin(); I.valid(); ++I) { - DbgValueLocation Loc = I.value(); + DbgVariableValue DbgValue = I.value(); // Undef values don't exist in locations (and thus not in LocNoMap either) // so skip over them. See getLocationNo(). - if (Loc.isUndef()) + if (DbgValue.isUndef()) continue; - unsigned NewLocNo = LocNoMap[Loc.locNo()]; - I.setValueUnchecked(Loc.changeLocNo(NewLocNo)); + unsigned NewLocNo = LocNoMap[DbgValue.getLocNo()]; + I.setValueUnchecked(DbgValue.changeLocNo(NewLocNo)); I.setStart(I.start()); } } @@ -1316,7 +1319,7 @@ } void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx, - SlotIndex StopIdx, DbgValueLocation Loc, + SlotIndex StopIdx, DbgVariableValue DbgValue, bool Spilled, unsigned SpillOffset, LiveIntervals &LIS, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI) { @@ -1326,12 +1329,14 @@ MachineBasicBlock::iterator I = findInsertLocation(MBB, StartIdx, LIS); // Undef values don't exist in locations so create new "noreg" register MOs // for them. See getLocationNo(). - MachineOperand MO = !Loc.isUndef() ? - locations[Loc.locNo()] : - MachineOperand::CreateReg(/* Reg */ 0, /* isDef */ false, /* isImp */ false, - /* isKill */ false, /* isDead */ false, - /* isUndef */ false, /* isEarlyClobber */ false, - /* SubReg */ 0, /* isDebug */ true); + MachineOperand MO = + !DbgValue.isUndef() + ? locations[DbgValue.getLocNo()] + : MachineOperand::CreateReg( + /* Reg */ 0, /* isDef */ false, /* isImp */ false, + /* isKill */ false, /* isDead */ false, + /* isUndef */ false, /* isEarlyClobber */ false, + /* SubReg */ 0, /* isDebug */ true); ++NumInsertedDebugValues; @@ -1343,9 +1348,9 @@ // original DBG_VALUE was indirect, we need to add DW_OP_deref to indicate // that the original virtual register was a pointer. Also, add the stack slot // offset for the spilled register to the expression. - const DIExpression *Expr = Loc.getExpression(); + const DIExpression *Expr = DbgValue.getExpression(); uint8_t DIExprFlags = DIExpression::ApplyOffset; - bool IsIndirect = Loc.wasIndirect(); + bool IsIndirect = DbgValue.getWasIndirect(); if (Spilled) { if (IsIndirect) DIExprFlags |= DIExpression::DerefAfter; @@ -1384,9 +1389,9 @@ for (LocMap::const_iterator I = locInts.begin(); I.valid();) { SlotIndex Start = I.start(); SlotIndex Stop = I.stop(); - DbgValueLocation Loc = I.value(); - auto SpillIt = - !Loc.isUndef() ? SpillOffsets.find(Loc.locNo()) : SpillOffsets.end(); + DbgVariableValue DbgValue = I.value(); + auto SpillIt = !DbgValue.isUndef() ? SpillOffsets.find(DbgValue.getLocNo()) + : SpillOffsets.end(); bool Spilled = SpillIt != SpillOffsets.end(); unsigned SpillOffset = Spilled ? SpillIt->second : 0; @@ -1396,13 +1401,14 @@ if (trimmedDefs.count(Start)) Start = Start.getPrevIndex(); - LLVM_DEBUG(dbgs() << "\t[" << Start << ';' << Stop << "):" << Loc.locNo()); + LLVM_DEBUG(dbgs() << "\t[" << Start << ';' << Stop + << "):" << DbgValue.getLocNo()); MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start)->getIterator(); SlotIndex MBBEnd = LIS.getMBBEndIdx(&*MBB); LLVM_DEBUG(dbgs() << ' ' << printMBBReference(*MBB) << '-' << MBBEnd); - insertDebugValue(&*MBB, Start, Stop, Loc, Spilled, SpillOffset, LIS, TII, - TRI); + insertDebugValue(&*MBB, Start, Stop, DbgValue, Spilled, SpillOffset, LIS, + TII, TRI); // This interval may span multiple basic blocks. // Insert a DBG_VALUE into each one. while (Stop > MBBEnd) { @@ -1412,8 +1418,8 @@ break; MBBEnd = LIS.getMBBEndIdx(&*MBB); LLVM_DEBUG(dbgs() << ' ' << printMBBReference(*MBB) << '-' << MBBEnd); - insertDebugValue(&*MBB, Start, Stop, Loc, Spilled, SpillOffset, LIS, TII, - TRI); + insertDebugValue(&*MBB, Start, Stop, DbgValue, Spilled, SpillOffset, LIS, + TII, TRI); } LLVM_DEBUG(dbgs() << '\n'); if (MBB == MFEnd)