@@ -1185,6 +1185,98 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
1185
1185
DDIV.clear ();
1186
1186
}
1187
1187
1188
+ bool SelectionDAGBuilder::handleDebugValue (const Value *V, DILocalVariable *Var,
1189
+ DIExpression *Expr, DebugLoc dl,
1190
+ DebugLoc InstDL, unsigned Order) {
1191
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo ();
1192
+ SDDbgValue *SDV;
1193
+ if (isa<ConstantInt>(V) || isa<ConstantFP>(V) || isa<UndefValue>(V) ||
1194
+ isa<ConstantPointerNull>(V)) {
1195
+ SDV = DAG.getConstantDbgValue (Var, Expr, V, dl, SDNodeOrder);
1196
+ DAG.AddDbgValue (SDV, nullptr , false );
1197
+ return true ;
1198
+ }
1199
+
1200
+ // If the Value is a frame index, we can create a FrameIndex debug value
1201
+ // without relying on the DAG at all.
1202
+ if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1203
+ auto SI = FuncInfo.StaticAllocaMap .find (AI);
1204
+ if (SI != FuncInfo.StaticAllocaMap .end ()) {
1205
+ auto SDV =
1206
+ DAG.getFrameIndexDbgValue (Var, Expr, SI->second ,
1207
+ /* IsIndirect*/ false , dl, SDNodeOrder);
1208
+ // Do not attach the SDNodeDbgValue to an SDNode: this variable location
1209
+ // is still available even if the SDNode gets optimized out.
1210
+ DAG.AddDbgValue (SDV, nullptr , false );
1211
+ return true ;
1212
+ }
1213
+ }
1214
+
1215
+ // Do not use getValue() in here; we don't want to generate code at
1216
+ // this point if it hasn't been done yet.
1217
+ SDValue N = NodeMap[V];
1218
+ if (!N.getNode () && isa<Argument>(V)) // Check unused arguments map.
1219
+ N = UnusedArgNodeMap[V];
1220
+ if (N.getNode ()) {
1221
+ if (EmitFuncArgumentDbgValue (V, Var, Expr, dl, false , N))
1222
+ return true ;
1223
+ SDV = getDbgValue (N, Var, Expr, dl, SDNodeOrder);
1224
+ DAG.AddDbgValue (SDV, N.getNode (), false );
1225
+ return true ;
1226
+ }
1227
+
1228
+ // Special rules apply for the first dbg.values of parameter variables in a
1229
+ // function. Identify them by the fact they reference Argument Values, that
1230
+ // they're parameters, and they are parameters of the current function. We
1231
+ // need to let them dangle until they get an SDNode.
1232
+ bool IsParamOfFunc = isa<Argument>(V) && Var->isParameter () &&
1233
+ !InstDL.getInlinedAt ();
1234
+ if (!IsParamOfFunc) {
1235
+ // The value is not used in this block yet (or it would have an SDNode).
1236
+ // We still want the value to appear for the user if possible -- if it has
1237
+ // an associated VReg, we can refer to that instead.
1238
+ auto VMI = FuncInfo.ValueMap .find (V);
1239
+ if (VMI != FuncInfo.ValueMap .end ()) {
1240
+ unsigned Reg = VMI->second ;
1241
+ // If this is a PHI node, it may be split up into several MI PHI nodes
1242
+ // (in FunctionLoweringInfo::set).
1243
+ RegsForValue RFV (V->getContext (), TLI, DAG.getDataLayout (), Reg,
1244
+ V->getType (), None);
1245
+ if (RFV.occupiesMultipleRegs ()) {
1246
+ unsigned Offset = 0 ;
1247
+ unsigned BitsToDescribe = 0 ;
1248
+ if (auto VarSize = Var->getSizeInBits ())
1249
+ BitsToDescribe = *VarSize;
1250
+ if (auto Fragment = Expr->getFragmentInfo ())
1251
+ BitsToDescribe = Fragment->SizeInBits ;
1252
+ for (auto RegAndSize : RFV.getRegsAndSizes ()) {
1253
+ unsigned RegisterSize = RegAndSize.second ;
1254
+ // Bail out if all bits are described already.
1255
+ if (Offset >= BitsToDescribe)
1256
+ break ;
1257
+ unsigned FragmentSize = (Offset + RegisterSize > BitsToDescribe)
1258
+ ? BitsToDescribe - Offset
1259
+ : RegisterSize;
1260
+ auto FragmentExpr = DIExpression::createFragmentExpression (
1261
+ Expr, Offset, FragmentSize);
1262
+ if (!FragmentExpr)
1263
+ continue ;
1264
+ SDV = DAG.getVRegDbgValue (Var, *FragmentExpr, RegAndSize.first ,
1265
+ false , dl, SDNodeOrder);
1266
+ DAG.AddDbgValue (SDV, nullptr , false );
1267
+ Offset += RegisterSize;
1268
+ }
1269
+ } else {
1270
+ SDV = DAG.getVRegDbgValue (Var, Expr, Reg, false , dl, SDNodeOrder);
1271
+ DAG.AddDbgValue (SDV, nullptr , false );
1272
+ }
1273
+ return true ;
1274
+ }
1275
+ }
1276
+
1277
+ return false ;
1278
+ }
1279
+
1188
1280
// / getCopyFromRegs - If there was virtual register allocated for the value V
1189
1281
// / emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise.
1190
1282
SDValue SelectionDAGBuilder::getCopyFromRegs (const Value *V, Type *Ty) {
@@ -5456,91 +5548,9 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
5456
5548
if (!V)
5457
5549
return nullptr ;
5458
5550
5459
- SDDbgValue *SDV;
5460
- if (isa<ConstantInt>(V) || isa<ConstantFP>(V) || isa<UndefValue>(V) ||
5461
- isa<ConstantPointerNull>(V)) {
5462
- SDV = DAG.getConstantDbgValue (Variable, Expression, V, dl, SDNodeOrder);
5463
- DAG.AddDbgValue (SDV, nullptr , false );
5551
+ if (handleDebugValue (V, Variable, Expression, DI.getDebugLoc (), dl,
5552
+ SDNodeOrder))
5464
5553
return nullptr ;
5465
- }
5466
-
5467
- // If the Value is a frame index, we can create a FrameIndex debug value
5468
- // without relying on the DAG at all.
5469
- if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
5470
- auto SI = FuncInfo.StaticAllocaMap .find (AI);
5471
- if (SI != FuncInfo.StaticAllocaMap .end ()) {
5472
- auto SDV =
5473
- DAG.getFrameIndexDbgValue (Variable, Expression, SI->second ,
5474
- /* IsIndirect*/ false , dl, SDNodeOrder);
5475
- // Do not attach the SDNodeDbgValue to an SDNode: this variable location
5476
- // is still available even if the SDNode gets optimized out.
5477
- DAG.AddDbgValue (SDV, nullptr , false );
5478
- return nullptr ;
5479
- }
5480
- }
5481
-
5482
- // Do not use getValue() in here; we don't want to generate code at
5483
- // this point if it hasn't been done yet.
5484
- SDValue N = NodeMap[V];
5485
- if (!N.getNode () && isa<Argument>(V)) // Check unused arguments map.
5486
- N = UnusedArgNodeMap[V];
5487
- if (N.getNode ()) {
5488
- if (EmitFuncArgumentDbgValue (V, Variable, Expression, dl, false , N))
5489
- return nullptr ;
5490
- SDV = getDbgValue (N, Variable, Expression, dl, SDNodeOrder);
5491
- DAG.AddDbgValue (SDV, N.getNode (), false );
5492
- return nullptr ;
5493
- }
5494
-
5495
- // Special rules apply for the first dbg.values of parameter variables in a
5496
- // function. Identify them by the fact they reference Argument Values, that
5497
- // they're parameters, and they are parameters of the current function. We
5498
- // need to let them dangle until they get an SDNode.
5499
- bool IsParamOfFunc = isa<Argument>(V) && Variable->isParameter () &&
5500
- !DI.getDebugLoc ()->getInlinedAt ();
5501
- if (!IsParamOfFunc) {
5502
- // The value is not used in this block yet (or it would have an SDNode).
5503
- // We still want the value to appear for the user if possible -- if it has
5504
- // an associated VReg, we can refer to that instead.
5505
- auto VMI = FuncInfo.ValueMap .find (V);
5506
- if (VMI != FuncInfo.ValueMap .end ()) {
5507
- unsigned Reg = VMI->second ;
5508
- // If this is a PHI node, it may be split up into several MI PHI nodes
5509
- // (in FunctionLoweringInfo::set).
5510
- RegsForValue RFV (V->getContext (), TLI, DAG.getDataLayout (), Reg,
5511
- V->getType (), None);
5512
- if (RFV.occupiesMultipleRegs ()) {
5513
- unsigned Offset = 0 ;
5514
- unsigned BitsToDescribe = 0 ;
5515
- if (auto VarSize = Variable->getSizeInBits ())
5516
- BitsToDescribe = *VarSize;
5517
- if (auto Fragment = Expression->getFragmentInfo ())
5518
- BitsToDescribe = Fragment->SizeInBits ;
5519
- for (auto RegAndSize : RFV.getRegsAndSizes ()) {
5520
- unsigned RegisterSize = RegAndSize.second ;
5521
- // Bail out if all bits are described already.
5522
- if (Offset >= BitsToDescribe)
5523
- break ;
5524
- unsigned FragmentSize = (Offset + RegisterSize > BitsToDescribe)
5525
- ? BitsToDescribe - Offset
5526
- : RegisterSize;
5527
- auto FragmentExpr = DIExpression::createFragmentExpression (
5528
- Expression, Offset, FragmentSize);
5529
- if (!FragmentExpr)
5530
- continue ;
5531
- SDV = DAG.getVRegDbgValue (Variable, *FragmentExpr, RegAndSize.first ,
5532
- false , dl, SDNodeOrder);
5533
- DAG.AddDbgValue (SDV, nullptr , false );
5534
- Offset += RegisterSize;
5535
- }
5536
- } else {
5537
- SDV = DAG.getVRegDbgValue (Variable, Expression, Reg, false , dl,
5538
- SDNodeOrder);
5539
- DAG.AddDbgValue (SDV, nullptr , false );
5540
- }
5541
- return nullptr ;
5542
- }
5543
- }
5544
5554
5545
5555
// TODO: When we get here we will either drop the dbg.value completely, or
5546
5556
// we try to move it forward by letting it dangle for awhile. So we should
0 commit comments