[llvm] [IR][NFC] Make PassConcept immovable (PR #208167)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 01:46:24 PDT 2026


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/208167

PassConcept is only ever created as a unique_ptr when added to the pass
list of a pass manager. The instances are never copied or moved. Due to
inheritance, this also wouldn't work anyway. Explicitly forbid
copying/moving and remove the dead functions.

Preliminary work for removing the vtable from PassConcept/PassModel.


>From a103cd17fdb0c429e4386e90d88a54438c90655f Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Wed, 8 Jul 2026 08:45:28 +0000
Subject: [PATCH] [spr] initial version

Created using spr 1.3.8-wip
---
 llvm/include/llvm/IR/PassManagerInternal.h | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/llvm/include/llvm/IR/PassManagerInternal.h b/llvm/include/llvm/IR/PassManagerInternal.h
index f96fb02b1d3c5..f894f91cf1783 100644
--- a/llvm/include/llvm/IR/PassManagerInternal.h
+++ b/llvm/include/llvm/IR/PassManagerInternal.h
@@ -38,9 +38,15 @@ namespace detail {
 /// polymorphically over pass objects.
 template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
 struct PassConcept {
+  PassConcept() = default;
+
   // Boiler plate necessary for the container of derived classes.
   virtual ~PassConcept() = default;
 
+  // Passes are immovable.
+  PassConcept(const PassConcept &) = delete;
+  PassConcept &operator=(const PassConcept &) = delete;
+
   /// The polymorphic API which runs the pass over a given IR entity.
   ///
   /// Note that actual pass object can omit the analysis manager argument if
@@ -71,22 +77,8 @@ struct PassConcept {
 /// be a copyable object.
 template <typename IRUnitT, typename PassT, typename AnalysisManagerT,
           typename... ExtraArgTs>
-struct PassModel : PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
+struct PassModel final : PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
   explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {}
-  // We have to explicitly define all the special member functions because MSVC
-  // refuses to generate them.
-  PassModel(const PassModel &Arg) : Pass(Arg.Pass) {}
-  PassModel(PassModel &&Arg) : Pass(std::move(Arg.Pass)) {}
-
-  friend void swap(PassModel &LHS, PassModel &RHS) {
-    using std::swap;
-    swap(LHS.Pass, RHS.Pass);
-  }
-
-  PassModel &operator=(PassModel RHS) {
-    swap(*this, RHS);
-    return *this;
-  }
 
   PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM,
                         ExtraArgTs... ExtraArgs) override {



More information about the llvm-commits mailing list