Index: lib/Target/NDS32/CMakeLists.txt =================================================================== --- lib/Target/NDS32/CMakeLists.txt +++ lib/Target/NDS32/CMakeLists.txt @@ -3,6 +3,7 @@ tablegen(LLVM NDS32GenRegisterInfo.inc -gen-register-info) tablegen(LLVM NDS32GenInstrInfo.inc -gen-instr-info) tablegen(LLVM NDS32GenCallingConv.inc -gen-callingconv) +tablegen(LLVM NDS32GenSubtargetInfo.inc -gen-subtarget) add_public_tablegen_target(NDS32CommonTableGen) @@ -10,3 +11,6 @@ add_llvm_target(NDS32CodeGen NDS32TargetMachine.cpp ) + +add_subdirectory(TargetInfo) +add_subdirectory(MCTargetDesc) Index: lib/Target/NDS32/LLVMBuild.txt =================================================================== --- lib/Target/NDS32/LLVMBuild.txt +++ lib/Target/NDS32/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = TargetInfo +subdirectories = TargetInfo MCTargetDesc [component_0] type = TargetGroup @@ -27,5 +27,5 @@ type = Library name = NDS32CodeGen parent = NDS32 -required_libraries = CodeGen Core NDS32Info Support Target +required_libraries = CodeGen Core NDS32Info NDS32Desc Support Target add_to_library_groups = NDS32 Index: lib/Target/NDS32/MCTargetDesc/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,4 @@ +add_llvm_library(LLVMNDS32Desc + NDS32MCTargetDesc.cpp + NDS32MCAsmInfo.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/NDS32MCAsmInfo.h =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCAsmInfo.h @@ -0,0 +1,31 @@ +//===-- NDS32MCAsmInfo.h - NDS32 asm properties --------------*- 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 declaration of the NDS32MCAsmInfo class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NDS32_MCTARGETDESC_NDS32MCASMINFO_H +#define LLVM_LIB_TARGET_NDS32_MCTARGETDESC_NDS32MCASMINFO_H + +#include "llvm/MC/MCAsmInfoELF.h" + +namespace llvm { +class Triple; + +class NDS32MCAsmInfo : public MCAsmInfoELF { + void anchor() override; + +public: + explicit NDS32MCAsmInfo(const Triple &TT); +}; + +} // namespace llvm + +#endif Index: lib/Target/NDS32/MCTargetDesc/NDS32MCAsmInfo.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCAsmInfo.cpp @@ -0,0 +1,31 @@ +//===-- NDS32MCAsmInfo.cpp - NDS32 asm properties -------------------------===// +// +// 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 declarations of the NDS32MCAsmInfo properties. +// +//===----------------------------------------------------------------------===// + +#include "NDS32MCAsmInfo.h" +using namespace llvm; + +void NDS32MCAsmInfo::anchor() { } + +NDS32MCAsmInfo::NDS32MCAsmInfo(const Triple &TT) { + PointerSize = CalleeSaveStackSlotSize = 4; + + CommentString = "!"; + + AlignmentIsInBytes = false; + UsesELFSectionDirectiveForBSS = true; + + SupportsDebugInformation = true; + ExceptionsType = ExceptionHandling::DwarfCFI; + DwarfRegNumForCFI = true; + UseIntegratedAssembler = true; +} Index: lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.h =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.h @@ -0,0 +1,49 @@ +//===-- 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 StringRef; +class Target; +class Triple; +class raw_ostream; +class raw_pwrite_stream; + +extern Target TheNDS32Target; + +} // End llvm namespace + +// Defines symbolic names for NDS32 registers. +// This defines a mapping from register name to register number. +#define GET_REGINFO_ENUM +#include "NDS32GenRegisterInfo.inc" + +// Defines symbolic names for the NDS32 instructions. +#define GET_INSTRINFO_ENUM +#include "NDS32GenInstrInfo.inc" + +#define GET_SUBTARGETINFO_ENUM +#include "NDS32GenSubtargetInfo.inc" + +#endif Index: lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/MCTargetDesc/NDS32MCTargetDesc.cpp @@ -0,0 +1,74 @@ +//===-- 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 "NDS32MCAsmInfo.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/Support/TargetRegistry.h" + +using namespace llvm; + +#define GET_INSTRINFO_MC_DESC +#include "NDS32GenInstrInfo.inc" + +#define GET_SUBTARGETINFO_MC_DESC +#include "NDS32GenSubtargetInfo.inc" + +#define GET_REGINFO_MC_DESC +#include "NDS32GenRegisterInfo.inc" + +static MCInstrInfo *createNDS32MCInstrInfo() { + MCInstrInfo *X = new MCInstrInfo(); + InitNDS32MCInstrInfo(X); + return X; +} + +static MCRegisterInfo *createNDS32MCRegisterInfo(const Triple &TT) { + MCRegisterInfo *X = new MCRegisterInfo(); + InitNDS32MCRegisterInfo(X, NDS32::LP); + return X; +} + +static MCAsmInfo *createNDS32MCAsmInfo(const MCRegisterInfo &MRI, + const Triple &TT) { + MCAsmInfo *MAI = new NDS32MCAsmInfo(TT); + + unsigned SP = MRI.getDwarfRegNum(NDS32::SP, true); + MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0); + MAI->addInitialFrameState(Inst); + + return MAI; +} + +static MCSubtargetInfo * +createNDS32MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { + return createNDS32MCSubtargetInfoImpl(TT, CPU, FS); +} + +extern "C" void LLVMInitializeNDS32TargetMC() { + // Register the MC asm info. + RegisterMCAsmInfoFn X(TheNDS32Target, createNDS32MCAsmInfo); + + // Register the MC instruction info. + TargetRegistry::RegisterMCInstrInfo(TheNDS32Target, createNDS32MCInstrInfo); + + // Register the MC register info. + TargetRegistry::RegisterMCRegInfo(TheNDS32Target, + createNDS32MCRegisterInfo); + + // Register the MC subtarget info. + TargetRegistry::RegisterMCSubtargetInfo(TheNDS32Target, + createNDS32MCSubtargetInfo); +} Index: lib/Target/NDS32/NDS32.h =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32.h @@ -0,0 +1,26 @@ +//==-- 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/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,20 @@ +//===-- 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::TheNDS32Target; + +extern "C" void LLVMInitializeNDS32TargetInfo() { + RegisterTarget + X(TheNDS32Target, "nds32", "NDS32 [experimental]"); +}