[clang] [PGO] Add a clang option -fprofile-continuous that enables PGO continuous mode (PR #124353)

Wael Yehia via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 27 13:32:34 PST 2025


================
@@ -785,6 +786,34 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
       D.Diag(diag::err_drv_unsupported_option_argument)
           << A->getSpelling() << Val;
   }
+  if (const auto *A = Args.getLastArg(options::OPT_fprofile_continuous)) {
+    if (!PGOGenerateArg && !CSPGOGenerateArg && !ProfileGenerateArg)
+      D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+          << A->getSpelling()
+          << "-fprofile-generate, -fprofile-instr-generate, or "
+             "-fcs-profile-generate";
+    else {
+      CmdArgs.push_back("-fprofile-continuous");
+      // Platforms that require a bias variable:
+      if (T.isOSFuchsia() || T.isOSBinFormatELF() || T.isOSAIX()) {
+        CmdArgs.push_back("-mllvm");
----------------
w2yehia wrote:

I see, I didn't know Fuchsia uses ELF.
So if `T.isOSBinFormatELF()` subsumes `T.isOSFuchsia()` then we can remove `T.isOSFuchsia()`.

I tried to copy the conditions that the [runtime](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingFile.c#L199) uses for when runtime relocation is needed:
`#elif defined(__ELF__) || defined(_WIN32) || defined(_AIX)`

Fuchsia [uses](https://github.com/llvm/llvm-project/blob/5815a311050ae218ebcda53adeee24ed96851943/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c#L183) runtime relocation AFAIU.

> This condition will add -runtime-counter-relocation to all ELF targets, which I think is not desired.
Continuous mode is not supported on many platforms, so the ELF targets that do not support it will not care if we pass the runtime-relocation or not. 
I didn't filter out unsupported plaftforms via a diagnostic in this patch. If it's desirable to do so, I can add a diagnostic.
Please advice.

https://github.com/llvm/llvm-project/pull/124353


More information about the cfe-commits mailing list