Skip to content

[RemoveDIs][NFC] Find DPValues using findDbgDeclares #73500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Module;

/// Finds dbg.declare intrinsics declaring local variables as living in the
/// memory that 'V' points to.
void findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers, Value *V);
void findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers, Value *V,
SmallVectorImpl<DPValue *> *DPValues = nullptr);

/// Finds the llvm.dbg.value intrinsics describing a value.
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
enum class LocationType {
Declare,
Value,

End, ///< Marks the end of the concrete types.
Any, ///< To indicate all LocationTypes in searches.
};
/// Classification of the debug-info record that this DPValue represents.
/// Essentially, "is this a dbg.value or dbg.declare?". dbg.declares are not
Expand Down
42 changes: 16 additions & 26 deletions llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,10 @@ using namespace llvm;
using namespace llvm::at;
using namespace llvm::dwarf;

void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
return;
auto *L = LocalAsMetadata::getIfExists(V);
if (!L)
return;
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
if (!MDV)
return;

for (User *U : MDV->users()) {
if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
DbgUsers.push_back(DDI);
}
}

template <typename IntrinsicT>
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
template <typename IntrinsicT,
DPValue::LocationType Type = DPValue::LocationType::Any>
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
SmallVectorImpl<DPValue *> *DPValues) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
Expand Down Expand Up @@ -94,7 +76,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
// Get DPValues that use this as a single value.
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
for (DPValue *DPV : L->getAllDPValueUsers()) {
if (DPV->getType() == DPValue::LocationType::Value)
if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
DPValues->push_back(DPV);
}
}
Expand All @@ -108,21 +90,29 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
continue;
DIArgList *DI = cast<DIArgList>(AL);
for (DPValue *DPV : DI->getAllDPValueUsers())
if (DPV->getType() == DPValue::LocationType::Value)
if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
if (EncounteredDPValues.insert(DPV).second)
DPValues->push_back(DPV);
}
}
}

void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
findDbgIntrinsics<DbgDeclareInst, DPValue::LocationType::Declare>(DbgUsers, V,
DPValues);
}

void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
findDbgIntrinsics<DbgValueInst>(DbgValues, V, DPValues);
findDbgIntrinsics<DbgValueInst, DPValue::LocationType::Value>(DbgValues, V,
DPValues);
}

void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
findDbgIntrinsics<DbgVariableIntrinsic>(DbgUsers, V, DPValues);
findDbgIntrinsics<DbgVariableIntrinsic, DPValue::LocationType::Any>(
DbgUsers, V, DPValues);
}

DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
Expand Down