[llvm-branch-commits] [llvm] 01f0d16 - Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

Hongtao Yu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 2 14:30:34 PST 2021


Author: Hongtao Yu
Date: 2021-01-02T14:26:21-08:00
New Revision: 01f0d162d672c02b7207e0b3a6c494c4d0ea513d

URL: https://github.com/llvm/llvm-project/commit/01f0d162d672c02b7207e0b3a6c494c4d0ea513d
DIFF: https://github.com/llvm/llvm-project/commit/01f0d162d672c02b7207e0b3a6c494c4d0ea513d.diff

LOG: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

`UniqueInternalLinkageNamesPass` is useful to CSSPGO, especially when pseudo probe is used. It solves naming conflict for static functions which otherwise will share a merged profile and likely have a profile quality issue with mismatched CFG checksums. Since the pseudo probe instrumentation happens very early in the pipeline, I'm moving `UniqueInternalLinkageNamesPass` right before it. This is being done only to the new pass manager.

Reviewed By: dblaikie, aeubanks

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

Added: 
    llvm/test/Other/new-pm-pseudo-probe.ll
    llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Modified: 
    llvm/include/llvm/Passes/PassBuilder.h
    llvm/lib/Passes/PassBuilder.cpp
    llvm/tools/opt/NewPMDriver.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 5a13df5b0c86..fdd4474a8ff0 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -127,6 +127,9 @@ class PipelineTuningOptions {
   /// Tuning option to enable/disable function merging. Its default value is
   /// false.
   bool MergeFunctions;
+
+  /// Uniquefy function linkage name. Its default value is false.
+  bool UniqueLinkageNames;
 };
 
 /// This class provides access to building LLVM's passes.

diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index dad40a2f540f..95f58d9e3f73 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -285,6 +285,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
   LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
   CallGraphProfile = true;
   MergeFunctions = false;
+  UniqueLinkageNames = false;
 }
 
 extern cl::opt<bool> EnableConstraintElimination;
@@ -1003,6 +1004,11 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
                                                ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+    MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1773,6 +1779,11 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+    MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
                  PGOOpt->Action == PGOOptions::IRUse))
     addPGOInstrPassesForO0(

diff  --git a/llvm/test/Other/new-pm-pseudo-probe.ll b/llvm/test/Other/new-pm-pseudo-probe.ll
new file mode 100644
index 000000000000..4d3f20556f2c
--- /dev/null
+++ b/llvm/test/Other/new-pm-pseudo-probe.ll
@@ -0,0 +1,12 @@
+; RUN: opt -S -passes='default<O1>' -new-pm-pseudo-probe-for-profiling -debug-pass-manager < %s 2>&1 | FileCheck %s
+; RUN: opt -S -passes='default<O2>' -new-pm-pseudo-probe-for-profiling -debug-pass-manager < %s 2>&1 | FileCheck %s
+; RUN: opt -S -passes='thinlto-pre-link<O1>' -new-pm-pseudo-probe-for-profiling -debug-pass-manager < %s 2>&1 | FileCheck %s
+; RUN: opt -S -passes='thinlto-pre-link<O2>' -new-pm-pseudo-probe-for-profiling -debug-pass-manager < %s 2>&1 | FileCheck %s
+
+define void @foo() {
+  ret void
+}
+
+;; Check the SampleProfileProbePass is enabled under the -new-pm-pseudo-probe-for-profiling switch.
+;; The switch can be used to test a specific pass order in a particular setup, e.g, in unique-internal-linkage-names.ll
+; CHECK: Running pass: SampleProfileProbePass

diff  --git a/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll b/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
new file mode 100644
index 000000000000..716009dbd0cc
--- /dev/null
+++ b/llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,24 @@
+; RUN: opt -S -passes='default<O0>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default<O1>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default<O2>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link<O1>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link<O2>' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+
+define internal i32 @foo() {
+entry:
+  ret i32 0
+}
+
+define dso_local i32 (...)* @bar() {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
+}
+
+; O0: Running pass: UniqueInternalLinkageNamesPass
+
+;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass.
+; O2: Running pass: UniqueInternalLinkageNamesPass
+; O2: Running pass: SampleProfileProbePass
+
+; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}

diff  --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 9badbdf64932..67c5a32168a0 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -134,6 +134,13 @@ static cl::opt<std::string>
 static cl::opt<bool> DebugInfoForProfiling(
     "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
     cl::desc("Emit special debug info to enable PGO profile generation."));
+static cl::opt<bool> PseudoProbeForProfiling(
+    "new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
+    cl::desc("Emit pseudo probes to enable PGO profile generation."));
+static cl::opt<bool> UniqueInternalLinkageNames(
+    "new-pm-unique-internal-linkage-names", cl::init(false), cl::Hidden,
+    cl::desc("Uniqueify Internal Linkage Symbol Names by appending the MD5 "
+             "hash of the module path."));
 /// @}}
 
 template <typename PassManagerT>
@@ -247,6 +254,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
     if (DebugInfoForProfiling)
       P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
                      true);
+    else if (PseudoProbeForProfiling)
+      P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+                     false, true);
     else
       P = None;
   }
@@ -282,6 +292,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
   // option has been enabled.
   PTO.LoopUnrolling = !DisableLoopUnrolling;
   PTO.Coroutines = Coroutines;
+  PTO.UniqueLinkageNames = UniqueInternalLinkageNames;
   PassBuilder PB(DebugPM, TM, PTO, P, &PIC);
   registerEPCallbacks(PB);
 


        


More information about the llvm-branch-commits mailing list