diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index fe30c6dc6abe4..42e7948afd63a 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -1103,14 +1103,13 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { FrameTy->getElementType(FrameData.getFieldIndex(E.first)), GEP, SpillAlignment, E.first->getName() + Twine(".reload")); - TinyPtrVector DIs = findDbgDeclares(Def); TinyPtrVector DVRs = findDVRDeclares(Def); // Try best to find dbg.declare. If the spill is a temp, there may not // be a direct dbg.declare. Walk up the load chain to find one from an // alias. if (F->getSubprogram()) { auto *CurDef = Def; - while (DIs.empty() && DVRs.empty() && isa(CurDef)) { + while (DVRs.empty() && isa(CurDef)) { auto *LdInst = cast(CurDef); // Only consider ptr to ptr same type load. if (LdInst->getPointerOperandType() != LdInst->getType()) @@ -1118,12 +1117,11 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { CurDef = LdInst->getPointerOperand(); if (!isa(CurDef)) break; - DIs = findDbgDeclares(CurDef); DVRs = findDVRDeclares(CurDef); } } - auto SalvageOne = [&](auto *DDI) { + auto SalvageOne = [&](DbgVariableRecord *DDI) { // This dbg.declare is preserved for all coro-split function // fragments. It will be unreachable in the main function, and // processed by coro::salvageDebugInfo() by the Cloner. @@ -1137,7 +1135,6 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { // will be deleted in all coro-split functions. coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/); }; - for_each(DIs, SalvageOne); for_each(DVRs, SalvageOne); } @@ -1218,8 +1215,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { SmallVector DIs; SmallVector DbgVariableRecords; findDbgUsers(DIs, Alloca, &DbgVariableRecords); - for (auto *DVI : DIs) - DVI->replaceUsesOfWith(Alloca, G); + assert(DIs.empty() && "Should never see debug-intrinsics"); for (auto *DVR : DbgVariableRecords) DVR->replaceVariableLocationOp(Alloca, G); @@ -1913,48 +1909,6 @@ salvageDebugInfoImpl(SmallDenseMap &ArgToAllocaMap, return {{*Storage, *Expr}}; } -void coro::salvageDebugInfo( - SmallDenseMap &ArgToAllocaMap, - DbgVariableIntrinsic &DVI, bool UseEntryValue) { - - Function *F = DVI.getFunction(); - // Follow the pointer arithmetic all the way to the incoming - // function argument and convert into a DIExpression. - bool SkipOutermostLoad = !isa(DVI); - Value *OriginalStorage = DVI.getVariableLocationOp(0); - - auto SalvagedInfo = - ::salvageDebugInfoImpl(ArgToAllocaMap, UseEntryValue, F, OriginalStorage, - DVI.getExpression(), SkipOutermostLoad); - if (!SalvagedInfo) - return; - - Value *Storage = &SalvagedInfo->first; - DIExpression *Expr = &SalvagedInfo->second; - - DVI.replaceVariableLocationOp(OriginalStorage, Storage); - DVI.setExpression(Expr); - // We only hoist dbg.declare today since it doesn't make sense to hoist - // dbg.value since it does not have the same function wide guarantees that - // dbg.declare does. - if (isa(DVI)) { - std::optional InsertPt; - if (auto *I = dyn_cast(Storage)) { - InsertPt = I->getInsertionPointAfterDef(); - // Update DILocation only if variable was not inlined. - DebugLoc ILoc = I->getDebugLoc(); - DebugLoc DVILoc = DVI.getDebugLoc(); - if (ILoc && DVILoc && - DVILoc->getScope()->getSubprogram() == - ILoc->getScope()->getSubprogram()) - DVI.setDebugLoc(I->getDebugLoc()); - } else if (isa(Storage)) - InsertPt = F->getEntryBlock().begin(); - if (InsertPt) - DVI.moveBefore(*(*InsertPt)->getParent(), *InsertPt); - } -} - void coro::salvageDebugInfo( SmallDenseMap &ArgToAllocaMap, DbgVariableRecord &DVR, bool UseEntryValue) { diff --git a/llvm/lib/Transforms/Coroutines/CoroInternal.h b/llvm/lib/Transforms/Coroutines/CoroInternal.h index b53c5a48eb10b..52f4ffe292dae 100644 --- a/llvm/lib/Transforms/Coroutines/CoroInternal.h +++ b/llvm/lib/Transforms/Coroutines/CoroInternal.h @@ -34,14 +34,11 @@ void suppressCoroAllocs(CoroIdInst *CoroId); void suppressCoroAllocs(LLVMContext &Context, ArrayRef CoroAllocs); -/// Attempts to rewrite the location operand of debug intrinsics in terms of +/// Attempts to rewrite the location operand of debug records in terms of /// the coroutine frame pointer, folding pointer offsets into the DIExpression /// of the intrinsic. /// If the frame pointer is an Argument, store it into an alloca to enhance the /// debugability. -void salvageDebugInfo( - SmallDenseMap &ArgToAllocaMap, - DbgVariableIntrinsic &DVI, bool IsEntryPoint); void salvageDebugInfo( SmallDenseMap &ArgToAllocaMap, DbgVariableRecord &DVR, bool UseEntryValue); diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index 5a8a41f0dc432..64b33e46404f0 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -618,19 +618,15 @@ static void replaceSwiftErrorOps(Function &F, coro::Shape &Shape, } } -/// Returns all DbgVariableIntrinsic in F. -static std::pair, - SmallVector> -collectDbgVariableIntrinsics(Function &F) { - SmallVector Intrinsics; +/// Returns all debug records in F. +static SmallVector +collectDbgVariableRecords(Function &F) { SmallVector DbgVariableRecords; for (auto &I : instructions(F)) { for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) DbgVariableRecords.push_back(&DVR); - if (auto *DVI = dyn_cast(&I)) - Intrinsics.push_back(DVI); } - return {Intrinsics, DbgVariableRecords}; + return DbgVariableRecords; } void coro::BaseCloner::replaceSwiftErrorOps() { @@ -638,13 +634,11 @@ void coro::BaseCloner::replaceSwiftErrorOps() { } void coro::BaseCloner::salvageDebugInfo() { - auto [Worklist, DbgVariableRecords] = collectDbgVariableIntrinsics(*NewF); + auto DbgVariableRecords = collectDbgVariableRecords(*NewF); SmallDenseMap ArgToAllocaMap; // Only 64-bit ABIs have a register we can refer to with the entry value. bool UseEntryValue = OrigF.getParent()->getTargetTriple().isArch64Bit(); - for (DbgVariableIntrinsic *DVI : Worklist) - coro::salvageDebugInfo(ArgToAllocaMap, *DVI, UseEntryValue); for (DbgVariableRecord *DVR : DbgVariableRecords) coro::salvageDebugInfo(ArgToAllocaMap, *DVR, UseEntryValue); @@ -655,7 +649,7 @@ void coro::BaseCloner::salvageDebugInfo() { return !isPotentiallyReachable(&NewF->getEntryBlock(), BB, nullptr, &DomTree); }; - auto RemoveOne = [&](auto *DVI) { + auto RemoveOne = [&](DbgVariableRecord *DVI) { if (IsUnreachableBlock(DVI->getParent())) DVI->eraseFromParent(); else if (isa_and_nonnull(DVI->getVariableLocationOp(0))) { @@ -669,7 +663,6 @@ void coro::BaseCloner::salvageDebugInfo() { DVI->eraseFromParent(); } }; - for_each(Worklist, RemoveOne); for_each(DbgVariableRecords, RemoveOne); } @@ -2022,9 +2015,7 @@ static void doSplitCoroutine(Function &F, SmallVectorImpl &Clones, // original function. The Cloner has already salvaged debug info in the new // coroutine funclets. SmallDenseMap ArgToAllocaMap; - auto [DbgInsts, DbgVariableRecords] = collectDbgVariableIntrinsics(F); - for (auto *DDI : DbgInsts) - coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/); + auto DbgVariableRecords = collectDbgVariableRecords(F); for (DbgVariableRecord *DVR : DbgVariableRecords) coro::salvageDebugInfo(ArgToAllocaMap, *DVR, false /*UseEntryValue*/);