LLVM  10.0.0
MipsTargetStreamer.h
Go to the documentation of this file.
1 //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
10 #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
11 
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/MC/MCELFStreamer.h"
17 #include "llvm/MC/MCRegisterInfo.h"
18 #include "llvm/MC/MCStreamer.h"
19 
20 namespace llvm {
21 
22 struct MipsABIFlagsSection;
23 
25 public:
27 
28  virtual void setPic(bool Value) {}
29 
30  virtual void emitDirectiveSetMicroMips();
31  virtual void emitDirectiveSetNoMicroMips();
32  virtual void setUsesMicroMips();
33  virtual void emitDirectiveSetMips16();
34  virtual void emitDirectiveSetNoMips16();
35 
36  virtual void emitDirectiveSetReorder();
37  virtual void emitDirectiveSetNoReorder();
38  virtual void emitDirectiveSetMacro();
39  virtual void emitDirectiveSetNoMacro();
40  virtual void emitDirectiveSetMsa();
41  virtual void emitDirectiveSetNoMsa();
42  virtual void emitDirectiveSetMt();
43  virtual void emitDirectiveSetNoMt();
44  virtual void emitDirectiveSetCRC();
45  virtual void emitDirectiveSetNoCRC();
46  virtual void emitDirectiveSetVirt();
47  virtual void emitDirectiveSetNoVirt();
48  virtual void emitDirectiveSetGINV();
49  virtual void emitDirectiveSetNoGINV();
50  virtual void emitDirectiveSetAt();
51  virtual void emitDirectiveSetAtWithArg(unsigned RegNo);
52  virtual void emitDirectiveSetNoAt();
53  virtual void emitDirectiveEnd(StringRef Name);
54 
55  virtual void emitDirectiveEnt(const MCSymbol &Symbol);
56  virtual void emitDirectiveAbiCalls();
57  virtual void emitDirectiveNaN2008();
58  virtual void emitDirectiveNaNLegacy();
59  virtual void emitDirectiveOptionPic0();
60  virtual void emitDirectiveOptionPic2();
61  virtual void emitDirectiveInsn();
62  virtual void emitFrame(unsigned StackReg, unsigned StackSize,
63  unsigned ReturnReg);
64  virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
65  virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
66 
67  virtual void emitDirectiveSetArch(StringRef Arch);
68  virtual void emitDirectiveSetMips0();
69  virtual void emitDirectiveSetMips1();
70  virtual void emitDirectiveSetMips2();
71  virtual void emitDirectiveSetMips3();
72  virtual void emitDirectiveSetMips4();
73  virtual void emitDirectiveSetMips5();
74  virtual void emitDirectiveSetMips32();
75  virtual void emitDirectiveSetMips32R2();
76  virtual void emitDirectiveSetMips32R3();
77  virtual void emitDirectiveSetMips32R5();
78  virtual void emitDirectiveSetMips32R6();
79  virtual void emitDirectiveSetMips64();
80  virtual void emitDirectiveSetMips64R2();
81  virtual void emitDirectiveSetMips64R3();
82  virtual void emitDirectiveSetMips64R5();
83  virtual void emitDirectiveSetMips64R6();
84  virtual void emitDirectiveSetDsp();
85  virtual void emitDirectiveSetDspr2();
86  virtual void emitDirectiveSetNoDsp();
87  virtual void emitDirectiveSetPop();
88  virtual void emitDirectiveSetPush();
89  virtual void emitDirectiveSetSoftFloat();
90  virtual void emitDirectiveSetHardFloat();
91 
92  // PIC support
93  virtual void emitDirectiveCpLoad(unsigned RegNo);
94  virtual void emitDirectiveCpLocal(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 emitRRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
134  MCOperand Op3, SMLoc IDLoc, const MCSubtargetInfo *STI);
135  void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
136  SMLoc IDLoc, const MCSubtargetInfo *STI);
137  void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0,
138  int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
139  const MCSubtargetInfo *STI);
140  void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
141  const MCSubtargetInfo *STI);
142  void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
143  SMLoc IDLoc, const MCSubtargetInfo *STI);
144  void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
145  const MCSubtargetInfo *STI);
146  void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
147 
148  /// Emit a store instruction with an offset. If the offset is out of range
149  /// then it will be synthesized using the assembler temporary.
150  ///
151  /// GetATReg() is a callback that can be used to obtain the current assembler
152  /// temporary and is only called when the assembler temporary is required. It
153  /// must handle the case where no assembler temporary is available (typically
154  /// by reporting an error).
155  void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
156  unsigned BaseReg, int64_t Offset,
157  function_ref<unsigned()> GetATReg, SMLoc IDLoc,
158  const MCSubtargetInfo *STI);
159  void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
160  int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
161  const MCSubtargetInfo *STI);
162  void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI);
163 
164  void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
165  void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
166  bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
167 
168  // This method enables template classes to set internal abi flags
169  // structure values.
170  template <class PredicateLibrary>
171  void updateABIInfo(const PredicateLibrary &P) {
172  ABI = P.getABI();
174  }
175 
177  const MipsABIInfo &getABI() const {
178  assert(ABI.hasValue() && "ABI hasn't been set!");
179  return *ABI;
180  }
181 
182 protected:
185 
187  unsigned GPRBitMask;
189 
191  unsigned FPRBitMask;
193 
196  unsigned FrameReg;
197  unsigned GPReg;
198  unsigned ReturnReg;
199 
200 private:
201  bool ModuleDirectiveAllowed;
202 };
203 
204 // This part is for ascii assembly output
207 
208 public:
210  void emitDirectiveSetMicroMips() override;
211  void emitDirectiveSetNoMicroMips() override;
212  void emitDirectiveSetMips16() override;
213  void emitDirectiveSetNoMips16() override;
214 
215  void emitDirectiveSetReorder() override;
216  void emitDirectiveSetNoReorder() override;
217  void emitDirectiveSetMacro() override;
218  void emitDirectiveSetNoMacro() override;
219  void emitDirectiveSetMsa() override;
220  void emitDirectiveSetNoMsa() override;
221  void emitDirectiveSetMt() override;
222  void emitDirectiveSetNoMt() override;
223  void emitDirectiveSetCRC() override;
224  void emitDirectiveSetNoCRC() override;
225  void emitDirectiveSetVirt() override;
226  void emitDirectiveSetNoVirt() override;
227  void emitDirectiveSetGINV() override;
228  void emitDirectiveSetNoGINV() override;
229  void emitDirectiveSetAt() override;
230  void emitDirectiveSetAtWithArg(unsigned RegNo) override;
231  void emitDirectiveSetNoAt() override;
232  void emitDirectiveEnd(StringRef Name) override;
233 
234  void emitDirectiveEnt(const MCSymbol &Symbol) override;
235  void emitDirectiveAbiCalls() override;
236  void emitDirectiveNaN2008() override;
237  void emitDirectiveNaNLegacy() override;
238  void emitDirectiveOptionPic0() override;
239  void emitDirectiveOptionPic2() override;
240  void emitDirectiveInsn() override;
241  void emitFrame(unsigned StackReg, unsigned StackSize,
242  unsigned ReturnReg) override;
243  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
244  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
245 
246  void emitDirectiveSetArch(StringRef Arch) override;
247  void emitDirectiveSetMips0() override;
248  void emitDirectiveSetMips1() override;
249  void emitDirectiveSetMips2() override;
250  void emitDirectiveSetMips3() override;
251  void emitDirectiveSetMips4() override;
252  void emitDirectiveSetMips5() override;
253  void emitDirectiveSetMips32() override;
254  void emitDirectiveSetMips32R2() override;
255  void emitDirectiveSetMips32R3() override;
256  void emitDirectiveSetMips32R5() override;
257  void emitDirectiveSetMips32R6() override;
258  void emitDirectiveSetMips64() override;
259  void emitDirectiveSetMips64R2() override;
260  void emitDirectiveSetMips64R3() override;
261  void emitDirectiveSetMips64R5() override;
262  void emitDirectiveSetMips64R6() override;
263  void emitDirectiveSetDsp() override;
264  void emitDirectiveSetDspr2() override;
265  void emitDirectiveSetNoDsp() override;
266  void emitDirectiveSetPop() override;
267  void emitDirectiveSetPush() override;
268  void emitDirectiveSetSoftFloat() override;
269  void emitDirectiveSetHardFloat() override;
270 
271  // PIC support
272  void emitDirectiveCpLoad(unsigned RegNo) override;
273  void emitDirectiveCpLocal(unsigned RegNo) override;
274 
275  /// Emit a .cprestore directive. If the offset is out of range then it will
276  /// be synthesized using the assembler temporary.
277  ///
278  /// GetATReg() is a callback that can be used to obtain the current assembler
279  /// temporary and is only called when the assembler temporary is required. It
280  /// must handle the case where no assembler temporary is available (typically
281  /// by reporting an error).
282  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
283  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
284  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
285  const MCSymbol &Sym, bool IsReg) override;
286  void emitDirectiveCpreturn(unsigned SaveLocation,
287  bool SaveLocationIsRegister) override;
288 
289  // FP abiflags directives
290  void emitDirectiveModuleFP() override;
291  void emitDirectiveModuleOddSPReg() override;
292  void emitDirectiveModuleSoftFloat() override;
293  void emitDirectiveModuleHardFloat() override;
294  void emitDirectiveModuleMT() override;
295  void emitDirectiveModuleCRC() override;
296  void emitDirectiveModuleNoCRC() override;
297  void emitDirectiveModuleVirt() override;
298  void emitDirectiveModuleNoVirt() override;
299  void emitDirectiveModuleGINV() override;
300  void emitDirectiveModuleNoGINV() override;
302  void emitDirectiveSetOddSPReg() override;
303  void emitDirectiveSetNoOddSPReg() override;
304 };
305 
306 // This part is for ELF object output
308  bool MicroMipsEnabled;
309  const MCSubtargetInfo &STI;
310  bool Pic;
311 
312 public:
313  bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
316 
317  void setPic(bool Value) override { Pic = Value; }
318 
319  void emitLabel(MCSymbol *Symbol) override;
320  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
321  void finish() override;
322 
323  void emitDirectiveSetMicroMips() override;
324  void emitDirectiveSetNoMicroMips() override;
325  void setUsesMicroMips() override;
326  void emitDirectiveSetMips16() override;
327 
328  void emitDirectiveSetNoReorder() override;
329  void emitDirectiveEnd(StringRef Name) override;
330 
331  void emitDirectiveEnt(const MCSymbol &Symbol) override;
332  void emitDirectiveAbiCalls() override;
333  void emitDirectiveNaN2008() override;
334  void emitDirectiveNaNLegacy() override;
335  void emitDirectiveOptionPic0() override;
336  void emitDirectiveOptionPic2() override;
337  void emitDirectiveInsn() override;
338  void emitFrame(unsigned StackReg, unsigned StackSize,
339  unsigned ReturnReg) override;
340  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
341  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
342 
343  // PIC support
344  void emitDirectiveCpLoad(unsigned RegNo) override;
345  void emitDirectiveCpLocal(unsigned RegNo) override;
346  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
347  SMLoc IDLoc, const MCSubtargetInfo *STI) override;
348  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
349  const MCSymbol &Sym, bool IsReg) override;
350  void emitDirectiveCpreturn(unsigned SaveLocation,
351  bool SaveLocationIsRegister) override;
352 
353  void emitMipsAbiFlags();
354 };
355 }
356 #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:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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:91
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:99
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()
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:35
virtual void emitDirectiveEnd(StringRef Name)
virtual void emitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:51
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:53
void emitRRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2, MCOperand Op3, SMLoc IDLoc, const MCSubtargetInfo *STI)
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:197
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()
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:99
virtual void emitDirectiveModuleNoVirt()
void setAllFromPredicates(const PredicateLibrary &P)
virtual void emitDirectiveCpLocal(unsigned RegNo)
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:74
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:54
virtual void emitDirectiveModuleNoCRC()
MipsABIFlagsSection & getABIFlagsSection()
Represents a location in source code.
Definition: SMLoc.h:23
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34
virtual void emitDirectiveSetAtWithArg(unsigned RegNo)
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Definition: MCStreamer.cpp:89
void setPic(bool Value) override