aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp377
1 files changed, 194 insertions, 183 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 422319e..3d3b97e 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -609,12 +609,12 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(
bool llvm::replaceDbgUsesWithUndef(Instruction *I) {
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
- SmallVector<DPValue *, 1> DPUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
findDbgUsers(DbgUsers, I, &DPUsers);
for (auto *DII : DbgUsers)
DII->setKillLocation();
- for (auto *DPV : DPUsers)
- DPV->setKillLocation();
+ for (auto *DVR : DPUsers)
+ DVR->setKillLocation();
return !DbgUsers.empty() || !DPUsers.empty();
}
@@ -1570,16 +1570,16 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar,
// is removed by LowerDbgDeclare(), we need to make sure that we are
// not inserting the same dbg.value intrinsic over and over.
SmallVector<DbgValueInst *, 1> DbgValues;
- SmallVector<DPValue *, 1> DPValues;
- findDbgValues(DbgValues, APN, &DPValues);
+ SmallVector<DbgVariableRecord *, 1> DbgVariableRecords;
+ findDbgValues(DbgValues, APN, &DbgVariableRecords);
for (auto *DVI : DbgValues) {
assert(is_contained(DVI->getValues(), APN));
if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
return true;
}
- for (auto *DPV : DPValues) {
- assert(is_contained(DPV->location_ops(), APN));
- if ((DPV->getVariable() == DIVar) && (DPV->getExpression() == DIExpr))
+ for (auto *DVR : DbgVariableRecords) {
+ assert(is_contained(DVR->location_ops(), APN));
+ if ((DVR->getVariable() == DIVar) && (DVR->getExpression() == DIExpr))
return true;
}
return false;
@@ -1617,23 +1617,23 @@ static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII) {
// Could not determine size of variable. Conservatively return false.
return false;
}
-// RemoveDIs: duplicate implementation of the above, using DPValues, the
-// replacement for dbg.values.
-static bool valueCoversEntireFragment(Type *ValTy, DPValue *DPV) {
- const DataLayout &DL = DPV->getModule()->getDataLayout();
+// RemoveDIs: duplicate implementation of the above, using DbgVariableRecords,
+// the replacement for dbg.values.
+static bool valueCoversEntireFragment(Type *ValTy, DbgVariableRecord *DVR) {
+ const DataLayout &DL = DVR->getModule()->getDataLayout();
TypeSize ValueSize = DL.getTypeAllocSizeInBits(ValTy);
- if (std::optional<uint64_t> FragmentSize = DPV->getFragmentSizeInBits())
+ if (std::optional<uint64_t> FragmentSize = DVR->getFragmentSizeInBits())
return TypeSize::isKnownGE(ValueSize, TypeSize::getFixed(*FragmentSize));
// We can't always calculate the size of the DI variable (e.g. if it is a
// VLA). Try to use the size of the alloca that the dbg intrinsic describes
// intead.
- if (DPV->isAddressOfVariable()) {
- // DPV should have exactly 1 location when it is an address.
- assert(DPV->getNumVariableLocationOps() == 1 &&
+ if (DVR->isAddressOfVariable()) {
+ // DVR should have exactly 1 location when it is an address.
+ assert(DVR->getNumVariableLocationOps() == 1 &&
"address of variable must have exactly 1 location operand.");
if (auto *AI =
- dyn_cast_or_null<AllocaInst>(DPV->getVariableLocationOp(0))) {
+ dyn_cast_or_null<AllocaInst>(DVR->getVariableLocationOp(0))) {
if (std::optional<TypeSize> FragmentSize = AI->getAllocationSizeInBits(DL)) {
return TypeSize::isKnownGE(ValueSize, *FragmentSize);
}
@@ -1643,38 +1643,38 @@ static bool valueCoversEntireFragment(Type *ValTy, DPValue *DPV) {
return false;
}
-static void insertDbgValueOrDPValue(DIBuilder &Builder, Value *DV,
- DILocalVariable *DIVar,
- DIExpression *DIExpr,
- const DebugLoc &NewLoc,
- BasicBlock::iterator Instr) {
+static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV,
+ DILocalVariable *DIVar,
+ DIExpression *DIExpr,
+ const DebugLoc &NewLoc,
+ BasicBlock::iterator Instr) {
if (!UseNewDbgInfoFormat) {
auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
(Instruction *)nullptr);
DbgVal.get<Instruction *>()->insertBefore(Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
- // DPValue directly instead of a dbg.value intrinsic.
+ // DbgVariableRecord directly instead of a dbg.value intrinsic.
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
- DPValue *DV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get());
+ DbgVariableRecord *DV =
+ new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
Instr->getParent()->insertDbgRecordBefore(DV, Instr);
}
}
-static void insertDbgValueOrDPValueAfter(DIBuilder &Builder, Value *DV,
- DILocalVariable *DIVar,
- DIExpression *DIExpr,
- const DebugLoc &NewLoc,
- BasicBlock::iterator Instr) {
+static void insertDbgValueOrDbgVariableRecordAfter(
+ DIBuilder &Builder, Value *DV, DILocalVariable *DIVar, DIExpression *DIExpr,
+ const DebugLoc &NewLoc, BasicBlock::iterator Instr) {
if (!UseNewDbgInfoFormat) {
auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
(Instruction *)nullptr);
DbgVal.get<Instruction *>()->insertAfter(&*Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
- // DPValue directly instead of a dbg.value intrinsic.
+ // DbgVariableRecord directly instead of a dbg.value intrinsic.
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
- DPValue *DV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get());
+ DbgVariableRecord *DV =
+ new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
Instr->getParent()->insertDbgRecordAfter(DV, &*Instr);
}
}
@@ -1707,8 +1707,8 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
valueCoversEntireFragment(DV->getType(), DII));
if (CanConvert) {
- insertDbgValueOrDPValue(Builder, DV, DIVar, DIExpr, NewLoc,
- SI->getIterator());
+ insertDbgValueOrDbgVariableRecord(Builder, DV, DIVar, DIExpr, NewLoc,
+ SI->getIterator());
return;
}
@@ -1720,8 +1720,8 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
// know which part) we insert an dbg.value intrinsic to indicate that we
// know nothing about the variable's content.
DV = UndefValue::get(DV->getType());
- insertDbgValueOrDPValue(Builder, DV, DIVar, DIExpr, NewLoc,
- SI->getIterator());
+ insertDbgValueOrDbgVariableRecord(Builder, DV, DIVar, DIExpr, NewLoc,
+ SI->getIterator());
}
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
@@ -1747,19 +1747,19 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
// future if multi-location support is added to the IR, it might be
// preferable to keep tracking both the loaded value and the original
// address in case the alloca can not be elided.
- insertDbgValueOrDPValueAfter(Builder, LI, DIVar, DIExpr, NewLoc,
- LI->getIterator());
+ insertDbgValueOrDbgVariableRecordAfter(Builder, LI, DIVar, DIExpr, NewLoc,
+ LI->getIterator());
}
-void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
- DIBuilder &Builder) {
- assert(DPV->isAddressOfVariable() || DPV->isDbgAssign());
- auto *DIVar = DPV->getVariable();
+void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
+ StoreInst *SI, DIBuilder &Builder) {
+ assert(DVR->isAddressOfVariable() || DVR->isDbgAssign());
+ auto *DIVar = DVR->getVariable();
assert(DIVar && "Missing variable");
- auto *DIExpr = DPV->getExpression();
+ auto *DIExpr = DVR->getExpression();
Value *DV = SI->getValueOperand();
- DebugLoc NewLoc = getDebugValueLoc(DPV);
+ DebugLoc NewLoc = getDebugValueLoc(DVR);
// If the alloca describes the variable itself, i.e. the expression in the
// dbg.declare doesn't start with a dereference, we can perform the
@@ -1775,16 +1775,16 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
// deref expression.
bool CanConvert =
DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
- valueCoversEntireFragment(DV->getType(), DPV));
+ valueCoversEntireFragment(DV->getType(), DVR));
if (CanConvert) {
- insertDbgValueOrDPValue(Builder, DV, DIVar, DIExpr, NewLoc,
- SI->getIterator());
+ insertDbgValueOrDbgVariableRecord(Builder, DV, DIVar, DIExpr, NewLoc,
+ SI->getIterator());
return;
}
// FIXME: If storing to a part of the variable described by the dbg.declare,
// then we want to insert a dbg.value for the corresponding fragment.
- LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DPV
+ LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DVR
<< '\n');
assert(UseNewDbgInfoFormat);
@@ -1793,8 +1793,9 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
// know nothing about the variable's content.
DV = UndefValue::get(DV->getType());
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
- DPValue *NewDPV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get());
- SI->getParent()->insertDbgRecordBefore(NewDPV, SI->getIterator());
+ DbgVariableRecord *NewDVR =
+ new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
+ SI->getParent()->insertDbgRecordBefore(NewDVR, SI->getIterator());
}
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
@@ -1826,26 +1827,27 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
// insertion point.
// FIXME: Insert dbg.value markers in the successors when appropriate.
if (InsertionPt != BB->end()) {
- insertDbgValueOrDPValue(Builder, APN, DIVar, DIExpr, NewLoc, InsertionPt);
+ insertDbgValueOrDbgVariableRecord(Builder, APN, DIVar, DIExpr, NewLoc,
+ InsertionPt);
}
}
-void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, LoadInst *LI,
+void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, LoadInst *LI,
DIBuilder &Builder) {
- auto *DIVar = DPV->getVariable();
- auto *DIExpr = DPV->getExpression();
+ auto *DIVar = DVR->getVariable();
+ auto *DIExpr = DVR->getExpression();
assert(DIVar && "Missing variable");
- if (!valueCoversEntireFragment(LI->getType(), DPV)) {
+ if (!valueCoversEntireFragment(LI->getType(), DVR)) {
// FIXME: If only referring to a part of the variable described by the
- // dbg.declare, then we want to insert a DPValue for the corresponding
- // fragment.
- LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DPValue: " << *DPV
- << '\n');
+ // dbg.declare, then we want to insert a DbgVariableRecord for the
+ // corresponding fragment.
+ LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DbgVariableRecord: "
+ << *DVR << '\n');
return;
}
- DebugLoc NewLoc = getDebugValueLoc(DPV);
+ DebugLoc NewLoc = getDebugValueLoc(DVR);
// We are now tracking the loaded value instead of the address. In the
// future if multi-location support is added to the IR, it might be
@@ -1853,9 +1855,10 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, LoadInst *LI,
// address in case the alloca can not be elided.
assert(UseNewDbgInfoFormat);
- // Create a DPValue directly and insert.
+ // Create a DbgVariableRecord directly and insert.
ValueAsMetadata *LIVAM = ValueAsMetadata::get(LI);
- DPValue *DV = new DPValue(LIVAM, DIVar, DIExpr, NewLoc.get());
+ DbgVariableRecord *DV =
+ new DbgVariableRecord(LIVAM, DIVar, DIExpr, NewLoc.get());
LI->getParent()->insertDbgRecordAfter(DV, LI);
}
@@ -1869,34 +1872,35 @@ static bool isArray(AllocaInst *AI) {
static bool isStructure(AllocaInst *AI) {
return AI->getAllocatedType() && AI->getAllocatedType()->isStructTy();
}
-void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, PHINode *APN,
+void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, PHINode *APN,
DIBuilder &Builder) {
- auto *DIVar = DPV->getVariable();
- auto *DIExpr = DPV->getExpression();
+ auto *DIVar = DVR->getVariable();
+ auto *DIExpr = DVR->getExpression();
assert(DIVar && "Missing variable");
if (PhiHasDebugValue(DIVar, DIExpr, APN))
return;
- if (!valueCoversEntireFragment(APN->getType(), DPV)) {
+ if (!valueCoversEntireFragment(APN->getType(), DVR)) {
// FIXME: If only referring to a part of the variable described by the
- // dbg.declare, then we want to insert a DPValue for the corresponding
- // fragment.
- LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DPValue: " << *DPV
- << '\n');
+ // dbg.declare, then we want to insert a DbgVariableRecord for the
+ // corresponding fragment.
+ LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DbgVariableRecord: "
+ << *DVR << '\n');
return;
}
BasicBlock *BB = APN->getParent();
auto InsertionPt = BB->getFirstInsertionPt();
- DebugLoc NewLoc = getDebugValueLoc(DPV);
+ DebugLoc NewLoc = getDebugValueLoc(DVR);
// The block may be a catchswitch block, which does not have a valid
// insertion point.
- // FIXME: Insert DPValue markers in the successors when appropriate.
+ // FIXME: Insert DbgVariableRecord markers in the successors when appropriate.
if (InsertionPt != BB->end()) {
- insertDbgValueOrDPValue(Builder, APN, DIVar, DIExpr, NewLoc, InsertionPt);
+ insertDbgValueOrDbgVariableRecord(Builder, APN, DIVar, DIExpr, NewLoc,
+ InsertionPt);
}
}
@@ -1906,19 +1910,19 @@ bool llvm::LowerDbgDeclare(Function &F) {
bool Changed = false;
DIBuilder DIB(*F.getParent(), /*AllowUnresolved*/ false);
SmallVector<DbgDeclareInst *, 4> Dbgs;
- SmallVector<DPValue *> DPVs;
+ SmallVector<DbgVariableRecord *> DVRs;
for (auto &FI : F) {
for (Instruction &BI : FI) {
if (auto *DDI = dyn_cast<DbgDeclareInst>(&BI))
Dbgs.push_back(DDI);
- for (DPValue &DPV : filterDbgVars(BI.getDbgRecordRange())) {
- if (DPV.getType() == DPValue::LocationType::Declare)
- DPVs.push_back(&DPV);
+ for (DbgVariableRecord &DVR : filterDbgVars(BI.getDbgRecordRange())) {
+ if (DVR.getType() == DbgVariableRecord::LocationType::Declare)
+ DVRs.push_back(&DVR);
}
}
}
- if (Dbgs.empty() && DPVs.empty())
+ if (Dbgs.empty() && DVRs.empty())
return Changed;
auto LowerOne = [&](auto *DDI) {
@@ -1962,8 +1966,9 @@ bool llvm::LowerDbgDeclare(Function &F) {
DebugLoc NewLoc = getDebugValueLoc(DDI);
auto *DerefExpr =
DIExpression::append(DDI->getExpression(), dwarf::DW_OP_deref);
- insertDbgValueOrDPValue(DIB, AI, DDI->getVariable(), DerefExpr,
- NewLoc, CI->getIterator());
+ insertDbgValueOrDbgVariableRecord(DIB, AI, DDI->getVariable(),
+ DerefExpr, NewLoc,
+ CI->getIterator());
}
} else if (BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
if (BI->getType()->isPointerTy())
@@ -1976,7 +1981,7 @@ bool llvm::LowerDbgDeclare(Function &F) {
};
for_each(Dbgs, LowerOne);
- for_each(DPVs, LowerOne);
+ for_each(DVRs, LowerOne);
if (Changed)
for (BasicBlock &BB : F)
@@ -1986,35 +1991,39 @@ bool llvm::LowerDbgDeclare(Function &F) {
}
// RemoveDIs: re-implementation of insertDebugValuesForPHIs, but which pulls the
-// debug-info out of the block's DPValues rather than dbg.value intrinsics.
-static void insertDPValuesForPHIs(BasicBlock *BB,
- SmallVectorImpl<PHINode *> &InsertedPHIs) {
- assert(BB && "No BasicBlock to clone DPValue(s) from.");
+// debug-info out of the block's DbgVariableRecords rather than dbg.value
+// intrinsics.
+static void
+insertDbgVariableRecordsForPHIs(BasicBlock *BB,
+ SmallVectorImpl<PHINode *> &InsertedPHIs) {
+ assert(BB && "No BasicBlock to clone DbgVariableRecord(s) from.");
if (InsertedPHIs.size() == 0)
return;
- // Map existing PHI nodes to their DPValues.
- DenseMap<Value *, DPValue *> DbgValueMap;
+ // Map existing PHI nodes to their DbgVariableRecords.
+ DenseMap<Value *, DbgVariableRecord *> DbgValueMap;
for (auto &I : *BB) {
- for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
- for (Value *V : DPV.location_ops())
+ for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
+ for (Value *V : DVR.location_ops())
if (auto *Loc = dyn_cast_or_null<PHINode>(V))
- DbgValueMap.insert({Loc, &DPV});
+ DbgValueMap.insert({Loc, &DVR});
}
}
if (DbgValueMap.size() == 0)
return;
- // Map a pair of the destination BB and old DPValue to the new DPValue,
- // so that if a DPValue is being rewritten to use more than one of the
- // inserted PHIs in the same destination BB, we can update the same DPValue
- // with all the new PHIs instead of creating one copy for each.
- MapVector<std::pair<BasicBlock *, DPValue *>, DPValue *> NewDbgValueMap;
+ // Map a pair of the destination BB and old DbgVariableRecord to the new
+ // DbgVariableRecord, so that if a DbgVariableRecord is being rewritten to use
+ // more than one of the inserted PHIs in the same destination BB, we can
+ // update the same DbgVariableRecord with all the new PHIs instead of creating
+ // one copy for each.
+ MapVector<std::pair<BasicBlock *, DbgVariableRecord *>, DbgVariableRecord *>
+ NewDbgValueMap;
// Then iterate through the new PHIs and look to see if they use one of the
- // previously mapped PHIs. If so, create a new DPValue that will propagate
- // the info through the new PHI. If we use more than one new PHI in a single
- // destination BB with the same old dbg.value, merge the updates so that we
- // get a single new DPValue with all the new PHIs.
+ // previously mapped PHIs. If so, create a new DbgVariableRecord that will
+ // propagate the info through the new PHI. If we use more than one new PHI in
+ // a single destination BB with the same old dbg.value, merge the updates so
+ // that we get a single new DbgVariableRecord with all the new PHIs.
for (auto PHI : InsertedPHIs) {
BasicBlock *Parent = PHI->getParent();
// Avoid inserting a debug-info record into an EH block.
@@ -2023,13 +2032,13 @@ static void insertDPValuesForPHIs(BasicBlock *BB,
for (auto VI : PHI->operand_values()) {
auto V = DbgValueMap.find(VI);
if (V != DbgValueMap.end()) {
- DPValue *DbgII = cast<DPValue>(V->second);
+ DbgVariableRecord *DbgII = cast<DbgVariableRecord>(V->second);
auto NewDI = NewDbgValueMap.find({Parent, DbgII});
if (NewDI == NewDbgValueMap.end()) {
- DPValue *NewDbgII = DbgII->clone();
+ DbgVariableRecord *NewDbgII = DbgII->clone();
NewDI = NewDbgValueMap.insert({{Parent, DbgII}, NewDbgII}).first;
}
- DPValue *NewDbgII = NewDI->second;
+ DbgVariableRecord *NewDbgII = NewDI->second;
// If PHI contains VI as an operand more than once, we may
// replaced it in NewDbgII; confirm that it is present.
if (is_contained(NewDbgII->location_ops(), VI))
@@ -2037,10 +2046,10 @@ static void insertDPValuesForPHIs(BasicBlock *BB,
}
}
}
- // Insert the new DPValues into their destination blocks.
+ // Insert the new DbgVariableRecords into their destination blocks.
for (auto DI : NewDbgValueMap) {
BasicBlock *Parent = DI.first.first;
- DPValue *NewDbgII = DI.second;
+ DbgVariableRecord *NewDbgII = DI.second;
auto InsertionPt = Parent->getFirstInsertionPt();
assert(InsertionPt != Parent->end() && "Ill-formed basic block");
@@ -2055,7 +2064,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
if (InsertedPHIs.size() == 0)
return;
- insertDPValuesForPHIs(BB, InsertedPHIs);
+ insertDbgVariableRecordsForPHIs(BB, InsertedPHIs);
// Map existing PHI nodes to their dbg.values.
ValueToValueMapTy DbgValueMap;
@@ -2117,7 +2126,7 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
DIBuilder &Builder, uint8_t DIExprFlags,
int Offset) {
TinyPtrVector<DbgDeclareInst *> DbgDeclares = findDbgDeclares(Address);
- TinyPtrVector<DPValue *> DPVDeclares = findDPVDeclares(Address);
+ TinyPtrVector<DbgVariableRecord *> DVRDeclares = findDVRDeclares(Address);
auto ReplaceOne = [&](auto *DII) {
assert(DII->getVariable() && "Missing variable");
@@ -2128,21 +2137,22 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
};
for_each(DbgDeclares, ReplaceOne);
- for_each(DPVDeclares, ReplaceOne);
+ for_each(DVRDeclares, ReplaceOne);
- return !DbgDeclares.empty() || !DPVDeclares.empty();
+ return !DbgDeclares.empty() || !DVRDeclares.empty();
}
static void updateOneDbgValueForAlloca(const DebugLoc &Loc,
DILocalVariable *DIVar,
DIExpression *DIExpr, Value *NewAddress,
- DbgValueInst *DVI, DPValue *DPV,
+ DbgValueInst *DVI,
+ DbgVariableRecord *DVR,
DIBuilder &Builder, int Offset) {
assert(DIVar && "Missing variable");
- // This is an alloca-based dbg.value/DPValue. The first thing it should do
- // with the alloca pointer is dereference it. Otherwise we don't know how to
- // handle it and give up.
+ // This is an alloca-based dbg.value/DbgVariableRecord. The first thing it
+ // should do with the alloca pointer is dereference it. Otherwise we don't
+ // know how to handle it and give up.
if (!DIExpr || DIExpr->getNumElements() < 1 ||
DIExpr->getElement(0) != dwarf::DW_OP_deref)
return;
@@ -2155,16 +2165,16 @@ static void updateOneDbgValueForAlloca(const DebugLoc &Loc,
DVI->setExpression(DIExpr);
DVI->replaceVariableLocationOp(0u, NewAddress);
} else {
- assert(DPV);
- DPV->setExpression(DIExpr);
- DPV->replaceVariableLocationOp(0u, NewAddress);
+ assert(DVR);
+ DVR->setExpression(DIExpr);
+ DVR->replaceVariableLocationOp(0u, NewAddress);
}
}
void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
DIBuilder &Builder, int Offset) {
SmallVector<DbgValueInst *, 1> DbgUsers;
- SmallVector<DPValue *, 1> DPUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
findDbgValues(DbgUsers, AI, &DPUsers);
// Attempt to replace dbg.values that use this alloca.
@@ -2173,18 +2183,18 @@ void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
DVI->getExpression(), NewAllocaAddress, DVI,
nullptr, Builder, Offset);
- // Replace any DPValues that use this alloca.
- for (DPValue *DPV : DPUsers)
- updateOneDbgValueForAlloca(DPV->getDebugLoc(), DPV->getVariable(),
- DPV->getExpression(), NewAllocaAddress, nullptr,
- DPV, Builder, Offset);
+ // Replace any DbgVariableRecords that use this alloca.
+ for (DbgVariableRecord *DVR : DPUsers)
+ updateOneDbgValueForAlloca(DVR->getDebugLoc(), DVR->getVariable(),
+ DVR->getExpression(), NewAllocaAddress, nullptr,
+ DVR, Builder, Offset);
}
/// Where possible to salvage debug information for \p I do so.
/// If not possible mark undef.
void llvm::salvageDebugInfo(Instruction &I) {
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
- SmallVector<DPValue *, 1> DPUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
findDbgUsers(DbgUsers, &I, &DPUsers);
salvageDebugInfoForDbgValues(I, DbgUsers, DPUsers);
}
@@ -2224,7 +2234,7 @@ template <typename T> static void salvageDbgAssignAddress(T *Assign) {
void llvm::salvageDebugInfoForDbgValues(
Instruction &I, ArrayRef<DbgVariableIntrinsic *> DbgUsers,
- ArrayRef<DPValue *> DPUsers) {
+ ArrayRef<DbgVariableRecord *> DPUsers) {
// These are arbitrary chosen limits on the maximum number of values and the
// maximum size of a debug expression we can salvage up to, used for
// performance reasons.
@@ -2290,67 +2300,68 @@ void llvm::salvageDebugInfoForDbgValues(
LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n');
Salvaged = true;
}
- // Duplicate of above block for DPValues.
- for (auto *DPV : DPUsers) {
- if (DPV->isDbgAssign()) {
- if (DPV->getAddress() == &I) {
- salvageDbgAssignAddress(DPV);
+ // Duplicate of above block for DbgVariableRecords.
+ for (auto *DVR : DPUsers) {
+ if (DVR->isDbgAssign()) {
+ if (DVR->getAddress() == &I) {
+ salvageDbgAssignAddress(DVR);
Salvaged = true;
}
- if (DPV->getValue() != &I)
+ if (DVR->getValue() != &I)
continue;
}
// Do not add DW_OP_stack_value for DbgDeclare and DbgAddr, because they
// are implicitly pointing out the value as a DWARF memory location
// description.
- bool StackValue = DPV->getType() != DPValue::LocationType::Declare;
- auto DPVLocation = DPV->location_ops();
+ bool StackValue =
+ DVR->getType() != DbgVariableRecord::LocationType::Declare;
+ auto DVRLocation = DVR->location_ops();
assert(
- is_contained(DPVLocation, &I) &&
+ is_contained(DVRLocation, &I) &&
"DbgVariableIntrinsic must use salvaged instruction as its location");
SmallVector<Value *, 4> AdditionalValues;
- // 'I' may appear more than once in DPV's location ops, and each use of 'I'
+ // 'I' may appear more than once in DVR's location ops, and each use of 'I'
// must be updated in the DIExpression and potentially have additional
// values added; thus we call salvageDebugInfoImpl for each 'I' instance in
- // DPVLocation.
+ // DVRLocation.
Value *Op0 = nullptr;
- DIExpression *SalvagedExpr = DPV->getExpression();
- auto LocItr = find(DPVLocation, &I);
- while (SalvagedExpr && LocItr != DPVLocation.end()) {
+ DIExpression *SalvagedExpr = DVR->getExpression();
+ auto LocItr = find(DVRLocation, &I);
+ while (SalvagedExpr && LocItr != DVRLocation.end()) {
SmallVector<uint64_t, 16> Ops;
- unsigned LocNo = std::distance(DPVLocation.begin(), LocItr);
+ unsigned LocNo = std::distance(DVRLocation.begin(), LocItr);
uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands();
Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues);
if (!Op0)
break;
SalvagedExpr =
DIExpression::appendOpsToArg(SalvagedExpr, Ops, LocNo, StackValue);
- LocItr = std::find(++LocItr, DPVLocation.end(), &I);
+ LocItr = std::find(++LocItr, DVRLocation.end(), &I);
}
// salvageDebugInfoImpl should fail on examining the first element of
// DbgUsers, or none of them.
if (!Op0)
break;
- DPV->replaceVariableLocationOp(&I, Op0);
+ DVR->replaceVariableLocationOp(&I, Op0);
bool IsValidSalvageExpr =
SalvagedExpr->getNumElements() <= MaxExpressionSize;
if (AdditionalValues.empty() && IsValidSalvageExpr) {
- DPV->setExpression(SalvagedExpr);
- } else if (DPV->getType() != DPValue::LocationType::Declare &&
+ DVR->setExpression(SalvagedExpr);
+ } else if (DVR->getType() != DbgVariableRecord::LocationType::Declare &&
IsValidSalvageExpr &&
- DPV->getNumVariableLocationOps() + AdditionalValues.size() <=
+ DVR->getNumVariableLocationOps() + AdditionalValues.size() <=
MaxDebugArgs) {
- DPV->addVariableLocationOps(AdditionalValues, SalvagedExpr);
+ DVR->addVariableLocationOps(AdditionalValues, SalvagedExpr);
} else {
// Do not salvage using DIArgList for dbg.addr/dbg.declare, as it is
// currently only valid for stack value expressions.
// Also do not salvage if the resulting DIArgList would contain an
// unreasonably large number of values.
- DPV->setKillLocation();
+ DVR->setKillLocation();
}
- LLVM_DEBUG(dbgs() << "SALVAGE: " << DPV << '\n');
+ LLVM_DEBUG(dbgs() << "SALVAGE: " << DVR << '\n');
Salvaged = true;
}
@@ -2360,8 +2371,8 @@ void llvm::salvageDebugInfoForDbgValues(
for (auto *DII : DbgUsers)
DII->setKillLocation();
- for (auto *DPV : DPUsers)
- DPV->setKillLocation();
+ for (auto *DVR : DPUsers)
+ DVR->setKillLocation();
}
Value *getSalvageOpsForGEP(GetElementPtrInst *GEP, const DataLayout &DL,
@@ -2577,10 +2588,10 @@ using DbgValReplacement = std::optional<DIExpression *>;
static bool rewriteDebugUsers(
Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT,
function_ref<DbgValReplacement(DbgVariableIntrinsic &DII)> RewriteExpr,
- function_ref<DbgValReplacement(DPValue &DPV)> RewriteDPVExpr) {
+ function_ref<DbgValReplacement(DbgVariableRecord &DVR)> RewriteDVRExpr) {
// Find debug users of From.
SmallVector<DbgVariableIntrinsic *, 1> Users;
- SmallVector<DPValue *, 1> DPUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
findDbgUsers(Users, &From, &DPUsers);
if (Users.empty() && DPUsers.empty())
return false;
@@ -2589,7 +2600,7 @@ static bool rewriteDebugUsers(
bool Changed = false;
SmallPtrSet<DbgVariableIntrinsic *, 1> UndefOrSalvage;
- SmallPtrSet<DPValue *, 1> UndefOrSalvageDPV;
+ SmallPtrSet<DbgVariableRecord *, 1> UndefOrSalvageDVR;
if (isa<Instruction>(&To)) {
bool DomPointAfterFrom = From.getNextNonDebugInstruction() == &DomPoint;
@@ -2608,22 +2619,22 @@ static bool rewriteDebugUsers(
}
}
- // DPValue implementation of the above.
- for (auto *DPV : DPUsers) {
- Instruction *MarkedInstr = DPV->getMarker()->MarkedInstr;
+ // DbgVariableRecord implementation of the above.
+ for (auto *DVR : DPUsers) {
+ Instruction *MarkedInstr = DVR->getMarker()->MarkedInstr;
Instruction *NextNonDebug = MarkedInstr;
// The next instruction might still be a dbg.declare, skip over it.
if (isa<DbgVariableIntrinsic>(NextNonDebug))
NextNonDebug = NextNonDebug->getNextNonDebugInstruction();
if (DomPointAfterFrom && NextNonDebug == &DomPoint) {
- LLVM_DEBUG(dbgs() << "MOVE: " << *DPV << '\n');
- DPV->removeFromParent();
+ LLVM_DEBUG(dbgs() << "MOVE: " << *DVR << '\n');
+ DVR->removeFromParent();
// Ensure there's a marker.
- DomPoint.getParent()->insertDbgRecordAfter(DPV, &DomPoint);
+ DomPoint.getParent()->insertDbgRecordAfter(DVR, &DomPoint);
Changed = true;
} else if (!DT.dominates(&DomPoint, MarkedInstr)) {
- UndefOrSalvageDPV.insert(DPV);
+ UndefOrSalvageDVR.insert(DVR);
}
}
}
@@ -2633,30 +2644,30 @@ static bool rewriteDebugUsers(
if (UndefOrSalvage.count(DII))
continue;
- DbgValReplacement DVR = RewriteExpr(*DII);
- if (!DVR)
+ DbgValReplacement DVRepl = RewriteExpr(*DII);
+ if (!DVRepl)
continue;
DII->replaceVariableLocationOp(&From, &To);
- DII->setExpression(*DVR);
+ DII->setExpression(*DVRepl);
LLVM_DEBUG(dbgs() << "REWRITE: " << *DII << '\n');
Changed = true;
}
- for (auto *DPV : DPUsers) {
- if (UndefOrSalvageDPV.count(DPV))
+ for (auto *DVR : DPUsers) {
+ if (UndefOrSalvageDVR.count(DVR))
continue;
- DbgValReplacement DVR = RewriteDPVExpr(*DPV);
- if (!DVR)
+ DbgValReplacement DVRepl = RewriteDVRExpr(*DVR);
+ if (!DVRepl)
continue;
- DPV->replaceVariableLocationOp(&From, &To);
- DPV->setExpression(*DVR);
- LLVM_DEBUG(dbgs() << "REWRITE: " << DPV << '\n');
+ DVR->replaceVariableLocationOp(&From, &To);
+ DVR->setExpression(*DVRepl);
+ LLVM_DEBUG(dbgs() << "REWRITE: " << DVR << '\n');
Changed = true;
}
- if (!UndefOrSalvage.empty() || !UndefOrSalvageDPV.empty()) {
+ if (!UndefOrSalvage.empty() || !UndefOrSalvageDVR.empty()) {
// Try to salvage the remaining debug users.
salvageDebugInfo(From);
Changed = true;
@@ -2704,15 +2715,15 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
auto Identity = [&](DbgVariableIntrinsic &DII) -> DbgValReplacement {
return DII.getExpression();
};
- auto IdentityDPV = [&](DPValue &DPV) -> DbgValReplacement {
- return DPV.getExpression();
+ auto IdentityDVR = [&](DbgVariableRecord &DVR) -> DbgValReplacement {
+ return DVR.getExpression();
};
// Handle no-op conversions.
Module &M = *From.getModule();
const DataLayout &DL = M.getDataLayout();
if (isBitCastSemanticsPreserving(DL, FromTy, ToTy))
- return rewriteDebugUsers(From, To, DomPoint, DT, Identity, IdentityDPV);
+ return rewriteDebugUsers(From, To, DomPoint, DT, Identity, IdentityDVR);
// Handle integer-to-integer widening and narrowing.
// FIXME: Use DW_OP_convert when it's available everywhere.
@@ -2724,7 +2735,7 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
// When the width of the result grows, assume that a debugger will only
// access the low `FromBits` bits when inspecting the source variable.
if (FromBits < ToBits)
- return rewriteDebugUsers(From, To, DomPoint, DT, Identity, IdentityDPV);
+ return rewriteDebugUsers(From, To, DomPoint, DT, Identity, IdentityDVR);
// The width of the result has shrunk. Use sign/zero extension to describe
// the source variable's high bits.
@@ -2740,10 +2751,10 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
return DIExpression::appendExt(DII.getExpression(), ToBits, FromBits,
Signed);
};
- // RemoveDIs: duplicate implementation working on DPValues rather than on
- // dbg.value intrinsics.
- auto SignOrZeroExtDPV = [&](DPValue &DPV) -> DbgValReplacement {
- DILocalVariable *Var = DPV.getVariable();
+ // RemoveDIs: duplicate implementation working on DbgVariableRecords rather
+ // than on dbg.value intrinsics.
+ auto SignOrZeroExtDVR = [&](DbgVariableRecord &DVR) -> DbgValReplacement {
+ DILocalVariable *Var = DVR.getVariable();
// Without knowing signedness, sign/zero extension isn't possible.
auto Signedness = Var->getSignedness();
@@ -2751,11 +2762,11 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
return std::nullopt;
bool Signed = *Signedness == DIBasicType::Signedness::Signed;
- return DIExpression::appendExt(DPV.getExpression(), ToBits, FromBits,
+ return DIExpression::appendExt(DVR.getExpression(), ToBits, FromBits,
Signed);
};
return rewriteDebugUsers(From, To, DomPoint, DT, SignOrZeroExt,
- SignOrZeroExtDPV);
+ SignOrZeroExtDVR);
}
// TODO: Floating-point conversions, vectors.
@@ -2795,8 +2806,8 @@ llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {
if (!Inst->use_empty() && !Inst->getType()->isTokenTy())
Inst->replaceAllUsesWith(PoisonValue::get(Inst->getType()));
if (Inst->isEHPad() || Inst->getType()->isTokenTy()) {
- // EHPads can't have DPValues attached to them, but it might be possible
- // for things with token type.
+ // EHPads can't have DbgVariableRecords attached to them, but it might be
+ // possible for things with token type.
Inst->dropDbgRecords();
EndInst = Inst;
continue;
@@ -3544,12 +3555,12 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI,
void llvm::dropDebugUsers(Instruction &I) {
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
- SmallVector<DPValue *, 1> DPUsers;
+ SmallVector<DbgVariableRecord *, 1> DPUsers;
findDbgUsers(DbgUsers, &I, &DPUsers);
for (auto *DII : DbgUsers)
DII->eraseFromParent();
- for (auto *DPV : DPUsers)
- DPV->eraseFromParent();
+ for (auto *DVR : DPUsers)
+ DVR->eraseFromParent();
}
void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,