File: CodeGenerator-mips-shared.h

package info (click to toggle)
thunderbird 1:60.8.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,339,208 kB
  • sloc: cpp: 5,456,704; ansic: 2,360,384; python: 596,095; asm: 340,963; java: 326,291; xml: 258,664; sh: 84,366; makefile: 23,702; perl: 17,317; objc: 3,768; yacc: 1,766; ada: 1,681; lex: 1,364; pascal: 1,264; cs: 879; exp: 527; php: 436; lisp: 258; ruby: 153; awk: 152; sed: 53; csh: 27
file content (301 lines) | stat: -rw-r--r-- 11,052 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jit_mips_shared_CodeGenerator_mips_shared_h
#define jit_mips_shared_CodeGenerator_mips_shared_h

#include "jit/shared/CodeGenerator-shared.h"

namespace js {
namespace jit {

class CodeGeneratorMIPSShared;
class OutOfLineBailout;
class OutOfLineTableSwitch;

using OutOfLineWasmTruncateCheck =
    OutOfLineWasmTruncateCheckBase<CodeGeneratorMIPSShared>;

class CodeGeneratorMIPSShared : public CodeGeneratorShared {
  friend class MoveResolverMIPS;

  CodeGeneratorMIPSShared* thisFromCtor() { return this; }

 protected:
  NonAssertingLabel deoptLabel_;

  Operand ToOperand(const LAllocation& a);
  Operand ToOperand(const LAllocation* a);
  Operand ToOperand(const LDefinition* def);

#ifdef JS_PUNBOX64
  Operand ToOperandOrRegister64(const LInt64Allocation input);
#else
  Register64 ToOperandOrRegister64(const LInt64Allocation input);
#endif

  MoveOperand toMoveOperand(LAllocation a) const;

  template <typename T1, typename T2>
  void bailoutCmp32(Assembler::Condition c, T1 lhs, T2 rhs,
                    LSnapshot* snapshot) {
    Label bail;
    masm.branch32(c, lhs, rhs, &bail);
    bailoutFrom(&bail, snapshot);
  }
  template <typename T>
  void bailoutTest32(Assembler::Condition c, Register lhs, T rhs,
                     LSnapshot* snapshot) {
    Label bail;
    masm.branchTest32(c, lhs, rhs, &bail);
    bailoutFrom(&bail, snapshot);
  }
  template <typename T1, typename T2>
  void bailoutCmpPtr(Assembler::Condition c, T1 lhs, T2 rhs,
                     LSnapshot* snapshot) {
    Label bail;
    masm.branchPtr(c, lhs, rhs, &bail);
    bailoutFrom(&bail, snapshot);
  }
  void bailoutTestPtr(Assembler::Condition c, Register lhs, Register rhs,
                      LSnapshot* snapshot) {
    Label bail;
    masm.branchTestPtr(c, lhs, rhs, &bail);
    bailoutFrom(&bail, snapshot);
  }
  void bailoutIfFalseBool(Register reg, LSnapshot* snapshot) {
    Label bail;
    masm.branchTest32(Assembler::Zero, reg, Imm32(0xFF), &bail);
    bailoutFrom(&bail, snapshot);
  }

  void bailoutFrom(Label* label, LSnapshot* snapshot);
  void bailout(LSnapshot* snapshot);

 protected:
  bool generateOutOfLineCode();

  template <typename T>
  void branchToBlock(Register lhs, T rhs, MBasicBlock* mir,
                     Assembler::Condition cond) {
    mir = skipTrivialBlocks(mir);

    Label* label = mir->lir()->label();
    if (Label* oolEntry = labelForBackedgeWithImplicitCheck(mir)) {
      // Note: the backedge is initially a jump to the next instruction.
      // It will be patched to the target block's label during link().
      RepatchLabel rejoin;
      CodeOffsetJump backedge;
      Label skip;

      masm.ma_b(lhs, rhs, &skip, Assembler::InvertCondition(cond), ShortJump);
      backedge = masm.backedgeJump(&rejoin);
      masm.bind(&rejoin);
      masm.bind(&skip);

      if (!patchableBackedges_.append(
              PatchableBackedgeInfo(backedge, label, oolEntry)))
        MOZ_CRASH();
    } else {
      masm.ma_b(lhs, rhs, label, cond);
    }
  }
  void branchToBlock(Assembler::FloatFormat fmt, FloatRegister lhs,
                     FloatRegister rhs, MBasicBlock* mir,
                     Assembler::DoubleCondition cond);

