Skip to content

Commit 28208c8

Browse files
authored
[DebugInfo] Remove debug-intrinsic coroutine codepaths (#149068)
There are a few duplicate paths/facilities in the coroutine code to deal with both intrinsics and debug-records; we can now delete the intrinsic version.
1 parent 3ce06b8 commit 28208c8

File tree

3 files changed

+11
-69
lines changed

3 files changed

+11
-69
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,27 +1103,25 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
11031103
FrameTy->getElementType(FrameData.getFieldIndex(E.first)), GEP,
11041104
SpillAlignment, E.first->getName() + Twine(".reload"));
11051105

1106-
TinyPtrVector<DbgDeclareInst *> DIs = findDbgDeclares(Def);
11071106
TinyPtrVector<DbgVariableRecord *> DVRs = findDVRDeclares(Def);
11081107
// Try best to find dbg.declare. If the spill is a temp, there may not
11091108
// be a direct dbg.declare. Walk up the load chain to find one from an
11101109
// alias.
11111110
if (F->getSubprogram()) {
11121111
auto *CurDef = Def;
1113-
while (DIs.empty() && DVRs.empty() && isa<LoadInst>(CurDef)) {
1112+
while (DVRs.empty() && isa<LoadInst>(CurDef)) {
11141113
auto *LdInst = cast<LoadInst>(CurDef);
11151114
// Only consider ptr to ptr same type load.
11161115
if (LdInst->getPointerOperandType() != LdInst->getType())
11171116
break;
11181117
CurDef = LdInst->getPointerOperand();
11191118
if (!isa<AllocaInst, LoadInst>(CurDef))
11201119
break;
1121-
DIs = findDbgDeclares(CurDef);
11221120
DVRs = findDVRDeclares(CurDef);
11231121
}
11241122
}
11251123

1126-
auto SalvageOne = [&](auto *DDI) {
1124+
auto SalvageOne = [&](DbgVariableRecord *DDI) {
11271125
// This dbg.declare is preserved for all coro-split function
11281126
// fragments. It will be unreachable in the main function, and
11291127
// processed by coro::salvageDebugInfo() by the Cloner.
@@ -1137,7 +1135,6 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
11371135
// will be deleted in all coro-split functions.
11381136
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/);
11391137
};
1140-
for_each(DIs, SalvageOne);
11411138
for_each(DVRs, SalvageOne);
11421139
}
11431140

@@ -1225,8 +1222,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12251222
SmallVector<DbgVariableIntrinsic *, 4> DIs;
12261223
SmallVector<DbgVariableRecord *> DbgVariableRecords;
12271224
findDbgUsers(DIs, Alloca, &DbgVariableRecords);
1228-
for (auto *DVI : DIs)
1229-
DVI->replaceUsesOfWith(Alloca, G);
1225+
assert(DIs.empty() && "Should never see debug-intrinsics");
12301226
for (auto *DVR : DbgVariableRecords)
12311227
DVR->replaceVariableLocationOp(Alloca, G);
12321228

@@ -1920,48 +1916,6 @@ salvageDebugInfoImpl(SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
19201916
return {{*Storage, *Expr}};
19211917
}
19221918

1923-
void coro::salvageDebugInfo(
1924-
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
1925-
DbgVariableIntrinsic &DVI, bool UseEntryValue) {
1926-
1927-
Function *F = DVI.getFunction();
1928-
// Follow the pointer arithmetic all the way to the incoming
1929-
// function argument and convert into a DIExpression.
1930-
bool SkipOutermostLoad = !isa<DbgValueInst>(DVI);
1931-
Value *OriginalStorage = DVI.getVariableLocationOp(0);
1932-
1933-
auto SalvagedInfo =
1934-
::salvageDebugInfoImpl(ArgToAllocaMap, UseEntryValue, F, OriginalStorage,
1935-
DVI.getExpression(), SkipOutermostLoad);
1936-
if (!SalvagedInfo)
1937-
return;
1938-
1939-
Value *Storage = &SalvagedInfo->first;
1940-
DIExpression *Expr = &SalvagedInfo->second;
1941-
1942-
DVI.replaceVariableLocationOp(OriginalStorage, Storage);
1943-
DVI.setExpression(Expr);
1944-
// We only hoist dbg.declare today since it doesn't make sense to hoist
1945-
// dbg.value since it does not have the same function wide guarantees that
1946-
// dbg.declare does.
1947-
if (isa<DbgDeclareInst>(DVI)) {
1948-
std::optional<BasicBlock::iterator> InsertPt;
1949-
if (auto *I = dyn_cast<Instruction>(Storage)) {
1950-
InsertPt = I->getInsertionPointAfterDef();
1951-
// Update DILocation only if variable was not inlined.
1952-
DebugLoc ILoc = I->getDebugLoc();
1953-
DebugLoc DVILoc = DVI.getDebugLoc();
1954-
if (ILoc && DVILoc &&
1955-
DVILoc->getScope()->getSubprogram() ==
1956-
ILoc->getScope()->getSubprogram())
1957-
DVI.setDebugLoc(I->getDebugLoc());
1958-
} else if (isa<Argument>(Storage))
1959-
InsertPt = F->getEntryBlock().begin();
1960-
if (InsertPt)
1961-
DVI.moveBefore(*(*InsertPt)->getParent(), *InsertPt);
1962-
}
1963-
}
1964-
19651919
void coro::salvageDebugInfo(
19661920
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
19671921
DbgVariableRecord &DVR, bool UseEntryValue) {

llvm/lib/Transforms/Coroutines/CoroInternal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ void suppressCoroAllocs(CoroIdInst *CoroId);
3434
void suppressCoroAllocs(LLVMContext &Context,
3535
ArrayRef<CoroAllocInst *> CoroAllocs);
3636

37-
/// Attempts to rewrite the location operand of debug intrinsics in terms of
37+
/// Attempts to rewrite the location operand of debug records in terms of
3838
/// the coroutine frame pointer, folding pointer offsets into the DIExpression
3939
/// of the intrinsic.
4040
/// If the frame pointer is an Argument, store it into an alloca to enhance the
4141
/// debugability.
42-
void salvageDebugInfo(
43-
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
44-
DbgVariableIntrinsic &DVI, bool IsEntryPoint);
4542
void salvageDebugInfo(
4643
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
4744
DbgVariableRecord &DVR, bool UseEntryValue);

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -618,33 +618,27 @@ static void replaceSwiftErrorOps(Function &F, coro::Shape &Shape,
618618
}
619619
}
620620

