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