[clang] 290a0a1 - [Clang] Make NewPM switch respect shouldDefaultToNewPM

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 12 22:14:47 PDT 2026


Author: Aiden Grossman
Date: 2026-08-12T22:14:41-07:00
New Revision: 290a0a140698f6b15b0a214778a1c58b459f0e66

URL: https://github.com/llvm/llvm-project/commit/290a0a140698f6b15b0a214778a1c58b459f0e66
DIFF: https://github.com/llvm/llvm-project/commit/290a0a140698f6b15b0a214778a1c58b459f0e66.diff

LOG: [Clang] Make NewPM switch respect shouldDefaultToNewPM

shouldDefaultToNewPM is a new target flag that allows targets to specify
that the NewPM should be used by default for compilation. Wire it up
into clang.

Reviewers: arsenm, efriedma-quic, jansvoboda11

Pull Request: https://github.com/llvm/llvm-project/pull/214571

Added: 
    

Modified: 
    clang/include/clang/Basic/CodeGenOptions.def
    clang/include/clang/Basic/CodeGenOptions.h
    clang/include/clang/Options/Options.td
    clang/lib/CodeGen/BackendUtil.cpp
    clang/test/CodeGen/X86/newpm.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index 7e54e75752f39..bf3e61f2f036f 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -351,7 +351,8 @@ CODEGENOPT(TimeTrace         , 1, 0, Benign) ///< Set when -ftime-trace is enabl
 VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500, Benign) ///< Minimum time granularity (in microseconds),
                                                         ///< traced by time profiler
 CODEGENOPT(InterchangeLoops  , 1, 0, Benign) ///< Run loop-interchange.
-CODEGENOPT(EnableNewPMCodeGen, 1, 0, Benign) ///< Use NewPM for the CodeGen pipeline.
+ENUM_CODEGENOPT(EnableNewPMCodeGen, NewPMEnablementLevel, 2,
+                NewPMEnablementLevel::Auto, Benign) ///< Use NewPM for the CodeGen pipeline.
 CODEGENOPT(FuseLoops         , 1, 0, Benign) ///< Run loop-fusion.
 CODEGENOPT(UnrollLoops       , 1, 0, Benign) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops       , 1, 0, Benign) ///< Control whether loops are rerolled.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index c12434135a198..6e9bde32e0655 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -240,6 +240,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
     NonStrictDefault = NonZero
   };
 
+  enum class NewPMEnablementLevel {
+    Auto,         // Use the target dependent default.
+    ForceEnable,  // Always enable regardless of the target default.
+    ForceDisable, // Always disable regardless of the target default.
+  };
+
   /// The code model to use (-mcmodel).
   std::string CodeModel;
 

diff  --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index b354a475346df..6af0f578b6d63 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4791,6 +4791,14 @@ defm enable_new_pm_codegen
                           "Use the NewPM for the Codegen Pipeline">>,
       DocBrief<
           [{When enabled, use the NewPM to drive the Codegen pipeline.}]>;
+def enable_new_pm_codegen : Joined<["-"], "fenable-new-pm-codegen=">,
+    Group<f_Group>,
+    Visibility<[CC1Option]>,
+    HelpText<"When enabled, use the NewPM to drive the CodeGen pipeline.">,
+    Values<"auto,force-on,force-disable">,
+    NormalizedValuesScope<"CodeGenOptions::NewPMEnablementLevel">,
+    NormalizedValues<["Auto","ForceEnable","ForceDisable"]>,
+    MarshallingInfoEnum<CodeGenOpts<"EnableNewPMCodeGen">, "Auto">;
 defm experimental_loop_fusion
     : OptInCC1FFlag<"experimental-loop-fusion", "Enable", "Disable",
                     "Enable the loop fusion pass",

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index e95552b7e9e06..0b1a4221d3351 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1252,7 +1252,11 @@ void EmitAssemblyHelper::RunCodegenPipeline(
       return;
   }
 
-  if (CodeGenOpts.EnableNewPMCodeGen) {
+  if (CodeGenOpts.getEnableNewPMCodeGen() ==
+          CodeGenOptions::NewPMEnablementLevel::ForceEnable ||
+      (CodeGenOpts.getEnableNewPMCodeGen() ==
+           CodeGenOptions::NewPMEnablementLevel::Auto &&
+       TM->shouldDefaultToNewPM())) {
     RunCodegenPipelineNewPM(Action, OS, DwoOS, CGFT);
   } else {
     RunCodegenPipelineLegacy(Action, OS, DwoOS, CGFT);

diff  --git a/clang/test/CodeGen/X86/newpm.c b/clang/test/CodeGen/X86/newpm.c
index dd8d03d910bad..6dec8a2e8e24a 100644
--- a/clang/test/CodeGen/X86/newpm.c
+++ b/clang/test/CodeGen/X86/newpm.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -triple=x86_64-unkown-linux-gnu -fenable-new-pm-codegen -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-unkown-linux-gnu -fenable-new-pm-codegen=force-on -S -o - %s | FileCheck %s
 
 int foo() {
   // CHECK-LABEL: foo


        


More information about the cfe-commits mailing list