@@ -1148,12 +1148,7 @@ SDValue SelectionDAGBuilder::getControlRoot() {
1148
1148
return updateRoot (PendingExports);
1149
1149
}
1150
1150
1151
- void SelectionDAGBuilder::visit (const Instruction &I) {
1152
- // Set up outgoing PHI node register values before emitting the terminator.
1153
- if (I.isTerminator ()) {
1154
- HandlePHINodesInSuccessorBlocks (I.getParent ());
1155
- }
1156
-
1151
+ void SelectionDAGBuilder::visitDbgInfo (const Instruction &I) {
1157
1152
// Add SDDbgValue nodes for any var locs here. Do so before updating
1158
1153
// SDNodeOrder, as this mapping is {Inst -> Locs BEFORE Inst}.
1159
1154
if (FunctionVarLocs const *FnVarLocs = DAG.getFunctionVarLocs ()) {
@@ -1169,10 +1164,56 @@ void SelectionDAGBuilder::visit(const Instruction &I) {
1169
1164
}
1170
1165
SmallVector<Value *> Values (It->Values .location_ops ());
1171
1166
if (!handleDebugValue (Values, Var, It->Expr , It->DL , SDNodeOrder,
1172
- It->Values .hasArgList ()))
1173
- addDanglingDebugInfo (It, SDNodeOrder);
1167
+ It->Values .hasArgList ())) {
1168
+ SmallVector<Value *, 4 > Vals;
1169
+ for (Value *V : It->Values .location_ops ())
1170
+ Vals.push_back (V);
1171
+ addDanglingDebugInfo (Vals,
1172
+ FnVarLocs->getDILocalVariable (It->VariableID ),
1173
+ It->Expr , Vals.size () > 1 , It->DL , SDNodeOrder);
1174
+ }
1175
+ }
1176
+ }
1177
+
1178
+ // Is there is any debug-info attached to this instruction, in the form of
1179
+ // DPValue non-instruction debug-info records.
1180
+ for (DPValue &DPV : I.getDbgValueRange ()) {
1181
+ DILocalVariable *Variable = DPV.getVariable ();
1182
+ DIExpression *Expression = DPV.getExpression ();
1183
+ dropDanglingDebugInfo (Variable, Expression);
1184
+
1185
+ // A DPValue with no locations is a kill location.
1186
+ SmallVector<Value *, 4 > Values (DPV.location_ops ());
1187
+ if (Values.empty ()) {
1188
+ handleKillDebugValue (Variable, Expression, DPV.getDebugLoc (),
1189
+ SDNodeOrder);
1190
+ continue ;
1191
+ }
1192
+
1193
+ // A DPValue with an undef or absent location is also a kill location.
1194
+ if (llvm::any_of (Values,
1195
+ [](Value *V) { return !V || isa<UndefValue>(V); })) {
1196
+ handleKillDebugValue (Variable, Expression, DPV.getDebugLoc (),
1197
+ SDNodeOrder);
1198
+ continue ;
1199
+ }
1200
+
1201
+ bool IsVariadic = DPV.hasArgList ();
1202
+ if (!handleDebugValue (Values, Variable, Expression, DPV.getDebugLoc (),
1203
+ SDNodeOrder, IsVariadic)) {
1204
+ addDanglingDebugInfo (Values, Variable, Expression, IsVariadic,
1205
+ DPV.getDebugLoc (), SDNodeOrder);
1174
1206
}
1175
1207
}
1208
+ }
1209
+
1210
+ void SelectionDAGBuilder::visit (const Instruction &I) {
1211
+ visitDbgInfo (I);
1212
+
1213
+ // Set up outgoing PHI node register values before emitting the terminator.
1214
+ if (I.isTerminator ()) {
1215
+ HandlePHINodesInSuccessorBlocks (I.getParent ());
1216
+ }
1176
1217
1177
1218
// Increase the SDNodeOrder if dealing with a non-debug instruction.
1178
1219
if (!isa<DbgInfoIntrinsic>(I))
@@ -1232,14 +1273,12 @@ void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) {
1232
1273
static bool handleDanglingVariadicDebugInfo (SelectionDAG &DAG,
1233
1274
DILocalVariable *Variable,
1234
1275
DebugLoc DL, unsigned Order,
1235
- RawLocationWrapper Values,
1276
+ SmallVectorImpl<Value *> & Values,
1236
1277
DIExpression *Expression) {
1237
- if (!Values.hasArgList ())
1238
- return false ;
1239
1278
// For variadic dbg_values we will now insert an undef.
1240
1279
// FIXME: We can potentially recover these!
1241
1280
SmallVector<SDDbgOperand, 2 > Locs;
1242
- for (const Value *V : Values. location_ops () ) {
1281
+ for (const Value *V : Values) {
1243
1282
auto *Undef = UndefValue::get (V->getType ());
1244
1283
Locs.push_back (SDDbgOperand::fromConst (Undef));
1245
1284
}
@@ -1250,44 +1289,31 @@ static bool handleDanglingVariadicDebugInfo(SelectionDAG &DAG,
1250
1289
return true ;
1251
1290
}
1252
1291
1253
- void SelectionDAGBuilder::addDanglingDebugInfo (const VarLocInfo *VarLoc,
1254
- unsigned Order) {
1255
- if (!handleDanglingVariadicDebugInfo (
1256
- DAG,
1257
- const_cast <DILocalVariable *>(DAG.getFunctionVarLocs ()
1258
- ->getVariable (VarLoc->VariableID )
1259
- .getVariable ()),
1260
- VarLoc->DL , Order, VarLoc->Values , VarLoc->Expr )) {
1261
- DanglingDebugInfoMap[VarLoc->Values .getVariableLocationOp (0 )].emplace_back (
1262
- VarLoc, Order);
1263
- }
1264
- }
1265
-
1266
- void SelectionDAGBuilder::addDanglingDebugInfo (const DbgValueInst *DI,
1292
+ void SelectionDAGBuilder::addDanglingDebugInfo (SmallVectorImpl<Value *> &Values,
1293
+ DILocalVariable *Var,
1294
+ DIExpression *Expr,
1295
+ bool IsVariadic, DebugLoc DL,
1267
1296
unsigned Order) {
1268
- // We treat variadic dbg_values differently at this stage.
1269
- if (!handleDanglingVariadicDebugInfo (
1270
- DAG, DI->getVariable (), DI->getDebugLoc (), Order,
1271
- DI->getWrappedLocation (), DI->getExpression ())) {
1272
- // TODO: Dangling debug info will eventually either be resolved or produce
1273
- // an Undef DBG_VALUE. However in the resolution case, a gap may appear
1274
- // between the original dbg.value location and its resolved DBG_VALUE,
1275
- // which we should ideally fill with an extra Undef DBG_VALUE.
1276
- assert (DI->getNumVariableLocationOps () == 1 &&
1277
- " DbgValueInst without an ArgList should have a single location "
1278
- " operand." );
1279
- DanglingDebugInfoMap[DI->getValue (0 )].emplace_back (DI, Order);
1297
+ if (IsVariadic) {
1298
+ handleDanglingVariadicDebugInfo (DAG, Var, DL, Order, Values, Expr);
1299
+ return ;
1280
1300
}
1301
+ // TODO: Dangling debug info will eventually either be resolved or produce
1302
+ // an Undef DBG_VALUE. However in the resolution case, a gap may appear
1303
+ // between the original dbg.value location and its resolved DBG_VALUE,
1304
+ // which we should ideally fill with an extra Undef DBG_VALUE.
1305
+ assert (Values.size () == 1 );
1306
+ DanglingDebugInfoMap[Values[0 ]].emplace_back (Var, Expr, DL, Order);
1281
1307
}
1282
1308
1283
1309
void SelectionDAGBuilder::dropDanglingDebugInfo (const DILocalVariable *Variable,
1284
1310
const DIExpression *Expr) {
1285
1311
auto isMatchingDbgValue = [&](DanglingDebugInfo &DDI) {
1286
- DIVariable *DanglingVariable = DDI.getVariable (DAG. getFunctionVarLocs () );
1312
+ DIVariable *DanglingVariable = DDI.getVariable ();
1287
1313
DIExpression *DanglingExpr = DDI.getExpression ();
1288
1314
if (DanglingVariable == Variable && Expr->fragmentsOverlap (DanglingExpr)) {
1289
- LLVM_DEBUG (dbgs () << " Dropping dangling debug info for " << printDDI (DDI)
1290
- << " \n " );
1315
+ LLVM_DEBUG (dbgs () << " Dropping dangling debug info for "
1316
+ << printDDI ( nullptr , DDI) << " \n " );
1291
1317
return true ;
1292
1318
}
1293
1319
return false ;
@@ -1300,7 +1326,7 @@ void SelectionDAGBuilder::dropDanglingDebugInfo(const DILocalVariable *Variable,
1300
1326
// whether it can be salvaged.
1301
1327
for (auto &DDI : DDIV)
1302
1328
if (isMatchingDbgValue (DDI))
1303
- salvageUnresolvedDbgValue (DDI);
1329
+ salvageUnresolvedDbgValue (DDIMI. first , DDI);
1304
1330
1305
1331
erase_if (DDIV, isMatchingDbgValue);
1306
1332
}
@@ -1319,7 +1345,7 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
1319
1345
DebugLoc DL = DDI.getDebugLoc ();
1320
1346
unsigned ValSDNodeOrder = Val.getNode ()->getIROrder ();
1321
1347
unsigned DbgSDNodeOrder = DDI.getSDNodeOrder ();
1322
- DILocalVariable *Variable = DDI.getVariable (DAG. getFunctionVarLocs () );
1348
+ DILocalVariable *Variable = DDI.getVariable ();
1323
1349
DIExpression *Expr = DDI.getExpression ();
1324
1350
assert (Variable->isValidLocationForIntrinsic (DL) &&
1325
1351
" Expected inlined-at fields to agree" );
@@ -1333,8 +1359,8 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
1333
1359
// calling EmitFuncArgumentDbgValue here.
1334
1360
if (!EmitFuncArgumentDbgValue (V, Variable, Expr, DL,
1335
1361
FuncArgumentDbgValueKind::Value, Val)) {
1336
- LLVM_DEBUG (dbgs () << " Resolve dangling debug info for " << printDDI (DDI)
1337
- << " \n " );
1362
+ LLVM_DEBUG (dbgs () << " Resolve dangling debug info for "
1363
+ << printDDI (V, DDI) << " \n " );
1338
1364
LLVM_DEBUG (dbgs () << " By mapping to:\n " ; Val.dump ());
1339
1365
// Increase the SDNodeOrder for the DbgValue here to make sure it is
1340
1366
// inserted after the definition of Val when emitting the instructions
@@ -1348,9 +1374,11 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
1348
1374
DAG.AddDbgValue (SDV, false );
1349
1375
} else
1350
1376
LLVM_DEBUG (dbgs () << " Resolved dangling debug info for "
1351
- << printDDI (DDI) << " in EmitFuncArgumentDbgValue\n " );
1377
+ << printDDI (V, DDI)
1378
+ << " in EmitFuncArgumentDbgValue\n " );
1352
1379
} else {
1353
- LLVM_DEBUG (dbgs () << " Dropping debug info for " << printDDI (DDI) << " \n " );
1380
+ LLVM_DEBUG (dbgs () << " Dropping debug info for " << printDDI (V, DDI)
1381
+ << " \n " );
1354
1382
auto Undef = UndefValue::get (V->getType ());
1355
1383
auto SDV =
1356
1384
DAG.getConstantDbgValue (Variable, Expr, Undef, DL, DbgSDNodeOrder);
@@ -1360,14 +1388,14 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
1360
1388
DDIV.clear ();
1361
1389
}
1362
1390
1363
- void SelectionDAGBuilder::salvageUnresolvedDbgValue (DanglingDebugInfo &DDI) {
1391
+ void SelectionDAGBuilder::salvageUnresolvedDbgValue (const Value *V,
1392
+ DanglingDebugInfo &DDI) {
1364
1393
// TODO: For the variadic implementation, instead of only checking the fail
1365
1394
// state of `handleDebugValue`, we need know specifically which values were
1366
1395
// invalid, so that we attempt to salvage only those values when processing
1367
1396
// a DIArgList.
1368
- Value *V = DDI.getVariableLocationOp (0 );
1369
- Value *OrigV = V;
1370
- DILocalVariable *Var = DDI.getVariable (DAG.getFunctionVarLocs ());
1397
+ const Value *OrigV = V;
1398
+ DILocalVariable *Var = DDI.getVariable ();
1371
1399
DIExpression *Expr = DDI.getExpression ();
1372
1400
DebugLoc DL = DDI.getDebugLoc ();
1373
1401
unsigned SDOrder = DDI.getSDNodeOrder ();
@@ -1384,11 +1412,12 @@ void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) {
1384
1412
// a non-instruction is seen, such as a constant expression or global
1385
1413
// variable. FIXME: Further work could recover those too.
1386
1414
while (isa<Instruction>(V)) {
1387
- Instruction &VAsInst = *cast<Instruction>(V);
1415
+ const Instruction &VAsInst = *cast<const Instruction>(V);
1388
1416
// Temporary "0", awaiting real implementation.
1389
1417
SmallVector<uint64_t , 16 > Ops;
1390
1418
SmallVector<Value *, 4 > AdditionalValues;
1391
- V = salvageDebugInfoImpl (VAsInst, Expr->getNumLocationOperands (), Ops,
1419
+ V = salvageDebugInfoImpl (const_cast <Instruction &>(VAsInst),
1420
+ Expr->getNumLocationOperands (), Ops,
1392
1421
AdditionalValues);
1393
1422
// If we cannot salvage any further, and haven't yet found a suitable debug
1394
1423
// expression, bail out.
@@ -1421,8 +1450,8 @@ void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) {
1421
1450
auto *Undef = UndefValue::get (OrigV->getType ());
1422
1451
auto *SDV = DAG.getConstantDbgValue (Var, Expr, Undef, DL, SDNodeOrder);
1423
1452
DAG.AddDbgValue (SDV, false );
1424
- LLVM_DEBUG (dbgs () << " Dropping debug value info for:\n " << printDDI (DDI)
1425
- << " \n " );
1453
+ LLVM_DEBUG (dbgs () << " Dropping debug value info for:\n "
1454
+ << printDDI (OrigV, DDI) << " \n " );
1426
1455
}
1427
1456
1428
1457
void SelectionDAGBuilder::handleKillDebugValue (DILocalVariable *Var,
@@ -1572,7 +1601,7 @@ void SelectionDAGBuilder::resolveOrClearDbgInfo() {
1572
1601
// Try to fixup any remaining dangling debug info -- and drop it if we can't.
1573
1602
for (auto &Pair : DanglingDebugInfoMap)
1574
1603
for (auto &DDI : Pair.second )
1575
- salvageUnresolvedDbgValue (DDI);
1604
+ salvageUnresolvedDbgValue (const_cast <Value *>(Pair. first ), DDI);
1576
1605
clearDanglingDebugInfo ();
1577
1606
}
1578
1607
@@ -6315,7 +6344,8 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
6315
6344
bool IsVariadic = DI.hasArgList ();
6316
6345
if (!handleDebugValue (Values, Variable, Expression, DI.getDebugLoc (),
6317
6346
SDNodeOrder, IsVariadic))
6318
- addDanglingDebugInfo (&DI, SDNodeOrder);
6347
+ addDanglingDebugInfo (Values, Variable, Expression, IsVariadic,
6348
+ DI.getDebugLoc (), SDNodeOrder);
6319
6349
return ;
6320
6350
}
6321
6351
0 commit comments