[llvm-branch-commits] [clang] [llvm] [Lanai] Default to NewPM (PR #214574)
Aiden Grossman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 12 23:00:02 PDT 2026
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/214574
>From b6bab3855cb359013032f0c7419ec78832f7c614 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 6 Aug 2026 20:42:46 +0000
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
[skip ci]
---
clang/include/clang/Basic/CodeGenOptions.def | 3 ++-
clang/include/clang/Basic/CodeGenOptions.h | 6 ++++++
clang/include/clang/Options/Options.td | 8 ++++++++
clang/lib/CodeGen/BackendUtil.cpp | 6 +++++-
clang/test/CodeGen/X86/newpm.c | 2 +-
llvm/include/llvm/Target/TargetMachine.h | 4 ++++
llvm/lib/Target/MSP430/MSP430TargetMachine.h | 2 ++
llvm/tools/llc/llc.cpp | 10 +++++++++-
8 files changed, 37 insertions(+), 4 deletions(-)
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 cf66ee3e52f2d..3c6a9560d4509 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4788,6 +4788,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 068b1b4c262c8..7910ccbbf854c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1251,7 +1251,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
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index 03c82913c94fc..24d45b7956cab 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -502,6 +502,10 @@ class LLVM_ABI TargetMachine {
inconvertibleErrorCode());
}
+ /// Returns true if frontends should default to using the NewPM for this
+ /// specific target.
+ virtual bool shouldDefaultToNewPM() const { return false; }
+
/// Returns true if the target is expected to pass all machine verifier
/// checks. This is a stopgap measure to fix targets one by one. We will
/// remove this at some point and always enable the verifier when
diff --git a/llvm/lib/Target/MSP430/MSP430TargetMachine.h b/llvm/lib/Target/MSP430/MSP430TargetMachine.h
index 1897e64fcdb56..b27ad4ffab741 100644
--- a/llvm/lib/Target/MSP430/MSP430TargetMachine.h
+++ b/llvm/lib/Target/MSP430/MSP430TargetMachine.h
@@ -55,6 +55,8 @@ class MSP430TargetMachine : public CodeGenTargetMachineImpl {
CodeGenFileType FileType,
const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
+
+ bool shouldDefaultToNewPM() const override { return true; }
}; // MSP430TargetMachine.
} // end namespace llvm
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index dcd54c18401d0..55f91a375fc8a 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -749,7 +749,15 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
else if (VerifyEach)
VK = VerifierKind::EachPass;
- if (EnableNewPassManager || !PassPipeline.empty()) {
+ // Use the NewPM if the user specifies -passes (NewPM specific), specifically
+ // requests the NewPM with -enable-new-pm, or the target defaults to the
+ // NewPM, the user has not explicitly disabled the NewPM with
+ // -enable-new-pm=false, and the user has not specified -run-pass.
+ if (!PassPipeline.empty() ||
+ (EnableNewPassManager.getNumOccurrences() > 0 && EnableNewPassManager) ||
+ (Target->shouldDefaultToNewPM() &&
+ !(EnableNewPassManager.getNumOccurrences() && !EnableNewPassManager) &&
+ getRunPassNames().empty())) {
return compileModuleWithNewPM(argv[0], std::move(M), std::move(MIR),
std::move(Target), std::move(Out),
std::move(DwoOut), Context, TLII, VK,
>From 6e827e93977b15ec87ebc1d21e3ad3ec80ef4c27 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 7 Aug 2026 05:50:01 +0000
Subject: [PATCH 2/2] formatting
Created using spr 1.3.7
---
llvm/lib/Target/Lanai/LanaiTargetMachine.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/Lanai/LanaiTargetMachine.h b/llvm/lib/Target/Lanai/LanaiTargetMachine.h
index fa3cb937f906d..22313a2ed7dd1 100644
--- a/llvm/lib/Target/Lanai/LanaiTargetMachine.h
+++ b/llvm/lib/Target/Lanai/LanaiTargetMachine.h
@@ -59,7 +59,7 @@ class LanaiTargetMachine : public CodeGenTargetMachineImpl {
CodeGenFileType FileType,
const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
-
+
bool shouldDefaultToNewPM() const override { return true; }
};
} // namespace llvm
More information about the llvm-branch-commits
mailing list