Index: llvm/CODE_OWNERS.TXT =================================================================== --- llvm/CODE_OWNERS.TXT +++ llvm/CODE_OWNERS.TXT @@ -232,3 +232,7 @@ N: Martin Storsjö E: martin@martin.st D: MinGW + +N: Zi Xuan Wu (Zeson) +E: zixuan.wu@linux.alibaba.com +D: C-SKY backend (lib/Target/CSKY/*) Index: llvm/docs/CompilerWriterInfo.rst =================================================================== --- llvm/docs/CompilerWriterInfo.rst +++ llvm/docs/CompilerWriterInfo.rst @@ -102,6 +102,11 @@ ------ * `RISC-V User-Level ISA Specification `_ +C-SKY +------ +* `C-SKY Architecture User Guide `_ +* `C-SKY V2 ABI `_ + SPARC ----- Index: llvm/lib/Target/CSKY/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/lib/Target/CSKY/CMakeLists.txt @@ -0,0 +1,5 @@ +add_llvm_target(CSKYCodeGen + CSKYTargetMachine.cpp + ) + +add_subdirectory(TargetInfo) Index: llvm/lib/Target/CSKY/CSKYTargetMachine.h =================================================================== --- /dev/null +++ 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 TLOF; + +public: + CSKYTargetMachine(const Target &T, const Triple &TT, StringRef CPU, + StringRef FS, const TargetOptions &Options, + Optional RM, Optional CM, + CodeGenOpt::Level OL, bool JIT); + + TargetPassConfig *createPassConfig(PassManagerBase &PM) override; + + TargetLoweringObjectFile *getObjFileLowering() const override { + return TLOF.get(); + } +}; +} // namespace llvm + +#endif Index: llvm/lib/Target/CSKY/CSKYTargetMachine.cpp =================================================================== --- /dev/null +++ llvm/lib/Target/CSKY/CSKYTargetMachine.cpp @@ -0,0 +1,105 @@ +//===--- 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 X(getTheCSKYTarget()); +} + +// Specifies how data is to be laid out in memory. +// The layout specification consists of a list of specifications separated by +// the minus sign character ('-'). +static std::string computeDataLayout(const Triple &TT) { + std::string Ret; + + // Specifies target lays out data in Big or Little endian form. + Ret += "e"; + + // S Specifies the natural alignment of the stack in bits. + Ret += "-S32"; + + Ret += DataLayout::getManglingComponent(TT); + + // p[n]:::: + // Specifies the size of a pointer and its and erred alignments + // for address space n. + Ret += "-p:32:32"; + // i:: + // This specifies the alignment for an integer type of a given bit . + Ret += "-i32:32:32"; + Ret += "-i64:32:32"; + // f:: + // This specifies the alignment for a floating-point type of a given bit + // . + Ret += "-f32:32:32"; + Ret += "-f64:32:32"; + // v:: + // This specifies the alignment for a vector type of a given bit . + Ret += "-v64:32:32"; + Ret += "-v128:32:32"; + // S Specifies the natural alignment of the stack in bits. + Ret += "-S32"; + // a:: This specifies the alignment for an object of aggregate + // type. + Ret += "-a:0:32"; + // F Specifies the alignment for function pointers. + Ret += "-Fi32"; + // n::... Specifies a set of native integer widths for + // target. + Ret += "-n32"; + + return Ret; +} + +static Reloc::Model getEffectiveRelocModel(const Triple &TT, + Optional RM) { + if (!RM.hasValue()) + return Reloc::Static; + return *RM; +} + +CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT, + StringRef CPU, StringRef FS, + const TargetOptions &Options, + Optional RM, + Optional CM, + CodeGenOpt::Level OL, bool JIT) + : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options, + getEffectiveRelocModel(TT, RM), + getEffectiveCodeModel(CM, CodeModel::Small), OL), + TLOF(std::make_unique()) { + initAsmInfo(); +} + +namespace { +class CSKYPassConfig : public TargetPassConfig { +public: + CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM) + : TargetPassConfig(TM, PM) {} + + CSKYTargetMachine &getCSKYTargetMachine() const { + return getTM(); + } +}; + +} // namespace + +TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) { + return new CSKYPassConfig(*this, PM); +} Index: llvm/lib/Target/CSKY/LLVMBuild.txt =================================================================== --- /dev/null +++ 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 Index: llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/lib/Target/CSKY/TargetInfo/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMCSKYInfo + CSKYTargetInfo.cpp + ) Index: llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.h =================================================================== --- /dev/null +++ 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 Index: llvm/lib/Target/CSKY/TargetInfo/CSKYTargetInfo.cpp =================================================================== --- /dev/null +++ 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 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() {} Index: llvm/lib/Target/CSKY/TargetInfo/LLVMBuild.txt =================================================================== --- /dev/null +++ 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 Index: llvm/lib/Target/LLVMBuild.txt =================================================================== --- llvm/lib/Target/LLVMBuild.txt +++ llvm/lib/Target/LLVMBuild.txt @@ -24,6 +24,7 @@ ARM AVR BPF + CSKY Hexagon Lanai MSP430