Skip to content

Commit 3cadca3

Browse files
committed
merge main into amd-staging
2 parents 78bade0 + 5328c73 commit 3cadca3

File tree

8 files changed

+90
-407
lines changed

8 files changed

+90
-407
lines changed

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class BasicBlock;
3636
class BranchInst;
3737
class CallBase;
3838
class CallInst;
39-
class DbgVariableIntrinsic;
4039
class DIBuilder;
4140
class DomTreeUpdater;
4241
class Function;
@@ -275,44 +274,31 @@ LLVM_ABI CallInst *changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
275274
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI,
276275
DIBuilder &Builder);
277276

278-
/// Creates and inserts an llvm.dbg.value intrinsic before a store
279-
/// that has an associated llvm.dbg.value intrinsic.
280-
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableIntrinsic *DII,
281-
StoreInst *SI, DIBuilder &Builder);
282-
283-
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
284-
/// that has an associated llvm.dbg.declare intrinsic.
285-
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
286-
StoreInst *SI,
287-
DIBuilder &Builder);
277+
/// Inserts a dbg.value record before a store to an alloca'd value
278+
/// that has an associated dbg.declare record.
288279
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
289280
StoreInst *SI,
290281
DIBuilder &Builder);
291282

292-
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
293-
/// that has an associated llvm.dbg.declare intrinsic.
294-
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
295-
LoadInst *LI, DIBuilder &Builder);
283+
/// Inserts a dbg.value record before a load of an alloca'd value
284+
/// that has an associated dbg.declare record.
296285
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
297286
LoadInst *LI, DIBuilder &Builder);
298287

299-
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
300-
/// llvm.dbg.declare intrinsic.
301-
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
302-
PHINode *LI, DIBuilder &Builder);
288+
/// Inserts a dbg.value record after a phi that has an associated
289+
/// llvm.dbg.declare record.
303290
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
304291
PHINode *LI, DIBuilder &Builder);
305292

306-
/// Lowers llvm.dbg.declare intrinsics into appropriate set of
307-
/// llvm.dbg.value intrinsics.
293+
/// Lowers dbg.declare records into appropriate set of dbg.value records.
308294
LLVM_ABI bool LowerDbgDeclare(Function &F);
309295

310296
/// Propagate dbg.value intrinsics through the newly inserted PHIs.
311297
LLVM_ABI void
312298
insertDebugValuesForPHIs(BasicBlock *BB,
313299
SmallVectorImpl<PHINode *> &InsertedPHIs);
314300

315-
/// Replaces llvm.dbg.declare instruction when the address it
301+
/// Replaces dbg.declare record when the address it
316302
/// describes is replaced with a new value. If Deref is true, an
317303
/// additional DW_OP_deref is prepended to the expression. If Offset
318304
/// is non-zero, a constant displacement is added to the expression
@@ -321,10 +307,10 @@ LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress,
321307
DIBuilder &Builder, uint8_t DIExprFlags,
322308
int Offset);
323309

324-
/// Replaces multiple llvm.dbg.value instructions when the alloca it describes
310+
/// Replaces multiple dbg.value records when the alloca it describes
325311
/// is replaced with a new value. If Offset is non-zero, a constant displacement
326312
/// is added to the expression (after the mandatory Deref). Offset can be
327-
/// negative. New llvm.dbg.value instructions are inserted at the locations of
313+
/// negative. New dbg.value records are inserted at the locations of
328314
/// the instructions they replace.
329315
LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
330316
DIBuilder &Builder, int Offset = 0);

llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace llvm {
2525
class DominatorTree;
26-
class DbgVariableIntrinsic;
2726
class IntrinsicInst;
2827
class PostDominatorTree;
2928
class AllocaInst;
@@ -53,8 +52,6 @@ struct AllocaInfo {
5352
AllocaInst *AI;
5453
SmallVector<IntrinsicInst *, 2> LifetimeStart;
5554
SmallVector<IntrinsicInst *, 2> LifetimeEnd;
56-
SmallVector<DbgVariableIntrinsic *, 2> DbgVariableIntrinsics;
57-
// Non-intrinsic records of variable locations.
5855
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
5956
};
6057

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,9 +3644,6 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
36443644
ConstantInt::get(Type::getInt1Ty(C->getContext()),
36453645
C->isFalseWhenEqual()));
36463646
} else if (auto *SI = dyn_cast<StoreInst>(I)) {
3647-
for (auto *DVI : DVIs)
3648-
if (DVI->isAddressOfVariable())
3649-
ConvertDebugDeclareToDebugValue(DVI, SI, *DIB);
36503647
for (auto *DVR : DVRs)
36513648
if (DVR->isAddressOfVariable())
36523649
ConvertDebugDeclareToDebugValue(DVR, SI, *DIB);

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}
322318
static 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.
330323
DbgVariableRecord *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.
51405112
bool 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-
51525118
const 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
}

llvm/lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,8 @@ void PruningFunctionCloner::CloneBlock(
576576
}
577577

578578
// Eagerly remap operands to the newly cloned instruction, except for PHI
579-
// nodes for which we defer processing until we update the CFG. Also defer
580-
// debug intrinsic processing because they may contain use-before-defs.
581-
if (!isa<PHINode>(NewInst) && !isa<DbgVariableIntrinsic>(NewInst)) {
579+
// nodes for which we defer processing until we update the CFG.
580+
if (!isa<PHINode>(NewInst)) {
582581
RemapInstruction(NewInst, VMap,
583582
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
584583

@@ -733,15 +732,6 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
733732
StartingInst = &StartingBB->front();
734733
}
735734

736-
// Collect debug intrinsics for remapping later.
737-
SmallVector<const DbgVariableIntrinsic *, 8> DbgIntrinsics;
738-
for (const auto &BB : *OldFunc) {
739-
for (const auto &I : BB) {
740-
if (const auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
741-
DbgIntrinsics.push_back(DVI);
742-
}
743-
}
744-
745735
// Clone the entry block, and anything recursively reachable from it.
746736
std::vector<const BasicBlock *> CloneWorklist;
747737
PFC.CloneBlock(StartingBB, StartingInst->getIterator(), CloneWorklist);
@@ -899,21 +889,11 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
899889
// Restore attributes.
900890
NewFunc->setAttributes(Attrs);
901891

902-
// Remap debug intrinsic operands now that all values have been mapped.
903-
// Doing this now (late) preserves use-before-defs in debug intrinsics. If
892+
// Remap debug records operands now that all values have been mapped.
893+
// Doing this now (late) preserves use-before-defs in debug records. If
904894
// we didn't do this, ValueAsMetadata(use-before-def) operands would be
905895
// replaced by empty metadata. This would signal later cleanup passes to
906-
// remove the debug intrinsics, potentially causing incorrect locations.
907-
for (const auto *DVI : DbgIntrinsics) {
908-
if (DbgVariableIntrinsic *NewDVI =
909-
cast_or_null<DbgVariableIntrinsic>(VMap.lookup(DVI)))
910-
RemapInstruction(NewDVI, VMap,
911-
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
912-
TypeMapper, Materializer);
913-
}
914-
915-
// Do the same for DbgVariableRecords, touching all the instructions in the
916-
// cloned range of blocks.
896+
// remove the debug records, potentially causing incorrect locations.
917897
Function::iterator Begin = cast<BasicBlock>(VMap[StartingBB])->getIterator();
918898
for (BasicBlock &BB : make_range(Begin, NewFunc->end())) {
919899
for (Instruction &I : BB) {

0 commit comments

Comments
 (0)