Skip to content

[lld][MachO] Add option to suppress mismatch profile errors #65551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lld/MachO/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ struct Configuration {
bool ltoDebugPassManager = false;
bool csProfileGenerate = false;
llvm::StringRef csProfilePath;
bool pgoWarnMismatch;

bool callGraphProfileSort = false;
llvm::StringRef printSymbolOrder;
Expand Down
2 changes: 2 additions & 0 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions lld/MachO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lld/MachO/Options.td
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions lld/test/MachO/pgo-warn-mismatch.ll
Original file line number Diff line number Diff line change
@@ -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