1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides XCore specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/XCoreMCTargetDesc.h"
15 #include "InstPrinter/XCoreInstPrinter.h"
16 #include "MCTargetDesc/XCoreMCAsmInfo.h"
17 #include "XCoreTargetStreamer.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/MCDwarf.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Support/CodeGen.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/FormattedStream.h"
26 #include "llvm/Support/TargetRegistry.h"
27 #include "llvm/Support/raw_ostream.h"
31 #define GET_INSTRINFO_MC_DESC
32 #include "XCoreGenInstrInfo.inc"
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "XCoreGenSubtargetInfo.inc"
37 #define GET_REGINFO_MC_DESC
38 #include "XCoreGenRegisterInfo.inc"
40 static MCInstrInfo *createXCoreMCInstrInfo() {
41 MCInstrInfo *X = new MCInstrInfo();
42 InitXCoreMCInstrInfo(X);
46 static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) {
47 MCRegisterInfo *X = new MCRegisterInfo();
48 InitXCoreMCRegisterInfo(X, XCore::LR);
52 static MCSubtargetInfo *
53 createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
54 return createXCoreMCSubtargetInfoImpl(TT, CPU, FS);
57 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
59 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
61 // Initial state of the frame pointer is SP.
62 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
63 MAI->addInitialFrameState(Inst);
68 static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
69 CodeModel::Model &CM) {
70 if (CM == CodeModel::Default) {
71 CM = CodeModel::Small;
73 if (CM != CodeModel::Small && CM != CodeModel::Large)
74 report_fatal_error("Target only supports CodeModel Small or Large");
77 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T,
78 unsigned SyntaxVariant,
80 const MCInstrInfo &MII,
81 const MCRegisterInfo &MRI) {
82 return new XCoreInstPrinter(MAI, MII, MRI);
85 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
87 XCoreTargetStreamer::~XCoreTargetStreamer() = default;
91 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
92 formatted_raw_ostream &OS;
95 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
97 void emitCCTopData(StringRef Name) override;
98 void emitCCTopFunction(StringRef Name) override;
99 void emitCCBottomData(StringRef Name) override;
100 void emitCCBottomFunction(StringRef Name) override;
103 } // end anonymous namespace
105 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
106 formatted_raw_ostream &OS)
107 : XCoreTargetStreamer(S), OS(OS) {}
109 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
110 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
113 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
114 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
117 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
118 OS << "\t.cc_bottom " << Name << ".data\n";
121 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
122 OS << "\t.cc_bottom " << Name << ".function\n";
125 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
126 formatted_raw_ostream &OS,
127 MCInstPrinter *InstPrint,
129 return new XCoreTargetAsmStreamer(S, OS);
132 // Force static initialization.
133 extern "C" void LLVMInitializeXCoreTargetMC() {
134 // Register the MC asm info.
135 RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo);
137 // Register the MC codegen info.
138 TargetRegistry::registerMCAdjustCodeGenOpts(getTheXCoreTarget(),
141 // Register the MC instruction info.
142 TargetRegistry::RegisterMCInstrInfo(getTheXCoreTarget(),
143 createXCoreMCInstrInfo);
145 // Register the MC register info.
146 TargetRegistry::RegisterMCRegInfo(getTheXCoreTarget(),
147 createXCoreMCRegisterInfo);
149 // Register the MC subtarget info.
150 TargetRegistry::RegisterMCSubtargetInfo(getTheXCoreTarget(),
151 createXCoreMCSubtargetInfo);
153 // Register the MCInstPrinter
154 TargetRegistry::RegisterMCInstPrinter(getTheXCoreTarget(),
155 createXCoreMCInstPrinter);
157 TargetRegistry::RegisterAsmTargetStreamer(getTheXCoreTarget(),
158 createTargetAsmStreamer);