diff options
author | Stephen Tozer <stephen.tozer@sony.com> | 2024-01-15 17:46:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 17:46:56 +0000 |
commit | 304119860ac0ded0a126ab1c8cc30367e29ebd01 (patch) | |
tree | 8c93725bba1685ae60e86c4dc6feab42cd9e0bdf /llvm/lib/IR/DebugInfo.cpp | |
parent | c6dfb62d4df969fc50f42cf2889b10bb82f51b1f (diff) | |
download | llvm-304119860ac0ded0a126ab1c8cc30367e29ebd01.zip llvm-304119860ac0ded0a126ab1c8cc30367e29ebd01.tar.gz llvm-304119860ac0ded0a126ab1c8cc30367e29ebd01.tar.bz2 |
[DebugInfo][RemoveDIs][NFC] Split findDbgDeclares into two functions (#77478)
This patch follows on from comments on
https://github.com/llvm/llvm-project/pull/73498, implementing the
proposed split of findDbgDeclares into two separate functions for
DbgDeclareInsts and DPVDeclares, which return containers rather than
taking containers by reference.
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 316197a..6b7dd74 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -44,6 +44,42 @@ using namespace llvm; using namespace llvm::at; using namespace llvm::dwarf; +TinyPtrVector<DbgDeclareInst *> llvm::findDbgDeclares(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 {}; + + TinyPtrVector<DbgDeclareInst *> Declares; + for (User *U : MDV->users()) + if (auto *DDI = dyn_cast<DbgDeclareInst>(U)) + Declares.push_back(DDI); + + return Declares; +} +TinyPtrVector<DPValue *> llvm::findDPVDeclares(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 {}; + + TinyPtrVector<DPValue *> Declares; + for (DPValue *DPV : L->getAllDPValueUsers()) + if (DPV->getType() == DPValue::LocationType::Declare) + Declares.push_back(DPV); + + return Declares; +} + template <typename IntrinsicT, DPValue::LocationType Type = DPValue::LocationType::Any> static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V, @@ -97,12 +133,6 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V, } } -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, DPValue::LocationType::Value>(DbgValues, V, |