Index: CODE_OWNERS.TXT =================================================================== --- CODE_OWNERS.TXT +++ CODE_OWNERS.TXT @@ -155,6 +155,10 @@ E: jpienaar@google.com D: Lanai Backend +N: Shiva Chen +E: shiva0217@gmail.com +D: NDS32 backend (lib/Target/NDS32/*) + N: Paul Robinson E: paul_robinson@playstation.sony.com D: Sony PlayStation®4 support Index: docs/CompilerWriterInfo.rst =================================================================== --- docs/CompilerWriterInfo.rst +++ docs/CompilerWriterInfo.rst @@ -114,6 +114,11 @@ * `The XMOS XS1 Architecture (ISA) `_ * `Tools Development Guide (includes ABI) `_ +NDS32 +------ +* `AndeStar ISA Manual (V3 ISA) `_ +* NOTE: This is an experimental porting of LLVM for AndeStar V3 ISA (NDS32 V3) of Andes Technology Corporation. Function-wise, correct code sequence is generated and it has passed key test suites. Performance-wise, there is NO target-specific optimization yet. + Hexagon ------- Index: lib/Target/LLVMBuild.txt =================================================================== --- lib/Target/LLVMBuild.txt +++ lib/Target/LLVMBuild.txt @@ -28,6 +28,7 @@ Hexagon MSP430 NVPTX + NDS32 Mips PowerPC RISCV Index: lib/Target/NDS32/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/CMakeLists.txt @@ -0,0 +1,6 @@ +add_llvm_target(NDS32CodeGen + NDS32TargetMachine.cpp + ) + +add_subdirectory(TargetInfo) +add_subdirectory(MCTargetDesc) Index: lib/Target/NDS32/LLVMBuild.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/LLVMBuild.txt @@ -0,0 +1,31 @@ +;===- ./lib/Target/NDS32/LLVMBuild.txt ------------------------*- Conf -*---===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; 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 MCTargetDesc + +[component_0] +type = TargetGroup +name = NDS32 +parent = Target + +[component_1] +type = Library +name = NDS32CodeGen +parent = NDS32 +required_libraries = CodeGen Core Support Target NDS32Info NDS32Desc +add_to_library_groups = NDS32 Index: lib/Target/NDS32/MCTargetDesc/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMNDS32Desc + NDS32MCTargetDesc.cpp + ) Index: lib/Target/NDS32/MCTargetDesc/LLVMBuild.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/NDS32/MCTargetDesc/LLVMBuild.txt -----------*- Conf -*---===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; 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 = NDS32Desc +parent = NDS32 +required_libraries = MC NDS32Info Support +add_to_library_groups = NDS32 Index: lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.h =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.h @@ -0,0 +1,38 @@ +//===-- NDS32MCTargetDesc.h - NDS32 Target Descriptions -------*- C++ -*---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides NDS32 specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NDS32_MCTARGETDESC_NDS32MCTARGETDESC_H +#define LLVM_LIB_TARGET_NDS32_MCTARGETDESC_NDS32MCTARGETDESC_H + +#include "llvm/Support/DataTypes.h" + +namespace llvm { +class MCAsmBackend; +class MCCodeEmitter; +class MCContext; +class MCInstrInfo; +class MCObjectWriter; +class MCRegisterInfo; +class MCSubtargetInfo; +class MCTargetOptions; +class StringRef; +class Target; +class Triple; +class raw_ostream; +class raw_pwrite_stream; + +Target &getTheNDS32Target(); + +} // End llvm namespace + +#endif Index: lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.cpp @@ -0,0 +1,23 @@ +//===-- NDS32MCTargetDesc.cpp - NDS32 Target Descriptions -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides NDS32 specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "NDS32MCTargetDesc.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/Support/TargetRegistry.h" + +using namespace llvm; + +extern "C" void LLVMInitializeNDS32TargetMC() { +} Index: lib/Target/NDS32/NDS32.h =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32.h @@ -0,0 +1,27 @@ +//==-- NDS32.h - Top-level interface for NDS32 representation --*- C++ -*---==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the entry points for global functions defined in +// the LLVM NDS32 backend. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NDS32_NDS32_H +#define LLVM_LIB_TARGET_NDS32_NDS32_H + +#include "MCTargetDesc/NDS32MCTargetDesc.h" +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + class NDS32TargetMachine; + class FunctionPass; + +} // end namespace llvm; + +#endif Index: lib/Target/NDS32/NDS32TargetMachine.h =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32TargetMachine.h @@ -0,0 +1,47 @@ +//===-- NDS32TargetMachine.h - Define TargetMachine for NDS32 -*- C++ -*---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares the NDS32 specific subclass of TargetMachine. +// +//===----------------------------------------------------------------------===// + + +#ifndef LLVM_LIB_TARGET_NDS32_NDS32TARGETMACHINE_H +#define LLVM_LIB_TARGET_NDS32_NDS32TARGETMACHINE_H + +#include "llvm/Target/TargetFrameLowering.h" +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +/// NDS32TargetMachine +/// +class NDS32TargetMachine : public LLVMTargetMachine { + +protected: + std::unique_ptr TLOF; + + +public: + NDS32TargetMachine(const Target &T, const Triple &TT, StringRef CPU, + StringRef FS, const TargetOptions &Options, + Optional RM, CodeModel::Model CM, + CodeGenOpt::Level OL); + ~NDS32TargetMachine() override; + + TargetPassConfig *createPassConfig(PassManagerBase &PM) override; + + TargetLoweringObjectFile *getObjFileLowering() const override { + return TLOF.get(); + } +}; // NDS32TargetMachine. + +} // end namespace llvm + +#endif Index: lib/Target/NDS32/NDS32TargetMachine.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32TargetMachine.cpp @@ -0,0 +1,100 @@ +//===-- NDS32TargetMachine.cpp - Define TargetMachine for NDS32 -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Top-level implementation for the NDS32 target. +// +//===----------------------------------------------------------------------===// + +#include "NDS32TargetMachine.h" +#include "NDS32.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" +#include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +#define DEBUG_TYPE "nds32" + +extern "C" void LLVMInitializeNDS32Target() { + // Register the target. + RegisterTargetMachine X(getTheNDS32Target()); +} + +static Reloc::Model getEffectiveRelocModel(Optional RM) { + if (!RM.hasValue()) + return Reloc::Static; + return *RM; +} + +static std::string computeDataLayout(const Triple &TT, StringRef CPU, + const TargetOptions &Options, + bool isLittle) { + std::string Ret = ""; + + if (isLittle) + // Little endian. + Ret += "e"; + else + // Big endian. + Ret += "E"; + + //ELF mangling of names is enabled + Ret += "-m:e"; + + // Pointers are 32 bits and aligned to 32 bits. + Ret += "-p:32:32"; + + // 64 bit integers with natural alignment. + Ret += "-i64:64"; + + // Try to align aggregates to 32 bits + Ret += "-a:0:32"; + + // Integer registers are 32 bits. + Ret += "-n32"; + + // The stack is 64 bit aligned + Ret += "-S64"; + + return Ret; +} + +NDS32TargetMachine::NDS32TargetMachine(const Target &T, const Triple &TT, + StringRef CPU, StringRef FS, + const TargetOptions &Options, + Optional RM, + CodeModel::Model CM, + CodeGenOpt::Level OL) + : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, true), + TT, CPU, FS, Options, getEffectiveRelocModel(RM), + CM, OL), + TLOF(make_unique()) { + initAsmInfo(); +} + +NDS32TargetMachine::~NDS32TargetMachine() {} + +namespace { +/// NDS32 Code Generator Pass Configuration Options. +class NDS32PassConfig : public TargetPassConfig { +public: + NDS32PassConfig(NDS32TargetMachine *TM, PassManagerBase &PM) + : TargetPassConfig(TM, PM) {} + + NDS32TargetMachine &getNDS32TargetMachine() const { + return getTM(); + } +}; +} // namespace + +TargetPassConfig *NDS32TargetMachine::createPassConfig(PassManagerBase &PM) { + return new NDS32PassConfig(this, PM); +} Index: lib/Target/NDS32/TargetInfo/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/TargetInfo/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMNDS32Info + NDS32TargetInfo.cpp + ) Index: lib/Target/NDS32/TargetInfo/LLVMBuild.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/TargetInfo/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/NDS32/TargetInfo/LLVMBuild.txt -------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; 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 = NDS32Info +parent = NDS32 +required_libraries = Support +add_to_library_groups = NDS32 Index: lib/Target/NDS32/TargetInfo/NDS32TargetInfo.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/TargetInfo/NDS32TargetInfo.cpp @@ -0,0 +1,23 @@ +//===-- NDS32TargetInfo.cpp - NDS32 Target Implementation -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "NDS32.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +Target &llvm::getTheNDS32Target() { + static Target TheNDS32Target; + return TheNDS32Target; +} + +extern "C" void LLVMInitializeNDS32TargetInfo() { + RegisterTarget + X(getTheNDS32Target(), "nds32", "NDS32 [experimental]"); +}