[llvm] [May] Registration the backend for May architecture (PR #93250)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 15:13:23 PDT 2024
https://github.com/EgorShirikov created https://github.com/llvm/llvm-project/pull/93250
None
>From ad560d0d7450c44465336545e45222bfed8b16c3 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 01:12:09 +0300
Subject: [PATCH] [May] Registration the backend for May architecture
---
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 ++++
9 files changed, 161 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/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
More information about the llvm-commits
mailing list