[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
This commit is contained in:
Zi Xuan Wu 2020-09-29 12:31:36 +08:00
parent 2bd4730850
commit e1c38dd55d
11 changed files with 221 additions and 0 deletions

View File

@ -232,3 +232,7 @@ D: llvm-objcopy (tools/llvm-objcopy)
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/*)

View File

@ -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
-----

View File

@ -0,0 +1,5 @@
add_llvm_target(CSKYCodeGen
CSKYTargetMachine.cpp
)
add_subdirectory(TargetInfo)

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
add_llvm_library(LLVMCSKYInfo
CSKYTargetInfo.cpp
)

View File

@ -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() {}

View File

@ -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

View File

@ -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

View File

@ -24,6 +24,7 @@ subdirectories =
ARM
AVR
BPF
CSKY
Hexagon
Lanai
MSP430