Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -609,6 +609,18 @@ DestModule.getContext(), {llvm::MDString::get(DestModule.getContext(), SrcModule->getSourceFileName())})); + + const auto InstructionCount = + cast( + Index.getGlobalValueSummary(F.getGUID(), false)) + ->instCount(); + F.setMetadata( + "thinlto_inst_count", + llvm::MDNode::get( + DestModule.getContext(), + {llvm::ConstantAsMetadata::get(ConstantInt::getIntegerValue( + Type::getInt32Ty(DestModule.getContext()), + APInt(32, InstructionCount)))})); } GlobalsToImport.insert(&F); } 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:.*]] !thinlto_inst_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]] !thinlto_inst_count ; 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:.*]] !thinlto_inst_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]] !thinlto_inst_count ; 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]] !thinlto_inst_count 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]] !thinlto_inst_count 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]] !thinlto_inst_count 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]] !thinlto_inst_count ; 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 !thinlto_inst_count ; 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