[llvm] r289957 - Pass sample pgo flags to thinlto.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 08:48:46 PST 2016


Author: dehao
Date: Fri Dec 16 10:48:46 2016
New Revision: 289957

URL: http://llvm.org/viewvc/llvm-project?rev=289957&view=rev
Log:
Pass sample pgo flags to thinlto.

Summary: ThinLTO needs to invoke SampleProfileLoader pass during link time in order to annotate profile correctly after module importing.

Reviewers: davidxl, mehdi_amini, tejohnson

Subscribers: pcc, davide, llvm-commits, mehdi_amini

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

Added:
    llvm/trunk/test/tools/gold/X86/Inputs/afdo.prof
    llvm/trunk/test/tools/gold/X86/thinlto_afdo.ll
Modified:
    llvm/trunk/include/llvm/LTO/Config.h
    llvm/trunk/lib/LTO/LTO.cpp
    llvm/trunk/lib/LTO/LTOBackend.cpp
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/include/llvm/LTO/Config.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/Config.h?rev=289957&r1=289956&r2=289957&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/Config.h (original)
+++ llvm/trunk/include/llvm/LTO/Config.h Fri Dec 16 10:48:46 2016
@@ -65,6 +65,9 @@ struct Config {
   /// with this triple.
   std::string DefaultTriple;
 
+  /// Sample PGO profile path.
+  std::string SampleProfile;
+
   bool ShouldDiscardValueNames = true;
   DiagnosticHandlerFunction DiagHandler;
 

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=289957&r1=289956&r2=289957&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Fri Dec 16 10:48:46 2016
@@ -129,6 +129,12 @@ static void computeCacheKey(
         ArrayRef<uint8_t>((const uint8_t *)&Linkage, sizeof(Linkage)));
   }
 
+  if (!Conf.SampleProfile.empty()) {
+    auto FileOrErr = MemoryBuffer::getFile(Conf.SampleProfile);
+    if (FileOrErr)
+      Hasher.update(FileOrErr.get()->getBuffer());
+  }
+
   Key = toHex(Hasher.result());
 }
 

Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=289957&r1=289956&r2=289957&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Fri Dec 16 10:48:46 2016
@@ -182,6 +182,7 @@ static void runOldPMPasses(Config &Conf,
   PMB.LoopVectorize = true;
   PMB.SLPVectorize = true;
   PMB.OptLevel = Conf.OptLevel;
+  PMB.PGOSampleUse = Conf.SampleProfile;
   if (IsThinLTO)
     PMB.populateThinLTOPassManager(passes);
   else

Added: llvm/trunk/test/tools/gold/X86/Inputs/afdo.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/Inputs/afdo.prof?rev=289957&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/X86/Inputs/afdo.prof (added)
+++ llvm/trunk/test/tools/gold/X86/Inputs/afdo.prof Fri Dec 16 10:48:46 2016
@@ -0,0 +1,2 @@
+f:100:3
+ 1: 100

Added: llvm/trunk/test/tools/gold/X86/thinlto_afdo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/thinlto_afdo.ll?rev=289957&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/X86/thinlto_afdo.ll (added)
+++ llvm/trunk/test/tools/gold/X86/thinlto_afdo.ll Fri Dec 16 10:48:46 2016
@@ -0,0 +1,25 @@
+; Generate summary sections
+; RUN: opt -module-summary %s -o %t1.o
+; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
+
+; RUN: rm -f %t1.o.4.opt.bc
+; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:    --plugin-opt=thinlto \
+; RUN:    --plugin-opt=save-temps \
+; RUN:    --plugin-opt=sample-profile=%p/Inputs/afdo.prof \
+; RUN:    --plugin-opt=jobs=1 \
+; RUN:    -shared %t1.o %t2.o -o %t3
+; RUN: opt -S %t1.o.4.opt.bc | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; CHECK: ProfileSummary
+declare void @g(...)
+declare void @h(...)
+
+define void @f() {
+entry:
+  call void (...) @g()
+  call void (...) @h()
+  ret void
+}

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=289957&r1=289956&r2=289957&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Dec 16 10:48:46 2016
@@ -171,6 +171,8 @@ namespace options {
   // Note: This array will contain all plugin options which are not claimed
   // as plugin exclusive to pass to the code generator.
   static std::vector<const char *> extra;
+  // Sample profile file path
+  static std::string sample_profile;
 
   static void process_plugin_option(const char *opt_)
   {
@@ -220,6 +222,8 @@ namespace options {
         message(LDPL_FATAL, "Invalid codegen partition level: %s", opt_ + 5);
     } else if (opt == "disable-verify") {
       DisableVerify = true;
+    } else if (opt.startswith("sample-profile=")) {
+      sample_profile= opt.substr(strlen("sample-profile="));
     } else {
       // Save this option to pass to the code generator.
       // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -728,6 +732,9 @@ static std::unique_ptr<LTO> createLTO()
     break;
   }
 
+  if (!options::sample_profile.empty())
+    Conf.SampleProfile = options::sample_profile;
+
   return llvm::make_unique<LTO>(std::move(Conf), Backend,
                                 options::ParallelCodeGenParallelismLevel);
 }




More information about the llvm-commits mailing list