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

>From abef90fe8f46431a5fb8b7fe717c9fb65eb30266 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Thu, 23 Jan 2025 00:03:15 +0000
Subject: [PATCH 1/8] [PGO] Add a clang option -fprofile-continuous that
 enables PGO continuous mode

---
 clang/docs/UsersManual.rst                   |  8 ++++
 clang/include/clang/Basic/CodeGenOptions.def |  1 +
 clang/include/clang/Driver/Options.td        |  5 +++
 clang/lib/CodeGen/BackendUtil.cpp            | 42 +++++++++++---------
 clang/lib/Driver/ToolChains/Clang.cpp        | 29 ++++++++++++++
 clang/test/CodeGen/profile-continuous.c      | 16 ++++++++
 6 files changed, 83 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGen/profile-continuous.c

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 260e84910c6f783..1e5099067339977 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3033,6 +3033,14 @@ indexed format, regardeless whether it is produced by 
frontend or the IR pass.
   overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
   by the target, or ``single`` otherwise.
 
+.. option:: -fprofile-continuous
+
+  Enables continuous PGO mode where profile counter updates are continuously
+  synced to a file. This option sets any neccessary modifiers (currently 
``%c``)
+  in the default profile filename and passes any necessary flags to the
+  middle-end to support this mode. Value profiling is not supported in
+  continuous mode.
+
 .. option:: -ftemporal-profile
 
   Enables the temporal profiling extension for IRPGO to improve startup time by
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 0f4ed13d5f3d8c1..bbaf8b183222e98 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -221,6 +221,7 @@ AFFECTING_VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< 
The -O[0-3] option spec
 AFFECTING_VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) 
is specified.
 
 CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic
+CODEGENOPT(ContinuousProfileSync, 1, 0) ///< Enable continuous PGO mode
 /// Choose profile instrumenation kind or no instrumentation.
 ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
 /// Choose profile kind for PGO use compilation.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2721c1b5d8dc554..5a7e64d5b5a96f3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1886,6 +1886,11 @@ def fprofile_update_EQ : Joined<["-"], 
"fprofile-update=">,
     Values<"atomic,prefer-atomic,single">,
     MetaVarName<"<method>">, HelpText<"Set update method of profile counters">,
     MarshallingInfoFlag<CodeGenOpts<"AtomicProfileUpdate">>;
+def fprofile_continuous : Flag<["-"], "fprofile-continuous">,
+    Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
+    HelpText<"Enable Continuous PGO mode">,
+    MarshallingInfoFlag<CodeGenOpts<"ContinuousProfileSync">>;
+
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag<SetTrue, [], [ClangOption], "Emit">,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 3951ad01497ccac..afafa8af585c712 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -133,6 +133,16 @@ std::string getDefaultProfileGenName() {
              : "default_%m.profraw";
 }
 
+// Path and name of file used for profile generation
+std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
+  std::string FileName = CodeGenOpts.InstrProfileOutput.empty()
+                             ? getDefaultProfileGenName()
+                             : CodeGenOpts.InstrProfileOutput;
+  if (CodeGenOpts.ContinuousProfileSync)
+    FileName = "%c" + FileName;
+  return FileName;
+}
+
 class EmitAssemblyHelper {
   CompilerInstance &CI;
   DiagnosticsEngine &Diags;
@@ -550,7 +560,9 @@ getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
     return std::nullopt;
   InstrProfOptions Options;
   Options.NoRedZone = CodeGenOpts.DisableRedZone;
-  Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
+  Options.InstrProfileOutput = CodeGenOpts.ContinuousProfileSync
+                                   ? ("%c" + CodeGenOpts.InstrProfileOutput)
+                                   : CodeGenOpts.InstrProfileOutput;
   Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
   return Options;
 }
@@ -811,13 +823,12 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 
   if (CodeGenOpts.hasProfileIRInstr())
     // -fprofile-generate.
-    PGOOpt = PGOOptions(
-        CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
-                                               : 
CodeGenOpts.InstrProfileOutput,
-        "", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
-        PGOOptions::NoCSAction, ClPGOColdFuncAttr,
-        CodeGenOpts.DebugInfoForProfiling,
-        /*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate);
+    PGOOpt = PGOOptions(getProfileGenName(CodeGenOpts), "", "",
+                        CodeGenOpts.MemoryProfileUsePath, nullptr,
+                        PGOOptions::IRInstr, PGOOptions::NoCSAction,
+                        ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling,
+                        /*PseudoProbeForProfiling=*/false,
+                        CodeGenOpts.AtomicProfileUpdate);
   else if (CodeGenOpts.hasProfileIRUse()) {
     // -fprofile-use.
     auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
@@ -861,18 +872,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
              PGOOpt->Action != PGOOptions::SampleUse &&
              "Cannot run CSProfileGen pass with ProfileGen or SampleUse "
              " pass");
