@@ -45,25 +45,6 @@ using namespace llvm;
4545using namespace llvm ::at;
4646using namespace llvm ::dwarf;
4747
48- TinyPtrVector<DbgDeclareInst *> llvm::findDbgDeclares (Value *V) {
49- // This function is hot. Check whether the value has any metadata to avoid a
50- // DenseMap lookup. This check is a bitfield datamember lookup.
51- if (!V->isUsedByMetadata ())
52- return {};
53- auto *L = ValueAsMetadata::getIfExists (V);
54- if (!L)
55- return {};
56- auto *MDV = MetadataAsValue::getIfExists (V->getContext (), L);
57- if (!MDV)
58- return {};
59-
60- TinyPtrVector<DbgDeclareInst *> Declares;
61- for (User *U : MDV->users ())
62- if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
63- Declares.push_back (DDI);
64-
65- return Declares;
66- }
6748TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares (Value *V) {
6849 // This function is hot. Check whether the value has any metadata to avoid a
6950 // DenseMap lookup. This check is a bitfield datamember lookup.
@@ -98,42 +79,31 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
9879 return Values;
9980}
10081
101- template <typename IntrinsicT, bool DbgAssignAndValuesOnly>
82+ template <bool DbgAssignAndValuesOnly>
10283static void
103- findDbgIntrinsics (SmallVectorImpl<IntrinsicT *> &Result, Value *V,
104- SmallVectorImpl<DbgVariableRecord *> * DbgVariableRecords) {
84+ findDbgIntrinsics (Value *V,
85+ SmallVectorImpl<DbgVariableRecord *> & DbgVariableRecords) {
10586 // This function is hot. Check whether the value has any metadata to avoid a
10687 // DenseMap lookup.
10788 if (!V->isUsedByMetadata ())
10889 return ;
10990
110- LLVMContext &Ctx = V->getContext ();
11191 // TODO: If this value appears multiple times in a DIArgList, we should still
112- // only add the owning DbgValueInst once; use this set to track ArgListUsers.
92+ // only add the owning dbg.value once; use this set to track ArgListUsers.
11393 // This behaviour can be removed when we can automatically remove duplicates.
11494 // V will also appear twice in a dbg.assign if its used in the both the value
11595 // and address components.
116- SmallPtrSet<IntrinsicT *, 4 > EncounteredIntrinsics;
11796 SmallPtrSet<DbgVariableRecord *, 4 > EncounteredDbgVariableRecords;
11897
119- // / Append IntrinsicT users of MetadataAsValue(MD).
120- auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
121- &EncounteredDbgVariableRecords, &Result,
122- DbgVariableRecords](Metadata *MD) {
123- if (auto *MDV = MetadataAsValue::getIfExists (Ctx, MD)) {
124- for (User *U : MDV->users ())
125- if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
126- if (EncounteredIntrinsics.insert (DVI).second )
127- Result.push_back (DVI);
128- }
129- if (!DbgVariableRecords)
130- return ;
98+ // / Append users of MetadataAsValue(MD).
99+ auto AppendUsers = [&EncounteredDbgVariableRecords,
100+ &DbgVariableRecords](Metadata *MD) {
131101 // Get DbgVariableRecords that use this as a single value.
132102 if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
133103 for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers ()) {
134104 if (!DbgAssignAndValuesOnly || DVR->isDbgValue () || DVR->isDbgAssign ())
135105 if (EncounteredDbgVariableRecords.insert (DVR).second )
136- DbgVariableRecords-> push_back (DVR);
106+ DbgVariableRecords. push_back (DVR);
137107 }
138108 }
139109 };
@@ -142,29 +112,23 @@ findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
142112 AppendUsers (L);
143113 for (Metadata *AL : L->getAllArgListUsers ()) {
144114 AppendUsers (AL);
145- if (!DbgVariableRecords)
146- continue ;
147115 DIArgList *DI = cast<DIArgList>(AL);
148116 for (DbgVariableRecord *DVR : DI->getAllDbgVariableRecordUsers ())
149117 if (!DbgAssignAndValuesOnly || DVR->isDbgValue () || DVR->isDbgAssign ())
150118 if (EncounteredDbgVariableRecords.insert (DVR).second )
151- DbgVariableRecords-> push_back (DVR);
119+ DbgVariableRecords. push_back (DVR);
152120 }
153121 }
154122}
155123
156124void llvm::findDbgValues (
157- SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
158- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
159- findDbgIntrinsics<DbgValueInst, /* DbgAssignAndValuesOnly=*/ true >(
160- DbgValues, V, DbgVariableRecords);
125+ Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
126+ findDbgIntrinsics</* DbgAssignAndValuesOnly=*/ true >(V, DbgVariableRecords);
161127}
162128
163129void llvm::findDbgUsers (
164- SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, Value *V,
165- SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
166- findDbgIntrinsics<DbgVariableIntrinsic, /* DbgAssignAndValuesOnly=*/ false >(
167- DbgUsers, V, DbgVariableRecords);
130+ Value *V, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
131+ findDbgIntrinsics</* DbgAssignAndValuesOnly=*/ false >(V, DbgVariableRecords);
168132}
169133
170134DISubprogram *llvm::getDISubprogram (const MDNode *Scope) {
@@ -173,18 +137,6 @@ DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
173137 return nullptr ;
174138}
175139
176- DebugLoc llvm::getDebugValueLoc (DbgVariableIntrinsic *DII) {
177- // Original dbg.declare must have a location.
178- const DebugLoc &DeclareLoc = DII->getDebugLoc ();
179- MDNode *Scope = DeclareLoc.getScope ();
180- DILocation *InlinedAt = DeclareLoc.getInlinedAt ();
181- // Because no machine insts can come from debug intrinsics, only the scope
182- // and inlinedAt is significant. Zero line numbers are used in case this
183- // DebugLoc leaks into any adjacent instructions. Produce an unknown location
184- // with the correct scope / inlinedAt fields.
185- return DILocation::get (DII->getContext (), 0 , 0 , Scope, InlinedAt);
186- }
187-
188140DebugLoc llvm::getDebugValueLoc (DbgVariableRecord *DVR) {
189141 // Original dbg.declare must have a location.
190142 const DebugLoc &DeclareLoc = DVR->getDebugLoc ();
@@ -852,19 +804,6 @@ void DebugTypeInfoRemoval::traverse(MDNode *N) {
852804bool llvm::stripNonLineTableDebugInfo (Module &M) {
853805 bool Changed = false ;
854806
855- // First off, delete the debug intrinsics.
856- auto RemoveUses = [&](StringRef Name) {
857- if (auto *DbgVal = M.getFunction (Name)) {
858- while (!DbgVal->use_empty ())
859- cast<Instruction>(DbgVal->user_back ())->eraseFromParent ();
860- DbgVal->eraseFromParent ();
861- Changed = true ;
862- }
863- };
864- RemoveUses (" llvm.dbg.declare" );
865- RemoveUses (" llvm.dbg.label" );
866- RemoveUses (" llvm.dbg.value" );
867-
868807 // Delete non-CU debug info named metadata nodes.
869808 for (auto NMI = M.named_metadata_begin (), NME = M.named_metadata_end ();
870809 NMI != NME;) {
0 commit comments