[llvm] r280024 - [ThinLTO] Indirect call promotion fixes for promoted local functions

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 29 15:46:57 PDT 2016


Author: tejohnson
Date: Mon Aug 29 17:46:56 2016
New Revision: 280024

URL: http://llvm.org/viewvc/llvm-project?rev=280024&view=rev
Log:
[ThinLTO] Indirect call promotion fixes for promoted local functions

Summary:
Fix a couple issues limiting the application of indirect call promotion
in ThinLTO mode:
- Invoke indirect call promotion before globalopt, since it may
  eliminate imported functions which appear unreferenced.
- Invoke indirect call promotion with InLTO=true so that the PGOFuncName
  metadata is used to get the name for locals which would have been
  renamed during promotion.

Reviewers: davidxl, mehdi_amini

Subscribers: Prazek, llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D24004

Modified:
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
    llvm/trunk/test/Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.ll
    llvm/trunk/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=280024&r1=280023&r2=280024&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Mon Aug 29 17:46:56 2016
@@ -136,6 +136,9 @@ std::string getPGOFuncName(StringRef Raw
 // (when \c InLTO is true): LTO's internalization privatizes many global linkage
 // symbols. This happens after value profile annotation, but those internal
 // linkage functions should not have a source prefix.
+// Additionally, for ThinLTO mode, exported internal functions are promoted
+// and renamed. We need to ensure that the original internal PGO name is
+// used when computing the GUID that is compared against the profiled GUIDs.
 // To differentiate compiler generated internal symbols from original ones,
 // PGOFuncName meta data are created and attached to the original internal
 // symbols in the value profile annotation step

Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=280024&r1=280023&r2=280024&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Mon Aug 29 17:46:56 2016
@@ -405,6 +405,16 @@ void PassManagerBuilder::populateModuleP
 
   addInitialAliasAnalysisPasses(MPM);
 
+  // For ThinLTO there are two passes of indirect call promotion. The
+  // first is during the compile phase when PerformThinLTO=false and
+  // intra-module indirect call targets are promoted. The second is during
+  // the ThinLTO backend when PerformThinLTO=true, when we promote imported
+  // inter-module indirect calls. For that we perform indirect call promotion
+  // earlier in the pass pipeline, here before globalopt. Otherwise imported
+  // available_externally functions look unreferenced and are removed.
+  if (PerformThinLTO)
+    MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true));
+
   if (!DisableUnitAtATime) {
     // Infer attributes about declarations if possible.
     MPM.add(createInferFunctionAttrsLegacyPass());
@@ -427,11 +437,12 @@ void PassManagerBuilder::populateModuleP
     /// PGO instrumentation is added during the compile phase for ThinLTO, do
     /// not run it a second time
     addPGOInstrPasses(MPM);
+    // Indirect call promotion that promotes intra-module targets only.
+    // For ThinLTO this is done earlier due to interactions with globalopt
+    // for imported functions.
+    MPM.add(createPGOIndirectCallPromotionLegacyPass());
   }
 
-  // Indirect call promotion that promotes intra-module targets only.
-  MPM.add(createPGOIndirectCallPromotionLegacyPass());
-
   if (EnableNonLTOGlobalsModRef)
     // We add a module alias analysis pass here. In part due to bugs in the
     // analysis infrastructure this "works" in that the analysis stays alive

Modified: llvm/trunk/test/Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.ll?rev=280024&r1=280023&r2=280024&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/Inputs/thinlto_indirect_call_promotion.ll Mon Aug 29 17:46:56 2016
@@ -1,7 +1,16 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
+source_filename = "thinlto_indirect_call_promotion.c"
+
 define void @a() {
 entry:
   ret void
 }
+
+define internal void @c() !PGOFuncName !1 {
+entry:
+  ret void
+}
+
+!1 = !{!"thinlto_indirect_call_promotion.c:c"}

Modified: llvm/trunk/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll?rev=280024&r1=280023&r2=280024&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll Mon Aug 29 17:46:56 2016
@@ -4,26 +4,33 @@
 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
 
 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -o %t4.bc -print-imports 2>&1 | FileCheck %s --check-prefix=IMPORTS
-; IMPORTS: Import a
+; IMPORTS-DAG: Import a
+; IMPORTS-DAG: Import c
 
-; RUN: opt %t4.bc -pgo-icall-prom -S -icp-count-threshold=1 | FileCheck %s --check-prefix=ICALL-PROM
-; RUN: opt %t4.bc -pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-count-threshold=1 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
+; RUN: opt %t4.bc -icp-lto -pgo-icall-prom -S -icp-count-threshold=1 | FileCheck %s --check-prefix=ICALL-PROM
+; RUN: opt %t4.bc -icp-lto -pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-count-threshold=1 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
 ; PASS-REMARK: Promote indirect call to a with count 1 out of 1
+; PASS-REMARK: Promote indirect call to c.llvm.0 with count 1 out of 1
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
 @foo = external local_unnamed_addr global void ()*, align 8
+ at bar = external local_unnamed_addr global void ()*, align 8
 
 define i32 @main() local_unnamed_addr {
 entry:
   %0 = load void ()*, void ()** @foo, align 8
 ; ICALL-PROM:   br i1 %{{[0-9]+}}, label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
   tail call void %0(), !prof !1
+  %1 = load void ()*, void ()** @bar, align 8
+; ICALL-PROM:   br i1 %{{[0-9]+}}, label %if.true.direct_targ1, label %if.false.orig_indirect2, !prof [[BRANCH_WEIGHT:![0-9]+]]
+  tail call void %1(), !prof !2
   ret i32 0
 }
 
 !1 = !{!"VP", i32 0, i64 1, i64 -6289574019528802036, i64 1}
+!2 = !{!"VP", i32 0, i64 1, i64 591260329866125152, i64 1}
 
 ; Should not have a VP annotation on new indirect call (check before and after
 ; branch_weights annotation).




More information about the llvm-commits mailing list