Debian Codegraph @

js/src/wasm/WasmBCDefs.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 *
4 * Copyright 2016 Mozilla Foundation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 // This is an INTERNAL header for Wasm baseline compiler: common configuration
20 // and simple definitions; all include directives.
21
22 #ifndef wasm_wasm_baseline_defs_h
23 #define wasm_wasm_baseline_defs_h
24
25 #include <algorithm>
26 #include <utility>
27
28 #include "jit/AtomicOp.h"
29 #include "jit/IonTypes.h"
30 #include "jit/JitAllocPolicy.h"
31 #include "jit/Label.h"
32 #include "jit/RegisterAllocator.h"
33 #include "jit/Registers.h"
34 #include "jit/RegisterSets.h"
35 #if defined(JS_CODEGEN_ARM)
36 # include "jit/arm/Assembler-arm.h"
37 #endif
38 #if defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86)
39 # include "jit/x86-shared/Architecture-x86-shared.h"
40 # include "jit/x86-shared/Assembler-x86-shared.h"
41 #endif
42 #if defined(JS_CODEGEN_MIPS64)
43 # include "jit/mips-shared/Assembler-mips-shared.h"
44 # include "jit/mips64/Assembler-mips64.h"
45 #endif
46 #if defined(JS_CODEGEN_LOONG64)
47 # include "jit/loong64/Assembler-loong64.h"
48 #endif
49 #if defined(JS_CODEGEN_RISCV64)
50 # include "jit/riscv64/Assembler-riscv64.h"
51 #endif
52 #include "js/ScalarType.h"
53 #include "util/Memory.h"
54 #include "wasm/WasmCodegenTypes.h"
55 #include "wasm/WasmDebugFrame.h"
56 #include "wasm/WasmGC.h"
57 #include "wasm/WasmGcObject.h"
58 #include "wasm/WasmGenerator.h"
59 #include "wasm/WasmInstance.h"
60 #include "wasm/WasmOpIter.h"
61 #include "wasm/WasmSignalHandlers.h"
62 #include "wasm/WasmStubs.h"
63 #include "wasm/WasmValidate.h"
64
65 namespace js {
66 namespace wasm {
67
68 using HandleNaNSpecially = bool;
69 using InvertBranch = bool;
70 using IsKnownNotZero = bool;
71 using IsUnsigned = bool;
72 using IsRemainder = bool;
73 using NeedsBoundsCheck = bool;
74 using WantResult = bool;
75 using ZeroOnOverflow = bool;
76
77 class BaseStackFrame;
78
79 // Two flags, useABI and restoreRegisterStateAndRealm, control how calls are
80 // made.
81 //
82 // UseABI::Wasm implies that the Instance/Heap/Global registers are nonvolatile,
83 // except when RestoreRegisterStateAndRealm::True is also set, when they are
84 // volatile.
85 //
86 // UseABI::Builtin implies that the Instance/Heap/Global registers are volatile.
87 // In this case, we require RestoreRegisterStateAndRealm::False. The calling
88 // convention is otherwise like UseABI::Wasm.
89 //
90 // UseABI::System implies that the Instance/Heap/Global registers are volatile.
91 // Additionally, the parameter passing mechanism may be slightly different from
92 // the UseABI::Wasm convention.
93 //
94 // When the Instance/Heap/Global registers are not volatile, the baseline
95 // compiler will restore the Instance register from its save slot before the
96 // call, since the baseline compiler uses the Instance register for other
97 // things.
98 //
99 // When those registers are volatile, the baseline compiler will reload them
100 // after the call (it will restore the Instance register from the save slot and
101 // load the other two from the Instance data).
102
103 enum class UseABI { Wasm, Builtin, System };
104 enum class RestoreRegisterStateAndRealm { False = false, True = true };
105 enum class RhsDestOp { True = true };
106
107 // Compiler configuration.
108 //
109 // The following internal configuration #defines are used. The configuration is
110 // partly below in this file, partly in WasmBCRegDefs.h.
111 //
112 // RABALDR_PIN_INSTANCE
113 // InstanceReg is not allocatable and always holds the current Instance*,
114 // except in known contexts where it could have been clobbered, such as after
115 // certain calls.
116 //
117 // RABALDR_ZERO_EXTENDS
118 // The canonical representation of a 32-bit value in a 64-bit register is
119 // zero-extended. For 64-bit platforms only. See comment block "64-bit GPRs
120 // carrying 32-bit values" in MacroAssembler.h.
121 //
122 // RABALDR_CHUNKY_STACK
123 // The platform must allocate the CPU stack in chunks and not word-at-a-time
124 // due to SP alignment requirements (ARM64 for now).
125 //
126 // RABALDR_INT_DIV_I64_CALLOUT
127 // The platform calls out to the runtime to divide i64/u64.
128 //
129 // RABALDR_I64_TO_FLOAT_CALLOUT
130 // The platform calls out to the runtime for i64 -> fXX conversions.
131 //
132 // RABALDR_FLOAT_TO_I64_CALLOUT
133 // The platform calls out to the runtime for fXX -> i64 conversions.
134 //
135 // RABALDR_SCRATCH_<TypeName>
136 // The baseline compiler has its own scratch registers for the given type, it
137 // does not use the MacroAssembler's scratch. This is really an anachronism -
138 // the baseline compiler should never use the MacroAssembler's scratches.
139 //
140 // RABALDR_SCRATCH_F32_ALIASES_F64
141 // On a platform where the baseline compiler has its own F32 and F64
142 // scratches, these are the same register.
143
144 #ifdef JS_CODEGEN_X64
145 # define RABALDR_ZERO_EXTENDS
146 # define RABALDR_PIN_INSTANCE
147 #endif
148
149 #ifdef JS_CODEGEN_ARM64
150 # define RABALDR_CHUNKY_STACK
151 # define RABALDR_ZERO_EXTENDS
152 # define RABALDR_PIN_INSTANCE
153 #endif
154
155 #ifdef JS_CODEGEN_X86
156 # define RABALDR_INT_DIV_I64_CALLOUT
157 #endif
158
159 #ifdef JS_CODEGEN_ARM
160 # define RABALDR_INT_DIV_I64_CALLOUT
161 # define RABALDR_I64_TO_FLOAT_CALLOUT
162 # define RABALDR_FLOAT_TO_I64_CALLOUT
163 #endif
164
165 #ifdef JS_CODEGEN_MIPS64
166 # define RABALDR_PIN_INSTANCE
167 #endif
168
169 #ifdef JS_CODEGEN_LOONG64
170 # define RABALDR_PIN_INSTANCE
171 #endif
172
173 #ifdef JS_CODEGEN_RISCV64
174 # define RABALDR_PIN_INSTANCE
175 #endif
176
177 // Max number of pushes onto the value stack for any opcode or emitter that
178 // does not push a variable, unbounded amount (anything with multiple
179 // results). This includes also intermediate pushes such as values pushed as
180 // parameters for builtin calls.
181 //
182 // This limit is set quite high on purpose, so as to avoid brittleness. The
183 // true max value is likely no more than four or five.
184
185 static constexpr size_t MaxPushesPerOpcode = 10;
186
187 } // namespace wasm
188 } // namespace js
189
190 #endif // wasm_wasm_baseline_defs_h