From: Teresa Johnson Date: Tue, 24 Nov 2015 22:55:46 +0000 (+0000) Subject: [ThinLTO] Add option to limit importing based on instruction count X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f65b5feba490438fca8b365dc84cee69f7d97ec7;p=oota-llvm.git [ThinLTO] Add option to limit importing based on instruction count Add a simple initial heuristic to control importing based on the number of instructions recorded in the function's summary. Add option to control the limit, and test using option. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254036 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/FunctionImport.cpp b/lib/Transforms/IPO/FunctionImport.cpp index 1f88da5e12a..ab0f7114957 100644 --- a/lib/Transforms/IPO/FunctionImport.cpp +++ b/lib/Transforms/IPO/FunctionImport.cpp @@ -28,6 +28,11 @@ using namespace llvm; #define DEBUG_TYPE "function-import" +/// Limit on instruction count of imported functions. +static cl::opt 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 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... // diff --git a/test/Transforms/FunctionImport/funcimport.ll b/test/Transforms/FunctionImport/funcimport.ll index 553d05bfcf3..57452b1ec53 100644 --- a/test/Transforms/FunctionImport/funcimport.ll +++ b/test/Transforms/FunctionImport/funcimport.ll @@ -4,7 +4,11 @@ ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc ; Do the import now -; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF + +; Test import with smaller instruction limit +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5 +; INSTLIM5-NOT: @staticfunc.llvm.2 define i32 @main() #0 { entry: @@ -28,14 +32,15 @@ declare void @weakalias(...) #1 ; CHECK-DAG: define available_externally void @globalfunc2() declare void @analias(...) #1 -; CHECK-DAG: define available_externally i32 @referencestatics(i32 %i) +; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) +; INSTLIM5-DAG: declare i32 @referencestatics(...) declare i32 @referencestatics(...) #1 ; The import of referencestatics will expose call to staticfunc that ; should in turn be imported as a promoted/renamed and hidden function. ; Ensure that the call is to the properly-renamed function. -; CHECK-DAG: %call = call i32 @staticfunc.llvm.2() -; CHECK-DAG: define available_externally hidden i32 @staticfunc.llvm.2() +; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2() +; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2() ; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) declare i32 @referenceglobals(...) #1