LLVM  5.0.0
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 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 emitDirectiveSetNoDsp();
81  virtual void emitDirectiveSetPop();
82  virtual void emitDirectiveSetPush();
83  virtual void emitDirectiveSetSoftFloat();
84  virtual void emitDirectiveSetHardFloat();
85 
86  // PIC support
87  virtual void emitDirectiveCpLoad(unsigned RegNo);
88  virtual bool emitDirectiveCpRestore(int Offset,
89  function_ref<unsigned()> GetATReg,
90  SMLoc IDLoc, const MCSubtargetInfo *STI);
91  virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
92  const MCSymbol &Sym, bool IsReg);
93  virtual void emitDirectiveCpreturn(unsigned SaveLocation,
94  bool SaveLocationIsRegister);
95 
96  // FP abiflags directives
97  virtual void emitDirectiveModuleFP();
98  virtual void emitDirectiveModuleOddSPReg();
99  virtual void emitDirectiveModuleSoftFloat();
100  virtual void emitDirectiveModuleHardFloat();
101  virtual void emitDirectiveModuleMT();
103  virtual void emitDirectiveSetOddSPReg();
104  virtual void emitDirectiveSetNoOddSPReg();
105 
106  void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
107  const MCSubtargetInfo *STI);
108  void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
109  const MCSubtargetInfo *STI);
110  void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc,
111  const MCSubtargetInfo *STI);
112  void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc,
113  const MCSubtargetInfo *STI);
114  void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc,
115  const MCSubtargetInfo *STI);
116  void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2,
117  SMLoc IDLoc, const MCSubtargetInfo *STI);
118  void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
119  SMLoc IDLoc, const MCSubtargetInfo *STI);
120  void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
121  SMLoc IDLoc, const MCSubtargetInfo *STI);
122  void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
123  const MCSubtargetInfo *STI);
124  void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
125  SMLoc IDLoc, const MCSubtargetInfo *STI);
126  void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
127  const MCSubtargetInfo *STI);
128  void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
129 
130  /// Emit a store instruction with an offset. If the offset is out of range
131  /// then it will be synthesized using the assembler temporary.
132  ///
133  /// GetATReg() is a callback that can be used to obtain the current assembler
134  /// temporary and is only called when the assembler temporary is required. It
135  /// must handle the case where no assembler temporary is available (typically
136  /// by reporting an error).
137  void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
138  unsigned BaseReg, int64_t Offset,
139  function_ref<unsigned()> GetATReg, SMLoc IDLoc,
140  const MCSubtargetInfo *STI);
141  void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg,
142  unsigned BaseReg, MCOperand &HiOperand,
143  MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
144  const MCSubtargetInfo *STI);
145  void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
146  int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
147  const MCSubtargetInfo *STI);
148  void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
149  MCOperand &HiOperand, MCOperand &LoOperand,
150  unsigned ATReg, SMLoc IDLoc,
151  const MCSubtargetInfo *STI);
152  void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI);
153 
154  void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
155  void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
156  bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
157 
158  // This method enables template classes to set internal abi flags
159  // structure values.
160  template <class PredicateLibrary>
161  void updateABIInfo(const PredicateLibrary &P) {
162  ABI = P.getABI();
164  }
165 
167  const MipsABIInfo &getABI() const {
168  assert(ABI.hasValue() && "ABI hasn't been set!");
169  return *ABI;
170  }
171 
172 protected:
175 
177  unsigned GPRBitMask;
179 
181  unsigned FPRBitMask;
183 
186  unsigned FrameReg;
187  unsigned ReturnReg;
188 
189 private:
190  bool ModuleDirectiveAllowed;
191 };
192 
193 // This part is for ascii assembly output
196 
197 public:
199  void emitDirectiveSetMicroMips() override;
200  void emitDirectiveSetNoMicroMips() override;
201  void emitDirectiveSetMips16() override;
202  void emitDirectiveSetNoMips16() override;
203 
204  void emitDirectiveSetReorder() override;
205  void emitDirectiveSetNoReorder() override;
206  void emitDirectiveSetMacro() override;
207  void emitDirectiveSetNoMacro() override;
208  void emitDirectiveSetMsa() override;
209  void emitDirectiveSetNoMsa() override;
210  void emitDirectiveSetMt() override;
211  void emitDirectiveSetNoMt() override;
212  void emitDirectiveSetAt() override;
213  void emitDirectiveSetAtWithArg(unsigned RegNo) override;
214  void emitDirectiveSetNoAt() override;
215  void emitDirectiveEnd(StringRef Name) override;
216 
217  void emitDirectiveEnt(const MCSymbol &Symbol) override;
218  void emitDirectiveAbiCalls() override;
219  void emitDirectiveNaN2008() override;
220  void emitDirectiveNaNLegacy() override;
221  void emitDirectiveOptionPic0() override;
222  void emitDirectiveOptionPic2() override;
223  void emitDirectiveInsn() override;
224  void emitFrame(unsigned StackReg, unsigned StackSize,
225  unsigned ReturnReg) override;
226  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
227  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
228 
229  void emitDirectiveSetArch(StringRef Arch) override;
230  void emitDirectiveSetMips0() override;
231  void emitDirectiveSetMips1() override;
232  void emitDirectiveSetMips2() override;
233  void emitDirectiveSetMips3() override;
234  void emitDirectiveSetMips4() override;
235  void emitDirectiveSetMips5() override;
236  void emitDirectiveSetMips32() override;
237  void emitDirectiveSetMips32R2() override;
238  void emitDirectiveSetMips32R3() override;
239  void emitDirectiveSetMips32R5() override;
240  void emitDirectiveSetMips32R6() override;
241  void emitDirectiveSetMips64() override;
242  void emitDirectiveSetMips64R2() override;
243  void emitDirectiveSetMips64R3() override;
244  void emitDirectiveSetMips64R5() override;
245  void emitDirectiveSetMips64R6() override;
246  void emitDirectiveSetDsp() override;
247  void emitDirectiveSetNoDsp() override;
248  void emitDirectiveSetPop() override;
249  void emitDirectiveSetPush() override;
250  void emitDirectiveSetSoftFloat() override;
251  void emitDirectiveSetHardFloat() override;
252 
253  // PIC support
254  void emitDirectiveCpLoad(unsigned RegNo) override;
255 
256  /// Emit a .cprestore directive. If the offset is out of range then it will
257  /// be synthesized using the assembler temporary.
258  ///
259  /// GetATReg() is a callback that can be used to obtain the current assembler
260  /// temporary and is only called when the assembler temporary is required. It
261  /// must handle the case where no assembler temporary is available (typically
262  /// by reporting an error).
263  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
264  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
265  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
266  const MCSymbol &Sym, bool IsReg) override;
267  void emitDirectiveCpreturn(unsigned SaveLocation,
268  bool SaveLocationIsRegister) override;
269 
270  // FP abiflags directives
271  void emitDirectiveModuleFP() override;
272  void emitDirectiveModuleOddSPReg() override;
273  void emitDirectiveModuleSoftFloat() override;
274  void emitDirectiveModuleHardFloat() override;
275  void emitDirectiveModuleMT() override;
277  void emitDirectiveSetOddSPReg() override;
278  void emitDirectiveSetNoOddSPReg() override;
279 };
280 
281 // This part is for ELF object output
283  bool MicroMipsEnabled;
284  const MCSubtargetInfo &STI;
285  bool Pic;
286 
287 public:
288  bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
291 
292  void setPic(bool Value) override { Pic = Value; }
293 
294  void emitLabel(MCSymbol *Symbol) override;
295  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
296  void finish() override;
297 
298  void emitDirectiveSetMicroMips() override;
299  void emitDirectiveSetNoMicroMips() override;
300  void setUsesMicroMips() override;
301  void emitDirectiveSetMips16() override;
302 
303  void emitDirectiveSetNoReorder() override;
304  void emitDirectiveEnd(StringRef Name) override;
305 
306  void emitDirectiveEnt(const MCSymbol &Symbol) override;
307  void emitDirectiveAbiCalls() override;
308  void emitDirectiveNaN2008() override;
309  void emitDirectiveNaNLegacy() override;
310  void emitDirectiveOptionPic0() override;
311  void emitDirectiveOptionPic2() override;
312  void emitDirectiveInsn() override;
313  void emitFrame(unsigned StackReg, unsigned StackSize,
314  unsigned ReturnReg) override;
315  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
316  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
317 
318  // PIC support
319  void emitDirectiveCpLoad(unsigned RegNo) override;
320  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
321  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
322  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
323  const MCSymbol &Sym, bool IsReg) override;
324  void emitDirectiveCpreturn(unsigned SaveLocation,
325  bool SaveLocationIsRegister) override;
326 
327  void emitMipsAbiFlags();
328 };
329 }
330 #endif
void emitDirectiveEnd(StringRef Name) override
virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff)
void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override
void emitDirectiveModuleSoftFloat() override
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg) override
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override
virtual void emitDirectiveOptionPic2()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void emitDirectiveSetNoMicroMips() override
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:78
void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister) override
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:89
virtual void emitDirectiveSetNoReorder()
virtual void emitDirectiveModuleHardFloat()
void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI) override
Emit a .cprestore directive.
void emitDirectiveCpLoad(unsigned RegNo) override
virtual void emitDirectiveSetMips32R3()
virtual void emitDirectiveSetMicroMips()
virtual void emitDirectiveSetMips3()
void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) override
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 emitDirectiveSetMips32R6()
void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override
virtual void emitDirectiveSetMips1()
virtual void emitDirectiveModuleOddSPReg()
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveModuleSoftFloat()
MipsABIFlagsSection ABIFlagsSection
void emitLabel(MCSymbol *Symbol) override
virtual void emitDirectiveSetOddSPReg()
virtual void emitDirectiveSetMips64R2()
virtual void emitDirectiveSetNoOddSPReg()
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg) override
const char * Name
void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
#define P(N)
Streaming machine code generation interface.
Definition: MCStreamer.h:167
virtual void emitDirectiveSetMips4()
virtual void emitDirectiveSetNoMicroMips()
virtual void emitDirectiveSetMips16()
virtual void emitDirectiveSetMacro()
void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister) override
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 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()
void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override
virtual void emitDirectiveSetMips64R6()
void emitDirectiveEnt(const MCSymbol &Symbol) override
void emitDirectiveEnt(const MCSymbol &Symbol) override
void setAllFromPredicates(const PredicateLibrary &P)
virtual void emitDirectiveOptionPic0()
void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
const MipsABIInfo & getABI() const
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetNoMips16()
void emitDirectiveSetNoOddSPReg() override
void emitDirectiveSetAtWithArg(unsigned RegNo) override
void emitDirectiveEnd(StringRef Name) override
MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg)
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 emitDirectiveCpLoad(unsigned RegNo) override
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()
MCSubtargetInfo - Generic base class for all target subtargets.
void emitDirectiveSetNoMicroMips() override
void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) override
static bool hasShortDelaySlot(unsigned Opcode)
void emitDirectiveSetArch(StringRef Arch) override
void emitDirectiveModuleOddSPReg() override
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
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
bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI) override
virtual void emitDirectiveSetAtWithArg(unsigned RegNo)
void emitDirectiveModuleHardFloat() override
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