Skip to content

Commit 8d106fe

Browse files
author
Raj Barik
committed
ProtocolDevirtualizer Part 2: Transformation Phase
1 parent 136773f commit 8d106fe

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/SILOptimizer/Transforms/GenericSpecializer.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,21 @@ bool ProtocolDevirtualizer::canDevirtualizeProtocolInFunction(ProtocolDevirtuali
238238
auto ProtoDecl = dyn_cast<ProtocolDecl>(SwiftProtoDecl);
239239
auto CD = PDA->getSoleClassImplementingProtocol(ProtoDecl);
240240
if (CD) {
241-
/// Save the mapping for transformation pass.
242-
Arg2DeclMap[i] = std::make_pair(ProtoDecl, CD);
243-
DEBUG(llvm::dbgs() << "Function: " << F->getName() << " has a singel class decl\n");
244-
returnFlag |= true;
241+
bool UnknownPattern = false;
242+
for (auto *Op : Args[i]->getUses()) {
243+
auto User = Op->getUser();
244+
auto *Open = dyn_cast<OpenExistentialRefInst>(User);
245+
auto *Debug = dyn_cast<DebugValueInst>(User);
246+
if(!(Open || Debug)) {
247+
UnknownPattern = true;
248+
}
249+
}
250+
if (!UnknownPattern) {
251+
/// Save the mapping for transformation pass.
252+
Arg2DeclMap[i] = std::make_pair(ProtoDecl, CD);
253+
DEBUG(llvm::dbgs() << "Function: " << F->getName() << " has a singel class decl\n");
254+
returnFlag |= true;
255+
}
245256
}
246257
}
247258
}

0 commit comments

Comments
 (0)