@@ -315,18 +315,11 @@ calculateFragment(DILocalVariable *Variable,
315
315
return UseFrag;
316
316
}
317
317
318
- static DebugVariable getAggregateVariable (DbgVariableIntrinsic *DVI) {
319
- return DebugVariable (DVI->getVariable (), std::nullopt,
320
- DVI->getDebugLoc ().getInlinedAt ());
321
- }
322
318
static DebugVariable getAggregateVariable (DbgVariableRecord *DVR) {
323
319
return DebugVariable (DVR->getVariable (), std::nullopt,
324
320
DVR->getDebugLoc ().getInlinedAt ());
325
321
}
326
322
327
- // / Helpers for handling new and old debug info modes in migrateDebugInfo.
328
- // / These overloads unwrap a DbgInstPtr {Instruction* | DbgRecord*} union based
329
- // / on the \p Unused parameter type.
330
323
DbgVariableRecord *UnwrapDbgInstPtr (DbgInstPtr P, DbgVariableRecord *Unused) {
331
324
(void )Unused;
332
325
return static_cast <DbgVariableRecord *>(cast<DbgRecord *>(P));
@@ -376,9 +369,6 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
376
369
// / Map of aggregate variables to their fragment associated with OldAlloca.
377
370
DenseMap<DebugVariable, std::optional<DIExpression::FragmentInfo>>
378
371
BaseFragments;
379
- for (auto *DAI : at::getAssignmentMarkers (OldAlloca))
380
- BaseFragments[getAggregateVariable (DAI)] =
381
- DAI->getExpression ()->getFragmentInfo ();
382
372
for (auto *DVR : at::getDVRAssignmentMarkers (OldAlloca))
383
373
BaseFragments[getAggregateVariable (DVR)] =
384
374
DVR->getExpression ()->getFragmentInfo ();
@@ -391,7 +381,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
391
381
DIBuilder DIB (*OldInst->getModule (), /* AllowUnresolved*/ false );
392
382
assert (OldAlloca->isStaticAlloca ());
393
383
394
- auto MigrateDbgAssign = [&](auto *DbgAssign) {
384
+ auto MigrateDbgAssign = [&](DbgVariableRecord *DbgAssign) {
395
385
LLVM_DEBUG (dbgs () << " existing dbg.assign is: " << *DbgAssign
396
386
<< " \n " );
397
387
auto *Expr = DbgAssign->getExpression ();
@@ -486,7 +476,6 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
486
476
LLVM_DEBUG (dbgs () << " Created new assign: " << *NewAssign << " \n " );
487
477
};
488
478
489
- for_each (MarkerRange, MigrateDbgAssign);
490
479
for_each (DVRAssignMarkerRange, MigrateDbgAssign);
491
480
}
492
481
@@ -5119,36 +5108,13 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
5119
5108
}
5120
5109
5121
5110
// There isn't a shared interface to get the "address" parts out of a
5122
- // dbg.declare and dbg.assign, so provide some wrappers now for
5123
- // both debug intrinsics and records.
5124
- const Value *getAddress (const DbgVariableIntrinsic *DVI) {
5125
- if (const auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI))
5126
- return DAI->getAddress ();
5127
- return cast<DbgDeclareInst>(DVI)->getAddress ();
5128
- }
5129
-
5130
- const Value *getAddress (const DbgVariableRecord *DVR) {
5131
- return DVR->getAddress ();
5132
- }
5133
-
5134
- bool isKillAddress (const DbgVariableIntrinsic *DVI) {
5135
- if (const auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI))
5136
- return DAI->isKillAddress ();
5137
- return cast<DbgDeclareInst>(DVI)->isKillLocation ();
5138
- }
5139
-
5111
+ // dbg.declare and dbg.assign, so provide some wrappers.
5140
5112
bool isKillAddress (const DbgVariableRecord *DVR) {
5141
5113
if (DVR->getType () == DbgVariableRecord::LocationType::Assign)
5142
5114
return DVR->isKillAddress ();
5143
5115
return DVR->isKillLocation ();
5144
5116
}
5145
5117
5146
- const DIExpression *getAddressExpression (const DbgVariableIntrinsic *DVI) {
5147
- if (const auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI))
5148
- return DAI->getAddressExpression ();
5149
- return cast<DbgDeclareInst>(DVI)->getExpression ();
5150
- }
5151
-
5152
5118
const DIExpression *getAddressExpression (const DbgVariableRecord *DVR) {
5153
5119
if (DVR->getType () == DbgVariableRecord::LocationType::Assign)
5154
5120
return DVR->getAddressExpression ();
@@ -5236,66 +5202,6 @@ static DIExpression *createOrReplaceFragment(const DIExpression *Expr,
5236
5202
return DIExpression::get (Expr->getContext (), Ops);
5237
5203
}
5238
5204
5239
- // / Insert a new dbg.declare.
5240
- // / \p Orig Original to copy debug loc and variable from.
5241
- // / \p NewAddr Location's new base address.
5242
- // / \p NewAddrExpr New expression to apply to address.
5243
- // / \p BeforeInst Insert position.
5244
- // / \p NewFragment New fragment (absolute, non-relative).
5245
- // / \p BitExtractAdjustment Offset to apply to any extract_bits op.
5246
- static void
5247
- insertNewDbgInst (DIBuilder &DIB, DbgDeclareInst *Orig, AllocaInst *NewAddr,
5248
- DIExpression *NewAddrExpr, Instruction *BeforeInst,
5249
- std::optional<DIExpression::FragmentInfo> NewFragment,
5250
- int64_t BitExtractAdjustment) {
5251
- if (NewFragment)
5252
- NewAddrExpr = createOrReplaceFragment (NewAddrExpr, *NewFragment,
5253
- BitExtractAdjustment);
5254
- if (!NewAddrExpr)
5255
- return ;
5256
-
5257
- DIB.insertDeclare (NewAddr, Orig->getVariable (), NewAddrExpr,
5258
- Orig->getDebugLoc (), BeforeInst->getIterator ());
5259
- }
5260
-
5261
- // / Insert a new dbg.assign.
5262
- // / \p Orig Original to copy debug loc, variable, value and value expression
5263
- // / from.
5264
- // / \p NewAddr Location's new base address.
5265
- // / \p NewAddrExpr New expression to apply to address.
5266
- // / \p BeforeInst Insert position.
5267
- // / \p NewFragment New fragment (absolute, non-relative).
5268
- // / \p BitExtractAdjustment Offset to apply to any extract_bits op.
5269
- static void
5270
- insertNewDbgInst (DIBuilder &DIB, DbgAssignIntrinsic *Orig, AllocaInst *NewAddr,
5271
- DIExpression *NewAddrExpr, Instruction *BeforeInst,
5272
- std::optional<DIExpression::FragmentInfo> NewFragment,
5273
- int64_t BitExtractAdjustment) {
5274
- // DIBuilder::insertDbgAssign will insert the #dbg_assign after NewAddr.
5275
- (void )BeforeInst;
5276
-
5277
- // A dbg.assign puts fragment info in the value expression only. The address
5278
- // expression has already been built: NewAddrExpr.
5279
- DIExpression *NewFragmentExpr = Orig->getExpression ();
5280
- if (NewFragment)
5281
- NewFragmentExpr = createOrReplaceFragment (NewFragmentExpr, *NewFragment,
5282
- BitExtractAdjustment);
5283
- if (!NewFragmentExpr)
5284
- return ;
5285
-
5286
- // Apply a DIAssignID to the store if it doesn't already have it.
5287
- if (!NewAddr->hasMetadata (LLVMContext::MD_DIAssignID)) {
5288
- NewAddr->setMetadata (LLVMContext::MD_DIAssignID,
5289
- DIAssignID::getDistinct (NewAddr->getContext ()));
5290
- }
5291
-
5292
- Instruction *NewAssign = cast<Instruction *>(DIB.insertDbgAssign (
5293
- NewAddr, Orig->getValue (), Orig->getVariable (), NewFragmentExpr, NewAddr,
5294
- NewAddrExpr, Orig->getDebugLoc ()));
5295
- LLVM_DEBUG (dbgs () << " Created new assign intrinsic: " << *NewAssign << " \n " );
5296
- (void )NewAssign;
5297
- }
5298
-
5299
5205
// / Insert a new DbgRecord.
5300
5206
// / \p Orig Original to copy record type, debug loc and variable from, and
5301
5207
// / additionally value and value expression for dbg_assign records.
@@ -5457,12 +5363,12 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
5457
5363
5458
5364
// Migrate debug information from the old alloca to the new alloca(s)
5459
5365
// and the individual partitions.
5460
- auto MigrateOne = [&](auto *DbgVariable) {
5366
+ auto MigrateOne = [&](DbgVariableRecord *DbgVariable) {
5461
5367
// Can't overlap with undef memory.
5462
5368
if (isKillAddress (DbgVariable))
5463
5369
return ;
5464
5370
5465
- const Value *DbgPtr = getAddress (DbgVariable );
5371
+ const Value *DbgPtr = DbgVariable-> getAddress ();
5466
5372
DIExpression::FragmentInfo VarFrag =
5467
5373
DbgVariable->getFragmentOrEntireVariable ();
5468
5374
// Get the address expression constant offset if one exists and the ops
@@ -5543,7 +5449,6 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
5543
5449
if (SameVariableFragment (OldDII, DbgVariable))
5544
5450
OldDII->eraseFromParent ();
5545
5451
};
5546
- for_each (findDbgDeclares (Fragment.Alloca ), RemoveOne);
5547
5452
for_each (findDVRDeclares (Fragment.Alloca ), RemoveOne);
5548
5453
for_each (findDVRValues (Fragment.Alloca ), RemoveOne);
5549
5454
insertNewDbgInst (DIB, DbgVariable, Fragment.Alloca , NewExpr, &AI,
@@ -5553,10 +5458,8 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
5553
5458
5554
5459
// Migrate debug information from the old alloca to the new alloca(s)
5555
5460
// and the individual partitions.
5556
- for_each (findDbgDeclares (&AI), MigrateOne);
5557
5461
for_each (findDVRDeclares (&AI), MigrateOne);
5558
5462
for_each (findDVRValues (&AI), MigrateOne);
5559
- for_each (at::getAssignmentMarkers (&AI), MigrateOne);
5560
5463
for_each (at::getDVRAssignmentMarkers (&AI), MigrateOne);
5561
5464
5562
5465
return Changed;
@@ -5777,8 +5680,6 @@ bool SROA::deleteDeadInstructions(
5777
5680
// not be able to find it.
5778
5681
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
5779
5682
DeletedAllocas.insert (AI);
5780
- for (DbgDeclareInst *OldDII : findDbgDeclares (AI))
5781
- OldDII->eraseFromParent ();
5782
5683
for (DbgVariableRecord *OldDII : findDVRDeclares (AI))
5783
5684
OldDII->eraseFromParent ();
5784
5685
}
0 commit comments