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 (RM == Reloc::Default) { 71 RM = Reloc::Static; 72 } 73 if (CM == CodeModel::Default) { 74 CM = CodeModel::Small; 75 } 76 if (CM != CodeModel::Small && CM != CodeModel::Large) 77 report_fatal_error("Target only supports CodeModel Small or Large"); 78 79 X->initMCCodeGenInfo(RM, CM, OL); 80 return X; 81 } 82 83 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T, 84 unsigned SyntaxVariant, 85 const MCAsmInfo &MAI, 86 const MCInstrInfo &MII, 87 const MCRegisterInfo &MRI) { 88 return new XCoreInstPrinter(MAI, MII, MRI); 89 } 90 91 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} 92 XCoreTargetStreamer::~XCoreTargetStreamer() {} 93 94 namespace { 95 96 class XCoreTargetAsmStreamer : public XCoreTargetStreamer { 97 formatted_raw_ostream &OS; 98 public: 99 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 100 void emitCCTopData(StringRef Name) override; 101 void emitCCTopFunction(StringRef Name) override; 102 void emitCCBottomData(StringRef Name) override; 103 void emitCCBottomFunction(StringRef Name) override; 104 }; 105 106 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S, 107 formatted_raw_ostream &OS) 108 : XCoreTargetStreamer(S), OS(OS) {} 109 110 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) { 111 OS << "\t.cc_top " << Name << ".data," << Name << '\n'; 112 } 113 114 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) { 115 OS << "\t.cc_top " << Name << ".function," << Name << '\n'; 116 } 117 118 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) { 119 OS << "\t.cc_bottom " << Name << ".data\n"; 120 } 121 122 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) { 123 OS << "\t.cc_bottom " << Name << ".function\n"; 124 } 125 } 126 127 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, 128 formatted_raw_ostream &OS, 129 MCInstPrinter *InstPrint, 130 bool isVerboseAsm) { 131 return new XCoreTargetAsmStreamer(S, OS); 132 } 133 134 // Force static initialization. 135 extern "C" void LLVMInitializeXCoreTargetMC() { 136 // Register the MC asm info. 137 RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo); 138 139 // Register the MC codegen info. 140 TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget, 141 createXCoreMCCodeGenInfo); 142 143 // Register the MC instruction info. 144 TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo); 145 146 // Register the MC register info. 147 TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo); 148 149 // Register the MC subtarget info. 150 TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget, 151 createXCoreMCSubtargetInfo); 152 153 // Register the MCInstPrinter 154 TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget, 155 createXCoreMCInstPrinter); 156 157 TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget, 158 createTargetAsmStreamer); 159 } 160