Skip to content

Commit

Permalink
[debug-info] If one sees a spill with a dbg.addr use, salvageDebugInf…
Browse files Browse the repository at this point in the history
…o upon it and don't hoist it.

This ensures that if we have a dbg.addr in a coroutine funclet that is on one of
our function arguments, that the dbg.addr is not mapped to undef and also that
later it isn't hoisted to the front of the basic block. Instead it remains at
its original cloned location.

rdar://83957028

Differential Revision: https://reviews.llvm.org/D119576
  • Loading branch information
gottesmm committed Feb 11, 2022
1 parent 0574b5f commit 19279ff
Show file tree
Hide file tree
Showing 3 changed files with 710 additions and 2 deletions.
13 changes: 11 additions & 2 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Expand Up @@ -27,6 +27,7 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
Expand Down Expand Up @@ -1662,6 +1663,12 @@ static Instruction *insertSpills(const FrameDataInfo &FrameData,
}
}

// Salvage debug info on any dbg.addr that we see. We do not insert them
// into each block where we have a use though.
if (auto *DI = dyn_cast<DbgAddrIntrinsic>(U)) {
coro::salvageDebugInfo(DbgPtrAllocaCache, DI, Shape.OptimizeFrame);
}

// If we have a single edge PHINode, remove it and replace it with a
// reload from the coroutine frame. (We already took care of multi edge
// PHINodes by rewriting them in the rewritePHIs function).
Expand Down Expand Up @@ -2579,8 +2586,10 @@ void coro::salvageDebugInfo(

DVI->replaceVariableLocationOp(OriginalStorage, Storage);
DVI->setExpression(Expr);
/// It makes no sense to move the dbg.value intrinsic.
if (!isa<DbgValueInst>(DVI)) {
// We only hoist dbg.declare today since it doesn't make sense to hoist
// dbg.value or dbg.addr since they do not have the same function wide
// guarantees that dbg.declare does.
if (!isa<DbgValueInst>(DVI) && !isa<DbgAddrIntrinsic>(DVI)) {
if (auto *II = dyn_cast<InvokeInst>(Storage))
DVI->moveBefore(II->getNormalDest()->getFirstNonPHI());
else if (auto *CBI = dyn_cast<CallBrInst>(Storage))
Expand Down

0 comments on commit 19279ff

Please sign in to comment.