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/MCAssembler.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/MC/TargetRegistry.h"
24 
25 #define GET_INSTRINFO_MC_DESC
26 #include "CSKYGenInstrInfo.inc"
27 
28 #define GET_REGINFO_MC_DESC
29 #include "CSKYGenRegisterInfo.inc"
30 
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "CSKYGenSubtargetInfo.inc"
33 
34 using namespace llvm;
35 
36 static MCAsmInfo *createCSKYMCAsmInfo(const MCRegisterInfo &MRI,
37                                       const Triple &TT,
38                                       const MCTargetOptions &Options) {
39   MCAsmInfo *MAI = new CSKYMCAsmInfo(TT);
40 
41   // Initial state of the frame pointer is SP.
42   unsigned Reg = MRI.getDwarfRegNum(CSKY::R14, true);
43   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 0);
44   MAI->addInitialFrameState(Inst);
45   return MAI;
46 }
47 
48 static MCInstrInfo *createCSKYMCInstrInfo() {
49   MCInstrInfo *Info = new MCInstrInfo();
50   InitCSKYMCInstrInfo(Info);
51   return Info;
52 }
53 
54 static MCInstPrinter *createCSKYMCInstPrinter(const Triple &T,
55                                               unsigned SyntaxVariant,
56                                               const MCAsmInfo &MAI,
57                                               const MCInstrInfo &MII,
58                                               const MCRegisterInfo &MRI) {
59   return new CSKYInstPrinter(MAI, MII, MRI);
60 }
61 
62 static MCRegisterInfo *createCSKYMCRegisterInfo(const Triple &TT) {
63   MCRegisterInfo *Info = new MCRegisterInfo();
64   InitCSKYMCRegisterInfo(Info, CSKY::R15);
65   return Info;
66 }
67 
68 static MCSubtargetInfo *createCSKYMCSubtargetInfo(const Triple &TT,
69                                                   StringRef CPU, StringRef FS) {
70   std::string CPUName = std::string(CPU);
71   if (CPUName.empty())
72     CPUName = "generic";
73   return createCSKYMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU=*/CPUName, FS);
74 }
75 
76 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTargetMC() {
77   auto &CSKYTarget = getTheCSKYTarget();
78   TargetRegistry::RegisterMCAsmBackend(CSKYTarget, createCSKYAsmBackend);
79   TargetRegistry::RegisterMCAsmInfo(CSKYTarget, createCSKYMCAsmInfo);
80   TargetRegistry::RegisterMCInstrInfo(CSKYTarget, createCSKYMCInstrInfo);
81   TargetRegistry::RegisterMCRegInfo(CSKYTarget, createCSKYMCRegisterInfo);
82   TargetRegistry::RegisterMCCodeEmitter(CSKYTarget, createCSKYMCCodeEmitter);
83   TargetRegistry::RegisterMCInstPrinter(CSKYTarget, createCSKYMCInstPrinter);
84   TargetRegistry::RegisterMCSubtargetInfo(CSKYTarget,
85                                           createCSKYMCSubtargetInfo);
86 }
87