-      PGOOpt->CSProfileGenFile = CodeGenOpts.InstrProfileOutput.empty()
-                                     ? getDefaultProfileGenName()
-                                     : CodeGenOpts.InstrProfileOutput;
+      PGOOpt->CSProfileGenFile = getProfileGenName(CodeGenOpts);
       PGOOpt->CSAction = PGOOptions::CSIRInstr;
     } else
-      PGOOpt = PGOOptions("",
-                          CodeGenOpts.InstrProfileOutput.empty()
-                              ? getDefaultProfileGenName()
-                              : CodeGenOpts.InstrProfileOutput,
-                          "", /*MemoryProfile=*/"", nullptr,
-                          PGOOptions::NoAction, PGOOptions::CSIRInstr,
-                          ClPGOColdFuncAttr, 
CodeGenOpts.DebugInfoForProfiling);
+      PGOOpt = PGOOptions("", getProfileGenName(CodeGenOpts), "",
+                          /*MemoryProfile=*/"", nullptr, PGOOptions::NoAction,
+                          PGOOptions::CSIRInstr, ClPGOColdFuncAttr,
+                          CodeGenOpts.DebugInfoForProfiling);
   }
   if (TM)
     TM->setPGOOption(PGOOpt);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 33f08cf28feca18..8aefa82951edbca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -580,6 +580,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
                                    const ArgList &Args, SanitizerArgs &SanArgs,
                                    ArgStringList &CmdArgs) {
   const Driver &D = TC.getDriver();
+  const llvm::Triple &T = TC.getTriple();
   auto *PGOGenerateArg = Args.getLastArg(options::OPT_fprofile_generate,
                                          options::OPT_fprofile_generate_EQ,
                                          options::OPT_fno_profile_generate);
@@ -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");
+        CmdArgs.push_back("-runtime-counter-relocation");
+      }
+      // -fprofile-instr-generate does not decide the profile file name in the
+      // FE, and so it does not define the filename symbol
+      // (__llvm_profile_filename). Instead, the runtime uses the name
+      // "default.profraw" for the profile file. When continuous mode is ON, we
+      // will create the filename symbol so that we can insert the "%c"
+      // modifier.
+      if (ProfileGenerateArg &&
+          (ProfileGenerateArg->getOption().matches(
+               options::OPT_fprofile_instr_generate) ||
+           (ProfileGenerateArg->getOption().matches(
+                options::OPT_fprofile_instr_generate_EQ) &&
+            strlen(ProfileGenerateArg->getValue()) == 0)))
+        CmdArgs.push_back("-fprofile-instrument-path=default.profraw");
+    }
+  }
 
   int FunctionGroups = 1;
   int SelectedFunctionGroup = 0;
diff --git a/clang/test/CodeGen/profile-continuous.c 
b/clang/test/CodeGen/profile-continuous.c
new file mode 100644
index 000000000000000..1db31c2f162b272
--- /dev/null
+++ b/clang/test/CodeGen/profile-continuous.c
@@ -0,0 +1,16 @@
+// RUN: %clang %s -S -emit-llvm -fprofile-generate -fprofile-continuous -o - | 
FileCheck %s --check-prefix=IRPGO
+// RUN: %clang %s -S -emit-llvm -fprofile-generate=mydir -fprofile-continuous 
-o - | FileCheck %s --check-prefix=IRPGO_EQ
+// RUN: %clang %s -S -emit-llvm -fcs-profile-generate -fprofile-continuous -O 
-o - | FileCheck %s --check-prefix=CSIRPGO
+// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate -fprofile-continuous 
-o - | FileCheck %s --check-prefix=CLANG_PGO
+// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate= -fprofile-continuous 
-o - | FileCheck %s --check-prefix=CLANG_PGO
+// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate=foo.profraw 
-fprofile-continuous -o - | FileCheck %s --check-prefix=CLANG_PGO_EQ
+
+// RUN: not %clang -### %s -fprofile-continuous -c 2>&1 | FileCheck %s 
--check-prefix=ERROR
+
+// IRPGO: @__llvm_profile_filename = {{.*}} c"%cdefault_%m.profraw\00"
+// IRPGO_EQ: @__llvm_profile_filename = {{.*}} c"%cmydir/default_%m.profraw\00"
+// CSIRPGO: @__llvm_profile_filename = {{.*}} c"%cdefault_%m.profraw\00"
+// CLANG_PGO: @__llvm_profile_filename = {{.*}} c"%cdefault.profraw\00"
+// CLANG_PGO_EQ: @__llvm_profile_filename = {{.*}} c"%cfoo.profraw\00"
+// ERROR: clang: error: invalid argument '-fprofile-continuous' only allowed 
with '-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'
+void foo(){}