621-
/// Returns all DbgVariableIntrinsic in F.
622-
static std::pair<SmallVector<DbgVariableIntrinsic *, 8>,
623-
SmallVector<DbgVariableRecord *>>
624-
collectDbgVariableIntrinsics(Function &F) {
625-
SmallVector<DbgVariableIntrinsic *, 8> Intrinsics;
621+
/// Returns all debug records in F.
622+
static SmallVector<DbgVariableRecord *>
623+
collectDbgVariableRecords(Function &F) {
626624
SmallVector<DbgVariableRecord *> DbgVariableRecords;
627625
for (auto &I : instructions(F)) {
628626
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
629627
DbgVariableRecords.push_back(&DVR);
630-
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
631-
Intrinsics.push_back(DVI);
632628
}
633-
return {Intrinsics, DbgVariableRecords};
629+
return DbgVariableRecords;
634630
}
635631

636632
void coro::BaseCloner::replaceSwiftErrorOps() {
637633
::replaceSwiftErrorOps(*NewF, Shape, &VMap);
638634
}
639635

640636
void coro::BaseCloner::salvageDebugInfo() {
641-
auto [Worklist, DbgVariableRecords] = collectDbgVariableIntrinsics(*NewF);
637+
auto DbgVariableRecords = collectDbgVariableRecords(*NewF);
642638
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
643639

644640
// Only 64-bit ABIs have a register we can refer to with the entry value.
645641
bool UseEntryValue = OrigF.getParent()->getTargetTriple().isArch64Bit();
646-
for (DbgVariableIntrinsic *DVI : Worklist)
647-
coro::salvageDebugInfo(ArgToAllocaMap, *DVI, UseEntryValue);
648642
for (DbgVariableRecord *DVR : DbgVariableRecords)
649643
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, UseEntryValue);
650644

@@ -655,7 +649,7 @@ void coro::BaseCloner::salvageDebugInfo() {
655649
return !isPotentiallyReachable(&NewF->getEntryBlock(), BB, nullptr,
656650
&DomTree);
657651
};
658-
auto RemoveOne = [&](auto *DVI) {
652+
auto RemoveOne = [&](DbgVariableRecord *DVI) {
659653
if (IsUnreachableBlock(DVI->getParent()))
660654
DVI->eraseFromParent();
661655
else if (isa_and_nonnull<AllocaInst>(DVI->getVariableLocationOp(0))) {
@@ -669,7 +663,6 @@ void coro::BaseCloner::salvageDebugInfo() {
669663
DVI->eraseFromParent();
670664
}
671665
};
672-
for_each(Worklist, RemoveOne);
673666
for_each(DbgVariableRecords, RemoveOne);
674667
}
675668

@@ -2022,9 +2015,7 @@ static void doSplitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
20222015
// original function. The Cloner has already salvaged debug info in the new
20232016
// coroutine funclets.
20242017
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
2025-
auto [DbgInsts, DbgVariableRecords] = collectDbgVariableIntrinsics(F);
2026-
for (auto *DDI : DbgInsts)
2027-
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/);
2018+
auto DbgVariableRecords = collectDbgVariableRecords(F);
20282019
for (DbgVariableRecord *DVR : DbgVariableRecords)
20292020
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, false /*UseEntryValue*/);
20302021

0 commit comments

Comments
 (0)