-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option #127442
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
SPGO in lto mode, linker needs -lto-sample-profile option to set sample profile file. Linux adds this option by transfering fprofile-sample-use but lld-link on Windows misses the transfering. So add it now.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: None (tianleliu) ChangesSPGO in lto mode, linker needs -lto-sample-profile option to set sample profile file. Linux adds this option by transfering fprofile-sample-use but lld-link on Windows misses the transfering. So add it now. Full diff: https://github.com/llvm/llvm-project/pull/127442.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index bae41fc06c036..1c6854e3ef775 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -232,6 +232,9 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
+ if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ))
+ CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
+ A->getValue()));
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
// Control Flow Guard checks
diff --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c
index 9bf8a8137926d..f1097ad0be9bf 100644
--- a/clang/test/Driver/cl-link.c
+++ b/clang/test/Driver/cl-link.c
@@ -71,3 +71,6 @@
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
// INFER-LLD: lld-link
// INFER-LLD-NOT: INFERASANLIBS
+
+// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -fuse-ld=lld -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s
+// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"
|
clang/test/Driver/cl-link.c
Outdated
@@ -71,3 +71,6 @@ | |||
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s | |||
// INFER-LLD: lld-link | |||
// INFER-LLD-NOT: INFERASANLIBS | |||
|
|||
// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -flto -fuse-ld=lld -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use /Tc%s?
-S should be removed.
It's option for linker. I suggest first compile it to .obj then check it when using clang_cl to invoke linker.
clang/lib/Driver/ToolChains/MSVC.cpp
Outdated
@@ -232,6 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, | |||
} | |||
} | |||
|
|||
if (C.getDriver().isUsingLTO()) { | |||
if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use getLastProfileSampleUseArg
This tittle looks like you are adding a new option -lto-sample-profile for LLD. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/5083 Here is the relevant piece of the build log for the reference
|
In SPGO lto mode, linker needs -lto-sample-profile option to set sample profile file.
Linux adds this option by transferring fprofile-sample-use to -plugin-opt=sample-profile=, which is alias of lto-sample-profile. (in clang\lib\Driver\ToolChains\CommonArgs.cpp: tools::addLTOOptions()).
But clang on Windows misses the transferring. So add it now.