[llvm] 5457fab - Reapply "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)"
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 06:50:34 PST 2023
Author: OCHyams
Date: 2023-12-12T14:50:07Z
New Revision: 5457fab15cd210cd7d89278bea173dc5d0261d3b
URL: https://github.com/llvm/llvm-project/commit/5457fab15cd210cd7d89278bea173dc5d0261d3b
DIFF: https://github.com/llvm/llvm-project/commit/5457fab15cd210cd7d89278bea173dc5d0261d3b.diff
LOG: Reapply "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)"
This patch doesn't change any call sites.
Depends on #73498.
Reverted in 87c686700f68ce24191f027082ef5fb9a654e9d8.
Added:
Modified:
llvm/include/llvm/IR/DebugInfo.h
llvm/include/llvm/IR/DebugProgramInstruction.h
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugProgramInstruction.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h
index 5ed423bfd1c13..36ef77f9505bc 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/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index f73a6237a4777..8230070343e0c 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 b3cc9996ace45..eab05eed428e4 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -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())
@@ -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);
}
}
@@ -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) {
diff --git a/llvm/lib/IR/DebugProgramInstruction.cpp b/llvm/lib/IR/DebugProgramInstruction.cpp
index df45c6ea3a776..7b709a2de0335 100644
--- a/llvm/lib/IR/DebugProgramInstruction.cpp
+++ b/llvm/lib/IR/DebugProgramInstruction.cpp
@@ -203,6 +203,10 @@ DPValue::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
case DPValue::LocationType::Value:
IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_value);
break;
+ case DPValue::LocationType::End:
+ case DPValue::LocationType::Any:
+ llvm_unreachable("Invalid LocationType");
+ break;
}
// Create the intrinsic from this DPValue's information, optionally insert
More information about the llvm-commits
mailing list