>From 5d9db9a4c3dd33d26a5e8578807d81242ae476ce Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Mon, 27 Jan 2025 17:18:37 +0000
Subject: [PATCH 2/8] Add example to the user documenation

---
 clang/docs/UsersManual.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 1e5099067339977..d9b29433468f936 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3041,6 +3041,16 @@ indexed format, regardeless whether it is produced by 
frontend or the IR pass.
   middle-end to support this mode. Value profiling is not supported in
   continuous mode.
 
+  .. code-block:: console
+
+    $ clang++ -O2 -fprofile-generate -fprofile-continuous code.cc -o code
+
+  Running `./code` will collect the profile and write it to the
+  `default_xxxx.profraw` file. However, if `./code` abruptly terminates or does
+  not call `exit()`, in continuous mode the profile collected up to the point 
of
+  termination will be available in `default_xxxx.profraw` while in the
+  non-continuous mode, no profile file is generated.
+
 .. option:: -ftemporal-profile
 
   Enables the temporal profiling extension for IRPGO to improve startup time by

>From 9d6af4c5046908f5e49cc9eacee7d07ab77e6b63 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Tue, 28 Jan 2025 00:53:21 +0000
Subject: [PATCH 3/8] Address code review and improve tests

---
 clang/lib/CodeGen/BackendUtil.cpp       |  8 ++++----
 clang/test/CodeGen/profile-continuous.c | 15 +++++----------
 clang/test/Driver/fprofile-continuous.c | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/Driver/fprofile-continuous.c

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index afafa8af585c712..1aed835fb5fbb8f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -124,17 +124,15 @@ namespace clang {
 extern llvm::cl::opt<bool> ClSanitizeGuardChecks;
 }
 