  // Emits a branch that directs control flow to the true block if |cond| is
  // true, and the false block if |cond| is false.
  template <typename T>
  void emitBranch(Register lhs, T rhs, Assembler::Condition cond,
                  MBasicBlock* mirTrue, MBasicBlock* mirFalse) {
    if (isNextBlock(mirFalse->lir())) {
      branchToBlock(lhs, rhs, mirTrue, cond);
    } else {
      branchToBlock(lhs, rhs, mirFalse, Assembler::InvertCondition(cond));
      jumpToBlock(mirTrue);
    }
  }
  void testZeroEmitBranch(Assembler::Condition cond, Register reg,
                          MBasicBlock* ifTrue, MBasicBlock* ifFalse) {
    emitBranch(reg, Imm32(0), cond, ifTrue, ifFalse);
  }

  void emitTableSwitchDispatch(MTableSwitch* mir, Register index,
                               Register base);

  template <typename T>
  void emitWasmLoad(T* ins);
  template <typename T>
  void emitWasmStore(T* ins);

 public:
  // Instruction visitors.
  void visitMinMaxD(LMinMaxD* ins);
  void visitMinMaxF(LMinMaxF* ins);
  void visitAbsD(LAbsD* ins);
  void visitAbsF(LAbsF* ins);
  void visitSqrtD(LSqrtD* ins);
  void visitSqrtF(LSqrtF* ins);
  void visitAddI(LAddI* ins);
  void visitAddI64(LAddI64* ins);
  void visitSubI(LSubI* ins);
  void visitSubI64(LSubI64* ins);
  void visitBitNotI(LBitNotI* ins);
  void visitBitOpI(LBitOpI* ins);
  void visitBitOpI64(LBitOpI64* ins);

  void visitMulI(LMulI* ins);
  void visitMulI64(LMulI64* ins);

  void visitDivI(LDivI* ins);
  void visitDivPowTwoI(LDivPowTwoI* ins);
  void visitModI(LModI* ins);
  void visitModPowTwoI(LModPowTwoI* ins);
  void visitModMaskI(LModMaskI* ins);
  void visitPowHalfD(LPowHalfD* ins);
  void visitShiftI(LShiftI* ins);
  void visitShiftI64(LShiftI64* ins);
  void visitRotateI64(LRotateI64* lir);
  void visitUrshD(LUrshD* ins);

  void visitClzI(LClzI* ins);
  void visitCtzI(LCtzI* ins);
  void visitPopcntI(LPopcntI* ins);
  void visitPopcntI64(LPopcntI64* lir);

  void visitTestIAndBranch(LTestIAndBranch* test);
  void visitCompare(LCompare* comp);
  void visitCompareAndBranch(LCompareAndBranch* comp);
  void visitTestDAndBranch(LTestDAndBranch* test);
  void visitTestFAndBranch(LTestFAndBranch* test);
  void visitCompareD(LCompareD* comp);
  void visitCompareF(LCompareF* comp);
  void visitCompareDAndBranch(LCompareDAndBranch* comp);
  void visitCompareFAndBranch(LCompareFAndBranch* comp);
  void visitBitAndAndBranch(LBitAndAndBranch* lir);
  void visitWasmUint32ToDouble(LWasmUint32ToDouble* lir);
  void visitWasmUint32ToFloat32(LWasmUint32ToFloat32* lir);
  void visitNotI(LNotI* ins);
  void visitNotD(LNotD* ins);
  void visitNotF(LNotF* ins);

  void visitMathD(LMathD* math);
  void visitMathF(LMathF* math);
  void visitFloor(LFloor* lir);
  void visitFloorF(LFloorF* lir);
  void visitCeil(LCeil* lir);
  void visitCeilF(LCeilF* lir);
  void visitRound(LRound* lir);
  void visitRoundF(LRoundF* lir);
  void visitTruncateDToInt32(LTruncateDToInt32* ins);
  void visitTruncateFToInt32(LTruncateFToInt32* ins);

  void visitWasmTruncateToInt32(LWasmTruncateToInt32* lir);

  // Out of line visitors.
  void visitOutOfLineBailout(OutOfLineBailout* ool);
  void visitOutOfLineTableSwitch(OutOfLineTableSwitch* ool);
  void visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateCheck* ool);
  void visitCopySignD(LCopySignD* ins);
  void visitCopySignF(LCopySignF* ins);

 public:
  CodeGeneratorMIPSShared(MIRGenerator* gen, LIRGraph* graph,
                          MacroAssembler* masm);

