[llvm] [RemoveDIs][NFC] Find DPValues using findDbgDeclares (PR #73500)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 04:08:15 PST 2023
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/73500
>From 19b3d8a850516d2ecd1d537dc7d03c01f8066136 Mon Sep 17 00:00:00 2001
From: OCHyams <orlando.hyams at sony.com>
Date: Mon, 27 Nov 2023 10:43:23 +0000
Subject: [PATCH 1/2] [RemoveDIs][NFC] Find DPValues using findDbgDeclares
This change doesn't change any call sites.
---
llvm/include/llvm/IR/DebugInfo.h | 3 ++-
llvm/lib/IR/DebugInfo.cpp | 42 ++++++++++++--------------------
2 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h
index 5ed423bfd1c131..36ef77f9505bc1 100644
--- a/llvm/include/llvm/IR/DebugInfo.h
+++ b/llvm/include/llvm/IR/DebugInfo.h
@@ -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,
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index b3cc9996ace459..eb6111854a0db0 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -44,28 +44,11 @@ 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, bool AnyType,
+ DPValue::LocationType Type = DPValue::LocationType(-1)>
+static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
+ SmallVectorImpl<DPValue *> *DPValues) {
+ static_assert(AnyType || (int)Type >= 0);
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
@@ -94,7 +77,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 (AnyType || DPV->getType() == Type)
DPValues->push_back(DPV);
}
}
@@ -108,21 +91,28 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
continue;
DIArgList *DI = cast<DIArgList>(AL);
for (DPValue *DPV : DI->getAllDPValueUsers())
- if (DPV->getType() == DPValue::LocationType::Value)
+ if (AnyType || 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, false, DPValue::LocationType::Declare>(
+ DbgUsers, V, DPValues);
+}
+
void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
- findDbgIntrinsics<DbgValueInst>(DbgValues, V, DPValues);
+ findDbgIntrinsics<DbgValueInst, false, DPValue::LocationType::Value>(
+ DbgValues, V, DPValues);
}
void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
- findDbgIntrinsics<DbgVariableIntrinsic>(DbgUsers, V, DPValues);
+ findDbgIntrinsics<DbgVariableIntrinsic, true>(DbgUsers, V, DPValues);
}
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
>From 4e3b973e3dd93bcb03fc462458edd91a098ca267 Mon Sep 17 00:00:00 2001
From: OCHyams <orlando.hyams at sony.com>
Date: Tue, 12 Dec 2023 12:07:17 +0000
Subject: [PATCH 2/2] Add ::End and ::Any
---
.../include/llvm/IR/DebugProgramInstruction.h | 3 +++
llvm/lib/IR/DebugInfo.cpp | 20 +++++++++----------
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index f73a6237a47779..8230070343e0c1 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -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
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index eb6111854a0db0..eab05eed428e47 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -44,11 +44,10 @@ using namespace llvm;
using namespace llvm::at;
using namespace llvm::dwarf;
-template <typename IntrinsicT, bool AnyType,
- DPValue::LocationType Type = DPValue::LocationType(-1)>
+template <typename IntrinsicT,
+ DPValue::LocationType Type = DPValue::LocationType::Any>
static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
SmallVectorImpl<DPValue *> *DPValues) {
- static_assert(AnyType || (int)Type >= 0);
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
@@ -77,7 +76,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
// Get DPValues that use this as a single value.
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
for (DPValue *DPV : L->getAllDPValueUsers()) {
- if (AnyType || DPV->getType() == Type)
+ if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
DPValues->push_back(DPV);
}
}
@@ -91,7 +90,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
continue;
DIArgList *DI = cast<DIArgList>(AL);
for (DPValue *DPV : DI->getAllDPValueUsers())
- if (AnyType || DPV->getType() == Type)
+ if (Type == DPValue::LocationType::Any || DPV->getType() == Type)
if (EncounteredDPValues.insert(DPV).second)
DPValues->push_back(DPV);
}
@@ -100,19 +99,20 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
void llvm::findDbgDeclares(SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
- findDbgIntrinsics<DbgDeclareInst, false, DPValue::LocationType::Declare>(
- DbgUsers, V, DPValues);
+ findDbgIntrinsics<DbgDeclareInst, DPValue::LocationType::Declare>(DbgUsers, V,
+ DPValues);
}
void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
- findDbgIntrinsics<DbgValueInst, false, DPValue::LocationType::Value>(
- DbgValues, V, DPValues);
+ findDbgIntrinsics<DbgValueInst, DPValue::LocationType::Value>(DbgValues, V,
+ DPValues);
}
void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
- findDbgIntrinsics<DbgVariableIntrinsic, true>(DbgUsers, V, DPValues);
+ findDbgIntrinsics<DbgVariableIntrinsic, DPValue::LocationType::Any>(
+ DbgUsers, V, DPValues);
}
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
More information about the llvm-commits
mailing list