[llvm] r254020 - [ThinLTO] Refactor function body scan during importing into helper (NFC)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 24 13:15:20 PST 2015
Author: tejohnson
Date: Tue Nov 24 15:15:19 2015
New Revision: 254020
URL: http://llvm.org/viewvc/llvm-project?rev=254020&view=rev
Log:
[ThinLTO] Refactor function body scan during importing into helper (NFC)
Modified:
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=254020&r1=254019&r2=254020&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Tue Nov 24 15:15:19 2015
@@ -53,6 +53,29 @@ Module &FunctionImporter::getOrLoadModul
return *Module;
}
+/// 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());
+ }
+ }
+ }
+ }
+}
+
// Automatically import functions in Module \p M based on the summaries index.
//
// The current implementation imports every called functions that exists in the
@@ -62,23 +85,13 @@ bool FunctionImporter::importFunctions(M
bool Changed = false;
- /// First step is collecting the called functions and the one defined in this
- /// module.
+ /// First step is collecting the called external functions.
StringSet<> CalledFunctions;
+ SmallVector<StringRef, 64> Worklist;
for (auto &F : M) {
if (F.isDeclaration() || F.hasFnAttribute(Attribute::OptimizeNone))
continue;
- 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();
- if (CalledFunction && CalledFunction->hasName() &&
- CalledFunction->isDeclaration())
- CalledFunctions.insert(CalledFunction->getName());
- }
- }
- }
+ findExternalCalls(F, CalledFunctions, Worklist);
}
/// Second step: for every call to an external function, try to import it.
@@ -86,12 +99,6 @@ bool FunctionImporter::importFunctions(M
// Linker that will be used for importing function
Linker L(&M, DiagnosticHandler);
- /// Insert initial called function set in a worklist, so that we can add
- /// transively called functions when importing.
- SmallVector<StringRef, 64> Worklist;
- for (auto &CalledFunction : CalledFunctions)
- Worklist.push_back(CalledFunction.first());
-
while (!Worklist.empty()) {
auto CalledFunctionName = Worklist.pop_back_val();
DEBUG(dbgs() << "Process import for " << CalledFunctionName << "\n");
@@ -175,23 +182,7 @@ bool FunctionImporter::importFunctions(M
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());
- }
- }
- }
- }
+ findExternalCalls(*NewF, CalledFunctions, Worklist);
Changed = true;
}
More information about the llvm-commits
mailing list