@@ -108,8 +108,8 @@ class LDVImpl;
108
108
// / held by the same virtual register. The equivalence class is the transitive
109
109
// / closure of that relation.
110
110
class UserValue {
111
- const MDNode *Variable; // /< The debug info variable we are part of.
112
- const MDNode *Expression; // /< Any complex address expression.
111
+ const DILocalVariable *Variable; // /< The debug info variable we are part of.
112
+ const DIExpression *Expression; // /< Any complex address expression.
113
113
bool IsIndirect; // /< true if this is a register-indirect+offset value.
114
114
DebugLoc dl; // /< The debug location for the variable. This is
115
115
// /< used by dwarf writer to find lexical scope.
@@ -132,8 +132,9 @@ class UserValue {
132
132
void coalesceLocation (unsigned LocNo);
133
133
134
134
// / insertDebugValue - Insert a DBG_VALUE into MBB at Idx for LocNo.
135
- void insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx, unsigned LocNo,
136
- LiveIntervals &LIS, const TargetInstrInfo &TII);
135
+ void insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx,
136
+ unsigned LocNo, bool Spilled, LiveIntervals &LIS,
137
+ const TargetInstrInfo &TII);
137
138
138
139
// / splitLocation - Replace OldLocNo ranges with NewRegs ranges where NewRegs
139
140
// / is live. Returns true if any changes were made.
@@ -142,8 +143,8 @@ class UserValue {
142
143
143
144
public:
144
145
// / UserValue - Create a new UserValue.
145
- UserValue (const MDNode *var, const MDNode *expr, bool i, DebugLoc L ,
146
- LocMap::Allocator &alloc)
146
+ UserValue (const DILocalVariable *var, const DIExpression *expr, bool i,
147
+ DebugLoc L, LocMap::Allocator &alloc)
147
148
: Variable(var), Expression(expr), IsIndirect(i), dl(std::move(L)),
148
149
leader (this ), locInts(alloc) {}
149
150
@@ -159,8 +160,8 @@ class UserValue {
159
160
UserValue *getNext () const { return next; }
160
161
161
162
// / match - Does this UserValue match the parameters?
162
- bool match (const MDNode *Var, const MDNode *Expr, const DILocation *IA ,
163
- bool indirect) const {
163
+ bool match (const DILocalVariable *Var, const DIExpression *Expr,
164
+ const DILocation *IA, bool indirect) const {
164
165
return Var == Variable && Expr == Expression && dl->getInlinedAt () == IA &&
165
166
indirect == IsIndirect;
166
167
}
@@ -262,12 +263,14 @@ class UserValue {
262
263
LiveIntervals &LIS);
263
264
264
265
// / rewriteLocations - Rewrite virtual register locations according to the
265
- // / provided virtual register map.
266
- void rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI);
266
+ // / provided virtual register map. Record which locations were spilled.
267
+ void rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI,
268
+ BitVector &SpilledLocations);
267
269
268
270
// / emitDebugValues - Recreate DBG_VALUE instruction from data structures.
269
- void emitDebugValues (VirtRegMap *VRM,
270
- LiveIntervals &LIS, const TargetInstrInfo &TRI);
271
+ void emitDebugValues (VirtRegMap *VRM, LiveIntervals &LIS,
272
+ const TargetInstrInfo &TRI,
273
+ const BitVector &SpilledLocations);
271
274
272
275
// / getDebugLoc - Return DebugLoc of this UserValue.
273
276
DebugLoc getDebugLoc () { return dl;}
@@ -297,11 +300,11 @@ class LDVImpl {
297
300
VRMap virtRegToEqClass;
298
301
299
302
// / Map user variable to eq class leader.
300
- using UVMap = DenseMap<const MDNode *, UserValue *>;
303
+ using UVMap = DenseMap<const DILocalVariable *, UserValue *>;
301
304
UVMap userVarMap;
302
305
303
306
// / getUserValue - Find or create a UserValue.
304
- UserValue *getUserValue (const MDNode *Var, const MDNode *Expr,
307
+ UserValue *getUserValue (const DILocalVariable *Var, const DIExpression *Expr,
305
308
bool IsIndirect, const DebugLoc &DL);
306
309
307
310
// / lookupVirtReg - Find the EC leader for VirtReg or null.
@@ -454,8 +457,9 @@ void UserValue::mapVirtRegs(LDVImpl *LDV) {
454
457
LDV->mapVirtReg (locations[i].getReg (), this );
455
458
}
456
459
457
- UserValue *LDVImpl::getUserValue (const MDNode *Var, const MDNode *Expr,
458
- bool IsIndirect, const DebugLoc &DL) {
460
+ UserValue *LDVImpl::getUserValue (const DILocalVariable *Var,
461
+ const DIExpression *Expr, bool IsIndirect,
462
+ const DebugLoc &DL) {
459
463
UserValue *&Leader = userVarMap[Var];
460
464
if (Leader) {
461
465
UserValue *UV = Leader->getLeader ();
@@ -494,11 +498,11 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
494
498
}
495
499
496
500
// Get or create the UserValue for (variable,offset).
497
- bool IsIndirect = MI.isIndirectDebugValue ();
501
+ bool IsIndirect = MI.getOperand ( 1 ). isImm ();
498
502
if (IsIndirect)
499
503
assert (MI.getOperand (1 ).getImm () == 0 && " DBG_VALUE with nonzero offset" );
500
- const MDNode *Var = MI.getDebugVariable ();
501
- const MDNode *Expr = MI.getDebugExpression ();
504
+ const DILocalVariable *Var = MI.getDebugVariable ();
505
+ const DIExpression *Expr = MI.getDebugExpression ();
502
506
// here.
503
507
UserValue *UV = getUserValue (Var, Expr, IsIndirect, MI.getDebugLoc ());
504
508
UV->addDef (Idx, MI.getOperand (0 ));
@@ -971,8 +975,10 @@ splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs, LiveIntervals &LIS) {
971
975
static_cast <LDVImpl*>(pImpl)->splitRegister (OldReg, NewRegs);
972
976
}
973
977
974
- void
975
- UserValue::rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI) {
978
+ void UserValue::rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI,
979
+ BitVector &SpilledLocations) {
980
+ SpilledLocations.resize (locations.size ());
981
+
976
982
// Iterate over locations in reverse makes it easier to handle coalescing.
977
983
for (unsigned i = locations.size (); i ; --i) {
978
984
unsigned LocNo = i-1 ;
@@ -991,6 +997,7 @@ UserValue::rewriteLocations(VirtRegMap &VRM, const TargetRegisterInfo &TRI) {
991
997
} else if (VRM.getStackSlot (VirtReg) != VirtRegMap::NO_STACK_SLOT) {
992
998
// FIXME: Translate SubIdx to a stackslot offset.
993
999
Loc = MachineOperand::CreateFI (VRM.getStackSlot (VirtReg));
1000
+ SpilledLocations.set (LocNo);
994
1001
} else {
995
1002
Loc.setReg (0 );
996
1003
Loc.setSubReg (0 );
@@ -1024,7 +1031,7 @@ findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx,
1024
1031
}
1025
1032
1026
1033
void UserValue::insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx,
1027
- unsigned LocNo,
1034
+ unsigned LocNo, bool Spilled,
1028
1035
LiveIntervals &LIS,
1029
1036
const TargetInstrInfo &TII) {
1030
1037
MachineBasicBlock::iterator I = findInsertLocation (MBB, Idx, LIS);
@@ -1034,25 +1041,35 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex Idx,
1034
1041
assert (cast<DILocalVariable>(Variable)
1035
1042
->isValidLocationForIntrinsic (getDebugLoc ()) &&
1036
1043
" Expected inlined-at fields to agree" );
1037
- if (Loc.isReg ())
1038
- BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE),
1039
- IsIndirect, Loc.getReg (), Variable, Expression);
1044
+
1045
+ // If the location was spilled, the new DBG_VALUE will be indirect. If the
1046
+ // original DBG_VALUE was indirect, we need to add DW_OP_deref to indicate
1047
+ // that the original virtual register was a pointer.
1048
+ bool NewIndirect = IsIndirect || Spilled;
1049
+ const DIExpression *Expr = Expression;
1050
+ if (Spilled && IsIndirect)
1051
+ Expr = DIExpression::prepend (Expr, DIExpression::WithDeref);
1052
+
1053
+ MachineInstrBuilder MIB =
1054
+ BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE))
1055
+ .add (Loc);
1056
+ if (NewIndirect)
1057
+ MIB.addImm (0U );
1040
1058
else
1041
- BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE))
1042
- .add (Loc)
1043
- .addImm (0U )
1044
- .addMetadata (Variable)
1045
- .addMetadata (Expression);
1059
+ MIB.addReg (0U , RegState::Debug);
1060
+ MIB.addMetadata (Variable).addMetadata (Expr);
1046
1061
}
1047
1062
1048
1063
void UserValue::emitDebugValues (VirtRegMap *VRM, LiveIntervals &LIS,
1049
- const TargetInstrInfo &TII) {
1064
+ const TargetInstrInfo &TII,
1065
+ const BitVector &SpilledLocations) {
1050
1066
MachineFunction::iterator MFEnd = VRM->getMachineFunction ().end ();
1051
1067
1052
1068
for (LocMap::const_iterator I = locInts.begin (); I.valid ();) {
1053
1069
SlotIndex Start = I.start ();
1054
1070
SlotIndex Stop = I.stop ();
1055
1071
unsigned LocNo = I.value ();
1072
+ bool Spilled = LocNo != ~0U ? SpilledLocations.test (LocNo) : false ;
1056
1073
1057
1074
// If the interval start was trimmed to the lexical scope insert the
1058
1075
// DBG_VALUE at the previous index (otherwise it appears after the
@@ -1065,7 +1082,7 @@ void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
1065
1082
SlotIndex MBBEnd = LIS.getMBBEndIdx (&*MBB);
1066
1083
1067
1084
DEBUG (dbgs () << " BB#" << MBB->getNumber () << ' -' << MBBEnd);
1068
- insertDebugValue (&*MBB, Start, LocNo, LIS, TII);
1085
+ insertDebugValue (&*MBB, Start, LocNo, Spilled, LIS, TII);
1069
1086
// This interval may span multiple basic blocks.
1070
1087
// Insert a DBG_VALUE into each one.
1071
1088
while (Stop > MBBEnd) {
@@ -1075,7 +1092,7 @@ void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
1075
1092
break ;
1076
1093
MBBEnd = LIS.getMBBEndIdx (&*MBB);
1077
1094
DEBUG (dbgs () << " BB#" << MBB->getNumber () << ' -' << MBBEnd);
1078
- insertDebugValue (&*MBB, Start, LocNo, LIS, TII);
1095
+ insertDebugValue (&*MBB, Start, LocNo, Spilled, LIS, TII);
1079
1096
}
1080
1097
DEBUG (dbgs () << ' \n ' );
1081
1098
if (MBB == MFEnd)
@@ -1090,10 +1107,11 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
1090
1107
if (!MF)
1091
1108
return ;
1092
1109
const TargetInstrInfo *TII = MF->getSubtarget ().getInstrInfo ();
1110
+ BitVector SpilledLocations;
1093
1111
for (unsigned i = 0 , e = userValues.size (); i != e; ++i) {
1094
1112
DEBUG (userValues[i]->print (dbgs (), TRI));
1095
- userValues[i]->rewriteLocations (*VRM, *TRI);
1096
- userValues[i]->emitDebugValues (VRM, *LIS, *TII);
1113
+ userValues[i]->rewriteLocations (*VRM, *TRI, SpilledLocations );
1114
+ userValues[i]->emitDebugValues (VRM, *LIS, *TII, SpilledLocations );
1097
1115
}
1098
1116
EmitDone = true ;
1099
1117
}
0 commit comments