[ThinLTO] Add option to limit importing based on instruction count
[oota-llvm.git] / lib / Transforms / IPO / FunctionImport.cpp
index 1f88da5e12ac6fdd3c0da56f330a0884eddb69f4..ab0f7114957b465a6154200f51b6630be48b5ff5 100644 (file)
@@ -28,6 +28,11 @@ using namespace llvm;
 
 #define DEBUG_TYPE "function-import"
 
+/// Limit on instruction count of imported functions.
+static cl::opt<unsigned> ImportInstrLimit(
+    "import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"),
+    cl::desc("Only import functions with less than N instructions"));
+
 // Load lazily a module from \p FileName in \p Context.
 static std::unique_ptr<Module> loadFile(const std::string &FileName,
                                         LLVMContext &Context) {
@@ -124,6 +129,13 @@ bool FunctionImporter::importFunctions(Module &M) {
       llvm_unreachable("Missing summary");
     }
 
+    if (Summary->instCount() > ImportInstrLimit) {
+      dbgs() << "Skip import of " << CalledFunctionName << " with "
+             << Summary->instCount() << " instructions (limit "
+             << ImportInstrLimit << ")\n";
+      continue;
+    }
+
     //
     // No profitability notion right now, just import all the time...
     //