@@ -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 ();
@@ -5236,66 +5202,6 @@ static DIExpression *createOrReplaceFragment(const DIExpression *Expr,
52365202 return DIExpression::get (Expr->getContext (), Ops);
52375203}
52385204
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-
52995205// / Insert a new DbgRecord.
53005206// / \p Orig Original to copy record type, debug loc and variable from, and
53015207// / additionally value and value expression for dbg_assign records.
@@ -5457,12 +5363,12 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
54575363
54585364 // Migrate debug information from the old alloca to the new alloca(s)
54595365 // and the individual partitions.
5460- auto MigrateOne = [&](auto *DbgVariable) {
5366+ auto MigrateOne = [&](DbgVariableRecord *DbgVariable) {
54615367 // Can't overlap with undef memory.
54625368 if (isKillAddress (DbgVariable))
54635369 return ;
54645370
5465- const Value *DbgPtr = getAddress (DbgVariable );
5371+ const Value *DbgPtr = DbgVariable-> getAddress ();
54665372 DIExpression::FragmentInfo VarFrag =
54675373 DbgVariable->getFragmentOrEntireVariable ();
54685374 // Get the address expression constant offset if one exists and the ops
@@ -5543,7 +5449,6 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
55435449 if (SameVariableFragment (OldDII, DbgVariable))
55445450 OldDII->eraseFromParent ();
55455451 };
5546- for_each (findDbgDeclares (Fragment.Alloca ), RemoveOne);
55475452 for_each (findDVRDeclares (Fragment.Alloca ), RemoveOne);
55485453 for_each (findDVRValues (Fragment.Alloca ), RemoveOne);
55495454 insertNewDbgInst (DIB, DbgVariable, Fragment.Alloca , NewExpr, &AI,
@@ -5553,10 +5458,8 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
55535458
55545459 // Migrate debug information from the old alloca to the new alloca(s)
55555460 // and the individual partitions.
5556- for_each (findDbgDeclares (&AI), MigrateOne);
55575461 for_each (findDVRDeclares (&AI), MigrateOne);
55585462 for_each (findDVRValues (&AI), MigrateOne);
5559- for_each (at::getAssignmentMarkers (&AI), MigrateOne);
55605463 for_each (at::getDVRAssignmentMarkers (&AI), MigrateOne);
55615464
55625465 return Changed;
@@ -5777,8 +5680,6 @@ bool SROA::deleteDeadInstructions(
57775680 // not be able to find it.
57785681 if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
57795682 DeletedAllocas.insert (AI);
5780- for (DbgDeclareInst *OldDII : findDbgDeclares (AI))
5781- OldDII->eraseFromParent ();
57825683 for (DbgVariableRecord *OldDII : findDVRDeclares (AI))
57835684 OldDII->eraseFromParent ();
57845685 }
0 commit comments