[llvm] [SandboxVec] Implement Pass class (PR #107617)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 11:12:07 PDT 2024


https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/107617

>From 5d4477757a6c2c180aef6aa570639cc667930b0f Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Thu, 5 Sep 2024 17:01:39 -0700
Subject: [PATCH 1/6] [SandboxVec] Implement Pass class

This patch implements the Pass base class and the FunctionPass sub-class that
operate on Sandbox IR.
---
 llvm/include/llvm/SandboxIR/Pass.h      | 82 +++++++++++++++++++++++++
 llvm/lib/SandboxIR/CMakeLists.txt       |  1 +
 llvm/lib/SandboxIR/Pass.cpp             | 19 ++++++
 llvm/unittests/SandboxIR/CMakeLists.txt |  1 +
 llvm/unittests/SandboxIR/PassTest.cpp   | 67 ++++++++++++++++++++
 5 files changed, 170 insertions(+)
 create mode 100644 llvm/include/llvm/SandboxIR/Pass.h
 create mode 100644 llvm/lib/SandboxIR/Pass.cpp
 create mode 100644 llvm/unittests/SandboxIR/PassTest.cpp

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
new file mode 100644
index 00000000000000..e005f1dc942635
--- /dev/null
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -0,0 +1,82 @@
+//===- Pass.h ---------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
+
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm::sandboxir {
+
+class Function;
+
+/// The base class of a Sandbox IR Pass.
+class Pass {
+public:
+  enum class ClassID : unsigned {
+    FunctionPass,
+  };
+  static const char *getSubclassIDStr(ClassID ID) {
+    switch (ID) {
+    case ClassID::FunctionPass:
+      return "FunctionPass";
+    }
+    llvm_unreachable("Unimplemented ID");
+  }
+
+protected:
+  /// The pass name.
+  const std::string Name;
+  /// The command-line flag used to specify that this pass should run.
+  const std::string Flag;
+  /// Used for isa/cast/dyn_cast.
+  ClassID SubclassID;
+
+public:
+  Pass(StringRef Name, StringRef Flag, ClassID SubclassID)
+      : Name(Name), Flag(Flag), SubclassID(SubclassID) {}
+  virtual ~Pass() {}
+  /// \Returns the name of the pass.
+  StringRef getName() const { return Name; }
+  /// \Returns the command-line flag used to enable the pass.
+  StringRef getFlag() const { return Flag; }
+  ClassID getSubclassID() const { return SubclassID; }
+#ifndef NDEBUG
+  friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
+    Pass.dump(OS);
+    return OS;
+  }
+  void dump(raw_ostream &OS) const { OS << Name << " " << Flag; }
+  LLVM_DUMP_METHOD void dump() const;
+#endif
+};
+
+/// A pass that runs on a sandbox::Function.
+class FunctionPass : public Pass {
+protected:
+  FunctionPass(StringRef Name, StringRef Flag, ClassID PassID)
+      : Pass(Name, Flag, PassID) {}
+
+public:
+  FunctionPass(StringRef Name, StringRef Flag)
+      : Pass(Name, Flag, ClassID::FunctionPass) {}
+  /// For isa/dyn_cast etc.
+  static bool classof(const Pass *From) {
+    switch (From->getSubclassID()) {
+    case ClassID::FunctionPass:
+      return true;
+    }
+  }
+  /// \Returns true if it modifies \p F.
+  virtual bool runOnFunction(Function &F) = 0;
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
diff --git a/llvm/lib/SandboxIR/CMakeLists.txt b/llvm/lib/SandboxIR/CMakeLists.txt
index d94f0642ccc4a1..2f047944e0335e 100644
--- a/llvm/lib/SandboxIR/CMakeLists.txt
+++ b/llvm/lib/SandboxIR/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_llvm_component_library(LLVMSandboxIR
+  Pass.cpp
   SandboxIR.cpp
   Tracker.cpp
   Type.cpp
diff --git a/llvm/lib/SandboxIR/Pass.cpp b/llvm/lib/SandboxIR/Pass.cpp
new file mode 100644
index 00000000000000..1453a6d9d101b4
--- /dev/null
+++ b/llvm/lib/SandboxIR/Pass.cpp
@@ -0,0 +1,19 @@
+//===- Pass.cpp - Passes that operate on Sandbox IR -----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/SandboxIR/Pass.h"
+#include "llvm/Support/Debug.h"
+
+using namespace llvm::sandboxir;
+
+#ifndef NDEBUG
+void Pass::dump() const {
+  dump(dbgs());
+  dbgs() << "\n";
+}
+#endif // NDEBUG
diff --git a/llvm/unittests/SandboxIR/CMakeLists.txt b/llvm/unittests/SandboxIR/CMakeLists.txt
index 2da936bffa02bf..a228637b062a43 100644
--- a/llvm/unittests/SandboxIR/CMakeLists.txt
+++ b/llvm/unittests/SandboxIR/CMakeLists.txt
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_llvm_unittest(SandboxIRTests
+  PassTest.cpp
   SandboxIRTest.cpp
   TrackerTest.cpp
   TypesTest.cpp
diff --git a/llvm/unittests/SandboxIR/PassTest.cpp b/llvm/unittests/SandboxIR/PassTest.cpp
new file mode 100644
index 00000000000000..ed95d14267e822
--- /dev/null
+++ b/llvm/unittests/SandboxIR/PassTest.cpp
@@ -0,0 +1,67 @@
+//===- PassesTest.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/SandboxIR/Pass.h"
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/Module.h"
+#include "llvm/SandboxIR/SandboxIR.h"
+#include "llvm/Support/SourceMgr.h"
+#include "gtest/gtest.h"
+
+using namespace llvm::sandboxir;
+
+struct PassTest : public testing::Test {
+  llvm::LLVMContext LLVMCtx;
+  std::unique_ptr<llvm::Module> LLVMM;
+  std::unique_ptr<Context> Ctx;
+
+  Function *parseFunction(const char *IR, const char *FuncName) {
+    llvm::SMDiagnostic Err;
+    LLVMM = parseAssemblyString(IR, Err, LLVMCtx);
+    if (!LLVMM)
+      Err.print("PassTest", llvm::errs());
+    Ctx = std::make_unique<Context>(LLVMCtx);
+    return Ctx->createFunction(LLVMM->getFunction(FuncName));
+  }
+};
+
+TEST_F(PassTest, FunctionPass) {
+  auto *F = parseFunction(R"IR(
+define void @foo() {
+  ret void
+}
+)IR",
+                          "foo");
+  class TestPass final : public FunctionPass {
+    unsigned &BBCnt;
+
+  public:
+    TestPass(unsigned &BBCnt)
+        : FunctionPass("TestPass", "-test-pass"), BBCnt(BBCnt) {}
+    bool runOnFunction(Function &F) final {
+      for ([[maybe_unused]] auto &BB : F)
+        ++BBCnt;
+      return false;
+    }
+  };
+  unsigned BBCnt = 0;
+  TestPass TPass(BBCnt);
+  // Check getName(),
+  EXPECT_EQ(TPass.getName(), "TestPass");
+  // Check getFlag().
+  EXPECT_EQ(TPass.getFlag(), "-test-pass");
+  // Check getSubclassID().
+  EXPECT_EQ(TPass.getSubclassID(), Pass::ClassID::FunctionPass);
+  // Check getSubclassIDStr().
+  EXPECT_EQ(Pass::getSubclassIDStr(TPass.getSubclassID()), "FunctionPass");
+  // Check classof().
+  EXPECT_TRUE(llvm::isa<FunctionPass>(TPass));
+  // Check runOnFunction();
+  TPass.runOnFunction(*F);
+  EXPECT_EQ(BBCnt, 1u);
+}

>From abb66ce4adcdd28ea96c9fcec93a2ba956128ede Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Fri, 6 Sep 2024 11:08:08 -0700
Subject: [PATCH 2/6] fixup! [SandboxVec] Implement Pass class

---
 llvm/include/llvm/SandboxIR/Pass.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index e005f1dc942635..b70cd1fcc6c5ae 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
-#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
+#ifndef LLVM_SANDBOXIR_PASS_H
+#define LLVM_SANDBOXIR_PASS_H
 
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -79,4 +79,4 @@ class FunctionPass : public Pass {
 
 } // namespace llvm::sandboxir
 
-#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASS_H
+#endif // LLVM_SANDBOXIR_PASS_H

>From 0f1bce7af9e6bbcd238dfa55133133e09a518c35 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Fri, 6 Sep 2024 15:21:56 -0700
Subject: [PATCH 3/6] fixup! fixup! [SandboxVec] Implement Pass class

---
 llvm/include/llvm/SandboxIR/Pass.h    |  4 ++--
 llvm/lib/SandboxIR/Pass.cpp           |  2 +-
 llvm/unittests/SandboxIR/PassTest.cpp | 16 ++++++++++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index b70cd1fcc6c5ae..bfac1bb681425a 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -49,10 +49,10 @@ class Pass {
   ClassID getSubclassID() const { return SubclassID; }
 #ifndef NDEBUG
   friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
-    Pass.dump(OS);
+    Pass.dumpOS(OS);
     return OS;
   }
-  void dump(raw_ostream &OS) const { OS << Name << " " << Flag; }
+  void dumpOS(raw_ostream &OS) const { OS << Name << " " << Flag; }
   LLVM_DUMP_METHOD void dump() const;
 #endif
 };
diff --git a/llvm/lib/SandboxIR/Pass.cpp b/llvm/lib/SandboxIR/Pass.cpp
index 1453a6d9d101b4..c6c3b1eabead7d 100644
--- a/llvm/lib/SandboxIR/Pass.cpp
+++ b/llvm/lib/SandboxIR/Pass.cpp
@@ -13,7 +13,7 @@ using namespace llvm::sandboxir;
 
 #ifndef NDEBUG
 void Pass::dump() const {
-  dump(dbgs());
+  dumpOS(dbgs());
   dbgs() << "\n";
 }
 #endif // NDEBUG
diff --git a/llvm/unittests/SandboxIR/PassTest.cpp b/llvm/unittests/SandboxIR/PassTest.cpp
index ed95d14267e822..1964424e755331 100644
--- a/llvm/unittests/SandboxIR/PassTest.cpp
+++ b/llvm/unittests/SandboxIR/PassTest.cpp
@@ -64,4 +64,20 @@ define void @foo() {
   // Check runOnFunction();
   TPass.runOnFunction(*F);
   EXPECT_EQ(BBCnt, 1u);
+#ifndef NDEBUG
+  {
+    // Check dump().
+    std::string Buff;
+    llvm::raw_string_ostream SS(Buff);
+    TPass.dumpOS(SS);
+    EXPECT_EQ(Buff, "FunctionPass");
+  }
+  {
+    // Check operator<<().
+    std::string Buff;
+    llvm::raw_string_ostream SS(Buff);
+    SS << TPass;
+    EXPECT_EQ(Buff, "FunctionPass");
+  }
+#endif
 }

>From 9915c98d40844e60f942275332ff00af72183ecf Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Mon, 9 Sep 2024 09:14:24 -0700
Subject: [PATCH 4/6] fixup! fixup! fixup! [SandboxVec] Implement Pass class

---
 llvm/include/llvm/SandboxIR/Pass.h    | 4 ++--
 llvm/lib/SandboxIR/Pass.cpp           | 2 +-
 llvm/unittests/SandboxIR/PassTest.cpp | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index bfac1bb681425a..9bb3ad16c1498a 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -49,10 +49,10 @@ class Pass {
   ClassID getSubclassID() const { return SubclassID; }
 #ifndef NDEBUG
   friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
-    Pass.dumpOS(OS);
+    Pass.print(OS);
     return OS;
   }
-  void dumpOS(raw_ostream &OS) const { OS << Name << " " << Flag; }
+  void print(raw_ostream &OS) const { OS << Name << " " << Flag; }
   LLVM_DUMP_METHOD void dump() const;
 #endif
 };
diff --git a/llvm/lib/SandboxIR/Pass.cpp b/llvm/lib/SandboxIR/Pass.cpp
index c6c3b1eabead7d..64e1b609a9f49d 100644
--- a/llvm/lib/SandboxIR/Pass.cpp
+++ b/llvm/lib/SandboxIR/Pass.cpp
@@ -13,7 +13,7 @@ using namespace llvm::sandboxir;
 
 #ifndef NDEBUG
 void Pass::dump() const {
-  dumpOS(dbgs());
+  print(dbgs());
   dbgs() << "\n";
 }
 #endif // NDEBUG
diff --git a/llvm/unittests/SandboxIR/PassTest.cpp b/llvm/unittests/SandboxIR/PassTest.cpp
index 1964424e755331..f027638b94c215 100644
--- a/llvm/unittests/SandboxIR/PassTest.cpp
+++ b/llvm/unittests/SandboxIR/PassTest.cpp
@@ -66,18 +66,18 @@ define void @foo() {
   EXPECT_EQ(BBCnt, 1u);
 #ifndef NDEBUG
   {
-    // Check dump().
+    // Check print().
     std::string Buff;
     llvm::raw_string_ostream SS(Buff);
-    TPass.dumpOS(SS);
-    EXPECT_EQ(Buff, "FunctionPass");
+    TPass.print(SS);
+    EXPECT_EQ(Buff, "TestPass -test-pass");
   }
   {
     // Check operator<<().
     std::string Buff;
     llvm::raw_string_ostream SS(Buff);
     SS << TPass;
-    EXPECT_EQ(Buff, "FunctionPass");
+    EXPECT_EQ(Buff, "TestPass -test-pass");
   }
 #endif
 }

>From 2e6a6f2003e0728bde84c3fe2fd442bc104b1b6f Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Mon, 9 Sep 2024 10:14:11 -0700
Subject: [PATCH 5/6] fixup! fixup! fixup! fixup! [SandboxVec] Implement Pass
 class

---
 llvm/include/llvm/SandboxIR/Pass.h    | 23 +++++++++++------------
 llvm/unittests/SandboxIR/PassTest.cpp | 19 ++++++++++++-------
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index 9bb3ad16c1498a..985792aca19c1c 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -31,28 +31,29 @@ class Pass {
   }
 
 protected:
-  /// The pass name.
+  /// The pass name. This is also used as a command-line flag and should not
+  /// contain whitespaces.
   const std::string Name;
-  /// The command-line flag used to specify that this pass should run.
-  const std::string Flag;
   /// Used for isa/cast/dyn_cast.
   ClassID SubclassID;
 
 public:
-  Pass(StringRef Name, StringRef Flag, ClassID SubclassID)
-      : Name(Name), Flag(Flag), SubclassID(SubclassID) {}
+  Pass(StringRef Name, ClassID SubclassID)
+      : Name(Name), SubclassID(SubclassID) {
+    assert(!Name.contains(' ') &&
+           "A pass name should not contain whitespaces!");
+    assert(!Name.starts_with('-') && "A pass name should not start with '-'!");
+  }
   virtual ~Pass() {}
   /// \Returns the name of the pass.
   StringRef getName() const { return Name; }
-  /// \Returns the command-line flag used to enable the pass.
-  StringRef getFlag() const { return Flag; }
   ClassID getSubclassID() const { return SubclassID; }
 #ifndef NDEBUG
   friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
     Pass.print(OS);
     return OS;
   }