  void visitValue(LValue* value);
  void visitDouble(LDouble* ins);
  void visitFloat32(LFloat32* ins);
  void visitNegI(LNegI* lir);
  void visitNegD(LNegD* lir);
  void visitNegF(LNegF* lir);
  void visitWasmLoad(LWasmLoad* ins);
  void visitWasmUnalignedLoad(LWasmUnalignedLoad* ins);
  void visitWasmStore(LWasmStore* ins);
  void visitWasmUnalignedStore(LWasmUnalignedStore* ins);
  void visitWasmAddOffset(LWasmAddOffset* ins);
  void visitAsmJSLoadHeap(LAsmJSLoadHeap* ins);
  void visitAsmJSStoreHeap(LAsmJSStoreHeap* ins);
  void visitWasmCompareExchangeHeap(LWasmCompareExchangeHeap* ins);
  void visitWasmAtomicExchangeHeap(LWasmAtomicExchangeHeap* ins);
  void visitWasmAtomicBinopHeap(LWasmAtomicBinopHeap* ins);
  void visitWasmAtomicBinopHeapForEffect(LWasmAtomicBinopHeapForEffect* ins);

  void visitWasmStackArg(LWasmStackArg* ins);
  void visitWasmStackArgI64(LWasmStackArgI64* ins);
  void visitWasmSelect(LWasmSelect* ins);
  void visitWasmReinterpret(LWasmReinterpret* ins);

  void visitMemoryBarrier(LMemoryBarrier* ins);
  void visitAtomicTypedArrayElementBinop(LAtomicTypedArrayElementBinop* lir);
  void visitAtomicTypedArrayElementBinopForEffect(
      LAtomicTypedArrayElementBinopForEffect* lir);
  void visitCompareExchangeTypedArrayElement(
      LCompareExchangeTypedArrayElement* lir);
  void visitAtomicExchangeTypedArrayElement(
      LAtomicExchangeTypedArrayElement* lir);

  void generateInvalidateEpilogue();

  // Generating a result.
  template <typename S, typename T>
  void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType,
                                  const S& value, const T& mem,
                                  Register flagTemp, Register outTemp,
                                  Register valueTemp, Register offsetTemp,
                                  Register maskTemp, AnyRegister output);

  // Generating no result.
  template <typename S, typename T>
  void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType,
                                  const S& value, const T& mem,
                                  Register flagTemp, Register valueTemp,
                                  Register offsetTemp, Register maskTemp);

  void visitWasmCompareExchangeI64(LWasmCompareExchangeI64* lir);
  void visitWasmAtomicExchangeI64(LWasmAtomicExchangeI64* lir);
  void visitWasmAtomicBinopI64(LWasmAtomicBinopI64* lir);

 protected:
  void visitEffectiveAddress(LEffectiveAddress* ins);
  void visitUDivOrMod(LUDivOrMod* ins);

 public:
  // Unimplemented SIMD instructions
  void visitSimdSplatX4(LSimdSplatX4* lir) { MOZ_CRASH("NYI"); }
  void visitSimd128Int(LSimd128Int* ins) { MOZ_CRASH("NYI"); }
  void visitSimd128Float(LSimd128Float* ins) { MOZ_CRASH("NYI"); }
  void visitSimdReinterpretCast(LSimdReinterpretCast* ins) { MOZ_CRASH("NYI"); }
  void visitSimdExtractElementI(LSimdExtractElementI* ins) { MOZ_CRASH("NYI"); }
  void visitSimdExtractElementF(LSimdExtractElementF* ins) { MOZ_CRASH("NYI"); }
  void visitSimdBinaryCompIx4(LSimdBinaryCompIx4* lir) { MOZ_CRASH("NYI"); }
  void visitSimdBinaryCompFx4(LSimdBinaryCompFx4* lir) { MOZ_CRASH("NYI"); }
  void visitSimdBinaryArithIx4(LSimdBinaryArithIx4* lir) { MOZ_CRASH("NYI"); }
  void visitSimdBinaryArithFx4(LSimdBinaryArithFx4* lir) { MOZ_CRASH("NYI"); }
  void visitSimdBinaryBitwise(LSimdBinaryBitwise* lir) { MOZ_CRASH("NYI"); }
  void visitSimdGeneralShuffleI(LSimdGeneralShuffleI* lir) { MOZ_CRASH("NYI"); }
  void visitSimdGeneralShuffleF(LSimdGeneralShuffleF* lir) { MOZ_CRASH("NYI"); }
};

// An out-of-line bailout thunk.
class OutOfLineBailout : public OutOfLineCodeBase<CodeGeneratorMIPSShared> {
  LSnapshot* snapshot_;
  uint32_t frameSize_;

 public:
  OutOfLineBailout(LSnapshot* snapshot, uint32_t frameSize)
      : snapshot_(snapshot), frameSize_(frameSize) {}

  void accept(CodeGeneratorMIPSShared* codegen) override;

  LSnapshot* snapshot() const { return snapshot_; }
};

}  // namespace jit
}  // namespace js

#endif /* jit_mips_shared_CodeGenerator_mips_shared_h */