Skip to content

Commit

Permalink
[CoroSplit][DebugInfo][nfc] Use more specialize Map arguments
Browse files Browse the repository at this point in the history
We use a map of Argument->AllocaInst when mapping Arguments to the
AllocaInst created for them.

Said map is declared from "Value" and called a "DbgPtrCache". This
commit:
* replaces Value to the more specialized Argument class, to reflect the
intent better (i.e. we are _always_ mapping Arguments).
* replaces the name "DbgPtrCache" with the more explicit "ArgToAllocaMap",
as it is not clear reading the code what a "DbgPtr" is.

Differential Revision: https://reviews.llvm.org/D149748
  • Loading branch information
felipepiovezan committed May 3, 2023
1 parent 5c6be1d commit 9ef5381
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
StructType *FrameTy = Shape.FrameTy;
Value *FramePtr = Shape.FramePtr;
DominatorTree DT(*F);
SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> DbgPtrAllocaCache;
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;

// Create a GEP with the given index into the coroutine frame for the original
// value Orig. Appends an extra 0 index for array-allocas, preserving the
Expand Down Expand Up @@ -1873,7 +1873,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
&*Builder.GetInsertPoint());
// This dbg.declare is for the main function entry point. It
// will be deleted in all coro-split functions.
coro::salvageDebugInfo(DbgPtrAllocaCache, DDI, Shape.OptimizeFrame);
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame);
}
}

Expand Down Expand Up @@ -2815,7 +2815,7 @@ static void collectFrameAlloca(AllocaInst *AI, coro::Shape &Shape,
}

void coro::salvageDebugInfo(
SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> &DbgPtrAllocaCache,
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
DbgVariableIntrinsic *DVI, bool OptimizeFrame) {
Function *F = DVI->getFunction();
IRBuilder<> Builder(F->getContext());
Expand Down Expand Up @@ -2870,8 +2870,8 @@ void coro::salvageDebugInfo(
// Avoid to create the alloca would be eliminated by optimization
// passes and the corresponding dbg.declares would be invalid.
if (!OptimizeFrame)
if (auto *Arg = dyn_cast<llvm::Argument>(Storage)) {
auto &Cached = DbgPtrAllocaCache[Storage];
if (auto *Arg = dyn_cast<Argument>(Storage)) {
auto &Cached = ArgToAllocaMap[Arg];
if (!Cached) {
Cached = Builder.CreateAlloca(Storage->getType(), 0, nullptr,
Arg->getName() + ".debug");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void replaceCoroFree(CoroIdInst *CoroId, bool Elide);
/// If the frame pointer is an Argument, store it into an alloca if
/// OptimizeFrame is false.
void salvageDebugInfo(
SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> &DbgPtrAllocaCache,
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
DbgVariableIntrinsic *DVI, bool OptimizeFrame);

// Keeps data and helper functions for lowering coroutine intrinsics.
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ void CoroCloner::replaceSwiftErrorOps() {
void CoroCloner::salvageDebugInfo() {
SmallVector<DbgVariableIntrinsic *, 8> Worklist =
collectDbgVariableIntrinsics(*NewF);
SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> DbgPtrAllocaCache;
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
for (DbgVariableIntrinsic *DVI : Worklist)
coro::salvageDebugInfo(DbgPtrAllocaCache, DVI, Shape.OptimizeFrame);
coro::salvageDebugInfo(ArgToAllocaMap, DVI, Shape.OptimizeFrame);

// Remove all salvaged dbg.declare intrinsics that became
// either unreachable or stale due to the CoroSplit transformation.
Expand Down Expand Up @@ -1981,9 +1981,9 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
// Salvage debug intrinsics that point into the coroutine frame in the
// original function. The Cloner has already salvaged debug info in the new
// coroutine funclets.
SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> DbgPtrAllocaCache;
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
for (auto *DDI : collectDbgVariableIntrinsics(F))
coro::salvageDebugInfo(DbgPtrAllocaCache, DDI, Shape.OptimizeFrame);
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame);

return Shape;
}
Expand Down

0 comments on commit 9ef5381

Please sign in to comment.