[PATCH] D23144: Add instruction_count MD to imported functions

Piotr Padlewski via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 14:22:19 PDT 2016


Prazek updated this revision to Diff 66856.
Prazek marked an inline comment as done.
Prazek added a comment.

Update


https://reviews.llvm.org/D23144

Files:
  lib/Transforms/IPO/FunctionImport.cpp
  test/Transforms/FunctionImport/funcimport.ll

Index: test/Transforms/FunctionImport/funcimport.ll
===================================================================
--- test/Transforms/FunctionImport/funcimport.ll
+++ test/Transforms/FunctionImport/funcimport.ll
@@ -49,36 +49,36 @@
 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
 
 ; 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.
 ; 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
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<FunctionSummary>(
+                  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);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23144.66856.patch
Type: text/x-patch
Size: 5118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160804/eeb1482e/attachment.bin>


More information about the llvm-commits mailing list