| 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: the compiler object |
| 20 |
// and its supporting types. |
| 21 |
|
| 22 |
#ifndef wasm_wasm_baseline_object_h |
| 23 |
#define wasm_wasm_baseline_object_h |
| 24 |
|
| 25 |
#include "jit/PerfSpewer.h" |
| 26 |
#include "wasm/WasmBCDefs.h" |
| 27 |
#include "wasm/WasmBCFrame.h" |
| 28 |
#include "wasm/WasmBCRegDefs.h" |
| 29 |
#include "wasm/WasmBCStk.h" |
| 30 |
#include "wasm/WasmConstants.h" |
| 31 |
|
| 32 |
namespace js { |
| 33 |
namespace wasm { |
| 34 |
|
| 35 |
// Container for a piece of out-of-line code, the slow path that supports an |
| 36 |
// operation. |
| 37 |
class OutOfLineCode; |
| 38 |
|
| 39 |
// Part of the inter-bytecode state for the boolean-evaluation-for-control |
| 40 |
// optimization. |
| 41 |
struct BranchState; |
| 42 |
|
| 43 |
// Representation of wasm local variables. |
| 44 |
using Local = BaseStackFrame::Local; |
| 45 |
|
| 46 |
// Bitset used for simple bounds check elimination. Capping this at 64 locals |
| 47 |
// makes sense; even 32 locals would probably be OK in practice. |
| 48 |
// |
| 49 |
// For more information about BCE, see the block comment in WasmBCMemory.cpp. |
| 50 |
using BCESet = uint64_t; |
| 51 |
|
| 52 |
// Information stored in the control node for generating exception handling |
| 53 |
// landing pads. |
| 54 |
struct CatchInfo { |
| 55 |
uint32_t tagIndex; // Index for the associated exception. |
| 56 |
NonAssertingLabel label; // The entry label for the handler. |
| 57 |
|
| 58 |
explicit CatchInfo(uint32_t tagIndex_) : tagIndex(tagIndex_) {} |
| 59 |
}; |
| 60 |
|
| 61 |
using CatchInfoVector = Vector<CatchInfo, 1, SystemAllocPolicy>; |
| 62 |
|
| 63 |
// Control node, representing labels and stack heights at join points. |
| 64 |
struct Control { |
| 65 |
NonAssertingLabel label; // The "exit" label |
| 66 |
NonAssertingLabel otherLabel; // Used for the "else" branch of if-then-else |
| 67 |
// and to allow delegate to jump to catches. |
| 68 |
StackHeight stackHeight; // From BaseStackFrame |
| 69 |
uint32_t stackSize; // Value stack height |
| 70 |
BCESet bceSafeOnEntry; // Bounds check info flowing into the item |
| 71 |
BCESet bceSafeOnExit; // Bounds check info flowing out of the item |
| 72 |
bool deadOnArrival; // deadCode_ was set on entry to the region |
| 73 |
bool deadThenBranch; // deadCode_ was set on exit from "then" |
| 74 |
size_t tryNoteIndex; // For tracking try branch code ranges. |
| 75 |
CatchInfoVector catchInfos; // Used for try-catch handlers. |
| 76 |
size_t loopBytecodeStart; // For LT: bytecode offset of start of a loop. |
| 77 |
CodeOffset offsetOfCtrDec; // For LT: masm offset of loop's counter decr. |
| 78 |
|
| 79 |
Control() |
| 80 |
: stackHeight(StackHeight::Invalid()), |
| 81 |
stackSize(UINT32_MAX), |
| 82 |
bceSafeOnEntry(0), |
| 83 |
bceSafeOnExit(~BCESet(0)), |
| 84 |
deadOnArrival(false), |
| 85 |
deadThenBranch(false), |
| 86 |
tryNoteIndex(0), |
| 87 |
loopBytecodeStart(UINTPTR_MAX), |
| 88 |
offsetOfCtrDec(CodeOffset()) {} |
| 89 |
|
| 90 |
Control(Control&&) = default; |
| 91 |
Control(const Control&) = delete; |
| 92 |
}; |
| 93 |
|
| 94 |
// A vector of Nothing values, used for reading opcodes. |
| 95 |
class BaseNothingVector { |
| 96 |
mozilla::Nothing unused_; |
| 97 |
|
| 98 |
public: |
| 99 |
bool reserve(size_t size) { return true; } |
| 100 |
bool resize(size_t length) { return true; } |
| 101 |
mozilla::Nothing& operator[](size_t) { return unused_; } |
| 102 |
mozilla::Nothing& back() { return unused_; } |
| 103 |
size_t length() const { return 0; } |
| 104 |
bool append(mozilla::Nothing& nothing) { return true; } |
| 105 |
void infallibleAppend(mozilla::Nothing& nothing) {} |
| 106 |
}; |
| 107 |
|
| 108 |
// The baseline compiler tracks values on a stack of its own -- it needs to scan |
| 109 |
// that stack for spilling -- and thus has no need for the values maintained by |
| 110 |
// the iterator. |
| 111 |
struct BaseCompilePolicy { |
| 112 |
using Value = mozilla::Nothing; |
| 113 |
using ValueVector = BaseNothingVector; |
| 114 |
|
| 115 |
// The baseline compiler uses the iterator's control stack, attaching |
| 116 |
// its own control information. |
| 117 |
using ControlItem = Control; |
| 118 |
}; |
| 119 |
|
| 120 |
using BaseOpIter = OpIter<BaseCompilePolicy>; |
| 121 |
|
| 122 |
// Latent operation for boolean-evaluation-for-control optimization. |
| 123 |
enum class LatentOp { None, Compare, Eqz }; |
| 124 |
|
| 125 |
// Encapsulate the checking needed for a memory access. |
| 126 |
struct AccessCheck { |
| 127 |
AccessCheck() |
| 128 |
: omitBoundsCheck(false), |
| 129 |
omitAlignmentCheck(false), |
| 130 |
onlyPointerAlignment(false) {} |
| 131 |
|
| 132 |
// If `omitAlignmentCheck` is true then we need check neither the |
| 133 |
// pointer nor the offset. Otherwise, if `onlyPointerAlignment` is true |
| 134 |
// then we need check only the pointer. Otherwise, check the sum of |
| 135 |
// pointer and offset. |
| 136 |
|
| 137 |
bool omitBoundsCheck; |
| 138 |
bool omitAlignmentCheck; |
| 139 |
bool onlyPointerAlignment; |
| 140 |
}; |
| 141 |
|
| 142 |
// Encapsulate all the information about a function call. |
| 143 |
struct FunctionCall { |
| 144 |
FunctionCall() |
| 145 |
: restoreRegisterStateAndRealm(false), |
| 146 |
usesSystemAbi(false), |
| 147 |
#ifdef JS_CODEGEN_ARM |
| 148 |
hardFP(true), |
| 149 |
#endif |
| 150 |
frameAlignAdjustment(0), |
| 151 |
stackArgAreaSize(0) { |
| 152 |
} |
| 153 |
|
| 154 |
WasmABIArgGenerator abi; |
| 155 |
bool restoreRegisterStateAndRealm; |
| 156 |
bool usesSystemAbi; |
| 157 |
#ifdef JS_CODEGEN_ARM |
| 158 |
bool hardFP; |
| 159 |
#endif |
| 160 |
size_t frameAlignAdjustment; |
| 161 |
size_t stackArgAreaSize; |
| 162 |
}; |
| 163 |
|
| 164 |
enum class PreBarrierKind { |
| 165 |
// No pre-write barrier is required because the previous value is undefined. |
| 166 |
None, |
| 167 |
// Perform a pre-write barrier to mark the previous value if an incremental |
| 168 |
// GC is underway. |
| 169 |
Normal, |
| 170 |
}; |
| 171 |
|
| 172 |
enum class PostBarrierKind { |
| 173 |
// Add a store buffer entry if the new value requires it, but do not attempt |
| 174 |
// to remove a pre-existing entry. |
| 175 |
Imprecise, |
| 176 |
// Remove an existing store buffer entry if the new value does not require |
| 177 |
// one. This is required to preserve invariants with HeapPtr when used for |
| 178 |
// movable storage. |
| 179 |
Precise, |
| 180 |
// Add a store buffer entry for the entire cell (e.g. the entire struct or |
| 181 |
// array who now has a field pointing into the nursery). |
| 182 |
WholeCell, |
| 183 |
}; |
| 184 |
|
| 185 |
struct BranchIfRefSubtypeRegisters { |
| 186 |
RegPtr superSTV; |
| 187 |
RegI32 scratch1; |
| 188 |
RegI32 scratch2; |
| 189 |
}; |
| 190 |
|
| 191 |
////////////////////////////////////////////////////////////////////////////// |
| 192 |
// |
| 193 |
// Wasm baseline compiler proper. |
| 194 |
// |
| 195 |
// This is a struct and not a class because there is no real benefit to hiding |
| 196 |
// anything, and because many static functions that are wrappers for masm |
| 197 |
// methods need to reach into it and would otherwise have to be declared as |
| 198 |
// friends. |
| 199 |
// |
| 200 |
// (Members generally have a '_' suffix but some don't because they are |
| 201 |
// referenced everywhere and it would be tedious to spell that out.) |
| 202 |
|
| 203 |
struct BaseCompiler final { |
| 204 |
/////////////////////////////////////////////////////////////////////////// |
| 205 |
// |
| 206 |
// Private types |
| 207 |
|
| 208 |
using LabelVector = Vector<NonAssertingLabel, 8, SystemAllocPolicy>; |
| 209 |
|
| 210 |
/////////////////////////////////////////////////////////////////////////// |
| 211 |
// |
| 212 |
// Read-only and write-once members. |
| 213 |
|
| 214 |
// Static compilation environment. |
| 215 |
const CodeMetadata& codeMeta_; |
| 216 |
const CompilerEnvironment& compilerEnv_; |
| 217 |
const FuncCompileInput& func_; |
| 218 |
const ValTypeVector& locals_; |
| 219 |
|
| 220 |
// Information about the locations of locals, this is set up during |
| 221 |
// initialization and read-only after that. |
| 222 |
BaseStackFrame::LocalVector localInfo_; |
| 223 |
|
| 224 |
// On specific platforms we sometimes need to use specific registers. |
| 225 |
const SpecificRegs specific_; |
| 226 |
|
| 227 |
// SigD and SigF are single-entry parameter lists for f64 and f32, these are |
| 228 |
// created during initialization. |
| 229 |
ValTypeVector SigD_; |
| 230 |
ValTypeVector SigF_; |
| 231 |
|
| 232 |
// Where to go to to return, bound as compilation ends. |
| 233 |
NonAssertingLabel returnLabel_; |
| 234 |
|
| 235 |
// Prologue and epilogue offsets, initialized during prologue and epilogue |
| 236 |
// generation and only used by the caller. |
| 237 |
FuncOffsets offsets_; |
| 238 |
|
| 239 |
// We call this address from the breakable point when the (per-module) debug |
| 240 |
// stub pointer in the Instance is not null. |
| 241 |
NonAssertingLabel perFunctionDebugStub_; |
| 242 |
uint32_t previousBreakablePoint_; |
| 243 |
|
| 244 |
// BaselineCompileFunctions() "lends" us the StkVector to use in this |
| 245 |
// BaseCompiler object, and that is installed in |stk_| in our constructor. |
| 246 |
// This is so as to avoid having to malloc/free the vector's contents at |
| 247 |
// each creation/destruction of a BaseCompiler object. It does however mean |
| 248 |
// that we need to hold on to a reference to BaselineCompileFunctions()'s |
| 249 |
// vector, so we can swap (give) its contents back when this BaseCompiler |
| 250 |
// object is destroyed. This significantly reduces the heap turnover of the |
| 251 |
// baseline compiler. See bug 1532592. |
| 252 |
StkVector& stkSource_; |
| 253 |
|
| 254 |
/////////////////////////////////////////////////////////////////////////// |
| 255 |
// |
| 256 |
// Output-only data structures. |
| 257 |
|
| 258 |
// Bump allocator for temporary memory, used for the value stack and |
| 259 |
// out-of-line code blobs. Bump-allocated memory is not freed until the end |
| 260 |
// of the compilation. |
| 261 |
TempAllocator::Fallible alloc_; |
| 262 |
|
| 263 |
// Machine code emitter. |
| 264 |
MacroAssembler& masm; |
| 265 |
|
| 266 |
// Perf spewer for annotated JIT code while profiling. |
| 267 |
WasmBaselinePerfSpewer perfSpewer_; |
| 268 |
|
| 269 |
/////////////////////////////////////////////////////////////////////////// |
| 270 |
// |
| 271 |
// Compilation state. |
| 272 |
|
| 273 |
// Decoder for this function, used for misc error reporting. |
| 274 |
Decoder& decoder_; |
| 275 |
|
| 276 |
// Opcode reader. |
| 277 |
BaseOpIter iter_; |
| 278 |
|
| 279 |
// Register allocator. |
| 280 |
BaseRegAlloc ra; |
| 281 |
|
| 282 |
// Stack frame abstraction. |
| 283 |
BaseStackFrame fr; |
| 284 |
|
| 285 |
// Latent out of line support code for some operations, code for these will be |
| 286 |
// emitted at the end of compilation. |
| 287 |
Vector<OutOfLineCode*, 8, SystemAllocPolicy> outOfLine_; |
| 288 |
|
| 289 |
// Stack map state. This keeps track of live pointer slots and allows precise |
| 290 |
// stack maps to be generated at safe points. |
| 291 |
StackMapGenerator stackMapGenerator_; |
| 292 |
|
| 293 |
// Wasm value stack. This maps values on the wasm stack to values in the |
| 294 |
// running code and their locations. |
| 295 |
// |
| 296 |
// The value stack facilitates on-the-fly register allocation and the use of |
| 297 |
// immediates in instructions. It tracks latent constants, latent references |
| 298 |
// to locals, register contents, and values that have been flushed to the CPU |
| 299 |
// stack. |
| 300 |
// |
| 301 |
// The stack can be flushed to the CPU stack using sync(). |
| 302 |
// |
| 303 |
// The stack is a StkVector rather than a StkVector& since constantly |
| 304 |
// dereferencing a StkVector& has been shown to add 0.5% or more to the |
| 305 |
// compiler's dynamic instruction count. |
| 306 |
StkVector stk_; |
| 307 |
|
| 308 |
// Flag indicating that the compiler is currently in a dead code region. |
| 309 |
bool deadCode_; |
| 310 |
|
| 311 |
// Store previously finished note to know if we need to insert a nop in |
| 312 |
// finishTryNote. |
| 313 |
size_t mostRecentFinishedTryNoteIndex_; |
| 314 |
|
| 315 |
/////////////////////////////////////////////////////////////////////////// |
| 316 |
// |
| 317 |
// State for bounds check elimination. |
| 318 |
|
| 319 |
// Locals that have been bounds checked and not updated since |
| 320 |
BCESet bceSafe_; |
| 321 |
|
| 322 |
/////////////////////////////////////////////////////////////////////////// |
| 323 |
// |
| 324 |
// State for boolean-evaluation-for-control. |
| 325 |
|
| 326 |
// Latent operation for branch (seen next) |
| 327 |
LatentOp latentOp_; |
| 328 |
|
| 329 |
// Operand type, if latentOp_ is true |
| 330 |
ValType latentType_; |
| 331 |
|
| 332 |
// Comparison operator, if latentOp_ == Compare, int types |
| 333 |
Assembler::Condition latentIntCmp_; |
| 334 |
|
| 335 |
// Comparison operator, if latentOp_ == Compare, float types |
| 336 |
Assembler::DoubleCondition latentDoubleCmp_; |
| 337 |
|
| 338 |
/////////////////////////////////////////////////////////////////////////// |
| 339 |
// |
| 340 |
// Main compilation API. |
| 341 |
// |
| 342 |
// A client will create a compiler object, and then call init(), |
| 343 |
// emitFunction(), and finish() in that order. |
| 344 |
|
| 345 |
BaseCompiler(const CodeMetadata& codeMetadata, |
| 346 |
const CompilerEnvironment& compilerEnv, |
| 347 |
const FuncCompileInput& func, const ValTypeVector& locals, |
| 348 |
const RegisterOffsets& trapExitLayout, |
| 349 |
size_t trapExitLayoutNumWords, Decoder& decoder, |
| 350 |
StkVector& stkSource, TempAllocator* alloc, MacroAssembler* masm, |
| 351 |
StackMaps* stackMaps); |
| 352 |
~BaseCompiler(); |
| 353 |
|
| 354 |
[[nodiscard]] bool init(); |
| 355 |
[[nodiscard]] bool emitFunction(); |
| 356 |
[[nodiscard]] FuncOffsets finish(); |
| 357 |
|
| 358 |
////////////////////////////////////////////////////////////////////////////// |
| 359 |
// |
| 360 |
// Sundry accessor abstractions and convenience predicates. |
| 361 |
// |
| 362 |
// WasmBaselineObject-inl.h. |
| 363 |
|
| 364 |
inline const FuncType& funcType() const; |
| 365 |
inline bool usesMemory() const; |
| 366 |
inline bool usesSharedMemory(uint32_t memoryIndex) const; |
| 367 |
inline bool isMem32(uint32_t memoryIndex) const; |
| 368 |
inline bool isMem64(uint32_t memoryIndex) const; |
| 369 |
inline bool hugeMemoryEnabled(uint32_t memoryIndex) const; |
| 370 |
inline uint32_t instanceOffsetOfMemoryBase(uint32_t memoryIndex) const; |
| 371 |
inline uint32_t instanceOffsetOfBoundsCheckLimit(uint32_t memoryIndex) const; |
| 372 |
|
| 373 |
// The casts are used by some of the ScratchRegister implementations. |
| 374 |
operator MacroAssembler&() const { return masm; } |
| 375 |
operator BaseRegAlloc&() { return ra; } |
| 376 |
|
| 377 |
////////////////////////////////////////////////////////////////////////////// |
| 378 |
// |
| 379 |
// Locals. |
| 380 |
// |
| 381 |
// WasmBaselineObject-inl.h. |
| 382 |
|
| 383 |
// Assert that the local at the given index has the given type, and return a |
| 384 |
// reference to the Local. |
| 385 |
inline const Local& localFromSlot(uint32_t slot, MIRType type); |
| 386 |
|
| 387 |
////////////////////////////////////////////////////////////////////////////// |
| 388 |
// |
| 389 |
// Out of line code management. |
| 390 |
|
| 391 |
[[nodiscard]] OutOfLineCode* addOutOfLineCode(OutOfLineCode* ool); |
| 392 |
[[nodiscard]] bool generateOutOfLineCode(); |
| 393 |
|
| 394 |
///////////////////////////////////////////////////////////////////////////// |
| 395 |
// |
| 396 |
// Layering in the compiler (briefly). |
| 397 |
// |
| 398 |
// At the lowest layers are abstractions for registers (managed by the |
| 399 |
// BaseRegAlloc and the wrappers below) and the stack frame (managed by the |
| 400 |
// BaseStackFrame). |
| 401 |
// |
| 402 |
// The registers and frame are in turn used by the value abstraction, which is |
| 403 |
// implemented by the Stk type and backed by the value stack. Values may be |
| 404 |
// stored in registers, in the frame, or may be latent constants, and the |
| 405 |
// value stack handles storage mostly transparently in its push and pop |
| 406 |
// routines. |
| 407 |
// |
| 408 |
// In turn, the pop routines bring values into registers so that we can |
| 409 |
// compute on them, and the push routines move values to the stack (where they |
| 410 |
// may still reside in registers until the registers are needed or the value |
| 411 |
// must be in memory). |
| 412 |
// |
| 413 |
// Routines for managing parameters and results (for blocks or calls) may also |
| 414 |
// manipulate the stack directly. |
| 415 |
// |
| 416 |
// At the top are the code generators: methods that use the poppers and |
| 417 |
// pushers and other utilities to move values into place, and that emit code |
| 418 |
// to compute on those values or change control flow. |
| 419 |
|
| 420 |
///////////////////////////////////////////////////////////////////////////// |
| 421 |
// |
| 422 |
// Register management. These are simply strongly-typed wrappers that |
| 423 |
// delegate to the register allocator. |
| 424 |
|
| 425 |
inline bool isAvailableI32(RegI32 r); |
| 426 |
inline bool isAvailableI64(RegI64 r); |
| 427 |
inline bool isAvailableRef(RegRef r); |
| 428 |
inline bool isAvailablePtr(RegPtr r); |
| 429 |
inline bool isAvailableF32(RegF32 r); |
| 430 |
inline bool isAvailableF64(RegF64 r); |
| 431 |
#ifdef ENABLE_WASM_SIMD |
| 432 |
inline bool isAvailableV128(RegV128 r); |
| 433 |
#endif |
| 434 |
|
| 435 |
// Allocate any register |
| 436 |
[[nodiscard]] inline RegI32 needI32(); |
| 437 |
[[nodiscard]] inline RegI64 needI64(); |
| 438 |
[[nodiscard]] inline RegRef needRef(); |
| 439 |
[[nodiscard]] inline RegPtr needPtr(); |
| 440 |
[[nodiscard]] inline RegF32 needF32(); |
| 441 |
[[nodiscard]] inline RegF64 needF64(); |
| 442 |
#ifdef ENABLE_WASM_SIMD |
| 443 |
[[nodiscard]] inline RegV128 needV128(); |
| 444 |
#endif |
| 445 |
|
| 446 |
// Allocate a specific register |
| 447 |
inline void needI32(RegI32 specific); |
| 448 |
inline void needI64(RegI64 specific); |
| 449 |
inline void needRef(RegRef specific); |
| 450 |
inline void needPtr(RegPtr specific); |
| 451 |
inline void needF32(RegF32 specific); |
| 452 |
inline void needF64(RegF64 specific); |
| 453 |
#ifdef ENABLE_WASM_SIMD |
| 454 |
inline void needV128(RegV128 specific); |
| 455 |
#endif |
| 456 |
|
| 457 |
template <typename RegType> |
| 458 |
inline RegType need(); |
| 459 |
|
| 460 |
// Just a shorthand. |
| 461 |
inline void need2xI32(RegI32 r0, RegI32 r1); |
| 462 |
inline void need2xI64(RegI64 r0, RegI64 r1); |
| 463 |
|
| 464 |
// Get a register but do not sync the stack to free one up. This will crash |
| 465 |
// if no register is available. |
| 466 |
inline void needI32NoSync(RegI32 r); |
| 467 |
|
| 468 |
#if defined(JS_CODEGEN_ARM) |
| 469 |
// Allocate a specific register pair (even-odd register numbers). |
| 470 |
[[nodiscard]] inline RegI64 needI64Pair(); |
| 471 |
#endif |
| 472 |
|
| 473 |
inline void freeAny(AnyReg r); |
| 474 |
inline void freeI32(RegI32 r); |
| 475 |
inline void freeI64(RegI64 r); |
| 476 |
inline void freeRef(RegRef r); |
| 477 |
inline void freePtr(RegPtr r); |
| 478 |
inline void freeF32(RegF32 r); |
| 479 |
inline void freeF64(RegF64 r); |
| 480 |
#ifdef ENABLE_WASM_SIMD |
| 481 |
inline void freeV128(RegV128 r); |
| 482 |
#endif |
| 483 |
|
| 484 |
template <typename RegType> |
| 485 |
inline void free(RegType r); |
| 486 |
|
| 487 |
// Free r if it is not invalid. |
| 488 |
inline void maybeFree(RegI32 r); |
| 489 |
inline void maybeFree(RegI64 r); |
| 490 |
inline void maybeFree(RegF32 r); |
| 491 |
inline void maybeFree(RegF64 r); |
| 492 |
inline void maybeFree(RegRef r); |
| 493 |
inline void maybeFree(RegPtr r); |
| 494 |
#ifdef ENABLE_WASM_SIMD |
| 495 |
inline void maybeFree(RegV128 r); |
| 496 |
#endif |
| 497 |
|
| 498 |
// On 64-bit systems, `except` must equal r and this is a no-op. On 32-bit |
| 499 |
// systems, `except` must equal the high or low part of a pair and the other |
| 500 |
// part of the pair is freed. |
| 501 |
inline void freeI64Except(RegI64 r, RegI32 except); |
| 502 |
|
| 503 |
// Return the 32-bit low part of the 64-bit register, do not free anything. |
| 504 |
inline RegI32 fromI64(RegI64 r); |
| 505 |
|
| 506 |
// If r is valid, return fromI64(r), otherwise an invalid RegI32. |
| 507 |
inline RegI32 maybeFromI64(RegI64 r); |
| 508 |
|
| 509 |
#ifdef JS_PUNBOX64 |
| 510 |
// On 64-bit systems, reinterpret r as 64-bit. |
| 511 |
inline RegI64 fromI32(RegI32 r); |
| 512 |
#endif |
| 513 |
|
| 514 |
// Widen r to 64 bits; this may allocate another register to form a pair. |
| 515 |
// Note this does not generate code for sign/zero extension. |
| 516 |
inline RegI64 widenI32(RegI32 r); |
| 517 |
|
| 518 |
// Narrow r to 32 bits; this may free part of a pair. Note this does not |
| 519 |
// generate code to canonicalize the value on 64-bit systems. |
| 520 |
inline RegI32 narrowI64(RegI64 r); |
| 521 |
inline RegI32 narrowRef(RegRef r); |
| 522 |
|
| 523 |
// Return the 32-bit low part of r. |
| 524 |
inline RegI32 lowPart(RegI64 r); |
| 525 |
|
| 526 |
// On 64-bit systems, return an invalid register. On 32-bit systems, return |
| 527 |
// the low part of a pair. |
| 528 |
inline RegI32 maybeHighPart(RegI64 r); |
| 529 |
|
| 530 |
////////////////////////////////////////////////////////////////////////////// |
| 531 |
// |
| 532 |
// Values and value stack: Low-level methods for moving Stk values of specific |
| 533 |
// kinds to registers. |
| 534 |
|
| 535 |
inline void loadConstI32(const Stk& src, RegI32 dest); |
| 536 |
inline void loadMemI32(const Stk& src, RegI32 dest); |
| 537 |
inline void loadLocalI32(const Stk& src, RegI32 dest); |
| 538 |
inline void loadRegisterI32(const Stk& src, RegI32 dest); |
| 539 |
inline void loadConstI64(const Stk& src, RegI64 dest); |
| 540 |
inline void loadMemI64(const Stk& src, RegI64 dest); |
| 541 |
inline void loadLocalI64(const Stk& src, RegI64 dest); |
| 542 |
inline void loadRegisterI64(const Stk& src, RegI64 dest); |
| 543 |
inline void loadConstRef(const Stk& src, RegRef dest); |
| 544 |
inline void loadMemRef(const Stk& src, RegRef dest); |
| 545 |
inline void loadLocalRef(const Stk& src, RegRef dest); |
| 546 |
inline void loadRegisterRef(const Stk& src, RegRef dest); |
| 547 |
inline void loadConstF64(const Stk& src, RegF64 dest); |
| 548 |
inline void loadMemF64(const Stk& src, RegF64 dest); |
| 549 |
inline void loadLocalF64(const Stk& src, RegF64 dest); |
| 550 |
inline void loadRegisterF64(const Stk& src, RegF64 dest); |
| 551 |
inline void loadConstF32(const Stk& src, RegF32 dest); |
| 552 |
inline void loadMemF32(const Stk& src, RegF32 dest); |
| 553 |
inline void loadLocalF32(const Stk& src, RegF32 dest); |
| 554 |
inline void loadRegisterF32(const Stk& src, RegF32 dest); |
| 555 |
#ifdef ENABLE_WASM_SIMD |
| 556 |
inline void loadConstV128(const Stk& src, RegV128 dest); |
| 557 |
inline void loadMemV128(const Stk& src, RegV128 dest); |
| 558 |
inline void loadLocalV128(const Stk& src, RegV128 dest); |
| 559 |
inline void loadRegisterV128(const Stk& src, RegV128 dest); |
| 560 |
#endif |
| 561 |
|
| 562 |
////////////////////////////////////////////////////////////////////////// |
| 563 |
// |
| 564 |
// Values and value stack: Mid-level routines for moving Stk values of any |
| 565 |
// kind to registers. |
| 566 |
|
| 567 |
inline void loadI32(const Stk& src, RegI32 dest); |
| 568 |
inline void loadI64(const Stk& src, RegI64 dest); |
| 569 |
#if !defined(JS_PUNBOX64) |
| 570 |
inline void loadI64Low(const Stk& src, RegI32 dest); |
| 571 |
inline void loadI64High(const Stk& src, RegI32 dest); |
| 572 |
#endif |
| 573 |
inline void loadF64(const Stk& src, RegF64 dest); |
| 574 |
inline void loadF32(const Stk& src, RegF32 dest); |
| 575 |
#ifdef ENABLE_WASM_SIMD |
| 576 |
inline void loadV128(const Stk& src, RegV128 dest); |
| 577 |
#endif |
| 578 |
inline void loadRef(const Stk& src, RegRef dest); |
| 579 |
|
| 580 |
////////////////////////////////////////////////////////////////////// |
| 581 |
// |
| 582 |
// Value stack: stack management. |
| 583 |
|
| 584 |
// Flush all local and register value stack elements to memory. |
| 585 |
inline void sync(); |
| 586 |
|
| 587 |
// Save a register on the value stack temporarily. |
| 588 |
void saveTempPtr(const RegPtr& r); |
| 589 |
|
| 590 |
// Restore a temporarily saved register from the value stack. |
| 591 |
void restoreTempPtr(const RegPtr& r); |
| 592 |
|
| 593 |
// This is an optimization used to avoid calling sync for setLocal: if the |
| 594 |
// local does not exist unresolved on the value stack then we can skip the |
| 595 |
// sync. |
| 596 |
inline bool hasLocal(uint32_t slot); |
| 597 |
|
| 598 |
// Sync the local if necessary. (This currently syncs everything if a sync is |
| 599 |
// needed at all.) |
| 600 |
inline void syncLocal(uint32_t slot); |
| 601 |
|
| 602 |
// Return the amount of execution stack consumed by the top numval |
| 603 |
// values on the value stack. |
| 604 |
inline size_t stackConsumed(size_t numval); |
| 605 |
|
| 606 |
// Drop one value off the stack, possibly also moving the physical stack |
| 607 |
// pointer. |
| 608 |
inline void dropValue(); |
| 609 |
|
| 610 |
#ifdef DEBUG |
| 611 |
// Check that we're not leaking registers by comparing the |
| 612 |
// state of the stack + available registers with the set of |
| 613 |
// all available registers. |
| 614 |
|
| 615 |
// Call this between opcodes. |
| 616 |
void performRegisterLeakCheck(); |
| 617 |
|
| 618 |
// This can be called at any point, really, but typically just after |
| 619 |
// performRegisterLeakCheck(). |
| 620 |
void assertStackInvariants() const; |
| 621 |
|
| 622 |
// Count the number of memory references on the value stack. |
| 623 |
inline size_t countMemRefsOnStk(); |
| 624 |
|
| 625 |
// Print the stack to stderr. |
| 626 |
void showStack(const char* who) const; |
| 627 |
#endif |
| 628 |
|
| 629 |
////////////////////////////////////////////////////////////////////// |
| 630 |
// |
| 631 |
// Value stack: pushers of values. |
| 632 |
|
| 633 |
// Push a register onto the value stack. |
| 634 |
inline void pushAny(AnyReg r); |
| 635 |
inline void pushI32(RegI32 r); |
| 636 |
inline void pushI64(RegI64 r); |
| 637 |
inline void pushRef(RegRef r); |
| 638 |
inline void pushPtr(RegPtr r); |
| 639 |
inline void pushF64(RegF64 r); |
| 640 |
inline void pushF32(RegF32 r); |
| 641 |
#ifdef ENABLE_WASM_SIMD |
| 642 |
inline void pushV128(RegV128 r); |
| 643 |
#endif |
| 644 |
|
| 645 |
// Template variation of the foregoing, for use by templated emitters. |
| 646 |
template <typename RegType> |
| 647 |
inline void push(RegType item); |
| 648 |
|
| 649 |
// Push a constant value onto the stack. pushI32 can also take uint32_t, and |
| 650 |
// pushI64 can take uint64_t; the semantics are the same. Appropriate sign |
| 651 |
// extension for a 32-bit value on a 64-bit architecture happens when the |
| 652 |
// value is popped, see the definition of moveImm32. |
| 653 |
inline void pushI32(int32_t v); |
| 654 |
inline void pushI64(int64_t v); |
| 655 |
inline void pushRef(intptr_t v); |
| 656 |
inline void pushPtr(intptr_t v); |
| 657 |
inline void pushF64(double v); |
| 658 |
inline void pushF32(float v); |
| 659 |
#ifdef ENABLE_WASM_SIMD |
| 660 |
inline void pushV128(V128 v); |
| 661 |
#endif |
| 662 |
inline void pushConstRef(intptr_t v); |
| 663 |
|
| 664 |
// Push the local slot onto the stack. The slot will not be read here; it |
| 665 |
// will be read when it is consumed, or when a side effect to the slot forces |
| 666 |
// its value to be saved. |
| 667 |
inline void pushLocalI32(uint32_t slot); |
| 668 |
inline void pushLocalI64(uint32_t slot); |
| 669 |
inline void pushLocalRef(uint32_t slot); |
| 670 |
inline void pushLocalF64(uint32_t slot); |
| 671 |
inline void pushLocalF32(uint32_t slot); |
| 672 |
#ifdef ENABLE_WASM_SIMD |
| 673 |
inline void pushLocalV128(uint32_t slot); |
| 674 |
#endif |
| 675 |
|
| 676 |
// Push an U32 as an I64, zero-extending it in the process |
| 677 |
inline void pushU32AsI64(RegI32 rs); |
| 678 |
|
| 679 |
////////////////////////////////////////////////////////////////////// |
| 680 |
// |
| 681 |
// Value stack: poppers and peekers of values. |
| 682 |
|
| 683 |
// Pop some value off the stack. |
| 684 |
inline AnyReg popAny(); |
| 685 |
inline AnyReg popAny(AnyReg specific); |
| 686 |
|
| 687 |
// Call only from other popI32() variants. v must be the stack top. May pop |
| 688 |
// the CPU stack. |
| 689 |
inline void popI32(const Stk& v, RegI32 dest); |
| 690 |
|
| 691 |
[[nodiscard]] inline RegI32 popI32(); |
| 692 |
inline RegI32 popI32(RegI32 specific); |
| 693 |
|
| 694 |
#ifdef ENABLE_WASM_SIMD |
| 695 |
// Call only from other popV128() variants. v must be the stack top. May pop |
| 696 |
// the CPU stack. |
| 697 |
inline void popV128(const Stk& v, RegV128 dest); |
| 698 |
|
| 699 |
[[nodiscard]] inline RegV128 popV128(); |
| 700 |
inline RegV128 popV128(RegV128 specific); |
| 701 |
#endif |
| 702 |
|
| 703 |
// Call only from other popI64() variants. v must be the stack top. May pop |
| 704 |
// the CPU stack. |
| 705 |
inline void popI64(const Stk& v, RegI64 dest); |
| 706 |
|
| 707 |
[[nodiscard]] inline RegI64 popI64(); |
| 708 |
inline RegI64 popI64(RegI64 specific); |
| 709 |
|
| 710 |
// Call only from other popRef() variants. v must be the stack top. May pop |
| 711 |
// the CPU stack. |
| 712 |
inline void popRef(const Stk& v, RegRef dest); |
| 713 |
|
| 714 |
inline RegRef popRef(RegRef specific); |
| 715 |
[[nodiscard]] inline RegRef popRef(); |
| 716 |
|
| 717 |
// Call only from other popPtr() variants. v must be the stack top. May pop |
| 718 |
// the CPU stack. |
| 719 |
inline void popPtr(const Stk& v, RegPtr dest); |
| 720 |
|
| 721 |
inline RegPtr popPtr(RegPtr specific); |
| 722 |
[[nodiscard]] inline RegPtr popPtr(); |
| 723 |
|
| 724 |
// Call only from other popF64() variants. v must be the stack top. May pop |
| 725 |
// the CPU stack. |
| 726 |
inline void popF64(const Stk& v, RegF64 dest); |
| 727 |
|
| 728 |
[[nodiscard]] inline RegF64 popF64(); |
| 729 |
inline RegF64 popF64(RegF64 specific); |
| 730 |
|
| 731 |
// Call only from other popF32() variants. v must be the stack top. May pop |
| 732 |
// the CPU stack. |
| 733 |
inline void popF32(const Stk& v, RegF32 dest); |
| 734 |
|
| 735 |
[[nodiscard]] inline RegF32 popF32(); |
| 736 |
inline RegF32 popF32(RegF32 specific); |
| 737 |
|
| 738 |
// Templated variation of the foregoing, for use by templated emitters. |
| 739 |
template <typename RegType> |
| 740 |
inline RegType pop(); |
| 741 |
|
| 742 |
// Constant poppers will return true and pop the value if the stack top is a |
| 743 |
// constant of the appropriate type; otherwise pop nothing and return false. |
| 744 |
[[nodiscard]] inline bool hasConst() const; |
| 745 |
[[nodiscard]] inline bool popConst(int32_t* c); |
| 746 |
[[nodiscard]] inline bool popConst(int64_t* c); |
| 747 |
[[nodiscard]] inline bool peekConst(int32_t* c); |
| 748 |
[[nodiscard]] inline bool peekConst(int64_t* c); |
| 749 |
[[nodiscard]] inline bool peek2xConst(int32_t* c0, int32_t* c1); |
| 750 |
[[nodiscard]] inline bool popConstPositivePowerOfTwo(int32_t* c, |
| 751 |
uint_fast8_t* power, |
| 752 |
int32_t cutoff); |
| 753 |
[[nodiscard]] inline bool popConstPositivePowerOfTwo(int64_t* c, |
| 754 |
uint_fast8_t* power, |
| 755 |
int64_t cutoff); |
| 756 |
|
| 757 |
// Shorthand: Pop r1, then r0. |
| 758 |
inline void pop2xI32(RegI32* r0, RegI32* r1); |
| 759 |
inline void pop2xI64(RegI64* r0, RegI64* r1); |
| 760 |
inline void pop2xF32(RegF32* r0, RegF32* r1); |
| 761 |
inline void pop2xF64(RegF64* r0, RegF64* r1); |
| 762 |
#ifdef ENABLE_WASM_SIMD |
| 763 |
inline void pop2xV128(RegV128* r0, RegV128* r1); |
| 764 |
#endif |
| 765 |
inline void pop2xRef(RegRef* r0, RegRef* r1); |
| 766 |
|
| 767 |
// Pop to a specific register |
| 768 |
inline RegI32 popI32ToSpecific(RegI32 specific); |
| 769 |
inline RegI64 popI64ToSpecific(RegI64 specific); |
| 770 |
|
| 771 |
#ifdef JS_CODEGEN_ARM |
| 772 |
// Pop an I64 as a valid register pair. |
| 773 |
inline RegI64 popI64Pair(); |
| 774 |
#endif |
| 775 |
|
| 776 |
// Pop an I64 but narrow it and return the narrowed part. |
| 777 |
inline RegI32 popI64ToI32(); |
| 778 |
inline RegI32 popI64ToSpecificI32(RegI32 specific); |
| 779 |
|
| 780 |
// Pop an I32 or I64 as an I64. The value is zero extended out to 64-bits. |
| 781 |
inline RegI64 popAddressToInt64(AddressType addressType); |
| 782 |
|
| 783 |
// Pop an I32 or I64 as an I32. The value is clamped to UINT32_MAX to ensure |
| 784 |
// that it trips bounds checks. |
| 785 |
inline RegI32 popTableAddressToClampedInt32(AddressType addressType); |
| 786 |
|
| 787 |
// A combined push/pop that replaces an I32 or I64 on the stack with a clamped |
| 788 |
// I32, which will trip bounds checks if out of I32 range. |
| 789 |
inline void replaceTableAddressWithClampedInt32(AddressType addressType); |
| 790 |
|
| 791 |
// Pop the stack until it has the desired size, but do not move the physical |
| 792 |
// stack pointer. |
| 793 |
inline void popValueStackTo(uint32_t stackSize); |
| 794 |
|
| 795 |
// Pop the given number of elements off the value stack, but do not move |
| 796 |
// the physical stack pointer. |
| 797 |
inline void popValueStackBy(uint32_t items); |
| 798 |
|
| 799 |
// Peek into the stack at relativeDepth from the top. |
| 800 |
inline Stk& peek(uint32_t relativeDepth); |
| 801 |
|
| 802 |
// Peek the reference value at the specified depth and load it into a |
| 803 |
// register. |
| 804 |
inline void peekRefAt(uint32_t depth, RegRef dest); |
| 805 |
|
| 806 |
// Peek at the value on the top of the stack and return true if it is a Local |
| 807 |
// of any type. |
| 808 |
[[nodiscard]] inline bool peekLocal(uint32_t* local); |
| 809 |
|
| 810 |
//////////////////////////////////////////////////////////////////////////// |
| 811 |
// |
| 812 |
// Block parameters and results. |
| 813 |
// |
| 814 |
// Blocks may have multiple parameters and multiple results. Blocks can also |
| 815 |
// be the target of branches: the entry for loops, and the exit for |
| 816 |
// non-loops. |
| 817 |
// |
| 818 |
// Passing multiple values to a non-branch target (i.e., the entry of a |
| 819 |
// "block") falls out naturally: any items on the value stack can flow |
| 820 |
// directly from one block to another. |
| 821 |
// |
| 822 |
// However, for branch targets, we need to allocate well-known locations for |
| 823 |
// the branch values. The approach taken in the baseline compiler is to |
| 824 |
// allocate registers to the top N values (currently N=1), and then stack |
| 825 |
// locations for the rest. |
| 826 |
// |
| 827 |
|
| 828 |
// Types of result registers that interest us for result-manipulating |
| 829 |
// functions. |
| 830 |
enum class ResultRegKind { |
| 831 |
// General and floating result registers. |
| 832 |
All, |
| 833 |
|
| 834 |
// General result registers only. |
| 835 |
OnlyGPRs |
| 836 |
}; |
| 837 |
|
| 838 |
// This is a flag ultimately intended for popBlockResults() that specifies how |
| 839 |
// the CPU stack should be handled after the result values have been |
| 840 |
// processed. |
| 841 |
enum class ContinuationKind { |
| 842 |
// Adjust the stack for a fallthrough: do nothing. |
| 843 |
Fallthrough, |
| 844 |
|
| 845 |
// Adjust the stack for a jump: make the stack conform to the |
| 846 |
// expected stack at the target |
| 847 |
Jump |
| 848 |
}; |
| 849 |
|
| 850 |
// TODO: It's definitely disputable whether the result register management is |
| 851 |
// hot enough to warrant inlining at the outermost level. |
| 852 |
|
| 853 |
inline void needResultRegisters(ResultType type, ResultRegKind which); |
| 854 |
#ifdef JS_64BIT |
| 855 |
inline void widenInt32ResultRegisters(ResultType type); |
| 856 |
#endif |
| 857 |
inline void freeResultRegisters(ResultType type, ResultRegKind which); |
| 858 |
inline void needIntegerResultRegisters(ResultType type); |
| 859 |
inline void freeIntegerResultRegisters(ResultType type); |
| 860 |
inline void needResultRegisters(ResultType type); |
| 861 |
inline void freeResultRegisters(ResultType type); |
| 862 |
void assertResultRegistersAvailable(ResultType type); |
| 863 |
inline void captureResultRegisters(ResultType type); |
| 864 |
inline void captureCallResultRegisters(ResultType type); |
| 865 |
|
| 866 |
void popRegisterResults(ABIResultIter& iter); |
| 867 |
void popStackResults(ABIResultIter& iter, StackHeight stackBase); |
| 868 |
|
| 869 |
void popBlockResults(ResultType type, StackHeight stackBase, |
| 870 |
ContinuationKind kind); |
| 871 |
|
| 872 |
// This function is similar to popBlockResults, but additionally handles the |
| 873 |
// implicit exception pointer that is pushed to the value stack on entry to |
| 874 |
// a catch handler by dropping it appropriately. |
| 875 |
void popCatchResults(ResultType type, StackHeight stackBase); |
| 876 |
|
| 877 |
Stk captureStackResult(const ABIResult& result, StackHeight resultsBase, |
| 878 |
uint32_t stackResultBytes); |
| 879 |
|
| 880 |
[[nodiscard]] bool pushResults(ResultType type, StackHeight resultsBase); |
| 881 |
[[nodiscard]] bool pushBlockResults(ResultType type); |
| 882 |
|
| 883 |
// A combination of popBlockResults + pushBlockResults, used when entering a |
| 884 |
// block with a control-flow join (loops) or split (if) to shuffle the |
| 885 |
// fallthrough block parameters into the locations expected by the |
| 886 |
// continuation. |
| 887 |
// |
| 888 |
// This function should only be called when entering a block with a |
| 889 |
// control-flow join at the entry, where there are no live temporaries in |
| 890 |
// the current block. |
| 891 |
[[nodiscard]] bool topBlockParams(ResultType type); |
| 892 |
|
| 893 |
// A combination of popBlockResults + pushBlockResults, used before branches |
| 894 |
// where we don't know the target (br_if / br_table). If and when the branch |
| 895 |
// is taken, the stack results will be shuffled down into place. For br_if |
| 896 |
// that has fallthrough, the parameters for the untaken branch flow through to |
| 897 |
// the continuation. |
| 898 |
[[nodiscard]] bool topBranchParams(ResultType type, StackHeight* height); |
| 899 |
|
| 900 |
// Conditional branches with fallthrough are preceded by a topBranchParams, so |
| 901 |
// we know that there are no stack results that need to be materialized. In |
| 902 |
// that case, we can just shuffle the whole block down before popping the |
| 903 |
// stack. |
| 904 |
void shuffleStackResultsBeforeBranch(StackHeight srcHeight, |
| 905 |
StackHeight destHeight, ResultType type); |
| 906 |
|
| 907 |
// If in debug mode, adds LeaveFrame breakpoint. |
| 908 |
bool insertDebugCollapseFrame(); |
| 909 |
|
| 910 |
////////////////////////////////////////////////////////////////////// |
| 911 |
// |
| 912 |
// Stack maps |
| 913 |
|
| 914 |
// Various methods for creating a stackmap. Stackmaps are indexed by the |
| 915 |
// lowest address of the instruction immediately *after* the instruction of |
| 916 |
// interest. In practice that means either: the return point of a call, the |
| 917 |
// instruction immediately after a trap instruction (the "resume" |
| 918 |
// instruction), or the instruction immediately following a no-op (when |
| 919 |
// debugging is enabled). |
| 920 |
|
| 921 |
// Create a vanilla stackmap. |
| 922 |
[[nodiscard]] bool createStackMap(const char* who); |
| 923 |
|
| 924 |
// Create a stackmap as vanilla, but for a custom assembler offset. |
| 925 |
[[nodiscard]] bool createStackMap(const char* who, |
| 926 |
CodeOffset assemblerOffset); |
| 927 |
|
| 928 |
// Create a stack map as vanilla, and note the presence of a ref-typed |
| 929 |
// DebugFrame on the stack. |
| 930 |
[[nodiscard]] bool createStackMap( |
| 931 |
const char* who, HasDebugFrameWithLiveRefs debugFrameWithLiveRefs); |
| 932 |
|
| 933 |
// The most general stackmap construction. |
| 934 |
[[nodiscard]] bool createStackMap( |
| 935 |
const char* who, const ExitStubMapVector& extras, |
| 936 |
uint32_t assemblerOffset, |
| 937 |
HasDebugFrameWithLiveRefs debugFrameWithLiveRefs); |
| 938 |
|
| 939 |
//////////////////////////////////////////////////////////// |
| 940 |
// |
| 941 |
// Control stack |
| 942 |
|
| 943 |
inline void initControl(Control& item, ResultType params); |
| 944 |
inline Control& controlItem(); |
| 945 |
inline Control& controlItem(uint32_t relativeDepth); |
| 946 |
inline Control& controlOutermost(); |
| 947 |
inline LabelKind controlKind(uint32_t relativeDepth); |
| 948 |
|
| 949 |
//////////////////////////////////////////////////////////// |
| 950 |
// |
| 951 |
// Debugger API |
| 952 |
|
| 953 |
// Insert a breakpoint almost anywhere. This will create a call, with all the |
| 954 |
// overhead that entails. |
| 955 |
void insertBreakablePoint(CallSiteKind kind); |
| 956 |
|
| 957 |
// Insert code at the end of a function for breakpoint filtering. |
| 958 |
void insertPerFunctionDebugStub(); |
| 959 |
|
| 960 |
// Debugger API used at the return point: shuffle register return values off |
| 961 |
// to memory for the debugger to see; and get them back again. |
| 962 |
void saveRegisterReturnValues(const ResultType& resultType); |
| 963 |
void restoreRegisterReturnValues(const ResultType& resultType); |
| 964 |
|
| 965 |
////////////////////////////////////////////////////////////////////// |
| 966 |
// |
| 967 |
// Function prologue and epilogue. |
| 968 |
|
| 969 |
// Set up and tear down frame, execute prologue and epilogue. |
| 970 |
[[nodiscard]] bool beginFunction(); |
| 971 |
[[nodiscard]] bool endFunction(); |
| 972 |
|
| 973 |
// Move return values to memory before returning, as appropriate |
| 974 |
void popStackReturnValues(const ResultType& resultType); |
| 975 |
|
| 976 |
////////////////////////////////////////////////////////////////////// |
| 977 |
// |
| 978 |
// Calls. |
| 979 |
|
| 980 |
void beginCall(FunctionCall& call, UseABI useABI, |
| 981 |
RestoreRegisterStateAndRealm restoreRegisterStateAndRealm); |
| 982 |
void endCall(FunctionCall& call, size_t stackSpace); |
| 983 |
void startCallArgs(size_t stackArgAreaSizeUnaligned, FunctionCall* call); |
| 984 |
ABIArg reservePointerArgument(FunctionCall* call); |
| 985 |
void passArg(ValType type, const Stk& arg, FunctionCall* call); |
| 986 |
CodeOffset callDefinition(uint32_t funcIndex, const FunctionCall& call); |
| 987 |
CodeOffset callSymbolic(SymbolicAddress callee, const FunctionCall& call); |
| 988 |
|
| 989 |
// Precondition for the call*() methods: sync() |
| 990 |
|
| 991 |
bool callIndirect(uint32_t funcTypeIndex, uint32_t tableIndex, |
| 992 |
const Stk& indexVal, const FunctionCall& call, |
| 993 |
bool tailCall, CodeOffset* fastCallOffset, |
| 994 |
CodeOffset* slowCallOffset); |
| 995 |
CodeOffset callImport(unsigned instanceDataOffset, const FunctionCall& call); |
| 996 |
bool updateCallRefMetrics(size_t callRefIndex); |
| 997 |
bool callRef(const Stk& calleeRef, const FunctionCall& call, |
| 998 |
mozilla::Maybe<size_t> callRefIndex, CodeOffset* fastCallOffset, |
| 999 |
CodeOffset* slowCallOffset); |
| 1000 |
void returnCallRef(const Stk& calleeRef, const FunctionCall& call, |
| 1001 |
const FuncType& funcType); |
| 1002 |
CodeOffset builtinCall(SymbolicAddress builtin, const FunctionCall& call); |
| 1003 |
CodeOffset builtinInstanceMethodCall(const SymbolicAddressSignature& builtin, |
| 1004 |
const ABIArg& instanceArg, |
| 1005 |
const FunctionCall& call); |
| 1006 |
[[nodiscard]] bool pushCallResults(const FunctionCall& call, ResultType type, |
| 1007 |
const StackResultsLoc& loc); |
| 1008 |
|
| 1009 |
// Helpers to pick up the returned value from the return register. |
| 1010 |
inline RegI32 captureReturnedI32(); |
| 1011 |
inline RegI64 captureReturnedI64(); |
| 1012 |
inline RegF32 captureReturnedF32(const FunctionCall& call); |
| 1013 |
inline RegF64 captureReturnedF64(const FunctionCall& call); |
| 1014 |
#ifdef ENABLE_WASM_SIMD |
| 1015 |
inline RegV128 captureReturnedV128(const FunctionCall& call); |
| 1016 |
#endif |
| 1017 |
inline RegRef captureReturnedRef(); |
| 1018 |
|
| 1019 |
////////////////////////////////////////////////////////////////////// |
| 1020 |
// |
| 1021 |
// Register-to-register moves. These emit nothing if src == dest. |
| 1022 |
|
| 1023 |
inline void moveI32(RegI32 src, RegI32 dest); |
| 1024 |
inline void moveI64(RegI64 src, RegI64 dest); |
| 1025 |
inline void moveRef(RegRef src, RegRef dest); |
| 1026 |
inline void movePtr(RegPtr src, RegPtr dest); |
| 1027 |
inline void moveF64(RegF64 src, RegF64 dest); |
| 1028 |
inline void moveF32(RegF32 src, RegF32 dest); |
| 1029 |
#ifdef ENABLE_WASM_SIMD |
| 1030 |
inline void moveV128(RegV128 src, RegV128 dest); |
| 1031 |
#endif |
| 1032 |
|
| 1033 |
template <typename RegType> |
| 1034 |
inline void move(RegType src, RegType dest); |
| 1035 |
|
| 1036 |
////////////////////////////////////////////////////////////////////// |
| 1037 |
// |
| 1038 |
// Immediate-to-register moves. |
| 1039 |
// |
| 1040 |
// The compiler depends on moveImm32() clearing the high bits of a 64-bit |
| 1041 |
// register on 64-bit systems except MIPS64 And LoongArch64 where high bits |
| 1042 |
// are sign extended from lower bits, see doc block "64-bit GPRs carrying |
| 1043 |
// 32-bit values" in MacroAssembler.h. |
| 1044 |
|
| 1045 |
inline void moveImm32(int32_t v, RegI32 dest); |
| 1046 |
inline void moveImm64(int64_t v, RegI64 dest); |
| 1047 |
inline void moveImmRef(intptr_t v, RegRef dest); |
| 1048 |
|
| 1049 |
////////////////////////////////////////////////////////////////////// |
| 1050 |
// |
| 1051 |
// Sundry low-level code generators. |
| 1052 |
|
| 1053 |
// Decrement the per-instance function hotness counter by `step` and request |
| 1054 |
// optimized compilation for this function if the updated counter is negative |
| 1055 |
// when regarded as an int32_t. The amount to decrement is to be filled in |
| 1056 |
// later by ::patchHotnessCheck. |
| 1057 |
[[nodiscard]] Maybe<CodeOffset> addHotnessCheck(); |
| 1058 |
|
| 1059 |
// Patch in the counter decrement for a hotness check, using the offset |
| 1060 |
// previously obtained from ::addHotnessCheck. We require 1 <= `step` <= 127. |
| 1061 |
void patchHotnessCheck(CodeOffset offset, uint32_t step); |
| 1062 |
|
| 1063 |
// Check the interrupt flag, trap if it is set. |
| 1064 |
[[nodiscard]] bool addInterruptCheck(); |
| 1065 |
|
| 1066 |
// Check that the value is not zero, trap if it is. |
| 1067 |
void checkDivideByZero(RegI32 rhs); |
| 1068 |
void checkDivideByZero(RegI64 r); |
| 1069 |
|
| 1070 |
// Check that a signed division will not overflow, trap or flush-to-zero if it |
| 1071 |
// will according to `zeroOnOverflow`. |
| 1072 |
void checkDivideSignedOverflow(RegI32 rhs, RegI32 srcDest, Label* done, |
| 1073 |
bool zeroOnOverflow); |
| 1074 |
void checkDivideSignedOverflow(RegI64 rhs, RegI64 srcDest, Label* done, |
| 1075 |
bool zeroOnOverflow); |
| 1076 |
|
| 1077 |
// Emit a jump table to be used by tableSwitch() |
| 1078 |
void jumpTable(const LabelVector& labels, Label* theTable); |
| 1079 |
|
| 1080 |
// Emit a table switch, `theTable` is the jump table. |
| 1081 |
void tableSwitch(Label* theTable, RegI32 switchValue, Label* dispatchCode); |
| 1082 |
|
| 1083 |
// Compare i64 and set an i32 boolean result according to the condition. |
| 1084 |
inline void cmp64Set(Assembler::Condition cond, RegI64 lhs, RegI64 rhs, |
| 1085 |
RegI32 dest); |
| 1086 |
|
| 1087 |
// Round floating to integer. |
| 1088 |
[[nodiscard]] inline bool supportsRoundInstruction(RoundingMode mode); |
| 1089 |
inline void roundF32(RoundingMode roundingMode, RegF32 f0); |
| 1090 |
inline void roundF64(RoundingMode roundingMode, RegF64 f0); |
| 1091 |
|
| 1092 |
// These are just wrappers around assembler functions, but without |
| 1093 |
// type-specific names, and using our register abstractions for better type |
| 1094 |
// discipline. |
| 1095 |
inline void branchTo(Assembler::DoubleCondition c, RegF64 lhs, RegF64 rhs, |
| 1096 |
Label* l); |
| 1097 |
inline void branchTo(Assembler::DoubleCondition c, RegF32 lhs, RegF32 rhs, |
| 1098 |
Label* l); |
| 1099 |
inline void branchTo(Assembler::Condition c, RegI32 lhs, RegI32 rhs, |
| 1100 |
Label* l); |
| 1101 |
inline void branchTo(Assembler::Condition c, RegI32 lhs, Imm32 rhs, Label* l); |
| 1102 |
inline void branchTo(Assembler::Condition c, RegI64 lhs, RegI64 rhs, |
| 1103 |
Label* l); |
| 1104 |
inline void branchTo(Assembler::Condition c, RegI64 lhs, Imm64 rhs, Label* l); |
| 1105 |
inline void branchTo(Assembler::Condition c, RegRef lhs, ImmWord rhs, |
| 1106 |
Label* l); |
| 1107 |
|
| 1108 |
// Helpers for accessing Instance::baselineScratchWords_. Note that Word |
| 1109 |
// and I64 versions of these routines access the same area and it is up to |
| 1110 |
// the caller to use it in some way which makes sense. |
| 1111 |
|
| 1112 |
// Store/load `r`, a machine word, to/from the `index`th scratch storage |
| 1113 |
// slot in the current Instance. `instancePtr` must point at the current |
| 1114 |
// Instance; it will not be modified. For ::stashWord, `r` must not be the |
| 1115 |
// same as `instancePtr`. |
| 1116 |
void stashWord(RegPtr instancePtr, size_t index, RegPtr r); |
| 1117 |
void unstashWord(RegPtr instancePtr, size_t index, RegPtr r); |
| 1118 |
|
| 1119 |
#ifdef JS_CODEGEN_X86 |
| 1120 |
// Store r in instance scratch storage after first loading the instance from |
| 1121 |
// the frame into the regForInstance. regForInstance must be neither of the |
| 1122 |
// registers in r. |
| 1123 |
void stashI64(RegPtr regForInstance, RegI64 r); |
| 1124 |
|
| 1125 |
// Load r from the instance scratch storage after first loading the instance |
| 1126 |
// from the frame into the regForInstance. regForInstance can be one of the |
| 1127 |
// registers in r. |
| 1128 |
void unstashI64(RegPtr regForInstance, RegI64 r); |
| 1129 |
#endif |
| 1130 |
|
| 1131 |
////////////////////////////////////////////////////////////////////// |
| 1132 |
// |
| 1133 |
// Code generators for actual operations. |
| 1134 |
|
| 1135 |
template <typename RegType, typename IntType> |
| 1136 |
void quotientOrRemainder(RegType rs, RegType rsd, RegType reserved, |
| 1137 |
IsUnsigned isUnsigned, ZeroOnOverflow zeroOnOverflow, |
| 1138 |
bool isConst, IntType c, |
| 1139 |
void (*operate)(MacroAssembler&, RegType, RegType, |
| 1140 |
RegType, IsUnsigned)); |
| 1141 |
|
| 1142 |
[[nodiscard]] bool truncateF32ToI32(RegF32 src, RegI32 dest, |
| 1143 |
TruncFlags flags); |
| 1144 |
[[nodiscard]] bool truncateF64ToI32(RegF64 src, RegI32 dest, |
| 1145 |
TruncFlags flags); |
| 1146 |
|
| 1147 |
#ifndef RABALDR_FLOAT_TO_I64_CALLOUT |
| 1148 |
[[nodiscard]] RegF64 needTempForFloatingToI64(TruncFlags flags); |
| 1149 |
[[nodiscard]] bool truncateF32ToI64(RegF32 src, RegI64 dest, TruncFlags flags, |
| 1150 |
RegF64 temp); |
| 1151 |
[[nodiscard]] bool truncateF64ToI64(RegF64 src, RegI64 dest, TruncFlags flags, |
| 1152 |
RegF64 temp); |
| 1153 |
#endif // RABALDR_FLOAT_TO_I64_CALLOUT |
| 1154 |
|
| 1155 |
#ifndef RABALDR_I64_TO_FLOAT_CALLOUT |
| 1156 |
[[nodiscard]] RegI32 needConvertI64ToFloatTemp(ValType to, bool isUnsigned); |
| 1157 |
void convertI64ToF32(RegI64 src, bool isUnsigned, RegF32 dest, RegI32 temp); |
| 1158 |
void convertI64ToF64(RegI64 src, bool isUnsigned, RegF64 dest, RegI32 temp); |
| 1159 |
#endif // RABALDR_I64_TO_FLOAT_CALLOUT |
| 1160 |
|
| 1161 |
////////////////////////////////////////////////////////////////////// |
| 1162 |
// |
| 1163 |
// Global variable access. |
| 1164 |
|
| 1165 |
Address addressOfGlobalVar(const GlobalDesc& global, RegPtr tmp); |
| 1166 |
|
| 1167 |
////////////////////////////////////////////////////////////////////// |
| 1168 |
// |
| 1169 |
// Table access. |
| 1170 |
|
| 1171 |
Address addressOfTableField(uint32_t tableIndex, uint32_t fieldOffset, |
| 1172 |
RegPtr instance); |
| 1173 |
void loadTableLength(uint32_t tableIndex, RegPtr instance, RegI32 length); |
| 1174 |
void loadTableElements(uint32_t tableIndex, RegPtr instance, RegPtr elements); |
| 1175 |
|
| 1176 |
////////////////////////////////////////////////////////////////////// |
| 1177 |
// |
| 1178 |
// Heap access. |
| 1179 |
|
| 1180 |
void bceCheckLocal(MemoryAccessDesc* access, AccessCheck* check, |
| 1181 |
uint32_t local); |
| 1182 |
void bceLocalIsUpdated(uint32_t local); |
| 1183 |
|
| 1184 |
// Fold offsets into ptr and bounds check as necessary. The instance will be |
| 1185 |
// valid in cases where it's needed. |
| 1186 |
template <typename RegAddressType> |
| 1187 |
void prepareMemoryAccess(MemoryAccessDesc* access, AccessCheck* check, |
| 1188 |
RegPtr instance, RegAddressType ptr); |
| 1189 |
|
| 1190 |
void branchAddNoOverflow(uint64_t offset, RegI32 ptr, Label* ok); |
| 1191 |
void branchTestLowZero(RegI32 ptr, Imm32 mask, Label* ok); |
| 1192 |
void boundsCheck4GBOrLargerAccess(uint32_t memoryIndex, RegPtr instance, |
| 1193 |
RegI32 ptr, Label* ok); |
| 1194 |
void boundsCheckBelow4GBAccess(uint32_t memoryIndex, RegPtr instance, |
| 1195 |
RegI32 ptr, Label* ok); |
| 1196 |
|
| 1197 |
void branchAddNoOverflow(uint64_t offset, RegI64 ptr, Label* ok); |
| 1198 |
void branchTestLowZero(RegI64 ptr, Imm32 mask, Label* ok); |
| 1199 |
void boundsCheck4GBOrLargerAccess(uint32_t memoryIndex, RegPtr instance, |
| 1200 |
RegI64 ptr, Label* ok); |
| 1201 |
void boundsCheckBelow4GBAccess(uint32_t memoryIndex, RegPtr instance, |
| 1202 |
RegI64 ptr, Label* ok); |
| 1203 |
|
| 1204 |
// Some consumers depend on the returned Address not incorporating instance, |
| 1205 |
// as instance may be the scratch register. |
| 1206 |
template <typename RegAddressType> |
| 1207 |
Address prepareAtomicMemoryAccess(MemoryAccessDesc* access, |
| 1208 |
AccessCheck* check, RegPtr instance, |
| 1209 |
RegAddressType ptr); |
| 1210 |
|
| 1211 |
template <typename RegAddressType> |
| 1212 |
void computeEffectiveAddress(MemoryAccessDesc* access); |
| 1213 |
|
| 1214 |
[[nodiscard]] bool needInstanceForAccess(const MemoryAccessDesc* access, |
| 1215 |
const AccessCheck& check); |
| 1216 |
|
| 1217 |
// ptr and dest may be the same iff dest is I32. |
| 1218 |
// This may destroy ptr even if ptr and dest are not the same. |
| 1219 |
void executeLoad(MemoryAccessDesc* access, AccessCheck* check, |
| 1220 |
RegPtr instance, RegPtr memoryBase, RegI32 ptr, AnyReg dest, |
| 1221 |
RegI32 temp); |
| 1222 |
void load(MemoryAccessDesc* access, AccessCheck* check, RegPtr instance, |
| 1223 |
RegPtr memoryBase, RegI32 ptr, AnyReg dest, RegI32 temp); |
| 1224 |
#ifdef ENABLE_WASM_MEMORY64 |
| 1225 |
void load(MemoryAccessDesc* access, AccessCheck* check, RegPtr instance, |
| 1226 |
RegPtr memoryBase, RegI64 ptr, AnyReg dest, RegI64 temp); |
| 1227 |
#endif |
| 1228 |
|
| 1229 |
template <typename RegType> |
| 1230 |
void doLoadCommon(MemoryAccessDesc* access, AccessCheck check, ValType type); |
| 1231 |
|
| 1232 |
void loadCommon(MemoryAccessDesc* access, AccessCheck check, ValType type); |
| 1233 |
|
| 1234 |
// ptr and src must not be the same register. |
| 1235 |
// This may destroy ptr and src. |
| 1236 |
void executeStore(MemoryAccessDesc* access, AccessCheck* check, |
| 1237 |
RegPtr instance, RegPtr memoryBase, RegI32 ptr, AnyReg src, |
| 1238 |
RegI32 temp); |
| 1239 |
void store(MemoryAccessDesc* access, AccessCheck* check, RegPtr instance, |
| 1240 |
RegPtr memoryBase, RegI32 ptr, AnyReg src, RegI32 temp); |
| 1241 |
#ifdef ENABLE_WASM_MEMORY64 |
| 1242 |
void store(MemoryAccessDesc* access, AccessCheck* check, RegPtr instance, |
| 1243 |
RegPtr memoryBase, RegI64 ptr, AnyReg src, RegI64 temp); |
| 1244 |
#endif |
| 1245 |
|
| 1246 |
template <typename RegType> |
| 1247 |
void doStoreCommon(MemoryAccessDesc* access, AccessCheck check, |
| 1248 |
ValType resultType); |
| 1249 |
|
| 1250 |
void storeCommon(MemoryAccessDesc* access, AccessCheck check, |
| 1251 |
ValType resultType); |
| 1252 |
|
| 1253 |
void atomicLoad(MemoryAccessDesc* access, ValType type); |
| 1254 |
#if !defined(JS_64BIT) |
| 1255 |
template <typename RegAddressType> |
| 1256 |
void atomicLoad64(MemoryAccessDesc* desc); |
| 1257 |
#endif |
| 1258 |
|
| 1259 |
void atomicStore(MemoryAccessDesc* access, ValType type); |
| 1260 |
|
| 1261 |
void atomicRMW(MemoryAccessDesc* access, ValType type, AtomicOp op); |
| 1262 |
template <typename RegAddressType> |
| 1263 |
void atomicRMW32(MemoryAccessDesc* access, ValType type, AtomicOp op); |
| 1264 |
template <typename RegAddressType> |
| 1265 |
void atomicRMW64(MemoryAccessDesc* access, ValType type, AtomicOp op); |
| 1266 |
|
| 1267 |
void atomicXchg(MemoryAccessDesc* access, ValType type); |
| 1268 |
template <typename RegAddressType> |
| 1269 |
void atomicXchg64(MemoryAccessDesc* access, WantResult wantResult); |
| 1270 |
template <typename RegAddressType> |
| 1271 |
void atomicXchg32(MemoryAccessDesc* access, ValType type); |
| 1272 |
|
| 1273 |
void atomicCmpXchg(MemoryAccessDesc* access, ValType type); |
| 1274 |
template <typename RegAddressType> |
| 1275 |
void atomicCmpXchg32(MemoryAccessDesc* access, ValType type); |
| 1276 |
template <typename RegAddressType> |
| 1277 |
void atomicCmpXchg64(MemoryAccessDesc* access, ValType type); |
| 1278 |
|
| 1279 |
template <typename RegType> |
| 1280 |
RegType popConstMemoryAccess(MemoryAccessDesc* access, AccessCheck* check); |
| 1281 |
template <typename RegType> |
| 1282 |
RegType popMemoryAccess(MemoryAccessDesc* access, AccessCheck* check); |
| 1283 |
|
| 1284 |
void pushHeapBase(uint32_t memoryIndex); |
| 1285 |
|
| 1286 |
//////////////////////////////////////////////////////////////////////////// |
| 1287 |
// |
| 1288 |
// Platform-specific popping and register targeting. |
| 1289 |
|
| 1290 |
// The simple popping methods pop values into targeted registers; the caller |
| 1291 |
// can free registers using standard functions. These are always called |
| 1292 |
// popXForY where X says something about types and Y something about the |
| 1293 |
// operation being targeted. |
| 1294 |
|
| 1295 |
RegI32 needRotate64Temp(); |
| 1296 |
void popAndAllocateForDivAndRemI32(RegI32* r0, RegI32* r1, RegI32* reserved); |
| 1297 |
void popAndAllocateForMulI64(RegI64* r0, RegI64* r1, RegI32* temp); |
| 1298 |
#ifndef RABALDR_INT_DIV_I64_CALLOUT |
| 1299 |
void popAndAllocateForDivAndRemI64(RegI64* r0, RegI64* r1, RegI64* reserved, |
| 1300 |
IsRemainder isRemainder); |
| 1301 |
#endif |
| 1302 |
RegI32 popI32RhsForShift(); |
| 1303 |
RegI32 popI32RhsForShiftI64(); |
| 1304 |
RegI64 popI64RhsForShift(); |
| 1305 |
RegI32 popI32RhsForRotate(); |
| 1306 |
RegI64 popI64RhsForRotate(); |
| 1307 |
void popI32ForSignExtendI64(RegI64* r0); |
| 1308 |
void popI64ForSignExtendI64(RegI64* r0); |
| 1309 |
|
| 1310 |
//////////////////////////////////////////////////////////// |
| 1311 |
// |
| 1312 |
// Sundry helpers. |
| 1313 |
|
| 1314 |
// Retrieve the current bytecodeOffset. |
| 1315 |
inline BytecodeOffset bytecodeOffset() const; |
| 1316 |
|
| 1317 |
// Get a trap site description for a trap that would occur in the current |
| 1318 |
// opcode. |
| 1319 |
inline TrapSiteDesc trapSiteDesc() const; |
| 1320 |
|
| 1321 |
// Generate a trap instruction for the current bytecodeOffset. |
| 1322 |
inline void trap(Trap t) const; |
| 1323 |
|
| 1324 |
// Abstracted helper for throwing, used for throw, rethrow, and rethrowing |
| 1325 |
// at the end of a series of catch blocks (if none matched the exception). |
| 1326 |
[[nodiscard]] bool throwFrom(RegRef exn); |
| 1327 |
|
| 1328 |
// Load the specified tag object from the Instance. |
| 1329 |
void loadTag(RegPtr instance, uint32_t tagIndex, RegRef tagDst); |
| 1330 |
|
| 1331 |
// Load the pending exception state from the Instance and then reset it. |
| 1332 |
void consumePendingException(RegPtr instance, RegRef* exnDst, RegRef* tagDst); |
| 1333 |
|
| 1334 |
[[nodiscard]] bool startTryNote(size_t* tryNoteIndex); |
| 1335 |
void finishTryNote(size_t tryNoteIndex); |
| 1336 |
|
| 1337 |
//////////////////////////////////////////////////////////// |
| 1338 |
// |
| 1339 |
// Barriers support. |
| 1340 |
|
| 1341 |
// This emits a GC pre-write barrier. The pre-barrier is needed when we |
| 1342 |
// replace a member field with a new value, and the previous field value |
| 1343 |
// might have no other referents, and incremental GC is ongoing. The field |
| 1344 |
// might belong to an object or be a stack slot or a register or a heap |
| 1345 |
// allocated value. |
| 1346 |
// |
| 1347 |
// let obj = { field: previousValue }; |
| 1348 |
// obj.field = newValue; // previousValue must be marked with a pre-barrier. |
| 1349 |
// |
| 1350 |
// The `valueAddr` is the address of the location that we are about to |
| 1351 |
// update. This function preserves that register. |
| 1352 |
void emitPreBarrier(RegPtr valueAddr); |
| 1353 |
|
| 1354 |
// These emit GC post-write barriers. The post-barrier is needed when we |
| 1355 |
// replace a member field with a new value, the new value is in the nursery, |
| 1356 |
// and the containing object is a tenured object. The field (or the entire |
| 1357 |
// containing object) must then be added to the store buffer so that the |
| 1358 |
// nursery can be correctly collected. The field might belong to an object or |
| 1359 |
// be a stack slot or a register or a heap allocated value. |
| 1360 |
// |
| 1361 |
// For the difference between 'precise' and 'imprecise', look at the |
| 1362 |
// documentation on PostBarrierKind. |
| 1363 |
|
| 1364 |
// Emits a post-write barrier that creates a whole-cell store buffer entry. |
| 1365 |
// See above for details. |
| 1366 |
// |
| 1367 |
// - `object` is a pointer to the object that contains the field. This |
| 1368 |
// register is preserved by this function. |
| 1369 |
// - `value` is the value that was stored in the field. This register is |
| 1370 |
// preserved by this function. |
| 1371 |
// - `temp` is clobbered by this function. |
| 1372 |
[[nodiscard]] bool emitPostBarrierWholeCell(RegRef object, RegRef value, |
| 1373 |
RegPtr temp); |
| 1374 |
|
| 1375 |
// Emits a post-write barrier of type WasmAnyRefEdge, imprecisely. See above |
| 1376 |
// for details. |
| 1377 |
// |
| 1378 |
// - `object` is a pointer to the object that contains the field. It is used, |
| 1379 |
// if present, to skip adding a store buffer entry when the containing |
| 1380 |
// object is in the nursery. This register is preserved by this function. |
| 1381 |
// - `valueAddr` is the address of the location that we are writing to. This |
| 1382 |
// register is consumed by this function. |
| 1383 |
// - `value` is the value that was stored in the field. This register is |
| 1384 |
// preserved by this function. |
| 1385 |
[[nodiscard]] bool emitPostBarrierEdgeImprecise( |
| 1386 |
const mozilla::Maybe<RegRef>& object, RegPtr valueAddr, RegRef value); |
| 1387 |
|
| 1388 |
// Emits a post-write barrier of type WasmAnyRefEdge, precisely. See above for |
| 1389 |
// details. |
| 1390 |
// |
| 1391 |
// - `object` is a pointer to the object that contains the field. It is used, |
| 1392 |
// if present, to skip adding a store buffer entry when the containing |
| 1393 |
// object is in the nursery. This register is preserved by this function. |
| 1394 |
// - `valueAddr` is the address of the location that we are writing to. This |
| 1395 |
// register is consumed by this function. |
| 1396 |
// - `prevValue` is the value that existed in the field before `value` was |
| 1397 |
// stored. This register is consumed by this function. |
| 1398 |
// - `value` is the value that was stored in the field. This register is |
| 1399 |
// preserved by this function. |
| 1400 |
[[nodiscard]] bool emitPostBarrierEdgePrecise( |
| 1401 |
const mozilla::Maybe<RegRef>& object, RegPtr valueAddr, RegRef prevValue, |
| 1402 |
RegRef value); |
| 1403 |
|
| 1404 |
// Emits a store to a JS object pointer at the address `valueAddr`, which is |
| 1405 |
// inside the GC cell `object`. |
| 1406 |
// |
| 1407 |
// Preserves `object` and `value`. Consumes `valueAddr`. |
| 1408 |
[[nodiscard]] bool emitBarrieredStore(const mozilla::Maybe<RegRef>& object, |
| 1409 |
RegPtr valueAddr, RegRef value, |
| 1410 |
PreBarrierKind preBarrierKind, |
| 1411 |
PostBarrierKind postBarrierKind); |
| 1412 |
|
| 1413 |
// Emits a store of nullptr to a JS object pointer at the address valueAddr. |
| 1414 |
// Preserves `valueAddr`. |
| 1415 |
void emitBarrieredClear(RegPtr valueAddr); |
| 1416 |
|
| 1417 |
//////////////////////////////////////////////////////////// |
| 1418 |
// |
| 1419 |
// Machinery for optimized conditional branches. See comments in the |
| 1420 |
// implementation. |
| 1421 |
|
| 1422 |
void setLatentCompare(Assembler::Condition compareOp, ValType operandType); |
| 1423 |
void setLatentCompare(Assembler::DoubleCondition compareOp, |
| 1424 |
ValType operandType); |
| 1425 |
void setLatentEqz(ValType operandType); |
| 1426 |
bool hasLatentOp() const; |
| 1427 |
void resetLatentOp(); |
| 1428 |
// Jump to the given branch, passing results, if the condition, `cond` |
| 1429 |
// matches between `lhs` and `rhs. |
| 1430 |
template <typename Cond, typename Lhs, typename Rhs> |
| 1431 |
[[nodiscard]] bool jumpConditionalWithResults(BranchState* b, Cond cond, |
| 1432 |
Lhs lhs, Rhs rhs); |
| 1433 |
// Jump to the given branch, passing results, if the WasmGcObject, `object`, |
| 1434 |
// is a subtype of `destType`. |
| 1435 |
[[nodiscard]] bool jumpConditionalWithResults(BranchState* b, RegRef object, |
| 1436 |
MaybeRefType sourceType, |
| 1437 |
RefType destType, |
| 1438 |
bool onSuccess); |
| 1439 |
template <typename Cond> |
| 1440 |
[[nodiscard]] bool sniffConditionalControlCmp(Cond compareOp, |
| 1441 |
ValType operandType); |
| 1442 |
[[nodiscard]] bool sniffConditionalControlEqz(ValType operandType); |
| 1443 |
void emitBranchSetup(BranchState* b); |
| 1444 |
[[nodiscard]] bool emitBranchPerform(BranchState* b); |
| 1445 |
|
| 1446 |
////////////////////////////////////////////////////////////////////// |
| 1447 |
|
| 1448 |
[[nodiscard]] bool emitBody(); |
| 1449 |
[[nodiscard]] bool emitBlock(); |
| 1450 |
[[nodiscard]] bool emitLoop(); |
| 1451 |
[[nodiscard]] bool emitIf(); |
| 1452 |
[[nodiscard]] bool emitElse(); |
| 1453 |
// Used for common setup for catch and catch_all. |
| 1454 |
void emitCatchSetup(LabelKind kind, Control& tryCatch, |
| 1455 |
const ResultType& resultType); |
| 1456 |
|
| 1457 |
[[nodiscard]] bool emitTry(); |
| 1458 |
[[nodiscard]] bool emitTryTable(); |
| 1459 |
[[nodiscard]] bool emitCatch(); |
| 1460 |
[[nodiscard]] bool emitCatchAll(); |
| 1461 |
[[nodiscard]] bool emitDelegate(); |
| 1462 |
[[nodiscard]] bool emitThrow(); |
| 1463 |
[[nodiscard]] bool emitThrowRef(); |
| 1464 |
[[nodiscard]] bool emitRethrow(); |
| 1465 |
[[nodiscard]] bool emitEnd(); |
| 1466 |
[[nodiscard]] bool emitBr(); |
| 1467 |
[[nodiscard]] bool emitBrIf(); |
| 1468 |
[[nodiscard]] bool emitBrTable(); |
| 1469 |
[[nodiscard]] bool emitDrop(); |
| 1470 |
[[nodiscard]] bool emitReturn(); |
| 1471 |
|
| 1472 |
// A flag passed to emitCallArgs, describing how the value stack is laid out. |
| 1473 |
enum class CalleeOnStack { |
| 1474 |
// After the arguments to the call, there is a callee pushed onto value |
| 1475 |
// stack. This is only the case for callIndirect. To get the arguments to |
| 1476 |
// the call, emitCallArgs has to reach one element deeper into the value |
| 1477 |
// stack, to skip the callee. |
| 1478 |
True, |
| 1479 |
|
| 1480 |
// No callee on the stack. |
| 1481 |
False |
| 1482 |
}; |
| 1483 |
|
| 1484 |
// The typename T for emitCallArgs can be one of the following: |
| 1485 |
// NormalCallResults, TailCallResults, or NoCallResults. |
| 1486 |
template <typename T> |
| 1487 |
[[nodiscard]] bool emitCallArgs(const ValTypeVector& argTypes, T results, |
| 1488 |
FunctionCall* baselineCall, |
| 1489 |
CalleeOnStack calleeOnStack); |
| 1490 |
|
| 1491 |
[[nodiscard]] bool emitCall(); |
| 1492 |
[[nodiscard]] bool emitReturnCall(); |
| 1493 |
[[nodiscard]] bool emitCallIndirect(); |
| 1494 |
[[nodiscard]] bool emitReturnCallIndirect(); |
| 1495 |
[[nodiscard]] bool emitUnaryMathBuiltinCall(SymbolicAddress callee, |
| 1496 |
ValType operandType); |
| 1497 |
[[nodiscard]] bool emitGetLocal(); |
| 1498 |
[[nodiscard]] bool emitSetLocal(); |
| 1499 |
[[nodiscard]] bool emitTeeLocal(); |
| 1500 |
[[nodiscard]] bool emitGetGlobal(); |
| 1501 |
[[nodiscard]] bool emitSetGlobal(); |
| 1502 |
[[nodiscard]] RegPtr maybeLoadMemoryBaseForAccess( |
| 1503 |
RegPtr instance, const MemoryAccessDesc* access); |
| 1504 |
[[nodiscard]] RegPtr maybeLoadInstanceForAccess( |
| 1505 |
const MemoryAccessDesc* access, const AccessCheck& check); |
| 1506 |
[[nodiscard]] RegPtr maybeLoadInstanceForAccess( |
| 1507 |
const MemoryAccessDesc* access, const AccessCheck& check, |
| 1508 |
RegPtr specific); |
| 1509 |
[[nodiscard]] bool emitLoad(ValType type, Scalar::Type viewType); |
| 1510 |
[[nodiscard]] bool emitStore(ValType resultType, Scalar::Type viewType); |
| 1511 |
[[nodiscard]] bool emitSelect(bool typed); |
| 1512 |
|
| 1513 |
template <bool isSetLocal> |
| 1514 |
[[nodiscard]] bool emitSetOrTeeLocal(uint32_t slot); |
| 1515 |
|
| 1516 |
[[nodiscard]] bool endBlock(ResultType type); |
| 1517 |
[[nodiscard]] bool endIfThen(ResultType type); |
| 1518 |
[[nodiscard]] bool endIfThenElse(ResultType type); |
| 1519 |
[[nodiscard]] bool endTryCatch(ResultType type); |
| 1520 |
[[nodiscard]] bool endTryTable(ResultType type); |
| 1521 |
|
| 1522 |
void doReturn(ContinuationKind kind); |
| 1523 |
void pushReturnValueOfCall(const FunctionCall& call, MIRType type); |
| 1524 |
|
| 1525 |
[[nodiscard]] bool pushStackResultsForCall(const ResultType& type, |
| 1526 |
RegPtr temp, StackResultsLoc* loc); |
| 1527 |
void popStackResultsAfterCall(const StackResultsLoc& results, |
| 1528 |
uint32_t stackArgBytes); |
| 1529 |
|
| 1530 |
void emitCompareI32(Assembler::Condition compareOp, ValType compareType); |
| 1531 |
void emitCompareI64(Assembler::Condition compareOp, ValType compareType); |
| 1532 |
void emitCompareF32(Assembler::DoubleCondition compareOp, |
| 1533 |
ValType compareType); |
| 1534 |
void emitCompareF64(Assembler::DoubleCondition compareOp, |
| 1535 |
ValType compareType); |
| 1536 |
void emitCompareRef(Assembler::Condition compareOp, ValType compareType); |
| 1537 |
|
| 1538 |
template <typename CompilerType> |
| 1539 |
inline CompilerType& selectCompiler(); |
| 1540 |
|
| 1541 |
template <typename SourceType, typename DestType> |
| 1542 |
inline void emitUnop(void (*op)(MacroAssembler& masm, SourceType rs, |
| 1543 |
DestType rd)); |
| 1544 |
|
| 1545 |
template <typename SourceType, typename DestType, typename TempType> |
| 1546 |
inline void emitUnop(void (*op)(MacroAssembler& masm, SourceType rs, |
| 1547 |
DestType rd, TempType temp)); |
| 1548 |
|
| 1549 |
template <typename SourceType, typename DestType, typename ImmType> |
| 1550 |
inline void emitUnop(ImmType immediate, void (*op)(MacroAssembler&, ImmType, |
| 1551 |
SourceType, DestType)); |
| 1552 |
|
| 1553 |
template <typename CompilerType, typename RegType> |
| 1554 |
inline void emitUnop(void (*op)(CompilerType& compiler, RegType rsd)); |
| 1555 |
|
| 1556 |
template <typename RegType, typename TempType> |
| 1557 |
inline void emitUnop(void (*op)(BaseCompiler& bc, RegType rsd, TempType rt), |
| 1558 |
TempType (*getSpecializedTemp)(BaseCompiler& bc)); |
| 1559 |
|
| 1560 |
template <typename CompilerType, typename RhsType, typename LhsDestType> |
| 1561 |
inline void emitBinop(void (*op)(CompilerType& masm, RhsType src, |
| 1562 |
LhsDestType srcDest)); |
| 1563 |
|
| 1564 |
template <typename RhsDestType, typename LhsType> |
| 1565 |
inline void emitBinop(void (*op)(MacroAssembler& masm, RhsDestType src, |
| 1566 |
LhsType srcDest, RhsDestOp)); |
| 1567 |
|
| 1568 |
template <typename RhsType, typename LhsDestType, typename TempType> |
| 1569 |
inline void emitBinop(void (*)(MacroAssembler& masm, RhsType rs, |
| 1570 |
LhsDestType rsd, TempType temp)); |
| 1571 |
|
| 1572 |
template <typename RhsType, typename LhsDestType, typename TempType1, |
| 1573 |
typename TempType2> |
| 1574 |
inline void emitBinop(void (*)(MacroAssembler& masm, RhsType rs, |
| 1575 |
LhsDestType rsd, TempType1 temp1, |
| 1576 |
TempType2 temp2)); |
| 1577 |
|
| 1578 |
template <typename RhsType, typename LhsDestType, typename ImmType> |
| 1579 |
inline void emitBinop(ImmType immediate, void (*op)(MacroAssembler&, ImmType, |
| 1580 |
RhsType, LhsDestType)); |
| 1581 |
|
| 1582 |
template <typename RhsType, typename LhsDestType, typename ImmType, |
| 1583 |
typename TempType1, typename TempType2> |
| 1584 |
inline void emitBinop(ImmType immediate, |
| 1585 |
void (*op)(MacroAssembler&, ImmType, RhsType, |
| 1586 |
LhsDestType, TempType1 temp1, |
| 1587 |
TempType2 temp2)); |
| 1588 |
|
| 1589 |
template <typename CompilerType1, typename CompilerType2, typename RegType, |
| 1590 |
typename ImmType> |
| 1591 |
inline void emitBinop(void (*op)(CompilerType1& compiler1, RegType rs, |
| 1592 |
RegType rd), |
| 1593 |
void (*opConst)(CompilerType2& compiler2, ImmType c, |
| 1594 |
RegType rd), |
| 1595 |
RegType (BaseCompiler::*rhsPopper)() = nullptr); |
| 1596 |
|
| 1597 |
template <typename CompilerType, typename ValType> |
| 1598 |
inline void emitTernary(void (*op)(CompilerType&, ValType src0, ValType src1, |
| 1599 |
ValType srcDest)); |
| 1600 |
|
| 1601 |
template <typename CompilerType, typename ValType> |
| 1602 |
inline void emitTernary(void (*op)(CompilerType&, ValType src0, ValType src1, |
| 1603 |
ValType srcDest, ValType temp)); |
| 1604 |
|
| 1605 |
template <typename CompilerType, typename ValType> |
| 1606 |
inline void emitTernaryResultLast(void (*op)(CompilerType&, ValType src0, |
| 1607 |
ValType src1, ValType srcDest)); |
| 1608 |
|
| 1609 |
template <typename R> |
| 1610 |
[[nodiscard]] inline bool emitInstanceCallOp( |
| 1611 |
const SymbolicAddressSignature& fn, R reader); |
| 1612 |
|
| 1613 |
template <typename A1, typename R> |
| 1614 |
[[nodiscard]] inline bool emitInstanceCallOp( |
| 1615 |
const SymbolicAddressSignature& fn, R reader); |
| 1616 |
|
| 1617 |
template <typename A1, typename A2, typename R> |
| 1618 |
[[nodiscard]] inline bool emitInstanceCallOp( |
| 1619 |
const SymbolicAddressSignature& fn, R reader); |
| 1620 |
|
| 1621 |
void emitMultiplyI64(); |
| 1622 |
void emitQuotientI32(); |
| 1623 |
void emitQuotientU32(); |
| 1624 |
void emitRemainderI32(); |
| 1625 |
void emitRemainderU32(); |
| 1626 |
#ifdef RABALDR_INT_DIV_I64_CALLOUT |
| 1627 |
[[nodiscard]] bool emitDivOrModI64BuiltinCall(SymbolicAddress callee, |
| 1628 |
ValType operandType); |
| 1629 |
#else |
| 1630 |
void emitQuotientI64(); |
| 1631 |
void emitQuotientU64(); |
| 1632 |
void emitRemainderI64(); |
| 1633 |
void emitRemainderU64(); |
| 1634 |
#endif |
| 1635 |
void emitRotrI64(); |
| 1636 |
void emitRotlI64(); |
| 1637 |
void emitEqzI32(); |
| 1638 |
void emitEqzI64(); |
| 1639 |
template <TruncFlags flags> |
| 1640 |
[[nodiscard]] bool emitTruncateF32ToI32(); |
| 1641 |
template <TruncFlags flags> |
| 1642 |
[[nodiscard]] bool emitTruncateF64ToI32(); |
| 1643 |
#ifdef RABALDR_FLOAT_TO_I64_CALLOUT |
| 1644 |
[[nodiscard]] bool emitConvertFloatingToInt64Callout(SymbolicAddress callee, |
| 1645 |
ValType operandType, |
| 1646 |
ValType resultType); |
| 1647 |
#else |
| 1648 |
template <TruncFlags flags> |
| 1649 |
[[nodiscard]] bool emitTruncateF32ToI64(); |
| 1650 |
template <TruncFlags flags> |
| 1651 |
[[nodiscard]] bool emitTruncateF64ToI64(); |
| 1652 |
#endif |
| 1653 |
void emitExtendI64_8(); |
| 1654 |
void emitExtendI64_16(); |
| 1655 |
void emitExtendI64_32(); |
| 1656 |
void emitExtendI32ToI64(); |
| 1657 |
void emitExtendU32ToI64(); |
| 1658 |
#ifdef RABALDR_I64_TO_FLOAT_CALLOUT |
| 1659 |
[[nodiscard]] bool emitConvertInt64ToFloatingCallout(SymbolicAddress callee, |
| 1660 |
ValType operandType, |
| 1661 |
ValType resultType); |
| 1662 |
#else |
| 1663 |
void emitConvertU64ToF32(); |
| 1664 |
void emitConvertU64ToF64(); |
| 1665 |
#endif |
| 1666 |
void emitRound(RoundingMode roundingMode, ValType operandType); |
| 1667 |
|
| 1668 |
// Generate a call to the instance function denoted by `builtin`, passing as |
| 1669 |
// args the top elements of the compiler's value stack and optionally an |
| 1670 |
// Instance* too. The relationship between the top of stack and arg |
| 1671 |
// ordering is as follows. If the value stack looks like this: |
| 1672 |
// |
| 1673 |
// A <- least recently pushed |
| 1674 |
// B |
| 1675 |
// C <- most recently pushed |
| 1676 |
// |
| 1677 |
// then the called function is expected to have signature [if an Instance* |
| 1678 |
// is also to be passed]: |
| 1679 |
// |
| 1680 |
// static Instance::foo(Instance*, A, B, C) |
| 1681 |
// |
| 1682 |
// and the SymbolicAddressSignature::argTypes array will be |
| 1683 |
// |
| 1684 |
// {_PTR, _A, _B, _C, _END} // _PTR is for the Instance* |
| 1685 |
// |
| 1686 |
// (see WasmBuiltins.cpp). In short, the most recently pushed value is the |
| 1687 |
// rightmost argument to the function. |
| 1688 |
[[nodiscard]] bool emitInstanceCall(const SymbolicAddressSignature& builtin); |
| 1689 |
|
| 1690 |
[[nodiscard]] bool emitMemoryGrow(); |
| 1691 |
[[nodiscard]] bool emitMemorySize(); |
| 1692 |
|
| 1693 |
[[nodiscard]] bool emitRefFunc(); |
| 1694 |
[[nodiscard]] bool emitRefNull(); |
| 1695 |
[[nodiscard]] bool emitRefIsNull(); |
| 1696 |
[[nodiscard]] bool emitRefAsNonNull(); |
| 1697 |
[[nodiscard]] bool emitBrOnNull(); |
| 1698 |
[[nodiscard]] bool emitBrOnNonNull(); |
| 1699 |
[[nodiscard]] bool emitCallRef(); |
| 1700 |
[[nodiscard]] bool emitReturnCallRef(); |
| 1701 |
|
| 1702 |
[[nodiscard]] bool emitAtomicCmpXchg(ValType type, Scalar::Type viewType); |
| 1703 |
[[nodiscard]] bool emitAtomicLoad(ValType type, Scalar::Type viewType); |
| 1704 |
[[nodiscard]] bool emitAtomicRMW(ValType type, Scalar::Type viewType, |
| 1705 |
AtomicOp op); |
| 1706 |
[[nodiscard]] bool emitAtomicStore(ValType type, Scalar::Type viewType); |
| 1707 |
[[nodiscard]] bool emitWait(ValType type, uint32_t byteSize); |
| 1708 |
[[nodiscard]] bool atomicWait(ValType type, MemoryAccessDesc* access); |
| 1709 |
[[nodiscard]] bool emitNotify(); |
| 1710 |
[[nodiscard]] bool atomicNotify(MemoryAccessDesc* access); |
| 1711 |
[[nodiscard]] bool emitFence(); |
| 1712 |
[[nodiscard]] bool emitAtomicXchg(ValType type, Scalar::Type viewType); |
| 1713 |
[[nodiscard]] bool emitMemInit(); |
| 1714 |
[[nodiscard]] bool emitMemCopy(); |
| 1715 |
[[nodiscard]] bool memCopyCall(uint32_t dstMemIndex, uint32_t srcMemIndex); |
| 1716 |
void memCopyInlineM32(); |
| 1717 |
[[nodiscard]] bool emitTableCopy(); |
| 1718 |
[[nodiscard]] bool emitDataOrElemDrop(bool isData); |
| 1719 |
[[nodiscard]] bool emitMemFill(); |
| 1720 |
[[nodiscard]] bool memFillCall(uint32_t memoryIndex); |
| 1721 |
void memFillInlineM32(); |
| 1722 |
[[nodiscard]] bool emitTableInit(); |
| 1723 |
[[nodiscard]] bool emitTableFill(); |
| 1724 |
[[nodiscard]] bool emitMemDiscard(); |
| 1725 |
[[nodiscard]] bool emitTableGet(); |
| 1726 |
[[nodiscard]] bool emitTableGrow(); |
| 1727 |
[[nodiscard]] bool emitTableSet(); |
| 1728 |
[[nodiscard]] bool emitTableSize(); |
| 1729 |
|
| 1730 |
void emitTableBoundsCheck(uint32_t tableIndex, RegI32 address, |
| 1731 |
RegPtr instance); |
| 1732 |
[[nodiscard]] bool emitTableGetAnyRef(uint32_t tableIndex); |
| 1733 |
[[nodiscard]] bool emitTableSetAnyRef(uint32_t tableIndex); |
| 1734 |
|
| 1735 |
[[nodiscard]] bool emitStructNew(); |
| 1736 |
[[nodiscard]] bool emitStructNewDefault(); |
| 1737 |
[[nodiscard]] bool emitStructGet(FieldWideningOp wideningOp); |
| 1738 |
[[nodiscard]] bool emitStructSet(); |
| 1739 |
[[nodiscard]] bool emitArrayNew(); |
| 1740 |
[[nodiscard]] bool emitArrayNewFixed(); |
| 1741 |
[[nodiscard]] bool emitArrayNewDefault(); |
| 1742 |
[[nodiscard]] bool emitArrayNewData(); |
| 1743 |
[[nodiscard]] bool emitArrayNewElem(); |
| 1744 |
[[nodiscard]] bool emitArrayInitData(); |
| 1745 |
[[nodiscard]] bool emitArrayInitElem(); |
| 1746 |
[[nodiscard]] bool emitArrayGet(FieldWideningOp wideningOp); |
| 1747 |
[[nodiscard]] bool emitArraySet(); |
| 1748 |
[[nodiscard]] bool emitArrayLen(); |
| 1749 |
[[nodiscard]] bool emitArrayCopy(); |
| 1750 |
[[nodiscard]] bool emitArrayFill(); |
| 1751 |
[[nodiscard]] bool emitRefI31(); |
| 1752 |
[[nodiscard]] bool emitI31Get(FieldWideningOp wideningOp); |
| 1753 |
[[nodiscard]] bool emitRefTest(bool nullable); |
| 1754 |
[[nodiscard]] bool emitRefCast(bool nullable); |
| 1755 |
[[nodiscard]] bool emitBrOnCastCommon(bool onSuccess, |
| 1756 |
uint32_t labelRelativeDepth, |
| 1757 |
const ResultType& labelType, |
| 1758 |
MaybeRefType sourceType, |
| 1759 |
RefType destType); |
| 1760 |
[[nodiscard]] bool emitBrOnCast(bool onSuccess); |
| 1761 |
[[nodiscard]] bool emitAnyConvertExtern(); |
| 1762 |
[[nodiscard]] bool emitExternConvertAny(); |
| 1763 |
|
| 1764 |
// Utility classes/methods to add trap information related to |
| 1765 |
// null pointer dereferences/accesses. |
| 1766 |
struct NoNullCheck { |
| 1767 |
static void emitNullCheck(BaseCompiler* bc, RegRef rp) {} |
| 1768 |
static void emitTrapSite(BaseCompiler* bc, FaultingCodeOffset fco, |
| 1769 |
TrapMachineInsn tmi) {} |
| 1770 |
}; |
| 1771 |
struct SignalNullCheck { |
| 1772 |
static void emitNullCheck(BaseCompiler* bc, RegRef rp); |
| 1773 |
static void emitTrapSite(BaseCompiler* bc, FaultingCodeOffset fco, |
| 1774 |
TrapMachineInsn tmi); |
| 1775 |
}; |
| 1776 |
|
| 1777 |
// Load a pointer to the AllocSite for current bytecode offset |
| 1778 |
RegPtr loadAllocSiteInstanceData(uint32_t allocSiteIndex); |
| 1779 |
|
| 1780 |
// Gets alloc site allociated with current instruction |
| 1781 |
[[nodiscard]] bool readAllocSiteIndex(uint32_t* index); |
| 1782 |
|
| 1783 |
// Load a pointer to the SuperTypeVector for a given type index |
| 1784 |
RegPtr loadSuperTypeVector(uint32_t typeIndex); |
| 1785 |
|
| 1786 |
// Emits allocation code for a GC struct. The struct may have an out-of-line |
| 1787 |
// data area; if so, `isOutlineStruct` will be true and `outlineBase` will be |
| 1788 |
// allocated and must be freed. |
| 1789 |
template <bool ZeroFields> |
| 1790 |
bool emitStructAlloc(uint32_t typeIndex, RegRef* object, |
| 1791 |
bool* isOutlineStruct, RegPtr* outlineBase, |
| 1792 |
uint32_t allocSiteIndex); |
| 1793 |
// Emits allocation code for a dynamically-sized GC array. |
| 1794 |
template <bool ZeroFields> |
| 1795 |
bool emitArrayAlloc(uint32_t typeIndex, RegRef object, RegI32 numElements, |
| 1796 |
uint32_t elemSize, uint32_t allocSiteIndex); |
| 1797 |
// Emits allocation code for a fixed-size GC array. |
| 1798 |
template <bool ZeroFields> |
| 1799 |
bool emitArrayAllocFixed(uint32_t typeIndex, RegRef object, |
| 1800 |
uint32_t numElements, uint32_t elemSize, |
| 1801 |
uint32_t allocSiteIndex); |
| 1802 |
|
| 1803 |
template <typename NullCheckPolicy> |
| 1804 |
RegPtr emitGcArrayGetData(RegRef rp); |
| 1805 |
template <typename NullCheckPolicy> |
| 1806 |
RegI32 emitGcArrayGetNumElements(RegRef rp); |
| 1807 |
void emitGcArrayBoundsCheck(RegI32 index, RegI32 numElements); |
| 1808 |
template <typename T, typename NullCheckPolicy> |
| 1809 |
void emitGcGet(StorageType type, FieldWideningOp wideningOp, const T& src); |
| 1810 |
template <typename T, typename NullCheckPolicy> |
| 1811 |
void emitGcSetScalar(const T& dst, StorageType type, AnyReg value); |
| 1812 |
|
| 1813 |
BranchIfRefSubtypeRegisters allocRegistersForBranchIfRefSubtype( |
| 1814 |
RefType destType); |
| 1815 |
void freeRegistersForBranchIfRefSubtype( |
| 1816 |
const BranchIfRefSubtypeRegisters& regs); |
| 1817 |
|
| 1818 |
// Write `value` to wasm struct `object`, at `areaBase + areaOffset`. The |
| 1819 |
// caller must decide on the in- vs out-of-lineness before the call and set |
| 1820 |
// the latter two accordingly; this routine does not take that into account. |
| 1821 |
// The value in `object` is unmodified, but `areaBase` and `value` may get |
| 1822 |
// trashed. |
| 1823 |
template <typename NullCheckPolicy> |
| 1824 |
[[nodiscard]] bool emitGcStructSet(RegRef object, RegPtr areaBase, |
| 1825 |
uint32_t areaOffset, StorageType type, |
| 1826 |
AnyReg value, |
| 1827 |
PreBarrierKind preBarrierKind); |
| 1828 |
|
| 1829 |
[[nodiscard]] bool emitGcArraySet(RegRef object, RegPtr data, RegI32 index, |
| 1830 |
const ArrayType& array, AnyReg value, |
| 1831 |
PreBarrierKind preBarrierKind); |
| 1832 |
|
| 1833 |
#ifdef ENABLE_WASM_SIMD |
| 1834 |
void emitVectorAndNot(); |
| 1835 |
# ifdef ENABLE_WASM_RELAXED_SIMD |
| 1836 |
void emitDotI8x16I7x16AddS(); |
| 1837 |
# endif |
| 1838 |
|
| 1839 |
void loadSplat(MemoryAccessDesc* access); |
| 1840 |
void loadZero(MemoryAccessDesc* access); |
| 1841 |
void loadExtend(MemoryAccessDesc* access, Scalar::Type viewType); |
| 1842 |
void loadLane(MemoryAccessDesc* access, uint32_t laneIndex); |
| 1843 |
void storeLane(MemoryAccessDesc* access, uint32_t laneIndex); |
| 1844 |
|
| 1845 |
[[nodiscard]] bool emitLoadSplat(Scalar::Type viewType); |
| 1846 |
[[nodiscard]] bool emitLoadZero(Scalar::Type viewType); |
| 1847 |
[[nodiscard]] bool emitLoadExtend(Scalar::Type viewType); |
| 1848 |
[[nodiscard]] bool emitLoadLane(uint32_t laneSize); |
| 1849 |
[[nodiscard]] bool emitStoreLane(uint32_t laneSize); |
| 1850 |
[[nodiscard]] bool emitVectorShuffle(); |
| 1851 |
[[nodiscard]] bool emitVectorLaneSelect(); |
| 1852 |
# if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) |
| 1853 |
[[nodiscard]] bool emitVectorShiftRightI64x2(); |
| 1854 |
# endif |
| 1855 |
#endif |
| 1856 |
[[nodiscard]] bool emitCallBuiltinModuleFunc(); |
| 1857 |
}; |
| 1858 |
|
| 1859 |
} // namespace wasm |
| 1860 |
} // namespace js |
| 1861 |
|
| 1862 |
#endif // wasm_wasm_baseline_object_h |