LLVM  8.0.1
MipsTargetStreamer.h
Go to the documentation of this file.
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 
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 
26 public:
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 emitDirectiveSetCRC();
46  virtual void emitDirectiveSetNoCRC();
47  virtual void emitDirectiveSetVirt();
48  virtual void emitDirectiveSetNoVirt();
49  virtual void emitDirectiveSetGINV();
50  virtual void emitDirectiveSetNoGINV();
51  virtual void emitDirectiveSetAt();
52  virtual void emitDirectiveSetAtWithArg(unsigned RegNo);
53  virtual void emitDirectiveSetNoAt();
54  virtual void emitDirectiveEnd(StringRef Name);
55 
56  virtual void emitDirectiveEnt(const MCSymbol &Symbol);
57  virtual void emitDirectiveAbiCalls();
58  virtual void emitDirectiveNaN2008();
59  virtual void emitDirectiveNaNLegacy();
60  virtual void emitDirectiveOptionPic0();
61  virtual void emitDirectiveOptionPic2();
62  virtual void emitDirectiveInsn();
63  virtual void emitFrame(unsigned StackReg, unsigned StackSize,
64  unsigned ReturnReg);
65  virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
66  virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
67 
68  virtual void emitDirectiveSetArch(StringRef Arch);
69  virtual void emitDirectiveSetMips0();
70  virtual void emitDirectiveSetMips1();
71  virtual void emitDirectiveSetMips2();
72  virtual void emitDirectiveSetMips3();
73  virtual void emitDirectiveSetMips4();
74  virtual void emitDirectiveSetMips5();
75  virtual void emitDirectiveSetMips32();
76  virtual void emitDirectiveSetMips32R2();
77  virtual void emitDirectiveSetMips32R3();
78  virtual void emitDirectiveSetMips32R5();
79  virtual void emitDirectiveSetMips32R6();
80  virtual void emitDirectiveSetMips64();
81  virtual void emitDirectiveSetMips64R2();
82  virtual void emitDirectiveSetMips64R3();
83  virtual void emitDirectiveSetMips64R5();
84  virtual void emitDirectiveSetMips64R6();
85  virtual void emitDirectiveSetDsp();
86  virtual void emitDirectiveSetDspr2();
87  virtual void emitDirectiveSetNoDsp();
88  virtual void emitDirectiveSetPop();
89  virtual void emitDirectiveSetPush();
90  virtual void emitDirectiveSetSoftFloat();
91  virtual void emitDirectiveSetHardFloat();
92 
93  // PIC support
94  virtual void emitDirectiveCpLoad(unsigned RegNo);
95  virtual bool emitDirectiveCpRestore(int Offset,
96  function_ref<unsigned()> GetATReg,
97  SMLoc IDLoc, const MCSubtargetInfo *STI);
98  virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
99  const MCSymbol &Sym, bool IsReg);
100  virtual void emitDirectiveCpreturn(unsigned SaveLocation,
101  bool SaveLocationIsRegister);
102 
103  // FP abiflags directives
104  virtual void emitDirectiveModuleFP();
105  virtual void emitDirectiveModuleOddSPReg();
106  virtual void emitDirectiveModuleSoftFloat();
107  virtual void emitDirectiveModuleHardFloat();
108  virtual void emitDirectiveModuleMT();
110  virtual void emitDirectiveSetOddSPReg();
111  virtual void emitDirectiveSetNoOddSPReg();
112  virtual void emitDirectiveModuleCRC();
113  virtual void emitDirectiveModuleNoCRC();
114  virtual void emitDirectiveModuleVirt();
115  virtual void emitDirectiveModuleNoVirt();
116  virtual void emitDirectiveModuleGINV();
117  virtual void emitDirectiveModuleNoGINV();
118 
119  void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
120  const MCSubtargetInfo *STI);
121  void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
122  const MCSubtargetInfo *STI);
123  void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc,
124  const MCSubtargetInfo *STI);
125  void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc,
126  const MCSubtargetInfo *STI);
127  void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc,
128  const MCSubtargetInfo *STI);
129  void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2,
130  SMLoc IDLoc, const MCSubtargetInfo *STI);
131  void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
132  SMLoc IDLoc, const MCSubtargetInfo *STI);
133  void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
134  SMLoc IDLoc, const MCSubtargetInfo *STI);
135  void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0,
136  int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
137  const MCSubtargetInfo *STI);
138  void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
139  const MCSubtargetInfo *STI);
140  void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
141  SMLoc IDLoc, const MCSubtargetInfo *STI);
142  void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
143  const MCSubtargetInfo *STI);
144  void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
145 
146  /// Emit a store instruction with an offset. If the offset is out of range
147  /// then it will be synthesized using the assembler temporary.
148  ///
149  /// GetATReg() is a callback that can be used to obtain the current assembler
150  /// temporary and is only called when the assembler temporary is required. It
151  /// must handle the case where no assembler temporary is available (typically
152  /// by reporting an error).
153  void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
154  unsigned BaseReg, int64_t Offset,
155  function_ref<unsigned()> GetATReg, SMLoc IDLoc,
156  const MCSubtargetInfo *STI);
157  void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg,
158  unsigned BaseReg, MCOperand &HiOperand,
159  MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
160  const MCSubtargetInfo *STI);
161  void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
162  int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
163  const MCSubtargetInfo *STI);
164  void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
165  MCOperand &HiOperand, MCOperand &LoOperand,
166  unsigned ATReg, SMLoc IDLoc,
167  const MCSubtargetInfo *STI);
168  void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI);
169 
170  void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
171  void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
172  bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
173 
174  // This method enables template classes to set internal abi flags
175  // structure values.
176  template <class PredicateLibrary>
177  void updateABIInfo(const PredicateLibrary &P) {
178  ABI = P.getABI();
180  }
181 
183  const MipsABIInfo &getABI() const {
184  assert(ABI.hasValue() && "ABI hasn't been set!");
185  return *ABI;
186  }
187 
188 protected:
191 
193  unsigned GPRBitMask;
195 
197  unsigned FPRBitMask;
199 
202  unsigned FrameReg;
203  unsigned ReturnReg;
204 
205 private:
206  bool ModuleDirectiveAllowed;
207 };
208 
209 // This part is for ascii assembly output
212 
213 public:
215  void emitDirectiveSetMicroMips() override;
216  void emitDirectiveSetNoMicroMips() override;
217  void emitDirectiveSetMips16() override;
218  void emitDirectiveSetNoMips16() override;
219 
220  void emitDirectiveSetReorder() override;
221  void emitDirectiveSetNoReorder() override;
222  void emitDirectiveSetMacro() override;
223  void emitDirectiveSetNoMacro() override;
224  void emitDirectiveSetMsa() override;
225  void emitDirectiveSetNoMsa() override;
226  void emitDirectiveSetMt() override;
227  void emitDirectiveSetNoMt() override;
228  void emitDirectiveSetCRC() override;
229  void emitDirectiveSetNoCRC() override;
230  void emitDirectiveSetVirt() override;
231  void emitDirectiveSetNoVirt() override;
232  void emitDirectiveSetGINV() override;
233  void emitDirectiveSetNoGINV() override;
234  void emitDirectiveSetAt() override;
235  void emitDirectiveSetAtWithArg(unsigned RegNo) override;
236  void emitDirectiveSetNoAt() override;
237  void emitDirectiveEnd(StringRef Name) override;
238 
239  void emitDirectiveEnt(const MCSymbol &Symbol) override;
240  void emitDirectiveAbiCalls() override;
241  void emitDirectiveNaN2008() override;
242  void emitDirectiveNaNLegacy() override;
243  void emitDirectiveOptionPic0() override;
244  void emitDirectiveOptionPic2() override;
245  void emitDirectiveInsn() override;
246  void emitFrame(unsigned StackReg, unsigned StackSize,
247  unsigned ReturnReg) override;
248  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
249  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
250 
251  void emitDirectiveSetArch(StringRef Arch) override;
252  void emitDirectiveSetMips0() override;
253  void emitDirectiveSetMips1() override;
254  void emitDirectiveSetMips2() override;
255  void emitDirectiveSetMips3() override;
256  void emitDirectiveSetMips4() override;
257  void emitDirectiveSetMips5() override;
258  void emitDirectiveSetMips32() override;
259  void emitDirectiveSetMips32R2() override;
260  void emitDirectiveSetMips32R3() override;
261  void emitDirectiveSetMips32R5() override;
262  void emitDirectiveSetMips32R6() override;
263  void emitDirectiveSetMips64() override;
264  void emitDirectiveSetMips64R2() override;
265  void emitDirectiveSetMips64R3() override;
266  void emitDirectiveSetMips64R5() override;
267  void emitDirectiveSetMips64R6() override;
268  void emitDirectiveSetDsp() override;
269  void emitDirectiveSetDspr2() override;
270  void emitDirectiveSetNoDsp() override;
271  void emitDirectiveSetPop() override;
272  void emitDirectiveSetPush() override;
273  void emitDirectiveSetSoftFloat() override;
274  void emitDirectiveSetHardFloat() override;
275 
276  // PIC support
277  void emitDirectiveCpLoad(unsigned RegNo) override;
278 
279  /// Emit a .cprestore directive. If the offset is out of range then it will
280  /// be synthesized using the assembler temporary.
281  ///
282  /// GetATReg() is a callback that can be used to obtain the current assembler
283  /// temporary and is only called when the assembler temporary is required. It
284  /// must handle the case where no assembler temporary is available (typically
285  /// by reporting an error).
286  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
287  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
288  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
289  const MCSymbol &Sym, bool IsReg) override;
290  void emitDirectiveCpreturn(unsigned SaveLocation,
291  bool SaveLocationIsRegister) override;
292 
293  // FP abiflags directives
294  void emitDirectiveModuleFP() override;
295  void emitDirectiveModuleOddSPReg() override;
296  void emitDirectiveModuleSoftFloat() override;
297  void emitDirectiveModuleHardFloat() override;
298  void emitDirectiveModuleMT() override;
299  void emitDirectiveModuleCRC() override;
300  void emitDirectiveModuleNoCRC() override;
301  void emitDirectiveModuleVirt() override;
302  void emitDirectiveModuleNoVirt() override;
303  void emitDirectiveModuleGINV() override;
304  void emitDirectiveModuleNoGINV() override;
306  void emitDirectiveSetOddSPReg() override;
307  void emitDirectiveSetNoOddSPReg() override;
308 };
309 
310 // This part is for ELF object output
312  bool MicroMipsEnabled;
313  const MCSubtargetInfo &STI;
314  bool Pic;
315 
316 public:
317  bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
320 
321  void setPic(bool Value) override { Pic = Value; }
322 
323  void emitLabel(MCSymbol *Symbol) override;
324  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
325  void finish() override;
326 
327  void emitDirectiveSetMicroMips() override;
328  void emitDirectiveSetNoMicroMips() override;
329  void setUsesMicroMips() override;
330  void emitDirectiveSetMips16() override;
331 
332  void emitDirectiveSetNoReorder() override;
333  void emitDirectiveEnd(StringRef Name) override;
334 
335  void emitDirectiveEnt(const MCSymbol &Symbol) override;
336  void emitDirectiveAbiCalls() override;
337  void emitDirectiveNaN2008() override;
338  void emitDirectiveNaNLegacy() override;
339  void emitDirectiveOptionPic0() override;
340  void emitDirectiveOptionPic2() override;
341  void emitDirectiveInsn() override;
342  void emitFrame(unsigned StackReg, unsigned StackSize,
343  unsigned ReturnReg) override;
344  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
345  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
346 
347  // PIC support
348  void emitDirectiveCpLoad(unsigned RegNo) override;
349  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
350  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
351  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
352  const MCSymbol &Sym, bool IsReg) override;
353  void emitDirectiveCpreturn(unsigned SaveLocation,
354  bool SaveLocationIsRegister) override;
355 
356  void emitMipsAbiFlags();
357 };
358 }
359 #endif
virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff)
void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveModuleGINV()
void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveOptionPic2()
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit, const MCSubtargetInfo *STI)
Target specific streamer interface.
Definition: MCStreamer.h:84
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
virtual void emitDirectiveSetNoReorder()
virtual void emitDirectiveModuleHardFloat()
virtual void emitDirectiveModuleNoGINV()
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
virtual void emitDirectiveSetMips32R3()
const MipsABIInfo & getABI() const
virtual void emitDirectiveSetMicroMips()
virtual void emitDirectiveSetMips3()
amdgpu Simplify well known AMD library false Value Value const Twine & Name
void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, int64_t Offset, unsigned TmpReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an immediate offset.
virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg)
virtual void emitDirectiveSetMips0()
virtual void emitDirectiveSetSoftFloat()
virtual void emitDirectiveSetNoMacro()
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
virtual void emitDirectiveEnd(StringRef Name)
virtual void emitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:49
virtual void emitDirectiveSetMips32R6()
virtual void emitDirectiveSetMips1()
virtual void emitDirectiveModuleOddSPReg()
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveModuleSoftFloat()
virtual void finish()
Definition: MCStreamer.cpp:51
MipsABIFlagsSection ABIFlagsSection
virtual void emitDirectiveSetOddSPReg()
virtual void emitDirectiveSetMips64R2()
virtual void emitDirectiveSetNoOddSPReg()
void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
#define P(N)
Streaming machine code generation interface.
Definition: MCStreamer.h:189
virtual void emitDirectiveSetMips4()
static bool hasShortDelaySlot(MCInst &Inst)
virtual void emitDirectiveSetNoMicroMips()
virtual void emitDirectiveModuleVirt()
virtual void emitDirectiveSetMips16()
virtual void emitDirectiveSetMacro()
void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveCpLoad(unsigned RegNo)
void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetArch(StringRef Arch)
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff)
virtual void emitDirectiveSetNoCRC()
virtual void emitDirectiveSetMips32R5()
virtual void emitDirectiveSetMips32R2()
void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an symbol offset.
virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value)
void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveAbiCalls()
virtual void emitDirectiveSetMips64R6()
MCStreamer & getStreamer()
Definition: MCStreamer.h:92
virtual void emitDirectiveModuleNoVirt()
void setAllFromPredicates(const PredicateLibrary &P)
virtual void emitDirectiveOptionPic0()
void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetNoGINV()
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetNoMips16()
virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg)
virtual void emitDirectiveSetNoVirt()
void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an offset.
virtual void emitDirectiveSetMips64R3()
virtual void emitDirectiveSetMips64R5()
virtual void setPic(bool Value)
void updateABIInfo(const PredicateLibrary &P)
virtual void emitDirectiveEnt(const MCSymbol &Symbol)
virtual void emitDirectiveSetHardFloat()
virtual void emitDirectiveSetMips64()
virtual bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetMips5()
virtual void emitDirectiveSetMips2()
Generic base class for all target subtargets.
void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void emitDirectiveSetReorder()
LLVM Value Representation.
Definition: Value.h:73
virtual void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister)
llvm::Optional< MipsABIInfo > ABI
virtual void emitDirectiveNaNLegacy()
void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetMips32()
virtual void emitDirectiveSetNoMsa()
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual void emitDirectiveModuleNoCRC()
MipsABIFlagsSection & getABIFlagsSection()
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
virtual void emitDirectiveSetAtWithArg(unsigned RegNo)
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Definition: MCStreamer.cpp:87
void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an symbol offset.
void setPic(bool Value) override