@@ -44,28 +44,11 @@ using namespace llvm;
44
44
using namespace llvm ::at;
45
45
using namespace llvm ::dwarf;
46
46
47
- void llvm::findDbgDeclares (SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
48
- Value *V) {
49
- // This function is hot. Check whether the value has any metadata to avoid a
50
- // DenseMap lookup.
51
- if (!V->isUsedByMetadata ())
52
- return ;
53
- auto *L = LocalAsMetadata::getIfExists (V);
54
- if (!L)
55
- return ;
56
- auto *MDV = MetadataAsValue::getIfExists (V->getContext (), L);
57
- if (!MDV)
58
- return ;
59
-
60
- for (User *U : MDV->users ()) {
61
- if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
62
- DbgUsers.push_back (DDI);
63
- }
64
- }
65
-
66
- template <typename IntrinsicT>
67
- static void findDbgIntrinsics (SmallVectorImpl<IntrinsicT *> &Result,
68
- Value *V, SmallVectorImpl<DPValue *> *DPValues) {
47
+ template <typename IntrinsicT, bool AnyType,
48
+ DPValue::LocationType Type = DPValue::LocationType(-1 )>
49
+ static void findDbgIntrinsics (SmallVectorImpl<IntrinsicT *> &Result, Value *V,
50
+ SmallVectorImpl<DPValue *> *DPValues) {
51
+ static_assert (AnyType || (int )Type >= 0 );
69
52
// This function is hot. Check whether the value has any metadata to avoid a
70
53
// DenseMap lookup.
71
54
if (!V->isUsedByMetadata ())
@@ -94,7 +77,7 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
94
77
// Get DPValues that use this as a single value.
95
78
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
96
79
for (DPValue *DPV : L->getAllDPValueUsers ()) {
97
- if (DPV->getType () == DPValue::LocationType::Value )
80
+ if (AnyType || DPV->getType () == Type )
98
81
DPValues->push_back (DPV);
99
82
}
100
83
}
@@ -108,21 +91,28 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result,
108
91
continue ;
109
92
DIArgList *DI = cast<DIArgList>(AL);
110
93
for (DPValue *DPV : DI->getAllDPValueUsers ())
111
- if (DPV->getType () == DPValue::LocationType::Value )
94
+ if (AnyType || DPV->getType () == Type )
112
95
if (EncounteredDPValues.insert (DPV).second )
113
96
DPValues->push_back (DPV);
114
97
}
115
98
}
116
99
}
117
100
101
+ void llvm::findDbgDeclares (SmallVectorImpl<DbgDeclareInst *> &DbgUsers,
102
+ Value *V, SmallVectorImpl<DPValue *> *DPValues) {
103
+ findDbgIntrinsics<DbgDeclareInst, false , DPValue::LocationType::Declare>(
104
+ DbgUsers, V, DPValues);
105
+ }
106
+
118
107
void llvm::findDbgValues (SmallVectorImpl<DbgValueInst *> &DbgValues,
119
108
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
120
- findDbgIntrinsics<DbgValueInst>(DbgValues, V, DPValues);
109
+ findDbgIntrinsics<DbgValueInst, false , DPValue::LocationType::Value>(
110
+ DbgValues, V, DPValues);
121
111
}
122
112
123
113
void llvm::findDbgUsers (SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
124
114
Value *V, SmallVectorImpl<DPValue *> *DPValues) {
125
- findDbgIntrinsics<DbgVariableIntrinsic>(DbgUsers, V, DPValues);
115
+ findDbgIntrinsics<DbgVariableIntrinsic, true >(DbgUsers, V, DPValues);
126
116
}
127
117
128
118
DISubprogram *llvm::getDISubprogram (const MDNode *Scope) {
0 commit comments