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