@@ -315,18 +315,11 @@ calculateFragment(DILocalVariable *Variable,
315315 return UseFrag;
316316}
317317
318- static DebugVariable getAggregateVariable (DbgVariableIntrinsic *DVI) {
319- return DebugVariable (DVI->getVariable (), std::nullopt ,
320- DVI->getDebugLoc ().getInlinedAt ());
321- }
322318static DebugVariable getAggregateVariable (DbgVariableRecord *DVR) {
323319 return DebugVariable (DVR->getVariable (), std::nullopt ,
324320 DVR->getDebugLoc ().getInlinedAt ());
325321}
326322
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.
330323DbgVariableRecord *UnwrapDbgInstPtr (DbgInstPtr P, DbgVariableRecord *Unused) {
331324 (void )Unused;
332325 return static_cast <DbgVariableRecord *>(cast<DbgRecord *>(P));
@@ -376,9 +369,6 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
376369 // / Map of aggregate variables to their fragment associated with OldAlloca.
377370 DenseMap<DebugVariable, std::optional<DIExpression::FragmentInfo>>
378371 BaseFragments;
379- for (auto *DAI : at::getAssignmentMarkers (OldAlloca))
380- BaseFragments[getAggregateVariable (DAI)] =
381- DAI->getExpression ()->getFragmentInfo ();
382372 for (auto *DVR : at::getDVRAssignmentMarkers (OldAlloca))
383373 BaseFragments[getAggregateVariable (DVR)] =
384374 DVR->getExpression ()->getFragmentInfo ();
@@ -391,7 +381,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
391381 DIBuilder DIB (*OldInst->getModule (), /* AllowUnresolved*/ false );
392382 assert (OldAlloca->isStaticAlloca ());
393383
394- auto MigrateDbgAssign = [&](auto *DbgAssign) {
384+ auto MigrateDbgAssign = [&](DbgVariableRecord *DbgAssign) {
395385 LLVM_DEBUG (dbgs () << " existing dbg.assign is: " << *DbgAssign
396386 << " \n " );
397387 auto *Expr = DbgAssign->getExpression ();
@@ -486,7 +476,6 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
486476 LLVM_DEBUG (dbgs () << " Created new assign: " << *NewAssign << " \n " );
487477 };
488478
489- for_each (MarkerRange, MigrateDbgAssign);
490479 for_each (DVRAssignMarkerRange, MigrateDbgAssign);
491480}
492481
@@ -5119,36 +5108,13 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
51195108}
51205109
51215110// 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.
51405112bool isKillAddress (const DbgVariableRecord *DVR) {
51415113 if (DVR->getType () == DbgVariableRecord::LocationType::Assign)
51425114 return DVR->isKillAddress ();
51435115 return DVR->isKillLocation ();
51445116}
51455117
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-
51525118const DIExpression *getAddressExpression (const DbgVariableRecord *DVR) {
51535119 if (DVR->getType () == DbgVariableRecord::LocationType::Assign)
51545120 return DVR->getAddressExpression ();
@@ -5245,66 +5211,6 @@ static DIExpression *createOrReplaceFragment(const DIExpression *Expr,
52455211 return DIExpression::get (Expr->getContext (), Ops);
52465212}
52475213
5248- // / Insert a new dbg.declare.
5249- // / \p Orig Original to copy debug loc and variable from.
5250- // / \p NewAddr Location's new base address.
5251- // / \p NewAddrExpr New expression to apply to address.
5252- // / \p BeforeInst Insert position.
5253- // / \p NewFragment New fragment (absolute, non-relative).
5254- // / \p BitExtractAdjustment Offset to apply to any extract_bits op.
5255- static void
5256- insertNewDbgInst (DIBuilder &DIB, DbgDeclareInst *Orig, AllocaInst *NewAddr,
5257- DIExpression *NewAddrExpr, Instruction *BeforeInst,
5258- std::optional<DIExpression::FragmentInfo> NewFragment,
5259- int64_t BitExtractAdjustment) {
5260- if (NewFragment)
5261- NewAddrExpr = createOrReplaceFragment (NewAddrExpr, *NewFragment,
5262- BitExtractAdjustment);
5263- if (!NewAddrExpr)
5264- return ;
5265-
5266- DIB.insertDeclare (NewAddr, Orig->getVariable (), NewAddrExpr,
5267- Orig->getDebugLoc (), BeforeInst->getIterator ());
5268- }
5269-
5270- // / Insert a new dbg.assign.
5271- // / \p Orig Original to copy debug loc, variable, value and value expression
5272- // / from.
5273- // / \p NewAddr Location's new base address.
5274- // / \p NewAddrExpr New expression to apply to address.
5275- // / \p BeforeInst Insert position.
5276- // / \p NewFragment New fragment (absolute, non-relative).
5277- // / \p BitExtractAdjustment Offset to apply to any extract_bits op.
5278- static void
5279- insertNewDbgInst (DIBuilder &DIB, DbgAssignIntrinsic *Orig, AllocaInst *NewAddr,
5280- DIExpression *NewAddrExpr, Instruction *BeforeInst,
5281- std::optional<DIExpression::FragmentInfo> NewFragment,
5282- int64_t BitExtractAdjustment) {
5283- // DIBuilder::insertDbgAssign will insert the #dbg_assign after NewAddr.
5284- (void )BeforeInst;
5285-
5286- // A dbg.assign puts fragment info in the value expression only. The address
5287- // expression has already been built: NewAddrExpr.
5288- DIExpression *NewFragmentExpr = Orig->getExpression ();
5289- if (NewFragment)
5290- NewFragmentExpr = createOrReplaceFragment (NewFragmentExpr, *NewFragment,
5291- BitExtractAdjustment);
5292- if (!NewFragmentExpr)
5293- return ;
5294-
5295- // Apply a DIAssignID to the store if it doesn't already have it.
5296- if (!NewAddr->hasMetadata (LLVMContext::MD_DIAssignID)) {
5297- NewAddr->setMetadata (LLVMContext::MD_DIAssignID,
5298- DIAssignID::getDistinct (NewAddr->getContext ()));
5299- }
5300-
5301- Instruction *NewAssign = cast<Instruction *>(DIB.insertDbgAssign (
5302- NewAddr, Orig->getValue (), Orig->getVariable (), NewFragmentExpr, NewAddr,
5303- NewAddrExpr, Orig->getDebugLoc ()));
5304- LLVM_DEBUG (dbgs () << " Created new assign intrinsic: " << *NewAssign << " \n " );
5305- (void )NewAssign;
5306- }
5307-
53085214// / Insert a new DbgRecord.
53095215// / \p Orig Original to copy record type, debug loc and variable from, and
53105216// / additionally value and value expression for dbg_assign records.
@@ -5479,12 +5385,12 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
54795385
54805386 // Migrate debug information from the old alloca to the new alloca(s)
54815387 // and the individual partitions.
5482- auto MigrateOne = [&](auto *DbgVariable) {
5388+ auto MigrateOne = [&](DbgVariableRecord *DbgVariable) {
54835389 // Can't overlap with undef memory.
54845390 if (isKillAddress (DbgVariable))
54855391 return ;
54865392
5487- const Value *DbgPtr = getAddress (DbgVariable );
5393+ const Value *DbgPtr = DbgVariable-> getAddress ();
54885394 DIExpression::FragmentInfo VarFrag =
54895395 DbgVariable->getFragmentOrEntireVariable ();
54905396 // Get the address expression constant offset if one exists and the ops
@@ -5572,7 +5478,6 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
55725478 if (SameVariableFragment (OldDII, DbgVariable))
55735479 OldDII->eraseFromParent ();
55745480 };
5575- for_each (findDbgDeclares (Fragment.Alloca ), RemoveOne);
55765481 for_each (findDVRDeclares (Fragment.Alloca ), RemoveOne);
55775482 for_each (findDVRValues (Fragment.Alloca ), RemoveOne);
55785483 insertNewDbgInst (DIB, DbgVariable, Fragment.Alloca , NewExpr, &AI,
@@ -5582,10 +5487,8 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
55825487
55835488 // Migrate debug information from the old alloca to the new alloca(s)
55845489 // and the individual partitions.
5585- for_each (findDbgDeclares (&AI), MigrateOne);
55865490 for_each (findDVRDeclares (&AI), MigrateOne);
55875491 for_each (findDVRValues (&AI), MigrateOne);
5588- for_each (at::getAssignmentMarkers (&AI), MigrateOne);
55895492 for_each (at::getDVRAssignmentMarkers (&AI), MigrateOne);
55905493
55915494 return Changed;
@@ -5806,8 +5709,6 @@ bool SROA::deleteDeadInstructions(
58065709 // not be able to find it.
58075710 if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
58085711 DeletedAllocas.insert (AI);
5809- for (DbgDeclareInst *OldDII : findDbgDeclares (AI))
5810- OldDII->eraseFromParent ();
58115712 for (DbgVariableRecord *OldDII : findDVRDeclares (AI))
58125713 OldDII->eraseFromParent ();
58135714 }
0 commit comments