@@ -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.
@@ -127,8 +127,9 @@ class UserValue {
127
127
SmallSet<SlotIndex, 2 > trimmedDefs;
128
128
129
129
// / insertDebugValue - Insert a DBG_VALUE into MBB at Idx for LocNo.
130
- void insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx, unsigned LocNo,
131
- LiveIntervals &LIS, const TargetInstrInfo &TII);
130
+ void insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx,
131
+ unsigned LocNo, bool Spilled, LiveIntervals &LIS,
132
+ const TargetInstrInfo &TII);
132
133
133
134
// / splitLocation - Replace OldLocNo ranges with NewRegs ranges where NewRegs
134
135
// / is live. Returns true if any changes were made.
@@ -137,8 +138,8 @@ class UserValue {
137
138
138
139
public:
139
140
// / UserValue - Create a new UserValue.
140
- UserValue (const MDNode *var, const MDNode *expr, bool i, DebugLoc L ,
141
- LocMap::Allocator &alloc)
141
+ UserValue (const DILocalVariable *var, const DIExpression *expr, bool i,
142
+ DebugLoc L, LocMap::Allocator &alloc)
142
143
: Variable(var), Expression(expr), IsIndirect(i), dl(std::move(L)),
143
144
leader (this ), locInts(alloc) {}
144
145
@@ -154,8 +155,8 @@ class UserValue {
154
155
UserValue *getNext () const { return next; }
155
156
156
157
// / match - Does this UserValue match the parameters?
157
- bool match (const MDNode *Var, const MDNode *Expr, const DILocation *IA ,
158
- bool indirect) const {
158
+ bool match (const DILocalVariable *Var, const DIExpression *Expr,
159
+ const DILocation *IA, bool indirect) const {
159
160
return Var == Variable && Expr == Expression && dl->getInlinedAt () == IA &&
160
161
indirect == IsIndirect;
161
162
}
@@ -259,12 +260,14 @@ class UserValue {
259
260
LiveIntervals &LIS);
260
261
261
262
// / rewriteLocations - Rewrite virtual register locations according to the
262
- // / provided virtual register map.
263
- void rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI);
263
+ // / provided virtual register map. Record which locations were spilled.
264
+ void rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI,
265
+ BitVector &SpilledLocations);
264
266
265
267
// / emitDebugValues - Recreate DBG_VALUE instruction from data structures.
266
- void emitDebugValues (VirtRegMap *VRM,
267
- LiveIntervals &LIS, const TargetInstrInfo &TRI);
268
+ void emitDebugValues (VirtRegMap *VRM, LiveIntervals &LIS,
269
+ const TargetInstrInfo &TRI,
270
+ const BitVector &SpilledLocations);
268
271
269
272
// / getDebugLoc - Return DebugLoc of this UserValue.
270
273
DebugLoc getDebugLoc () { return dl;}
@@ -294,11 +297,11 @@ class LDVImpl {
294
297
VRMap virtRegToEqClass;
295
298
296
299
// / Map user variable to eq class leader.
297
- using UVMap = DenseMap<const MDNode *, UserValue *>;
300
+ using UVMap = DenseMap<const DILocalVariable *, UserValue *>;
298
301
UVMap userVarMap;
299
302
300
303
// / getUserValue - Find or create a UserValue.
301
- UserValue *getUserValue (const MDNode *Var, const MDNode *Expr,
304
+ UserValue *getUserValue (const DILocalVariable *Var, const DIExpression *Expr,
302
305
bool IsIndirect, const DebugLoc &DL);
303
306
304
307
// / lookupVirtReg - Find the EC leader for VirtReg or null.
@@ -423,8 +426,9 @@ void UserValue::mapVirtRegs(LDVImpl *LDV) {
423
426
LDV->mapVirtReg (locations[i].getReg (), this );
424
427
}
425
428
426
- UserValue *LDVImpl::getUserValue (const MDNode *Var, const MDNode *Expr,
427
- bool IsIndirect, const DebugLoc &DL) {
429
+ UserValue *LDVImpl::getUserValue (const DILocalVariable *Var,
430
+ const DIExpression *Expr, bool IsIndirect,
431
+ const DebugLoc &DL) {
428
432
UserValue *&Leader = userVarMap[Var];
429
433
if (Leader) {
430
434
UserValue *UV = Leader->getLeader ();
@@ -463,11 +467,11 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
463
467
}
464
468
465
469
// Get or create the UserValue for (variable,offset).
466
- bool IsIndirect = MI.isIndirectDebugValue ();
470
+ bool IsIndirect = MI.getOperand ( 1 ). isImm ();
467
471
if (IsIndirect)
468
472
assert (MI.getOperand (1 ).getImm () == 0 && " DBG_VALUE with nonzero offset" );
469
- const MDNode *Var = MI.getDebugVariable ();
470
- const MDNode *Expr = MI.getDebugExpression ();
473
+ const DILocalVariable *Var = MI.getDebugVariable ();
474
+ const DIExpression *Expr = MI.getDebugExpression ();
471
475
// here.
472
476
UserValue *UV = getUserValue (Var, Expr, IsIndirect, MI.getDebugLoc ());
473
477
UV->addDef (Idx, MI.getOperand (0 ));
@@ -940,15 +944,20 @@ splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs, LiveIntervals &LIS) {
940
944
static_cast <LDVImpl*>(pImpl)->splitRegister (OldReg, NewRegs);
941
945
}
942
946
943
- void UserValue::rewriteLocations (VirtRegMap &VRM,
944
- const TargetRegisterInfo &TRI ) {
947
+ void UserValue::rewriteLocations (VirtRegMap &VRM, const TargetRegisterInfo &TRI,
948
+ BitVector &SpilledLocations ) {
945
949
// Build a set of new locations with new numbers so we can coalesce our
946
950
// IntervalMap if two vreg intervals collapse to the same physical location.
947
951
// Use MapVector instead of SetVector because MapVector::insert returns the
948
- // position of the previously or newly inserted element.
952
+ // position of the previously or newly inserted element. The boolean value
953
+ // tracks if the location was produced by a spill.
954
+ // FIXME: This will be problematic if we ever support direct and indirect
955
+ // frame index locations, i.e. expressing both variables in memory and
956
+ // 'int x, *px = &x'. The "spilled" bit must become part of the location.
949
957
MapVector<MachineOperand, bool > NewLocations;
950
958
SmallVector<unsigned , 4 > LocNoMap (locations.size ());
951
959
for (unsigned I = 0 , E = locations.size (); I != E; ++I) {
960
+ bool Spilled = false ;
952
961
MachineOperand Loc = locations[I];
953
962
// Only virtual registers are rewritten.
954
963
if (Loc.isReg () && Loc.getReg () &&
@@ -963,6 +972,7 @@ void UserValue::rewriteLocations(VirtRegMap &VRM,
963
972
} else if (VRM.getStackSlot (VirtReg) != VirtRegMap::NO_STACK_SLOT) {
964
973
// FIXME: Translate SubIdx to a stackslot offset.
965
974
Loc = MachineOperand::CreateFI (VRM.getStackSlot (VirtReg));
975
+ Spilled = true ;
966
976
} else {
967
977
Loc.setReg (0 );
968
978
Loc.setSubReg (0 );
@@ -971,14 +981,22 @@ void UserValue::rewriteLocations(VirtRegMap &VRM,
971
981
972
982
// Insert this location if it doesn't already exist and record a mapping
973
983
// from the old number to the new number.
974
- auto InsertResult = NewLocations.insert ({Loc, false });
975
- LocNoMap[I] = std::distance (NewLocations.begin (), InsertResult.first );
984
+ auto InsertResult = NewLocations.insert ({Loc, Spilled});
985
+ unsigned NewLocNo = std::distance (NewLocations.begin (), InsertResult.first );
986
+ LocNoMap[I] = NewLocNo;
976
987
}
977
988
978
- // Rewrite the locations.
989
+ // Rewrite the locations and record which ones were spill slots .
979
990
locations.clear ();
980
- for (const auto &Pair : NewLocations)
991
+ SpilledLocations.clear ();
992
+ SpilledLocations.resize (NewLocations.size ());
993
+ for (auto &Pair : NewLocations) {
981
994
locations.push_back (Pair.first );
995
+ if (Pair.second ) {
996
+ unsigned NewLocNo = std::distance (&*NewLocations.begin (), &Pair);
997
+ SpilledLocations.set (NewLocNo);
998
+ }
999
+ }
982
1000
983
1001
// Update the interval map, but only coalesce left, since intervals to the
984
1002
// right use the old location numbers. This should merge two contiguous
@@ -1016,7 +1034,7 @@ findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx,
1016
1034
}
1017
1035
1018
1036
void UserValue::insertDebugValue (MachineBasicBlock *MBB, SlotIndex Idx,
1019
- unsigned LocNo,
1037
+ unsigned LocNo, bool Spilled,
1020
1038
LiveIntervals &LIS,
1021
1039
const TargetInstrInfo &TII) {
1022
1040
MachineBasicBlock::iterator I = findInsertLocation (MBB, Idx, LIS);
@@ -1026,25 +1044,38 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex Idx,
1026
1044
assert (cast<DILocalVariable>(Variable)
1027
1045
->isValidLocationForIntrinsic (getDebugLoc ()) &&
1028
1046
" Expected inlined-at fields to agree" );
1029
- if (Loc.isReg ())
1030
- BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE),
1031
- IsIndirect, Loc.getReg (), Variable, Expression);
1047
+
1048
+ // If the location was spilled, the new DBG_VALUE will be indirect. If the
1049
+ // original DBG_VALUE was indirect, we need to add DW_OP_deref to indicate
1050
+ // that the original virtual register was a pointer.
1051
+ bool NewIndirect = IsIndirect || Spilled;
1052
+ const DIExpression *Expr = Expression;
1053
+ if (Spilled && IsIndirect)
1054
+ Expr = DIExpression::prepend (Expr, DIExpression::WithDeref);
1055
+
1056
+ assert ((!Spilled || Loc.isFI ()) &&
1057
+ " a spilled location must be a frame index" );
1058
+
1059
+ MachineInstrBuilder MIB =
1060
+ BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE))
1061
+ .add (Loc);
1062
+ if (NewIndirect)
1063
+ MIB.addImm (0U );
1032
1064
else
1033
- BuildMI (*MBB, I, getDebugLoc (), TII.get (TargetOpcode::DBG_VALUE))
1034
- .add (Loc)
1035
- .addImm (0U )
1036
- .addMetadata (Variable)
1037
- .addMetadata (Expression);
1065
+ MIB.addReg (0U , RegState::Debug);
1066
+ MIB.addMetadata (Variable).addMetadata (Expr);
1038
1067
}
1039
1068
1040
1069
void UserValue::emitDebugValues (VirtRegMap *VRM, LiveIntervals &LIS,
1041
- const TargetInstrInfo &TII) {
1070
+ const TargetInstrInfo &TII,
1071
+ const BitVector &SpilledLocations) {
1042
1072
MachineFunction::iterator MFEnd = VRM->getMachineFunction ().end ();
1043
1073
1044
1074
for (LocMap::const_iterator I = locInts.begin (); I.valid ();) {
1045
1075
SlotIndex Start = I.start ();
1046
1076
SlotIndex Stop = I.stop ();
1047
1077
unsigned LocNo = I.value ();
1078
+ bool Spilled = LocNo != UndefLocNo ? SpilledLocations.test (LocNo) : false ;
1048
1079
1049
1080
// If the interval start was trimmed to the lexical scope insert the
1050
1081
// DBG_VALUE at the previous index (otherwise it appears after the
@@ -1057,7 +1088,7 @@ void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
1057
1088
SlotIndex MBBEnd = LIS.getMBBEndIdx (&*MBB);
1058
1089
1059
1090
DEBUG (dbgs () << " BB#" << MBB->getNumber () << ' -' << MBBEnd);
1060
- insertDebugValue (&*MBB, Start, LocNo, LIS, TII);
1091
+ insertDebugValue (&*MBB, Start, LocNo, Spilled, LIS, TII);
1061
1092
// This interval may span multiple basic blocks.
1062
1093
// Insert a DBG_VALUE into each one.
1063
1094
while (Stop > MBBEnd) {
@@ -1067,7 +1098,7 @@ void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
1067
1098
break ;
1068
1099
MBBEnd = LIS.getMBBEndIdx (&*MBB);
1069
1100
DEBUG (dbgs () << " BB#" << MBB->getNumber () << ' -' << MBBEnd);
1070
- insertDebugValue (&*MBB, Start, LocNo, LIS, TII);
1101
+ insertDebugValue (&*MBB, Start, LocNo, Spilled, LIS, TII);
1071
1102
}
1072
1103
DEBUG (dbgs () << ' \n ' );
1073
1104
if (MBB == MFEnd)
@@ -1082,10 +1113,11 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
1082
1113
if (!MF)
1083
1114
return ;
1084
1115
const TargetInstrInfo *TII = MF->getSubtarget ().getInstrInfo ();
1116
+ BitVector SpilledLocations;
1085
1117
for (unsigned i = 0 , e = userValues.size (); i != e; ++i) {
1086
1118
DEBUG (userValues[i]->print (dbgs (), TRI));
1087
- userValues[i]->rewriteLocations (*VRM, *TRI);
1088
- userValues[i]->emitDebugValues (VRM, *LIS, *TII);
1119
+ userValues[i]->rewriteLocations (*VRM, *TRI, SpilledLocations );
1120
+ userValues[i]->emitDebugValues (VRM, *LIS, *TII, SpilledLocations );
1089
1121
}
1090
1122
EmitDone = true ;
1091
1123
}
0 commit comments