Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Mips/MipsTargetStreamer.h
Line
Count
Source (jump to first uncovered line)
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
12
#include "MCTargetDesc/MipsABIFlagsSection.h"
13
#include "MCTargetDesc/MipsABIInfo.h"
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
24
class MipsTargetStreamer : public MCTargetStreamer {
25
public:
26
  MipsTargetStreamer(MCStreamer &S);
27
28
1.95k
  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();
109
  virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
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
264k
  void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
171
32
  void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
172
127
  bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
173
174
  // This method enables template classes to set internal abi flags
175
  // structure values.
176
  template <class PredicateLibrary>
177
6.55k
  void updateABIInfo(const PredicateLibrary &P) {
178
6.55k
    ABI = P.getABI();
179
6.55k
    ABIFlagsSection.setAllFromPredicates(P);
180
6.55k
  }
void llvm::MipsTargetStreamer::updateABIInfo<llvm::MipsSubtarget>(llvm::MipsSubtarget const&)
Line
Count
Source
177
2.91k
  void updateABIInfo(const PredicateLibrary &P) {
178
2.91k
    ABI = P.getABI();
179
2.91k
    ABIFlagsSection.setAllFromPredicates(P);
180
2.91k
  }
MipsAsmParser.cpp:void llvm::MipsTargetStreamer::updateABIInfo<(anonymous namespace)::MipsAsmParser>((anonymous namespace)::MipsAsmParser const&)
Line
Count
Source
177
3.64k
  void updateABIInfo(const PredicateLibrary &P) {
178
3.64k
    ABI = P.getABI();
179
3.64k
    ABIFlagsSection.setAllFromPredicates(P);
180
3.64k
  }
181
182
0
  MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
183
1.98k
  const MipsABIInfo &getABI() const {
184
1.98k
    assert(ABI.hasValue() && "ABI hasn't been set!");
185
1.98k
    return *ABI;
186
1.98k
  }
187
188
protected:
189
  llvm::Optional<MipsABIInfo> ABI;
190
  MipsABIFlagsSection ABIFlagsSection;
191
192
  bool GPRInfoSet;
193
  unsigned GPRBitMask;
194
  int GPROffset;
195
196
  bool FPRInfoSet;
197
  unsigned FPRBitMask;
198
  int FPROffset;
199
200
  bool FrameInfoSet;
201
  int FrameOffset;
202
  unsigned FrameReg;
203
  unsigned GPReg;
204
  unsigned ReturnReg;
205
206
private:
207
  bool ModuleDirectiveAllowed;
208
};
209
210
// This part is for ascii assembly output
211
class MipsTargetAsmStreamer : public MipsTargetStreamer {
212
  formatted_raw_ostream &OS;
213
214
public:
215
  MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
216
  void emitDirectiveSetMicroMips() override;
217
  void emitDirectiveSetNoMicroMips() override;
218
  void emitDirectiveSetMips16() override;
219
  void emitDirectiveSetNoMips16() override;
220
221
  void emitDirectiveSetReorder() override;
222
  void emitDirectiveSetNoReorder() override;
223
  void emitDirectiveSetMacro() override;
224
  void emitDirectiveSetNoMacro() override;
225
  void emitDirectiveSetMsa() override;
226
  void emitDirectiveSetNoMsa() override;
227
  void emitDirectiveSetMt() override;
228
  void emitDirectiveSetNoMt() override;
229
  void emitDirectiveSetCRC() override;
230
  void emitDirectiveSetNoCRC() override;
231
  void emitDirectiveSetVirt() override;
232
  void emitDirectiveSetNoVirt() override;
233
  void emitDirectiveSetGINV() override;
234
  void emitDirectiveSetNoGINV() override;
235
  void emitDirectiveSetAt() override;
236
  void emitDirectiveSetAtWithArg(unsigned RegNo) override;
237
  void emitDirectiveSetNoAt() override;
238
  void emitDirectiveEnd(StringRef Name) override;
239
240
  void emitDirectiveEnt(const MCSymbol &Symbol) override;
241
  void emitDirectiveAbiCalls() override;
242
  void emitDirectiveNaN2008() override;
243
  void emitDirectiveNaNLegacy() override;
244
  void emitDirectiveOptionPic0() override;
245
  void emitDirectiveOptionPic2() override;
246
  void emitDirectiveInsn() override;
247
  void emitFrame(unsigned StackReg, unsigned StackSize,
248
                 unsigned ReturnReg) override;
249
  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
250
  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
251
252
  void emitDirectiveSetArch(StringRef Arch) override;
253
  void emitDirectiveSetMips0() override;
254
  void emitDirectiveSetMips1() override;
255
  void emitDirectiveSetMips2() override;
256
  void emitDirectiveSetMips3() override;
257
  void emitDirectiveSetMips4() override;
258
  void emitDirectiveSetMips5() override;
259
  void emitDirectiveSetMips32() override;
260
  void emitDirectiveSetMips32R2() override;
261
  void emitDirectiveSetMips32R3() override;
262
  void emitDirectiveSetMips32R5() override;
263
  void emitDirectiveSetMips32R6() override;
264
  void emitDirectiveSetMips64() override;
265
  void emitDirectiveSetMips64R2() override;
266
  void emitDirectiveSetMips64R3() override;
267
  void emitDirectiveSetMips64R5() override;
268
  void emitDirectiveSetMips64R6() override;
269
  void emitDirectiveSetDsp() override;
270
  void emitDirectiveSetDspr2() override;
271
  void emitDirectiveSetNoDsp() override;
272
  void emitDirectiveSetPop() override;
273
  void emitDirectiveSetPush() override;
274
  void emitDirectiveSetSoftFloat() override;
275
  void emitDirectiveSetHardFloat() override;
276
277
  // PIC support
278
  void emitDirectiveCpLoad(unsigned RegNo) override;
279
  void emitDirectiveCpLocal(unsigned RegNo) override;
280
281
  /// Emit a .cprestore directive.  If the offset is out of range then it will
282
  /// be synthesized using the assembler temporary.
283
  ///
284
  /// GetATReg() is a callback that can be used to obtain the current assembler
285
  /// temporary and is only called when the assembler temporary is required. It
286
  /// must handle the case where no assembler temporary is available (typically
287
  /// by reporting an error).
288
  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
289
                              SMLoc IDLoc, const MCSubtargetInfo *STI) override;
