Skip to content

Conversation

@HaohaiWen
Copy link
Contributor

Sampling PGO has already been supported on Windows. This patch adds
/fprofile-sample-use= /fprofile-sample-use: /fno-profile-sample-use and
supports -fprofile-sample-use= for CL.

Sampling PGO has already been supported on Windows. This patch adds
/fprofile-sample-use= /fprofile-sample-use: /fno-profile-sample-use
and supports -fprofile-sample-use= for CL.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Nov 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2024

@llvm/pr-subscribers-clang-driver

Author: Haohai Wen (HaohaiWen)

Changes

Sampling PGO has already been supported on Windows. This patch adds
/fprofile-sample-use= /fprofile-sample-use: /fno-profile-sample-use and
supports -fprofile-sample-use= for CL.


Full diff: https://github.com/llvm/llvm-project/pull/117282.diff

3 Files Affected:

  • (modified) clang/docs/UsersManual.rst (+2-2)
  • (modified) clang/include/clang/Driver/Options.td (+4-1)
  • (modified) clang/test/Driver/cl-options.c (+8)
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2ef603d64557f3..e5d67bc58350c7 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2660,7 +2660,7 @@ usual build cycle when using sample profilers for optimization:
 
      > clang-cl /O2 -gdwarf -gline-tables-only ^
        /clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
