diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h index 59eb882c07836..3191396f65b83 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 2ef170254c2ec..00ff3439a043b 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1670,6 +1670,8 @@ bool link(ArrayRef 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 7a852f48dde84..a5b0f4d3d2a74 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 b60f5e44c3c1d..f92e6cda31e52 100644 --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -1,5 +1,10 @@ include "llvm/Option/OptParser.td" +multiclass BB { + def NAME: Flag<["--"], name>, HelpText; + def no_ # NAME: Flag<["--"], "no-" # name>, HelpText; +} + // 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; def cs_profile_path: Joined<["--"], "cs-profile-path=">, HelpText<"Context sensitive profile file path">, Group; +defm pgo_warn_mismatch: BB<"pgo-warn-mismatch", + "turn on warnings about profile cfg mismatch (default)", + "turn off warnings about profile cfg mismatch">, Group; // 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 0000000000000..632adffb01fb3 --- /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