Debian Codegraph @

js/src/jit/loong64/CodeGenerator-loong64.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_loong64_CodeGenerator_loong64_h
8 #define jit_loong64_CodeGenerator_loong64_h
9
10 #include "jit/loong64/Assembler-loong64.h"
11 #include "jit/shared/CodeGenerator-shared.h"
12
13 namespace js {
14 namespace jit {
15
16 class CodeGeneratorLOONG64;
17 class OutOfLineTableSwitch;
18
19 using OutOfLineWasmTruncateCheck =
20 OutOfLineWasmTruncateCheckBase<CodeGeneratorLOONG64>;
21
22 class CodeGeneratorLOONG64 : public CodeGeneratorShared {
23 friend class MoveResolverLA;
24
25 protected:
26 CodeGeneratorLOONG64(MIRGenerator* gen, LIRGraph* graph, MacroAssembler* masm,
27 const wasm::CodeMetadata* wasmCodeMeta);
28
29 NonAssertingLabel deoptLabel_;
30
31 Operand ToOperand(const LAllocation& a);
32 Operand ToOperand(const LAllocation* a);
33 Operand ToOperand(const LDefinition* def);
34
35 #ifdef JS_PUNBOX64
36 Operand ToOperandOrRegister64(const LInt64Allocation& input);
37 #else
38 Register64 ToOperandOrRegister64(const LInt64Allocation& input);
39 #endif
40
41 MoveOperand toMoveOperand(LAllocation a) const;
42
43 template <typename T1, typename T2>
44 void bailoutCmp32(Assembler::Condition c, T1 lhs, T2 rhs,
45 LSnapshot* snapshot) {
46 Label bail;
47 masm.branch32(c, lhs, rhs, &bail);
48 bailoutFrom(&bail, snapshot);
49 }
50 template <typename T1, typename T2>
51 void bailoutTest32(Assembler::Condition c, T1 lhs, T2 rhs,
52 LSnapshot* snapshot) {
53 Label bail;
54 masm.branchTest32(c, lhs, rhs, &bail);
55 bailoutFrom(&bail, snapshot);
56 }
57 template <typename T1, typename T2>
58 void bailoutCmpPtr(Assembler::Condition c, T1 lhs, T2 rhs,
59 LSnapshot* snapshot) {
60 Label bail;
61 masm.branchPtr(c, lhs, rhs, &bail);
62 bailoutFrom(&bail, snapshot);
63 }
64 void bailoutTestPtr(Assembler::Condition c, Register lhs, Register rhs,
65 LSnapshot* snapshot) {
66 // TODO(loong64) Didn't use branchTestPtr due to '-Wundefined-inline'.
67 MOZ_ASSERT(c == Assembler::Zero || c == Assembler::NonZero ||
68 c == Assembler::Signed || c == Assembler::NotSigned);
69 Label bail;
70 if (lhs == rhs) {
71 masm.ma_b(lhs, rhs, &bail, c);
72 } else {
73 ScratchRegisterScope scratch(masm);
74 masm.as_and(scratch, lhs, rhs);
75 masm.ma_b(scratch, scratch, &bail, c);
76 }
77 bailoutFrom(&bail, snapshot);
78 }
79 void bailoutIfFalseBool(Register reg, LSnapshot* snapshot) {
80 Label bail;
81 ScratchRegisterScope scratch(masm);
82 masm.ma_and(scratch, reg, Imm32(0xFF));
83 masm.ma_b(scratch, scratch, &bail, Assembler::Zero);
84 bailoutFrom(&bail, snapshot);
85 }
86
87 void bailoutFrom(Label* label, LSnapshot* snapshot);
88 void bailout(LSnapshot* snapshot);
89
90 bool generateOutOfLineCode();
91
92 template <typename T>
93 void branchToBlock(Register lhs, T rhs, MBasicBlock* mir,
94 Assembler::Condition cond) {
95 masm.ma_b(lhs, rhs, skipTrivialBlocks(mir)->lir()->label(), cond);
96 }
97 void branchToBlock(Assembler::FloatFormat fmt, FloatRegister lhs,
98 FloatRegister rhs, MBasicBlock* mir,
99 Assembler::DoubleCondition cond);
100
101 // Emits a branch that directs control flow to the true block if |cond| is
102 // true, and the false block if |cond| is false.
103 template <typename T>
104 void emitBranch(Register lhs, T rhs, Assembler::Condition cond,
105 MBasicBlock* mirTrue, MBasicBlock* mirFalse) {
106 if (isNextBlock(mirFalse->lir())) {
107 branchToBlock(lhs, rhs, mirTrue, cond);
108 } else {
109 branchToBlock(lhs, rhs, mirFalse, Assembler::InvertCondition(cond));
110 jumpToBlock(mirTrue);
111 }
112 }
113
114 void emitTableSwitchDispatch(MTableSwitch* mir, Register index,
115 Register base);
116
117 template <typename T>
118 void emitWasmLoad(T* ins);
119 template <typename T>
120 void emitWasmStore(T* ins);
121
122 void generateInvalidateEpilogue();
123
124 // Generating a result.
125 template <typename S, typename T>
126 void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType,
127 const S& value, const T& mem,
128 Register flagTemp, Register outTemp,
129 Register valueTemp, Register offsetTemp,
130 Register maskTemp, AnyRegister output);
131
132 // Generating no result.
133 template <typename S, typename T>
134 void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType,
135 const S& value, const T& mem,
136 Register flagTemp, Register valueTemp,
137 Register offsetTemp, Register maskTemp);
138
139 public:
140 // Out of line visitors.
141 void visitOutOfLineTableSwitch(OutOfLineTableSwitch* ool);
142 void visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateCheck* ool);
143
144 protected:
145 void emitBigIntPtrDiv(LBigIntPtrDiv* ins, Register dividend, Register divisor,
146 Register output);
147 void emitBigIntPtrMod(LBigIntPtrMod* ins, Register dividend, Register divisor,
148 Register output);
149
150 template <typename T>
151 void emitWasmLoadI64(T* ins);
152 template <typename T>
153 void emitWasmStoreI64(T* ins);
154 };
155
156 typedef CodeGeneratorLOONG64 CodeGeneratorSpecific;
157
158 } // namespace jit
159 } // namespace js
160
161 #endif /* jit_loong64_CodeGenerator_loong64_h */