@@ -130,6 +130,30 @@ void LLParser::restoreParsingState(const SlotMapping *Slots) {
130
130
std::make_pair (I.first , std::make_pair (I.second , LocTy ())));
131
131
}
132
132
133
+ static void dropIntrinsicWithUnknownMetadataArgument (IntrinsicInst *II) {
134
+ // White-list intrinsics that are safe to drop.
135
+ if (!isa<DbgInfoIntrinsic>(II) &&
136
+ II->getIntrinsicID () != Intrinsic::experimental_noalias_scope_decl)
137
+ return ;
138
+
139
+ SmallVector<MetadataAsValue *> MVs;
140
+ for (Value *V : II->args ())
141
+ if (auto *MV = dyn_cast<MetadataAsValue>(V))
142
+ if (auto *MD = dyn_cast<MDNode>(MV->getMetadata ()))
143
+ if (MD->isTemporary ())
144
+ MVs.push_back (MV);
145
+
146
+ if (!MVs.empty ()) {
147
+ assert (II->use_empty () && " Cannot have uses" );
148
+ II->eraseFromParent ();
149
+
150
+ // Also remove no longer used MetadataAsValue wrappers.
151
+ for (MetadataAsValue *MV : MVs)
152
+ if (MV->use_empty ())
153
+ delete MV;
154
+ }
155
+ }
156
+
133
157
void LLParser::dropUnknownMetadataReferences () {
134
158
auto Pred = [](unsigned MDKind, MDNode *Node) { return Node->isTemporary (); };
135
159
for (Function &F : *M) {
@@ -138,32 +162,8 @@ void LLParser::dropUnknownMetadataReferences() {
138
162
for (Instruction &I : make_early_inc_range (BB)) {
139
163
I.eraseMetadataIf (Pred);
140
164
141
- if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
142
- // If this is a white-listed intrinsic with an unknown metadata
143
- // operand, drop it.
144
- if (isa<DbgInfoIntrinsic>(II) ||
145
- II->getIntrinsicID () ==
146
- Intrinsic::experimental_noalias_scope_decl) {
147
- SmallVector<MetadataAsValue *> MVs;
148
- for (Value *V : II->args ()) {
149
- if (auto *MV = dyn_cast<MetadataAsValue>(V))
150
- if (auto *MD = dyn_cast<MDNode>(MV->getMetadata ()))
151
- if (MD->isTemporary ())
152
- MVs.push_back (MV);
153
- }
154
-
155
- if (!MVs.empty ()) {
156
- assert (II->use_empty () && " Cannot have uses" );
157
- II->eraseFromParent ();
158
-
159
- // Also remove no longer used MetadataAsValue wrappers.
160
- for (MetadataAsValue *MV : MVs) {
161
- if (MV->use_empty ())
162
- delete MV;
163
- }
164
- }
165
- }
166
- }
165
+ if (auto *II = dyn_cast<IntrinsicInst>(&I))
166
+ dropIntrinsicWithUnknownMetadataArgument (II);
167
167
}
168
168
}
169
169
}
0 commit comments