@@ -100,27 +100,28 @@ enum : unsigned { UndefLocNo = ~0U };
100100// / usage of the location.
101101class DbgValueLocation {
102102public:
103- DbgValueLocation (unsigned LocNo)
104- : LocNo(LocNo) {
103+ DbgValueLocation (unsigned LocNo, bool WasIndirect )
104+ : LocNo(LocNo), WasIndirect(WasIndirect) {
105105 static_assert (sizeof (*this ) == sizeof (unsigned ), " bad bitfield packing" );
106106 assert (locNo () == LocNo && " location truncation" );
107107 }
108108
109- DbgValueLocation () : LocNo(0 ) {}
109+ DbgValueLocation () : LocNo(0 ), WasIndirect( 0 ) {}
110110
111111 unsigned locNo () const {
112112 // Fix up the undef location number, which gets truncated.
113113 return LocNo == INT_MAX ? UndefLocNo : LocNo;
114114 }
115+ bool wasIndirect () const { return WasIndirect; }
115116 bool isUndef () const { return locNo () == UndefLocNo; }
116117
117118 DbgValueLocation changeLocNo (unsigned NewLocNo) const {
118- return DbgValueLocation (NewLocNo);
119+ return DbgValueLocation (NewLocNo, WasIndirect );
119120 }
120121
121122 friend inline bool operator ==(const DbgValueLocation &LHS,
122123 const DbgValueLocation &RHS) {
123- return LHS.LocNo == RHS.LocNo ;
124+ return LHS.LocNo == RHS.LocNo && LHS. WasIndirect == RHS. WasIndirect ;
124125 }
125126
126127 friend inline bool operator !=(const DbgValueLocation &LHS,
@@ -129,7 +130,8 @@ class DbgValueLocation {
129130 }
130131
131132private:
132- unsigned LocNo;
133+ unsigned LocNo : 31 ;
134+ unsigned WasIndirect : 1 ;
133135};
134136
135137// / Map of where a user value is live, and its location.
@@ -283,8 +285,8 @@ class UserValue {
283285 void mapVirtRegs (LDVImpl *LDV);
284286
285287 // / Add a definition point to this value.
286- void addDef (SlotIndex Idx, const MachineOperand &LocMO) {
287- DbgValueLocation Loc (getLocationNo (LocMO));
288+ void addDef (SlotIndex Idx, const MachineOperand &LocMO, bool IsIndirect ) {
289+ DbgValueLocation Loc (getLocationNo (LocMO), IsIndirect );
288290 // Add a singular (Idx,Idx) -> Loc mapping.
289291 LocMap::iterator I = locInts.find (Idx);
290292 if (!I.valid () || I.start () != Idx)
@@ -319,10 +321,11 @@ class UserValue {
319321 // /
320322 // / \param LI Scan for copies of the value in LI->reg.
321323 // / \param LocNo Location number of LI->reg.
324+ // / \param WasIndirect Indicates if the original use of LI->reg was indirect
322325 // / \param Kills Points where the range of LocNo could be extended.
323326 // / \param [in,out] NewDefs Append (Idx, LocNo) of inserted defs here.
324327 void addDefsFromCopies (
325- LiveInterval *LI, unsigned LocNo,
328+ LiveInterval *LI, unsigned LocNo, bool WasIndirect,
326329 const SmallVectorImpl<SlotIndex> &Kills,
327330 SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
328331 MachineRegisterInfo &MRI, LiveIntervals &LIS);
@@ -542,6 +545,8 @@ void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
542545 OS << " undef" ;
543546 else {
544547 OS << I.value ().locNo ();
548+ if (I.value ().wasIndirect ())
549+ OS << " ind" ;
545550 }
546551 }
547552 for (unsigned i = 0 , e = locations.size (); i != e; ++i) {
@@ -650,18 +655,19 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
650655 }
651656
652657 // Get or create the UserValue for (variable,offset) here.
653- assert (!MI.getOperand (1 ).isImm () && " DBG_VALUE with indirect flag before "
654- " LiveDebugVariables" );
658+ bool IsIndirect = MI.getOperand (1 ).isImm ();
659+ if (IsIndirect)
660+ assert (MI.getOperand (1 ).getImm () == 0 && " DBG_VALUE with nonzero offset" );
655661 const DILocalVariable *Var = MI.getDebugVariable ();
656662 const DIExpression *Expr = MI.getDebugExpression ();
657663 UserValue *UV =
658664 getUserValue (Var, Expr, MI.getDebugLoc ());
659665 if (!Discard)
660- UV->addDef (Idx, MI.getOperand (0 ));
666+ UV->addDef (Idx, MI.getOperand (0 ), IsIndirect );
661667 else {
662668 MachineOperand MO = MachineOperand::CreateReg (0U , false );
663669 MO.setIsDebug ();
664- UV->addDef (Idx, MO);
670+ UV->addDef (Idx, MO, false );
665671 }
666672 return true ;
667673}
@@ -769,7 +775,7 @@ void UserValue::extendDef(SlotIndex Idx, DbgValueLocation Loc, LiveRange *LR,
769775}
770776
771777void UserValue::addDefsFromCopies (
772- LiveInterval *LI, unsigned LocNo,
778+ LiveInterval *LI, unsigned LocNo, bool WasIndirect,
773779 const SmallVectorImpl<SlotIndex> &Kills,
774780 SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
775781 MachineRegisterInfo &MRI, LiveIntervals &LIS) {
@@ -833,7 +839,7 @@ void UserValue::addDefsFromCopies(
833839 MachineInstr *CopyMI = LIS.getInstructionFromIndex (DstVNI->def );
834840 assert (CopyMI && CopyMI->isCopy () && " Bad copy value" );
835841 unsigned LocNo = getLocationNo (CopyMI->getOperand (0 ));
836- DbgValueLocation NewLoc (LocNo);
842+ DbgValueLocation NewLoc (LocNo, WasIndirect );
837843 I.insert (Idx, Idx.getNextSlot (), NewLoc);
838844 NewDefs.push_back (std::make_pair (Idx, NewLoc));
839845 break ;
@@ -881,7 +887,8 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
881887 // sub-register in that regclass). For now, simply skip handling copies if
882888 // a sub-register is involved.
883889 if (LI && !LocMO.getSubReg ())
884- addDefsFromCopies (LI, Loc.locNo (), Kills, Defs, MRI, LIS);
890+ addDefsFromCopies (LI, Loc.locNo (), Loc.wasIndirect (), Kills, Defs, MRI,
891+ LIS);
885892 continue ;
886893 }
887894
@@ -1323,14 +1330,21 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx,
13231330 // that the original virtual register was a pointer. Also, add the stack slot
13241331 // offset for the spilled register to the expression.
13251332 const DIExpression *Expr = Expression;
1326- if (Spilled)
1327- Expr = DIExpression::prepend (Expr, DIExpression::ApplyOffset, SpillOffset);
1333+ uint8_t DIExprFlags = DIExpression::ApplyOffset;
1334+ bool IsIndirect = Loc.wasIndirect ();
1335+ if (Spilled) {
1336+ if (IsIndirect)
1337+ DIExprFlags |= DIExpression::DerefAfter;
1338+ Expr =
1339+ DIExpression::prepend (Expr, DIExprFlags, SpillOffset);
1340+ IsIndirect = true ;
1341+ }
13281342
13291343 assert ((!Spilled || MO.isFI ()) && " a spilled location must be a frame index" );
13301344
13311345 do {
13321346 BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE),
1333- Spilled , MO, Variable, Expr);
1347+ IsIndirect , MO, Variable, Expr);
13341348
13351349 // Continue and insert DBG_VALUES after every redefinition of register
13361350 // associated with the debug value within the range
0 commit comments