[llvm] [NFC][AArch64] Extracted AArch64PassConfig::isGlobalISelOptNone (PR #196856)

Anshul Nigham via llvm-commits llvm-commits at lists.llvm.org
Sun May 10 17:40:27 PDT 2026


https://github.com/nigham created https://github.com/llvm/llvm-project/pull/196856

Extracts AArch64PassConfig::isGlobalISelOptNone into a standalone function.

This will help with NewPM porting since this functionality is required in NewPM orchestration. 

>From a57844dc0f4d0355d44a7754bcec298909d2c6cc Mon Sep 17 00:00:00 2001
From: Anshul Nigham <nigham at google.com>
Date: Sun, 10 May 2026 17:38:41 -0700
Subject: [PATCH] [NFC][AArch64] Extracted
 AArch64PassConfig::isGlobalISelOptNone into a standalone function

---
 .../Target/AArch64/AArch64TargetMachine.cpp   | 38 ++++++++-----------
 .../lib/Target/AArch64/AArch64TargetMachine.h |  7 ++++
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index 1ef404b320c31..2ec3bfd92bf3a 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -282,6 +282,16 @@ LLVMInitializeAArch64Target() {
   initializeAArch64Arm64ECCallLoweringPass(PR);
 }
 
+bool llvm::isGlobalISelOptNone(const TargetMachine *TM) {
+  const bool GlobalISelFlag =
+      getCGPassBuilderOption().EnableGlobalISelOption.value_or(false);
+
+  return TM->getOptLevel() == CodeGenOptLevel::None ||
+         (static_cast<unsigned>(TM->getOptLevel()) >
+              static_cast<unsigned>(EnableGlobalISelAtO) &&
+          !GlobalISelFlag);
+}
+
 void AArch64TargetMachine::reset() { SubtargetMap.clear(); }
 
 //===----------------------------------------------------------------------===//
@@ -584,9 +594,6 @@ class AArch64PassConfig : public TargetPassConfig {
   bool addRegAssignAndRewriteOptimized() override;
 
   std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
-
-private:
-  bool isGlobalISelOptNone() const;
 };
 
 } // end anonymous namespace
@@ -620,21 +627,6 @@ std::unique_ptr<CSEConfigBase> AArch64PassConfig::getCSEConfig() const {
   return getStandardCSEConfigForOpt(TM->getOptLevel());
 }
 
-// This function checks whether the opt level is explicitly set to none,
-// or whether GlobalISel was enabled due to SDAG encountering an optnone
-// function. If the opt level is greater than the level we automatically enable
-// globalisel at, and it wasn't enabled via CLI, we know that it must be because
-// of an optnone function.
-bool AArch64PassConfig::isGlobalISelOptNone() const {
-  const bool GlobalISelFlag =
-      getCGPassBuilderOption().EnableGlobalISelOption.value_or(false);
-
-  return getOptLevel() == CodeGenOptLevel::None ||
-         (static_cast<unsigned>(getOptLevel()) >
-              getAArch64TargetMachine().getEnableGlobalISelAtO() &&
-          !GlobalISelFlag);
-}
-
 void AArch64PassConfig::addIRPasses() {
   // Always expand atomic operations, we don't deal with atomicrmw or cmpxchg
   // ourselves.
@@ -763,7 +755,7 @@ bool AArch64PassConfig::addIRTranslator() {
 }
 
 void AArch64PassConfig::addPreLegalizeMachineIR() {
-  if (isGlobalISelOptNone()) {
+  if (isGlobalISelOptNone(&getAArch64TargetMachine())) {
     addPass(createAArch64O0PreLegalizerCombiner());
     addPass(new Localizer());
   } else {
@@ -780,8 +772,10 @@ bool AArch64PassConfig::addLegalizeMachineIR() {
 }
 
 void AArch64PassConfig::addPreRegBankSelect() {
-  if (!isGlobalISelOptNone()) {
-    addPass(createAArch64PostLegalizerCombiner(isGlobalISelOptNone()));
+  const bool IsGlobalISelOptNone =
+      isGlobalISelOptNone(&getAArch64TargetMachine());
+  if (!IsGlobalISelOptNone) {
+    addPass(createAArch64PostLegalizerCombiner(IsGlobalISelOptNone));
     if (EnableGISelLoadStoreOptPostLegal)
       addPass(new LoadStoreOpt());
   }
@@ -795,7 +789,7 @@ bool AArch64PassConfig::addRegBankSelect() {
 
 bool AArch64PassConfig::addGlobalInstructionSelect() {
   addPass(new InstructionSelect(getOptLevel()));
-  if (!isGlobalISelOptNone())
+  if (!isGlobalISelOptNone(&getAArch64TargetMachine()))
     addPass(createAArch64PostSelectOptimize());
   return false;
 }
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.h b/llvm/lib/Target/AArch64/AArch64TargetMachine.h
index 209374553d297..f1969cd602e83 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.h
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.h
@@ -21,6 +21,13 @@
 
 namespace llvm {
 
+// This function checks whether the opt level is explicitly set to none,
+// or whether GlobalISel was enabled due to SDAG encountering an optnone
+// function. If the opt level is greater than the level we automatically enable
+// globalisel at, and it wasn't enabled via CLI, we know that it must be because
+// of an optnone function.
+bool isGlobalISelOptNone(const TargetMachine *TM);
+
 class AArch64TargetMachine : public CodeGenTargetMachineImpl {
 protected:
   std::unique_ptr<TargetLoweringObjectFile> TLOF;



More information about the llvm-commits mailing list