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,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 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 RM, + Optional 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()) { + 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