[lld] 30e688e - [lld][MachO] Add option to suppress mismatch profile errors (#65551)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 09:14:00 PDT 2023


Author: Ellis Hoag
Date: 2023-09-11T09:13:55-07:00
New Revision: 30e688e6d061bf0f2a6fcbe39d2d23560a363436

URL: https://github.com/llvm/llvm-project/commit/30e688e6d061bf0f2a6fcbe39d2d23560a363436
DIFF: https://github.com/llvm/llvm-project/commit/30e688e6d061bf0f2a6fcbe39d2d23560a363436.diff

LOG: [lld][MachO] Add option to suppress mismatch profile errors (#65551)

Both ELF and COFF support `--no-lto-pgo-warn-mismatch` in
https://reviews.llvm.org/D104431 to suppress warnings due to mismatching
profile hashes. As profiles go stale, it becomes likely that some
function's CFGs will change so that their profiles can no longer be
used. This commit adds the linker option `--no-pgo-warn-mismatch` to
suppress these warnings.

Note that we do have the LLVM backend flag `no-pgo-warn-mismatch`
https://github.com/llvm/llvm-project/blob/3df1a64ebad8f31231ba05cf6ff43a985fea9235/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp#L210

but that is set to true by default during LTO
https://github.com/llvm/llvm-project/blob/3df1a64ebad8f31231ba05cf6ff43a985fea9235/llvm/include/llvm/LTO/Config.h#L76-L77

Added: 
    lld/test/MachO/pgo-warn-mismatch.ll

Modified: 
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/LTO.cpp
    lld/MachO/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 59eb882c078369a..3191396f65b832f 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -208,6 +208,7 @@ struct Configuration {
   bool ltoDebugPassManager = false;
   bool csProfileGenerate = false;
   llvm::StringRef csProfilePath;
+  bool pgoWarnMismatch;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 2ef170254c2ec4f..00ff3439a043be9 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1670,6 +1670,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
   config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
   config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
+  config->pgoWarnMismatch =
+      args.hasFlag(OPT_pgo_warn_mismatch, OPT_no_pgo_warn_mismatch, true);
   config->generateUuid = !args.hasArg(OPT_no_uuid);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {

diff  --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 7a852f48dde84b1..a5b0f4d3d2a746d 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -71,6 +71,7 @@ static lto::Config createConfig() {
   c.DebugPassManager = config->ltoDebugPassManager;
   c.CSIRProfile = std::string(config->csProfilePath);
   c.RunCSIRInstr = config->csProfileGenerate;
+  c.PGOWarnMismatch = config->pgoWarnMismatch;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index b60f5e44c3c1d90..f92e6cda31e5297 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -1,5 +1,10 @@
 include "llvm/Option/OptParser.td"
 
+multiclass BB<string name, string help1, string help2> {
+  def NAME: Flag<["--"], name>, HelpText<help1>;
+  def no_ # NAME: Flag<["--"], "no-" # name>, HelpText<help2>;
+}
+
 // Flags that lld/MachO understands but ld64 doesn't. These take
 // '--' instead of '-' and use dashes instead of underscores, so
 // they don't collide with the ld64 compat options.
@@ -130,6 +135,9 @@ def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
     HelpText<"Perform context senstive PGO instrumentation">, Group<grp_lld>;
 def cs_profile_path: Joined<["--"], "cs-profile-path=">,
     HelpText<"Context sensitive profile file path">, Group<grp_lld>;
+defm pgo_warn_mismatch: BB<"pgo-warn-mismatch",
+  "turn on warnings about profile cfg mismatch (default)",
+  "turn off warnings about profile cfg mismatch">, Group<grp_lld>;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo

diff  --git a/lld/test/MachO/pgo-warn-mismatch.ll b/lld/test/MachO/pgo-warn-mismatch.ll
new file mode 100644
index 000000000000000..632adffb01fb3ee
--- /dev/null
+++ b/lld/test/MachO/pgo-warn-mismatch.ll
@@ -0,0 +1,34 @@
+; REQUIRES: x86
+
+; RUN: rm -rf %t && split-file %s %t
+; RUN: llvm-as %t/a.ll -o %t/a.o
+; RUN: llvm-profdata merge %t/cs.proftext -o %t/cs.profdata
+
+;; Ensure lld generates warnings for profile cfg mismatch.
+; RUN: not %lld -dylib --cs-profile-path=%t/cs.profdata %t/a.o -o /dev/null 2>&1 | FileCheck %s
+; RUN: not %lld -dylib --cs-profile-path=%t/cs.profdata --pgo-warn-mismatch %t/a.o -o /dev/null 2>&1 | FileCheck %s
+
+;; Ensure lld will not generate warnings for profile cfg mismatch.
+; RUN: %lld -dylib --cs-profile-path=%t/cs.profdata --no-pgo-warn-mismatch %t/a.o -o /dev/null
+
+; CHECK: function control flow change detected (hash mismatch) foo Hash = [[#]]
+
+;--- a.ll
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define i32 @foo() {
+entry:
+  ret i32 0
+}
+
+;--- cs.proftext
+:csir
+_foo
+# Func Hash:
+2277602155505015273
+# Num Counters:
+2
+# Counter Values:
+1
+0


        


More information about the llvm-commits mailing list