+ // Process the newly imported function and add callees to the worklist.
+ GlobalValue *NewGV = M.getNamedValue(ImportFunctionName);
+ assert(NewGV);
+ Function *NewF = dyn_cast<Function>(NewGV);
+ assert(NewF);
+
+ for (auto &BB : *NewF) {
+ 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());
+ }
+ }
+ }
+ }