1 //===-- CSKYMCTargetDesc.cpp - CSKY Target Descriptions -------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// This file provides CSKY specific target descriptions. 10 /// 11 //===----------------------------------------------------------------------===// 12 13 #include "CSKYMCTargetDesc.h" 14 #include "CSKYAsmBackend.h" 15 #include "CSKYInstPrinter.h" 16 #include "CSKYMCAsmInfo.h" 17 #include "CSKYMCCodeEmitter.h" 18 #include "TargetInfo/CSKYTargetInfo.h" 19 #include "llvm/MC/MCInstrInfo.h" 20 #include "llvm/MC/MCRegisterInfo.h" 21 #include "llvm/MC/MCSubtargetInfo.h" 22 #include "llvm/MC/TargetRegistry.h" 23 24 #define GET_INSTRINFO_MC_DESC 25 #include "CSKYGenInstrInfo.inc" 26 27 #define GET_REGINFO_MC_DESC 28 #include "CSKYGenRegisterInfo.inc" 29 30 #define GET_SUBTARGETINFO_MC_DESC 31 #include "CSKYGenSubtargetInfo.inc" 32 33 using namespace llvm; 34 35 static MCAsmInfo *createCSKYMCAsmInfo(const MCRegisterInfo &MRI, 36 const Triple &TT, 37 const MCTargetOptions &Options) { 38 MCAsmInfo *MAI = new CSKYMCAsmInfo(TT); 39 40 // Initial state of the frame pointer is SP. 41 unsigned Reg = MRI.getDwarfRegNum(CSKY::R14, true); 42 MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 0); 43 MAI->addInitialFrameState(Inst); 44 return MAI; 45 } 46 47 static MCInstrInfo *createCSKYMCInstrInfo() { 48 MCInstrInfo *Info = new MCInstrInfo(); 49 InitCSKYMCInstrInfo(Info); 50 return Info; 51 } 52 53 static MCInstPrinter *createCSKYMCInstPrinter(const Triple &T, 54 unsigned SyntaxVariant, 55 const MCAsmInfo &MAI, 56 const MCInstrInfo &MII, 57 const MCRegisterInfo &MRI) { 58 return new CSKYInstPrinter(MAI, MII, MRI); 59 } 60 61 static MCRegisterInfo *createCSKYMCRegisterInfo(const Triple &TT) { 62 MCRegisterInfo *Info = new MCRegisterInfo(); 63 InitCSKYMCRegisterInfo(Info, CSKY::R15); 64 return Info; 65 } 66 67 static MCSubtargetInfo *createCSKYMCSubtargetInfo(const Triple &TT, 68 StringRef CPU, StringRef FS) { 69 std::string CPUName = std::string(CPU); 70 if (CPUName.empty()) 71 CPUName = "generic"; 72 return createCSKYMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU=*/CPUName, FS); 73 } 74 75 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTargetMC() { 76 auto &CSKYTarget = getTheCSKYTarget(); 77 TargetRegistry::RegisterMCAsmBackend(CSKYTarget, createCSKYAsmBackend); 78 TargetRegistry::RegisterMCAsmInfo(CSKYTarget, createCSKYMCAsmInfo); 79 TargetRegistry::RegisterMCInstrInfo(CSKYTarget, createCSKYMCInstrInfo); 80 TargetRegistry::RegisterMCRegInfo(CSKYTarget, createCSKYMCRegisterInfo); 81 TargetRegistry::RegisterMCCodeEmitter(CSKYTarget, createCSKYMCCodeEmitter); 82 TargetRegistry::RegisterMCInstPrinter(CSKYTarget, createCSKYMCInstPrinter); 83 TargetRegistry::RegisterMCSubtargetInfo(CSKYTarget, 84 createCSKYMCSubtargetInfo); 85 } 86