[llvm] [SandboxIR][NFC] Move Argument into a separate file (PR #110174)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 15:30:14 PDT 2024


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

>From 81085cc02f549dbf172cbbbcf430d04201ca8883 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Thu, 26 Sep 2024 09:16:16 -0700
Subject: [PATCH] [SandboxIR][NFC] Move Argument into a separate file

---
 llvm/include/llvm/SandboxIR/Argument.h  | 38 +++++++++++++++++++++++++
 llvm/include/llvm/SandboxIR/SandboxIR.h | 20 +------------
 llvm/include/llvm/SandboxIR/Value.h     |  2 ++
 llvm/lib/SandboxIR/Argument.cpp         | 23 +++++++++++++++
 llvm/lib/SandboxIR/CMakeLists.txt       |  1 +
 llvm/lib/SandboxIR/SandboxIR.cpp        | 11 +------
 6 files changed, 66 insertions(+), 29 deletions(-)
 create mode 100644 llvm/include/llvm/SandboxIR/Argument.h
 create mode 100644 llvm/lib/SandboxIR/Argument.cpp

diff --git a/llvm/include/llvm/SandboxIR/Argument.h b/llvm/include/llvm/SandboxIR/Argument.h
new file mode 100644
index 00000000000000..aed886e8f22f28
--- /dev/null
+++ b/llvm/include/llvm/SandboxIR/Argument.h
@@ -0,0 +1,38 @@
+//===- Argument.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_SANDBOXIR_ARGUMENT_H
+#define LLVM_SANDBOXIR_ARGUMENT_H
+
+#include "llvm/IR/Argument.h"
+#include "llvm/SandboxIR/Value.h"
+
+namespace llvm::sandboxir {
+
+/// Argument of a sandboxir::Function.
+class Argument : public sandboxir::Value {
+  Argument(llvm::Argument *Arg, sandboxir::Context &Ctx)
+      : Value(ClassID::Argument, Arg, Ctx) {}
+  friend class Context; // For constructor.
+
+public:
+  static bool classof(const sandboxir::Value *From) {
+    return From->getSubclassID() == ClassID::Argument;
+  }
+#ifndef NDEBUG
+  void verify() const final {
+    assert(isa<llvm::Argument>(Val) && "Expected Argument!");
+  }
+  void printAsOperand(raw_ostream &OS) const;
+  void dumpOS(raw_ostream &OS) const final;
+#endif
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_SANDBOXIR_ARGUMENT_H
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 3d206bca9eae6c..66de9ee078d619 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -109,6 +109,7 @@
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
+#include "llvm/SandboxIR/Argument.h"
 #include "llvm/SandboxIR/Context.h"
 #include "llvm/SandboxIR/Module.h"
 #include "llvm/SandboxIR/Tracker.h"
@@ -189,25 +190,6 @@ class CmpInst;
 class ICmpInst;
 class FCmpInst;
 
-/// Argument of a sandboxir::Function.
-class Argument : public sandboxir::Value {
-  Argument(llvm::Argument *Arg, sandboxir::Context &Ctx)
-      : sandboxir::Value(ClassID::Argument, Arg, Ctx) {}
-  friend class Context; // For constructor.
-
-public:
-  static bool classof(const sandboxir::Value *From) {
-    return From->getSubclassID() == ClassID::Argument;
-  }
-#ifndef NDEBUG
-  void verify() const final {
-    assert(isa<llvm::Argument>(Val) && "Expected Argument!");
-  }
-  void printAsOperand(raw_ostream &OS) const;
-  void dumpOS(raw_ostream &OS) const final;
-#endif
-};
-
 class Constant : public sandboxir::User {
 protected:
   Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
diff --git a/llvm/include/llvm/SandboxIR/Value.h b/llvm/include/llvm/SandboxIR/Value.h
index 5dc06c5fc39bf8..49bd9be82b0df5 100644
--- a/llvm/include/llvm/SandboxIR/Value.h
+++ b/llvm/include/llvm/SandboxIR/Value.h
@@ -16,6 +16,8 @@ namespace llvm::sandboxir {
 
 // Forward declare all classes to avoid some MSVC build errors.
 #define DEF_INSTR(ID, OPC, CLASS) class CLASS;
+#define DEF_CONST(ID, CLASS) class CLASS;
+#define DEF_USER(ID, CLASS) class CLASS;
 #include "llvm/SandboxIR/SandboxIRValues.def"
 class Context;
 class FuncletPadInst;
diff --git a/llvm/lib/SandboxIR/Argument.cpp b/llvm/lib/SandboxIR/Argument.cpp
new file mode 100644
index 00000000000000..e35da2d1dbcb7b
--- /dev/null
+++ b/llvm/lib/SandboxIR/Argument.cpp
@@ -0,0 +1,23 @@
+//===- Argument.cpp - The function Argument class of 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/Argument.h"
+
+namespace llvm::sandboxir {
+
+#ifndef NDEBUG
+void Argument::printAsOperand(raw_ostream &OS) const {
+  printAsOperandCommon(OS);
+}
+void Argument::dumpOS(raw_ostream &OS) const {
+  dumpCommonPrefix(OS);
+  dumpCommonSuffix(OS);
+}
+#endif // NDEBUG
+
+} // namespace llvm::sandboxir
diff --git a/llvm/lib/SandboxIR/CMakeLists.txt b/llvm/lib/SandboxIR/CMakeLists.txt
index 6386fc908388a0..d9259db970da58 100644
--- a/llvm/lib/SandboxIR/CMakeLists.txt
+++ b/llvm/lib/SandboxIR/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_llvm_component_library(LLVMSandboxIR
+  Argument.cpp
   Context.cpp
   Module.cpp
   Pass.cpp
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 92b1ebeedc55b0..12cac66480b0c3 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/SandboxIR/Argument.h"
 #include "llvm/Support/Debug.h"
 #include <sstream>
 
@@ -105,16 +106,6 @@ int OperandUseIterator::operator-(const OperandUseIterator &Other) const {
   return ThisOpNo - OtherOpNo;
 }
 
-#ifndef NDEBUG
-void Argument::printAsOperand(raw_ostream &OS) const {
-  printAsOperandCommon(OS);
-}
-void Argument::dumpOS(raw_ostream &OS) const {
-  dumpCommonPrefix(OS);
-  dumpCommonSuffix(OS);
-}
-#endif // NDEBUG
-
 BBIterator &BBIterator::operator++() {
   auto ItE = BB->end();
   assert(It != ItE && "Already at end!");



More information about the llvm-commits mailing list