| 1 | //===-- XCoreMCTargetDesc.cpp - XCore 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 XCore specific target descriptions. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "MCTargetDesc/XCoreMCTargetDesc.h" |
| 14 | #include "MCTargetDesc/XCoreInstPrinter.h" |
| 15 | #include "MCTargetDesc/XCoreMCAsmInfo.h" |
| 16 | #include "TargetInfo/XCoreTargetInfo.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/MC/TargetRegistry.h" |
| 24 | #include "llvm/Support/Compiler.h" |
| 25 | #include "llvm/Support/ErrorHandling.h" |
| 26 | #include "llvm/Support/FormattedStream.h" |
| 27 | #include "llvm/Support/raw_ostream.h" |
| 28 | |
| 29 | using namespace llvm; |
| 30 | |
| 31 | #define GET_INSTRINFO_MC_DESC |
| 32 | #define ENABLE_INSTR_PREDICATE_VERIFIER |
| 33 | #include "XCoreGenInstrInfo.inc" |
| 34 | |
| 35 | #define GET_SUBTARGETINFO_MC_DESC |
| 36 | #include "XCoreGenSubtargetInfo.inc" |
| 37 | |
| 38 | #define GET_REGINFO_MC_DESC |
| 39 | #include "XCoreGenRegisterInfo.inc" |
| 40 | |
| 41 | static MCInstrInfo *createXCoreMCInstrInfo() { |
| 42 | MCInstrInfo *X = new MCInstrInfo(); |
| 43 | InitXCoreMCInstrInfo(II: X); |
| 44 | return X; |
| 45 | } |
| 46 | |
| 47 | static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) { |
| 48 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 49 | InitXCoreMCRegisterInfo(RI: X, RA: XCore::LR); |
| 50 | return X; |
| 51 | } |
| 52 | |
| 53 | static MCSubtargetInfo * |
| 54 | createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { |
| 55 | return createXCoreMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); |
| 56 | } |
| 57 | |
| 58 | static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI, |
| 59 | const Triple &TT, |
| 60 | const MCTargetOptions &Options) { |
| 61 | MCAsmInfo *MAI = new XCoreMCAsmInfo(TT); |
| 62 | |
| 63 | // Initial state of the frame pointer is SP. |
| 64 | MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(L: nullptr, Register: XCore::SP, Offset: 0); |
| 65 | MAI->addInitialFrameState(Inst); |
| 66 | |
| 67 | return MAI; |
| 68 | } |
| 69 | |
| 70 | static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T, |
| 71 | unsigned SyntaxVariant, |
| 72 | const MCAsmInfo &MAI, |
| 73 | const MCInstrInfo &MII, |
| 74 | const MCRegisterInfo &MRI) { |
| 75 | return new XCoreInstPrinter(MAI, MII, MRI); |
| 76 | } |
| 77 | |
| 78 | XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} |
| 79 | |
| 80 | XCoreTargetStreamer::~XCoreTargetStreamer() = default; |
| 81 | |
| 82 | namespace { |
| 83 | |
| 84 | class XCoreTargetAsmStreamer : public XCoreTargetStreamer { |
| 85 | formatted_raw_ostream &OS; |
| 86 | |
| 87 | public: |
| 88 | XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); |
| 89 | |
| 90 | void emitCCTopData(StringRef Name) override; |
| 91 | void emitCCTopFunction(StringRef Name) override; |
| 92 | void emitCCBottomData(StringRef Name) override; |
| 93 | void emitCCBottomFunction(StringRef Name) override; |
| 94 | }; |
| 95 | |
| 96 | } // end anonymous namespace |
| 97 | |
| 98 | XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S, |
| 99 | formatted_raw_ostream &OS) |
| 100 | : XCoreTargetStreamer(S), OS(OS) {} |
| 101 | |
| 102 | void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) { |
| 103 | OS << "\t.cc_top " << Name << ".data," << Name << '\n'; |
| 104 | } |
| 105 | |
| 106 | void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) { |
| 107 | OS << "\t.cc_top " << Name << ".function," << Name << '\n'; |
| 108 | } |
| 109 | |
| 110 | void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) { |
| 111 | OS << "\t.cc_bottom " << Name << ".data\n" ; |
| 112 | } |
| 113 | |
| 114 | void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) { |
| 115 | OS << "\t.cc_bottom " << Name << ".function\n" ; |
| 116 | } |
| 117 | |
| 118 | static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, |
| 119 | formatted_raw_ostream &OS, |
| 120 | MCInstPrinter *InstPrint) { |
| 121 | return new XCoreTargetAsmStreamer(S, OS); |
| 122 | } |
| 123 | |
| 124 | static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) { |
| 125 | return new XCoreTargetStreamer(S); |
| 126 | } |
| 127 | |
| 128 | // Force static initialization. |
| 129 | extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void |
| 130 | LLVMInitializeXCoreTargetMC() { |
| 131 | // Register the MC asm info. |
| 132 | RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo); |
| 133 | |
| 134 | // Register the MC instruction info. |
| 135 | TargetRegistry::RegisterMCInstrInfo(T&: getTheXCoreTarget(), |
| 136 | Fn: createXCoreMCInstrInfo); |
| 137 | |
| 138 | // Register the MC register info. |
| 139 | TargetRegistry::RegisterMCRegInfo(T&: getTheXCoreTarget(), |
| 140 | Fn: createXCoreMCRegisterInfo); |
| 141 | |
| 142 | // Register the MC subtarget info. |
| 143 | TargetRegistry::RegisterMCSubtargetInfo(T&: getTheXCoreTarget(), |
| 144 | Fn: createXCoreMCSubtargetInfo); |
| 145 | |
| 146 | // Register the MCInstPrinter |
| 147 | TargetRegistry::RegisterMCInstPrinter(T&: getTheXCoreTarget(), |
| 148 | Fn: createXCoreMCInstPrinter); |
| 149 | |
| 150 | TargetRegistry::RegisterAsmTargetStreamer(T&: getTheXCoreTarget(), |
| 151 | Fn: createTargetAsmStreamer); |
| 152 | |
| 153 | TargetRegistry::RegisterNullTargetStreamer(T&: getTheXCoreTarget(), |
| 154 | Fn: createNullTargetStreamer); |
| 155 | } |
| 156 | |