85 changes: 43 additions & 42 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static void cacheDIVar(FrameDataInfo &FrameData,
DIVarCache.insert({V, (*I)->getVariable()});
};
CacheIt(findDbgDeclares(V));
CacheIt(findDPVDeclares(V));
CacheIt(findDVRDeclares(V));
}
}

Expand Down Expand Up @@ -1123,18 +1123,18 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
"Coroutine with switch ABI should own Promise alloca");

TinyPtrVector<DbgDeclareInst *> DIs = findDbgDeclares(PromiseAlloca);
TinyPtrVector<DPValue *> DPVs = findDPVDeclares(PromiseAlloca);
TinyPtrVector<DbgVariableRecord *> DVRs = findDVRDeclares(PromiseAlloca);

DILocalVariable *PromiseDIVariable = nullptr;
DILocation *DILoc = nullptr;
if (!DIs.empty()) {
DbgDeclareInst *PromiseDDI = DIs.front();
PromiseDIVariable = PromiseDDI->getVariable();
DILoc = PromiseDDI->getDebugLoc().get();
} else if (!DPVs.empty()) {
DPValue *PromiseDPV = DPVs.front();
PromiseDIVariable = PromiseDPV->getVariable();
DILoc = PromiseDPV->getDebugLoc().get();
} else if (!DVRs.empty()) {
DbgVariableRecord *PromiseDVR = DVRs.front();
PromiseDIVariable = PromiseDVR->getVariable();
DILoc = PromiseDVR->getDebugLoc().get();
} else {
return;
}
Expand Down Expand Up @@ -1273,11 +1273,12 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
}

if (UseNewDbgInfoFormat) {
DPValue *NewDPV = new DPValue(ValueAsMetadata::get(Shape.FramePtr),
FrameDIVar, DBuilder.createExpression(),
DILoc, DPValue::LocationType::Declare);
DbgVariableRecord *NewDVR =
new DbgVariableRecord(ValueAsMetadata::get(Shape.FramePtr), FrameDIVar,
DBuilder.createExpression(), DILoc,
DbgVariableRecord::LocationType::Declare);
BasicBlock::iterator It = Shape.getInsertPtAfterFramePtr();
It->getParent()->insertDbgRecordBefore(NewDPV, It);
It->getParent()->insertDbgRecordBefore(NewDVR, It);
} else {
DBuilder.insertDeclare(Shape.FramePtr, FrameDIVar,
DBuilder.createExpression(), DILoc,
Expand Down Expand Up @@ -1862,13 +1863,13 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
SpillAlignment, E.first->getName() + Twine(".reload"));

TinyPtrVector<DbgDeclareInst *> DIs = findDbgDeclares(Def);
TinyPtrVector<DPValue *> DPVs = findDPVDeclares(Def);
TinyPtrVector<DbgVariableRecord *> 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() && DPVs.empty() && isa<LoadInst>(CurDef)) {
while (DIs.empty() && DVRs.empty() && isa<LoadInst>(CurDef)) {
auto *LdInst = cast<LoadInst>(CurDef);
// Only consider ptr to ptr same type load.
if (LdInst->getPointerOperandType() != LdInst->getType())
Expand All @@ -1877,7 +1878,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
if (!isa<AllocaInst, LoadInst>(CurDef))
break;
DIs = findDbgDeclares(CurDef);
DPVs = findDPVDeclares(CurDef);
DVRs = findDVRDeclares(CurDef);
}
}

Expand All @@ -1887,12 +1888,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
// fragments. It will be unreachable in the main function, and
// processed by coro::salvageDebugInfo() by CoroCloner.
if (UseNewDbgInfoFormat) {
DPValue *NewDPV =
new DPValue(ValueAsMetadata::get(CurrentReload),
DDI->getVariable(), DDI->getExpression(),
DDI->getDebugLoc(), DPValue::LocationType::Declare);
DbgVariableRecord *NewDVR = new DbgVariableRecord(
ValueAsMetadata::get(CurrentReload), DDI->getVariable(),
DDI->getExpression(), DDI->getDebugLoc(),
DbgVariableRecord::LocationType::Declare);
Builder.GetInsertPoint()->getParent()->insertDbgRecordBefore(
NewDPV, Builder.GetInsertPoint());
NewDVR, Builder.GetInsertPoint());
} else {
DIBuilder(*CurrentBlock->getParent()->getParent(), AllowUnresolved)
.insertDeclare(CurrentReload, DDI->getVariable(),
Expand All @@ -1905,7 +1906,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
false /*UseEntryValue*/);
};
for_each(DIs, SalvageOne);
for_each(DPVs, SalvageOne);
for_each(DVRs, SalvageOne);
}

// If we have a single edge PHINode, remove it and replace it with a
Expand All @@ -1925,8 +1926,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
U->replaceUsesOfWith(Def, CurrentReload);
// Instructions are added to Def's user list if the attached
// debug records use Def. Update those now.
for (DPValue &DPV : filterDbgVars(U->getDbgRecordRange()))
DPV.replaceVariableLocationOp(Def, CurrentReload, true);
for (DbgVariableRecord &DVR : filterDbgVars(U->getDbgRecordRange()))
DVR.replaceVariableLocationOp(Def, CurrentReload, true);
}
}

Expand Down Expand Up @@ -1977,12 +1978,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
G->setName(Alloca->getName() + Twine(".reload.addr"));

SmallVector<DbgVariableIntrinsic *, 4> DIs;
SmallVector<DPValue *> DPValues;
findDbgUsers(DIs, Alloca, &DPValues);
SmallVector<DbgVariableRecord *> DbgVariableRecords;
findDbgUsers(DIs, Alloca, &DbgVariableRecords);
for (auto *DVI : DIs)
DVI->replaceUsesOfWith(Alloca, G);
for (auto *DPV : DPValues)
DPV->replaceVariableLocationOp(Alloca, G);
for (auto *DVR : DbgVariableRecords)
DVR->replaceVariableLocationOp(Alloca, G);

for (Instruction *I : UsersToUpdate) {
// It is meaningless to retain the lifetime intrinsics refer for the
Expand Down Expand Up @@ -2960,43 +2961,43 @@ void coro::salvageDebugInfo(
}

void coro::salvageDebugInfo(
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, DPValue &DPV,
bool OptimizeFrame, bool UseEntryValue) {
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
DbgVariableRecord &DVR, bool OptimizeFrame, bool UseEntryValue) {

Function *F = DPV.getFunction();
Function *F = DVR.getFunction();
// Follow the pointer arithmetic all the way to the incoming
// function argument and convert into a DIExpression.
bool SkipOutermostLoad = DPV.isDbgDeclare();
Value *OriginalStorage = DPV.getVariableLocationOp(0);
bool SkipOutermostLoad = DVR.isDbgDeclare();
Value *OriginalStorage = DVR.getVariableLocationOp(0);

auto SalvagedInfo = ::salvageDebugInfoImpl(
ArgToAllocaMap, OptimizeFrame, UseEntryValue, F, OriginalStorage,
DPV.getExpression(), SkipOutermostLoad);
DVR.getExpression(), SkipOutermostLoad);
if (!SalvagedInfo)
return;

Value *Storage = &SalvagedInfo->first;
DIExpression *Expr = &SalvagedInfo->second;

DPV.replaceVariableLocationOp(OriginalStorage, Storage);
DPV.setExpression(Expr);
DVR.replaceVariableLocationOp(OriginalStorage, Storage);
DVR.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 (DPV.getType() == DPValue::LocationType::Declare) {
if (DVR.getType() == DbgVariableRecord::LocationType::Declare) {
std::optional<BasicBlock::iterator> InsertPt;
if (auto *I = dyn_cast<Instruction>(Storage)) {
InsertPt = I->getInsertionPointAfterDef();
// Update DILocation only in O0 since it is easy to get out of sync in
// optimizations. See https://github.com/llvm/llvm-project/pull/75104 for
// an example.
if (!OptimizeFrame && I->getDebugLoc())
DPV.setDebugLoc(I->getDebugLoc());
DVR.setDebugLoc(I->getDebugLoc());
} else if (isa<Argument>(Storage))
InsertPt = F->getEntryBlock().begin();
if (InsertPt) {
DPV.removeFromParent();
(*InsertPt)->getParent()->insertDbgRecordBefore(&DPV, *InsertPt);
DVR.removeFromParent();
(*InsertPt)->getParent()->insertDbgRecordBefore(&DVR, *InsertPt);
}
}
}
Expand Down Expand Up @@ -3188,15 +3189,15 @@ void coro::buildCoroutineFrame(
for (auto &Iter : FrameData.Spills) {
auto *V = Iter.first;
SmallVector<DbgValueInst *, 16> DVIs;
SmallVector<DPValue *, 16> DPVs;
findDbgValues(DVIs, V, &DPVs);
SmallVector<DbgVariableRecord *, 16> DVRs;
findDbgValues(DVIs, V, &DVRs);
for (DbgValueInst *DVI : DVIs)
if (Checker.isDefinitionAcrossSuspend(*V, DVI))
FrameData.Spills[V].push_back(DVI);
// Add the instructions which carry debug info that is in the frame.
for (DPValue *DPV : DPVs)
if (Checker.isDefinitionAcrossSuspend(*V, DPV->Marker->MarkedInstr))
FrameData.Spills[V].push_back(DPV->Marker->MarkedInstr);
for (DbgVariableRecord *DVR : DVRs)
if (Checker.isDefinitionAcrossSuspend(*V, DVR->Marker->MarkedInstr))
FrameData.Spills[V].push_back(DVR->Marker->MarkedInstr);
}

LLVM_DEBUG(dumpSpills("Spills", FrameData.Spills));
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Coroutines/CoroInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void salvageDebugInfo(
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
DbgVariableIntrinsic &DVI, bool OptimizeFrame, bool IsEntryPoint);
void salvageDebugInfo(
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, DPValue &DPV,
bool OptimizeFrame, bool UseEntryValue);
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
DbgVariableRecord &DVR, bool OptimizeFrame, bool UseEntryValue);

// Keeps data and helper functions for lowering coroutine intrinsics.
struct LowererBase {
Expand Down
25 changes: 13 additions & 12 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,25 +679,26 @@ static void replaceSwiftErrorOps(Function &F, coro::Shape &Shape,
}

/// Returns all DbgVariableIntrinsic in F.
static std::pair<SmallVector<DbgVariableIntrinsic *, 8>, SmallVector<DPValue *>>
static std::pair<SmallVector<DbgVariableIntrinsic *, 8>,
SmallVector<DbgVariableRecord *>>
collectDbgVariableIntrinsics(Function &F) {
SmallVector<DbgVariableIntrinsic *, 8> Intrinsics;
SmallVector<DPValue *> DPValues;
SmallVector<DbgVariableRecord *> DbgVariableRecords;
for (auto &I : instructions(F)) {
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange()))
DPValues.push_back(&DPV);
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
DbgVariableRecords.push_back(&DVR);
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
Intrinsics.push_back(DVI);
}
return {Intrinsics, DPValues};
return {Intrinsics, DbgVariableRecords};
}

void CoroCloner::replaceSwiftErrorOps() {
::replaceSwiftErrorOps(*NewF, Shape, &VMap);
}

