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 &DbgUsers, Value *V); +void findDbgDeclares(SmallVectorImpl &DbgUsers, Value *V, + SmallVectorImpl *DPValues = nullptr); /// Finds the llvm.dbg.value intrinsics describing a value. void findDbgValues(SmallVectorImpl &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, 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 &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(U)) - DbgUsers.push_back(DDI); - } -} - -template -static void findDbgIntrinsics(SmallVectorImpl &Result, - Value *V, SmallVectorImpl *DPValues) { +template +static void findDbgIntrinsics(SmallVectorImpl &Result, Value *V, + SmallVectorImpl *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 &Result, // Get DPValues that use this as a single value. if (LocalAsMetadata *L = dyn_cast(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 &Result, continue; DIArgList *DI = cast(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 &DbgUsers, + Value *V, SmallVectorImpl *DPValues) { + findDbgIntrinsics(DbgUsers, V, + DPValues); +} + void llvm::findDbgValues(SmallVectorImpl &DbgValues, Value *V, SmallVectorImpl *DPValues) { - findDbgIntrinsics(DbgValues, V, DPValues); + findDbgIntrinsics(DbgValues, V, + DPValues); } void llvm::findDbgUsers(SmallVectorImpl &DbgUsers, Value *V, SmallVectorImpl *DPValues) { - findDbgIntrinsics(DbgUsers, V, DPValues); + findDbgIntrinsics( + DbgUsers, V, DPValues); } DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {