]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MipsTargetStreamer.h
MFV r302649: 7016 arc_available_memory is not 32-bit safe
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MipsTargetStreamer.h
1 //===-- 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
10 #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
11 #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
12
13 #include "MCTargetDesc/MipsABIFlagsSection.h"
14 #include "MCTargetDesc/MipsABIInfo.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/MC/MCELFStreamer.h"
18 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCStreamer.h"
20
21 namespace llvm {
22
23 struct MipsABIFlagsSection;
24
25 class MipsTargetStreamer : public MCTargetStreamer {
26 public:
27   MipsTargetStreamer(MCStreamer &S);
28
29   virtual void setPic(bool Value) {}
30
31   virtual void emitDirectiveSetMicroMips();
32   virtual void emitDirectiveSetNoMicroMips();
33   virtual void setUsesMicroMips();
34   virtual void emitDirectiveSetMips16();
35   virtual void emitDirectiveSetNoMips16();
36
37   virtual void emitDirectiveSetReorder();
38   virtual void emitDirectiveSetNoReorder();
39   virtual void emitDirectiveSetMacro();
40   virtual void emitDirectiveSetNoMacro();
41   virtual void emitDirectiveSetMsa();
42   virtual void emitDirectiveSetNoMsa();
43   virtual void emitDirectiveSetMt();
44   virtual void emitDirectiveSetNoMt();
45   virtual void emitDirectiveSetAt();
46   virtual void emitDirectiveSetAtWithArg(unsigned RegNo);
47   virtual void emitDirectiveSetNoAt();
48   virtual void emitDirectiveEnd(StringRef Name);
49
50   virtual void emitDirectiveEnt(const MCSymbol &Symbol);
51   virtual void emitDirectiveAbiCalls();
52   virtual void emitDirectiveNaN2008();
53   virtual void emitDirectiveNaNLegacy();
54   virtual void emitDirectiveOptionPic0();
55   virtual void emitDirectiveOptionPic2();
56   virtual void emitDirectiveInsn();
57   virtual void emitFrame(unsigned StackReg, unsigned StackSize,
58                          unsigned ReturnReg);
59   virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
60   virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
61
62   virtual void emitDirectiveSetArch(StringRef Arch);
63   virtual void emitDirectiveSetMips0();
64   virtual void emitDirectiveSetMips1();
65   virtual void emitDirectiveSetMips2();
66   virtual void emitDirectiveSetMips3();
67   virtual void emitDirectiveSetMips4();
68   virtual void emitDirectiveSetMips5();
69   virtual void emitDirectiveSetMips32();
70   virtual void emitDirectiveSetMips32R2();
71   virtual void emitDirectiveSetMips32R3();
72   virtual void emitDirectiveSetMips32R5();
73   virtual void emitDirectiveSetMips32R6();
74   virtual void emitDirectiveSetMips64();
75   virtual void emitDirectiveSetMips64R2();
76   virtual void emitDirectiveSetMips64R3();
77   virtual void emitDirectiveSetMips64R5();
78   virtual void emitDirectiveSetMips64R6();
79   virtual void emitDirectiveSetDsp();
80   virtual void emitDirectiveSetDspr2();
81   virtual void emitDirectiveSetNoDsp();
82   virtual void emitDirectiveSetPop();
83   virtual void emitDirectiveSetPush();
84   virtual void emitDirectiveSetSoftFloat();
85   virtual void emitDirectiveSetHardFloat();
86
87   // PIC support
88   virtual void emitDirectiveCpLoad(unsigned RegNo);
89   virtual bool emitDirectiveCpRestore(int Offset,
90                                       function_ref<unsigned()> GetATReg,
91                                       SMLoc IDLoc, const MCSubtargetInfo *STI);
92   virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
93                                     const MCSymbol &Sym, bool IsReg);
94   virtual void emitDirectiveCpreturn(unsigned SaveLocation,
95                                      bool SaveLocationIsRegister);
96
97   // FP abiflags directives
98   virtual void emitDirectiveModuleFP();
99   virtual void emitDirectiveModuleOddSPReg();
100   virtual void emitDirectiveModuleSoftFloat();
101   virtual void emitDirectiveModuleHardFloat();
102   virtual void emitDirectiveModuleMT();
103   virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
104   virtual void emitDirectiveSetOddSPReg();
105   virtual void emitDirectiveSetNoOddSPReg();
106
107   void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
108              const MCSubtargetInfo *STI);
109   void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
110               const MCSubtargetInfo *STI);
111   void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc,
112               const MCSubtargetInfo *STI);
113   void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc,
114               const MCSubtargetInfo *STI);
115   void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc,
116               const MCSubtargetInfo *STI);
117   void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2,
118                SMLoc IDLoc, const MCSubtargetInfo *STI);
119   void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
120                SMLoc IDLoc, const MCSubtargetInfo *STI);
121   void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
122                SMLoc IDLoc, const MCSubtargetInfo *STI);
123   void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0,
124                  int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
125                  const MCSubtargetInfo *STI);
126   void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
127                 const MCSubtargetInfo *STI);
128   void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
129                 SMLoc IDLoc, const MCSubtargetInfo *STI);
130   void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
131                           const MCSubtargetInfo *STI);
132   void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
133
134   /// Emit a store instruction with an offset. If the offset is out of range
135   /// then it will be synthesized using the assembler temporary.
136   ///
137   /// GetATReg() is a callback that can be used to obtain the current assembler
138   /// temporary and is only called when the assembler temporary is required. It
139   /// must handle the case where no assembler temporary is available (typically
140   /// by reporting an error).
141   void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
142                               unsigned BaseReg, int64_t Offset,
143                               function_ref<unsigned()> GetATReg, SMLoc IDLoc,
144                               const MCSubtargetInfo *STI);
145   void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg,
146                               unsigned BaseReg, MCOperand &HiOperand,
147                               MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
148                               const MCSubtargetInfo *STI);
149   void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
150                              int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
151                              const MCSubtargetInfo *STI);
152   void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
153                              MCOperand &HiOperand, MCOperand &LoOperand,
154                              unsigned ATReg, SMLoc IDLoc,
155                              const MCSubtargetInfo *STI);
156   void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI);
157
158   void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
159   void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
160   bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
161
162   // This method enables template classes to set internal abi flags
163   // structure values.
164   template <class PredicateLibrary>
165   void updateABIInfo(const PredicateLibrary &P) {
166     ABI = P.getABI();
167     ABIFlagsSection.setAllFromPredicates(P);
168   }
169
170   MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
171   const MipsABIInfo &getABI() const {
172     assert(ABI.hasValue() && "ABI hasn't been set!");
173     return *ABI;
174   }
175
176 protected:
177   llvm::Optional<MipsABIInfo> ABI;
178   MipsABIFlagsSection ABIFlagsSection;
179
180   bool GPRInfoSet;
181   unsigned GPRBitMask;
182   int GPROffset;
183
184   bool FPRInfoSet;
185   unsigned FPRBitMask;
186   int FPROffset;
187
188   bool FrameInfoSet;
189   int FrameOffset;
190   unsigned FrameReg;
191   unsigned ReturnReg;
192
193 private:
194   bool ModuleDirectiveAllowed;
195 };
196
197 // This part is for ascii assembly output
198 class MipsTargetAsmStreamer : public MipsTargetStreamer {
199   formatted_raw_ostream &OS;
200
201 public:
202   MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
203   void emitDirectiveSetMicroMips() override;
204   void emitDirectiveSetNoMicroMips() override;
205   void emitDirectiveSetMips16() override;
206   void emitDirectiveSetNoMips16() override;
207
208   void emitDirectiveSetReorder() override;
209   void emitDirectiveSetNoReorder() override;
210   void emitDirectiveSetMacro() override;
211   void emitDirectiveSetNoMacro() override;
212   void emitDirectiveSetMsa() override;
213   void emitDirectiveSetNoMsa() override;
214   void emitDirectiveSetMt() override;
215   void emitDirectiveSetNoMt() override;
216   void emitDirectiveSetAt() override;
217   void emitDirectiveSetAtWithArg(unsigned RegNo) override;
218   void emitDirectiveSetNoAt() override;
219   void emitDirectiveEnd(StringRef Name) override;
220
221   void emitDirectiveEnt(const MCSymbol &Symbol) override;
222   void emitDirectiveAbiCalls() override;
223   void emitDirectiveNaN2008() override;
224   void emitDirectiveNaNLegacy() override;
225   void emitDirectiveOptionPic0() override;
226   void emitDirectiveOptionPic2() override;
227   void emitDirectiveInsn() override;
228   void emitFrame(unsigned StackReg, unsigned StackSize,
229                  unsigned ReturnReg) override;
230   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
231   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
232
233   void emitDirectiveSetArch(StringRef Arch) override;
234   void emitDirectiveSetMips0() override;
235   void emitDirectiveSetMips1() override;
236   void emitDirectiveSetMips2() override;
237   void emitDirectiveSetMips3() override;
238   void emitDirectiveSetMips4() override;
239   void emitDirectiveSetMips5() override;
240   void emitDirectiveSetMips32() override;
241   void emitDirectiveSetMips32R2() override;
242   void emitDirectiveSetMips32R3() override;
243   void emitDirectiveSetMips32R5() override;
244   void emitDirectiveSetMips32R6() override;
245   void emitDirectiveSetMips64() override;
246   void emitDirectiveSetMips64R2() override;
247   void emitDirectiveSetMips64R3() override;
248   void emitDirectiveSetMips64R5() override;
249   void emitDirectiveSetMips64R6() override;
250   void emitDirectiveSetDsp() override;
251   void emitDirectiveSetDspr2() override;
252   void emitDirectiveSetNoDsp() override;
253   void emitDirectiveSetPop() override;
254   void emitDirectiveSetPush() override;
255   void emitDirectiveSetSoftFloat() override;
256   void emitDirectiveSetHardFloat() override;
257
258   // PIC support
259   void emitDirectiveCpLoad(unsigned RegNo) override;
260
261   /// Emit a .cprestore directive.  If the offset is out of range then it will
262   /// be synthesized using the assembler temporary.
263   ///
264   /// GetATReg() is a callback that can be used to obtain the current assembler
265   /// temporary and is only called when the assembler temporary is required. It
266   /// must handle the case where no assembler temporary is available (typically
267   /// by reporting an error).
268   bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
269                               SMLoc IDLoc, const MCSubtargetInfo *STI) override;
270   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
271                             const MCSymbol &Sym, bool IsReg) override;
272   void emitDirectiveCpreturn(unsigned SaveLocation,
273                              bool SaveLocationIsRegister) override;
274
275   // FP abiflags directives
276   void emitDirectiveModuleFP() override;
277   void emitDirectiveModuleOddSPReg() override;
278   void emitDirectiveModuleSoftFloat() override;
279   void emitDirectiveModuleHardFloat() override;
280   void emitDirectiveModuleMT() override;
281   void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
282   void emitDirectiveSetOddSPReg() override;
283   void emitDirectiveSetNoOddSPReg() override;
284 };
285
286 // This part is for ELF object output
287 class MipsTargetELFStreamer : public MipsTargetStreamer {
288   bool MicroMipsEnabled;
289   const MCSubtargetInfo &STI;
290   bool Pic;
291
292 public:
293   bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
294   MCELFStreamer &getStreamer();
295   MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
296
297   void setPic(bool Value) override { Pic = Value; }
298
299   void emitLabel(MCSymbol *Symbol) override;
300   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
301   void finish() override;
302
303   void emitDirectiveSetMicroMips() override;
304   void emitDirectiveSetNoMicroMips() override;
305   void setUsesMicroMips() override;
306   void emitDirectiveSetMips16() override;
307
308   void emitDirectiveSetNoReorder() override;
309   void emitDirectiveEnd(StringRef Name) override;
310
311   void emitDirectiveEnt(const MCSymbol &Symbol) override;
312   void emitDirectiveAbiCalls() override;
313   void emitDirectiveNaN2008() override;
314   void emitDirectiveNaNLegacy() override;
315   void emitDirectiveOptionPic0() override;
316   void emitDirectiveOptionPic2() override;
317   void emitDirectiveInsn() override;
318   void emitFrame(unsigned StackReg, unsigned StackSize,
319                  unsigned ReturnReg) override;
320   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
321   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
322
323   // PIC support
324   void emitDirectiveCpLoad(unsigned RegNo) override;
325   bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
326                               SMLoc IDLoc, const MCSubtargetInfo *STI) override;
327   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
328                             const MCSymbol &Sym, bool IsReg) override;
329   void emitDirectiveCpreturn(unsigned SaveLocation,
330                              bool SaveLocationIsRegister) override;
331
332   void emitMipsAbiFlags();
333 };
334 }
335 #endif