290
  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
291
                            const MCSymbol &Sym, bool IsReg) override;
292
  void emitDirectiveCpreturn(unsigned SaveLocation,
293
                             bool SaveLocationIsRegister) override;
294
295
  // FP abiflags directives
296
  void emitDirectiveModuleFP() override;
297
  void emitDirectiveModuleOddSPReg() override;
298
  void emitDirectiveModuleSoftFloat() override;
299
  void emitDirectiveModuleHardFloat() override;
300
  void emitDirectiveModuleMT() override;
301
  void emitDirectiveModuleCRC() override;
302
  void emitDirectiveModuleNoCRC() override;
303
  void emitDirectiveModuleVirt() override;
304
  void emitDirectiveModuleNoVirt() override;
305
  void emitDirectiveModuleGINV() override;
306
  void emitDirectiveModuleNoGINV() override;
307
  void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
308
  void emitDirectiveSetOddSPReg() override;
309
  void emitDirectiveSetNoOddSPReg() override;
310
};
311
312
// This part is for ELF object output
313
class MipsTargetELFStreamer : public MipsTargetStreamer {
314
  bool MicroMipsEnabled;
315
  const MCSubtargetInfo &STI;
316
  bool Pic;
317
318
public:
319
23.3k
  bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
320
  MCELFStreamer &getStreamer();
321
  MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
322
323
63
  void setPic(bool Value) override { Pic = Value; }
324
325
  void emitLabel(MCSymbol *Symbol) override;
326
  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
327
  void finish() override;
328
329
  void emitDirectiveSetMicroMips() override;
330
  void emitDirectiveSetNoMicroMips() override;
331
  void setUsesMicroMips() override;
332
  void emitDirectiveSetMips16() override;
333
334
  void emitDirectiveSetNoReorder() override;
335
  void emitDirectiveEnd(StringRef Name) override;
336
337
  void emitDirectiveEnt(const MCSymbol &Symbol) override;
338
  void emitDirectiveAbiCalls() override;
339
  void emitDirectiveNaN2008() override;
340
  void emitDirectiveNaNLegacy() override;
341
  void emitDirectiveOptionPic0() override;
342
  void emitDirectiveOptionPic2() override;
343
  void emitDirectiveInsn() override;
344
  void emitFrame(unsigned StackReg, unsigned StackSize,
345
                 unsigned ReturnReg) override;
346
  void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
347
  void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
348
349
  // PIC support
350
  void emitDirectiveCpLoad(unsigned RegNo) override;
351
  void emitDirectiveCpLocal(unsigned RegNo) override;
352
  bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
353
                              SMLoc IDLoc, const MCSubtargetInfo *STI) override;
354
  void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
355
                            const MCSymbol &Sym, bool IsReg) override;
356
  void emitDirectiveCpreturn(unsigned SaveLocation,
357
                             bool SaveLocationIsRegister) override;
358
359
  void emitMipsAbiFlags();
360
};
361
}
362
#endif