Skip to content

Commit d29478f

Browse files
committedMar 27, 2016
[ThinLTO] Add optional import message and statistics
Summary: Add a statistic to count the number of imported functions. Also, add a new -print-imports option to emit a trace of imported functions, that works even for an NDEBUG build. Note that emitOptimizationRemark does not work for the above printing as it expects a Function object and DebugLoc, neither of which we have with summary-based importing. This is part 2 of D18487, the first part was committed separately as r264536. Reviewers: joker.eph Subscribers: llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D18487 llvm-svn: 264537
1 parent 9aae395 commit d29478f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎llvm/lib/Transforms/IPO/FunctionImport.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Transforms/IPO/FunctionImport.h"
1515

1616
#include "llvm/ADT/SmallVector.h"
17+
#include "llvm/ADT/Statistic.h"
1718
#include "llvm/ADT/StringSet.h"
1819
#include "llvm/IR/AutoUpgrade.h"
1920
#include "llvm/IR/DiagnosticPrinter.h"
@@ -31,6 +32,8 @@
3132

3233
using namespace llvm;
3334

35+
STATISTIC(NumImported, "Number of functions imported");
36+
3437
/// Limit on instruction count of imported functions.
3538
static cl::opt<unsigned> ImportInstrLimit(
3639
"import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"),
@@ -43,6 +46,9 @@ static cl::opt<float>
4346
"`import-instr-limit` threshold by this factor "
4447
"before processing newly imported functions"));
4548

49+
static cl::opt<bool> PrintImports("print-imports", cl::init(false), cl::Hidden,
50+
cl::desc("Print imported functions"));
51+
4652
// Load lazily a module from \p FileName in \p Context.
4753
static std::unique_ptr<Module> loadFile(const std::string &FileName,
4854
LLVMContext &Context) {
@@ -348,13 +354,21 @@ bool FunctionImporter::importFunctions(
348354
if (renameModuleForThinLTO(*SrcModule, Index, &GlobalsToImport))
349355
return true;
350356

357+
if (PrintImports) {
358+
for (const auto *GV : GlobalsToImport)
359+
dbgs() << DestModule.getSourceFileName() << ": Import " << GV->getName()
360+
<< " from " << SrcModule->getSourceFileName() << "\n";
361+
}
362+
351363
if (TheLinker.linkInModule(std::move(SrcModule), Linker::Flags::None,
352364
&GlobalsToImport))
353365
report_fatal_error("Function Import: link error");
354366

355367
ImportedCount += GlobalsToImport.size();
356368
}
357369

370+
NumImported += ImportedCount;
371+
358372
DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
359373
<< DestModule.getModuleIdentifier() << "\n");
360374
return ImportedCount;

‎llvm/test/Transforms/FunctionImport/funcimport.ll

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
55

66
; Do the import now
7-
; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF
7+
; RUN: opt -function-import -stats -print-imports -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF
88

99
; Test import with smaller instruction limit
1010
; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5
@@ -34,32 +34,41 @@ declare void @analias(...) #1
3434

3535
; Aliases import the aliasee function
3636
declare void @linkoncealias(...) #1
37+
; INSTLIMDEF-DAG: Import linkoncealias
38+
; INSTLIMDEF-DAG: Import linkoncefunc
3739
; CHECK-DAG: define linkonce_odr void @linkoncefunc()
3840
; CHECK-DAG: @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*
3941

42+
; INSTLIMDEF-DAG: Import referencestatics
4043
; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i)
4144
; INSTLIM5-DAG: declare i32 @referencestatics(...)
4245
declare i32 @referencestatics(...) #1
4346

4447
; The import of referencestatics will expose call to staticfunc that
4548
; should in turn be imported as a promoted/renamed and hidden function.
4649
; Ensure that the call is to the properly-renamed function.
50+
; INSTLIMDEF-DAG: Import staticfunc
4751
; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2()
4852
; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2()
4953

54+
; INSTLIMDEF-DAG: Import referenceglobals
5055
; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i)
5156
declare i32 @referenceglobals(...) #1
5257

5358
; The import of referenceglobals will expose call to globalfunc1 that
5459
; should in turn be imported.
60+
; INSTLIMDEF-DAG: Import globalfunc1
5561
; CHECK-DAG: define available_externally void @globalfunc1()
5662

63+
; INSTLIMDEF-DAG: Import referencecommon
5764
; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i)
5865
declare i32 @referencecommon(...) #1
5966

67+
; INSTLIMDEF-DAG: Import setfuncptr
6068
; CHECK-DAG: define available_externally void @setfuncptr()
6169
declare void @setfuncptr(...) #1
6270

71+
; INSTLIMDEF-DAG: Import callfuncptr
6372
; CHECK-DAG: define available_externally void @callfuncptr()
6473
declare void @callfuncptr(...) #1
6574

@@ -73,5 +82,9 @@ declare void @callfuncptr(...) #1
7382
; CHECK-DAG: declare void @weakfunc(...)
7483
declare void @weakfunc(...) #1
7584

85+
; INSTLIMDEF-DAG: Import funcwithpersonality
7686
; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.2() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
7787
; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.2()
88+
89+
; INSTLIMDEF-DAG: Import globalfunc2
90+
; INSTLIMDEF: 11 function-import - Number of functions imported

0 commit comments

Comments
 (0)
Please sign in to comment.