[llvm] [May] Registering the backend for the May architecture (PR #93254)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 16:28:57 PDT 2024


https://github.com/EgorShirikov created https://github.com/llvm/llvm-project/pull/93254

None

>From d5263108dba4379c7e8c084de7bf4dd7d8c3cb81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=95=D0=B3=D0=BE=D1=80=20=D0=A8=D0=B8=D1=80=D0=B8=D0=BA?=
 =?UTF-8?q?=D0=BE=D0=B2?= <egor at MacBook-Pro-Egor-2.local>
Date: Fri, 24 May 2024 02:26:46 +0300
Subject: [PATCH] [May] Registering the backend for the May architecture

---
 llvm/CMakeLists.txt                           |  1 +
 llvm/include/llvm/TargetParser/Triple.h       |  1 +
 llvm/lib/Target/May/CMakeLists.txt            | 18 ++++++
 .../Target/May/MCTargetDesc/CMakeLists.txt    | 12 ++++
 .../May/MCTargetDesc/MayMcTargetDesc.cpp      |  3 +
 .../Target/May/MCTargetDesc/MayMcTargetDesc.h |  4 ++
 llvm/lib/Target/May/MayTargetMachine.cpp      | 57 +++++++++++++++++++
 llvm/lib/Target/May/MayTargetMachine.h        | 32 +++++++++++
 llvm/lib/Target/May/TargetInfo/CMakeLists.txt | 10 ++++
 .../Target/May/TargetInfo/MayTargetInfo.cpp   | 13 +++++
 .../lib/Target/May/TargetInfo/MayTargetInfo.h | 12 ++++
 llvm/lib/TargetParser/Triple.cpp              | 10 ++++
 12 files changed, 173 insertions(+)
 create mode 100644 llvm/lib/Target/May/CMakeLists.txt
 create mode 100644 llvm/lib/Target/May/MCTargetDesc/CMakeLists.txt
 create mode 100644 llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.cpp
 create mode 100644 llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.h
 create mode 100644 llvm/lib/Target/May/MayTargetMachine.cpp
 create mode 100644 llvm/lib/Target/May/MayTargetMachine.h
 create mode 100644 llvm/lib/Target/May/TargetInfo/CMakeLists.txt
 create mode 100644 llvm/lib/Target/May/TargetInfo/MayTargetInfo.cpp
 create mode 100644 llvm/lib/Target/May/TargetInfo/MayTargetInfo.h

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index c06e661573ed4..44b400edbfa97 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -486,6 +486,7 @@ set(LLVM_ALL_TARGETS
   VE
   WebAssembly
   X86
+  May
   XCore
   )
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index b3bb354b38ff5..ac3a4cf567af0 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -84,6 +84,7 @@ class Triple {
     thumbeb,        // Thumb (big endian): thumbeb
     x86,            // X86: i[3-9]86
     x86_64,         // X86-64: amd64, x86_64
+    may.            // May
     xcore,          // XCore: xcore
     xtensa,         // Tensilica: Xtensa
     nvptx,          // NVPTX: 32-bit
diff --git a/llvm/lib/Target/May/CMakeLists.txt b/llvm/lib/Target/May/CMakeLists.txt
new file mode 100644
index 0000000000000..892c60bb22599
--- /dev/null
+++ b/llvm/lib/Target/May/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_llvm_component_group(May)
+
+add_llvm_target(MayCodeGen
+        MayTargetMachine.cpp
+
+        LINK_COMPONENTS
+        CodeGen
+        Core
+        Support
+        Target
+        MayInfo
+
+        ADD_TO_COMPONENT
+        May
+    )
+
+add_subdirectory(MCTargetDesc)
+add_subdirectory(TargetInfo)
\ No newline at end of file
diff --git a/llvm/lib/Target/May/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/May/MCTargetDesc/CMakeLists.txt
new file mode 100644
index 0000000000000..f88881af502f2
--- /dev/null
+++ b/llvm/lib/Target/May/MCTargetDesc/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_llvm_component_library(LLVMMayDesc
+        MayMcTargetDesc.cpp
+
+        LINK_COMPONENTS
+        MC
+        Support
+        MayInfo
+
+        ADD_TO_COMPONENT
+        May
+
+)
\ No newline at end of file
diff --git a/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.cpp b/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.cpp
new file mode 100644
index 0000000000000..7ced45ab7d44d
--- /dev/null
+++ b/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.cpp
@@ -0,0 +1,3 @@
+#include "MayMcTargetDesc.h"
+
+extern "C" void LLVMInitializeMayTargetMC(){}
\ No newline at end of file
diff --git a/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.h b/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.h
new file mode 100644
index 0000000000000..bb70517d59ad9
--- /dev/null
+++ b/llvm/lib/Target/May/MCTargetDesc/MayMcTargetDesc.h
@@ -0,0 +1,4 @@
+#ifndef LLVM_LIB_TARGET_May_MCTARGETDESC_MAYMCTARGETDESC_H
+#define LLVM_LIB_TARGET_May_MCTARGETDESC_MAYMCTARGETDESC_H
+
+#endif
diff --git a/llvm/lib/Target/May/MayTargetMachine.cpp b/llvm/lib/Target/May/MayTargetMachine.cpp
new file mode 100644
index 0000000000000..fc7f1d21bc935
--- /dev/null
+++ b/llvm/lib/Target/May/MayTargetMachine.cpp
@@ -0,0 +1,57 @@
+#include "MayTargetMachine.h"
+#include "TargetInfo/MayTargetInfo.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/Scalar.h"
+#include <optional>
+
+using namespace llvm;
+
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMayTarget() {
+  // Register the target.
+  RegisterTargetMachine<MayTargetMachine> A(getTheMayTarget());
+}
+
+static std::string computeDataLayout(const Triple &TT, StringRef CPU,
+                                     const TargetOptions &Options,
+                                     bool IsLittle) {
+  std::string Ret = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32";
+  return Ret;
+}
+
+static Reloc::Model getEffectiveRelocModel(bool JIT,
+                                           std::optional<Reloc::Model> RM) {
+  if (!RM || JIT)
+    return Reloc::Static;
+  return *RM;
+}
+
+MayTargetMachine::MayTargetMachine(const Target &T, const Triple &TT,
+                                   StringRef CPU, StringRef FS,
+                                   const TargetOptions &Options,
+                                   std::optional<Reloc::Model> RM,
+                                   std::optional<CodeModel::Model> CM,
+                                   CodeGenOptLevel OL, bool JIT,
+                                   bool IsLittle)
+    : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, IsLittle), TT,
+                        CPU, FS, Options, getEffectiveRelocModel(JIT, RM),
+                        getEffectiveCodeModel(CM, CodeModel::Small), OL),
+      TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
+  initAsmInfo();
+}
+
+MayTargetMachine::MayTargetMachine(const Target &T, const Triple &TT,
+                                   StringRef CPU, StringRef FS,
+                                   const TargetOptions &Options,
+                                   std::optional<Reloc::Model> RM,
+                                   std::optional<CodeModel::Model> CM,
+                                   CodeGenOptLevel OL, bool JIT)
+    : MayTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
+
+TargetPassConfig *MayTargetMachine::createPassConfig(PassManagerBase &PM) {
+  return new TargetPassConfig(*this, PM);
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/May/MayTargetMachine.h b/llvm/lib/Target/May/MayTargetMachine.h
new file mode 100644
index 0000000000000..b39ba551a8ce1
--- /dev/null
+++ b/llvm/lib/Target/May/MayTargetMachine.h
@@ -0,0 +1,32 @@
+#ifndef LLVM_PROJECT_MAYTARGETMACHINE_CPP_H
+#define LLVM_PROJECT_MAYTARGETMACHINE_CPP_H
+
+#include "llvm/Target/TargetMachine.h"
+#include "optional"
+
+namespace llvm {
+extern Target TheMayTarget;
+
+class MayTargetMachine : public LLVMTargetMachine {
+  std::unique_ptr<TargetLoweringObjectFile> TLOF;
+
+public:
+  MayTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
+                   StringRef FS, const TargetOptions &Options,
+                   std::optional<Reloc::Model> RM,
+                   std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
+                   bool JIT, bool isLittle);
+
+  MayTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
+                   StringRef FS, const TargetOptions &Options,
+                   std::optional<Reloc::Model> RM,
+                   std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
+                   bool JIT);
+
+  TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
+  TargetLoweringObjectFile *getObjFileLowering() const override {
+    return TLOF.get();
+  }
+};
+} // end namespace llvm
+#endif
diff --git a/llvm/lib/Target/May/TargetInfo/CMakeLists.txt b/llvm/lib/Target/May/TargetInfo/CMakeLists.txt
new file mode 100644
index 0000000000000..aee9db2fef4c0
--- /dev/null
+++ b/llvm/lib/Target/May/TargetInfo/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_llvm_component_library(LLVMMayInfo
+        MayTargetInfo.cpp
+
+        LINK_COMPONENTS
+        MC
+        Support
+
+        ADD_TO_COMPONENT
+        May
+)
\ No newline at end of file
diff --git a/llvm/lib/Target/May/TargetInfo/MayTargetInfo.cpp b/llvm/lib/Target/May/TargetInfo/MayTargetInfo.cpp
new file mode 100644
index 0000000000000..e43dfb8b0fb76
--- /dev/null
+++ b/llvm/lib/Target/May/TargetInfo/MayTargetInfo.cpp
@@ -0,0 +1,13 @@
+#include "TargetInfo/MayTargetInfo.h"
+#include "llvm/MC/TargetRegistry.h"
+using namespace llvm;
+
+Target &llvm::getTheMayTarget() {
+  static Target TheMayTarget;
+  return TheMayTarget;
+}
+
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMayTargetInfo() {
+  RegisterTarget<Triple::may> X(getTheMayTarget(), "may", "May Instruction Set",
+                                "May");
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/May/TargetInfo/MayTargetInfo.h b/llvm/lib/Target/May/TargetInfo/MayTargetInfo.h
new file mode 100644
index 0000000000000..28d377973e38b
--- /dev/null
+++ b/llvm/lib/Target/May/TargetInfo/MayTargetInfo.h
@@ -0,0 +1,12 @@
+#ifndef LLVM_PROJECT_MAYTARGETINFO_H
+#define LLVM_PROJECT_MAYTARGETINFO_H
+
+namespace llvm {
+
+class Target;
+
+Target &getTheMayTarget();
+
+}
+
+#endif
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 4fc1ff5aaa051..9e98962a8eed1 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -84,6 +84,7 @@ StringRef Triple::getArchTypeName(ArchType Kind) {
   case wasm64:         return "wasm64";
   case x86:            return "i386";
   case x86_64:         return "x86_64";
+  case may:            return "may";
   case xcore:          return "xcore";
   case xtensa:         return "xtensa";
   }
@@ -192,6 +193,7 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
 
   case x86:
   case x86_64:      return "x86";
+  case may:         return "may"; 
 
   case xcore:       return "xcore";
 
@@ -429,6 +431,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
     .Case("x86", x86)
     .Case("i386", x86)
     .Case("x86-64", x86_64)
+    .Case("may", may)  
     .Case("xcore", xcore)
     .Case("nvptx", nvptx)
     .Case("nvptx64", nvptx64)
@@ -597,6 +600,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
           .Case("ve", Triple::ve)
           .Case("wasm32", Triple::wasm32)
           .Case("wasm64", Triple::wasm64)
+          .Case("may", Triple::may)
           .Case("csky", Triple::csky)
           .Case("loongarch32", Triple::loongarch32)
           .Case("loongarch64", Triple::loongarch64)
@@ -898,6 +902,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
   case Triple::armeb:
   case Triple::avr:
   case Triple::bpfeb:
+  case Triple::may:
   case Triple::bpfel:
   case Triple::csky:
   case Triple::hexagon:
@@ -1596,6 +1601,7 @@ unsigned Triple::getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
   case llvm::Triple::amdil:
   case llvm::Triple::arc:
   case llvm::Triple::arm:
+  case llvm::Triple::may:
   case llvm::Triple::armeb:
   case llvm::Triple::csky:
   case llvm::Triple::dxil:
@@ -1717,6 +1723,7 @@ Triple Triple::get32BitArchVariant() const {
   case Triple::thumbeb:
   case Triple::wasm32:
   case Triple::x86:
+  case Triple::may:  
   case Triple::xcore:
   case Triple::xtensa:
     // Already 32-bit.
@@ -1768,6 +1775,7 @@ Triple Triple::get64BitArchVariant() const {
   case Triple::shave:
   case Triple::sparcel:
   case Triple::tce:
+  case Triple::may:
   case Triple::tcele:
   case Triple::xcore:
   case Triple::xtensa:
@@ -1863,6 +1871,7 @@ Triple Triple::getBigEndianArchVariant() const {
   case Triple::shave:
   case Triple::spir64:
   case Triple::spir:
+  case Triple::may:
   case Triple::spirv:
   case Triple::spirv32:
   case Triple::spirv64:
@@ -1983,6 +1992,7 @@ bool Triple::isLittleEndian() const {
   case Triple::wasm64:
   case Triple::x86:
   case Triple::x86_64:
+  case Triple::may:
   case Triple::xcore:
   case Triple::xtensa:
     return true;



More information about the llvm-commits mailing list