-  void print(raw_ostream &OS) const { OS << Name << " " << Flag; }
+  void print(raw_ostream &OS) const { OS << Name; }
   LLVM_DUMP_METHOD void dump() const;
 #endif
 };
@@ -60,12 +61,10 @@ class Pass {
 /// A pass that runs on a sandbox::Function.
 class FunctionPass : public Pass {
 protected:
-  FunctionPass(StringRef Name, StringRef Flag, ClassID PassID)
-      : Pass(Name, Flag, PassID) {}
+  FunctionPass(StringRef Name, ClassID PassID) : Pass(Name, PassID) {}
 
 public:
-  FunctionPass(StringRef Name, StringRef Flag)
-      : Pass(Name, Flag, ClassID::FunctionPass) {}
+  FunctionPass(StringRef Name) : Pass(Name, ClassID::FunctionPass) {}
   /// For isa/dyn_cast etc.
   static bool classof(const Pass *From) {
     switch (From->getSubclassID()) {
diff --git a/llvm/unittests/SandboxIR/PassTest.cpp b/llvm/unittests/SandboxIR/PassTest.cpp
index f027638b94c215..de0ef5fa5ebbe3 100644
--- a/llvm/unittests/SandboxIR/PassTest.cpp
+++ b/llvm/unittests/SandboxIR/PassTest.cpp
@@ -41,8 +41,7 @@ define void @foo() {
     unsigned &BBCnt;
 
   public:
-    TestPass(unsigned &BBCnt)
-        : FunctionPass("TestPass", "-test-pass"), BBCnt(BBCnt) {}
+    TestPass(unsigned &BBCnt) : FunctionPass("test-pass"), BBCnt(BBCnt) {}
     bool runOnFunction(Function &F) final {
       for ([[maybe_unused]] auto &BB : F)
         ++BBCnt;
@@ -52,9 +51,7 @@ define void @foo() {
   unsigned BBCnt = 0;
   TestPass TPass(BBCnt);
   // Check getName(),
-  EXPECT_EQ(TPass.getName(), "TestPass");
-  // Check getFlag().
-  EXPECT_EQ(TPass.getFlag(), "-test-pass");
+  EXPECT_EQ(TPass.getName(), "test-pass");
   // Check getSubclassID().
   EXPECT_EQ(TPass.getSubclassID(), Pass::ClassID::FunctionPass);
   // Check getSubclassIDStr().
@@ -70,14 +67,22 @@ define void @foo() {
     std::string Buff;
     llvm::raw_string_ostream SS(Buff);
     TPass.print(SS);
-    EXPECT_EQ(Buff, "TestPass -test-pass");
+    EXPECT_EQ(Buff, "test-pass");
   }
   {
     // Check operator<<().
     std::string Buff;
     llvm::raw_string_ostream SS(Buff);
     SS << TPass;
-    EXPECT_EQ(Buff, "TestPass -test-pass");
+    EXPECT_EQ(Buff, "test-pass");
   }
+  // Check pass name assertions.
+  class TestNamePass final : public FunctionPass {
+  public:
+    TestNamePass(llvm::StringRef Name) : FunctionPass(Name) {}
+    bool runOnFunction(Function &F) { return false; }
+  };
+  EXPECT_DEATH(TestNamePass("white space"), ".*whitespace.*");
+  EXPECT_DEATH(TestNamePass("-dash"), ".*start with.*");
 #endif
 }

>From fae107d5674e0d370b65733b58d29dfdbd36981c Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Mon, 9 Sep 2024 11:09:06 -0700
Subject: [PATCH 6/6] fixup! fixup! fixup! fixup! fixup! [SandboxVec] Implement
 Pass class

---
 llvm/include/llvm/SandboxIR/Pass.h    | 30 ++-------------------------
 llvm/unittests/SandboxIR/PassTest.cpp |  4 ----
 2 files changed, 2 insertions(+), 32 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index 985792aca19c1c..d659e968392132 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -18,28 +18,13 @@ class Function;
 
 /// The base class of a Sandbox IR Pass.
 class Pass {
-public:
-  enum class ClassID : unsigned {
-    FunctionPass,
-  };
-  static const char *getSubclassIDStr(ClassID ID) {
-    switch (ID) {
-    case ClassID::FunctionPass:
-      return "FunctionPass";
-    }
-    llvm_unreachable("Unimplemented ID");
-  }
-
 protected:
   /// The pass name. This is also used as a command-line flag and should not
   /// contain whitespaces.
   const std::string Name;
-  /// Used for isa/cast/dyn_cast.
-  ClassID SubclassID;
 
 public:
-  Pass(StringRef Name, ClassID SubclassID)
-      : Name(Name), SubclassID(SubclassID) {
+  Pass(StringRef Name) : Name(Name) {
     assert(!Name.contains(' ') &&
            "A pass name should not contain whitespaces!");
     assert(!Name.starts_with('-') && "A pass name should not start with '-'!");
@@ -47,7 +32,6 @@ class Pass {
   virtual ~Pass() {}
   /// \Returns the name of the pass.
   StringRef getName() const { return Name; }
-  ClassID getSubclassID() const { return SubclassID; }
 #ifndef NDEBUG
   friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
     Pass.print(OS);
@@ -60,18 +44,8 @@ class Pass {
 
 /// A pass that runs on a sandbox::Function.
 class FunctionPass : public Pass {
-protected:
-  FunctionPass(StringRef Name, ClassID PassID) : Pass(Name, PassID) {}
-
 public:
-  FunctionPass(StringRef Name) : Pass(Name, ClassID::FunctionPass) {}
-  /// For isa/dyn_cast etc.
-  static bool classof(const Pass *From) {
-    switch (From->getSubclassID()) {
-    case ClassID::FunctionPass:
-      return true;
-    }
-  }
+  FunctionPass(StringRef Name) : Pass(Name) {}
   /// \Returns true if it modifies \p F.
   virtual bool runOnFunction(Function &F) = 0;
 };
diff --git a/llvm/unittests/SandboxIR/PassTest.cpp b/llvm/unittests/SandboxIR/PassTest.cpp
index de0ef5fa5ebbe3..1abb0ddc5240ab 100644
--- a/llvm/unittests/SandboxIR/PassTest.cpp
+++ b/llvm/unittests/SandboxIR/PassTest.cpp
@@ -52,10 +52,6 @@ define void @foo() {
   TestPass TPass(BBCnt);
   // Check getName(),
   EXPECT_EQ(TPass.getName(), "test-pass");
-  // Check getSubclassID().
-  EXPECT_EQ(TPass.getSubclassID(), Pass::ClassID::FunctionPass);
-  // Check getSubclassIDStr().
-  EXPECT_EQ(Pass::getSubclassIDStr(TPass.getSubclassID()), "FunctionPass");
   // Check classof().
   EXPECT_TRUE(llvm::isa<FunctionPass>(TPass));
   // Check runOnFunction();



More information about the llvm-commits mailing list