[llvm] 57186af - [NewPM] Add helper function to skip for opt-bisect

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 11:25:05 PDT 2026


Author: Aiden Grossman
Date: 2026-09-15T11:25:00-07:00
New Revision: 57186afd172250f0c1695b809505947382f227cd

URL: https://github.com/llvm/llvm-project/commit/57186afd172250f0c1695b809505947382f227cd
DIFF: https://github.com/llvm/llvm-project/commit/57186afd172250f0c1695b809505947382f227cd.diff

LOG: [NewPM] Add helper function to skip for opt-bisect

With the introduction of CodeGen passes to the NewPM infrastructure, we
get the concept of required passes that perform optimizations and want
to skip them when running under opt bisect. This occurs for passes like
SelectionDAG and StackColoring. Add a helper function to make it easy to
query, although make it specific to opt bisect unlike the LegacyPM
skipFunction. A helper function is slightly more convenient (i.e., no
need to forward the pass name explicitly).

Reviewers: nikic, arsenm, aeubanks

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassManager.h
    llvm/lib/IR/PassManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index c8e2276ac22ee..17beecf233851 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -44,6 +44,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/IR/Analysis.h"
+#include "llvm/IR/IRUnitRef.h"
 #include "llvm/IR/PassManagerInternal.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/TypeName.h"
@@ -89,6 +90,8 @@ struct PassInfoMixin : detail::InfoMixin<DerivedT> {
   // TODO: remove once out of tree users are updated.
   static bool isRequired() { return false; }
 };
+
+bool shouldSkipOptimizationForOptBisect(IRUnitRef IR, StringRef PassName);
 } // namespace detail
 
 class Function;
@@ -101,6 +104,11 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
 template <typename DerivedT>
 struct RequiredPassInfoMixin : detail::PassInfoMixin<DerivedT> {
   static bool isRequired() { return true; }
+
+public:
+  bool shouldSkipOptimizationForOptBisect(IRUnitRef IR) {
+    return detail::shouldSkipOptimizationForOptBisect(IR, DerivedT::name());
+  }
 };
 
 /// A CRTP mix-in for passes that can be skipped.

diff  --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp
index af22b779ddbb0..dca3c0e8fbc9f 100644
--- a/llvm/lib/IR/PassManager.cpp
+++ b/llvm/lib/IR/PassManager.cpp
@@ -7,14 +7,34 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/PassManager.h"
+#include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/OptBisect.h"
 #include "llvm/IR/PassManagerImpl.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <optional>
 
 using namespace llvm;
 
 namespace llvm {
+
+bool detail::shouldSkipOptimizationForOptBisect(IRUnitRef IR,
+                                                StringRef PassName) {
+  LLVMContext *Ctx = nullptr;
+  std::string IRName = "";
+  if (const auto *M = dyn_cast<Module>(IR)) {
+    Ctx = &M->getContext();
+    IRName = "[module]";
+  } else if (const auto *F = dyn_cast<Function>(IR)) {
+    Ctx = &F->getContext();
+    IRName = F->getName().str();
+  } else {
+    llvm_unreachable("Tried to check skipping for an invalid IR type");
+  }
+  return Ctx->getOptPassGate().shouldRunPass(PassName, IRName);
+}
+
 // Explicit template instantiations and specialization defininitions for core
 // template typedefs.
 template class LLVM_EXPORT_TEMPLATE AllAnalysesOn<Module>;


        


More information about the llvm-commits mailing list