-       /fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
+       /fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
 
    [OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
    edge counters. The profile inference algorithm (profi) can be used to infer
@@ -2679,7 +2679,7 @@ usual build cycle when using sample profilers for optimization:
 
      > clang-cl /clang:-fsample-profile-use-profi /O2 -gdwarf -gline-tables-only ^
        /clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
-       /fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
+       /fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
 
 Sample Profile Formats
 """"""""""""""""""""""
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..3a9655d89ff67b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1736,7 +1736,7 @@ def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group<f_Grou
     Visibility<[ClangOption, CLOption]>;
 def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
     Group<f_Group>,
-    Visibility<[ClangOption, CC1Option]>,
+    Visibility<[ClangOption, CLOption, CC1Option]>,
     HelpText<"Enable sample-based profile guided optimizations">,
     MarshallingInfoString<CodeGenOpts<"SampleProfileFile">>;
 def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
@@ -8484,6 +8484,9 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias<ffp_model_EQ>, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias<fsanitize_EQ>, AliasArgs<["address"]>;
+def : CLJoined<"fno-profile-sample-use">, Alias<fno_profile_sample_use>;
+def : CLJoined<"fprofile-sample-use:">, Alias<fprofile_sample_use_EQ>;
+def : CLJoined<"fprofile-sample-use=">, Alias<fprofile_sample_use_EQ>;
 def _SLASH_GA : CLFlag<"GA">, Alias<ftlsmodel_EQ>, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 8191fda97788c1..f219304111a94c 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -101,6 +101,14 @@
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
+// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
+
+// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof /fno-profile-sample-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-SAMPLE-USE %s
+// CHECK-NO-PROFILE-SAMPLE-USE-NOT: "-fprofile-sample-use={{.*}}/file.prof"
+
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 

@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2024

@llvm/pr-subscribers-clang

Author: Haohai Wen (HaohaiWen)

Changes

Sampling PGO has already been supported on Windows. This patch adds
/fprofile-sample-use= /fprofile-sample-use: /fno-profile-sample-use and
supports -fprofile-sample-use= for CL.


Full diff: https://github.com/llvm/llvm-project/pull/117282.diff

3 Files Affected:

  • (modified) clang/docs/UsersManual.rst (+2-2)
  • (modified) clang/include/clang/Driver/Options.td (+4-1)
  • (modified) clang/test/Driver/cl-options.c (+8)
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 2ef603d64557f3..e5d67bc58350c7 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2660,7 +2660,7 @@ usual build cycle when using sample profilers for optimization:
 
      > clang-cl /O2 -gdwarf -gline-tables-only ^
        /clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
-       /fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
+       /fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
 
    [OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
    edge counters. The profile inference algorithm (profi) can be used to infer
@@ -2679,7 +2679,7 @@ usual build cycle when using sample profilers for optimization:
 
      > clang-cl /clang:-fsample-profile-use-profi /O2 -gdwarf -gline-tables-only ^
        /clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
-       /fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
+       /fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
 
 Sample Profile Formats
 """"""""""""""""""""""
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..3a9655d89ff67b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1736,7 +1736,7 @@ def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group<f_Grou
     Visibility<[ClangOption, CLOption]>;
 def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
     Group<f_Group>,
-    Visibility<[ClangOption, CC1Option]>,
+    Visibility<[ClangOption, CLOption, CC1Option]>,
     HelpText<"Enable sample-based profile guided optimizations">,
     MarshallingInfoString<CodeGenOpts<"SampleProfileFile">>;
 def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
@@ -8484,6 +8484,9 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias<ffp_model_EQ>, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias<fsanitize_EQ>, AliasArgs<["address"]>;
+def : CLJoined<"fno-profile-sample-use">, Alias<fno_profile_sample_use>;
+def : CLJoined<"fprofile-sample-use:">, Alias<fprofile_sample_use_EQ>;
+def : CLJoined<"fprofile-sample-use=">, Alias<fprofile_sample_use_EQ>;
 def _SLASH_GA : CLFlag<"GA">, Alias<ftlsmodel_EQ>, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 8191fda97788c1..f219304111a94c 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -101,6 +101,14 @@
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
+// RUN: %clang_cl -### /FA -fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// RUN: %clang_cl -### /FA /fprofile-sample-use:%S/Inputs/file.prof -- %s 2>&1 | FileCheck --check-prefix=CHECK-PROFILE-SAMPLE-USE %s
+// CHECK-PROFILE-SAMPLE-USE: "-fprofile-sample-use={{.*}}/file.prof"
+
+// RUN: %clang_cl -### /FA /fprofile-sample-use=%S/Inputs/file.prof /fno-profile-sample-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-SAMPLE-USE %s
+// CHECK-NO-PROFILE-SAMPLE-USE-NOT: "-fprofile-sample-use={{.*}}/file.prof"
+
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 

> clang-cl /O2 -gdwarf -gline-tables-only ^
/clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
/fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it this wasn't working? (Neither /fprofile-sample-use nor /fuse-ld?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I checked options.td.
-fprofile-sample-use was not a CLOption and there's no /fuse-ld.

Copy link
Contributor

@tcreech-intel tcreech-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@HaohaiWen HaohaiWen added the clang-cl `clang-cl` driver. Don't use for other compiler parts label Nov 25, 2024
def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
HelpText<"Enable AddressSanitizer">,
Alias<fsanitize_EQ>, AliasArgs<["address"]>;
def : CLJoined<"fno-profile-sample-use">, Alias<fno_profile_sample_use>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these aliases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, /fprofile-sample-use= is needed.
I saw other CL _EQ flags has _COL alias.
In fact, I don't really need /fno-profile-sample-use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed /fno-profile-sample-use.

@HaohaiWen
Copy link
Contributor Author

I'd like to merge it in if no objection.

@HaohaiWen HaohaiWen merged commit c8cd497 into llvm:main Nov 28, 2024
9 checks passed
@HaohaiWen HaohaiWen deleted the cl branch November 28, 2024 01:33
@MaskRay
Copy link
Member

MaskRay commented Nov 28, 2024

Adding CLOption to -fprofile-sample-use= suffices.
We don't need these CLJoined aliases. They are for MSVC options that are ported to clang.
For clang-specific options, we don't want to add unneeded aliases.

@HaohaiWen
Copy link
Contributor Author

Adding CLOption to -fprofile-sample-use= suffices. We don't need these CLJoined aliases. They are for MSVC options that are ported to clang. For clang-specific options, we don't want to add unneeded aliases.

Got it. I checked CL flags with MSVC. You're right.
Let me revert those SLASH flags.

HaohaiWen added a commit to HaohaiWen/llvm-project that referenced this pull request Nov 28, 2024
Those flags are introduced in llvm#117282. They are not supported by MSVC.
HaohaiWen added a commit that referenced this pull request Nov 28, 2024
Those flags are introduced in #117282. They are not supported by MSVC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category clang-cl `clang-cl` driver. Don't use for other compiler parts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants