1 | //===-- SparcMCTargetDesc.cpp - Sparc 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 Sparc specific target descriptions. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "SparcMCTargetDesc.h" |
14 | #include "SparcInstPrinter.h" |
15 | #include "SparcMCAsmInfo.h" |
16 | #include "SparcTargetStreamer.h" |
17 | #include "TargetInfo/SparcTargetInfo.h" |
18 | #include "llvm/MC/MCInstrInfo.h" |
19 | #include "llvm/MC/MCRegisterInfo.h" |
20 | #include "llvm/MC/MCSubtargetInfo.h" |
21 | #include "llvm/MC/TargetRegistry.h" |
22 | #include "llvm/Support/ErrorHandling.h" |
23 | |
24 | namespace llvm { |
25 | namespace SparcASITag { |
26 | #define GET_ASITagsList_IMPL |
27 | #include "SparcGenSearchableTables.inc" |
28 | } // end namespace SparcASITag |
29 | |
30 | namespace SparcPrefetchTag { |
31 | #define GET_PrefetchTagsList_IMPL |
32 | #include "SparcGenSearchableTables.inc" |
33 | } // end namespace SparcPrefetchTag |
34 | } // end namespace llvm |
35 | |
36 | using namespace llvm; |
37 | |
38 | #define GET_INSTRINFO_MC_DESC |
39 | #define ENABLE_INSTR_PREDICATE_VERIFIER |
40 | #include "SparcGenInstrInfo.inc" |
41 | |
42 | #define GET_SUBTARGETINFO_MC_DESC |
43 | #include "SparcGenSubtargetInfo.inc" |
44 | |
45 | #define GET_REGINFO_MC_DESC |
46 | #include "SparcGenRegisterInfo.inc" |
47 | |
48 | static MCAsmInfo *createSparcMCAsmInfo(const MCRegisterInfo &MRI, |
49 | const Triple &TT, |
50 | const MCTargetOptions &Options) { |
51 | MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT); |
52 | unsigned Reg = MRI.getDwarfRegNum(RegNum: SP::O6, isEH: true); |
53 | MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(L: nullptr, Register: Reg, Offset: 0); |
54 | MAI->addInitialFrameState(Inst); |
55 | return MAI; |
56 | } |
57 | |
58 | static MCAsmInfo *createSparcV9MCAsmInfo(const MCRegisterInfo &MRI, |
59 | const Triple &TT, |
60 | const MCTargetOptions &Options) { |
61 | MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT); |
62 | unsigned Reg = MRI.getDwarfRegNum(RegNum: SP::O6, isEH: true); |
63 | MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(L: nullptr, Register: Reg, Offset: 2047); |
64 | MAI->addInitialFrameState(Inst); |
65 | return MAI; |
66 | } |
67 | |
68 | static MCInstrInfo *createSparcMCInstrInfo() { |
69 | MCInstrInfo *X = new MCInstrInfo(); |
70 | InitSparcMCInstrInfo(II: X); |
71 | return X; |
72 | } |
73 | |
74 | static MCRegisterInfo *createSparcMCRegisterInfo(const Triple &TT) { |
75 | MCRegisterInfo *X = new MCRegisterInfo(); |
76 | InitSparcMCRegisterInfo(RI: X, RA: SP::O7); |
77 | return X; |
78 | } |
79 | |
80 | static MCSubtargetInfo * |
81 | createSparcMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { |
82 | if (CPU.empty()) |
83 | CPU = (TT.getArch() == Triple::sparcv9) ? "v9" : "v8" ; |
84 | return createSparcMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); |
85 | } |
86 | |
87 | static MCTargetStreamer * |
88 | createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) { |
89 | return new SparcTargetELFStreamer(S); |
90 | } |
91 | |
92 | static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, |
93 | formatted_raw_ostream &OS, |
94 | MCInstPrinter *InstPrint) { |
95 | return new SparcTargetAsmStreamer(S, OS); |
96 | } |
97 | |
98 | static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) { |
99 | return new SparcTargetStreamer(S); |
100 | } |
101 | |
102 | static MCInstPrinter *createSparcMCInstPrinter(const Triple &T, |
103 | unsigned SyntaxVariant, |
104 | const MCAsmInfo &MAI, |
105 | const MCInstrInfo &MII, |
106 | const MCRegisterInfo &MRI) { |
107 | return new SparcInstPrinter(MAI, MII, MRI); |
108 | } |
109 | |
110 | extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcTargetMC() { |
111 | // Register the MC asm info. |
112 | RegisterMCAsmInfoFn X(getTheSparcTarget(), createSparcMCAsmInfo); |
113 | RegisterMCAsmInfoFn Y(getTheSparcV9Target(), createSparcV9MCAsmInfo); |
114 | RegisterMCAsmInfoFn Z(getTheSparcelTarget(), createSparcMCAsmInfo); |
115 | |
116 | for (Target *T : |
117 | {&getTheSparcTarget(), &getTheSparcV9Target(), &getTheSparcelTarget()}) { |
118 | // Register the MC instruction info. |
119 | TargetRegistry::RegisterMCInstrInfo(T&: *T, Fn: createSparcMCInstrInfo); |
120 | |
121 | // Register the MC register info. |
122 | TargetRegistry::RegisterMCRegInfo(T&: *T, Fn: createSparcMCRegisterInfo); |
123 | |
124 | // Register the MC subtarget info. |
125 | TargetRegistry::RegisterMCSubtargetInfo(T&: *T, Fn: createSparcMCSubtargetInfo); |
126 | |
127 | // Register the MC Code Emitter. |
128 | TargetRegistry::RegisterMCCodeEmitter(T&: *T, Fn: createSparcMCCodeEmitter); |
129 | |
130 | // Register the asm backend. |
131 | TargetRegistry::RegisterMCAsmBackend(T&: *T, Fn: createSparcAsmBackend); |
132 | |
133 | // Register the object target streamer. |
134 | TargetRegistry::RegisterObjectTargetStreamer(T&: *T, |
135 | Fn: createObjectTargetStreamer); |
136 | |
137 | // Register the asm streamer. |
138 | TargetRegistry::RegisterAsmTargetStreamer(T&: *T, Fn: createTargetAsmStreamer); |
139 | |
140 | // Register the null streamer. |
141 | TargetRegistry::RegisterNullTargetStreamer(T&: *T, Fn: createNullTargetStreamer); |
142 | |
143 | // Register the MCInstPrinter |
144 | TargetRegistry::RegisterMCInstPrinter(T&: *T, Fn: createSparcMCInstPrinter); |
145 | } |
146 | } |
147 | |