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/CodeGen.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/FormattedStream.h"
27#include "llvm/Support/raw_ostream.h"
28
29using 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
41static MCInstrInfo *createXCoreMCInstrInfo() {
42 MCInstrInfo *X = new MCInstrInfo();
43 InitXCoreMCInstrInfo(II: X);
44 return X;
45}
46
47static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) {
48 MCRegisterInfo *X = new MCRegisterInfo();
49 InitXCoreMCRegisterInfo(RI: X, RA: XCore::LR);
50 return X;
51}
52
53static MCSubtargetInfo *
54createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
55 return createXCoreMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
56}
57
58static 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
70static 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
78XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
79
80XCoreTargetStreamer::~XCoreTargetStreamer() = default;
81
82namespace {
83
84class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
85 formatted_raw_ostream &OS;
86
87public:
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
98XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
99 formatted_raw_ostream &OS)
100 : XCoreTargetStreamer(S), OS(OS) {}
101
102void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
103 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
104}
105
106void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
107 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
108}
109
110void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
111 OS << "\t.cc_bottom " << Name << ".data\n";
112}
113
114void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
115 OS << "\t.cc_bottom " << Name << ".function\n";
116}
117
118static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
119 formatted_raw_ostream &OS,
120 MCInstPrinter *InstPrint) {
121 return new XCoreTargetAsmStreamer(S, OS);
122}
123
124static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
125 return new XCoreTargetStreamer(S);
126}
127
128// Force static initialization.
129extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXCoreTargetMC() {
130 // Register the MC asm info.
131 RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo);
132
133 // Register the MC instruction info.
134 TargetRegistry::RegisterMCInstrInfo(T&: getTheXCoreTarget(),
135 Fn: createXCoreMCInstrInfo);
136
137 // Register the MC register info.
138 TargetRegistry::RegisterMCRegInfo(T&: getTheXCoreTarget(),
139 Fn: createXCoreMCRegisterInfo);
140
141 // Register the MC subtarget info.
142 TargetRegistry::RegisterMCSubtargetInfo(T&: getTheXCoreTarget(),
143 Fn: createXCoreMCSubtargetInfo);
144
145 // Register the MCInstPrinter
146 TargetRegistry::RegisterMCInstPrinter(T&: getTheXCoreTarget(),
147 Fn: createXCoreMCInstPrinter);
148
149 TargetRegistry::RegisterAsmTargetStreamer(T&: getTheXCoreTarget(),
150 Fn: createTargetAsmStreamer);
151
152 TargetRegistry::RegisterNullTargetStreamer(T&: getTheXCoreTarget(),
153 Fn: createNullTargetStreamer);
154}
155