[llvm] e1c38dd - [CSKY 1/n] Add basic stub or infra of csky backend
Zi Xuan Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 19:46:15 PDT 2020
Author: Zi Xuan Wu
Date: 2020-10-10T10:44:08+08:00
New Revision: e1c38dd55d9dab332ccabb7c83a80ca92c373af0
URL: https://github.com/llvm/llvm-project/commit/e1c38dd55d9dab332ccabb7c83a80ca92c373af0
DIFF: https://github.com/llvm/llvm-project/commit/e1c38dd55d9dab332ccabb7c83a80ca92c373af0.diff
LOG: [CSKY 1/n] Add basic stub or infra of csky backend
This patch introduce files that just enough for lib/Target/CSKY to compile.
Notably a basic CSKYTargetMachine and CSKYTargetInfo.
Differential Revision: https://reviews.llvm.org/D88466
Added:
llvm/lib/Target/CSKY/CMakeLists.txt
llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
llvm/lib/Target/CSKY/CSKYTargetMachine.h
llvm/lib/Target/CSKY/LLVMBuild.txt
llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt
llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.cpp
llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.h
llvm/lib/Target/CSKY/TargetInfo/LLVMBuild.txt
Modified:
llvm/CODE_OWNERS.TXT
llvm/docs/CompilerWriterInfo.rst
llvm/lib/Target/LLVMBuild.txt
Removed:
################################################################################
diff --git a/llvm/CODE_OWNERS.TXT b/llvm/CODE_OWNERS.TXT
index 543858c29bd8..19728eda9996 100644
--- a/llvm/CODE_OWNERS.TXT
+++ b/llvm/CODE_OWNERS.TXT
@@ -232,3 +232,7 @@ D: llvm-objcopy (tools/llvm-objcopy)
N: Martin Storsjö
E: martin at martin.st
D: MinGW
+
+N: Zi Xuan Wu (Zeson)
+E: zixuan.wu at linux.alibaba.com
+D: C-SKY backend (lib/Target/CSKY/*)
diff --git a/llvm/docs/CompilerWriterInfo.rst b/llvm/docs/CompilerWriterInfo.rst
index 41e176295197..55c2b92e4931 100644
--- a/llvm/docs/CompilerWriterInfo.rst
+++ b/llvm/docs/CompilerWriterInfo.rst
@@ -102,6 +102,11 @@ RISC-V
------
* `RISC-V User-Level ISA Specification <https://riscv.org/specifications/>`_
+C-SKY
+------
+* `C-SKY Architecture User Guide <https://github.com/c-sky/csky-doc/blob/master/CSKY%20Architecture%20user_guide.pdf>`_
+* `C-SKY V2 ABI <https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf>`_
+
SPARC
-----
diff --git a/llvm/lib/Target/CSKY/CMakeLists.txt b/llvm/lib/Target/CSKY/CMakeLists.txt
new file mode 100644
index 000000000000..a8ab01d25b89
--- /dev/null
+++ b/llvm/lib/Target/CSKY/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_llvm_target(CSKYCodeGen
+ CSKYTargetMachine.cpp
+ )
+
+add_subdirectory(TargetInfo)
diff --git a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
new file mode 100644
index 000000000000..3e4e1b083f7a
--- /dev/null
+++ b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
@@ -0,0 +1,68 @@
+//===--- CSKYTargetMachine.cpp - Define TargetMachine for CSKY ------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the info about CSKY target spec.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CSKYTargetMachine.h"
+#include "TargetInfo/CSKYTargetInfo.h"
+#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/Support/TargetRegistry.h"
+
+using namespace llvm;
+
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTarget() {
+ RegisterTargetMachine<CSKYTargetMachine> X(getTheCSKYTarget());
+}
+
+static std::string computeDataLayout(const Triple &TT) {
+ std::string Ret;
+
+ // Only support little endian for now.
+ // TODO: Add support for big endian.
+ Ret += "e";
+
+ // CSKY is always 32-bit target with the CSKYv2 ABI as prefer now.
+ // It's a 4-byte aligned stack with ELF mangling only.
+ Ret += "-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32"
+ "-v128:32:32-a:0:32-Fi32-n32";
+
+ return Ret;
+}
+
+CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT,
+ StringRef CPU, StringRef FS,
+ const TargetOptions &Options,
+ Optional<Reloc::Model> RM,
+ Optional<CodeModel::Model> CM,
+ CodeGenOpt::Level OL, bool JIT)
+ : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
+ !RM.hasValue() ? Reloc::Static : *RM,
+ getEffectiveCodeModel(CM, CodeModel::Small), OL),
+ TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
+ initAsmInfo();
+}
+
+namespace {
+class CSKYPassConfig : public TargetPassConfig {
+public:
+ CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM)
+ : TargetPassConfig(TM, PM) {}
+
+ CSKYTargetMachine &getCSKYTargetMachine() const {
+ return getTM<CSKYTargetMachine>();
+ }
+};
+
+} // namespace
+
+TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) {
+ return new CSKYPassConfig(*this, PM);
+}
diff --git a/llvm/lib/Target/CSKY/CSKYTargetMachine.h b/llvm/lib/Target/CSKY/CSKYTargetMachine.h
new file mode 100644
index 000000000000..d50e3877b550
--- /dev/null
+++ b/llvm/lib/Target/CSKY/CSKYTargetMachine.h
@@ -0,0 +1,38 @@
+//===--- CSKYTargetMachine.h - Define TargetMachine for CSKY ----*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the CSKY specific subclass of TargetMachine.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_CSKY_CSKYTARGETMACHINE_H
+#define LLVM_LIB_TARGET_CSKY_CSKYTARGETMACHINE_H
+
+#include "llvm/IR/DataLayout.h"
+#include "llvm/Target/TargetMachine.h"
+
+namespace llvm {
+
+class CSKYTargetMachine : public LLVMTargetMachine {
+ std::unique_ptr<TargetLoweringObjectFile> TLOF;
+
+public:
+ CSKYTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
+ StringRef FS, const TargetOptions &Options,
+ Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
+ CodeGenOpt::Level OL, bool JIT);
+
+ TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
+
+ TargetLoweringObjectFile *getObjFileLowering() const override {
+ return TLOF.get();
+ }
+};
+} // namespace llvm
+
+#endif
diff --git a/llvm/lib/Target/CSKY/LLVMBuild.txt b/llvm/lib/Target/CSKY/LLVMBuild.txt
new file mode 100644
index 000000000000..97f09b6ec288
--- /dev/null
+++ b/llvm/lib/Target/CSKY/LLVMBuild.txt
@@ -0,0 +1,30 @@
+;===----- ./lib/Target/CSKY/LLVMBuild.txt ----------------------*- Conf -*--===;
+;
+; 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
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[common]
+subdirectories = TargetInfo
+
+[component_0]
+type = TargetGroup
+name = CSKY
+parent = Target
+
+[component_1]
+type = Library
+name = CSKYCodeGen
+parent = CSKY
+required_libraries = Core CodeGen CSKYInfo Support Target
+add_to_library_groups = CSKY
diff --git a/llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt b/llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt
new file mode 100644
index 000000000000..712021d31ab9
--- /dev/null
+++ b/llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_llvm_library(LLVMCSKYInfo
+ CSKYTargetInfo.cpp
+ )
diff --git a/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.cpp b/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.cpp
new file mode 100644
index 000000000000..45a84703370e
--- /dev/null
+++ b/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.cpp
@@ -0,0 +1,25 @@
+//===-- CSKYTargetInfo.cpp - CSKY Target Implementation -------------------===//
+//
+// 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 "TargetInfo/CSKYTargetInfo.h"
+#include "llvm/Support/TargetRegistry.h"
+using namespace llvm;
+
+Target &llvm::getTheCSKYTarget() {
+ static Target TheCSKYTarget;
+ return TheCSKYTarget;
+}
+
+extern "C" void LLVMInitializeCSKYTargetInfo() {
+ RegisterTarget<Triple::csky> X(getTheCSKYTarget(), "csky", "C-SKY", "CSKY");
+}
+
+// FIXME: Temporary stub - this function must be defined for linking
+// to succeed and will be called unconditionally by llc, so must be a no-op.
+// Remove once this function is properly implemented.
+extern "C" void LLVMInitializeCSKYTargetMC() {}
diff --git a/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.h b/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.h
new file mode 100644
index 000000000000..c317c5401f03
--- /dev/null
+++ b/llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.h
@@ -0,0 +1,20 @@
+//===-- CSKYTargetInfo.cpp - CSKY Target Implementation -------------------===//
+//
+// 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_LIB_TARGET_CSKY_TARGETINFO_CSKYTARGETINFO_H
+#define LLVM_LIB_TARGET_CSKY_TARGETINFO_CSKYTARGETINFO_H
+
+namespace llvm {
+
+class Target;
+
+Target &getTheCSKYTarget();
+
+} // namespace llvm
+
+#endif // LLVM_LIB_TARGET_CSKY_TARGETINFO_CSKYTARGETINFO_H
diff --git a/llvm/lib/Target/CSKY/TargetInfo/LLVMBuild.txt b/llvm/lib/Target/CSKY/TargetInfo/LLVMBuild.txt
new file mode 100644
index 000000000000..2634816b9cfb
--- /dev/null
+++ b/llvm/lib/Target/CSKY/TargetInfo/LLVMBuild.txt
@@ -0,0 +1,22 @@
+;===-- ./lib/Target/CSKY/TargetInfo/LLVMBuild.txt --------------*- Conf -*--===;
+;
+; 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
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Library
+name = CSKYInfo
+parent = CSKY
+required_libraries = Support
+add_to_library_groups = CSKY
diff --git a/llvm/lib/Target/LLVMBuild.txt b/llvm/lib/Target/LLVMBuild.txt
index e5a9d787e7fa..d7570a18986b 100644
--- a/llvm/lib/Target/LLVMBuild.txt
+++ b/llvm/lib/Target/LLVMBuild.txt
@@ -24,6 +24,7 @@ subdirectories =
ARM
AVR
BPF
+ CSKY
Hexagon
Lanai
MSP430
More information about the llvm-commits
mailing list