blob: 6cab226628ef8717b77fede26c5852d2adb0a112 [file] [log] [blame]
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001//===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
11#define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
Rafael Espindolaa17151a2013-10-08 13:08:17 +000012
Chandler Carruthd9903882015-01-14 11:23:27 +000013#include "MCTargetDesc/MipsABIFlagsSection.h"
Eric Christophera5762812015-01-26 17:33:46 +000014#include "MCTargetDesc/MipsABIInfo.h"
Simon Atanasyan4d45c762015-09-14 11:18:03 +000015#include "llvm/ADT/Optional.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000016#include "llvm/MC/MCELFStreamer.h"
Daniel Sandersd97a6342014-08-13 10:07:34 +000017#include "llvm/MC/MCRegisterInfo.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000018#include "llvm/MC/MCStreamer.h"
19
20namespace llvm {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000021
Daniel Sanders324ad952014-07-08 13:13:42 +000022struct MipsABIFlagsSection;
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000023
Rafael Espindolaa17151a2013-10-08 13:08:17 +000024class MipsTargetStreamer : public MCTargetStreamer {
Rafael Espindolaa17151a2013-10-08 13:08:17 +000025public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +000026 MipsTargetStreamer(MCStreamer &S);
Rafael Espindola60890b82014-06-23 19:43:40 +000027 virtual void emitDirectiveSetMicroMips();
28 virtual void emitDirectiveSetNoMicroMips();
29 virtual void emitDirectiveSetMips16();
30 virtual void emitDirectiveSetNoMips16();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +000031
Rafael Espindola60890b82014-06-23 19:43:40 +000032 virtual void emitDirectiveSetReorder();
33 virtual void emitDirectiveSetNoReorder();
34 virtual void emitDirectiveSetMacro();
35 virtual void emitDirectiveSetNoMacro();
Daniel Sanders44934432014-08-07 12:03:36 +000036 virtual void emitDirectiveSetMsa();
37 virtual void emitDirectiveSetNoMsa();
Rafael Espindola60890b82014-06-23 19:43:40 +000038 virtual void emitDirectiveSetAt();
Toma Tabacu16a74492015-02-13 10:30:57 +000039 virtual void emitDirectiveSetAtWithArg(unsigned RegNo);
Rafael Espindola60890b82014-06-23 19:43:40 +000040 virtual void emitDirectiveSetNoAt();
41 virtual void emitDirectiveEnd(StringRef Name);
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +000042
Rafael Espindola60890b82014-06-23 19:43:40 +000043 virtual void emitDirectiveEnt(const MCSymbol &Symbol);
44 virtual void emitDirectiveAbiCalls();
45 virtual void emitDirectiveNaN2008();
46 virtual void emitDirectiveNaNLegacy();
47 virtual void emitDirectiveOptionPic0();
48 virtual void emitDirectiveOptionPic2();
Toma Tabacu9ca50962015-04-16 09:53:47 +000049 virtual void emitDirectiveInsn();
Rafael Espindola054234f2014-01-27 03:53:56 +000050 virtual void emitFrame(unsigned StackReg, unsigned StackSize,
Rafael Espindola60890b82014-06-23 19:43:40 +000051 unsigned ReturnReg);
52 virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
53 virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
Vladimir Medic615b26e2014-03-04 09:54:09 +000054
Toma Tabacu85618b32014-08-19 14:22:52 +000055 virtual void emitDirectiveSetArch(StringRef Arch);
Toma Tabacu26647792014-09-09 12:52:14 +000056 virtual void emitDirectiveSetMips0();
Daniel Sandersf0df2212014-08-04 12:20:00 +000057 virtual void emitDirectiveSetMips1();
58 virtual void emitDirectiveSetMips2();
59 virtual void emitDirectiveSetMips3();
60 virtual void emitDirectiveSetMips4();
61 virtual void emitDirectiveSetMips5();
62 virtual void emitDirectiveSetMips32();
Rafael Espindola60890b82014-06-23 19:43:40 +000063 virtual void emitDirectiveSetMips32R2();
Daniel Sanders17793142015-02-18 16:24:50 +000064 virtual void emitDirectiveSetMips32R3();
65 virtual void emitDirectiveSetMips32R5();
Daniel Sandersf0df2212014-08-04 12:20:00 +000066 virtual void emitDirectiveSetMips32R6();
Rafael Espindola60890b82014-06-23 19:43:40 +000067 virtual void emitDirectiveSetMips64();
68 virtual void emitDirectiveSetMips64R2();
Daniel Sanders17793142015-02-18 16:24:50 +000069 virtual void emitDirectiveSetMips64R3();
70 virtual void emitDirectiveSetMips64R5();
Daniel Sandersf0df2212014-08-04 12:20:00 +000071 virtual void emitDirectiveSetMips64R6();
Rafael Espindola60890b82014-06-23 19:43:40 +000072 virtual void emitDirectiveSetDsp();
Toma Tabacu351b2fe2014-09-17 09:01:54 +000073 virtual void emitDirectiveSetNoDsp();
Toma Tabacu9db22db2014-09-09 10:15:38 +000074 virtual void emitDirectiveSetPop();
75 virtual void emitDirectiveSetPush();
Toma Tabacu29696502015-06-02 09:48:04 +000076 virtual void emitDirectiveSetSoftFloat();
77 virtual void emitDirectiveSetHardFloat();
Matheus Almeida525bc4f2014-04-30 11:28:42 +000078
79 // PIC support
Toma Tabacuc4c202a2014-10-01 14:53:19 +000080 virtual void emitDirectiveCpLoad(unsigned RegNo);
Daniel Sandersc6924fa2016-04-18 12:06:15 +000081 virtual void emitDirectiveCpRestore(int Offset);
Matheus Almeidad92a3fa2014-05-01 10:24:46 +000082 virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
Rafael Espindola60890b82014-06-23 19:43:40 +000083 const MCSymbol &Sym, bool IsReg);
Daniel Sandersf173dda2015-09-22 10:50:09 +000084 virtual void emitDirectiveCpreturn(unsigned SaveLocation,
85 bool SaveLocationIsRegister);
Daniel Sanders7e527422014-07-10 13:38:23 +000086
Toma Tabacua64e5402015-06-25 12:44:38 +000087 // FP abiflags directives
88 virtual void emitDirectiveModuleFP();
Toma Tabacu3c499582015-06-25 10:56:57 +000089 virtual void emitDirectiveModuleOddSPReg();
Toma Tabacu0f093132015-06-30 13:46:03 +000090 virtual void emitDirectiveModuleSoftFloat();
91 virtual void emitDirectiveModuleHardFloat();
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000092 virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
Toma Tabacu32c72aa2015-06-30 09:36:50 +000093 virtual void emitDirectiveSetOddSPReg();
94 virtual void emitDirectiveSetNoOddSPReg();
Toma Tabacua64e5402015-06-25 12:44:38 +000095
Daniel Sandersa736b372016-04-29 13:33:12 +000096 void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
97 const MCSubtargetInfo *STI);
98 void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
99 const MCSubtargetInfo *STI);
100 void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc,
101 const MCSubtargetInfo *STI);
102 void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc,
103 const MCSubtargetInfo *STI);
104 void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc,
105 const MCSubtargetInfo *STI);
106 void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2,
107 SMLoc IDLoc, const MCSubtargetInfo *STI);
108 void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
109 SMLoc IDLoc, const MCSubtargetInfo *STI);
110 void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
111 SMLoc IDLoc, const MCSubtargetInfo *STI);
112 void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
113 const MCSubtargetInfo *STI);
114 void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
115 SMLoc IDLoc, const MCSubtargetInfo *STI);
116 void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
117 const MCSubtargetInfo *STI);
118 void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
Daniel Sandersfba875f2016-04-29 13:43:45 +0000119 void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
120 unsigned BaseReg, int64_t Offset, unsigned ATReg,
121 SMLoc IDLoc, const MCSubtargetInfo *STI);
122 void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg,
123 unsigned BaseReg, MCOperand &HiOperand,
124 MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
125 const MCSubtargetInfo *STI);
126 void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
127 int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
128 const MCSubtargetInfo *STI);
129 void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
130 MCOperand &HiOperand, MCOperand &LoOperand,
131 unsigned ATReg, SMLoc IDLoc,
132 const MCSubtargetInfo *STI);
Daniel Sandersa736b372016-04-29 13:33:12 +0000133
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000134 void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000135 void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000136 bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000137
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000138 // This method enables template classes to set internal abi flags
139 // structure values.
140 template <class PredicateLibrary>
141 void updateABIInfo(const PredicateLibrary &P) {
Simon Atanasyan4d45c762015-09-14 11:18:03 +0000142 ABI = P.getABI();
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000143 ABIFlagsSection.setAllFromPredicates(P);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000144 }
145
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000146 MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
Eric Christophera5762812015-01-26 17:33:46 +0000147 const MipsABIInfo &getABI() const {
Simon Atanasyan4d45c762015-09-14 11:18:03 +0000148 assert(ABI.hasValue() && "ABI hasn't been set!");
Eric Christophera5762812015-01-26 17:33:46 +0000149 return *ABI;
150 }
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000151
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000152protected:
Simon Atanasyan4d45c762015-09-14 11:18:03 +0000153 llvm::Optional<MipsABIInfo> ABI;
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000154 MipsABIFlagsSection ABIFlagsSection;
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000155
Daniel Sandersd97a6342014-08-13 10:07:34 +0000156 bool GPRInfoSet;
157 unsigned GPRBitMask;
158 int GPROffset;
159
160 bool FPRInfoSet;
161 unsigned FPRBitMask;
162 int FPROffset;
163
164 bool FrameInfoSet;
165 int FrameOffset;
166 unsigned FrameReg;
167 unsigned ReturnReg;
168
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000169private:
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000170 bool ModuleDirectiveAllowed;
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000171};
Jack Carter86ac5c12013-11-18 23:55:27 +0000172
173// This part is for ascii assembly output
174class MipsTargetAsmStreamer : public MipsTargetStreamer {
Jack Carter6ef6cc52013-11-19 20:53:28 +0000175 formatted_raw_ostream &OS;
176
Jack Carter86ac5c12013-11-18 23:55:27 +0000177public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000178 MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
Craig Topper56c590a2014-04-29 07:58:02 +0000179 void emitDirectiveSetMicroMips() override;
180 void emitDirectiveSetNoMicroMips() override;
181 void emitDirectiveSetMips16() override;
182 void emitDirectiveSetNoMips16() override;
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000183
Craig Topper56c590a2014-04-29 07:58:02 +0000184 void emitDirectiveSetReorder() override;
185 void emitDirectiveSetNoReorder() override;
186 void emitDirectiveSetMacro() override;
187 void emitDirectiveSetNoMacro() override;
Daniel Sanders44934432014-08-07 12:03:36 +0000188 void emitDirectiveSetMsa() override;
189 void emitDirectiveSetNoMsa() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000190 void emitDirectiveSetAt() override;
Toma Tabacu16a74492015-02-13 10:30:57 +0000191 void emitDirectiveSetAtWithArg(unsigned RegNo) override;
Craig Topper56c590a2014-04-29 07:58:02 +0000192 void emitDirectiveSetNoAt() override;
193 void emitDirectiveEnd(StringRef Name) override;
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000194
Craig Topper56c590a2014-04-29 07:58:02 +0000195 void emitDirectiveEnt(const MCSymbol &Symbol) override;
196 void emitDirectiveAbiCalls() override;
197 void emitDirectiveNaN2008() override;
198 void emitDirectiveNaNLegacy() override;
199 void emitDirectiveOptionPic0() override;
200 void emitDirectiveOptionPic2() override;
Toma Tabacu9ca50962015-04-16 09:53:47 +0000201 void emitDirectiveInsn() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000202 void emitFrame(unsigned StackReg, unsigned StackSize,
203 unsigned ReturnReg) override;
204 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
205 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
Vladimir Medic615b26e2014-03-04 09:54:09 +0000206
Toma Tabacu85618b32014-08-19 14:22:52 +0000207 void emitDirectiveSetArch(StringRef Arch) override;
Toma Tabacu26647792014-09-09 12:52:14 +0000208 void emitDirectiveSetMips0() override;
Daniel Sandersf0df2212014-08-04 12:20:00 +0000209 void emitDirectiveSetMips1() override;
210 void emitDirectiveSetMips2() override;
211 void emitDirectiveSetMips3() override;
212 void emitDirectiveSetMips4() override;
213 void emitDirectiveSetMips5() override;
214 void emitDirectiveSetMips32() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000215 void emitDirectiveSetMips32R2() override;
Daniel Sanders17793142015-02-18 16:24:50 +0000216 void emitDirectiveSetMips32R3() override;
217 void emitDirectiveSetMips32R5() override;
Daniel Sandersf0df2212014-08-04 12:20:00 +0000218 void emitDirectiveSetMips32R6() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000219 void emitDirectiveSetMips64() override;
220 void emitDirectiveSetMips64R2() override;
Daniel Sanders17793142015-02-18 16:24:50 +0000221 void emitDirectiveSetMips64R3() override;
222 void emitDirectiveSetMips64R5() override;
Daniel Sandersf0df2212014-08-04 12:20:00 +0000223 void emitDirectiveSetMips64R6() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000224 void emitDirectiveSetDsp() override;
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000225 void emitDirectiveSetNoDsp() override;
Toma Tabacu9db22db2014-09-09 10:15:38 +0000226 void emitDirectiveSetPop() override;
227 void emitDirectiveSetPush() override;
Toma Tabacu29696502015-06-02 09:48:04 +0000228 void emitDirectiveSetSoftFloat() override;
229 void emitDirectiveSetHardFloat() override;
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000230
231 // PIC support
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000232 void emitDirectiveCpLoad(unsigned RegNo) override;
Daniel Sandersc6924fa2016-04-18 12:06:15 +0000233 void emitDirectiveCpRestore(int Offset) override;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000234 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
235 const MCSymbol &Sym, bool IsReg) override;
Daniel Sandersf173dda2015-09-22 10:50:09 +0000236 void emitDirectiveCpreturn(unsigned SaveLocation,
237 bool SaveLocationIsRegister) override;
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000238
Toma Tabacua64e5402015-06-25 12:44:38 +0000239 // FP abiflags directives
240 void emitDirectiveModuleFP() override;
Toma Tabacu3c499582015-06-25 10:56:57 +0000241 void emitDirectiveModuleOddSPReg() override;
Toma Tabacu0f093132015-06-30 13:46:03 +0000242 void emitDirectiveModuleSoftFloat() override;
243 void emitDirectiveModuleHardFloat() override;
Daniel Sanders7e527422014-07-10 13:38:23 +0000244 void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000245 void emitDirectiveSetOddSPReg() override;
246 void emitDirectiveSetNoOddSPReg() override;
Jack Carter86ac5c12013-11-18 23:55:27 +0000247};
248
249// This part is for ELF object output
250class MipsTargetELFStreamer : public MipsTargetStreamer {
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000251 bool MicroMipsEnabled;
Rafael Espindola972e71a2014-01-31 23:10:26 +0000252 const MCSubtargetInfo &STI;
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000253 bool Pic;
Jack Carter39536722014-01-22 23:08:42 +0000254
Jack Carter86ac5c12013-11-18 23:55:27 +0000255public:
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000256 bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
Jack Carter86ac5c12013-11-18 23:55:27 +0000257 MCELFStreamer &getStreamer();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000258 MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000259
Craig Topper56c590a2014-04-29 07:58:02 +0000260 void emitLabel(MCSymbol *Symbol) override;
261 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
Craig Topper73156022014-03-02 09:09:27 +0000262 void finish() override;
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000263
Craig Topper56c590a2014-04-29 07:58:02 +0000264 void emitDirectiveSetMicroMips() override;
265 void emitDirectiveSetNoMicroMips() override;
266 void emitDirectiveSetMips16() override;
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000267
Craig Topper56c590a2014-04-29 07:58:02 +0000268 void emitDirectiveSetNoReorder() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000269 void emitDirectiveEnd(StringRef Name) override;
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000270
Craig Topper56c590a2014-04-29 07:58:02 +0000271 void emitDirectiveEnt(const MCSymbol &Symbol) override;
272 void emitDirectiveAbiCalls() override;
273 void emitDirectiveNaN2008() override;
274 void emitDirectiveNaNLegacy() override;
275 void emitDirectiveOptionPic0() override;
276 void emitDirectiveOptionPic2() override;
Toma Tabacu9ca50962015-04-16 09:53:47 +0000277 void emitDirectiveInsn() override;
Craig Topper56c590a2014-04-29 07:58:02 +0000278 void emitFrame(unsigned StackReg, unsigned StackSize,
279 unsigned ReturnReg) override;
280 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
281 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
Vladimir Medic615b26e2014-03-04 09:54:09 +0000282
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000283 // PIC support
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000284 void emitDirectiveCpLoad(unsigned RegNo) override;
Daniel Sandersc6924fa2016-04-18 12:06:15 +0000285 void emitDirectiveCpRestore(int Offset) override;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000286 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
287 const MCSymbol &Sym, bool IsReg) override;
Daniel Sandersf173dda2015-09-22 10:50:09 +0000288 void emitDirectiveCpreturn(unsigned SaveLocation,
289 bool SaveLocationIsRegister) override;
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000290
Toma Tabacue95a4912015-03-13 11:40:01 +0000291 void emitMipsAbiFlags();
Jack Carter86ac5c12013-11-18 23:55:27 +0000292};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000293}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000294#endif