1 //===-- CSKYMCTargetDesc.cpp - CSKY Target Descriptions -------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// This file provides CSKY specific target descriptions.
11 //===----------------------------------------------------------------------===//
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/Support/TargetRegistry.h"
24 #define GET_INSTRINFO_MC_DESC
25 #include "CSKYGenInstrInfo.inc"
27 #define GET_REGINFO_MC_DESC
28 #include "CSKYGenRegisterInfo.inc"
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "CSKYGenSubtargetInfo.inc"
35 static MCAsmInfo
*createCSKYMCAsmInfo(const MCRegisterInfo
&MRI
,
37 const MCTargetOptions
&Options
) {
38 MCAsmInfo
*MAI
= new CSKYMCAsmInfo(TT
);
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
);
47 static MCInstrInfo
*createCSKYMCInstrInfo() {
48 MCInstrInfo
*Info
= new MCInstrInfo();
49 InitCSKYMCInstrInfo(Info
);
53 static MCInstPrinter
*createCSKYMCInstPrinter(const Triple
&T
,
54 unsigned SyntaxVariant
,
56 const MCInstrInfo
&MII
,
57 const MCRegisterInfo
&MRI
) {
58 return new CSKYInstPrinter(MAI
, MII
, MRI
);
61 static MCRegisterInfo
*createCSKYMCRegisterInfo(const Triple
&TT
) {
62 MCRegisterInfo
*Info
= new MCRegisterInfo();
63 InitCSKYMCRegisterInfo(Info
, CSKY::R15
);
67 static MCSubtargetInfo
*createCSKYMCSubtargetInfo(const Triple
&TT
,
68 StringRef CPU
, StringRef FS
) {
69 std::string CPUName
= std::string(CPU
);
72 return createCSKYMCSubtargetInfoImpl(TT
, CPUName
, /*TuneCPU=*/CPUName
, FS
);
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
);