Index: include/llvm/Transforms/IPO/FunctionImport.h =================================================================== --- include/llvm/Transforms/IPO/FunctionImport.h +++ include/llvm/Transforms/IPO/FunctionImport.h @@ -29,11 +29,12 @@ /// based on the provided summary informations. class FunctionImporter { public: + using ImportThresholdTy = unsigned; /// Set of functions to import from a source module. Each entry is a map /// containing all the functions to import for a source module. /// The keys is the GUID identifying a function to import, and the value /// is the threshold applied when deciding to import it. - typedef std::map FunctionsToImportTy; + typedef std::map FunctionsToImportTy; /// The map contains an entry for every module to import from, the key being /// the module identifier to pass to the ModuleLoader. The value is the set of Index: include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h =================================================================== --- include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h +++ include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h @@ -77,6 +77,7 @@ int32_t NumberOfRealInlines = 0; bool Imported = false; bool Visited = false; + unsigned NumberOfInstructions = 0; }; public: Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -601,6 +601,8 @@ << SrcModule->getSourceFileName() << "\n"); if (Import) { F.materialize(); + GlobalsToImport.insert(&F); + if (EnableImportMetadata) { // Add 'thinlto_src_module' metadata for statistics and debugging. F.setMetadata( @@ -609,8 +611,19 @@ DestModule.getContext(), {llvm::MDString::get(DestModule.getContext(), SrcModule->getSourceFileName())})); + + const auto InstructionCount = + cast( + Index.getGlobalValueSummary(F.getGUID(), false)) + ->instCount(); + F.setMetadata( + "instructions_count", + llvm::MDNode::get( + DestModule.getContext(), + {llvm::ConstantAsMetadata::get(ConstantInt::getIntegerValue( + Type::getInt32Ty(DestModule.getContext()), + APInt(32, InstructionCount)))})); } - GlobalsToImport.insert(&F); } } for (GlobalVariable &GV : SrcModule->globals()) { Index: test/Transforms/FunctionImport/funcimport.ll =================================================================== --- test/Transforms/FunctionImport/funcimport.ll +++ test/Transforms/FunctionImport/funcimport.ll @@ -49,7 +49,7 @@ declare void @linkoncealias(...) #1 ; INSTLIMDEF-DAG: Import referencestatics -; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 { +; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module ![[MOD:.*]] !instructions_count ; INSTLIM5-DAG: declare i32 @referencestatics(...) declare i32 @referencestatics(...) #1 @@ -58,27 +58,27 @@ ; Ensure that the call is to the properly-renamed function. ; INSTLIMDEF-DAG: Import staticfunc ; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm. -; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 { +; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module ![[MOD]] ; INSTLIMDEF-DAG: Import referenceglobals -; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 { +; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module ![[MOD:.*]] !instructions_count ![[COUNT:.*]] { declare i32 @referenceglobals(...) #1 ; The import of referenceglobals will expose call to globalfunc1 that ; should in turn be imported. ; INSTLIMDEF-DAG: Import globalfunc1 -; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 +; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module ![[MOD]] ; INSTLIMDEF-DAG: Import referencecommon -; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 { +; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module ![[MOD]] declare i32 @referencecommon(...) #1 ; INSTLIMDEF-DAG: Import setfuncptr -; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 { +; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module ![[MOD]] declare void @setfuncptr(...) #1 ; INSTLIMDEF-DAG: Import callfuncptr -; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 { +; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module ![[MOD]] declare void @callfuncptr(...) #1 ; Ensure that all uses of local variable @P which has used in setfuncptr @@ -89,7 +89,7 @@ ; Ensure that @referencelargelinkonce definition is pulled in, but later we ; also check that the linkonceodr function is not. -; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 { +; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module ![[MOD]] ; INSTLIM5-DAG: declare void @linkonceodr() declare void @referencelargelinkonce(...) @@ -102,12 +102,14 @@ declare void @linkoncefunc2(...) #1 ; INSTLIMDEF-DAG: Import funcwithpersonality -; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 { +; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() ; INSTLIMDEF-DAG: Import globalfunc2 ; INSTLIMDEF-DAG: 13 function-import - Number of functions imported -; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} + +; CHECK-DAG: !{{.*}} = !{!"{{.*}}/Inputs/funcimport.ll"} +; CHECK-DAG: ![[COUNT]] = !{i32 5} ; The actual GUID values will depend on path to test. ; GUID-DAG: GUID {{.*}} is weakalias