+/// Walk through the instructions in \p F looking for external
+/// calls not already in the \p CalledFunctions set. If any are
+/// found they are added to the \p Worklist for importing.
+static void findExternalCalls(const Function &F, StringSet<> &CalledFunctions,
+ SmallVector<StringRef, 64> &Worklist) {
+ for (auto &BB : F) {
+ for (auto &I : BB) {
+ if (isa<CallInst>(I)) {
+ DEBUG(dbgs() << "Found a call: '" << I << "'\n");
+ auto CalledFunction = cast<CallInst>(I).getCalledFunction();
+ // Insert any new external calls that have not already been
+ // added to set/worklist.
+ if (CalledFunction && CalledFunction->hasName() &&
+ CalledFunction->isDeclaration() &&
+ !CalledFunctions.count(CalledFunction->getName())) {
+ CalledFunctions.insert(CalledFunction->getName());
+ Worklist.push_back(CalledFunction->getName());
+ }
+ }
+ }
+ }
+}
+