Skip to content

Commit f1c0230

Browse files
committed
Move intrinsic dropping into a separate function
Allows us to use early exit and avoids very deeply nested code.
1 parent 8f71d65 commit f1c0230

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ void LLParser::restoreParsingState(const SlotMapping *Slots) {
130130
std::make_pair(I.first, std::make_pair(I.second, LocTy())));
131131
}
132132

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+
133157
void LLParser::dropUnknownMetadataReferences() {
134158
auto Pred = [](unsigned MDKind, MDNode *Node) { return Node->isTemporary(); };
135159
for (Function &F : *M) {
@@ -138,32 +162,8 @@ void LLParser::dropUnknownMetadataReferences() {
138162
for (Instruction &I : make_early_inc_range(BB)) {
139163
I.eraseMetadataIf(Pred);
140164

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);
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)