void CoroCloner::salvageDebugInfo() {
auto [Worklist, DPValues] = collectDbgVariableIntrinsics(*NewF);
auto [Worklist, DbgVariableRecords] = collectDbgVariableIntrinsics(*NewF);
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;

// Only 64-bit ABIs have a register we can refer to with the entry value.
Expand All @@ -706,8 +707,8 @@ void CoroCloner::salvageDebugInfo() {
for (DbgVariableIntrinsic *DVI : Worklist)
coro::salvageDebugInfo(ArgToAllocaMap, *DVI, Shape.OptimizeFrame,
UseEntryValue);
for (DPValue *DPV : DPValues)
coro::salvageDebugInfo(ArgToAllocaMap, *DPV, Shape.OptimizeFrame,
for (DbgVariableRecord *DVR : DbgVariableRecords)
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, Shape.OptimizeFrame,
UseEntryValue);

// Remove all salvaged dbg.declare intrinsics that became
Expand All @@ -732,7 +733,7 @@ void CoroCloner::salvageDebugInfo() {
}
};
for_each(Worklist, RemoveOne);
for_each(DPValues, RemoveOne);
for_each(DbgVariableRecords, RemoveOne);
}

void CoroCloner::replaceEntryBlock() {
Expand Down Expand Up @@ -2107,12 +2108,12 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
// original function. The Cloner has already salvaged debug info in the new
// coroutine funclets.
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
auto [DbgInsts, DPValues] = collectDbgVariableIntrinsics(F);
auto [DbgInsts, DbgVariableRecords] = collectDbgVariableIntrinsics(F);
for (auto *DDI : DbgInsts)
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, Shape.OptimizeFrame,
false /*UseEntryValue*/);
for (DPValue *DPV : DPValues)
coro::salvageDebugInfo(ArgToAllocaMap, *DPV, Shape.OptimizeFrame,
for (DbgVariableRecord *DVR : DbgVariableRecords)
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, Shape.OptimizeFrame,
false /*UseEntryValue*/);
return Shape;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/IROutliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ static void moveFunctionData(Function &Old, Function &New,
for (Instruction &Val : CurrBB) {
// Since debug-info originates from many different locations in the
// program, it will cause incorrect reporting from a debugger if we keep
// the same debug instructions. Drop non-intrinsic DPValues here,
// collect intrinsics for removal later.
// the same debug instructions. Drop non-intrinsic DbgVariableRecords
// here, collect intrinsics for removal later.
Val.dropDbgRecords();

// We must handle the scoping of called functions differently than
Expand Down
62 changes: 32 additions & 30 deletions llvm/lib/Transforms/IPO/MergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,22 @@ class MergeFunctions {

/// Fill PDIUnrelatedWL with instructions from the entry block that are
/// unrelated to parameter related debug info.
/// \param PDPVUnrelatedWL The equivalent non-intrinsic debug records.
void filterInstsUnrelatedToPDI(BasicBlock *GEntryBlock,
std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DPValue *> &PDPVUnrelatedWL);
/// \param PDVRUnrelatedWL The equivalent non-intrinsic debug records.
void
filterInstsUnrelatedToPDI(BasicBlock *GEntryBlock,
std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DbgVariableRecord *> &PDVRUnrelatedWL);

/// Erase the rest of the CFG (i.e. barring the entry block).
void eraseTail(Function *G);

/// Erase the instructions in PDIUnrelatedWL as they are unrelated to the
/// parameter debug info, from the entry block.
/// \param PDPVUnrelatedWL contains the equivalent set of non-instruction
/// \param PDVRUnrelatedWL contains the equivalent set of non-instruction
/// debug-info records.
void eraseInstsUnrelatedToPDI(std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DPValue *> &PDPVUnrelatedWL);
void
eraseInstsUnrelatedToPDI(std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DbgVariableRecord *> &PDVRUnrelatedWL);

/// Replace G with a simple tail call to bitcast(F). Also (unless
/// MergeFunctionsPDI holds) replace direct uses of G with bitcast(F),
Expand Down Expand Up @@ -512,7 +514,7 @@ static Value *createCast(IRBuilder<> &Builder, Value *V, Type *DestTy) {
// parameter debug info, from the entry block.
void MergeFunctions::eraseInstsUnrelatedToPDI(
std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DPValue *> &PDPVUnrelatedWL) {
std::vector<DbgVariableRecord *> &PDVRUnrelatedWL) {
LLVM_DEBUG(
dbgs() << " Erasing instructions (in reverse order of appearance in "
"entry block) unrelated to parameter debug info from entry "
Expand All @@ -526,13 +528,13 @@ void MergeFunctions::eraseInstsUnrelatedToPDI(
PDIUnrelatedWL.pop_back();
}

while (!PDPVUnrelatedWL.empty()) {
DPValue *DPV = PDPVUnrelatedWL.back();
LLVM_DEBUG(dbgs() << " Deleting DPValue ");
LLVM_DEBUG(DPV->print(dbgs()));
while (!PDVRUnrelatedWL.empty()) {
DbgVariableRecord *DVR = PDVRUnrelatedWL.back();
LLVM_DEBUG(dbgs() << " Deleting DbgVariableRecord ");
LLVM_DEBUG(DVR->print(dbgs()));
LLVM_DEBUG(dbgs() << "\n");
DPV->eraseFromParent();
PDPVUnrelatedWL.pop_back();
DVR->eraseFromParent();
PDVRUnrelatedWL.pop_back();
}

LLVM_DEBUG(dbgs() << " } // Done erasing instructions unrelated to parameter "
Expand Down Expand Up @@ -564,12 +566,12 @@ void MergeFunctions::eraseTail(Function *G) {
// PDIUnrelatedWL with such instructions.
void MergeFunctions::filterInstsUnrelatedToPDI(
BasicBlock *GEntryBlock, std::vector<Instruction *> &PDIUnrelatedWL,
std::vector<DPValue *> &PDPVUnrelatedWL) {
std::vector<DbgVariableRecord *> &PDVRUnrelatedWL) {
std::set<Instruction *> PDIRelated;
std::set<DPValue *> PDPVRelated;
std::set<DbgVariableRecord *> PDVRRelated;

// Work out whether a dbg.value intrinsic or an equivalent DPValue is a
// parameter to be preserved.
// Work out whether a dbg.value intrinsic or an equivalent DbgVariableRecord
// is a parameter to be preserved.
auto ExamineDbgValue = [](auto *DbgVal, auto &Container) {
LLVM_DEBUG(dbgs() << " Deciding: ");
LLVM_DEBUG(DbgVal->print(dbgs()));
Expand Down Expand Up @@ -641,14 +643,14 @@ void MergeFunctions::filterInstsUnrelatedToPDI(

for (BasicBlock::iterator BI = GEntryBlock->begin(), BIE = GEntryBlock->end();
BI != BIE; ++BI) {
// Examine DPValues as they happen "before" the instruction. Are they
// connected to parameters?
for (DPValue &DPV : filterDbgVars(BI->getDbgRecordRange())) {
if (DPV.isDbgValue() || DPV.isDbgAssign()) {
ExamineDbgValue(&DPV, PDPVRelated);
// Examine DbgVariableRecords as they happen "before" the instruction. Are
// they connected to parameters?
for (DbgVariableRecord &DVR : filterDbgVars(BI->getDbgRecordRange())) {
if (DVR.isDbgValue() || DVR.isDbgAssign()) {
ExamineDbgValue(&DVR, PDVRRelated);
} else {
assert(DPV.isDbgDeclare());
ExamineDbgDeclare(&DPV, PDPVRelated);
assert(DVR.isDbgDeclare());
ExamineDbgDeclare(&DVR, PDVRRelated);
}
}

Expand Down Expand Up @@ -686,8 +688,8 @@ void MergeFunctions::filterInstsUnrelatedToPDI(

// Collect the set of unrelated instructions and debug records.
for (Instruction &I : *GEntryBlock) {
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange()))
IsPDIRelated(&DPV, PDPVRelated, PDPVUnrelatedWL);
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
IsPDIRelated(&DVR, PDVRRelated, PDVRUnrelatedWL);
IsPDIRelated(&I, PDIRelated, PDIUnrelatedWL);
}
LLVM_DEBUG(dbgs() << " }\n");
Expand Down Expand Up @@ -728,7 +730,7 @@ static void copyMetadataIfPresent(Function *From, Function *To, StringRef Key) {
void MergeFunctions::writeThunk(Function *F, Function *G) {
BasicBlock *GEntryBlock = nullptr;
std::vector<Instruction *> PDIUnrelatedWL;
std::vector<DPValue *> PDPVUnrelatedWL;
std::vector<DbgVariableRecord *> PDVRUnrelatedWL;
BasicBlock *BB = nullptr;
Function *NewG = nullptr;
if (MergeFunctionsPDI) {
Expand All @@ -740,7 +742,7 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
dbgs() << "writeThunk: (MergeFunctionsPDI) filter parameter related "
"debug info for "
<< G->getName() << "() {\n");
filterInstsUnrelatedToPDI(GEntryBlock, PDIUnrelatedWL, PDPVUnrelatedWL);
filterInstsUnrelatedToPDI(GEntryBlock, PDIUnrelatedWL, PDVRUnrelatedWL);
GEntryBlock->getTerminator()->eraseFromParent();
BB = GEntryBlock;
} else {
Expand Down Expand Up @@ -790,7 +792,7 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
<< G->getName() << "()\n");
}
eraseTail(G);
eraseInstsUnrelatedToPDI(PDIUnrelatedWL, PDPVUnrelatedWL);
eraseInstsUnrelatedToPDI(PDIUnrelatedWL, PDVRUnrelatedWL);
LLVM_DEBUG(
dbgs() << "} // End of parameter related debug info filtering for: "
<< G->getName() << "()\n");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
FunctionAnalysisManager &FAM =
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();

// RemoveDIs: there's no bitcode representation of the DPValue debug-info,
// convert to dbg.values before writing out.
// RemoveDIs: there's no bitcode representation of the DbgVariableRecord
// debug-info, convert to dbg.values before writing out.
bool ConvertToOldDbgFormatForWrite =
M.IsNewDbgInfoFormat && !WriteNewDbgInfoFormatToBitcode;
if (ConvertToOldDbgFormatForWrite)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Instruction *InstCombinerImpl::SimplifyAnyMemSet(AnyMemSetInst *MI) {
DbgAssign->replaceVariableLocationOp(FillC, FillVal);
};
for_each(at::getAssignmentMarkers(S), replaceOpForAssignmentMarkers);
for_each(at::getDPVAssignmentMarkers(S), replaceOpForAssignmentMarkers);
for_each(at::getDVRAssignmentMarkers(S), replaceOpForAssignmentMarkers);

S->setAlignment(Alignment);
if (isa<AtomicMemSetInst>(MI))
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,9 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
void tryToSinkInstructionDbgValues(
Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
BasicBlock *DestBlock, SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers);
void tryToSinkInstructionDPValues(Instruction *I,
BasicBlock::iterator InsertPos,
BasicBlock *SrcBlock, BasicBlock *DestBlock,
SmallVectorImpl<DPValue *> &DPUsers);
void tryToSinkInstructionDbgVariableRecords(
Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
BasicBlock *DestBlock, SmallVectorImpl<DbgVariableRecord *> &DPUsers);

bool removeInstructionsBeforeUnreachable(Instruction &I);
void addDeadEdge(BasicBlock *From, BasicBlock *To,
Expand Down
136 changes: 69 additions & 67 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3120,10 +3120,10 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
// If we are removing an alloca with a dbg.declare, insert dbg.value calls
// before each store.
SmallVector<DbgVariableIntrinsic *, 8> DVIs;
SmallVector<DPValue *, 8> DPVs;
SmallVector<DbgVariableRecord *, 8> DVRs;
std::unique_ptr<DIBuilder> DIB;
if (isa<AllocaInst>(MI)) {
findDbgUsers(DVIs, &MI, &DPVs);
findDbgUsers(DVIs, &MI, &DVRs);
DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false));
}

Expand Down Expand Up @@ -3163,9 +3163,9 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
for (auto *DVI : DVIs)
if (DVI->isAddressOfVariable())
ConvertDebugDeclareToDebugValue(DVI, SI, *DIB);
for (auto *DPV : DPVs)
if (DPV->isAddressOfVariable())
ConvertDebugDeclareToDebugValue(DPV, SI, *DIB);
for (auto *DVR : DVRs)
if (DVR->isAddressOfVariable())
ConvertDebugDeclareToDebugValue(DVR, SI, *DIB);
} else {
// Casts, GEP, or anything else: we're about to delete this instruction,
// so it can not have any valid uses.
Expand Down Expand Up @@ -3210,9 +3210,9 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
for (auto *DVI : DVIs)
if (DVI->isAddressOfVariable() || DVI->getExpression()->startsWithDeref())
DVI->eraseFromParent();
for (auto *DPV : DPVs)
if (DPV->isAddressOfVariable() || DPV->getExpression()->startsWithDeref())
DPV->eraseFromParent();
for (auto *DVR : DVRs)
if (DVR->isAddressOfVariable() || DVR->getExpression()->startsWithDeref())
DVR->eraseFromParent();

return eraseInstFromFunction(MI);
}
Expand Down Expand Up @@ -4613,12 +4613,13 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
// mark the location undef: we know it was supposed to receive a new location
// here, but that computation has been sunk.
SmallVector<DbgVariableIntrinsic *, 2> DbgUsers;
SmallVector<DPValue *, 2> DPValues;
findDbgUsers(DbgUsers, I, &DPValues);
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
findDbgUsers(DbgUsers, I, &DbgVariableRecords);
if (!DbgUsers.empty())
tryToSinkInstructionDbgValues(I, InsertPos, SrcBlock, DestBlock, DbgUsers);
if (!DPValues.empty())
tryToSinkInstructionDPValues(I, InsertPos, SrcBlock, DestBlock, DPValues);
if (!DbgVariableRecords.empty())
tryToSinkInstructionDbgVariableRecords(I, InsertPos, SrcBlock, DestBlock,
DbgVariableRecords);

// PS: there are numerous flaws with this behaviour, not least that right now
// assignments can be re-ordered past other assignments to the same variable
Expand Down Expand Up @@ -4691,47 +4692,48 @@ void InstCombinerImpl::tryToSinkInstructionDbgValues(
}
}

void InstCombinerImpl::tryToSinkInstructionDPValues(
void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords(
Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
BasicBlock *DestBlock, SmallVectorImpl<DPValue *> &DPValues) {
// Implementation of tryToSinkInstructionDbgValues, but for the DPValue of
// variable assignments rather than dbg.values.

// Fetch all DPValues not already in the destination.
SmallVector<DPValue *, 2> DPValuesToSalvage;
for (auto &DPV : DPValues)
if (DPV->getParent() != DestBlock)
DPValuesToSalvage.push_back(DPV);

// Fetch a second collection, of DPValues in the source block that we're going
// to sink.
SmallVector<DPValue *> DPValuesToSink;
for (DPValue *DPV : DPValuesToSalvage)
if (DPV->getParent() == SrcBlock)
DPValuesToSink.push_back(DPV);

// Sort DPValues according to their position in the block. This is a partial
// order: DPValues attached to different instructions will be ordered by the
// instruction order, but DPValues attached to the same instruction won't
// have an order.
auto Order = [](DPValue *A, DPValue *B) -> bool {
BasicBlock *DestBlock,
SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
// Implementation of tryToSinkInstructionDbgValues, but for the
// DbgVariableRecord of variable assignments rather than dbg.values.

// Fetch all DbgVariableRecords not already in the destination.
SmallVector<DbgVariableRecord *, 2> DbgVariableRecordsToSalvage;
for (auto &DVR : DbgVariableRecords)
if (DVR->getParent() != DestBlock)
DbgVariableRecordsToSalvage.push_back(DVR);

// Fetch a second collection, of DbgVariableRecords in the source block that
// we're going to sink.
SmallVector<DbgVariableRecord *> DbgVariableRecordsToSink;
for (DbgVariableRecord *DVR : DbgVariableRecordsToSalvage)
if (DVR->getParent() == SrcBlock)
DbgVariableRecordsToSink.push_back(DVR);

// Sort DbgVariableRecords according to their position in the block. This is a
// partial order: DbgVariableRecords attached to different instructions will
// be ordered by the instruction order, but DbgVariableRecords attached to the
// same instruction won't have an order.
auto Order = [](DbgVariableRecord *A, DbgVariableRecord *B) -> bool {
return B->getInstruction()->comesBefore(A->getInstruction());
};
llvm::stable_sort(DPValuesToSink, Order);
llvm::stable_sort(DbgVariableRecordsToSink, Order);

// If there are two assignments to the same variable attached to the same
// instruction, the ordering between the two assignments is important. Scan
// for this (rare) case and establish which is the last assignment.
using InstVarPair = std::pair<const Instruction *, DebugVariable>;
SmallDenseMap<InstVarPair, DPValue *> FilterOutMap;
if (DPValuesToSink.size() > 1) {
SmallDenseMap<InstVarPair, DbgVariableRecord *> FilterOutMap;
if (DbgVariableRecordsToSink.size() > 1) {
SmallDenseMap<InstVarPair, unsigned> CountMap;
// Count how many assignments to each variable there is per instruction.
for (DPValue *DPV : DPValuesToSink) {
for (DbgVariableRecord *DVR : DbgVariableRecordsToSink) {
DebugVariable DbgUserVariable =
DebugVariable(DPV->getVariable(), DPV->getExpression(),
DPV->getDebugLoc()->getInlinedAt());
CountMap[std::make_pair(DPV->getInstruction(), DbgUserVariable)] += 1;
DebugVariable(DVR->getVariable(), DVR->getExpression(),
DVR->getDebugLoc()->getInlinedAt());
CountMap[std::make_pair(DVR->getInstruction(), DbgUserVariable)] += 1;
}

// If there are any instructions with two assignments, add them to the
Expand All @@ -4747,74 +4749,74 @@ void InstCombinerImpl::tryToSinkInstructionDPValues(
// For all instruction/variable pairs needing extra filtering, find the
// latest assignment.
for (const Instruction *Inst : DupSet) {
for (DPValue &DPV :
for (DbgVariableRecord &DVR :
llvm::reverse(filterDbgVars(Inst->getDbgRecordRange()))) {
DebugVariable DbgUserVariable =
DebugVariable(DPV.getVariable(), DPV.getExpression(),
DPV.getDebugLoc()->getInlinedAt());
DebugVariable(DVR.getVariable(), DVR.getExpression(),
DVR.getDebugLoc()->getInlinedAt());
auto FilterIt =
FilterOutMap.find(std::make_pair(Inst, DbgUserVariable));
if (FilterIt == FilterOutMap.end())
continue;
if (FilterIt->second != nullptr)
continue;
FilterIt->second = &DPV;
FilterIt->second = &DVR;
}
}
}

// Perform cloning of the DPValues that we plan on sinking, filter out any
// duplicate assignments identified above.
SmallVector<DPValue *, 2> DPVClones;
// Perform cloning of the DbgVariableRecords that we plan on sinking, filter
// out any duplicate assignments identified above.
SmallVector<DbgVariableRecord *, 2> DVRClones;
SmallSet<DebugVariable, 4> SunkVariables;
for (DPValue *DPV : DPValuesToSink) {
if (DPV->Type == DPValue::LocationType::Declare)
for (DbgVariableRecord *DVR : DbgVariableRecordsToSink) {
if (DVR->Type == DbgVariableRecord::LocationType::Declare)
continue;

DebugVariable DbgUserVariable =
DebugVariable(DPV->getVariable(), DPV->getExpression(),
DPV->getDebugLoc()->getInlinedAt());
DebugVariable(DVR->getVariable(), DVR->getExpression(),
DVR->getDebugLoc()->getInlinedAt());

// For any variable where there were multiple assignments in the same place,
// ignore all but the last assignment.
if (!FilterOutMap.empty()) {
InstVarPair IVP = std::make_pair(DPV->getInstruction(), DbgUserVariable);
InstVarPair IVP = std::make_pair(DVR->getInstruction(), DbgUserVariable);
auto It = FilterOutMap.find(IVP);

// Filter out.
if (It != FilterOutMap.end() && It->second != DPV)
if (It != FilterOutMap.end() && It->second != DVR)
continue;
}

if (!SunkVariables.insert(DbgUserVariable).second)
continue;

if (DPV->isDbgAssign())
if (DVR->isDbgAssign())
continue;

DPVClones.emplace_back(DPV->clone());
LLVM_DEBUG(dbgs() << "CLONE: " << *DPVClones.back() << '\n');
DVRClones.emplace_back(DVR->clone());
LLVM_DEBUG(dbgs() << "CLONE: " << *DVRClones.back() << '\n');
}

// Perform salvaging without the clones, then sink the clones.
if (DPVClones.empty())
if (DVRClones.empty())
return;

salvageDebugInfoForDbgValues(*I, {}, DPValuesToSalvage);
salvageDebugInfoForDbgValues(*I, {}, DbgVariableRecordsToSalvage);

// The clones are in reverse order of original appearance. Assert that the
// head bit is set on the iterator as we _should_ have received it via
// getFirstInsertionPt. Inserting like this will reverse the clone order as
// we'll repeatedly insert at the head, such as:
// DPV-3 (third insertion goes here)
// DPV-2 (second insertion goes here)
// DPV-1 (first insertion goes here)
// Any-Prior-DPVs
// DVR-3 (third insertion goes here)
// DVR-2 (second insertion goes here)
// DVR-1 (first insertion goes here)
// Any-Prior-DVRs
// InsertPtInst
assert(InsertPos.getHeadBit());
for (DPValue *DPVClone : DPVClones) {
InsertPos->getParent()->insertDbgRecordBefore(DPVClone, InsertPos);
LLVM_DEBUG(dbgs() << "SINK: " << *DPVClone << '\n');
for (DbgVariableRecord *DVRClone : DVRClones) {
InsertPos->getParent()->insertDbgRecordBefore(DVRClone, InsertPos);
LLVM_DEBUG(dbgs() << "SINK: " << *DVRClone << '\n');
}
}

Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,8 @@ static DbgAssignIntrinsic *DynCastToDbgAssign(DbgVariableIntrinsic *DVI) {
return dyn_cast<DbgAssignIntrinsic>(DVI);
}

static DPValue *DynCastToDbgAssign(DPValue *DPV) {
return DPV->isDbgAssign() ? DPV : nullptr;
static DbgVariableRecord *DynCastToDbgAssign(DbgVariableRecord *DVR) {
return DVR->isDbgAssign() ? DVR : nullptr;
}

bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
Expand Down Expand Up @@ -1441,7 +1441,8 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
});

// Helper utility for adding DW_OP_LLVM_tag_offset to debug-info records,
// abstracted over whether they're intrinsic-stored or DPValue stored.
// abstracted over whether they're intrinsic-stored or DbgVariableRecord
// stored.
auto AnnotateDbgRecord = [&](auto *DPtr) {
// Prepend "tag_offset, N" to the dwarf expression.
// Tag offset logically applies to the alloca pointer, and it makes sense
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/Transforms/Scalar/ADCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,16 @@ ADCEChanged AggressiveDeadCodeElimination::removeDeadInstructions() {
// value of the function, and may therefore be deleted safely.
// NOTE: We reuse the Worklist vector here for memory efficiency.
for (Instruction &I : llvm::reverse(instructions(F))) {
// With "RemoveDIs" debug-info stored in DPValue objects, debug-info
// attached to this instruction, and drop any for scopes that aren't alive,
// like the rest of this loop does. Extending support to assignment tracking
// is future work.
// With "RemoveDIs" debug-info stored in DbgVariableRecord objects,
// debug-info attached to this instruction, and drop any for scopes that
// aren't alive, like the rest of this loop does. Extending support to
// assignment tracking is future work.
for (DbgRecord &DR : make_early_inc_range(I.getDbgRecordRange())) {
// Avoid removing a DPV that is linked to instructions because it holds
// Avoid removing a DVR that is linked to instructions because it holds
// information about an existing store.
if (DPValue *DPV = dyn_cast<DPValue>(&DR); DPV && DPV->isDbgAssign())
if (!at::getAssignmentInsts(DPV).empty())
if (DbgVariableRecord *DVR = dyn_cast<DbgVariableRecord>(&DR);
DVR && DVR->isDbgAssign())
if (!at::getAssignmentInsts(DVR).empty())
continue;
if (AliveScopes.count(DR.getDebugLoc()->getScope()))
continue;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
// returned by getAssignmentMarkers so save a copy of the markers to iterate
// over.
auto LinkedRange = at::getAssignmentMarkers(Inst);
SmallVector<DPValue *> LinkedDPVAssigns = at::getDPVAssignmentMarkers(Inst);
SmallVector<DbgVariableRecord *> LinkedDVRAssigns =
at::getDVRAssignmentMarkers(Inst);
SmallVector<DbgAssignIntrinsic *> Linked(LinkedRange.begin(),
LinkedRange.end());
auto InsertAssignForOverlap = [&](auto *Assign) {
Expand Down Expand Up @@ -554,7 +555,7 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
NewAssign->setKillAddress();
};
for_each(Linked, InsertAssignForOverlap);
for_each(LinkedDPVAssigns, InsertAssignForOverlap);
for_each(LinkedDVRAssigns, InsertAssignForOverlap);
}

static bool tryToShorten(Instruction *DeadI, int64_t &DeadStart,
Expand Down
46 changes: 23 additions & 23 deletions llvm/lib/Transforms/Scalar/JumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ static bool replaceFoldableUses(Instruction *Cond, Value *ToVal,
Changed |= replaceNonLocalUsesWith(Cond, ToVal);
for (Instruction &I : reverse(*KnownAtEndOfBB)) {
// Replace any debug-info record users of Cond with ToVal.
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange()))
DPV.replaceVariableLocationOp(Cond, ToVal, true);
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
DVR.replaceVariableLocationOp(Cond, ToVal, true);

// Reached the Cond whose uses we are trying to replace, so there are no
// more uses.
Expand Down Expand Up @@ -1955,7 +1955,7 @@ void JumpThreadingPass::updateSSA(
SSAUpdater SSAUpdate;
SmallVector<Use *, 16> UsesToRename;
SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DPValue *, 4> DPValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;

for (Instruction &I : *BB) {
// Scan all uses of this instruction to see if it is used outside of its
Expand All @@ -1972,16 +1972,16 @@ void JumpThreadingPass::updateSSA(
}

// Find debug values outside of the block
findDbgValues(DbgValues, &I, &DPValues);
findDbgValues(DbgValues, &I, &DbgVariableRecords);
llvm::erase_if(DbgValues, [&](const DbgValueInst *DbgVal) {
return DbgVal->getParent() == BB;
});
llvm::erase_if(DPValues, [&](const DPValue *DPVal) {
return DPVal->getParent() == BB;
llvm::erase_if(DbgVariableRecords, [&](const DbgVariableRecord *DbgVarRec) {
return DbgVarRec->getParent() == BB;
});

// If there are no uses outside the block, we're done with this instruction.
if (UsesToRename.empty() && DbgValues.empty() && DPValues.empty())
if (UsesToRename.empty() && DbgValues.empty() && DbgVariableRecords.empty())
continue;
LLVM_DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n");

Expand All @@ -1994,11 +1994,11 @@ void JumpThreadingPass::updateSSA(

while (!UsesToRename.empty())
SSAUpdate.RewriteUse(*UsesToRename.pop_back_val());
if (!DbgValues.empty() || !DPValues.empty()) {
if (!DbgValues.empty() || !DbgVariableRecords.empty()) {
SSAUpdate.UpdateDebugValues(&I, DbgValues);
SSAUpdate.UpdateDebugValues(&I, DPValues);
SSAUpdate.UpdateDebugValues(&I, DbgVariableRecords);
DbgValues.clear();
DPValues.clear();
DbgVariableRecords.clear();
}

LLVM_DEBUG(dbgs() << "\n");
Expand Down Expand Up @@ -2041,11 +2041,11 @@ JumpThreadingPass::cloneInstructions(BasicBlock::iterator BI,
return true;
};

// Duplicate implementation of the above dbg.value code, using DPValues
// instead.
auto RetargetDPValueIfPossible = [&](DPValue *DPV) {
// Duplicate implementation of the above dbg.value code, using
// DbgVariableRecords instead.
auto RetargetDbgVariableRecordIfPossible = [&](DbgVariableRecord *DVR) {
SmallSet<std::pair<Value *, Value *>, 16> OperandsToRemap;
for (auto *Op : DPV->location_ops()) {
for (auto *Op : DVR->location_ops()) {
Instruction *OpInst = dyn_cast<Instruction>(Op);
if (!OpInst)
continue;
Expand All @@ -2056,7 +2056,7 @@ JumpThreadingPass::cloneInstructions(BasicBlock::iterator BI,
}

for (auto &[OldOp, MappedOp] : OperandsToRemap)
DPV->replaceVariableLocationOp(OldOp, MappedOp);
DVR->replaceVariableLocationOp(OldOp, MappedOp);
};

BasicBlock *RangeBB = BI->getParent();
Expand All @@ -2080,9 +2080,9 @@ JumpThreadingPass::cloneInstructions(BasicBlock::iterator BI,
cloneNoAliasScopes(NoAliasScopes, ClonedScopes, "thread", Context);

auto CloneAndRemapDbgInfo = [&](Instruction *NewInst, Instruction *From) {
auto DPVRange = NewInst->cloneDebugInfoFrom(From);
for (DPValue &DPV : filterDbgVars(DPVRange))
RetargetDPValueIfPossible(&DPV);
auto DVRRange = NewInst->cloneDebugInfoFrom(From);
for (DbgVariableRecord &DVR : filterDbgVars(DVRRange))
RetargetDbgVariableRecordIfPossible(&DVR);
};

// Clone the non-phi instructions of the source basic block into NewBB,
Expand All @@ -2109,15 +2109,15 @@ JumpThreadingPass::cloneInstructions(BasicBlock::iterator BI,
}
}

// There may be DPValues on the terminator, clone directly from marker
// to marker as there isn't an instruction there.
// There may be DbgVariableRecords on the terminator, clone directly from
// marker to marker as there isn't an instruction there.
if (BE != RangeBB->end() && BE->hasDbgRecords()) {
// Dump them at the end.
DPMarker *Marker = RangeBB->getMarker(BE);
DPMarker *EndMarker = NewBB->createMarker(NewBB->end());
auto DPVRange = EndMarker->cloneDebugInfoFrom(Marker, std::nullopt);
for (DPValue &DPV : filterDbgVars(DPVRange))
RetargetDPValueIfPossible(&DPV);
auto DVRRange = EndMarker->cloneDebugInfoFrom(Marker, std::nullopt);
for (DbgVariableRecord &DVR : filterDbgVars(DVRRange))
RetargetDbgVariableRecordIfPossible(&DVR);
}

return ValueMapping;
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6367,10 +6367,10 @@ struct DVIRecoveryRec {
DVIRecoveryRec(DbgValueInst *DbgValue)
: DbgRef(DbgValue), Expr(DbgValue->getExpression()),
HadLocationArgList(false) {}
DVIRecoveryRec(DPValue *DPV)
: DbgRef(DPV), Expr(DPV->getExpression()), HadLocationArgList(false) {}
DVIRecoveryRec(DbgVariableRecord *DVR)
: DbgRef(DVR), Expr(DVR->getExpression()), HadLocationArgList(false) {}

PointerUnion<DbgValueInst *, DPValue *> DbgRef;
PointerUnion<DbgValueInst *, DbgVariableRecord *> DbgRef;
DIExpression *Expr;
bool HadLocationArgList;
SmallVector<WeakVH, 2> LocationOps;
Expand Down Expand Up @@ -6466,7 +6466,7 @@ static void UpdateDbgValueInst(DVIRecoveryRec &DVIRec,
if (isa<DbgValueInst *>(DVIRec.DbgRef))
UpdateDbgValueInstImpl(cast<DbgValueInst *>(DVIRec.DbgRef));
else
UpdateDbgValueInstImpl(cast<DPValue *>(DVIRec.DbgRef));
UpdateDbgValueInstImpl(cast<DbgVariableRecord *>(DVIRec.DbgRef));
}

/// Cached location ops may be erased during LSR, in which case a poison is
Expand Down Expand Up @@ -6512,7 +6512,7 @@ static void restorePreTransformState(DVIRecoveryRec &DVIRec) {
if (isa<DbgValueInst *>(DVIRec.DbgRef))
RestorePreTransformStateImpl(cast<DbgValueInst *>(DVIRec.DbgRef));
else
RestorePreTransformStateImpl(cast<DPValue *>(DVIRec.DbgRef));
RestorePreTransformStateImpl(cast<DbgVariableRecord *>(DVIRec.DbgRef));
}

static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE,
Expand All @@ -6522,7 +6522,7 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE,

if (isa<DbgValueInst *>(DVIRec.DbgRef)
? !cast<DbgValueInst *>(DVIRec.DbgRef)->isKillLocation()
: !cast<DPValue *>(DVIRec.DbgRef)->isKillLocation())
: !cast<DbgVariableRecord *>(DVIRec.DbgRef)->isKillLocation())
return false;

// LSR may have caused several changes to the dbg.value in the failed salvage
Expand Down Expand Up @@ -6620,7 +6620,7 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE,
<< *cast<DbgValueInst *>(DVIRec.DbgRef) << "\n");
else
LLVM_DEBUG(dbgs() << "scev-salvage: Updated DVI: "
<< *cast<DPValue *>(DVIRec.DbgRef) << "\n");
<< *cast<DbgVariableRecord *>(DVIRec.DbgRef) << "\n");
return true;
}

Expand Down Expand Up @@ -6711,9 +6711,9 @@ static void DbgGatherSalvagableDVI(
SalvageableDVISCEVs.push_back(std::move(NewRec));
return true;
};
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
if (DPV.isDbgValue() || DPV.isDbgAssign())
ProcessDbgValue(&DPV);
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (DVR.isDbgValue() || DVR.isDbgAssign())
ProcessDbgValue(&DVR);
}
auto DVI = dyn_cast<DbgValueInst>(&I);
if (!DVI)
Expand Down
48 changes: 24 additions & 24 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,17 @@ static DebugVariable getAggregateVariable(DbgVariableIntrinsic *DVI) {
return DebugVariable(DVI->getVariable(), std::nullopt,
DVI->getDebugLoc().getInlinedAt());
}
static DebugVariable getAggregateVariable(DPValue *DPV) {
return DebugVariable(DPV->getVariable(), std::nullopt,
DPV->getDebugLoc().getInlinedAt());
static DebugVariable getAggregateVariable(DbgVariableRecord *DVR) {
return DebugVariable(DVR->getVariable(), std::nullopt,
DVR->getDebugLoc().getInlinedAt());
}

/// Helpers for handling new and old debug info modes in migrateDebugInfo.
/// These overloads unwrap a DbgInstPtr {Instruction* | DbgRecord*} union based
/// on the \p Unused parameter type.
DPValue *UnwrapDbgInstPtr(DbgInstPtr P, DPValue *Unused) {
DbgVariableRecord *UnwrapDbgInstPtr(DbgInstPtr P, DbgVariableRecord *Unused) {
(void)Unused;
return static_cast<DPValue *>(cast<DbgRecord *>(P));
return static_cast<DbgVariableRecord *>(cast<DbgRecord *>(P));
}
DbgAssignIntrinsic *UnwrapDbgInstPtr(DbgInstPtr P, DbgAssignIntrinsic *Unused) {
(void)Unused;
Expand All @@ -356,9 +356,9 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
Instruction *Inst, Value *Dest, Value *Value,
const DataLayout &DL) {
auto MarkerRange = at::getAssignmentMarkers(OldInst);
auto DPVAssignMarkerRange = at::getDPVAssignmentMarkers(OldInst);
auto DVRAssignMarkerRange = at::getDVRAssignmentMarkers(OldInst);
// Nothing to do if OldInst has no linked dbg.assign intrinsics.
if (MarkerRange.empty() && DPVAssignMarkerRange.empty())
if (MarkerRange.empty() && DVRAssignMarkerRange.empty())
return;

LLVM_DEBUG(dbgs() << " migrateDebugInfo\n");
Expand All @@ -379,9 +379,9 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
for (auto *DAI : at::getAssignmentMarkers(OldAlloca))
BaseFragments[getAggregateVariable(DAI)] =
DAI->getExpression()->getFragmentInfo();
for (auto *DPV : at::getDPVAssignmentMarkers(OldAlloca))
BaseFragments[getAggregateVariable(DPV)] =
DPV->getExpression()->getFragmentInfo();
for (auto *DVR : at::getDVRAssignmentMarkers(OldAlloca))
BaseFragments[getAggregateVariable(DVR)] =
DVR->getExpression()->getFragmentInfo();

// The new inst needs a DIAssignID unique metadata tag (if OldInst has
// one). It shouldn't already have one: assert this assumption.
Expand Down Expand Up @@ -488,7 +488,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
};

for_each(MarkerRange, MigrateDbgAssign);
for_each(DPVAssignMarkerRange, MigrateDbgAssign);
for_each(DVRAssignMarkerRange, MigrateDbgAssign);
}

namespace {
Expand Down Expand Up @@ -3195,7 +3195,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
// emit dbg.assign intrinsics for mem intrinsics storing through non-
// constant geps, or storing a variable number of bytes.
assert(at::getAssignmentMarkers(&II).empty() &&
at::getDPVAssignmentMarkers(&II).empty() &&
at::getDVRAssignmentMarkers(&II).empty() &&
"AT: Unexpected link to non-const GEP");
deleteIfTriviallyDead(OldPtr);
return false;
Expand Down Expand Up @@ -3350,7 +3350,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
DbgAssign->replaceVariableLocationOp(II.getDest(), AdjustedPtr);
};
for_each(at::getAssignmentMarkers(&II), UpdateAssignAddress);
for_each(at::getDPVAssignmentMarkers(&II), UpdateAssignAddress);
for_each(at::getDVRAssignmentMarkers(&II), UpdateAssignAddress);
II.setDest(AdjustedPtr);
II.setDestAlignment(SliceAlign);
} else {
Expand Down Expand Up @@ -3939,7 +3939,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
DL);
} else {
assert(at::getAssignmentMarkers(Store).empty() &&
at::getDPVAssignmentMarkers(Store).empty() &&
at::getDVRAssignmentMarkers(Store).empty() &&
"AT: unexpected debug.assign linked to store through "
"unbounded GEP");
}
Expand Down Expand Up @@ -5034,25 +5034,25 @@ static void insertNewDbgInst(DIBuilder &DIB, DbgAssignIntrinsic *Orig,
LLVM_DEBUG(dbgs() << "Created new assign intrinsic: " << *NewAssign << "\n");
(void)NewAssign;
}
static void insertNewDbgInst(DIBuilder &DIB, DPValue *Orig, AllocaInst *NewAddr,
DIExpression *NewFragmentExpr,
static void insertNewDbgInst(DIBuilder &DIB, DbgVariableRecord *Orig,
AllocaInst *NewAddr, DIExpression *NewFragmentExpr,
Instruction *BeforeInst) {
(void)DIB;
if (Orig->isDbgDeclare()) {
DPValue *DPV = DPValue::createDPVDeclare(
DbgVariableRecord *DVR = DbgVariableRecord::createDVRDeclare(
NewAddr, Orig->getVariable(), NewFragmentExpr, Orig->getDebugLoc());
BeforeInst->getParent()->insertDbgRecordBefore(DPV,
BeforeInst->getParent()->insertDbgRecordBefore(DVR,
BeforeInst->getIterator());
return;
}
if (!NewAddr->hasMetadata(LLVMContext::MD_DIAssignID)) {
NewAddr->setMetadata(LLVMContext::MD_DIAssignID,
DIAssignID::getDistinct(NewAddr->getContext()));
}
DPValue *NewAssign = DPValue::createLinkedDPVAssign(
DbgVariableRecord *NewAssign = DbgVariableRecord::createLinkedDVRAssign(
NewAddr, Orig->getValue(), Orig->getVariable(), NewFragmentExpr, NewAddr,
Orig->getAddressExpression(), Orig->getDebugLoc());
LLVM_DEBUG(dbgs() << "Created new DPVAssign: " << *NewAssign << "\n");
LLVM_DEBUG(dbgs() << "Created new DVRAssign: " << *NewAssign << "\n");
(void)NewAssign;
}

Expand Down Expand Up @@ -5220,7 +5220,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
OldDII->eraseFromParent();
};
for_each(findDbgDeclares(Fragment.Alloca), RemoveOne);
for_each(findDPVDeclares(Fragment.Alloca), RemoveOne);
for_each(findDVRDeclares(Fragment.Alloca), RemoveOne);

insertNewDbgInst(DIB, DbgVariable, Fragment.Alloca, FragmentExpr, &AI);
}
Expand All @@ -5229,9 +5229,9 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
// Migrate debug information from the old alloca to the new alloca(s)
// and the individual partitions.
for_each(findDbgDeclares(&AI), MigrateOne);
for_each(findDPVDeclares(&AI), MigrateOne);
for_each(findDVRDeclares(&AI), MigrateOne);
for_each(at::getAssignmentMarkers(&AI), MigrateOne);
for_each(at::getDPVAssignmentMarkers(&AI), MigrateOne);
for_each(at::getDVRAssignmentMarkers(&AI), MigrateOne);

return Changed;
}
Expand Down Expand Up @@ -5355,7 +5355,7 @@ bool SROA::deleteDeadInstructions(
DeletedAllocas.insert(AI);
for (DbgDeclareInst *OldDII : findDbgDeclares(AI))
OldDII->eraseFromParent();
for (DPValue *OldDII : findDPVDeclares(AI))
for (DbgVariableRecord *OldDII : findDVRDeclares(AI))
OldDII->eraseFromParent();
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,9 @@ static BasicBlock *buildClonedLoopBlocks(
Module *M = ClonedPH->getParent()->getParent();
for (auto *ClonedBB : NewBlocks)
for (Instruction &I : *ClonedBB) {
RemapDPValueRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapInstruction(&I, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
if (auto *II = dyn_cast<AssumeInst>(&I))
Expand Down
23 changes: 12 additions & 11 deletions llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ static InstructionCost ComputeSpeculationCost(const Instruction *I,
bool SpeculativeExecutionPass::considerHoistingFromTo(
BasicBlock &FromBlock, BasicBlock &ToBlock) {
SmallPtrSet<const Instruction *, 8> NotHoisted;
SmallDenseMap<const Instruction *, SmallVector<DPValue *>> DPValuesToHoist;
SmallDenseMap<const Instruction *, SmallVector<DbgVariableRecord *>>
DbgVariableRecordsToHoist;
auto HasNoUnhoistedInstr = [&NotHoisted](auto Values) {
for (const Value *V : Values) {
if (const auto *I = dyn_cast_or_null<Instruction>(V))
Expand Down Expand Up @@ -291,11 +292,11 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
InstructionCost TotalSpeculationCost = 0;
unsigned NotHoistedInstCount = 0;
for (const auto &I : FromBlock) {
// Make note of any DPValues that need hoisting. DPLabels
// Make note of any DbgVariableRecords that need hoisting. DPLabels
// get left behind just like llvm.dbg.labels.
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
if (HasNoUnhoistedInstr(DPV.location_ops()))
DPValuesToHoist[DPV.getInstruction()].push_back(&DPV);
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (HasNoUnhoistedInstr(DVR.location_ops()))
DbgVariableRecordsToHoist[DVR.getInstruction()].push_back(&DVR);
}
const InstructionCost Cost = ComputeSpeculationCost(&I, *TTI);
if (Cost.isValid() && isSafeToSpeculativelyExecute(&I) &&
Expand All @@ -314,13 +315,13 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
}

for (auto I = FromBlock.begin(); I != FromBlock.end();) {
// If any DPValues attached to this instruction should be hoisted, hoist
// them now - they will end up attached to either the next hoisted
// If any DbgVariableRecords attached to this instruction should be hoisted,
// hoist them now - they will end up attached to either the next hoisted
// instruction or the ToBlock terminator.
if (DPValuesToHoist.contains(&*I)) {
for (auto *DPV : DPValuesToHoist[&*I]) {
DPV->removeFromParent();
ToBlock.insertDbgRecordBefore(DPV,
if (DbgVariableRecordsToHoist.contains(&*I)) {
for (auto *DVR : DbgVariableRecordsToHoist[&*I]) {
DVR->removeFromParent();
ToBlock.insertDbgRecordBefore(DVR,
ToBlock.getTerminator()->getIterator());
}
}
Expand Down
85 changes: 44 additions & 41 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ bool llvm::MergeBlockSuccessorsIntoGivenBlocks(
/// - Check fully overlapping fragments and not only identical fragments.
/// - Support dbg.declare. dbg.label, and possibly other meta instructions being
/// part of the sequence of consecutive instructions.
static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
SmallVector<DPValue *, 8> ToBeRemoved;
static bool
DbgVariableRecordsRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
SmallDenseSet<DebugVariable> VariableSet;
for (auto &I : reverse(*BB)) {
for (DbgRecord &DR : reverse(I.getDbgRecordRange())) {
Expand All @@ -394,10 +395,10 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
continue;
}

DPValue &DPV = cast<DPValue>(DR);
DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
// Skip declare-type records, as the debug intrinsic method only works
// on dbg.value intrinsics.
if (DPV.getType() == DPValue::LocationType::Declare) {
if (DVR.getType() == DbgVariableRecord::LocationType::Declare) {
// The debug intrinsic method treats dbg.declares are "non-debug"
// instructions (i.e., a break in a consecutive range of debug
// intrinsics). Emulate that to create identical outputs. See
Expand All @@ -407,23 +408,23 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
continue;
}

DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
DPV.getDebugLoc()->getInlinedAt());
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
DVR.getDebugLoc()->getInlinedAt());
auto R = VariableSet.insert(Key);
// If the same variable fragment is described more than once it is enough
// to keep the last one (i.e. the first found since we for reverse
// iteration).
if (R.second)
continue;

if (DPV.isDbgAssign()) {
if (DVR.isDbgAssign()) {
// Don't delete dbg.assign intrinsics that are linked to instructions.
if (!at::getAssignmentInsts(&DPV).empty())
if (!at::getAssignmentInsts(&DVR).empty())
continue;
// Unlinked dbg.assign intrinsics can be treated like dbg.values.
}

ToBeRemoved.push_back(&DPV);
ToBeRemoved.push_back(&DVR);
continue;
}
// Sequence with consecutive dbg.value instrs ended. Clear the map to
Expand All @@ -432,15 +433,15 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
VariableSet.clear();
}

for (auto &DPV : ToBeRemoved)
DPV->eraseFromParent();
for (auto &DVR : ToBeRemoved)
DVR->eraseFromParent();

return !ToBeRemoved.empty();
}

static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
if (BB->IsNewDbgInfoFormat)
return DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BB);
return DbgVariableRecordsRemoveRedundantDbgInstrsUsingBackwardScan(BB);

SmallVector<DbgValueInst *, 8> ToBeRemoved;
SmallDenseSet<DebugVariable> VariableSet;
Expand Down Expand Up @@ -499,29 +500,30 @@ static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
///
/// Possible improvements:
/// - Keep track of non-overlapping fragments.
static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
SmallVector<DPValue *, 8> ToBeRemoved;
static bool
DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
DenseMap<DebugVariable, std::pair<SmallVector<Value *, 4>, DIExpression *>>
VariableMap;
for (auto &I : *BB) {
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
if (DPV.getType() == DPValue::LocationType::Declare)
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (DVR.getType() == DbgVariableRecord::LocationType::Declare)
continue;
DebugVariable Key(DPV.getVariable(), std::nullopt,
DPV.getDebugLoc()->getInlinedAt());
DebugVariable Key(DVR.getVariable(), std::nullopt,
DVR.getDebugLoc()->getInlinedAt());
auto VMI = VariableMap.find(Key);
// A dbg.assign with no linked instructions can be treated like a
// dbg.value (i.e. can be deleted).
bool IsDbgValueKind =
(!DPV.isDbgAssign() || at::getAssignmentInsts(&DPV).empty());
(!DVR.isDbgAssign() || at::getAssignmentInsts(&DVR).empty());

// Update the map if we found a new value/expression describing the
// variable, or if the variable wasn't mapped already.
SmallVector<Value *, 4> Values(DPV.location_ops());
SmallVector<Value *, 4> Values(DVR.location_ops());
if (VMI == VariableMap.end() || VMI->second.first != Values ||
VMI->second.second != DPV.getExpression()) {
VMI->second.second != DVR.getExpression()) {
if (IsDbgValueKind)
VariableMap[Key] = {Values, DPV.getExpression()};
VariableMap[Key] = {Values, DVR.getExpression()};
else
VariableMap[Key] = {Values, nullptr};
continue;
Expand All @@ -530,55 +532,56 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
if (!IsDbgValueKind)
continue;
// Found an identical mapping. Remember the instruction for later removal.
ToBeRemoved.push_back(&DPV);
ToBeRemoved.push_back(&DVR);
}
}

for (auto *DPV : ToBeRemoved)
DPV->eraseFromParent();
for (auto *DVR : ToBeRemoved)
DVR->eraseFromParent();

return !ToBeRemoved.empty();
}

static bool DPValuesRemoveUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
static bool
DbgVariableRecordsRemoveUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
assert(BB->isEntryBlock() && "expected entry block");
SmallVector<DPValue *, 8> ToBeRemoved;
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
DenseSet<DebugVariable> SeenDefForAggregate;
// Returns the DebugVariable for DVI with no fragment info.
auto GetAggregateVariable = [](const DPValue &DPV) {
return DebugVariable(DPV.getVariable(), std::nullopt,
DPV.getDebugLoc().getInlinedAt());
auto GetAggregateVariable = [](const DbgVariableRecord &DVR) {
return DebugVariable(DVR.getVariable(), std::nullopt,
DVR.getDebugLoc().getInlinedAt());
};

// Remove undef dbg.assign intrinsics that are encountered before
// any non-undef intrinsics from the entry block.
for (auto &I : *BB) {
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
if (!DPV.isDbgValue() && !DPV.isDbgAssign())
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (!DVR.isDbgValue() && !DVR.isDbgAssign())
continue;
bool IsDbgValueKind =
(DPV.isDbgValue() || at::getAssignmentInsts(&DPV).empty());
DebugVariable Aggregate = GetAggregateVariable(DPV);
(DVR.isDbgValue() || at::getAssignmentInsts(&DVR).empty());
DebugVariable Aggregate = GetAggregateVariable(DVR);
if (!SeenDefForAggregate.contains(Aggregate)) {
bool IsKill = DPV.isKillLocation() && IsDbgValueKind;
bool IsKill = DVR.isKillLocation() && IsDbgValueKind;
if (!IsKill) {
SeenDefForAggregate.insert(Aggregate);
} else if (DPV.isDbgAssign()) {
ToBeRemoved.push_back(&DPV);
} else if (DVR.isDbgAssign()) {
ToBeRemoved.push_back(&DVR);
}
}
}
}

for (DPValue *DPV : ToBeRemoved)
DPV->eraseFromParent();
for (DbgVariableRecord *DVR : ToBeRemoved)
DVR->eraseFromParent();

return !ToBeRemoved.empty();
}

static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
if (BB->IsNewDbgInfoFormat)
return DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BB);
return DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BB);

SmallVector<DbgValueInst *, 8> ToBeRemoved;
DenseMap<DebugVariable, std::pair<SmallVector<Value *, 4>, DIExpression *>>
Expand Down Expand Up @@ -642,7 +645,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
/// - Keep track of non-overlapping fragments.
static bool removeUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
if (BB->IsNewDbgInfoFormat)
return DPValuesRemoveUndefDbgAssignsFromEntryBlock(BB);
return DbgVariableRecordsRemoveUndefDbgAssignsFromEntryBlock(BB);

assert(BB->isEntryBlock() && "expected entry block");
SmallVector<DbgAssignIntrinsic *, 8> ToBeRemoved;
Expand Down
24 changes: 13 additions & 11 deletions llvm/lib/Transforms/Utils/CloneFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
// attached debug-info records.
for (Instruction &II : *BB) {
RemapInstruction(&II, VMap, RemapFlag, TypeMapper, Materializer);
RemapDPValueRange(II.getModule(), II.getDbgRecordRange(), VMap, RemapFlag,
TypeMapper, Materializer);
RemapDbgVariableRecordRange(II.getModule(), II.getDbgRecordRange(), VMap,
RemapFlag, TypeMapper, Materializer);
}

// Only update !llvm.dbg.cu for DifferentModule (not CloneModule). In the
Expand Down Expand Up @@ -641,8 +641,8 @@ void PruningFunctionCloner::CloneBlock(
// Recursively clone any reachable successor blocks.
append_range(ToClone, successors(BB->getTerminator()));
} else {
// If we didn't create a new terminator, clone DPValues from the old
// terminator onto the new terminator.
// If we didn't create a new terminator, clone DbgVariableRecords from the
// old terminator onto the new terminator.
Instruction *NewInst = NewBB->getTerminator();
assert(NewInst);

Expand Down Expand Up @@ -884,14 +884,15 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
TypeMapper, Materializer);
}

// Do the same for DPValues, touching all the instructions in the cloned
// range of blocks.
// Do the same for DbgVariableRecords, touching all the instructions in the
// cloned range of blocks.
Function::iterator Begin = cast<BasicBlock>(VMap[StartingBB])->getIterator();
for (BasicBlock &BB : make_range(Begin, NewFunc->end())) {
for (Instruction &I : BB) {
RemapDPValueRange(I.getModule(), I.getDbgRecordRange(), VMap,
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
TypeMapper, Materializer);
RemapDbgVariableRecordRange(I.getModule(), I.getDbgRecordRange(), VMap,
ModuleLevelChanges ? RF_None
: RF_NoModuleLevelChanges,
TypeMapper, Materializer);
}
}

Expand Down Expand Up @@ -990,8 +991,9 @@ void llvm::remapInstructionsInBlocks(ArrayRef<BasicBlock *> Blocks,
// Rewrite the code to refer to itself.
for (auto *BB : Blocks) {
for (auto &Inst : *BB) {
RemapDPValueRange(Inst.getModule(), Inst.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(
Inst.getModule(), Inst.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapInstruction(&Inst, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
}
Expand Down
30 changes: 15 additions & 15 deletions llvm/lib/Transforms/Utils/CodeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,14 +1524,14 @@ void CodeExtractor::calculateNewCallTerminatorWeights(
static void eraseDebugIntrinsicsWithNonLocalRefs(Function &F) {
for (Instruction &I : instructions(F)) {
SmallVector<DbgVariableIntrinsic *, 4> DbgUsers;
SmallVector<DPValue *, 4> DPValues;
findDbgUsers(DbgUsers, &I, &DPValues);
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
findDbgUsers(DbgUsers, &I, &DbgVariableRecords);
for (DbgVariableIntrinsic *DVI : DbgUsers)
if (DVI->getFunction() != &F)
DVI->eraseFromParent();
for (DPValue *DPV : DPValues)
if (DPV->getFunction() != &F)
DPV->eraseFromParent();
for (DbgVariableRecord *DVR : DbgVariableRecords)
if (DVR->getFunction() != &F)
DVR->eraseFromParent();
}
}

Expand Down Expand Up @@ -1585,7 +1585,7 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
// point to a variable in the wrong scope.
SmallDenseMap<DINode *, DINode *> RemappedMetadata;
SmallVector<Instruction *, 4> DebugIntrinsicsToDelete;
SmallVector<DPValue *, 4> DPVsToDelete;
SmallVector<DbgVariableRecord *, 4> DVRsToDelete;
DenseMap<const MDNode *, MDNode *> Cache;

auto GetUpdatedDIVariable = [&](DILocalVariable *OldVar) {
Expand Down Expand Up @@ -1624,19 +1624,19 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
continue;
}

DPValue &DPV = cast<DPValue>(DR);
DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
// Apply the two updates that dbg.values get: invalid operands, and
// variable metadata fixup.
if (any_of(DPV.location_ops(), IsInvalidLocation)) {
DPVsToDelete.push_back(&DPV);
if (any_of(DVR.location_ops(), IsInvalidLocation)) {
DVRsToDelete.push_back(&DVR);
continue;
}
if (DPV.isDbgAssign() && IsInvalidLocation(DPV.getAddress())) {
DPVsToDelete.push_back(&DPV);
if (DVR.isDbgAssign() && IsInvalidLocation(DVR.getAddress())) {
DVRsToDelete.push_back(&DVR);
continue;
}
if (!DPV.getDebugLoc().getInlinedAt())
DPV.setVariable(GetUpdatedDIVariable(DPV.getVariable()));
if (!DVR.getDebugLoc().getInlinedAt())
DVR.setVariable(GetUpdatedDIVariable(DVR.getVariable()));
}
};

Expand Down Expand Up @@ -1674,8 +1674,8 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,

for (auto *DII : DebugIntrinsicsToDelete)
DII->eraseFromParent();
for (auto *DPV : DPVsToDelete)
DPV->getMarker()->MarkedInstr->dropOneDbgRecord(DPV);
for (auto *DVR : DVRsToDelete)
DVR->getMarker()->MarkedInstr->dropOneDbgRecord(DVR);
DIB.finalizeSubprogram(NewSP);

// Fix up the scope information attached to the line locations in the new
Expand Down
24 changes: 12 additions & 12 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,26 +1710,26 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
};

// Helper-util for updating debug-info records attached to instructions.
auto UpdateDPV = [&](DbgRecord *DPV) {
assert(DPV->getDebugLoc() && "Debug Value must have debug loc");
auto UpdateDVR = [&](DbgRecord *DVR) {
assert(DVR->getDebugLoc() && "Debug Value must have debug loc");
if (NoInlineLineTables) {
DPV->setDebugLoc(TheCallDL);
DVR->setDebugLoc(TheCallDL);
return;
}
DebugLoc DL = DPV->getDebugLoc();
DebugLoc DL = DVR->getDebugLoc();
DebugLoc IDL =
inlineDebugLoc(DL, InlinedAtNode,
DPV->getMarker()->getParent()->getContext(), IANodes);
DPV->setDebugLoc(IDL);
DVR->getMarker()->getParent()->getContext(), IANodes);
DVR->setDebugLoc(IDL);
};

// Iterate over all instructions, updating metadata and debug-info records.
for (; FI != Fn->end(); ++FI) {
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
++BI) {
UpdateInst(*BI);
for (DbgRecord &DPV : BI->getDbgRecordRange()) {
UpdateDPV(&DPV);
for (DbgRecord &DVR : BI->getDbgRecordRange()) {
UpdateDVR(&DVR);
}
}

Expand Down Expand Up @@ -1797,7 +1797,7 @@ static at::StorageToVarsMap collectEscapedLocals(const DataLayout &DL,
EscapedLocals[Base].insert(at::VarRecord(DbgAssign));
};
for_each(at::getAssignmentMarkers(Base), CollectAssignsForStorage);
for_each(at::getDPVAssignmentMarkers(Base), CollectAssignsForStorage);
for_each(at::getDVRAssignmentMarkers(Base), CollectAssignsForStorage);
}
return EscapedLocals;
}
Expand Down Expand Up @@ -1829,9 +1829,9 @@ static void fixupAssignments(Function::iterator Start, Function::iterator End) {
// attachment or use, replace it with a new version.
for (auto BBI = Start; BBI != End; ++BBI) {
for (Instruction &I : *BBI) {
for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
if (DPV.isDbgAssign())
DPV.setAssignId(GetNewID(DPV.getAssignID()));
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (DVR.isDbgAssign())
DVR.setAssignId(GetNewID(DVR.getAssignID()));
}
if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID))
I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID));
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Utils/LCSSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
}

SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DPValue *, 4> DPValues;
llvm::findDbgValues(DbgValues, I, &DPValues);
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);

// Update pre-existing debug value uses that reside outside the loop.
for (auto *DVI : DbgValues) {
Expand All @@ -261,8 +261,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,

// RemoveDIs: copy-paste of block above, using non-instruction debug-info
// records.
for (DPValue *DPV : DPValues) {
BasicBlock *UserBB = DPV->getMarker()->getParent();
for (DbgVariableRecord *DVR : DbgVariableRecords) {
BasicBlock *UserBB = DVR->getMarker()->getParent();
if (InstBB == UserBB || L->contains(UserBB))
continue;
// We currently only handle debug values residing in blocks that were
Expand All @@ -271,7 +271,7 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
Value *V = AddedPHIs.size() == 1 ? AddedPHIs[0]
: SSAUpdate.FindValueForBlock(UserBB);
if (V)
DPV->replaceVariableLocationOp(I, V);
DVR->replaceVariableLocationOp(I, V);
}

// SSAUpdater might have inserted phi-nodes inside other loops. We'll need
Expand Down
377 changes: 194 additions & 183 deletions llvm/lib/Transforms/Utils/Local.cpp

Large diffs are not rendered by default.

53 changes: 29 additions & 24 deletions llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
// Replace MetadataAsValue(ValueAsMetadata(OrigHeaderVal)) uses in debug
// intrinsics.
SmallVector<DbgValueInst *, 1> DbgValues;
SmallVector<DPValue *, 1> DPValues;
llvm::findDbgValues(DbgValues, OrigHeaderVal, &DPValues);
SmallVector<DbgVariableRecord *, 1> DbgVariableRecords;
llvm::findDbgValues(DbgValues, OrigHeaderVal, &DbgVariableRecords);
for (auto &DbgValue : DbgValues) {
// The original users in the OrigHeader are already using the original
// definitions.
Expand All @@ -183,11 +183,11 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
}

// RemoveDIs: duplicate implementation for non-instruction debug-info
// storage in DPValues.
for (DPValue *DPV : DPValues) {
// storage in DbgVariableRecords.
for (DbgVariableRecord *DVR : DbgVariableRecords) {
// The original users in the OrigHeader are already using the original
// definitions.
BasicBlock *UserBB = DPV->getMarker()->getParent();
BasicBlock *UserBB = DVR->getMarker()->getParent();
if (UserBB == OrigHeader)
continue;

Expand All @@ -202,7 +202,7 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
NewVal = SSA.GetValueInMiddleOfBlock(UserBB);
else
NewVal = UndefValue::get(OrigHeaderVal->getType());
DPV->replaceVariableLocationOp(OrigHeaderVal, NewVal);
DVR->replaceVariableLocationOp(OrigHeaderVal, NewVal);
}
}
}
Expand Down Expand Up @@ -552,20 +552,22 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
for (Instruction &I : llvm::drop_begin(llvm::reverse(*OrigPreheader))) {
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
DbgIntrinsics.insert(makeHash(DII));
// Until RemoveDIs supports dbg.declares in DPValue format, we'll need
// to collect DPValues attached to any other debug intrinsics.
for (const DPValue &DPV : filterDbgVars(DII->getDbgRecordRange()))
DbgIntrinsics.insert(makeHash(&DPV));
// Until RemoveDIs supports dbg.declares in DbgVariableRecord format,
// we'll need to collect DbgVariableRecords attached to any other debug
// intrinsics.
for (const DbgVariableRecord &DVR :
filterDbgVars(DII->getDbgRecordRange()))
DbgIntrinsics.insert(makeHash(&DVR));
} else {
break;
}
}

// Build DPValue hashes for DPValues attached to the terminator, which isn't
// considered in the loop above.
for (const DPValue &DPV :
// Build DbgVariableRecord hashes for DbgVariableRecords attached to the
// terminator, which isn't considered in the loop above.
for (const DbgVariableRecord &DVR :
filterDbgVars(OrigPreheader->getTerminator()->getDbgRecordRange()))
DbgIntrinsics.insert(makeHash(&DPV));
DbgIntrinsics.insert(makeHash(&DVR));

// Remember the local noalias scope declarations in the header. After the
// rotation, they must be duplicated and the scope must be cloned. This
Expand Down Expand Up @@ -627,13 +629,14 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
!NextDbgInsts.empty()) {
auto DbgValueRange =
LoopEntryBranch->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
RemapDPValueRange(M, DbgValueRange, ValueMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(M, DbgValueRange, ValueMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
// Erase anything we've seen before.
for (DPValue &DPV :
for (DbgVariableRecord &DVR :
make_early_inc_range(filterDbgVars(DbgValueRange)))
if (DbgIntrinsics.count(makeHash(&DPV)))
DPV.eraseFromParent();
if (DbgIntrinsics.count(makeHash(&DVR)))
DVR.eraseFromParent();
}

NextDbgInsts = I->getDbgRecordRange();
Expand All @@ -653,13 +656,15 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
if (LoopEntryBranch->getParent()->IsNewDbgInfoFormat &&
!NextDbgInsts.empty()) {
auto Range = C->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
RemapDPValueRange(M, Range, ValueMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(M, Range, ValueMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
NextDbgInsts = DPMarker::getEmptyDbgRecordRange();
// Erase anything we've seen before.
for (DPValue &DPV : make_early_inc_range(filterDbgVars(Range)))
if (DbgIntrinsics.count(makeHash(&DPV)))
DPV.eraseFromParent();
for (DbgVariableRecord &DVR :
make_early_inc_range(filterDbgVars(Range)))
if (DbgIntrinsics.count(makeHash(&DVR)))
DVR.eraseFromParent();
}

// Eagerly remap the operands of the instruction.
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,9 @@ bool llvm::UnrollRuntimeLoopRemainder(
for (Instruction &I : *BB) {
RemapInstruction(&I, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDPValueRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
}
}

Expand Down
26 changes: 13 additions & 13 deletions llvm/lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
// Use a map to unique and a vector to guarantee deterministic ordering.
llvm::SmallDenseSet<DebugVariable, 4> DeadDebugSet;
llvm::SmallVector<DbgVariableIntrinsic *, 4> DeadDebugInst;
llvm::SmallVector<DPValue *, 4> DeadDPValues;
llvm::SmallVector<DbgVariableRecord *, 4> DeadDbgVariableRecords;

if (ExitBlock) {
// Given LCSSA form is satisfied, we should not have users of instructions
Expand All @@ -631,17 +631,17 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
U.set(Poison);
}

// RemoveDIs: do the same as below for DPValues.
// RemoveDIs: do the same as below for DbgVariableRecords.
if (Block->IsNewDbgInfoFormat) {
for (DPValue &DPV : llvm::make_early_inc_range(
for (DbgVariableRecord &DVR : llvm::make_early_inc_range(
filterDbgVars(I.getDbgRecordRange()))) {
DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
DPV.getDebugLoc().get());
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
DVR.getDebugLoc().get());
if (!DeadDebugSet.insert(Key).second)
continue;
// Unlinks the DPV from it's container, for later insertion.
DPV.removeFromParent();
DeadDPValues.push_back(&DPV);
// Unlinks the DVR from it's container, for later insertion.
DVR.removeFromParent();
DeadDbgVariableRecords.push_back(&DVR);
}
}

Expand Down Expand Up @@ -673,11 +673,11 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
DVI->moveBefore(*ExitBlock, InsertDbgValueBefore);

// Due to the "head" bit in BasicBlock::iterator, we're going to insert
// each DPValue right at the start of the block, wheras dbg.values would be
// repeatedly inserted before the first instruction. To replicate this
// behaviour, do it backwards.
for (DPValue *DPV : llvm::reverse(DeadDPValues))
ExitBlock->insertDbgRecordBefore(DPV, InsertDbgValueBefore);
// each DbgVariableRecord right at the start of the block, wheras dbg.values
// would be repeatedly inserted before the first instruction. To replicate
// this behaviour, do it backwards.
for (DbgVariableRecord *DVR : llvm::reverse(DeadDbgVariableRecords))
ExitBlock->insertDbgRecordBefore(DVR, InsertDbgValueBefore);
}

// Remove the block from the reference counting scheme, so that we can
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void MemoryOpRemark::visitVariable(const Value *V,
}
};
for_each(findDbgDeclares(const_cast<Value *>(V)), FindDI);
for_each(findDPVDeclares(const_cast<Value *>(V)), FindDI);
for_each(findDVRDeclares(const_cast<Value *>(V)), FindDI);

if (FoundDI) {
assert(!Result.empty());
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ Instruction *getUntagLocationIfFunctionExit(Instruction &Inst) {

void StackInfoBuilder::visit(Instruction &Inst) {
// Visit non-intrinsic debug-info records attached to Inst.
for (DPValue &DPV : filterDbgVars(Inst.getDbgRecordRange())) {
for (DbgVariableRecord &DVR : filterDbgVars(Inst.getDbgRecordRange())) {
auto AddIfInteresting = [&](Value *V) {
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
if (!isInterestingAlloca(*AI))
return;
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
auto &DPVVec = AInfo.DbgVariableRecords;
if (DPVVec.empty() || DPVVec.back() != &DPV)
DPVVec.push_back(&DPV);
auto &DVRVec = AInfo.DbgVariableRecords;
if (DVRVec.empty() || DVRVec.back() != &DVR)
DVRVec.push_back(&DVR);
}
};

for_each(DPV.location_ops(), AddIfInteresting);
if (DPV.isDbgAssign())
AddIfInteresting(DPV.getAddress());
for_each(DVR.location_ops(), AddIfInteresting);
if (DVR.isDbgAssign())
AddIfInteresting(DVR.getAddress());
}

if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
Expand Down
70 changes: 36 additions & 34 deletions llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ namespace {
static void createDebugValue(DIBuilder &DIB, Value *NewValue,
DILocalVariable *Variable,
DIExpression *Expression, const DILocation *DI,
DPValue *InsertBefore) {
// FIXME: Merge these two functions now that DIBuilder supports DPValues.
// We neeed the API to accept DPValues as an insert point for that to work.
DbgVariableRecord *InsertBefore) {
// FIXME: Merge these two functions now that DIBuilder supports
// DbgVariableRecords. We neeed the API to accept DbgVariableRecords as an
// insert point for that to work.
(void)DIB;
DPValue::createDPValue(NewValue, Variable, Expression, DI, *InsertBefore);
DbgVariableRecord::createDbgVariableRecord(NewValue, Variable, Expression, DI,
*InsertBefore);
}
static void createDebugValue(DIBuilder &DIB, Value *NewValue,
DILocalVariable *Variable,
Expand All @@ -123,7 +125,7 @@ class AssignmentTrackingInfo {
/// fragment. (i.e. not be a comprehensive set if there are multiple
/// dbg.assigns for one variable fragment).
SmallVector<DbgVariableIntrinsic *> DbgAssigns;
SmallVector<DPValue *> DPVAssigns;
SmallVector<DbgVariableRecord *> DVRAssigns;

public:
void init(AllocaInst *AI) {
Expand All @@ -132,21 +134,21 @@ class AssignmentTrackingInfo {
if (Vars.insert(DebugVariable(DAI)).second)
DbgAssigns.push_back(DAI);
}
for (DPValue *DPV : at::getDPVAssignmentMarkers(AI)) {
if (Vars.insert(DebugVariable(DPV)).second)
DPVAssigns.push_back(DPV);
for (DbgVariableRecord *DVR : at::getDVRAssignmentMarkers(AI)) {
if (Vars.insert(DebugVariable(DVR)).second)
DVRAssigns.push_back(DVR);
}
}

/// Update assignment tracking debug info given for the to-be-deleted store
/// \p ToDelete that stores to this alloca.
void
updateForDeletedStore(StoreInst *ToDelete, DIBuilder &DIB,
SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DPValue *, 8> *DPVAssignsToDelete) const {
void updateForDeletedStore(
StoreInst *ToDelete, DIBuilder &DIB,
SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) const {
// There's nothing to do if the alloca doesn't have any variables using
// assignment tracking.
if (DbgAssigns.empty() && DPVAssigns.empty())
if (DbgAssigns.empty() && DVRAssigns.empty())
return;

// Insert a dbg.value where the linked dbg.assign is and remember to delete
Expand All @@ -165,8 +167,8 @@ class AssignmentTrackingInfo {
};
for (auto *Assign : at::getAssignmentMarkers(ToDelete))
InsertValueForAssign(Assign, DbgAssignsToDelete);
for (auto *Assign : at::getDPVAssignmentMarkers(ToDelete))
InsertValueForAssign(Assign, DPVAssignsToDelete);
for (auto *Assign : at::getDVRAssignmentMarkers(ToDelete))
InsertValueForAssign(Assign, DVRAssignsToDelete);

// It's possible for variables using assignment tracking to have no
// dbg.assign linked to this store. These are variables in DbgAssigns that
Expand All @@ -182,7 +184,7 @@ class AssignmentTrackingInfo {
ConvertDebugDeclareToDebugValue(Assign, ToDelete, DIB);
};
for_each(DbgAssigns, ConvertUnlinkedAssignToValue);
for_each(DPVAssigns, ConvertUnlinkedAssignToValue);
for_each(DVRAssigns, ConvertUnlinkedAssignToValue);
}

/// Update assignment tracking debug info given for the newly inserted PHI \p
Expand All @@ -193,20 +195,20 @@ class AssignmentTrackingInfo {
// debug-phi.
for (auto *DAI : DbgAssigns)
ConvertDebugDeclareToDebugValue(DAI, NewPhi, DIB);
for (auto *DPV : DPVAssigns)
ConvertDebugDeclareToDebugValue(DPV, NewPhi, DIB);
for (auto *DVR : DVRAssigns)
ConvertDebugDeclareToDebugValue(DVR, NewPhi, DIB);
}

void clear() {
DbgAssigns.clear();
DPVAssigns.clear();
DVRAssigns.clear();
}
bool empty() { return DbgAssigns.empty() && DPVAssigns.empty(); }
bool empty() { return DbgAssigns.empty() && DVRAssigns.empty(); }
};

struct AllocaInfo {
using DbgUserVec = SmallVector<DbgVariableIntrinsic *, 1>;
using DPUserVec = SmallVector<DPValue *, 1>;
using DPUserVec = SmallVector<DbgVariableRecord *, 1>;

SmallVector<BasicBlock *, 32> DefiningBlocks;
SmallVector<BasicBlock *, 32> UsingBlocks;
Expand Down Expand Up @@ -262,15 +264,15 @@ struct AllocaInfo {
}
}
DbgUserVec AllDbgUsers;
SmallVector<DPValue *> AllDPUsers;
SmallVector<DbgVariableRecord *> AllDPUsers;
findDbgUsers(AllDbgUsers, AI, &AllDPUsers);
std::copy_if(AllDbgUsers.begin(), AllDbgUsers.end(),
std::back_inserter(DbgUsers), [](DbgVariableIntrinsic *DII) {
return !isa<DbgAssignIntrinsic>(DII);
});
std::copy_if(AllDPUsers.begin(), AllDPUsers.end(),
std::back_inserter(DPUsers),
[](DPValue *DPV) { return !DPV->isDbgAssign(); });
[](DbgVariableRecord *DVR) { return !DVR->isDbgAssign(); });
AssignmentTracking.init(AI);
}
};
Expand Down Expand Up @@ -378,7 +380,7 @@ struct PromoteMem2Reg {
/// A set of dbg.assigns to delete because they've been demoted to
/// dbg.values. Call cleanUpDbgAssigns to delete them.
SmallSet<DbgAssignIntrinsic *, 8> DbgAssignsToDelete;
SmallSet<DPValue *, 8> DPVAssignsToDelete;
SmallSet<DbgVariableRecord *, 8> DVRAssignsToDelete;

/// The set of basic blocks the renamer has already visited.
SmallPtrSet<BasicBlock *, 16> Visited;
Expand Down Expand Up @@ -428,9 +430,9 @@ struct PromoteMem2Reg {
for (auto *DAI : DbgAssignsToDelete)
DAI->eraseFromParent();
DbgAssignsToDelete.clear();
for (auto *DPV : DPVAssignsToDelete)
DPV->eraseFromParent();
DPVAssignsToDelete.clear();
for (auto *DVR : DVRAssignsToDelete)
DVR->eraseFromParent();
DVRAssignsToDelete.clear();
}
};

Expand Down Expand Up @@ -508,7 +510,7 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
const DataLayout &DL, DominatorTree &DT,
AssumptionCache *AC,
SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DPValue *, 8> *DPVAssignsToDelete) {
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) {
StoreInst *OnlyStore = Info.OnlyStore;
bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
BasicBlock *StoreBB = OnlyStore->getParent();
Expand Down Expand Up @@ -569,7 +571,7 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
// Update assignment tracking info for the store we're going to delete.
Info.AssignmentTracking.updateForDeletedStore(
Info.OnlyStore, DIB, DbgAssignsToDelete, DPVAssignsToDelete);
Info.OnlyStore, DIB, DbgAssignsToDelete, DVRAssignsToDelete);

// Record debuginfo for the store and remove the declaration's
// debuginfo.
Expand Down Expand Up @@ -618,7 +620,7 @@ promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
LargeBlockInfo &LBI, const DataLayout &DL,
DominatorTree &DT, AssumptionCache *AC,
SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DPValue *, 8> *DPVAssignsToDelete) {
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) {
// The trickiest case to handle is when we have large blocks. Because of this,
// this code is optimized assuming that large blocks happen. This does not
// significantly pessimize the small block case. This uses LargeBlockInfo to
Expand Down Expand Up @@ -683,7 +685,7 @@ promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
StoreInst *SI = cast<StoreInst>(AI->user_back());
// Update assignment tracking info for the store we're going to delete.
Info.AssignmentTracking.updateForDeletedStore(SI, DIB, DbgAssignsToDelete,
DPVAssignsToDelete);
DVRAssignsToDelete);
// Record debuginfo for the store before removing it.
auto DbgUpdateForStore = [&](auto &Container) {
for (auto *DbgItem : Container) {
Expand Down Expand Up @@ -755,7 +757,7 @@ void PromoteMem2Reg::run() {
// it that are directly dominated by the definition with the value stored.
if (Info.DefiningBlocks.size() == 1) {
if (rewriteSingleStoreAlloca(AI, Info, LBI, SQ.DL, DT, AC,
&DbgAssignsToDelete, &DPVAssignsToDelete)) {
&DbgAssignsToDelete, &DVRAssignsToDelete)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
++NumSingleStore;
Expand All @@ -767,7 +769,7 @@ void PromoteMem2Reg::run() {
// linear sweep over the block to eliminate it.
if (Info.OnlyUsedInOneBlock &&
promoteSingleBlockAlloca(AI, Info, LBI, SQ.DL, DT, AC,
&DbgAssignsToDelete, &DPVAssignsToDelete)) {
&DbgAssignsToDelete, &DVRAssignsToDelete)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
continue;
Expand Down Expand Up @@ -1174,7 +1176,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
// Record debuginfo for the store before removing it.
IncomingLocs[AllocaNo] = SI->getDebugLoc();
AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB, &DbgAssignsToDelete,
&DPVAssignsToDelete);
&DVRAssignsToDelete);
auto ConvertDbgDeclares = [&](auto &Container) {
for (auto *DbgItem : Container)
if (DbgItem->isAddressOfVariable())
Expand Down
26 changes: 13 additions & 13 deletions llvm/lib/Transforms/Utils/SSAUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ void SSAUpdater::RewriteUse(Use &U) {

void SSAUpdater::UpdateDebugValues(Instruction *I) {
SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DPValue *, 4> DPValues;
llvm::findDbgValues(DbgValues, I, &DPValues);
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
for (auto &DbgValue : DbgValues) {
if (DbgValue->getParent() == I->getParent())
continue;
UpdateDebugValue(I, DbgValue);
}
for (auto &DPV : DPValues) {
if (DPV->getParent() == I->getParent())
for (auto &DVR : DbgVariableRecords) {
if (DVR->getParent() == I->getParent())
continue;
UpdateDebugValue(I, DPV);
UpdateDebugValue(I, DVR);
}
}

Expand All @@ -220,10 +220,10 @@ void SSAUpdater::UpdateDebugValues(Instruction *I,
}
}

void SSAUpdater::UpdateDebugValues(Instruction *I,
SmallVectorImpl<DPValue *> &DPValues) {
for (auto &DPV : DPValues) {
UpdateDebugValue(I, DPV);
void SSAUpdater::UpdateDebugValues(
Instruction *I, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
for (auto &DVR : DbgVariableRecords) {
UpdateDebugValue(I, DVR);
}
}

Expand All @@ -236,13 +236,13 @@ void SSAUpdater::UpdateDebugValue(Instruction *I, DbgValueInst *DbgValue) {
DbgValue->setKillLocation();
}

void SSAUpdater::UpdateDebugValue(Instruction *I, DPValue *DPV) {
BasicBlock *UserBB = DPV->getParent();
void SSAUpdater::UpdateDebugValue(Instruction *I, DbgVariableRecord *DVR) {
BasicBlock *UserBB = DVR->getParent();
if (HasValueForBlock(UserBB)) {
Value *NewVal = GetValueAtEndOfBlock(UserBB);
DPV->replaceVariableLocationOp(I, NewVal);
DVR->replaceVariableLocationOp(I, NewVal);
} else
DPV->setKillLocation();
DVR->setKillLocation();
}

void SSAUpdater::RewriteUseAfterInsertions(Use &U) {
Expand Down
Loading