-namespace {
-
 // Default filename used for profile generation.
-std::string getDefaultProfileGenName() {
+static std::string getDefaultProfileGenName() {
   return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
              ? "default_%m.proflite"
              : "default_%m.profraw";
 }
 
 // Path and name of file used for profile generation
-std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
+static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
   std::string FileName = CodeGenOpts.InstrProfileOutput.empty()
                              ? getDefaultProfileGenName()
                              : CodeGenOpts.InstrProfileOutput;
@@ -143,6 +141,8 @@ std::string getProfileGenName(const CodeGenOptions 
&CodeGenOpts) {
   return FileName;
 }
 
+namespace {
+
 class EmitAssemblyHelper {
   CompilerInstance &CI;
   DiagnosticsEngine &Diags;
diff --git a/clang/test/CodeGen/profile-continuous.c 
b/clang/test/CodeGen/profile-continuous.c
index 1db31c2f162b272..86fa1d149b9719f 100644
--- a/clang/test/CodeGen/profile-continuous.c
+++ b/clang/test/CodeGen/profile-continuous.c
@@ -1,16 +1,11 @@
-// RUN: %clang %s -S -emit-llvm -fprofile-generate -fprofile-continuous -o - | 
FileCheck %s --check-prefix=IRPGO
-// RUN: %clang %s -S -emit-llvm -fprofile-generate=mydir -fprofile-continuous 
-o - | FileCheck %s --check-prefix=IRPGO_EQ
-// RUN: %clang %s -S -emit-llvm -fcs-profile-generate -fprofile-continuous -O 
-o - | FileCheck %s --check-prefix=CSIRPGO
-// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate -fprofile-continuous 
-o - | FileCheck %s --check-prefix=CLANG_PGO
-// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate= -fprofile-continuous 
-o - | FileCheck %s --check-prefix=CLANG_PGO
-// RUN: %clang %s -S -emit-llvm -fprofile-instr-generate=foo.profraw 
-fprofile-continuous -o - | FileCheck %s --check-prefix=CLANG_PGO_EQ
-
-// RUN: not %clang -### %s -fprofile-continuous -c 2>&1 | FileCheck %s 
--check-prefix=ERROR
+// RUN: %clang_cc1 -emit-llvm -fprofile-instrument=llvm -fprofile-continuous 
%s -o - | FileCheck %s --check-prefix=IRPGO
+// RUN: %clang_cc1 -emit-llvm -fprofile-instrument=llvm -fprofile-continuous 
-fprofile-instrument-path=mydir/default_%m.profraw -mllvm 
-runtime-counter-relocation %s -o - \
+// RUN:  | FileCheck %s --check-prefix=IRPGO_EQ
+// RUN: %clang_cc1 -emit-llvm -O2 -fprofile-instrument=csllvm 
-fprofile-continuous %s -o - | FileCheck %s --check-prefix=CSIRPGO
+// RUN: %clang_cc1 -emit-llvm -fprofile-instrument=clang -fprofile-continuous 
-fprofile-instrument-path=default.profraw %s -o - | FileCheck %s 
--check-prefix=CLANG_PGO
 
 // IRPGO: @__llvm_profile_filename = {{.*}} c"%cdefault_%m.profraw\00"
 // IRPGO_EQ: @__llvm_profile_filename = {{.*}} c"%cmydir/default_%m.profraw\00"
 // CSIRPGO: @__llvm_profile_filename = {{.*}} c"%cdefault_%m.profraw\00"
 // CLANG_PGO: @__llvm_profile_filename = {{.*}} c"%cdefault.profraw\00"
-// CLANG_PGO_EQ: @__llvm_profile_filename = {{.*}} c"%cfoo.profraw\00"
-// ERROR: clang: error: invalid argument '-fprofile-continuous' only allowed 
with '-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'
 void foo(){}
diff --git a/clang/test/Driver/fprofile-continuous.c 
b/clang/test/Driver/fprofile-continuous.c
new file mode 100644
index 000000000000000..cbe2b16579949b8
--- /dev/null
+++ b/clang/test/Driver/fprofile-continuous.c
@@ -0,0 +1,21 @@
+// 1) test on platforms that (do or do not) require runtime relocation
+//
+// RUN: %clang -target x86_64-darwin -fprofile-generate -fprofile-continuous 
-### -c %s 2>&1 | FileCheck %s --check-prefix=NO_RELOC
+// NO_RELOC: "-cc1" {{.*}} "-fprofile-continuous"
+// NO_RELOC-NOT: "-mllvm" "-runtime-counter-relocation"
+
+// RUN: %clang -target powerpc64-ibm-aix -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+// RUN: %clang -target x86_64-unknown-fuchsia -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+// RELOC: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation"
+
+// 2) test -fprofile-continuous with cs-profile-generate and 
-fprofile-instr-generate
+//
+// RUN: %clang -target powerpc-ibm-aix -fprofile-instr-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
+// RUN: %clang -target powerpc64le-unknown-linux -fprofile-instr-generate= 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
+// CLANG_PGO: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation" "-fprofile-instrument-path=default.profraw"
+
+// RUN: %clang -target x86_64-unknown-fuchsia -fcs-profile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+
+// RUN: not %clang -fprofile-continuous -### -c %s 2>&1 | FileCheck %s 
--check-prefix=ERROR
+// ERROR: clang: error: invalid argument '-fprofile-continuous' only allowed 
with '-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'
+void foo(){}

>From ba4267e8879ea643cc68af438ad6bab75d32980f Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Thu, 30 Jan 2025 17:09:52 +0000
Subject: [PATCH 4/8] remove 'clang:' from testcase

---
 clang/test/Driver/fprofile-continuous.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/fprofile-continuous.c 
b/clang/test/Driver/fprofile-continuous.c
index cbe2b16579949b8..85a431718a0ebb8 100644
--- a/clang/test/Driver/fprofile-continuous.c
+++ b/clang/test/Driver/fprofile-continuous.c
@@ -17,5 +17,5 @@
 // RUN: %clang -target x86_64-unknown-fuchsia -fcs-profile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
 
 // RUN: not %clang -fprofile-continuous -### -c %s 2>&1 | FileCheck %s 
--check-prefix=ERROR
-// ERROR: clang: error: invalid argument '-fprofile-continuous' only allowed 
with '-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'
+// ERROR: error: invalid argument '-fprofile-continuous' only allowed with 
'-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'
 void foo(){}

>From 45259f3e54fdb781aeaeeab45f65cab4278ae8b6 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Thu, 30 Jan 2025 17:20:27 +0000
Subject: [PATCH 5/8] remove isOSFuchsia because it's subsumed by
 isOSBinFormatELF

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8aefa82951edbca..8e91f3bff2a17a8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -795,7 +795,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
     else {
       CmdArgs.push_back("-fprofile-continuous");
       // Platforms that require a bias variable:
-      if (T.isOSFuchsia() || T.isOSBinFormatELF() || T.isOSAIX()) {
+      if (T.isOSBinFormatELF() || T.isOSAIX()) {
         CmdArgs.push_back("-mllvm");
         CmdArgs.push_back("-runtime-counter-relocation");
       }

>From 2596b2c4a7d777616a056a6d680360de2cf30526 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Wed, 5 Feb 2025 16:35:18 +0000
Subject: [PATCH 6/8] s/PGO/instrumentation profiling/g

---
 clang/docs/UsersManual.rst                   | 10 +++++-----
 clang/include/clang/Basic/CodeGenOptions.def |  2 +-
 clang/include/clang/Driver/Options.td        |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index d9b29433468f936..ddd7c58cc0ef7fd 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3035,11 +3035,11 @@ indexed format, regardeless whether it is produced by 
frontend or the IR pass.
 
 .. option:: -fprofile-continuous
 
-  Enables continuous PGO mode where profile counter updates are continuously
-  synced to a file. This option sets any neccessary modifiers (currently 
``%c``)
-  in the default profile filename and passes any necessary flags to the
-  middle-end to support this mode. Value profiling is not supported in
-  continuous mode.
+  Enables the continuous instrumentation profiling where profile counter 
updates
+  are continuously synced to a file. This option sets any neccessary modifiers
+  (currently ``%c``) in the default profile filename and passes any necessary
+  flags to the middle-end to support this mode. Value profiling is not 
supported
+  in continuous mode.
 
   .. code-block:: console
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index bbaf8b183222e98..2b7e717237a15e3 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -221,7 +221,7 @@ AFFECTING_VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< 
The -O[0-3] option spec
 AFFECTING_VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) 
is specified.
 
 CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic
-CODEGENOPT(ContinuousProfileSync, 1, 0) ///< Enable continuous PGO mode
+CODEGENOPT(ContinuousProfileSync, 1, 0) ///< Enable continuous instrumentation 
profiling
 /// Choose profile instrumenation kind or no instrumentation.
 ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
 /// Choose profile kind for PGO use compilation.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5a7e64d5b5a96f3..c39cc9f276fef99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1888,7 +1888,7 @@ def fprofile_update_EQ : Joined<["-"], 
"fprofile-update=">,
     MarshallingInfoFlag<CodeGenOpts<"AtomicProfileUpdate">>;
 def fprofile_continuous : Flag<["-"], "fprofile-continuous">,
     Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
-    HelpText<"Enable Continuous PGO mode">,
+    HelpText<"Enable continuous instrumentation profiling mode">,
     MarshallingInfoFlag<CodeGenOpts<"ContinuousProfileSync">>;
 
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",

>From da33ed96e71f58a00de49d5dc2f477870ab80657 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Thu, 6 Feb 2025 19:01:18 +0000
Subject: [PATCH 7/8] more code review

---
 clang/docs/UsersManual.rst              | 10 +++++-----
 clang/test/Driver/fprofile-continuous.c | 12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ddd7c58cc0ef7fd..1ea252872e8fe7e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3045,11 +3045,11 @@ indexed format, regardeless whether it is produced by 
frontend or the IR pass.
 
     $ clang++ -O2 -fprofile-generate -fprofile-continuous code.cc -o code
 
-  Running `./code` will collect the profile and write it to the
-  `default_xxxx.profraw` file. However, if `./code` abruptly terminates or does
-  not call `exit()`, in continuous mode the profile collected up to the point 
of
-  termination will be available in `default_xxxx.profraw` while in the
-  non-continuous mode, no profile file is generated.
+  Running ``./code`` will collect the profile and write it to the
+  ``default_xxxx.profraw`` file. However, if ``./code`` abruptly terminates or
+  does not call ``exit()``, in continuous mode the profile collected up to the
+  point of termination will be available in ``default_xxxx.profraw`` while in
+  the non-continuous mode, no profile file is generated.
 
 .. option:: -ftemporal-profile
 
diff --git a/clang/test/Driver/fprofile-continuous.c 
b/clang/test/Driver/fprofile-continuous.c
index 85a431718a0ebb8..665616941ea9f56 100644
--- a/clang/test/Driver/fprofile-continuous.c
+++ b/clang/test/Driver/fprofile-continuous.c
@@ -1,20 +1,20 @@
 // 1) test on platforms that (do or do not) require runtime relocation
 //
-// RUN: %clang -target x86_64-darwin -fprofile-generate -fprofile-continuous 
-### -c %s 2>&1 | FileCheck %s --check-prefix=NO_RELOC
+// RUN: %clang --target=x86_64-darwin -fprofile-generate -fprofile-continuous 
-### -c %s 2>&1 | FileCheck %s --check-prefix=NO_RELOC
 // NO_RELOC: "-cc1" {{.*}} "-fprofile-continuous"
 // NO_RELOC-NOT: "-mllvm" "-runtime-counter-relocation"
 
-// RUN: %clang -target powerpc64-ibm-aix -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
-// RUN: %clang -target x86_64-unknown-fuchsia -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+// RUN: %clang --target=powerpc64-ibm-aix -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+// RUN: %clang --target=x86_64-unknown-fuchsia -fprofile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
 // RELOC: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation"
 
 // 2) test -fprofile-continuous with cs-profile-generate and 
-fprofile-instr-generate
 //
-// RUN: %clang -target powerpc-ibm-aix -fprofile-instr-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
-// RUN: %clang -target powerpc64le-unknown-linux -fprofile-instr-generate= 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
+// RUN: %clang --target=powerpc-ibm-aix -fprofile-instr-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
+// RUN: %clang --target=powerpc64le-unknown-linux -fprofile-instr-generate= 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
 // CLANG_PGO: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation" "-fprofile-instrument-path=default.profraw"
 
-// RUN: %clang -target x86_64-unknown-fuchsia -fcs-profile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
+// RUN: %clang --target=x86_64-unknown-fuchsia -fcs-profile-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=RELOC
 
 // RUN: not %clang -fprofile-continuous -### -c %s 2>&1 | FileCheck %s 
--check-prefix=ERROR
 // ERROR: error: invalid argument '-fprofile-continuous' only allowed with 
'-fprofile-generate, -fprofile-instr-generate, or -fcs-profile-generate'

>From 7b4f6f257617c579237da8c7a67a8dc4a86befdc Mon Sep 17 00:00:00 2001
From: Wael Yehia <wye...@ca.ibm.com>
Date: Sat, 8 Feb 2025 17:14:12 -0500
Subject: [PATCH 8/8] more

---
 clang/test/Driver/fprofile-continuous.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/fprofile-continuous.c 
b/clang/test/Driver/fprofile-continuous.c
index 665616941ea9f56..81719fb70cb1e17 100644
--- a/clang/test/Driver/fprofile-continuous.c
+++ b/clang/test/Driver/fprofile-continuous.c
@@ -1,5 +1,5 @@
 // 1) test on platforms that (do or do not) require runtime relocation
-//
+
 // RUN: %clang --target=x86_64-darwin -fprofile-generate -fprofile-continuous 
-### -c %s 2>&1 | FileCheck %s --check-prefix=NO_RELOC
 // NO_RELOC: "-cc1" {{.*}} "-fprofile-continuous"
 // NO_RELOC-NOT: "-mllvm" "-runtime-counter-relocation"
@@ -9,7 +9,7 @@
 // RELOC: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation"
 
 // 2) test -fprofile-continuous with cs-profile-generate and 
-fprofile-instr-generate
-//
+
 // RUN: %clang --target=powerpc-ibm-aix -fprofile-instr-generate 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
 // RUN: %clang --target=powerpc64le-unknown-linux -fprofile-instr-generate= 
-fprofile-continuous -### -c %s 2>&1 | FileCheck %s --check-prefix=CLANG_PGO
 // CLANG_PGO: "-cc1" {{.*}} "-fprofile-continuous" "-mllvm" 
"-runtime-counter-relocation" "-fprofile-instrument-path=default.profraw"

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to