1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file provides XCore specific target descriptions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "XCoreMCTargetDesc.h" 15 #include "InstPrinter/XCoreInstPrinter.h" 16 #include "XCoreMCAsmInfo.h" 17 #include "XCoreTargetStreamer.h" 18 #include "llvm/MC/MCCodeGenInfo.h" 19 #include "llvm/MC/MCInstrInfo.h" 20 #include "llvm/MC/MCRegisterInfo.h" 21 #include "llvm/MC/MCSubtargetInfo.h" 22 #include "llvm/Support/ErrorHandling.h" 23 #include "llvm/Support/FormattedStream.h" 24 #include "llvm/Support/TargetRegistry.h" 25 26 using namespace llvm; 27 28 #define GET_INSTRINFO_MC_DESC 29 #include "XCoreGenInstrInfo.inc" 30 31 #define GET_SUBTARGETINFO_MC_DESC 32 #include "XCoreGenSubtargetInfo.inc" 33 34 #define GET_REGINFO_MC_DESC 35 #include "XCoreGenRegisterInfo.inc" 36 37 static MCInstrInfo *createXCoreMCInstrInfo() { 38 MCInstrInfo *X = new MCInstrInfo(); 39 InitXCoreMCInstrInfo(X); 40 return X; 41 } 42 43 static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) { 44 MCRegisterInfo *X = new MCRegisterInfo(); 45 InitXCoreMCRegisterInfo(X, XCore::LR); 46 return X; 47 } 48 49 static MCSubtargetInfo * 50 createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { 51 return createXCoreMCSubtargetInfoImpl(TT, CPU, FS); 52 } 53 54 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI, 55 const Triple &TT) { 56 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT); 57 58 // Initial state of the frame pointer is SP. 59 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0); 60 MAI->addInitialFrameState(Inst); 61 62 return MAI; 63 } 64 65 static MCCodeGenInfo *createXCoreMCCodeGenInfo(const Triple &TT, 66 Reloc::Model RM, 67 CodeModel::Model CM, 68 CodeGenOpt::Level OL) { 69 MCCodeGenInfo *X = new MCCodeGenInfo(); 70 if (CM == CodeModel::Default) { 71 CM = CodeModel::Small; 72 } 73 if (CM != CodeModel::Small && CM != CodeModel::Large) 74 report_fatal_error("Target only supports CodeModel Small or Large"); 75 76 X->initMCCodeGenInfo(RM, CM, OL); 77 return X; 78 } 79 80 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T, 81 unsigned SyntaxVariant, 82 const MCAsmInfo &MAI, 83 const MCInstrInfo &MII, 84 const MCRegisterInfo &MRI) { 85 return new XCoreInstPrinter(MAI, MII, MRI); 86 } 87 88 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} 89 XCoreTargetStreamer::~XCoreTargetStreamer() {} 90 91 namespace { 92 93 class XCoreTargetAsmStreamer : public XCoreTargetStreamer { 94 formatted_raw_ostream &OS; 95 public: 96 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; 101 }; 102 103 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S, 104 formatted_raw_ostream &OS) 105 : XCoreTargetStreamer(S), OS(OS) {} 106 107 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) { 108 OS << "\t.cc_top " << Name << ".data," << Name << '\n'; 109 } 110 111 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) { 112 OS << "\t.cc_top " << Name << ".function," << Name << '\n'; 113 } 114 115 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) { 116 OS << "\t.cc_bottom " << Name << ".data\n"; 117 } 118 119 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) { 120 OS << "\t.cc_bottom " << Name << ".function\n"; 121 } 122 } 123 124 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, 125 formatted_raw_ostream &OS, 126 MCInstPrinter *InstPrint, 127 bool isVerboseAsm) { 128 return new XCoreTargetAsmStreamer(S, OS); 129 } 130 131 // Force static initialization. 132 extern "C" void LLVMInitializeXCoreTargetMC() { 133 // Register the MC asm info. 134 RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo); 135 136 // Register the MC codegen info. 137 TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget, 138 createXCoreMCCodeGenInfo); 139 140 // Register the MC instruction info. 141 TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo); 142 143 // Register the MC register info. 144 TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo); 145 146 // Register the MC subtarget info. 147 TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget, 148 createXCoreMCSubtargetInfo); 149 150 // Register the MCInstPrinter 151 TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget, 152 createXCoreMCInstPrinter); 153 154 TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget, 155 createTargetAsmStreamer); 156 } 157