| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
/* |
| 8 |
* Everything needed to build actual MIR instructions: the actual opcodes and |
| 9 |
* instructions, the instruction interface, and use chains. |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef jit_MIR_wasm_h |
| 13 |
#define jit_MIR_wasm_h |
| 14 |
|
| 15 |
#include "mozilla/Array.h" |
| 16 |
#include "mozilla/HashFunctions.h" |
| 17 |
#ifdef JS_JITSPEW |
| 18 |
# include "mozilla/Sprintf.h" |
| 19 |
# include "mozilla/Vector.h" |
| 20 |
#endif |
| 21 |
|
| 22 |
#include <algorithm> |
| 23 |
#include <initializer_list> |
| 24 |
|
| 25 |
#include "jit/MIR.h" |
| 26 |
#include "util/DifferentialTesting.h" |
| 27 |
#include "wasm/WasmGcObject.h" |
| 28 |
|
| 29 |
namespace js { |
| 30 |
|
| 31 |
class WasmInstanceObject; |
| 32 |
|
| 33 |
namespace wasm { |
| 34 |
class FuncExport; |
| 35 |
extern uint32_t MIRTypeToABIResultSize(jit::MIRType); |
| 36 |
} // namespace wasm |
| 37 |
|
| 38 |
namespace jit { |
| 39 |
|
| 40 |
class MWasmNullConstant : public MNullaryInstruction { |
| 41 |
mozilla::Maybe<wasm::RefTypeHierarchy> hierarchy_; |
| 42 |
|
| 43 |
explicit MWasmNullConstant(wasm::MaybeRefType type) |
| 44 |
: MNullaryInstruction(classOpcode), |
| 45 |
hierarchy_(type.isSome() ? mozilla::Some(type.value().hierarchy()) |
| 46 |
: mozilla::Nothing()) { |
| 47 |
setResultType(MIRType::WasmAnyRef); |
| 48 |
setMovable(); |
| 49 |
if (type.isSome()) { |
| 50 |
initWasmRefType(wasm::MaybeRefType(type.value().bottomType())); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public: |
| 55 |
INSTRUCTION_HEADER(WasmNullConstant) |
| 56 |
TRIVIAL_NEW_WRAPPERS |
| 57 |
|
| 58 |
mozilla::Maybe<wasm::RefTypeHierarchy> hierarchy() const { |
| 59 |
return hierarchy_; |
| 60 |
} |
| 61 |
|
| 62 |
HashNumber valueHash() const override; |
| 63 |
bool congruentTo(const MDefinition* ins) const override { |
| 64 |
return ins->isWasmNullConstant() && |
| 65 |
hierarchy() == ins->toWasmNullConstant()->hierarchy(); |
| 66 |
} |
| 67 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 68 |
|
| 69 |
ALLOW_CLONE(MWasmNullConstant) |
| 70 |
}; |
| 71 |
|
| 72 |
// Floating-point value as created by wasm. Just a constant value, used to |
| 73 |
// effectively inhibit all the MIR optimizations. This uses the same LIR nodes |
| 74 |
// as a MConstant of the same type would. |
| 75 |
class MWasmFloatConstant : public MNullaryInstruction { |
| 76 |
union { |
| 77 |
float f32_; |
| 78 |
double f64_; |
| 79 |
#ifdef ENABLE_WASM_SIMD |
| 80 |
int8_t s128_[16]; |
| 81 |
uint64_t bits_[2]; |
| 82 |
#else |
| 83 |
uint64_t bits_[1]; |
| 84 |
#endif |
| 85 |
} u; |
| 86 |
|
| 87 |
explicit MWasmFloatConstant(MIRType type) : MNullaryInstruction(classOpcode) { |
| 88 |
u.bits_[0] = 0; |
| 89 |
#ifdef ENABLE_WASM_SIMD |
| 90 |
u.bits_[1] = 0; |
| 91 |
#endif |
| 92 |
setResultType(type); |
| 93 |
} |
| 94 |
|
| 95 |
public: |
| 96 |
INSTRUCTION_HEADER(WasmFloatConstant) |
| 97 |
|
| 98 |
static MWasmFloatConstant* NewDouble(TempAllocator& alloc, double d) { |
| 99 |
auto* ret = new (alloc) MWasmFloatConstant(MIRType::Double); |
| 100 |
ret->u.f64_ = d; |
| 101 |
return ret; |
| 102 |
} |
| 103 |
|
| 104 |
static MWasmFloatConstant* NewFloat32(TempAllocator& alloc, float f) { |
| 105 |
auto* ret = new (alloc) MWasmFloatConstant(MIRType::Float32); |
| 106 |
ret->u.f32_ = f; |
| 107 |
return ret; |
| 108 |
} |
| 109 |
|
| 110 |
#ifdef ENABLE_WASM_SIMD |
| 111 |
static MWasmFloatConstant* NewSimd128(TempAllocator& alloc, |
| 112 |
const SimdConstant& s) { |
| 113 |
auto* ret = new (alloc) MWasmFloatConstant(MIRType::Simd128); |
| 114 |
memcpy(ret->u.s128_, s.bytes(), 16); |
| 115 |
return ret; |
| 116 |
} |
| 117 |
#endif |
| 118 |
|
| 119 |
HashNumber valueHash() const override; |
| 120 |
bool congruentTo(const MDefinition* ins) const override; |
| 121 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 122 |
|
| 123 |
const double& toDouble() const { |
| 124 |
MOZ_ASSERT(type() == MIRType::Double); |
| 125 |
return u.f64_; |
| 126 |
} |
| 127 |
const float& toFloat32() const { |
| 128 |
MOZ_ASSERT(type() == MIRType::Float32); |
| 129 |
return u.f32_; |
| 130 |
} |
| 131 |
#ifdef ENABLE_WASM_SIMD |
| 132 |
const SimdConstant toSimd128() const { |
| 133 |
MOZ_ASSERT(type() == MIRType::Simd128); |
| 134 |
return SimdConstant::CreateX16(u.s128_); |
| 135 |
} |
| 136 |
#endif |
| 137 |
#ifdef JS_JITSPEW |
| 138 |
void getExtras(ExtrasCollector* extras) const override { |
| 139 |
char buf[64]; |
| 140 |
switch (type()) { |
| 141 |
case MIRType::Float32: |
| 142 |
SprintfLiteral(buf, "f32{%e}", (double)u.f32_); |
| 143 |
break; |
| 144 |
case MIRType::Double: |
| 145 |
SprintfLiteral(buf, "f64{%e}", u.f64_); |
| 146 |
break; |
| 147 |
# ifdef ENABLE_WASM_SIMD |
| 148 |
case MIRType::Simd128: |
| 149 |
SprintfLiteral(buf, "v128{[1]=%016llx:[0]=%016llx}", |
| 150 |
(unsigned long long int)u.bits_[1], |
| 151 |
(unsigned long long int)u.bits_[0]); |
| 152 |
break; |
| 153 |
# endif |
| 154 |
default: |
| 155 |
SprintfLiteral(buf, "!!getExtras: missing case!!"); |
| 156 |
break; |
| 157 |
} |
| 158 |
extras->add(buf); |
| 159 |
} |
| 160 |
#endif |
| 161 |
|
| 162 |
ALLOW_CLONE(MWasmFloatConstant) |
| 163 |
}; |
| 164 |
|
| 165 |
// Converts a uint32 to a float32 (coming from wasm). |
| 166 |
class MWasmUnsignedToFloat32 : public MUnaryInstruction, |
| 167 |
public NoTypePolicy::Data { |
| 168 |
explicit MWasmUnsignedToFloat32(MDefinition* def) |
| 169 |
: MUnaryInstruction(classOpcode, def) { |
| 170 |
setResultType(MIRType::Float32); |
| 171 |
setMovable(); |
| 172 |
} |
| 173 |
|
| 174 |
public: |
| 175 |
INSTRUCTION_HEADER(WasmUnsignedToFloat32) |
| 176 |
TRIVIAL_NEW_WRAPPERS |
| 177 |
|
| 178 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 179 |
bool congruentTo(const MDefinition* ins) const override { |
| 180 |
return congruentIfOperandsEqual(ins); |
| 181 |
} |
| 182 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 183 |
|
| 184 |
bool canProduceFloat32() const override { return true; } |
| 185 |
|
| 186 |
ALLOW_CLONE(MWasmUnsignedToFloat32) |
| 187 |
}; |
| 188 |
|
| 189 |
class MWasmNewI31Ref : public MUnaryInstruction, public NoTypePolicy::Data { |
| 190 |
explicit MWasmNewI31Ref(MDefinition* input) |
| 191 |
: MUnaryInstruction(classOpcode, input) { |
| 192 |
MOZ_ASSERT(input->type() == MIRType::Int32); |
| 193 |
setResultType(MIRType::WasmAnyRef); |
| 194 |
setMovable(); |
| 195 |
initWasmRefType(wasm::MaybeRefType(wasm::RefType::i31().asNonNullable())); |
| 196 |
} |
| 197 |
|
| 198 |
public: |
| 199 |
INSTRUCTION_HEADER(WasmNewI31Ref) |
| 200 |
TRIVIAL_NEW_WRAPPERS |
| 201 |
|
| 202 |
bool congruentTo(const MDefinition* ins) const override { |
| 203 |
return congruentIfOperandsEqual(ins); |
| 204 |
} |
| 205 |
|
| 206 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 207 |
}; |
| 208 |
|
| 209 |
// The same as MWasmTruncateToInt64 but with the Instance dependency. |
| 210 |
// It used only for arm now because on arm we need to call builtin to truncate |
| 211 |
// to i64. |
| 212 |
class MWasmBuiltinTruncateToInt64 : public MAryInstruction<2>, |
| 213 |
public NoTypePolicy::Data { |
| 214 |
TruncFlags flags_; |
| 215 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 216 |
|
| 217 |
MWasmBuiltinTruncateToInt64(MDefinition* def, MDefinition* instance, |
| 218 |
TruncFlags flags, |
| 219 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 220 |
: MAryInstruction(classOpcode), |
| 221 |
flags_(flags), |
| 222 |
trapSiteDesc_(trapSiteDesc) { |
| 223 |
initOperand(0, def); |
| 224 |
initOperand(1, instance); |
| 225 |
|
| 226 |
setResultType(MIRType::Int64); |
| 227 |
setGuard(); // neither removable nor movable because of possible |
| 228 |
// side-effects. |
| 229 |
} |
| 230 |
|
| 231 |
public: |
| 232 |
INSTRUCTION_HEADER(WasmBuiltinTruncateToInt64) |
| 233 |
NAMED_OPERANDS((0, input), (1, instance)); |
| 234 |
TRIVIAL_NEW_WRAPPERS |
| 235 |
|
| 236 |
bool isUnsigned() const { return flags_ & TRUNC_UNSIGNED; } |
| 237 |
bool isSaturating() const { return flags_ & TRUNC_SATURATING; } |
| 238 |
TruncFlags flags() const { return flags_; } |
| 239 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 240 |
|
| 241 |
bool congruentTo(const MDefinition* ins) const override { |
| 242 |
return congruentIfOperandsEqual(ins) && |
| 243 |
ins->toWasmBuiltinTruncateToInt64()->flags() == flags_; |
| 244 |
} |
| 245 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 246 |
}; |
| 247 |
|
| 248 |
class MWasmTruncateToInt64 : public MUnaryInstruction, |
| 249 |
public NoTypePolicy::Data { |
| 250 |
TruncFlags flags_; |
| 251 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 252 |
|
| 253 |
MWasmTruncateToInt64(MDefinition* def, TruncFlags flags, |
| 254 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 255 |
: MUnaryInstruction(classOpcode, def), |
| 256 |
flags_(flags), |
| 257 |
trapSiteDesc_(trapSiteDesc) { |
| 258 |
setResultType(MIRType::Int64); |
| 259 |
setGuard(); // neither removable nor movable because of possible |
| 260 |
// side-effects. |
| 261 |
} |
| 262 |
|
| 263 |
public: |
| 264 |
INSTRUCTION_HEADER(WasmTruncateToInt64) |
| 265 |
TRIVIAL_NEW_WRAPPERS |
| 266 |
|
| 267 |
bool isUnsigned() const { return flags_ & TRUNC_UNSIGNED; } |
| 268 |
bool isSaturating() const { return flags_ & TRUNC_SATURATING; } |
| 269 |
TruncFlags flags() const { return flags_; } |
| 270 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 271 |
|
| 272 |
bool congruentTo(const MDefinition* ins) const override { |
| 273 |
return congruentIfOperandsEqual(ins) && |
| 274 |
ins->toWasmTruncateToInt64()->flags() == flags_; |
| 275 |
} |
| 276 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 277 |
}; |
| 278 |
|
| 279 |
// Truncate a value to an int32, with wasm semantics: this will trap when the |
| 280 |
// value is out of range. |
| 281 |
class MWasmTruncateToInt32 : public MUnaryInstruction, |
| 282 |
public NoTypePolicy::Data { |
| 283 |
TruncFlags flags_; |
| 284 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 285 |
|
| 286 |
explicit MWasmTruncateToInt32(MDefinition* def, TruncFlags flags, |
| 287 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 288 |
: MUnaryInstruction(classOpcode, def), |
| 289 |
flags_(flags), |
| 290 |
trapSiteDesc_(trapSiteDesc) { |
| 291 |
setResultType(MIRType::Int32); |
| 292 |
setGuard(); // neither removable nor movable because of possible |
| 293 |
// side-effects. |
| 294 |
} |
| 295 |
|
| 296 |
public: |
| 297 |
INSTRUCTION_HEADER(WasmTruncateToInt32) |
| 298 |
TRIVIAL_NEW_WRAPPERS |
| 299 |
|
| 300 |
bool isUnsigned() const { return flags_ & TRUNC_UNSIGNED; } |
| 301 |
bool isSaturating() const { return flags_ & TRUNC_SATURATING; } |
| 302 |
TruncFlags flags() const { return flags_; } |
| 303 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 304 |
|
| 305 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 306 |
|
| 307 |
bool congruentTo(const MDefinition* ins) const override { |
| 308 |
return congruentIfOperandsEqual(ins) && |
| 309 |
ins->toWasmTruncateToInt32()->flags() == flags_; |
| 310 |
} |
| 311 |
|
| 312 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 313 |
}; |
| 314 |
|
| 315 |
// It is like MTruncateToInt32 but with instance dependency. |
| 316 |
class MWasmBuiltinTruncateToInt32 : public MAryInstruction<2>, |
| 317 |
public ToInt32Policy::Data { |
| 318 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 319 |
|
| 320 |
MWasmBuiltinTruncateToInt32( |
| 321 |
MDefinition* def, MDefinition* instance, |
| 322 |
wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc()) |
| 323 |
: MAryInstruction(classOpcode), trapSiteDesc_(trapSiteDesc) { |
| 324 |
initOperand(0, def); |
| 325 |
initOperand(1, instance); |
| 326 |
setResultType(MIRType::Int32); |
| 327 |
setMovable(); |
| 328 |
|
| 329 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 330 |
if (MTruncateToInt32::mightHaveSideEffects(def)) { |
| 331 |
setGuard(); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
public: |
| 336 |
INSTRUCTION_HEADER(WasmBuiltinTruncateToInt32) |
| 337 |
NAMED_OPERANDS((0, input), (1, instance)) |
| 338 |
TRIVIAL_NEW_WRAPPERS |
| 339 |
|
| 340 |
bool congruentTo(const MDefinition* ins) const override { |
| 341 |
return congruentIfOperandsEqual(ins); |
| 342 |
} |
| 343 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 344 |
|
| 345 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 346 |
|
| 347 |
ALLOW_CLONE(MWasmBuiltinTruncateToInt32) |
| 348 |
}; |
| 349 |
|
| 350 |
class MWasmBuiltinDivI64 : public MAryInstruction<3>, public ArithPolicy::Data { |
| 351 |
bool canBeNegativeZero_; |
| 352 |
bool canBeNegativeOverflow_; |
| 353 |
bool canBeDivideByZero_; |
| 354 |
bool canBeNegativeDividend_; |
| 355 |
bool unsigned_; // If false, signedness will be derived from operands |
| 356 |
bool trapOnError_; |
| 357 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 358 |
|
| 359 |
MWasmBuiltinDivI64(MDefinition* left, MDefinition* right, |
| 360 |
MDefinition* instance) |
| 361 |
: MAryInstruction(classOpcode), |
| 362 |
canBeNegativeZero_(true), |
| 363 |
canBeNegativeOverflow_(true), |
| 364 |
canBeDivideByZero_(true), |
| 365 |
canBeNegativeDividend_(true), |
| 366 |
unsigned_(false), |
| 367 |
trapOnError_(false) { |
| 368 |
initOperand(0, left); |
| 369 |
initOperand(1, right); |
| 370 |
initOperand(2, instance); |
| 371 |
|
| 372 |
setResultType(MIRType::Int64); |
| 373 |
setMovable(); |
| 374 |
} |
| 375 |
|
| 376 |
public: |
| 377 |
INSTRUCTION_HEADER(WasmBuiltinDivI64) |
| 378 |
|
| 379 |
NAMED_OPERANDS((0, lhs), (1, rhs), (2, instance)) |
| 380 |
|
| 381 |
static MWasmBuiltinDivI64* New( |
| 382 |
TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 383 |
MDefinition* instance, bool unsignd, bool trapOnError = false, |
| 384 |
wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc()) { |
| 385 |
auto* wasm64Div = new (alloc) MWasmBuiltinDivI64(left, right, instance); |
| 386 |
wasm64Div->unsigned_ = unsignd; |
| 387 |
wasm64Div->trapOnError_ = trapOnError; |
| 388 |
wasm64Div->trapSiteDesc_ = trapSiteDesc; |
| 389 |
if (trapOnError) { |
| 390 |
wasm64Div->setGuard(); // not removable because of possible side-effects. |
| 391 |
wasm64Div->setNotMovable(); |
| 392 |
} |
| 393 |
return wasm64Div; |
| 394 |
} |
| 395 |
|
| 396 |
bool canBeNegativeZero() const { return canBeNegativeZero_; } |
| 397 |
void setCanBeNegativeZero(bool negativeZero) { |
| 398 |
canBeNegativeZero_ = negativeZero; |
| 399 |
} |
| 400 |
|
| 401 |
bool canBeNegativeOverflow() const { return canBeNegativeOverflow_; } |
| 402 |
|
| 403 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 404 |
|
| 405 |
bool canBeNegativeDividend() const { |
| 406 |
// "Dividend" is an ambiguous concept for unsigned truncated |
| 407 |
// division, because of the truncation procedure: |
| 408 |
// ((x>>>0)/2)|0, for example, gets transformed in |
| 409 |
// MWasmDiv::truncate into a node with lhs representing x (not |
| 410 |
// x>>>0) and rhs representing the constant 2; in other words, |
| 411 |
// the MIR node corresponds to "cast operands to unsigned and |
| 412 |
// divide" operation. In this case, is the dividend x or is it |
| 413 |
// x>>>0? In order to resolve such ambiguities, we disallow |
| 414 |
// the usage of this method for unsigned division. |
| 415 |
MOZ_ASSERT(!unsigned_); |
| 416 |
return canBeNegativeDividend_; |
| 417 |
} |
| 418 |
|
| 419 |
bool isUnsigned() const { return unsigned_; } |
| 420 |
|
| 421 |
bool trapOnError() const { return trapOnError_; } |
| 422 |
const wasm::TrapSiteDesc& trapSiteDesc() const { |
| 423 |
MOZ_ASSERT(trapSiteDesc_.isValid()); |
| 424 |
return trapSiteDesc_; |
| 425 |
} |
| 426 |
|
| 427 |
ALLOW_CLONE(MWasmBuiltinDivI64) |
| 428 |
}; |
| 429 |
|
| 430 |
class MWasmBuiltinModD : public MAryInstruction<3>, public ArithPolicy::Data { |
| 431 |
wasm::BytecodeOffset bytecodeOffset_; |
| 432 |
|
| 433 |
MWasmBuiltinModD(MDefinition* left, MDefinition* right, MDefinition* instance, |
| 434 |
MIRType type) |
| 435 |
: MAryInstruction(classOpcode) { |
| 436 |
initOperand(0, left); |
| 437 |
initOperand(1, right); |
| 438 |
initOperand(2, instance); |
| 439 |
|
| 440 |
setResultType(type); |
| 441 |
setMovable(); |
| 442 |
} |
| 443 |
|
| 444 |
public: |
| 445 |
INSTRUCTION_HEADER(WasmBuiltinModD) |
| 446 |
NAMED_OPERANDS((0, lhs), (1, rhs), (2, instance)) |
| 447 |
|
| 448 |
static MWasmBuiltinModD* New( |
| 449 |
TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 450 |
MDefinition* instance, MIRType type, |
| 451 |
wasm::BytecodeOffset bytecodeOffset = wasm::BytecodeOffset()) { |
| 452 |
auto* wasmBuiltinModD = |
| 453 |
new (alloc) MWasmBuiltinModD(left, right, instance, type); |
| 454 |
wasmBuiltinModD->bytecodeOffset_ = bytecodeOffset; |
| 455 |
return wasmBuiltinModD; |
| 456 |
} |
| 457 |
|
| 458 |
wasm::BytecodeOffset bytecodeOffset() const { |
| 459 |
MOZ_ASSERT(bytecodeOffset_.isValid()); |
| 460 |
return bytecodeOffset_; |
| 461 |
} |
| 462 |
|
| 463 |
ALLOW_CLONE(MWasmBuiltinModD) |
| 464 |
}; |
| 465 |
|
| 466 |
class MWasmBuiltinModI64 : public MAryInstruction<3>, public ArithPolicy::Data { |
| 467 |
bool unsigned_; // If false, signedness will be derived from operands |
| 468 |
bool canBeNegativeDividend_; |
| 469 |
bool canBeDivideByZero_; |
| 470 |
bool trapOnError_; |
| 471 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 472 |
|
| 473 |
MWasmBuiltinModI64(MDefinition* left, MDefinition* right, |
| 474 |
MDefinition* instance) |
| 475 |
: MAryInstruction(classOpcode), |
| 476 |
unsigned_(false), |
| 477 |
canBeNegativeDividend_(true), |
| 478 |
canBeDivideByZero_(true), |
| 479 |
trapOnError_(false) { |
| 480 |
initOperand(0, left); |
| 481 |
initOperand(1, right); |
| 482 |
initOperand(2, instance); |
| 483 |
|
| 484 |
setResultType(MIRType::Int64); |
| 485 |
setMovable(); |
| 486 |
} |
| 487 |
|
| 488 |
public: |
| 489 |
INSTRUCTION_HEADER(WasmBuiltinModI64) |
| 490 |
|
| 491 |
NAMED_OPERANDS((0, lhs), (1, rhs), (2, instance)) |
| 492 |
|
| 493 |
static MWasmBuiltinModI64* New( |
| 494 |
TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 495 |
MDefinition* instance, bool unsignd, bool trapOnError = false, |
| 496 |
wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc()) { |
| 497 |
auto* mod = new (alloc) MWasmBuiltinModI64(left, right, instance); |
| 498 |
mod->unsigned_ = unsignd; |
| 499 |
mod->trapOnError_ = trapOnError; |
| 500 |
mod->trapSiteDesc_ = trapSiteDesc; |
| 501 |
if (trapOnError) { |
| 502 |
mod->setGuard(); // not removable because of possible side-effects. |
| 503 |
mod->setNotMovable(); |
| 504 |
} |
| 505 |
return mod; |
| 506 |
} |
| 507 |
|
| 508 |
bool canBeNegativeDividend() const { |
| 509 |
MOZ_ASSERT(!unsigned_); |
| 510 |
return canBeNegativeDividend_; |
| 511 |
} |
| 512 |
|
| 513 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 514 |
|
| 515 |
bool isUnsigned() const { return unsigned_; } |
| 516 |
|
| 517 |
bool trapOnError() const { return trapOnError_; } |
| 518 |
const wasm::TrapSiteDesc& trapSiteDesc() const { |
| 519 |
MOZ_ASSERT(trapSiteDesc_.isValid()); |
| 520 |
return trapSiteDesc_; |
| 521 |
} |
| 522 |
|
| 523 |
ALLOW_CLONE(MWasmBuiltinModI64) |
| 524 |
}; |
| 525 |
|
| 526 |
// Check whether we need to fire the interrupt handler (in wasm code). |
| 527 |
class MWasmInterruptCheck : public MUnaryInstruction, |
| 528 |
public NoTypePolicy::Data { |
| 529 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 530 |
|
| 531 |
MWasmInterruptCheck(MDefinition* instance, |
| 532 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 533 |
: MUnaryInstruction(classOpcode, instance), trapSiteDesc_(trapSiteDesc) { |
| 534 |
setGuard(); |
| 535 |
} |
| 536 |
|
| 537 |
public: |
| 538 |
INSTRUCTION_HEADER(WasmInterruptCheck) |
| 539 |
TRIVIAL_NEW_WRAPPERS |
| 540 |
NAMED_OPERANDS((0, instance)) |
| 541 |
|
| 542 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 543 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 544 |
|
| 545 |
ALLOW_CLONE(MWasmInterruptCheck) |
| 546 |
}; |
| 547 |
|
| 548 |
// Directly jumps to the indicated trap, leaving Wasm code and reporting a |
| 549 |
// runtime error. |
| 550 |
|
| 551 |
class MWasmTrap : public MAryControlInstruction<0, 0>, |
| 552 |
public NoTypePolicy::Data { |
| 553 |
wasm::Trap trap_; |
| 554 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 555 |
|
| 556 |
explicit MWasmTrap(wasm::Trap trap, const wasm::TrapSiteDesc& trapSiteDesc) |
| 557 |
: MAryControlInstruction(classOpcode), |
| 558 |
trap_(trap), |
| 559 |
trapSiteDesc_(trapSiteDesc) {} |
| 560 |
|
| 561 |
public: |
| 562 |
INSTRUCTION_HEADER(WasmTrap) |
| 563 |
TRIVIAL_NEW_WRAPPERS |
| 564 |
|
| 565 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 566 |
|
| 567 |
wasm::Trap trap() const { return trap_; } |
| 568 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 569 |
}; |
| 570 |
|
| 571 |
// Flips the input's sign bit, independently of the rest of the number's |
| 572 |
// payload. Note this is different from multiplying by minus-one, which has |
| 573 |
// side-effects for e.g. NaNs. |
| 574 |
class MWasmNeg : public MUnaryInstruction, public NoTypePolicy::Data { |
| 575 |
MWasmNeg(MDefinition* op, MIRType type) : MUnaryInstruction(classOpcode, op) { |
| 576 |
setResultType(type); |
| 577 |
setMovable(); |
| 578 |
} |
| 579 |
|
| 580 |
public: |
| 581 |
INSTRUCTION_HEADER(WasmNeg) |
| 582 |
TRIVIAL_NEW_WRAPPERS |
| 583 |
ALLOW_CLONE(MWasmNeg) |
| 584 |
}; |
| 585 |
|
| 586 |
// Machine-level bitwise AND/OR/XOR, avoiding all JS-level complexity embodied |
| 587 |
// in MBinaryBitwiseInstruction. |
| 588 |
class MWasmBinaryBitwise : public MBinaryInstruction, |
| 589 |
public NoTypePolicy::Data { |
| 590 |
public: |
| 591 |
enum class SubOpcode { And, Or, Xor }; |
| 592 |
|
| 593 |
protected: |
| 594 |
MWasmBinaryBitwise(MDefinition* left, MDefinition* right, MIRType type, |
| 595 |
SubOpcode subOpcode) |
| 596 |
: MBinaryInstruction(classOpcode, left, right), subOpcode_(subOpcode) { |
| 597 |
MOZ_ASSERT(type == MIRType::Int32 || type == MIRType::Int64); |
| 598 |
setResultType(type); |
| 599 |
setMovable(); |
| 600 |
setCommutative(); |
| 601 |
} |
| 602 |
|
| 603 |
public: |
| 604 |
INSTRUCTION_HEADER(WasmBinaryBitwise) |
| 605 |
TRIVIAL_NEW_WRAPPERS |
| 606 |
|
| 607 |
SubOpcode subOpcode() const { return subOpcode_; } |
| 608 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 609 |
|
| 610 |
bool congruentTo(const MDefinition* ins) const override { |
| 611 |
return ins->isWasmBinaryBitwise() && |
| 612 |
ins->toWasmBinaryBitwise()->subOpcode() == subOpcode() && |
| 613 |
binaryCongruentTo(ins); |
| 614 |
} |
| 615 |
|
| 616 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 617 |
|
| 618 |
#ifdef JS_JITSPEW |
| 619 |
void getExtras(ExtrasCollector* extras) const override { |
| 620 |
const char* what = "!!unknown!!"; |
| 621 |
switch (subOpcode()) { |
| 622 |
case SubOpcode::And: |
| 623 |
what = "And"; |
| 624 |
break; |
| 625 |
case SubOpcode::Or: |
| 626 |
what = "Or"; |
| 627 |
break; |
| 628 |
case SubOpcode::Xor: |
| 629 |
what = "Xor"; |
| 630 |
break; |
| 631 |
} |
| 632 |
extras->add(what); |
| 633 |
} |
| 634 |
#endif |
| 635 |
|
| 636 |
private: |
| 637 |
SubOpcode subOpcode_; |
| 638 |
|
| 639 |
ALLOW_CLONE(MWasmBinaryBitwise) |
| 640 |
}; |
| 641 |
|
| 642 |
class MWasmLoadInstance : public MUnaryInstruction, public NoTypePolicy::Data { |
| 643 |
uint32_t offset_; |
| 644 |
AliasSet aliases_; |
| 645 |
|
| 646 |
explicit MWasmLoadInstance(MDefinition* instance, uint32_t offset, |
| 647 |
MIRType type, AliasSet aliases) |
| 648 |
: MUnaryInstruction(classOpcode, instance), |
| 649 |
offset_(offset), |
| 650 |
aliases_(aliases) { |
| 651 |
// Different instance data have different alias classes and only those |
| 652 |
// classes are allowed. |
| 653 |
MOZ_ASSERT( |
| 654 |
aliases_.flags() == AliasSet::Load(AliasSet::WasmHeapMeta).flags() || |
| 655 |
aliases_.flags() == AliasSet::Load(AliasSet::WasmTableMeta).flags() || |
| 656 |
aliases_.flags() == |
| 657 |
AliasSet::Load(AliasSet::WasmPendingException).flags() || |
| 658 |
aliases_.flags() == AliasSet::None().flags()); |
| 659 |
|
| 660 |
// The only types supported at the moment. |
| 661 |
MOZ_ASSERT(type == MIRType::Pointer || type == MIRType::Int32 || |
| 662 |
type == MIRType::Int64 || type == MIRType::WasmAnyRef); |
| 663 |
|
| 664 |
setMovable(); |
| 665 |
setResultType(type); |
| 666 |
} |
| 667 |
|
| 668 |
public: |
| 669 |
INSTRUCTION_HEADER(WasmLoadInstance) |
| 670 |
TRIVIAL_NEW_WRAPPERS |
| 671 |
NAMED_OPERANDS((0, instance)) |
| 672 |
|
| 673 |
uint32_t offset() const { return offset_; } |
| 674 |
|
| 675 |
bool congruentTo(const MDefinition* ins) const override { |
| 676 |
return op() == ins->op() && |
| 677 |
offset() == ins->toWasmLoadInstance()->offset() && |
| 678 |
type() == ins->type(); |
| 679 |
} |
| 680 |
|
| 681 |
HashNumber valueHash() const override { |
| 682 |
return addU32ToHash(HashNumber(op()), offset()); |
| 683 |
} |
| 684 |
|
| 685 |
AliasSet getAliasSet() const override { return aliases_; } |
| 686 |
}; |
| 687 |
|
| 688 |
class MWasmStoreInstance : public MBinaryInstruction, |
| 689 |
public NoTypePolicy::Data { |
| 690 |
uint32_t offset_; |
| 691 |
AliasSet aliases_; |
| 692 |
|
| 693 |
explicit MWasmStoreInstance(MDefinition* instance, MDefinition* value, |
| 694 |
uint32_t offset, MIRType type, AliasSet aliases) |
| 695 |
: MBinaryInstruction(classOpcode, instance, value), |
| 696 |
offset_(offset), |
| 697 |
aliases_(aliases) { |
| 698 |
// Different instance data have different alias classes and only those |
| 699 |
// classes are allowed. |
| 700 |
MOZ_ASSERT(aliases_.flags() == |
| 701 |
AliasSet::Store(AliasSet::WasmPendingException).flags()); |
| 702 |
|
| 703 |
// The only types supported at the moment. |
| 704 |
MOZ_ASSERT(type == MIRType::Pointer || type == MIRType::Int32 || |
| 705 |
type == MIRType::Int64 || type == MIRType::WasmAnyRef); |
| 706 |
} |
| 707 |
|
| 708 |
public: |
| 709 |
INSTRUCTION_HEADER(WasmStoreInstance) |
| 710 |
TRIVIAL_NEW_WRAPPERS |
| 711 |
NAMED_OPERANDS((0, instance), (1, value)) |
| 712 |
|
| 713 |
uint32_t offset() const { return offset_; } |
| 714 |
|
| 715 |
AliasSet getAliasSet() const override { return aliases_; } |
| 716 |
}; |
| 717 |
|
| 718 |
class MWasmHeapReg : public MNullaryInstruction { |
| 719 |
AliasSet aliases_; |
| 720 |
|
| 721 |
explicit MWasmHeapReg(AliasSet aliases) |
| 722 |
: MNullaryInstruction(classOpcode), aliases_(aliases) { |
| 723 |
setMovable(); |
| 724 |
setResultType(MIRType::Pointer); |
| 725 |
} |
| 726 |
|
| 727 |
public: |
| 728 |
INSTRUCTION_HEADER(WasmHeapReg) |
| 729 |
TRIVIAL_NEW_WRAPPERS |
| 730 |
|
| 731 |
bool congruentTo(const MDefinition* ins) const override { |
| 732 |
return ins->isWasmHeapReg(); |
| 733 |
} |
| 734 |
|
| 735 |
AliasSet getAliasSet() const override { return aliases_; } |
| 736 |
}; |
| 737 |
|
| 738 |
// For memory32, bounds check nodes are of type Int32 on 32-bit systems for both |
| 739 |
// wasm and asm.js code, as well as on 64-bit systems for asm.js code and for |
| 740 |
// wasm code that is known to have a bounds check limit that fits into 32 bits. |
| 741 |
// They are of type Int64 only on 64-bit systems for wasm code with 4GB heaps. |
| 742 |
// There is no way for nodes of both types to be present in the same function. |
| 743 |
// Should this change, then BCE must be updated to take type into account. |
| 744 |
// |
| 745 |
// For memory64, bounds check nodes are always of type Int64. |
| 746 |
|
| 747 |
class MWasmBoundsCheck : public MBinaryInstruction, public NoTypePolicy::Data { |
| 748 |
public: |
| 749 |
enum Target { |
| 750 |
// Linear memory at index zero, which is the only memory allowed so far. |
| 751 |
Memory0, |
| 752 |
// Everything else. Currently comprises tables, and arrays in the GC |
| 753 |
// proposal. |
| 754 |
Unknown |
| 755 |
}; |
| 756 |
|
| 757 |
private: |
| 758 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 759 |
Target target_; |
| 760 |
|
| 761 |
explicit MWasmBoundsCheck(MDefinition* index, MDefinition* boundsCheckLimit, |
| 762 |
const wasm::TrapSiteDesc& trapSiteDesc, |
| 763 |
Target target) |
| 764 |
: MBinaryInstruction(classOpcode, index, boundsCheckLimit), |
| 765 |
trapSiteDesc_(trapSiteDesc), |
| 766 |
target_(target) { |
| 767 |
MOZ_ASSERT(index->type() == boundsCheckLimit->type()); |
| 768 |
|
| 769 |
// Bounds check is effectful: it throws for OOB. |
| 770 |
setGuard(); |
| 771 |
|
| 772 |
if (JitOptions.spectreIndexMasking) { |
| 773 |
setResultType(index->type()); |
| 774 |
} |
| 775 |
} |
| 776 |
|
| 777 |
public: |
| 778 |
INSTRUCTION_HEADER(WasmBoundsCheck) |
| 779 |
TRIVIAL_NEW_WRAPPERS |
| 780 |
NAMED_OPERANDS((0, index), (1, boundsCheckLimit)) |
| 781 |
|
| 782 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 783 |
|
| 784 |
bool isMemory0() const { return target_ == MWasmBoundsCheck::Memory0; } |
| 785 |
|
| 786 |
bool isRedundant() const { return !isGuard(); } |
| 787 |
|
| 788 |
void setRedundant() { setNotGuard(); } |
| 789 |
|
| 790 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 791 |
|
| 792 |
ALLOW_CLONE(MWasmBoundsCheck) |
| 793 |
}; |
| 794 |
|
| 795 |
class MWasmAddOffset : public MUnaryInstruction, public NoTypePolicy::Data { |
| 796 |
uint64_t offset_; |
| 797 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 798 |
|
| 799 |
MWasmAddOffset(MDefinition* base, uint64_t offset, |
| 800 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 801 |
: MUnaryInstruction(classOpcode, base), |
| 802 |
offset_(offset), |
| 803 |
trapSiteDesc_(trapSiteDesc) { |
| 804 |
setGuard(); |
| 805 |
MOZ_ASSERT(base->type() == MIRType::Int32 || |
| 806 |
base->type() == MIRType::Int64); |
| 807 |
setResultType(base->type()); |
| 808 |
} |
| 809 |
|
| 810 |
public: |
| 811 |
INSTRUCTION_HEADER(WasmAddOffset) |
| 812 |
TRIVIAL_NEW_WRAPPERS |
| 813 |
NAMED_OPERANDS((0, base)) |
| 814 |
|
| 815 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 816 |
|
| 817 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 818 |
|
| 819 |
uint64_t offset() const { return offset_; } |
| 820 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 821 |
}; |
| 822 |
|
| 823 |
class MWasmAlignmentCheck : public MUnaryInstruction, |
| 824 |
public NoTypePolicy::Data { |
| 825 |
uint32_t byteSize_; |
| 826 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 827 |
|
| 828 |
explicit MWasmAlignmentCheck(MDefinition* index, uint32_t byteSize, |
| 829 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 830 |
: MUnaryInstruction(classOpcode, index), |
| 831 |
byteSize_(byteSize), |
| 832 |
trapSiteDesc_(trapSiteDesc) { |
| 833 |
MOZ_ASSERT(mozilla::IsPowerOfTwo(byteSize)); |
| 834 |
// Alignment check is effectful: it throws for unaligned. |
| 835 |
setGuard(); |
| 836 |
} |
| 837 |
|
| 838 |
public: |
| 839 |
INSTRUCTION_HEADER(WasmAlignmentCheck) |
| 840 |
TRIVIAL_NEW_WRAPPERS |
| 841 |
NAMED_OPERANDS((0, index)) |
| 842 |
|
| 843 |
bool congruentTo(const MDefinition* ins) const override; |
| 844 |
|
| 845 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 846 |
|
| 847 |
uint32_t byteSize() const { return byteSize_; } |
| 848 |
|
| 849 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 850 |
|
| 851 |
ALLOW_CLONE(MWasmAlignmentCheck) |
| 852 |
}; |
| 853 |
|
| 854 |
class MWasmLoad |
| 855 |
: public MVariadicInstruction, // memoryBase is nullptr on some platforms |
| 856 |
public NoTypePolicy::Data { |
| 857 |
wasm::MemoryAccessDesc access_; |
| 858 |
|
| 859 |
explicit MWasmLoad(const wasm::MemoryAccessDesc& access, MIRType resultType) |
| 860 |
: MVariadicInstruction(classOpcode), access_(access) { |
| 861 |
setGuard(); |
| 862 |
setResultType(resultType); |
| 863 |
} |
| 864 |
|
| 865 |
public: |
| 866 |
INSTRUCTION_HEADER(WasmLoad) |
| 867 |
NAMED_OPERANDS((0, base), (1, memoryBase)); |
| 868 |
|
| 869 |
static MWasmLoad* New(TempAllocator& alloc, MDefinition* memoryBase, |
| 870 |
MDefinition* base, const wasm::MemoryAccessDesc& access, |
| 871 |
MIRType resultType) { |
| 872 |
MWasmLoad* load = new (alloc) MWasmLoad(access, resultType); |
| 873 |
if (!load->init(alloc, 1 + !!memoryBase)) { |
| 874 |
return nullptr; |
| 875 |
} |
| 876 |
|
| 877 |
load->initOperand(0, base); |
| 878 |
if (memoryBase) { |
| 879 |
load->initOperand(1, memoryBase); |
| 880 |
} |
| 881 |
|
| 882 |
return load; |
| 883 |
} |
| 884 |
|
| 885 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 886 |
|
| 887 |
AliasSet getAliasSet() const override { |
| 888 |
// When a barrier is needed, make the instruction effectful by giving |
| 889 |
// it a "store" effect. |
| 890 |
if (access_.isAtomic()) { |
| 891 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 892 |
} |
| 893 |
return AliasSet::Load(AliasSet::WasmHeap); |
| 894 |
} |
| 895 |
|
| 896 |
bool hasMemoryBase() const { return numOperands() > 1; } |
| 897 |
|
| 898 |
#ifdef JS_JITSPEW |
| 899 |
void getExtras(ExtrasCollector* extras) const override { |
| 900 |
char buf[64]; |
| 901 |
SprintfLiteral(buf, "(offs=%lld)", (long long int)access().offset64()); |
| 902 |
extras->add(buf); |
| 903 |
} |
| 904 |
#endif |
| 905 |
|
| 906 |
// Unfortunately we cannot use ALLOW_CLONE here, due to the variable number |
| 907 |
// of operands. |
| 908 |
bool canClone() const override { return true; } |
| 909 |
MInstruction* clone(TempAllocator& alloc, |
| 910 |
const MDefinitionVector& inputs) const override { |
| 911 |
MInstruction* res = |
| 912 |
MWasmLoad::New(alloc, hasMemoryBase() ? memoryBase() : nullptr, base(), |
| 913 |
access(), type()); |
| 914 |
if (!res) { |
| 915 |
return nullptr; |
| 916 |
} |
| 917 |
for (size_t i = 0; i < numOperands(); i++) { |
| 918 |
res->replaceOperand(i, inputs[i]); |
| 919 |
} |
| 920 |
return res; |
| 921 |
} |
| 922 |
}; |
| 923 |
|
| 924 |
class MWasmStore : public MVariadicInstruction, public NoTypePolicy::Data { |
| 925 |
wasm::MemoryAccessDesc access_; |
| 926 |
|
| 927 |
explicit MWasmStore(const wasm::MemoryAccessDesc& access) |
| 928 |
: MVariadicInstruction(classOpcode), access_(access) { |
| 929 |
setGuard(); |
| 930 |
} |
| 931 |
|
| 932 |
public: |
| 933 |
INSTRUCTION_HEADER(WasmStore) |
| 934 |
NAMED_OPERANDS((0, base), (1, value), (2, memoryBase)) |
| 935 |
|
| 936 |
static MWasmStore* New(TempAllocator& alloc, MDefinition* memoryBase, |
| 937 |
MDefinition* base, |
| 938 |
const wasm::MemoryAccessDesc& access, |
| 939 |
MDefinition* value) { |
| 940 |
MWasmStore* store = new (alloc) MWasmStore(access); |
| 941 |
if (!store->init(alloc, 2 + !!memoryBase)) { |
| 942 |
return nullptr; |
| 943 |
} |
| 944 |
|
| 945 |
store->initOperand(0, base); |
| 946 |
store->initOperand(1, value); |
| 947 |
if (memoryBase) { |
| 948 |
store->initOperand(2, memoryBase); |
| 949 |
} |
| 950 |
|
| 951 |
return store; |
| 952 |
} |
| 953 |
|
| 954 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 955 |
|
| 956 |
AliasSet getAliasSet() const override { |
| 957 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 958 |
} |
| 959 |
|
| 960 |
bool hasMemoryBase() const { return numOperands() > 2; } |
| 961 |
|
| 962 |
#ifdef JS_JITSPEW |
| 963 |
void getExtras(ExtrasCollector* extras) const override { |
| 964 |
char buf[64]; |
| 965 |
SprintfLiteral(buf, "(offs=%lld)", (long long int)access().offset64()); |
| 966 |
extras->add(buf); |
| 967 |
} |
| 968 |
#endif |
| 969 |
|
| 970 |
bool canClone() const override { return true; } |
| 971 |
MInstruction* clone(TempAllocator& alloc, |
| 972 |
const MDefinitionVector& inputs) const override { |
| 973 |
MInstruction* res = |
| 974 |
MWasmStore::New(alloc, hasMemoryBase() ? memoryBase() : nullptr, base(), |
| 975 |
access(), value()); |
| 976 |
if (!res) { |
| 977 |
return nullptr; |
| 978 |
} |
| 979 |
for (size_t i = 0; i < numOperands(); i++) { |
| 980 |
res->replaceOperand(i, inputs[i]); |
| 981 |
} |
| 982 |
return res; |
| 983 |
} |
| 984 |
}; |
| 985 |
|
| 986 |
class MAsmJSMemoryAccess { |
| 987 |
Scalar::Type accessType_; |
| 988 |
bool needsBoundsCheck_; |
| 989 |
|
| 990 |
public: |
| 991 |
explicit MAsmJSMemoryAccess(Scalar::Type accessType) |
| 992 |
: accessType_(accessType), needsBoundsCheck_(true) { |
| 993 |
MOZ_ASSERT(accessType != Scalar::Uint8Clamped); |
| 994 |
} |
| 995 |
|
| 996 |
Scalar::Type accessType() const { return accessType_; } |
| 997 |
unsigned byteSize() const { return TypedArrayElemSize(accessType()); } |
| 998 |
bool needsBoundsCheck() const { return needsBoundsCheck_; } |
| 999 |
|
| 1000 |
wasm::MemoryAccessDesc access() const { |
| 1001 |
return wasm::MemoryAccessDesc(0, accessType_, Scalar::byteSize(accessType_), |
| 1002 |
0, wasm::TrapSiteDesc(), false); |
| 1003 |
} |
| 1004 |
|
| 1005 |
void removeBoundsCheck() { needsBoundsCheck_ = false; } |
| 1006 |
}; |
| 1007 |
|
| 1008 |
class MAsmJSLoadHeap |
| 1009 |
: public MVariadicInstruction, // 1 plus optional memoryBase and |
| 1010 |
// boundsCheckLimit |
| 1011 |
public MAsmJSMemoryAccess, |
| 1012 |
public NoTypePolicy::Data { |
| 1013 |
uint32_t memoryBaseIndex_; |
| 1014 |
|
| 1015 |
explicit MAsmJSLoadHeap(uint32_t memoryBaseIndex, Scalar::Type accessType) |
| 1016 |
: MVariadicInstruction(classOpcode), |
| 1017 |
MAsmJSMemoryAccess(accessType), |
| 1018 |
memoryBaseIndex_(memoryBaseIndex) { |
| 1019 |
setResultType(ScalarTypeToMIRType(accessType)); |
| 1020 |
} |
| 1021 |
|
| 1022 |
public: |
| 1023 |
INSTRUCTION_HEADER(AsmJSLoadHeap) |
| 1024 |
NAMED_OPERANDS((0, base), (1, boundsCheckLimit)) |
| 1025 |
|
| 1026 |
static MAsmJSLoadHeap* New(TempAllocator& alloc, MDefinition* memoryBase, |
| 1027 |
MDefinition* base, MDefinition* boundsCheckLimit, |
| 1028 |
Scalar::Type accessType) { |
| 1029 |
uint32_t nextIndex = 2; |
| 1030 |
uint32_t memoryBaseIndex = memoryBase ? nextIndex++ : UINT32_MAX; |
| 1031 |
|
| 1032 |
MAsmJSLoadHeap* load = |
| 1033 |
new (alloc) MAsmJSLoadHeap(memoryBaseIndex, accessType); |
| 1034 |
if (!load->init(alloc, nextIndex)) { |
| 1035 |
return nullptr; |
| 1036 |
} |
| 1037 |
|
| 1038 |
load->initOperand(0, base); |
| 1039 |
load->initOperand(1, boundsCheckLimit); |
| 1040 |
if (memoryBase) { |
| 1041 |
load->initOperand(memoryBaseIndex, memoryBase); |
| 1042 |
} |
| 1043 |
|
| 1044 |
return load; |
| 1045 |
} |
| 1046 |
|
| 1047 |
bool hasMemoryBase() const { return memoryBaseIndex_ != UINT32_MAX; } |
| 1048 |
MDefinition* memoryBase() const { |
| 1049 |
MOZ_ASSERT(hasMemoryBase()); |
| 1050 |
return getOperand(memoryBaseIndex_); |
| 1051 |
} |
| 1052 |
|
| 1053 |
bool congruentTo(const MDefinition* ins) const override; |
| 1054 |
AliasSet getAliasSet() const override { |
| 1055 |
return AliasSet::Load(AliasSet::WasmHeap); |
| 1056 |
} |
| 1057 |
AliasType mightAlias(const MDefinition* def) const override; |
| 1058 |
}; |
| 1059 |
|
| 1060 |
class MAsmJSStoreHeap |
| 1061 |
: public MVariadicInstruction, // 2 plus optional memoryBase and |
| 1062 |
// boundsCheckLimit |
| 1063 |
public MAsmJSMemoryAccess, |
| 1064 |
public NoTypePolicy::Data { |
| 1065 |
uint32_t memoryBaseIndex_; |
| 1066 |
|
| 1067 |
explicit MAsmJSStoreHeap(uint32_t memoryBaseIndex, Scalar::Type accessType) |
| 1068 |
: MVariadicInstruction(classOpcode), |
| 1069 |
MAsmJSMemoryAccess(accessType), |
| 1070 |
memoryBaseIndex_(memoryBaseIndex) {} |
| 1071 |
|
| 1072 |
public: |
| 1073 |
INSTRUCTION_HEADER(AsmJSStoreHeap) |
| 1074 |
NAMED_OPERANDS((0, base), (1, value), (2, boundsCheckLimit)) |
| 1075 |
|
| 1076 |
static MAsmJSStoreHeap* New(TempAllocator& alloc, MDefinition* memoryBase, |
| 1077 |
MDefinition* base, MDefinition* boundsCheckLimit, |
| 1078 |
Scalar::Type accessType, MDefinition* v) { |
| 1079 |
uint32_t nextIndex = 3; |
| 1080 |
uint32_t memoryBaseIndex = memoryBase ? nextIndex++ : UINT32_MAX; |
| 1081 |
|
| 1082 |
MAsmJSStoreHeap* store = |
| 1083 |
new (alloc) MAsmJSStoreHeap(memoryBaseIndex, accessType); |
| 1084 |
if (!store->init(alloc, nextIndex)) { |
| 1085 |
return nullptr; |
| 1086 |
} |
| 1087 |
|
| 1088 |
store->initOperand(0, base); |
| 1089 |
store->initOperand(1, v); |
| 1090 |
store->initOperand(2, boundsCheckLimit); |
| 1091 |
if (memoryBase) { |
| 1092 |
store->initOperand(memoryBaseIndex, memoryBase); |
| 1093 |
} |
| 1094 |
|
| 1095 |
return store; |
| 1096 |
} |
| 1097 |
|
| 1098 |
bool hasMemoryBase() const { return memoryBaseIndex_ != UINT32_MAX; } |
| 1099 |
MDefinition* memoryBase() const { |
| 1100 |
MOZ_ASSERT(hasMemoryBase()); |
| 1101 |
return getOperand(memoryBaseIndex_); |
| 1102 |
} |
| 1103 |
|
| 1104 |
AliasSet getAliasSet() const override { |
| 1105 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 1106 |
} |
| 1107 |
}; |
| 1108 |
|
| 1109 |
class MWasmCompareExchangeHeap : public MVariadicInstruction, |
| 1110 |
public NoTypePolicy::Data { |
| 1111 |
wasm::MemoryAccessDesc access_; |
| 1112 |
wasm::BytecodeOffset bytecodeOffset_; |
| 1113 |
|
| 1114 |
explicit MWasmCompareExchangeHeap(const wasm::MemoryAccessDesc& access, |
| 1115 |
wasm::BytecodeOffset bytecodeOffset) |
| 1116 |
: MVariadicInstruction(classOpcode), |
| 1117 |
access_(access), |
| 1118 |
bytecodeOffset_(bytecodeOffset) { |
| 1119 |
setGuard(); // Not removable |
| 1120 |
setResultType(ScalarTypeToMIRType(access.type())); |
| 1121 |
} |
| 1122 |
|
| 1123 |
public: |
| 1124 |
INSTRUCTION_HEADER(WasmCompareExchangeHeap) |
| 1125 |
NAMED_OPERANDS((0, base), (1, oldValue), (2, newValue), (3, instance), |
| 1126 |
(4, memoryBase)) |
| 1127 |
|
| 1128 |
static MWasmCompareExchangeHeap* New(TempAllocator& alloc, |
| 1129 |
wasm::BytecodeOffset bytecodeOffset, |
| 1130 |
MDefinition* memoryBase, |
| 1131 |
MDefinition* base, |
| 1132 |
const wasm::MemoryAccessDesc& access, |
| 1133 |
MDefinition* oldv, MDefinition* newv, |
| 1134 |
MDefinition* instance) { |
| 1135 |
MWasmCompareExchangeHeap* cas = |
| 1136 |
new (alloc) MWasmCompareExchangeHeap(access, bytecodeOffset); |
| 1137 |
if (!cas->init(alloc, 4 + !!memoryBase)) { |
| 1138 |
return nullptr; |
| 1139 |
} |
| 1140 |
cas->initOperand(0, base); |
| 1141 |
cas->initOperand(1, oldv); |
| 1142 |
cas->initOperand(2, newv); |
| 1143 |
cas->initOperand(3, instance); |
| 1144 |
if (memoryBase) { |
| 1145 |
cas->initOperand(4, memoryBase); |
| 1146 |
} |
| 1147 |
return cas; |
| 1148 |
} |
| 1149 |
|
| 1150 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 1151 |
wasm::BytecodeOffset bytecodeOffset() const { return bytecodeOffset_; } |
| 1152 |
|
| 1153 |
AliasSet getAliasSet() const override { |
| 1154 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 1155 |
} |
| 1156 |
|
| 1157 |
bool hasMemoryBase() const { return numOperands() > 4; } |
| 1158 |
}; |
| 1159 |
|
| 1160 |
class MWasmAtomicExchangeHeap : public MVariadicInstruction, |
| 1161 |
public NoTypePolicy::Data { |
| 1162 |
wasm::MemoryAccessDesc access_; |
| 1163 |
wasm::BytecodeOffset bytecodeOffset_; |
| 1164 |
|
| 1165 |
explicit MWasmAtomicExchangeHeap(const wasm::MemoryAccessDesc& access, |
| 1166 |
wasm::BytecodeOffset bytecodeOffset) |
| 1167 |
: MVariadicInstruction(classOpcode), |
| 1168 |
access_(access), |
| 1169 |
bytecodeOffset_(bytecodeOffset) { |
| 1170 |
setGuard(); // Not removable |
| 1171 |
setResultType(ScalarTypeToMIRType(access.type())); |
| 1172 |
} |
| 1173 |
|
| 1174 |
public: |
| 1175 |
INSTRUCTION_HEADER(WasmAtomicExchangeHeap) |
| 1176 |
NAMED_OPERANDS((0, base), (1, value), (2, instance), (3, memoryBase)) |
| 1177 |
|
| 1178 |
static MWasmAtomicExchangeHeap* New(TempAllocator& alloc, |
| 1179 |
wasm::BytecodeOffset bytecodeOffset, |
| 1180 |
MDefinition* memoryBase, |
| 1181 |
MDefinition* base, |
| 1182 |
const wasm::MemoryAccessDesc& access, |
| 1183 |
MDefinition* value, |
| 1184 |
MDefinition* instance) { |
| 1185 |
MWasmAtomicExchangeHeap* xchg = |
| 1186 |
new (alloc) MWasmAtomicExchangeHeap(access, bytecodeOffset); |
| 1187 |
if (!xchg->init(alloc, 3 + !!memoryBase)) { |
| 1188 |
return nullptr; |
| 1189 |
} |
| 1190 |
|
| 1191 |
xchg->initOperand(0, base); |
| 1192 |
xchg->initOperand(1, value); |
| 1193 |
xchg->initOperand(2, instance); |
| 1194 |
if (memoryBase) { |
| 1195 |
xchg->initOperand(3, memoryBase); |
| 1196 |
} |
| 1197 |
|
| 1198 |
return xchg; |
| 1199 |
} |
| 1200 |
|
| 1201 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 1202 |
wasm::BytecodeOffset bytecodeOffset() const { return bytecodeOffset_; } |
| 1203 |
|
| 1204 |
AliasSet getAliasSet() const override { |
| 1205 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 1206 |
} |
| 1207 |
|
| 1208 |
bool hasMemoryBase() const { return numOperands() > 3; } |
| 1209 |
}; |
| 1210 |
|
| 1211 |
class MWasmAtomicBinopHeap : public MVariadicInstruction, |
| 1212 |
public NoTypePolicy::Data { |
| 1213 |
AtomicOp op_; |
| 1214 |
wasm::MemoryAccessDesc access_; |
| 1215 |
wasm::BytecodeOffset bytecodeOffset_; |
| 1216 |
|
| 1217 |
explicit MWasmAtomicBinopHeap(AtomicOp op, |
| 1218 |
const wasm::MemoryAccessDesc& access, |
| 1219 |
wasm::BytecodeOffset bytecodeOffset) |
| 1220 |
: MVariadicInstruction(classOpcode), |
| 1221 |
op_(op), |
| 1222 |
access_(access), |
| 1223 |
bytecodeOffset_(bytecodeOffset) { |
| 1224 |
setGuard(); // Not removable |
| 1225 |
setResultType(ScalarTypeToMIRType(access.type())); |
| 1226 |
} |
| 1227 |
|
| 1228 |
public: |
| 1229 |
INSTRUCTION_HEADER(WasmAtomicBinopHeap) |
| 1230 |
NAMED_OPERANDS((0, base), (1, value), (2, instance), (3, memoryBase)) |
| 1231 |
|
| 1232 |
static MWasmAtomicBinopHeap* New(TempAllocator& alloc, |
| 1233 |
wasm::BytecodeOffset bytecodeOffset, |
| 1234 |
AtomicOp op, MDefinition* memoryBase, |
| 1235 |
MDefinition* base, |
| 1236 |
const wasm::MemoryAccessDesc& access, |
| 1237 |
MDefinition* v, MDefinition* instance) { |
| 1238 |
MWasmAtomicBinopHeap* binop = |
| 1239 |
new (alloc) MWasmAtomicBinopHeap(op, access, bytecodeOffset); |
| 1240 |
if (!binop->init(alloc, 3 + !!memoryBase)) { |
| 1241 |
return nullptr; |
| 1242 |
} |
| 1243 |
|
| 1244 |
binop->initOperand(0, base); |
| 1245 |
binop->initOperand(1, v); |
| 1246 |
binop->initOperand(2, instance); |
| 1247 |
if (memoryBase) { |
| 1248 |
binop->initOperand(3, memoryBase); |
| 1249 |
} |
| 1250 |
|
| 1251 |
return binop; |
| 1252 |
} |
| 1253 |
|
| 1254 |
AtomicOp operation() const { return op_; } |
| 1255 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 1256 |
wasm::BytecodeOffset bytecodeOffset() const { return bytecodeOffset_; } |
| 1257 |
|
| 1258 |
AliasSet getAliasSet() const override { |
| 1259 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 1260 |
} |
| 1261 |
|
| 1262 |
bool hasMemoryBase() const { return numOperands() > 3; } |
| 1263 |
}; |
| 1264 |
|
| 1265 |
class MWasmLoadInstanceDataField : public MUnaryInstruction, |
| 1266 |
public NoTypePolicy::Data { |
| 1267 |
unsigned instanceDataOffset_; |
| 1268 |
bool isConstant_; |
| 1269 |
|
| 1270 |
MWasmLoadInstanceDataField( |
| 1271 |
MIRType type, unsigned instanceDataOffset, bool isConstant, |
| 1272 |
MDefinition* instance, |
| 1273 |
wasm::MaybeRefType maybeRefType = wasm::MaybeRefType()) |
| 1274 |
: MUnaryInstruction(classOpcode, instance), |
| 1275 |
instanceDataOffset_(instanceDataOffset), |
| 1276 |
isConstant_(isConstant) { |
| 1277 |
MOZ_ASSERT(IsNumberType(type) || type == MIRType::Simd128 || |
| 1278 |
type == MIRType::Pointer || type == MIRType::WasmAnyRef); |
| 1279 |
setResultType(type); |
| 1280 |
setMovable(); |
| 1281 |
initWasmRefType(maybeRefType); |
| 1282 |
} |
| 1283 |
|
| 1284 |
public: |
| 1285 |
INSTRUCTION_HEADER(WasmLoadInstanceDataField) |
| 1286 |
TRIVIAL_NEW_WRAPPERS |
| 1287 |
NAMED_OPERANDS((0, instance)) |
| 1288 |
|
| 1289 |
unsigned instanceDataOffset() const { return instanceDataOffset_; } |
| 1290 |
|
| 1291 |
HashNumber valueHash() const override; |
| 1292 |
bool congruentTo(const MDefinition* ins) const override; |
| 1293 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 1294 |
|
| 1295 |
AliasSet getAliasSet() const override { |
| 1296 |
return isConstant_ ? AliasSet::None() |
| 1297 |
: AliasSet::Load(AliasSet::WasmInstanceData); |
| 1298 |
} |
| 1299 |
|
| 1300 |
AliasType mightAlias(const MDefinition* def) const override; |
| 1301 |
|
| 1302 |
#ifdef JS_JITSPEW |
| 1303 |
void getExtras(ExtrasCollector* extras) const override { |
| 1304 |
char buf[96]; |
| 1305 |
SprintfLiteral(buf, "(offs=%lld, isConst=%s)", |
| 1306 |
(long long int)instanceDataOffset_, |
| 1307 |
isConstant_ ? "true" : "false"); |
| 1308 |
extras->add(buf); |
| 1309 |
} |
| 1310 |
#endif |
| 1311 |
|
| 1312 |
ALLOW_CLONE(MWasmLoadInstanceDataField) |
| 1313 |
}; |
| 1314 |
|
| 1315 |
class MWasmLoadGlobalCell : public MUnaryInstruction, |
| 1316 |
public NoTypePolicy::Data { |
| 1317 |
MWasmLoadGlobalCell(MIRType type, MDefinition* cellPtr, |
| 1318 |
wasm::ValType globalType) |
| 1319 |
: MUnaryInstruction(classOpcode, cellPtr) { |
| 1320 |
setResultType(type); |
| 1321 |
setMovable(); |
| 1322 |
initWasmRefType(globalType.toMaybeRefType()); |
| 1323 |
} |
| 1324 |
|
| 1325 |
public: |
| 1326 |
INSTRUCTION_HEADER(WasmLoadGlobalCell) |
| 1327 |
TRIVIAL_NEW_WRAPPERS |
| 1328 |
NAMED_OPERANDS((0, cellPtr)) |
| 1329 |
|
| 1330 |
// The default valueHash is good enough, because there are no non-operand |
| 1331 |
// fields. |
| 1332 |
bool congruentTo(const MDefinition* ins) const override; |
| 1333 |
|
| 1334 |
AliasSet getAliasSet() const override { |
| 1335 |
return AliasSet::Load(AliasSet::WasmGlobalCell); |
| 1336 |
} |
| 1337 |
|
| 1338 |
AliasType mightAlias(const MDefinition* def) const override; |
| 1339 |
|
| 1340 |
ALLOW_CLONE(MWasmLoadGlobalCell) |
| 1341 |
}; |
| 1342 |
|
| 1343 |
class MWasmLoadTableElement : public MBinaryInstruction, |
| 1344 |
public NoTypePolicy::Data { |
| 1345 |
MWasmLoadTableElement(MDefinition* elements, MDefinition* index, |
| 1346 |
wasm::RefType refType) |
| 1347 |
: MBinaryInstruction(classOpcode, elements, index) { |
| 1348 |
setResultType(MIRType::WasmAnyRef); |
| 1349 |
initWasmRefType(wasm::MaybeRefType(refType)); |
| 1350 |
} |
| 1351 |
|
| 1352 |
public: |
| 1353 |
INSTRUCTION_HEADER(WasmLoadTableElement) |
| 1354 |
TRIVIAL_NEW_WRAPPERS |
| 1355 |
NAMED_OPERANDS((0, elements)) |
| 1356 |
NAMED_OPERANDS((1, index)) |
| 1357 |
|
| 1358 |
AliasSet getAliasSet() const override { |
| 1359 |
return AliasSet::Load(AliasSet::WasmTableElement); |
| 1360 |
} |
| 1361 |
}; |
| 1362 |
|
| 1363 |
class MWasmStoreInstanceDataField : public MBinaryInstruction, |
| 1364 |
public NoTypePolicy::Data { |
| 1365 |
MWasmStoreInstanceDataField(unsigned instanceDataOffset, MDefinition* value, |
| 1366 |
MDefinition* instance) |
| 1367 |
: MBinaryInstruction(classOpcode, value, instance), |
| 1368 |
instanceDataOffset_(instanceDataOffset) {} |
| 1369 |
|
| 1370 |
unsigned instanceDataOffset_; |
| 1371 |
|
| 1372 |
public: |
| 1373 |
INSTRUCTION_HEADER(WasmStoreInstanceDataField) |
| 1374 |
TRIVIAL_NEW_WRAPPERS |
| 1375 |
NAMED_OPERANDS((0, value), (1, instance)) |
| 1376 |
|
| 1377 |
unsigned instanceDataOffset() const { return instanceDataOffset_; } |
| 1378 |
|
| 1379 |
AliasSet getAliasSet() const override { |
| 1380 |
return AliasSet::Store(AliasSet::WasmInstanceData); |
| 1381 |
} |
| 1382 |
}; |
| 1383 |
|
| 1384 |
class MWasmStoreGlobalCell : public MBinaryInstruction, |
| 1385 |
public NoTypePolicy::Data { |
| 1386 |
MWasmStoreGlobalCell(MDefinition* value, MDefinition* cellPtr) |
| 1387 |
: MBinaryInstruction(classOpcode, value, cellPtr) {} |
| 1388 |
|
| 1389 |
public: |
| 1390 |
INSTRUCTION_HEADER(WasmStoreGlobalCell) |
| 1391 |
TRIVIAL_NEW_WRAPPERS |
| 1392 |
NAMED_OPERANDS((0, value), (1, cellPtr)) |
| 1393 |
|
| 1394 |
AliasSet getAliasSet() const override { |
| 1395 |
return AliasSet::Store(AliasSet::WasmGlobalCell); |
| 1396 |
} |
| 1397 |
|
| 1398 |
ALLOW_CLONE(MWasmStoreGlobalCell) |
| 1399 |
}; |
| 1400 |
|
| 1401 |
class MWasmStoreStackResult : public MBinaryInstruction, |
| 1402 |
public NoTypePolicy::Data { |
| 1403 |
MWasmStoreStackResult(MDefinition* stackResultArea, uint32_t offset, |
| 1404 |
MDefinition* value) |
| 1405 |
: MBinaryInstruction(classOpcode, stackResultArea, value), |
| 1406 |
offset_(offset) {} |
| 1407 |
|
| 1408 |
uint32_t offset_; |
| 1409 |
|
| 1410 |
public: |
| 1411 |
INSTRUCTION_HEADER(WasmStoreStackResult) |
| 1412 |
TRIVIAL_NEW_WRAPPERS |
| 1413 |
NAMED_OPERANDS((0, stackResultArea), (1, value)) |
| 1414 |
|
| 1415 |
uint32_t offset() const { return offset_; } |
| 1416 |
|
| 1417 |
AliasSet getAliasSet() const override { |
| 1418 |
return AliasSet::Store(AliasSet::WasmStackResult); |
| 1419 |
} |
| 1420 |
}; |
| 1421 |
|
| 1422 |
// Represents a known-good derived pointer into an object or memory region (in |
| 1423 |
// the most general sense) that will not move while the derived pointer is live. |
| 1424 |
// The `offset` *must* be a valid offset into the object represented by `base`; |
| 1425 |
// hence overflow in the address calculation will never be an issue. `offset` |
| 1426 |
// must be representable as a 31-bit unsigned integer. |
| 1427 |
// |
| 1428 |
// DO NOT use this with a base value of any JS-heap-resident object type. |
| 1429 |
// Such a value would need to be adjusted during GC, yet we have no mechanism |
| 1430 |
// to do that. See bug 1810090. |
| 1431 |
|
| 1432 |
class MWasmDerivedPointer : public MUnaryInstruction, |
| 1433 |
public NoTypePolicy::Data { |
| 1434 |
MWasmDerivedPointer(MDefinition* base, size_t offset) |
| 1435 |
: MUnaryInstruction(classOpcode, base), offset_(uint32_t(offset)) { |
| 1436 |
MOZ_ASSERT(offset <= INT32_MAX); |
| 1437 |
// Do not change this to allow `base` to be a GC-heap allocated type. |
| 1438 |
MOZ_ASSERT(base->type() == MIRType::Pointer || |
| 1439 |
base->type() == TargetWordMIRType()); |
| 1440 |
setResultType(MIRType::Pointer); |
| 1441 |
setMovable(); |
| 1442 |
} |
| 1443 |
|
| 1444 |
uint32_t offset_; |
| 1445 |
|
| 1446 |
public: |
| 1447 |
INSTRUCTION_HEADER(WasmDerivedPointer) |
| 1448 |
TRIVIAL_NEW_WRAPPERS |
| 1449 |
NAMED_OPERANDS((0, base)) |
| 1450 |
|
| 1451 |
uint32_t offset() const { return offset_; } |
| 1452 |
|
| 1453 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1454 |
|
| 1455 |
bool congruentTo(const MDefinition* ins) const override { |
| 1456 |
return congruentIfOperandsEqual(ins) && |
| 1457 |
ins->toWasmDerivedPointer()->offset() == offset(); |
| 1458 |
} |
| 1459 |
|
| 1460 |
#ifdef JS_JITSPEW |
| 1461 |
void getExtras(ExtrasCollector* extras) const override { |
| 1462 |
char buf[64]; |
| 1463 |
SprintfLiteral(buf, "(offs=%lld)", (long long int)offset_); |
| 1464 |
extras->add(buf); |
| 1465 |
} |
| 1466 |
#endif |
| 1467 |
|
| 1468 |
ALLOW_CLONE(MWasmDerivedPointer) |
| 1469 |
}; |
| 1470 |
|
| 1471 |
// As with MWasmDerivedPointer, DO NOT use this with a base value of any |
| 1472 |
// JS-heap-resident object type. |
| 1473 |
class MWasmDerivedIndexPointer : public MBinaryInstruction, |
| 1474 |
public NoTypePolicy::Data { |
| 1475 |
MWasmDerivedIndexPointer(MDefinition* base, MDefinition* index, Scale scale) |
| 1476 |
: MBinaryInstruction(classOpcode, base, index), scale_(scale) { |
| 1477 |
// Do not change this to allow `base` to be a GC-heap allocated type. |
| 1478 |
MOZ_ASSERT(base->type() == MIRType::Pointer); |
| 1479 |
setResultType(MIRType::Pointer); |
| 1480 |
setMovable(); |
| 1481 |
} |
| 1482 |
|
| 1483 |
Scale scale_; |
| 1484 |
|
| 1485 |
public: |
| 1486 |
INSTRUCTION_HEADER(WasmDerivedIndexPointer) |
| 1487 |
TRIVIAL_NEW_WRAPPERS |
| 1488 |
NAMED_OPERANDS((0, base)) |
| 1489 |
NAMED_OPERANDS((1, index)) |
| 1490 |
|
| 1491 |
Scale scale() const { return scale_; } |
| 1492 |
|
| 1493 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1494 |
|
| 1495 |
bool congruentTo(const MDefinition* ins) const override { |
| 1496 |
return congruentIfOperandsEqual(ins) && |
| 1497 |
ins->toWasmDerivedIndexPointer()->scale() == scale(); |
| 1498 |
} |
| 1499 |
|
| 1500 |
ALLOW_CLONE(MWasmDerivedIndexPointer) |
| 1501 |
}; |
| 1502 |
|
| 1503 |
// Whether to perform a pre-write barrier for a wasm store reference. |
| 1504 |
enum class WasmPreBarrierKind : uint8_t { None, Normal }; |
| 1505 |
|
| 1506 |
// Stores a reference to an address. This performs a pre-barrier on the address, |
| 1507 |
// but not a post-barrier. A post-barrier must be performed separately, if it's |
| 1508 |
// required. The accessed location is `valueBase + valueOffset`. The latter |
| 1509 |
// must be be representable as a 31-bit unsigned integer. |
| 1510 |
|
| 1511 |
class MWasmStoreRef : public MAryInstruction<3>, public NoTypePolicy::Data { |
| 1512 |
uint32_t offset_; |
| 1513 |
AliasSet::Flag aliasSet_; |
| 1514 |
WasmPreBarrierKind preBarrierKind_; |
| 1515 |
|
| 1516 |
MWasmStoreRef(MDefinition* instance, MDefinition* valueBase, |
| 1517 |
size_t valueOffset, MDefinition* value, AliasSet::Flag aliasSet, |
| 1518 |
WasmPreBarrierKind preBarrierKind) |
| 1519 |
: MAryInstruction<3>(classOpcode), |
| 1520 |
offset_(uint32_t(valueOffset)), |
| 1521 |
aliasSet_(aliasSet), |
| 1522 |
preBarrierKind_(preBarrierKind) { |
| 1523 |
MOZ_ASSERT(valueOffset <= INT32_MAX); |
| 1524 |
MOZ_ASSERT(valueBase->type() == MIRType::Pointer || |
| 1525 |
valueBase->type() == MIRType::StackResults); |
| 1526 |
MOZ_ASSERT(value->type() == MIRType::WasmAnyRef); |
| 1527 |
initOperand(0, instance); |
| 1528 |
initOperand(1, valueBase); |
| 1529 |
initOperand(2, value); |
| 1530 |
} |
| 1531 |
|
| 1532 |
public: |
| 1533 |
INSTRUCTION_HEADER(WasmStoreRef) |
| 1534 |
TRIVIAL_NEW_WRAPPERS |
| 1535 |
NAMED_OPERANDS((0, instance), (1, valueBase), (2, value)) |
| 1536 |
|
| 1537 |
uint32_t offset() const { return offset_; } |
| 1538 |
AliasSet getAliasSet() const override { return AliasSet::Store(aliasSet_); } |
| 1539 |
WasmPreBarrierKind preBarrierKind() const { return preBarrierKind_; } |
| 1540 |
|
| 1541 |
#ifdef JS_JITSPEW |
| 1542 |
void getExtras(ExtrasCollector* extras) const override { |
| 1543 |
char buf[64]; |
| 1544 |
SprintfLiteral(buf, "(offs=%lld)", (long long int)offset_); |
| 1545 |
extras->add(buf); |
| 1546 |
} |
| 1547 |
#endif |
| 1548 |
}; |
| 1549 |
|
| 1550 |
// Given a value being written to another object, update the generational store |
| 1551 |
// buffer if the value is in the nursery and object is in the tenured heap. |
| 1552 |
class MWasmPostWriteBarrierWholeCell : public MTernaryInstruction, |
| 1553 |
public NoTypePolicy::Data { |
| 1554 |
MWasmPostWriteBarrierWholeCell(MDefinition* instance, MDefinition* object, |
| 1555 |
MDefinition* value) |
| 1556 |
: MTernaryInstruction(classOpcode, instance, object, value) { |
| 1557 |
setGuard(); |
| 1558 |
} |
| 1559 |
|
| 1560 |
public: |
| 1561 |
INSTRUCTION_HEADER(WasmPostWriteBarrierWholeCell) |
| 1562 |
TRIVIAL_NEW_WRAPPERS |
| 1563 |
NAMED_OPERANDS((0, instance), (1, object), (2, value)) |
| 1564 |
|
| 1565 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1566 |
|
| 1567 |
ALLOW_CLONE(MWasmPostWriteBarrierWholeCell) |
| 1568 |
}; |
| 1569 |
|
| 1570 |
// Given a value being written to another object, update the generational store |
| 1571 |
// buffer if the value is in the nursery and object is in the tenured heap. |
| 1572 |
class MWasmPostWriteBarrierEdgeAtIndex : public MAryInstruction<5>, |
| 1573 |
public NoTypePolicy::Data { |
| 1574 |
uint32_t elemSize_; |
| 1575 |
|
| 1576 |
MWasmPostWriteBarrierEdgeAtIndex(MDefinition* instance, MDefinition* object, |
| 1577 |
MDefinition* valueBase, MDefinition* index, |
| 1578 |
uint32_t scale, MDefinition* value) |
| 1579 |
: MAryInstruction<5>(classOpcode), elemSize_(scale) { |
| 1580 |
initOperand(0, instance); |
| 1581 |
initOperand(1, object); |
| 1582 |
initOperand(2, valueBase); |
| 1583 |
initOperand(3, index); |
| 1584 |
initOperand(4, value); |
| 1585 |
setGuard(); |
| 1586 |
} |
| 1587 |
|
| 1588 |
public: |
| 1589 |
INSTRUCTION_HEADER(WasmPostWriteBarrierEdgeAtIndex) |
| 1590 |
TRIVIAL_NEW_WRAPPERS |
| 1591 |
NAMED_OPERANDS((0, instance), (1, object), (2, valueBase), (3, index), |
| 1592 |
(4, value)) |
| 1593 |
|
| 1594 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1595 |
uint32_t elemSize() const { return elemSize_; } |
| 1596 |
|
| 1597 |
ALLOW_CLONE(MWasmPostWriteBarrierEdgeAtIndex) |
| 1598 |
}; |
| 1599 |
|
| 1600 |
class MWasmParameter : public MNullaryInstruction { |
| 1601 |
ABIArg abi_; |
| 1602 |
|
| 1603 |
MWasmParameter(ABIArg abi, MIRType mirType, |
| 1604 |
wasm::MaybeRefType refType = wasm::MaybeRefType()) |
| 1605 |
: MNullaryInstruction(classOpcode), abi_(abi) { |
| 1606 |
setResultType(mirType); |
| 1607 |
initWasmRefType(refType); |
| 1608 |
} |
| 1609 |
|
| 1610 |
public: |
| 1611 |
INSTRUCTION_HEADER(WasmParameter) |
| 1612 |
TRIVIAL_NEW_WRAPPERS |
| 1613 |
|
| 1614 |
ABIArg abi() const { return abi_; } |
| 1615 |
}; |
| 1616 |
|
| 1617 |
class MWasmReturn : public MAryControlInstruction<2, 0>, |
| 1618 |
public NoTypePolicy::Data { |
| 1619 |
MWasmReturn(MDefinition* ins, MDefinition* instance) |
| 1620 |
: MAryControlInstruction(classOpcode) { |
| 1621 |
initOperand(0, ins); |
| 1622 |
initOperand(1, instance); |
| 1623 |
} |
| 1624 |
|
| 1625 |
public: |
| 1626 |
INSTRUCTION_HEADER(WasmReturn) |
| 1627 |
TRIVIAL_NEW_WRAPPERS |
| 1628 |
|
| 1629 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1630 |
}; |
| 1631 |
|
| 1632 |
class MWasmReturnVoid : public MAryControlInstruction<1, 0>, |
| 1633 |
public NoTypePolicy::Data { |
| 1634 |
explicit MWasmReturnVoid(MDefinition* instance) |
| 1635 |
: MAryControlInstruction(classOpcode) { |
| 1636 |
initOperand(0, instance); |
| 1637 |
} |
| 1638 |
|
| 1639 |
public: |
| 1640 |
INSTRUCTION_HEADER(WasmReturnVoid) |
| 1641 |
TRIVIAL_NEW_WRAPPERS |
| 1642 |
|
| 1643 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1644 |
}; |
| 1645 |
|
| 1646 |
class MWasmStackArg : public MUnaryInstruction, public NoTypePolicy::Data { |
| 1647 |
MWasmStackArg(uint32_t spOffset, MDefinition* ins) |
| 1648 |
: MUnaryInstruction(classOpcode, ins), spOffset_(spOffset) {} |
| 1649 |
|
| 1650 |
uint32_t spOffset_; |
| 1651 |
|
| 1652 |
public: |
| 1653 |
INSTRUCTION_HEADER(WasmStackArg) |
| 1654 |
TRIVIAL_NEW_WRAPPERS |
| 1655 |
NAMED_OPERANDS((0, arg)) |
| 1656 |
|
| 1657 |
uint32_t spOffset() const { return spOffset_; } |
| 1658 |
void incrementOffset(uint32_t inc) { spOffset_ += inc; } |
| 1659 |
|
| 1660 |
ALLOW_CLONE(MWasmStackArg) |
| 1661 |
}; |
| 1662 |
|
| 1663 |
template <typename Location> |
| 1664 |
class MWasmResultBase : public MNullaryInstruction { |
| 1665 |
Location loc_; |
| 1666 |
|
| 1667 |
protected: |
| 1668 |
MWasmResultBase(Opcode op, MIRType type, Location loc) |
| 1669 |
: MNullaryInstruction(op), loc_(loc) { |
| 1670 |
setResultType(type); |
| 1671 |
setCallResultCapture(); |
| 1672 |
} |
| 1673 |
|
| 1674 |
public: |
| 1675 |
Location loc() { return loc_; } |
| 1676 |
}; |
| 1677 |
|
| 1678 |
class MWasmRegisterResult : public MWasmResultBase<Register> { |
| 1679 |
MWasmRegisterResult(MIRType type, Register reg, |
| 1680 |
wasm::MaybeRefType maybeRefType = wasm::MaybeRefType()) |
| 1681 |
: MWasmResultBase(classOpcode, type, reg) { |
| 1682 |
initWasmRefType(maybeRefType); |
| 1683 |
} |
| 1684 |
|
| 1685 |
public: |
| 1686 |
INSTRUCTION_HEADER(WasmRegisterResult) |
| 1687 |
TRIVIAL_NEW_WRAPPERS |
| 1688 |
}; |
| 1689 |
|
| 1690 |
class MWasmFloatRegisterResult : public MWasmResultBase<FloatRegister> { |
| 1691 |
MWasmFloatRegisterResult(MIRType type, FloatRegister reg) |
| 1692 |
: MWasmResultBase(classOpcode, type, reg) {} |
| 1693 |
|
| 1694 |
public: |
| 1695 |
INSTRUCTION_HEADER(WasmFloatRegisterResult) |
| 1696 |
TRIVIAL_NEW_WRAPPERS |
| 1697 |
}; |
| 1698 |
|
| 1699 |
class MWasmRegister64Result : public MWasmResultBase<Register64> { |
| 1700 |
explicit MWasmRegister64Result(Register64 reg) |
| 1701 |
: MWasmResultBase(classOpcode, MIRType::Int64, reg) {} |
| 1702 |
|
| 1703 |
public: |
| 1704 |
INSTRUCTION_HEADER(WasmRegister64Result) |
| 1705 |
TRIVIAL_NEW_WRAPPERS |
| 1706 |
}; |
| 1707 |
|
| 1708 |
class MWasmStackResultArea : public MNullaryInstruction { |
| 1709 |
public: |
| 1710 |
class StackResult { |
| 1711 |
// Offset in bytes from lowest address of stack result area. |
| 1712 |
uint32_t offset_; |
| 1713 |
MIRType type_; |
| 1714 |
|
| 1715 |
public: |
| 1716 |
StackResult() : type_(MIRType::Undefined) {} |
| 1717 |
StackResult(uint32_t offset, MIRType type) : offset_(offset), type_(type) {} |
| 1718 |
|
| 1719 |
bool initialized() const { return type_ != MIRType::Undefined; } |
| 1720 |
uint32_t offset() const { |
| 1721 |
MOZ_ASSERT(initialized()); |
| 1722 |
return offset_; |
| 1723 |
} |
| 1724 |
MIRType type() const { |
| 1725 |
MOZ_ASSERT(initialized()); |
| 1726 |
return type_; |
| 1727 |
} |
| 1728 |
uint32_t endOffset() const { |
| 1729 |
return offset() + wasm::MIRTypeToABIResultSize(type()); |
| 1730 |
} |
| 1731 |
}; |
| 1732 |
|
| 1733 |
private: |
| 1734 |
FixedList<StackResult> results_; |
| 1735 |
uint32_t base_; |
| 1736 |
|
| 1737 |
explicit MWasmStackResultArea() |
| 1738 |
: MNullaryInstruction(classOpcode), base_(UINT32_MAX) { |
| 1739 |
setResultType(MIRType::StackResults); |
| 1740 |
} |
| 1741 |
|
| 1742 |
void assertInitialized() const { |
| 1743 |
MOZ_ASSERT(results_.length() != 0); |
| 1744 |
#ifdef DEBUG |
| 1745 |
for (size_t i = 0; i < results_.length(); i++) { |
| 1746 |
MOZ_ASSERT(results_[i].initialized()); |
| 1747 |
} |
| 1748 |
#endif |
| 1749 |
} |
| 1750 |
|
| 1751 |
bool baseInitialized() const { return base_ != UINT32_MAX; } |
| 1752 |
|
| 1753 |
public: |
| 1754 |
INSTRUCTION_HEADER(WasmStackResultArea) |
| 1755 |
TRIVIAL_NEW_WRAPPERS |
| 1756 |
|
| 1757 |
[[nodiscard]] bool init(TempAllocator& alloc, size_t stackResultCount) { |
| 1758 |
MOZ_ASSERT(results_.length() == 0); |
| 1759 |
MOZ_ASSERT(stackResultCount > 0); |
| 1760 |
if (!results_.init(alloc, stackResultCount)) { |
| 1761 |
return false; |
| 1762 |
} |
| 1763 |
for (size_t n = 0; n < stackResultCount; n++) { |
| 1764 |
results_[n] = StackResult(); |
| 1765 |
} |
| 1766 |
return true; |
| 1767 |
} |
| 1768 |
|
| 1769 |
size_t resultCount() const { return results_.length(); } |
| 1770 |
const StackResult& result(size_t n) const { |
| 1771 |
MOZ_ASSERT(results_[n].initialized()); |
| 1772 |
return results_[n]; |
| 1773 |
} |
| 1774 |
void initResult(size_t n, const StackResult& loc) { |
| 1775 |
MOZ_ASSERT(!results_[n].initialized()); |
| 1776 |
MOZ_ASSERT((n == 0) == (loc.offset() == 0)); |
| 1777 |
MOZ_ASSERT_IF(n > 0, loc.offset() >= result(n - 1).endOffset()); |
| 1778 |
results_[n] = loc; |
| 1779 |
} |
| 1780 |
|
| 1781 |
uint32_t byteSize() const { |
| 1782 |
assertInitialized(); |
| 1783 |
return result(resultCount() - 1).endOffset(); |
| 1784 |
} |
| 1785 |
|
| 1786 |
// Stack index indicating base of stack area. |
| 1787 |
uint32_t base() const { |
| 1788 |
MOZ_ASSERT(baseInitialized()); |
| 1789 |
return base_; |
| 1790 |
} |
| 1791 |
void setBase(uint32_t base) { |
| 1792 |
MOZ_ASSERT(!baseInitialized()); |
| 1793 |
base_ = base; |
| 1794 |
MOZ_ASSERT(baseInitialized()); |
| 1795 |
} |
| 1796 |
}; |
| 1797 |
|
| 1798 |
class MWasmStackResult : public MUnaryInstruction, public NoTypePolicy::Data { |
| 1799 |
uint32_t resultIdx_; |
| 1800 |
|
| 1801 |
MWasmStackResult(MWasmStackResultArea* resultArea, size_t idx) |
| 1802 |
: MUnaryInstruction(classOpcode, resultArea), resultIdx_(idx) { |
| 1803 |
setResultType(result().type()); |
| 1804 |
setCallResultCapture(); |
| 1805 |
} |
| 1806 |
|
| 1807 |
public: |
| 1808 |
INSTRUCTION_HEADER(WasmStackResult) |
| 1809 |
TRIVIAL_NEW_WRAPPERS |
| 1810 |
NAMED_OPERANDS((0, resultArea)) |
| 1811 |
|
| 1812 |
const MWasmStackResultArea::StackResult& result() const { |
| 1813 |
return resultArea()->toWasmStackResultArea()->result(resultIdx_); |
| 1814 |
} |
| 1815 |
}; |
| 1816 |
|
| 1817 |
// Mixin class for wasm calls that may or may not be catchable. |
| 1818 |
class MWasmCallBase { |
| 1819 |
public: |
| 1820 |
struct Arg { |
| 1821 |
AnyRegister reg; |
| 1822 |
MDefinition* def; |
| 1823 |
Arg(AnyRegister reg, MDefinition* def) : reg(reg), def(def) {} |
| 1824 |
}; |
| 1825 |
using Args = Vector<Arg, 8, SystemAllocPolicy>; |
| 1826 |
|
| 1827 |
protected: |
| 1828 |
wasm::CallSiteDesc desc_; |
| 1829 |
wasm::CalleeDesc callee_; |
| 1830 |
wasm::FailureMode builtinMethodFailureMode_; |
| 1831 |
FixedList<AnyRegister> argRegs_; |
| 1832 |
uint32_t stackArgAreaSizeUnaligned_; |
| 1833 |
ABIArg instanceArg_; |
| 1834 |
bool inTry_; |
| 1835 |
size_t tryNoteIndex_; |
| 1836 |
|
| 1837 |
MWasmCallBase(const wasm::CallSiteDesc& desc, const wasm::CalleeDesc& callee, |
| 1838 |
uint32_t stackArgAreaSizeUnaligned, bool inTry, |
| 1839 |
size_t tryNoteIndex) |
| 1840 |
: desc_(desc), |
| 1841 |
callee_(callee), |
| 1842 |
builtinMethodFailureMode_(wasm::FailureMode::Infallible), |
| 1843 |
stackArgAreaSizeUnaligned_(stackArgAreaSizeUnaligned), |
| 1844 |
inTry_(inTry), |
| 1845 |
tryNoteIndex_(tryNoteIndex) {} |
| 1846 |
|
| 1847 |
template <class MVariadicT> |
| 1848 |
[[nodiscard]] bool initWithArgs(TempAllocator& alloc, MVariadicT* ins, |
| 1849 |
const Args& args, |
| 1850 |
MDefinition* tableAddressOrRef) { |
| 1851 |
if (!argRegs_.init(alloc, args.length())) { |
| 1852 |
return false; |
| 1853 |
} |
| 1854 |
for (size_t i = 0; i < argRegs_.length(); i++) { |
| 1855 |
argRegs_[i] = args[i].reg; |
| 1856 |
} |
| 1857 |
|
| 1858 |
if (!ins->init(alloc, argRegs_.length() + (tableAddressOrRef ? 1 : 0))) { |
| 1859 |
return false; |
| 1860 |
} |
| 1861 |
// FixedList doesn't initialize its elements, so do an unchecked init. |
| 1862 |
for (size_t i = 0; i < argRegs_.length(); i++) { |
| 1863 |
ins->initOperand(i, args[i].def); |
| 1864 |
} |
| 1865 |
if (tableAddressOrRef) { |
| 1866 |
ins->initOperand(argRegs_.length(), tableAddressOrRef); |
| 1867 |
} |
| 1868 |
return true; |
| 1869 |
} |
| 1870 |
|
| 1871 |
public: |
| 1872 |
static bool IsWasmCall(MDefinition* def) { |
| 1873 |
return def->isWasmCallCatchable() || def->isWasmCallUncatchable() || |
| 1874 |
def->isWasmReturnCall(); |
| 1875 |
} |
| 1876 |
|
| 1877 |
size_t numArgs() const { return argRegs_.length(); } |
| 1878 |
AnyRegister registerForArg(size_t index) const { |
| 1879 |
MOZ_ASSERT(index < numArgs()); |
| 1880 |
return argRegs_[index]; |
| 1881 |
} |
| 1882 |
const wasm::CallSiteDesc& desc() const { return desc_; } |
| 1883 |
const wasm::CalleeDesc& callee() const { return callee_; } |
| 1884 |
wasm::FailureMode builtinMethodFailureMode() const { |
| 1885 |
MOZ_ASSERT(callee_.which() == wasm::CalleeDesc::BuiltinInstanceMethod); |
| 1886 |
return builtinMethodFailureMode_; |
| 1887 |
} |
| 1888 |
uint32_t stackArgAreaSizeUnaligned() const { |
| 1889 |
return stackArgAreaSizeUnaligned_; |
| 1890 |
} |
| 1891 |
|
| 1892 |
const ABIArg& instanceArg() const { return instanceArg_; } |
| 1893 |
|
| 1894 |
bool inTry() const { return inTry_; } |
| 1895 |
size_t tryNoteIndex() const { return tryNoteIndex_; } |
| 1896 |
|
| 1897 |
static AliasSet wasmCallAliasSet() { |
| 1898 |
// This is ok because: |
| 1899 |
// - numElements is immutable |
| 1900 |
// - the GC will rewrite any array data pointers on move |
| 1901 |
AliasSet exclude = AliasSet(AliasSet::WasmArrayNumElements) | |
| 1902 |
AliasSet(AliasSet::WasmArrayDataPointer); |
| 1903 |
return AliasSet::Store(AliasSet::Any) & ~exclude; |
| 1904 |
} |
| 1905 |
}; |
| 1906 |
|
| 1907 |
// A wasm call that is catchable. This instruction is a control instruction, |
| 1908 |
// and terminates the block it is on. A normal return will proceed in a the |
| 1909 |
// fallthrough block. An exceptional return will unwind into the landing pad |
| 1910 |
// block for this call. The landing pad block must begin with an |
| 1911 |
// MWasmCallLandingPrePad. |
| 1912 |
class MWasmCallCatchable final : public MVariadicControlInstruction<2>, |
| 1913 |
public MWasmCallBase, |
| 1914 |
public NoTypePolicy::Data { |
| 1915 |
MWasmCallCatchable(const wasm::CallSiteDesc& desc, |
| 1916 |
const wasm::CalleeDesc& callee, |
| 1917 |
uint32_t stackArgAreaSizeUnaligned, size_t tryNoteIndex) |
| 1918 |
: MVariadicControlInstruction(classOpcode), |
| 1919 |
MWasmCallBase(desc, callee, stackArgAreaSizeUnaligned, true, |
| 1920 |
tryNoteIndex) {} |
| 1921 |
|
| 1922 |
public: |
| 1923 |
INSTRUCTION_HEADER(WasmCallCatchable) |
| 1924 |
|
| 1925 |
static MWasmCallCatchable* New( |
| 1926 |
TempAllocator& alloc, const wasm::CallSiteDesc& desc, |
| 1927 |
const wasm::CalleeDesc& callee, const Args& args, |
| 1928 |
uint32_t stackArgAreaSizeUnaligned, uint32_t tryNoteIndex, |
| 1929 |
MBasicBlock* fallthroughBlock, MBasicBlock* prePadBlock, |
| 1930 |
MDefinition* tableAddressOrRef = nullptr); |
| 1931 |
|
| 1932 |
static MWasmCallCatchable* NewBuiltinInstanceMethodCall( |
| 1933 |
TempAllocator& alloc, const wasm::CallSiteDesc& desc, |
| 1934 |
const wasm::SymbolicAddress builtin, wasm::FailureMode failureMode, |
| 1935 |
const ABIArg& instanceArg, const Args& args, |
| 1936 |
uint32_t stackArgAreaSizeUnaligned, uint32_t tryNoteIndex, |
| 1937 |
MBasicBlock* fallthroughBlock, MBasicBlock* prePadBlock); |
| 1938 |
|
| 1939 |
bool possiblyCalls() const override { return true; } |
| 1940 |
AliasSet getAliasSet() const override { return wasmCallAliasSet(); } |
| 1941 |
|
| 1942 |
static const size_t FallthroughBranchIndex = 0; |
| 1943 |
static const size_t PrePadBranchIndex = 1; |
| 1944 |
}; |
| 1945 |
|
| 1946 |
// A wasm call that is not catchable. This instruction is not a control |
| 1947 |
// instruction, and therefore is not a block terminator. |
| 1948 |
class MWasmCallUncatchable final : public MVariadicInstruction, |
| 1949 |
public MWasmCallBase, |
| 1950 |
public NoTypePolicy::Data { |
| 1951 |
MWasmCallUncatchable(const wasm::CallSiteDesc& desc, |
| 1952 |
const wasm::CalleeDesc& callee, |
| 1953 |
uint32_t stackArgAreaSizeUnaligned) |
| 1954 |
: MVariadicInstruction(classOpcode), |
| 1955 |
MWasmCallBase(desc, callee, stackArgAreaSizeUnaligned, false, 0) {} |
| 1956 |
|
| 1957 |
public: |
| 1958 |
INSTRUCTION_HEADER(WasmCallUncatchable) |
| 1959 |
|
| 1960 |
static MWasmCallUncatchable* New(TempAllocator& alloc, |
| 1961 |
const wasm::CallSiteDesc& desc, |
| 1962 |
const wasm::CalleeDesc& callee, |
| 1963 |
const Args& args, |
| 1964 |
uint32_t stackArgAreaSizeUnaligned, |
| 1965 |
MDefinition* tableAddressOrRef = nullptr); |
| 1966 |
|
| 1967 |
static MWasmCallUncatchable* NewBuiltinInstanceMethodCall( |
| 1968 |
TempAllocator& alloc, const wasm::CallSiteDesc& desc, |
| 1969 |
const wasm::SymbolicAddress builtin, wasm::FailureMode failureMode, |
| 1970 |
const ABIArg& instanceArg, const Args& args, |
| 1971 |
uint32_t stackArgAreaSizeUnaligned); |
| 1972 |
|
| 1973 |
bool possiblyCalls() const override { return true; } |
| 1974 |
AliasSet getAliasSet() const override { return wasmCallAliasSet(); } |
| 1975 |
}; |
| 1976 |
|
| 1977 |
class MWasmReturnCall final : public MVariadicControlInstruction<0>, |
| 1978 |
public MWasmCallBase, |
| 1979 |
public NoTypePolicy::Data { |
| 1980 |
MWasmReturnCall(const wasm::CallSiteDesc& desc, |
| 1981 |
const wasm::CalleeDesc& callee, |
| 1982 |
uint32_t stackArgAreaSizeUnaligned) |
| 1983 |
: MVariadicControlInstruction(classOpcode), |
| 1984 |
MWasmCallBase(desc, callee, stackArgAreaSizeUnaligned, false, 0) {} |
| 1985 |
|
| 1986 |
public: |
| 1987 |
INSTRUCTION_HEADER(WasmReturnCall) |
| 1988 |
|
| 1989 |
static MWasmReturnCall* New(TempAllocator& alloc, |
| 1990 |
const wasm::CallSiteDesc& desc, |
| 1991 |
const wasm::CalleeDesc& callee, const Args& args, |
| 1992 |
uint32_t stackArgAreaSizeUnaligned, |
| 1993 |
MDefinition* tableAddressOrRef = nullptr); |
| 1994 |
|
| 1995 |
bool possiblyCalls() const override { return true; } |
| 1996 |
}; |
| 1997 |
|
| 1998 |
// A marker instruction for a block which is the landing pad for a catchable |
| 1999 |
// wasm call. This instruction does not emit any code, only filling in |
| 2000 |
// metadata. This instruction must be the first instruction added to the |
| 2001 |
// landing pad block. |
| 2002 |
class MWasmCallLandingPrePad : public MNullaryInstruction { |
| 2003 |
// The block of the call that may unwind to this landing pad. |
| 2004 |
MBasicBlock* callBlock_; |
| 2005 |
// The index of the try note to initialize a landing pad for. |
| 2006 |
size_t tryNoteIndex_; |
| 2007 |
|
| 2008 |
explicit MWasmCallLandingPrePad(MBasicBlock* callBlock, size_t tryNoteIndex) |
| 2009 |
: MNullaryInstruction(classOpcode), |
| 2010 |
callBlock_(callBlock), |
| 2011 |
tryNoteIndex_(tryNoteIndex) { |
| 2012 |
setGuard(); |
| 2013 |
} |
| 2014 |
|
| 2015 |
public: |
| 2016 |
INSTRUCTION_HEADER(WasmCallLandingPrePad) |
| 2017 |
TRIVIAL_NEW_WRAPPERS |
| 2018 |
|
| 2019 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2020 |
|
| 2021 |
size_t tryNoteIndex() { return tryNoteIndex_; } |
| 2022 |
MBasicBlock* callBlock() { return callBlock_; } |
| 2023 |
}; |
| 2024 |
|
| 2025 |
class MWasmSelect : public MTernaryInstruction, public NoTypePolicy::Data { |
| 2026 |
MWasmSelect(MDefinition* trueExpr, MDefinition* falseExpr, |
| 2027 |
MDefinition* condExpr) |
| 2028 |
: MTernaryInstruction(classOpcode, trueExpr, falseExpr, condExpr) { |
| 2029 |
MOZ_ASSERT(condExpr->type() == MIRType::Int32); |
| 2030 |
MOZ_ASSERT(trueExpr->type() == falseExpr->type()); |
| 2031 |
setResultType(trueExpr->type()); |
| 2032 |
setMovable(); |
| 2033 |
} |
| 2034 |
|
| 2035 |
public: |
| 2036 |
INSTRUCTION_HEADER(WasmSelect) |
| 2037 |
TRIVIAL_NEW_WRAPPERS |
| 2038 |
NAMED_OPERANDS((0, trueExpr), (1, falseExpr), (2, condExpr)) |
| 2039 |
|
| 2040 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2041 |
|
| 2042 |
bool congruentTo(const MDefinition* ins) const override { |
| 2043 |
return congruentIfOperandsEqual(ins); |
| 2044 |
} |
| 2045 |
|
| 2046 |
wasm::MaybeRefType computeWasmRefType() const override { |
| 2047 |
return wasm::MaybeRefType::leastUpperBound(trueExpr()->wasmRefType(), |
| 2048 |
falseExpr()->wasmRefType()); |
| 2049 |
} |
| 2050 |
|
| 2051 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2052 |
|
| 2053 |
ALLOW_CLONE(MWasmSelect) |
| 2054 |
}; |
| 2055 |
|
| 2056 |
// Wasm SIMD. |
| 2057 |
// |
| 2058 |
// See comment in WasmIonCompile.cpp for a justification for these nodes. |
| 2059 |
|
| 2060 |
// (v128, v128, v128) -> v128 effect-free operation. |
| 2061 |
class MWasmTernarySimd128 : public MTernaryInstruction, |
| 2062 |
public NoTypePolicy::Data { |
| 2063 |
wasm::SimdOp simdOp_; |
| 2064 |
|
| 2065 |
MWasmTernarySimd128(MDefinition* v0, MDefinition* v1, MDefinition* v2, |
| 2066 |
wasm::SimdOp simdOp) |
| 2067 |
: MTernaryInstruction(classOpcode, v0, v1, v2), simdOp_(simdOp) { |
| 2068 |
setMovable(); |
| 2069 |
setResultType(MIRType::Simd128); |
| 2070 |
} |
| 2071 |
|
| 2072 |
public: |
| 2073 |
INSTRUCTION_HEADER(WasmTernarySimd128) |
| 2074 |
TRIVIAL_NEW_WRAPPERS |
| 2075 |
NAMED_OPERANDS((0, v0), (1, v1), (2, v2)) |
| 2076 |
|
| 2077 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2078 |
bool congruentTo(const MDefinition* ins) const override { |
| 2079 |
return congruentIfOperandsEqual(ins) && |
| 2080 |
simdOp() == ins->toWasmTernarySimd128()->simdOp(); |
| 2081 |
} |
| 2082 |
#ifdef ENABLE_WASM_SIMD |
| 2083 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2084 |
|
| 2085 |
// If the control mask of a bitselect allows the operation to be specialized |
| 2086 |
// as a shuffle and it is profitable to specialize it on this platform, return |
| 2087 |
// true and the appropriate shuffle mask. |
| 2088 |
bool specializeBitselectConstantMaskAsShuffle(int8_t shuffle[16]); |
| 2089 |
// Checks if more relaxed version of lane select can be used. It returns true |
| 2090 |
// if a bit mask input expected to be all 0s or 1s for entire 8-bit lanes, |
| 2091 |
// false otherwise. |
| 2092 |
bool canRelaxBitselect(); |
| 2093 |
#endif |
| 2094 |
|
| 2095 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2096 |
|
| 2097 |
ALLOW_CLONE(MWasmTernarySimd128) |
| 2098 |
}; |
| 2099 |
|
| 2100 |
// (v128, v128) -> v128 effect-free operations. |
| 2101 |
class MWasmBinarySimd128 : public MBinaryInstruction, |
| 2102 |
public NoTypePolicy::Data { |
| 2103 |
wasm::SimdOp simdOp_; |
| 2104 |
|
| 2105 |
MWasmBinarySimd128(MDefinition* lhs, MDefinition* rhs, bool commutative, |
| 2106 |
wasm::SimdOp simdOp) |
| 2107 |
: MBinaryInstruction(classOpcode, lhs, rhs), simdOp_(simdOp) { |
| 2108 |
setMovable(); |
| 2109 |
setResultType(MIRType::Simd128); |
| 2110 |
if (commutative) { |
| 2111 |
setCommutative(); |
| 2112 |
} |
| 2113 |
} |
| 2114 |
|
| 2115 |
public: |
| 2116 |
INSTRUCTION_HEADER(WasmBinarySimd128) |
| 2117 |
TRIVIAL_NEW_WRAPPERS |
| 2118 |
|
| 2119 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2120 |
bool congruentTo(const MDefinition* ins) const override { |
| 2121 |
return congruentIfOperandsEqual(ins) && |
| 2122 |
ins->toWasmBinarySimd128()->simdOp() == simdOp_; |
| 2123 |
} |
| 2124 |
#ifdef ENABLE_WASM_SIMD |
| 2125 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2126 |
|
| 2127 |
// Checks if pmaddubsw operation is supported. |
| 2128 |
bool canPmaddubsw(); |
| 2129 |
#endif |
| 2130 |
|
| 2131 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2132 |
|
| 2133 |
// Platform-dependent specialization. |
| 2134 |
bool specializeForConstantRhs(); |
| 2135 |
|
| 2136 |
ALLOW_CLONE(MWasmBinarySimd128) |
| 2137 |
}; |
| 2138 |
|
| 2139 |
// (v128, const) -> v128 effect-free operations. |
| 2140 |
class MWasmBinarySimd128WithConstant : public MUnaryInstruction, |
| 2141 |
public NoTypePolicy::Data { |
| 2142 |
SimdConstant rhs_; |
| 2143 |
wasm::SimdOp simdOp_; |
| 2144 |
|
| 2145 |
MWasmBinarySimd128WithConstant(MDefinition* lhs, const SimdConstant& rhs, |
| 2146 |
wasm::SimdOp simdOp) |
| 2147 |
: MUnaryInstruction(classOpcode, lhs), rhs_(rhs), simdOp_(simdOp) { |
| 2148 |
setMovable(); |
| 2149 |
setResultType(MIRType::Simd128); |
| 2150 |
} |
| 2151 |
|
| 2152 |
public: |
| 2153 |
INSTRUCTION_HEADER(WasmBinarySimd128WithConstant) |
| 2154 |
TRIVIAL_NEW_WRAPPERS |
| 2155 |
|
| 2156 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2157 |
bool congruentTo(const MDefinition* ins) const override { |
| 2158 |
return congruentIfOperandsEqual(ins) && |
| 2159 |
ins->toWasmBinarySimd128WithConstant()->simdOp() == simdOp_ && |
| 2160 |
rhs_.bitwiseEqual(ins->toWasmBinarySimd128WithConstant()->rhs()); |
| 2161 |
} |
| 2162 |
|
| 2163 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2164 |
MDefinition* lhs() const { return input(); } |
| 2165 |
const SimdConstant& rhs() const { return rhs_; } |
| 2166 |
|
| 2167 |
ALLOW_CLONE(MWasmBinarySimd128WithConstant) |
| 2168 |
}; |
| 2169 |
|
| 2170 |
// (v128, scalar, imm) -> v128 effect-free operations. |
| 2171 |
class MWasmReplaceLaneSimd128 : public MBinaryInstruction, |
| 2172 |
public NoTypePolicy::Data { |
| 2173 |
uint32_t laneIndex_; |
| 2174 |
wasm::SimdOp simdOp_; |
| 2175 |
|
| 2176 |
MWasmReplaceLaneSimd128(MDefinition* lhs, MDefinition* rhs, |
| 2177 |
uint32_t laneIndex, wasm::SimdOp simdOp) |
| 2178 |
: MBinaryInstruction(classOpcode, lhs, rhs), |
| 2179 |
laneIndex_(laneIndex), |
| 2180 |
simdOp_(simdOp) { |
| 2181 |
setMovable(); |
| 2182 |
setResultType(MIRType::Simd128); |
| 2183 |
} |
| 2184 |
|
| 2185 |
public: |
| 2186 |
INSTRUCTION_HEADER(WasmReplaceLaneSimd128) |
| 2187 |
TRIVIAL_NEW_WRAPPERS |
| 2188 |
|
| 2189 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2190 |
bool congruentTo(const MDefinition* ins) const override { |
| 2191 |
return congruentIfOperandsEqual(ins) && |
| 2192 |
ins->toWasmReplaceLaneSimd128()->simdOp() == simdOp_ && |
| 2193 |
ins->toWasmReplaceLaneSimd128()->laneIndex() == laneIndex_; |
| 2194 |
} |
| 2195 |
|
| 2196 |
uint32_t laneIndex() const { return laneIndex_; } |
| 2197 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2198 |
|
| 2199 |
ALLOW_CLONE(MWasmReplaceLaneSimd128) |
| 2200 |
}; |
| 2201 |
|
| 2202 |
// (scalar) -> v128 effect-free operations. |
| 2203 |
class MWasmScalarToSimd128 : public MUnaryInstruction, |
| 2204 |
public NoTypePolicy::Data { |
| 2205 |
wasm::SimdOp simdOp_; |
| 2206 |
|
| 2207 |
MWasmScalarToSimd128(MDefinition* src, wasm::SimdOp simdOp) |
| 2208 |
: MUnaryInstruction(classOpcode, src), simdOp_(simdOp) { |
| 2209 |
setMovable(); |
| 2210 |
setResultType(MIRType::Simd128); |
| 2211 |
} |
| 2212 |
|
| 2213 |
public: |
| 2214 |
INSTRUCTION_HEADER(WasmScalarToSimd128) |
| 2215 |
TRIVIAL_NEW_WRAPPERS |
| 2216 |
|
| 2217 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2218 |
bool congruentTo(const MDefinition* ins) const override { |
| 2219 |
return congruentIfOperandsEqual(ins) && |
| 2220 |
ins->toWasmScalarToSimd128()->simdOp() == simdOp_; |
| 2221 |
} |
| 2222 |
#ifdef ENABLE_WASM_SIMD |
| 2223 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2224 |
#endif |
| 2225 |
|
| 2226 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2227 |
|
| 2228 |
ALLOW_CLONE(MWasmScalarToSimd128) |
| 2229 |
}; |
| 2230 |
|
| 2231 |
// (v128, imm) -> scalar effect-free operations. |
| 2232 |
class MWasmReduceSimd128 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2233 |
wasm::SimdOp simdOp_; |
| 2234 |
uint32_t imm_; |
| 2235 |
|
| 2236 |
MWasmReduceSimd128(MDefinition* src, wasm::SimdOp simdOp, MIRType outType, |
| 2237 |
uint32_t imm) |
| 2238 |
: MUnaryInstruction(classOpcode, src), simdOp_(simdOp), imm_(imm) { |
| 2239 |
setMovable(); |
| 2240 |
setResultType(outType); |
| 2241 |
} |
| 2242 |
|
| 2243 |
public: |
| 2244 |
INSTRUCTION_HEADER(WasmReduceSimd128) |
| 2245 |
TRIVIAL_NEW_WRAPPERS |
| 2246 |
|
| 2247 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2248 |
bool congruentTo(const MDefinition* ins) const override { |
| 2249 |
return congruentIfOperandsEqual(ins) && |
| 2250 |
ins->toWasmReduceSimd128()->simdOp() == simdOp_ && |
| 2251 |
ins->toWasmReduceSimd128()->imm() == imm_; |
| 2252 |
} |
| 2253 |
#ifdef ENABLE_WASM_SIMD |
| 2254 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2255 |
#endif |
| 2256 |
|
| 2257 |
uint32_t imm() const { return imm_; } |
| 2258 |
wasm::SimdOp simdOp() const { return simdOp_; } |
| 2259 |
|
| 2260 |
ALLOW_CLONE(MWasmReduceSimd128) |
| 2261 |
}; |
| 2262 |
|
| 2263 |
class MWasmLoadLaneSimd128 |
| 2264 |
: public MVariadicInstruction, // memoryBase is nullptr on some platforms |
| 2265 |
public NoTypePolicy::Data { |
| 2266 |
wasm::MemoryAccessDesc access_; |
| 2267 |
uint32_t laneSize_; |
| 2268 |
uint32_t laneIndex_; |
| 2269 |
uint32_t memoryBaseIndex_; |
| 2270 |
|
| 2271 |
MWasmLoadLaneSimd128(const wasm::MemoryAccessDesc& access, uint32_t laneSize, |
| 2272 |
uint32_t laneIndex, uint32_t memoryBaseIndex) |
| 2273 |
: MVariadicInstruction(classOpcode), |
| 2274 |
access_(access), |
| 2275 |
laneSize_(laneSize), |
| 2276 |
laneIndex_(laneIndex), |
| 2277 |
memoryBaseIndex_(memoryBaseIndex) { |
| 2278 |
MOZ_ASSERT(!access_.isAtomic()); |
| 2279 |
setGuard(); |
| 2280 |
setResultType(MIRType::Simd128); |
| 2281 |
} |
| 2282 |
|
| 2283 |
public: |
| 2284 |
INSTRUCTION_HEADER(WasmLoadLaneSimd128) |
| 2285 |
NAMED_OPERANDS((0, base), (1, value)); |
| 2286 |
|
| 2287 |
static MWasmLoadLaneSimd128* New(TempAllocator& alloc, |
| 2288 |
MDefinition* memoryBase, MDefinition* base, |
| 2289 |
const wasm::MemoryAccessDesc& access, |
| 2290 |
uint32_t laneSize, uint32_t laneIndex, |
| 2291 |
MDefinition* value) { |
| 2292 |
uint32_t nextIndex = 2; |
| 2293 |
uint32_t memoryBaseIndex = memoryBase ? nextIndex++ : UINT32_MAX; |
| 2294 |
|
| 2295 |
MWasmLoadLaneSimd128* load = new (alloc) |
| 2296 |
MWasmLoadLaneSimd128(access, laneSize, laneIndex, memoryBaseIndex); |
| 2297 |
if (!load->init(alloc, nextIndex)) { |
| 2298 |
return nullptr; |
| 2299 |
} |
| 2300 |
|
| 2301 |
load->initOperand(0, base); |
| 2302 |
load->initOperand(1, value); |
| 2303 |
if (memoryBase) { |
| 2304 |
load->initOperand(memoryBaseIndex, memoryBase); |
| 2305 |
} |
| 2306 |
|
| 2307 |
return load; |
| 2308 |
} |
| 2309 |
|
| 2310 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 2311 |
uint32_t laneSize() const { return laneSize_; } |
| 2312 |
uint32_t laneIndex() const { return laneIndex_; } |
| 2313 |
bool hasMemoryBase() const { return memoryBaseIndex_ != UINT32_MAX; } |
| 2314 |
MDefinition* memoryBase() const { |
| 2315 |
MOZ_ASSERT(hasMemoryBase()); |
| 2316 |
return getOperand(memoryBaseIndex_); |
| 2317 |
} |
| 2318 |
|
| 2319 |
AliasSet getAliasSet() const override { |
| 2320 |
return AliasSet::Load(AliasSet::WasmHeap); |
| 2321 |
} |
| 2322 |
}; |
| 2323 |
|
| 2324 |
class MWasmStoreLaneSimd128 : public MVariadicInstruction, |
| 2325 |
public NoTypePolicy::Data { |
| 2326 |
wasm::MemoryAccessDesc access_; |
| 2327 |
uint32_t laneSize_; |
| 2328 |
uint32_t laneIndex_; |
| 2329 |
uint32_t memoryBaseIndex_; |
| 2330 |
|
| 2331 |
explicit MWasmStoreLaneSimd128(const wasm::MemoryAccessDesc& access, |
| 2332 |
uint32_t laneSize, uint32_t laneIndex, |
| 2333 |
uint32_t memoryBaseIndex) |
| 2334 |
: MVariadicInstruction(classOpcode), |
| 2335 |
access_(access), |
| 2336 |
laneSize_(laneSize), |
| 2337 |
laneIndex_(laneIndex), |
| 2338 |
memoryBaseIndex_(memoryBaseIndex) { |
| 2339 |
MOZ_ASSERT(!access_.isAtomic()); |
| 2340 |
setGuard(); |
| 2341 |
setResultType(MIRType::Simd128); |
| 2342 |
} |
| 2343 |
|
| 2344 |
public: |
| 2345 |
INSTRUCTION_HEADER(WasmStoreLaneSimd128) |
| 2346 |
NAMED_OPERANDS((0, base), (1, value)) |
| 2347 |
|
| 2348 |
static MWasmStoreLaneSimd128* New(TempAllocator& alloc, |
| 2349 |
MDefinition* memoryBase, MDefinition* base, |
| 2350 |
const wasm::MemoryAccessDesc& access, |
| 2351 |
uint32_t laneSize, uint32_t laneIndex, |
| 2352 |
MDefinition* value) { |
| 2353 |
uint32_t nextIndex = 2; |
| 2354 |
uint32_t memoryBaseIndex = memoryBase ? nextIndex++ : UINT32_MAX; |
| 2355 |
|
| 2356 |
MWasmStoreLaneSimd128* store = new (alloc) |
| 2357 |
MWasmStoreLaneSimd128(access, laneSize, laneIndex, memoryBaseIndex); |
| 2358 |
if (!store->init(alloc, nextIndex)) { |
| 2359 |
return nullptr; |
| 2360 |
} |
| 2361 |
|
| 2362 |
store->initOperand(0, base); |
| 2363 |
store->initOperand(1, value); |
| 2364 |
if (memoryBase) { |
| 2365 |
store->initOperand(memoryBaseIndex, memoryBase); |
| 2366 |
} |
| 2367 |
|
| 2368 |
return store; |
| 2369 |
} |
| 2370 |
|
| 2371 |
const wasm::MemoryAccessDesc& access() const { return access_; } |
| 2372 |
uint32_t laneSize() const { return laneSize_; } |
| 2373 |
uint32_t laneIndex() const { return laneIndex_; } |
| 2374 |
bool hasMemoryBase() const { return memoryBaseIndex_ != UINT32_MAX; } |
| 2375 |
MDefinition* memoryBase() const { |
| 2376 |
MOZ_ASSERT(hasMemoryBase()); |
| 2377 |
return getOperand(memoryBaseIndex_); |
| 2378 |
} |
| 2379 |
|
| 2380 |
AliasSet getAliasSet() const override { |
| 2381 |
return AliasSet::Store(AliasSet::WasmHeap); |
| 2382 |
} |
| 2383 |
}; |
| 2384 |
|
| 2385 |
// End Wasm SIMD |
| 2386 |
|
| 2387 |
class MIonToWasmCall final : public MVariadicInstruction, |
| 2388 |
public NoTypePolicy::Data { |
| 2389 |
CompilerGCPointer<WasmInstanceObject*> instanceObj_; |
| 2390 |
const wasm::FuncExport& funcExport_; |
| 2391 |
|
| 2392 |
MIonToWasmCall(WasmInstanceObject* instanceObj, MIRType resultType, |
| 2393 |
const wasm::FuncExport& funcExport) |
| 2394 |
: MVariadicInstruction(classOpcode), |
| 2395 |
instanceObj_(instanceObj), |
| 2396 |
funcExport_(funcExport) { |
| 2397 |
setResultType(resultType); |
| 2398 |
} |
| 2399 |
|
| 2400 |
public: |
| 2401 |
INSTRUCTION_HEADER(IonToWasmCall); |
| 2402 |
|
| 2403 |
static MIonToWasmCall* New(TempAllocator& alloc, |
| 2404 |
WasmInstanceObject* instanceObj, |
| 2405 |
const wasm::FuncExport& funcExport); |
| 2406 |
|
| 2407 |
void initArg(size_t i, MDefinition* arg) { initOperand(i, arg); } |
| 2408 |
|
| 2409 |
WasmInstanceObject* instanceObject() const { return instanceObj_; } |
| 2410 |
wasm::Instance* instance() const { return &instanceObj_->instance(); } |
| 2411 |
const wasm::FuncExport& funcExport() const { return funcExport_; } |
| 2412 |
bool possiblyCalls() const override { return true; } |
| 2413 |
#ifdef DEBUG |
| 2414 |
bool isConsistentFloat32Use(MUse* use) const override; |
| 2415 |
#endif |
| 2416 |
}; |
| 2417 |
|
| 2418 |
// For accesses to wasm object fields, we need to be able to describe 8- and |
| 2419 |
// 16-bit accesses. But MIRType can't represent those. Hence these two |
| 2420 |
// supplemental enums, used for reading and writing fields respectively. |
| 2421 |
|
| 2422 |
// Indicates how to widen an 8- or 16-bit value (when it is read from memory). |
| 2423 |
enum class MWideningOp : uint8_t { None, FromU16, FromS16, FromU8, FromS8 }; |
| 2424 |
|
| 2425 |
#ifdef JS_JITSPEW |
| 2426 |
static inline const char* StringFromMWideningOp(MWideningOp op) { |
| 2427 |
switch (op) { |
| 2428 |
case MWideningOp::None: |
| 2429 |
return "None"; |
| 2430 |
case MWideningOp::FromU16: |
| 2431 |
return "FromU16"; |
| 2432 |
case MWideningOp::FromS16: |
| 2433 |
return "FromS16"; |
| 2434 |
case MWideningOp::FromU8: |
| 2435 |
return "FromU8"; |
| 2436 |
case MWideningOp::FromS8: |
| 2437 |
return "FromS8"; |
| 2438 |
default: |
| 2439 |
break; |
| 2440 |
} |
| 2441 |
MOZ_CRASH("Unknown MWideningOp"); |
| 2442 |
} |
| 2443 |
#endif |
| 2444 |
|
| 2445 |
// Indicates how to narrow a 32-bit value (when it is written to memory). The |
| 2446 |
// operation is a simple truncate. |
| 2447 |
enum class MNarrowingOp : uint8_t { None, To16, To8 }; |
| 2448 |
|
| 2449 |
#ifdef JS_JITSPEW |
| 2450 |
static inline const char* StringFromMNarrowingOp(MNarrowingOp op) { |
| 2451 |
switch (op) { |
| 2452 |
case MNarrowingOp::None: |
| 2453 |
return "None"; |
| 2454 |
case MNarrowingOp::To16: |
| 2455 |
return "To16"; |
| 2456 |
case MNarrowingOp::To8: |
| 2457 |
return "To8"; |
| 2458 |
default: |
| 2459 |
break; |
| 2460 |
} |
| 2461 |
MOZ_CRASH("Unknown MNarrowingOp"); |
| 2462 |
} |
| 2463 |
#endif |
| 2464 |
|
| 2465 |
// Loads a value from a location, denoted as a fixed offset from a base |
| 2466 |
// pointer. This field may be any value type, including references. No |
| 2467 |
// barriers are performed. |
| 2468 |
// |
| 2469 |
// This instruction can extend the lifetime of an optional `keepAlive` |
| 2470 |
// parameter to match the lifetime of this instruction. This is necessary if |
| 2471 |
// the base pointer is owned by some GC'ed object, which means that the GC |
| 2472 |
// object must have the same lifetime as all uses of it's owned pointers. |
| 2473 |
// No code to access the keepAlive value is generated. |
| 2474 |
// |
| 2475 |
// `offset` must be representable as a 31-bit unsigned integer. |
| 2476 |
// |
| 2477 |
// An optional structFieldIndex can be given for struct accesses and used in |
| 2478 |
// scalar replacement. |
| 2479 |
class MWasmLoadField : public MBinaryInstruction, public NoTypePolicy::Data { |
| 2480 |
uint32_t offset_; |
| 2481 |
mozilla::Maybe<uint32_t> structFieldIndex_; |
| 2482 |
MWideningOp wideningOp_; |
| 2483 |
AliasSet aliases_; |
| 2484 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2485 |
mozilla::Maybe<wasm::RefTypeHierarchy> hierarchy_; |
| 2486 |
|
| 2487 |
MWasmLoadField(MDefinition* base, MDefinition* keepAlive, size_t offset, |
| 2488 |
mozilla::Maybe<uint32_t> structFieldIndex, MIRType type, |
| 2489 |
MWideningOp wideningOp, AliasSet aliases, |
| 2490 |
wasm::MaybeTrapSiteDesc maybeTrap = mozilla::Nothing(), |
| 2491 |
wasm::MaybeRefType maybeRefType = wasm::MaybeRefType()) |
| 2492 |
: MBinaryInstruction(classOpcode, base, keepAlive ? keepAlive : base), |
| 2493 |
offset_(uint32_t(offset)), |
| 2494 |
structFieldIndex_(structFieldIndex), |
| 2495 |
wideningOp_(wideningOp), |
| 2496 |
aliases_(aliases), |
| 2497 |
maybeTrap_(std::move(maybeTrap)), |
| 2498 |
hierarchy_(maybeRefType.hierarchy()) { |
| 2499 |
MOZ_ASSERT(offset <= INT32_MAX); |
| 2500 |
// "if you want to widen the value when it is loaded, the destination type |
| 2501 |
// must be Int32". |
| 2502 |
MOZ_ASSERT_IF(wideningOp != MWideningOp::None, type == MIRType::Int32); |
| 2503 |
MOZ_ASSERT( |
| 2504 |
aliases.flags() == |
| 2505 |
AliasSet::Load(AliasSet::WasmStructOutlineDataPointer).flags() || |
| 2506 |
aliases.flags() == |
| 2507 |
AliasSet::Load(AliasSet::WasmStructInlineDataArea).flags() || |
| 2508 |
aliases.flags() == |
| 2509 |
AliasSet::Load(AliasSet::WasmStructOutlineDataArea).flags() || |
| 2510 |
aliases.flags() == |
| 2511 |
AliasSet::Load(AliasSet::WasmArrayNumElements).flags() || |
| 2512 |
aliases.flags() == |
| 2513 |
AliasSet::Load(AliasSet::WasmArrayDataPointer).flags() || |
| 2514 |
aliases.flags() == |
| 2515 |
AliasSet::Load(AliasSet::WasmArrayDataArea).flags() || |
| 2516 |
aliases.flags() == AliasSet::Load(AliasSet::Any).flags()); |
| 2517 |
setResultType(type); |
| 2518 |
if (maybeTrap_) { |
| 2519 |
setGuard(); |
| 2520 |
} |
| 2521 |
initWasmRefType(maybeRefType); |
| 2522 |
} |
| 2523 |
|
| 2524 |
public: |
| 2525 |
INSTRUCTION_HEADER(WasmLoadField) |
| 2526 |
TRIVIAL_NEW_WRAPPERS |
| 2527 |
NAMED_OPERANDS((0, base), (1, keepAlive)) |
| 2528 |
|
| 2529 |
uint32_t offset() const { return offset_; } |
| 2530 |
mozilla::Maybe<uint32_t> structFieldIndex() const { |
| 2531 |
return structFieldIndex_; |
| 2532 |
} |
| 2533 |
MWideningOp wideningOp() const { return wideningOp_; } |
| 2534 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2535 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2536 |
mozilla::Maybe<wasm::RefTypeHierarchy> hierarchy() const { |
| 2537 |
return hierarchy_; |
| 2538 |
} |
| 2539 |
|
| 2540 |
bool congruentTo(const MDefinition* ins) const override { |
| 2541 |
if (!ins->isWasmLoadField()) { |
| 2542 |
return false; |
| 2543 |
} |
| 2544 |
const MWasmLoadField* other = ins->toWasmLoadField(); |
| 2545 |
return ins->isWasmLoadField() && congruentIfOperandsEqual(ins) && |
| 2546 |
offset() == other->offset() && |
| 2547 |
structFieldIndex() == other->structFieldIndex() && |
| 2548 |
wideningOp() == other->wideningOp() && |
| 2549 |
getAliasSet().flags() == other->getAliasSet().flags() && |
| 2550 |
hierarchy() == other->hierarchy(); |
| 2551 |
} |
| 2552 |
|
| 2553 |
#ifdef JS_JITSPEW |
| 2554 |
void getExtras(ExtrasCollector* extras) const override { |
| 2555 |
char buf[96]; |
| 2556 |
SprintfLiteral(buf, "(offs=%lld, wideningOp=%s)", (long long int)offset_, |
| 2557 |
StringFromMWideningOp(wideningOp_)); |
| 2558 |
extras->add(buf); |
| 2559 |
} |
| 2560 |
#endif |
| 2561 |
|
| 2562 |
ALLOW_CLONE(MWasmLoadField) |
| 2563 |
}; |
| 2564 |
|
| 2565 |
// Loads a value from base pointer, given an index and element size. This field |
| 2566 |
// may be any value type, including references. No barriers are performed. |
| 2567 |
// |
| 2568 |
// The element size is implicitly defined by MIRType and MWideningOp. For |
| 2569 |
// example, MIRType::Float32 indicates an element size of 32 bits, and |
| 2570 |
// MIRType::Int32 and MWideningOp::FromU16 together indicate an element size of |
| 2571 |
// 16 bits. |
| 2572 |
// |
| 2573 |
// This instruction takes an optional second object `keepAlive` that must be |
| 2574 |
// kept alive, as described for MWasmLoadField above. |
| 2575 |
class MWasmLoadElement : public MTernaryInstruction, public NoTypePolicy::Data { |
| 2576 |
MWideningOp wideningOp_; |
| 2577 |
Scale scale_; |
| 2578 |
AliasSet aliases_; |
| 2579 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2580 |
|
| 2581 |
MWasmLoadElement(MDefinition* base, MDefinition* keepAlive, |
| 2582 |
MDefinition* index, MIRType type, MWideningOp wideningOp, |
| 2583 |
Scale scale, AliasSet aliases, |
| 2584 |
wasm::MaybeTrapSiteDesc maybeTrap = mozilla::Nothing(), |
| 2585 |
wasm::MaybeRefType maybeRefType = wasm::MaybeRefType()) |
| 2586 |
: MTernaryInstruction(classOpcode, base, index, |
| 2587 |
keepAlive ? keepAlive : base), |
| 2588 |
wideningOp_(wideningOp), |
| 2589 |
scale_(scale), |
| 2590 |
aliases_(aliases), |
| 2591 |
maybeTrap_(std::move(maybeTrap)) { |
| 2592 |
MOZ_ASSERT(base->type() == MIRType::WasmArrayData); |
| 2593 |
MOZ_ASSERT(aliases.flags() == |
| 2594 |
AliasSet::Load(AliasSet::WasmArrayDataArea).flags() || |
| 2595 |
aliases.flags() == AliasSet::Load(AliasSet::Any).flags()); |
| 2596 |
setResultType(type); |
| 2597 |
if (maybeTrap_) { |
| 2598 |
setGuard(); |
| 2599 |
} |
| 2600 |
initWasmRefType(maybeRefType); |
| 2601 |
} |
| 2602 |
|
| 2603 |
public: |
| 2604 |
INSTRUCTION_HEADER(WasmLoadElement) |
| 2605 |
TRIVIAL_NEW_WRAPPERS |
| 2606 |
NAMED_OPERANDS((0, base), (1, index), (2, keepAlive)) |
| 2607 |
|
| 2608 |
MWideningOp wideningOp() const { return wideningOp_; } |
| 2609 |
Scale scale() const { return scale_; } |
| 2610 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2611 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2612 |
|
| 2613 |
#ifdef JS_JITSPEW |
| 2614 |
void getExtras(ExtrasCollector* extras) const override { |
| 2615 |
char buf[96]; |
| 2616 |
SprintfLiteral(buf, "(wideningOp=%s, scale=%s)", |
| 2617 |
StringFromMWideningOp(wideningOp_), StringFromScale(scale_)); |
| 2618 |
extras->add(buf); |
| 2619 |
} |
| 2620 |
#endif |
| 2621 |
|
| 2622 |
ALLOW_CLONE(MWasmLoadElement) |
| 2623 |
}; |
| 2624 |
|
| 2625 |
// Stores a non-reference value to anlocation, denoted as a fixed offset from |
| 2626 |
// a base pointer, which (it is assumed) is within a wasm object. This field |
| 2627 |
// may be any value type, _excluding_ references. References _must_ use the |
| 2628 |
// 'Ref' variant of this instruction. The offset must be representable as a |
| 2629 |
// 31-bit unsigned integer. |
| 2630 |
// |
| 2631 |
// This instruction takes a second object `keepAlive` that must be kept alive, |
| 2632 |
// as described for MWasmLoadField above. |
| 2633 |
class MWasmStoreField : public MTernaryInstruction, public NoTypePolicy::Data { |
| 2634 |
uint32_t offset_; |
| 2635 |
mozilla::Maybe<uint32_t> structFieldIndex_; |
| 2636 |
MNarrowingOp narrowingOp_; |
| 2637 |
AliasSet aliases_; |
| 2638 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2639 |
|
| 2640 |
MWasmStoreField(MDefinition* base, MDefinition* keepAlive, size_t offset, |
| 2641 |
mozilla::Maybe<uint32_t> structFieldIndex, MDefinition* value, |
| 2642 |
MNarrowingOp narrowingOp, AliasSet aliases, |
| 2643 |
wasm::MaybeTrapSiteDesc maybeTrap = mozilla::Nothing()) |
| 2644 |
: MTernaryInstruction(classOpcode, base, value, |
| 2645 |
keepAlive ? keepAlive : base), |
| 2646 |
offset_(uint32_t(offset)), |
| 2647 |
structFieldIndex_(structFieldIndex), |
| 2648 |
narrowingOp_(narrowingOp), |
| 2649 |
aliases_(aliases), |
| 2650 |
maybeTrap_(std::move(maybeTrap)) { |
| 2651 |
MOZ_ASSERT(offset <= INT32_MAX); |
| 2652 |
MOZ_ASSERT(value->type() != MIRType::WasmAnyRef); |
| 2653 |
// "if you want to narrow the value when it is stored, the source type |
| 2654 |
// must be Int32". |
| 2655 |
MOZ_ASSERT_IF(narrowingOp != MNarrowingOp::None, |
| 2656 |
value->type() == MIRType::Int32); |
| 2657 |
MOZ_ASSERT( |
| 2658 |
aliases.flags() == |
| 2659 |
AliasSet::Store(AliasSet::WasmStructInlineDataArea).flags() || |
| 2660 |
aliases.flags() == |
| 2661 |
AliasSet::Store(AliasSet::WasmStructOutlineDataArea).flags() || |
| 2662 |
aliases.flags() == |
| 2663 |
AliasSet::Store(AliasSet::WasmArrayDataArea).flags() || |
| 2664 |
aliases.flags() == AliasSet::Store(AliasSet::Any).flags()); |
| 2665 |
if (maybeTrap_) { |
| 2666 |
setGuard(); |
| 2667 |
} |
| 2668 |
} |
| 2669 |
|
| 2670 |
public: |
| 2671 |
INSTRUCTION_HEADER(WasmStoreField) |
| 2672 |
TRIVIAL_NEW_WRAPPERS |
| 2673 |
NAMED_OPERANDS((0, base), (1, value), (2, keepAlive)) |
| 2674 |
|
| 2675 |
uint32_t offset() const { return offset_; } |
| 2676 |
mozilla::Maybe<uint32_t> structFieldIndex() const { |
| 2677 |
return structFieldIndex_; |
| 2678 |
} |
| 2679 |
MNarrowingOp narrowingOp() const { return narrowingOp_; } |
| 2680 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2681 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2682 |
|
| 2683 |
#ifdef JS_JITSPEW |
| 2684 |
void getExtras(ExtrasCollector* extras) const override { |
| 2685 |
char buf[96]; |
| 2686 |
SprintfLiteral(buf, "(offs=%lld, narrowingOp=%s)", (long long int)offset_, |
| 2687 |
StringFromMNarrowingOp(narrowingOp_)); |
| 2688 |
extras->add(buf); |
| 2689 |
} |
| 2690 |
#endif |
| 2691 |
|
| 2692 |
ALLOW_CLONE(MWasmStoreField) |
| 2693 |
}; |
| 2694 |
|
| 2695 |
// Stores a reference value to a location, denoted as a fixed offset from a |
| 2696 |
// base pointer, which (it is assumed) is within a wasm object. This |
| 2697 |
// instruction emits a pre-barrier. A post barrier _must_ be performed |
| 2698 |
// separately. The offset must be representable as a 31-bit unsigned integer. |
| 2699 |
// |
| 2700 |
// This instruction takes a second object `keepAlive` that must be kept alive, |
| 2701 |
// as described for MWasmLoadField above. |
| 2702 |
class MWasmStoreFieldRef : public MAryInstruction<4>, |
| 2703 |
public NoTypePolicy::Data { |
| 2704 |
uint32_t offset_; |
| 2705 |
mozilla::Maybe<uint32_t> structFieldIndex_; |
| 2706 |
AliasSet aliases_; |
| 2707 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2708 |
WasmPreBarrierKind preBarrierKind_; |
| 2709 |
|
| 2710 |
MWasmStoreFieldRef(MDefinition* instance, MDefinition* base, |
| 2711 |
MDefinition* keepAlive, size_t offset, |
| 2712 |
mozilla::Maybe<uint32_t> structFieldIndex, |
| 2713 |
MDefinition* value, AliasSet aliases, |
| 2714 |
wasm::MaybeTrapSiteDesc maybeTrap, |
| 2715 |
WasmPreBarrierKind preBarrierKind) |
| 2716 |
: MAryInstruction<4>(classOpcode), |
| 2717 |
offset_(uint32_t(offset)), |
| 2718 |
structFieldIndex_(structFieldIndex), |
| 2719 |
aliases_(aliases), |
| 2720 |
maybeTrap_(std::move(maybeTrap)), |
| 2721 |
preBarrierKind_(preBarrierKind) { |
| 2722 |
MOZ_ASSERT(base->type() == TargetWordMIRType() || |
| 2723 |
base->type() == MIRType::Pointer || |
| 2724 |
base->type() == MIRType::WasmAnyRef || |
| 2725 |
base->type() == MIRType::WasmArrayData); |
| 2726 |
MOZ_ASSERT(offset <= INT32_MAX); |
| 2727 |
MOZ_ASSERT(value->type() == MIRType::WasmAnyRef); |
| 2728 |
MOZ_ASSERT( |
| 2729 |
aliases.flags() == |
| 2730 |
AliasSet::Store(AliasSet::WasmStructInlineDataArea).flags() || |
| 2731 |
aliases.flags() == |
| 2732 |
AliasSet::Store(AliasSet::WasmStructOutlineDataArea).flags() || |
| 2733 |
aliases.flags() == |
| 2734 |
AliasSet::Store(AliasSet::WasmArrayDataArea).flags() || |
| 2735 |
aliases.flags() == AliasSet::Store(AliasSet::Any).flags()); |
| 2736 |
initOperand(0, instance); |
| 2737 |
initOperand(1, base); |
| 2738 |
initOperand(2, value); |
| 2739 |
initOperand(3, keepAlive ? keepAlive : base); |
| 2740 |
if (maybeTrap_) { |
| 2741 |
setGuard(); |
| 2742 |
} |
| 2743 |
} |
| 2744 |
|
| 2745 |
public: |
| 2746 |
INSTRUCTION_HEADER(WasmStoreFieldRef) |
| 2747 |
TRIVIAL_NEW_WRAPPERS |
| 2748 |
NAMED_OPERANDS((0, instance), (1, base), (2, value), (3, keepAlive)) |
| 2749 |
|
| 2750 |
uint32_t offset() const { return offset_; } |
| 2751 |
mozilla::Maybe<uint32_t> structFieldIndex() const { |
| 2752 |
return structFieldIndex_; |
| 2753 |
} |
| 2754 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2755 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2756 |
WasmPreBarrierKind preBarrierKind() const { return preBarrierKind_; } |
| 2757 |
|
| 2758 |
#ifdef JS_JITSPEW |
| 2759 |
void getExtras(ExtrasCollector* extras) const override { |
| 2760 |
char buf[64]; |
| 2761 |
SprintfLiteral(buf, "(offs=%lld)", (long long int)offset_); |
| 2762 |
extras->add(buf); |
| 2763 |
} |
| 2764 |
#endif |
| 2765 |
|
| 2766 |
ALLOW_CLONE(MWasmStoreFieldRef) |
| 2767 |
}; |
| 2768 |
|
| 2769 |
// Stores a non-reference value to a base pointer, given an index and element |
| 2770 |
// size. This field may be any value type, excluding references. References MUST |
| 2771 |
// use the 'Ref' variant of this instruction. |
| 2772 |
// |
| 2773 |
// The element size is implicitly defined by MIRType and MNarrowingOp. For |
| 2774 |
// example, MIRType::Float32 indicates an element size of 32 bits, and |
| 2775 |
// MIRType::Int32 and MNarrowingOp::To16 together indicate an element size of 16 |
| 2776 |
// bits. |
| 2777 |
// |
| 2778 |
// This instruction takes a second object `keepAlive` that must be kept alive, |
| 2779 |
// as described for MWasmLoadField above. |
| 2780 |
class MWasmStoreElement : public MQuaternaryInstruction, |
| 2781 |
public NoTypePolicy::Data { |
| 2782 |
MNarrowingOp narrowingOp_; |
| 2783 |
Scale scale_; |
| 2784 |
AliasSet aliases_; |
| 2785 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2786 |
|
| 2787 |
MWasmStoreElement(MDefinition* base, MDefinition* index, MDefinition* value, |
| 2788 |
MDefinition* keepAlive, MNarrowingOp narrowingOp, |
| 2789 |
Scale scale, AliasSet aliases, |
| 2790 |
wasm::MaybeTrapSiteDesc maybeTrap = mozilla::Nothing()) |
| 2791 |
: MQuaternaryInstruction(classOpcode, base, index, value, |
| 2792 |
keepAlive ? keepAlive : base), |
| 2793 |
narrowingOp_(narrowingOp), |
| 2794 |
scale_(scale), |
| 2795 |
aliases_(aliases), |
| 2796 |
maybeTrap_(std::move(maybeTrap)) { |
| 2797 |
MOZ_ASSERT(base->type() == MIRType::WasmArrayData); |
| 2798 |
MOZ_ASSERT(value->type() != MIRType::WasmAnyRef); |
| 2799 |
// "if you want to narrow the value when it is stored, the source type |
| 2800 |
// must be Int32". |
| 2801 |
MOZ_ASSERT_IF(narrowingOp != MNarrowingOp::None, |
| 2802 |
value->type() == MIRType::Int32); |
| 2803 |
MOZ_ASSERT(aliases.flags() == |
| 2804 |
AliasSet::Store(AliasSet::WasmArrayDataArea).flags() || |
| 2805 |
aliases.flags() == AliasSet::Store(AliasSet::Any).flags()); |
| 2806 |
if (maybeTrap_) { |
| 2807 |
setGuard(); |
| 2808 |
} |
| 2809 |
} |
| 2810 |
|
| 2811 |
public: |
| 2812 |
INSTRUCTION_HEADER(WasmStoreElement) |
| 2813 |
TRIVIAL_NEW_WRAPPERS |
| 2814 |
NAMED_OPERANDS((0, base), (1, index), (2, value), (3, keepAlive)) |
| 2815 |
|
| 2816 |
MNarrowingOp narrowingOp() const { return narrowingOp_; } |
| 2817 |
Scale scale() const { return scale_; } |
| 2818 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2819 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2820 |
|
| 2821 |
#ifdef JS_JITSPEW |
| 2822 |
void getExtras(ExtrasCollector* extras) const override { |
| 2823 |
char buf[96]; |
| 2824 |
SprintfLiteral(buf, "(narrowingOp=%s, scale=%s)", |
| 2825 |
StringFromMNarrowingOp(narrowingOp_), |
| 2826 |
StringFromScale(scale_)); |
| 2827 |
extras->add(buf); |
| 2828 |
} |
| 2829 |
#endif |
| 2830 |
|
| 2831 |
ALLOW_CLONE(MWasmStoreElement) |
| 2832 |
}; |
| 2833 |
|
| 2834 |
// Stores a reference value to a base pointer, given an index and element size. |
| 2835 |
// This instruction emits a pre-barrier. A post barrier MUST be performed |
| 2836 |
// separately. |
| 2837 |
// |
| 2838 |
// The element size is implicitly defined by MIRType and MNarrowingOp, as |
| 2839 |
// described for MWasmStoreElement above. |
| 2840 |
// |
| 2841 |
// This instruction takes a second object `ka` that must be kept alive, as |
| 2842 |
// described for MWasmLoadField above. |
| 2843 |
class MWasmStoreElementRef : public MAryInstruction<5>, |
| 2844 |
public NoTypePolicy::Data { |
| 2845 |
AliasSet aliases_; |
| 2846 |
wasm::MaybeTrapSiteDesc maybeTrap_; |
| 2847 |
WasmPreBarrierKind preBarrierKind_; |
| 2848 |
|
| 2849 |
MWasmStoreElementRef(MDefinition* instance, MDefinition* base, |
| 2850 |
MDefinition* index, MDefinition* value, |
| 2851 |
MDefinition* keepAlive, AliasSet aliases, |
| 2852 |
wasm::MaybeTrapSiteDesc maybeTrap, |
| 2853 |
WasmPreBarrierKind preBarrierKind) |
| 2854 |
: MAryInstruction<5>(classOpcode), |
| 2855 |
aliases_(aliases), |
| 2856 |
maybeTrap_(std::move(maybeTrap)), |
| 2857 |
preBarrierKind_(preBarrierKind) { |
| 2858 |
MOZ_ASSERT(base->type() == MIRType::WasmArrayData); |
| 2859 |
MOZ_ASSERT(value->type() == MIRType::WasmAnyRef); |
| 2860 |
MOZ_ASSERT(aliases.flags() == |
| 2861 |
AliasSet::Store(AliasSet::WasmArrayDataArea).flags() || |
| 2862 |
aliases.flags() == AliasSet::Store(AliasSet::Any).flags()); |
| 2863 |
initOperand(0, instance); |
| 2864 |
initOperand(1, base); |
| 2865 |
initOperand(2, index); |
| 2866 |
initOperand(3, value); |
| 2867 |
initOperand(4, keepAlive ? keepAlive : base); |
| 2868 |
if (maybeTrap_) { |
| 2869 |
setGuard(); |
| 2870 |
} |
| 2871 |
} |
| 2872 |
|
| 2873 |
public: |
| 2874 |
INSTRUCTION_HEADER(WasmStoreElementRef) |
| 2875 |
TRIVIAL_NEW_WRAPPERS |
| 2876 |
NAMED_OPERANDS((0, instance), (1, base), (2, index), (3, value), |
| 2877 |
(4, keepAlive)) |
| 2878 |
|
| 2879 |
AliasSet getAliasSet() const override { return aliases_; } |
| 2880 |
wasm::MaybeTrapSiteDesc maybeTrap() const { return maybeTrap_; } |
| 2881 |
WasmPreBarrierKind preBarrierKind() const { return preBarrierKind_; } |
| 2882 |
|
| 2883 |
ALLOW_CLONE(MWasmStoreElementRef) |
| 2884 |
}; |
| 2885 |
|
| 2886 |
class MWasmRefAsNonNull : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2887 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 2888 |
|
| 2889 |
MWasmRefAsNonNull(MDefinition* ref, const wasm::TrapSiteDesc& trapSiteDesc) |
| 2890 |
: MUnaryInstruction(classOpcode, ref), trapSiteDesc_(trapSiteDesc) { |
| 2891 |
setResultType(MIRType::WasmAnyRef); |
| 2892 |
setGuard(); |
| 2893 |
} |
| 2894 |
|
| 2895 |
public: |
| 2896 |
INSTRUCTION_HEADER(WasmRefAsNonNull) |
| 2897 |
TRIVIAL_NEW_WRAPPERS |
| 2898 |
NAMED_OPERANDS((0, ref)) |
| 2899 |
|
| 2900 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 2901 |
|
| 2902 |
bool congruentTo(const MDefinition* ins) const override { |
| 2903 |
return congruentIfOperandsEqual(ins); |
| 2904 |
} |
| 2905 |
|
| 2906 |
wasm::MaybeRefType computeWasmRefType() const override { |
| 2907 |
if (ref()->wasmRefType().isNothing()) { |
| 2908 |
return wasm::MaybeRefType(); |
| 2909 |
} |
| 2910 |
return wasm::MaybeRefType(ref()->wasmRefType().value().asNonNullable()); |
| 2911 |
} |
| 2912 |
|
| 2913 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2914 |
|
| 2915 |
ALLOW_CLONE(MWasmRefAsNonNull) |
| 2916 |
}; |
| 2917 |
|
| 2918 |
// Tests if the wasm ref `ref` is a subtype of `destType` and returns the |
| 2919 |
// boolean representing the result. |
| 2920 |
class MWasmRefTestAbstract : public MUnaryInstruction, |
| 2921 |
public NoTypePolicy::Data { |
| 2922 |
wasm::RefType destType_; |
| 2923 |
|
| 2924 |
MWasmRefTestAbstract(MDefinition* ref, wasm::RefType destType) |
| 2925 |
: MUnaryInstruction(classOpcode, ref), destType_(destType) { |
| 2926 |
MOZ_ASSERT(!destType.isTypeRef()); |
| 2927 |
setResultType(MIRType::Int32); |
| 2928 |
setMovable(); |
| 2929 |
} |
| 2930 |
|
| 2931 |
public: |
| 2932 |
INSTRUCTION_HEADER(WasmRefTestAbstract) |
| 2933 |
TRIVIAL_NEW_WRAPPERS |
| 2934 |
NAMED_OPERANDS((0, ref)) |
| 2935 |
|
| 2936 |
wasm::RefType destType() const { return destType_; }; |
| 2937 |
|
| 2938 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2939 |
|
| 2940 |
bool congruentTo(const MDefinition* ins) const override { |
| 2941 |
return congruentIfOperandsEqual(ins) && |
| 2942 |
destType() == ins->toWasmRefTestAbstract()->destType(); |
| 2943 |
} |
| 2944 |
|
| 2945 |
HashNumber valueHash() const override { |
| 2946 |
HashNumber hn = MUnaryInstruction::valueHash(); |
| 2947 |
hn = addU64ToHash(hn, destType().packed().bits()); |
| 2948 |
return hn; |
| 2949 |
} |
| 2950 |
|
| 2951 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2952 |
|
| 2953 |
ALLOW_CLONE(MWasmRefTestAbstract) |
| 2954 |
}; |
| 2955 |
|
| 2956 |
// Tests if the wasm ref `ref` is a subtype of `superSTV` and returns the |
| 2957 |
// boolean representing the result. |
| 2958 |
// |
| 2959 |
// The actual super type definition must be known at compile time, so that the |
| 2960 |
// subtyping depth of super type depth can be used. |
| 2961 |
class MWasmRefTestConcrete : public MBinaryInstruction, |
| 2962 |
public NoTypePolicy::Data { |
| 2963 |
wasm::RefType destType_; |
| 2964 |
|
| 2965 |
MWasmRefTestConcrete(MDefinition* ref, MDefinition* superSTV, |
| 2966 |
wasm::RefType destType) |
| 2967 |
: MBinaryInstruction(classOpcode, ref, superSTV), destType_(destType) { |
| 2968 |
MOZ_ASSERT(destType.isTypeRef()); |
| 2969 |
setResultType(MIRType::Int32); |
| 2970 |
setMovable(); |
| 2971 |
} |
| 2972 |
|
| 2973 |
public: |
| 2974 |
INSTRUCTION_HEADER(WasmRefTestConcrete) |
| 2975 |
TRIVIAL_NEW_WRAPPERS |
| 2976 |
NAMED_OPERANDS((0, ref), (1, superSTV)) |
| 2977 |
|
| 2978 |
wasm::RefType destType() const { return destType_; }; |
| 2979 |
|
| 2980 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2981 |
|
| 2982 |
bool congruentTo(const MDefinition* ins) const override { |
| 2983 |
return congruentIfOperandsEqual(ins) && |
| 2984 |
destType() == ins->toWasmRefTestConcrete()->destType(); |
| 2985 |
} |
| 2986 |
|
| 2987 |
HashNumber valueHash() const override { |
| 2988 |
HashNumber hn = MBinaryInstruction::valueHash(); |
| 2989 |
hn = addU64ToHash(hn, destType().packed().bits()); |
| 2990 |
return hn; |
| 2991 |
} |
| 2992 |
|
| 2993 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2994 |
|
| 2995 |
ALLOW_CLONE(MWasmRefTestConcrete) |
| 2996 |
}; |
| 2997 |
|
| 2998 |
// Tests if the wasm ref `ref` is a subtype of `destType` and if so returns the |
| 2999 |
// ref, otherwise it does a wasm trap. |
| 3000 |
class MWasmRefCastAbstract : public MUnaryInstruction, |
| 3001 |
public NoTypePolicy::Data { |
| 3002 |
wasm::RefType destType_; |
| 3003 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 3004 |
|
| 3005 |
MWasmRefCastAbstract(MDefinition* ref, wasm::RefType destType, |
| 3006 |
wasm::TrapSiteDesc&& trapSiteDesc) |
| 3007 |
: MUnaryInstruction(classOpcode, ref), |
| 3008 |
destType_(destType), |
| 3009 |
trapSiteDesc_(std::move(trapSiteDesc)) { |
| 3010 |
MOZ_ASSERT(!destType.isTypeRef()); |
| 3011 |
setResultType(MIRType::WasmAnyRef); |
| 3012 |
// This may trap, which requires this to be a guard. |
| 3013 |
setGuard(); |
| 3014 |
initWasmRefType(wasm::MaybeRefType(destType)); |
| 3015 |
} |
| 3016 |
|
| 3017 |
public: |
| 3018 |
INSTRUCTION_HEADER(WasmRefCastAbstract) |
| 3019 |
TRIVIAL_NEW_WRAPPERS |
| 3020 |
NAMED_OPERANDS((0, ref)) |
| 3021 |
|
| 3022 |
wasm::RefType destType() const { return destType_; }; |
| 3023 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 3024 |
|
| 3025 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3026 |
}; |
| 3027 |
|
| 3028 |
// Tests if the wasm ref `ref` is a subtype of `superSTV`, if so return the |
| 3029 |
// ref, otherwise do a wasm trap. |
| 3030 |
// |
| 3031 |
// The actual super type definition must be known at compile time, so that the |
| 3032 |
// subtyping depth of super type depth can be used. |
| 3033 |
class MWasmRefCastConcrete : public MBinaryInstruction, |
| 3034 |
public NoTypePolicy::Data { |
| 3035 |
wasm::RefType destType_; |
| 3036 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 3037 |
|
| 3038 |
MWasmRefCastConcrete(MDefinition* ref, MDefinition* superSTV, |
| 3039 |
wasm::RefType destType, |
| 3040 |
wasm::TrapSiteDesc&& trapSiteDesc) |
| 3041 |
: MBinaryInstruction(classOpcode, ref, superSTV), |
| 3042 |
destType_(destType), |
| 3043 |
trapSiteDesc_(std::move(trapSiteDesc)) { |
| 3044 |
MOZ_ASSERT(destType.isTypeRef()); |
| 3045 |
setResultType(MIRType::WasmAnyRef); |
| 3046 |
// This may trap, which requires this to be a guard. |
| 3047 |
setGuard(); |
| 3048 |
initWasmRefType(wasm::MaybeRefType(destType)); |
| 3049 |
} |
| 3050 |
|
| 3051 |
public: |
| 3052 |
INSTRUCTION_HEADER(WasmRefCastConcrete) |
| 3053 |
TRIVIAL_NEW_WRAPPERS |
| 3054 |
NAMED_OPERANDS((0, ref), (1, superSTV)) |
| 3055 |
|
| 3056 |
wasm::RefType destType() const { return destType_; }; |
| 3057 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 3058 |
|
| 3059 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3060 |
}; |
| 3061 |
|
| 3062 |
class MWasmRefConvertAnyExtern : public MUnaryInstruction, |
| 3063 |
public NoTypePolicy::Data { |
| 3064 |
wasm::RefType::Kind destTypeKind_; |
| 3065 |
|
| 3066 |
MWasmRefConvertAnyExtern(MDefinition* ref, wasm::RefType::Kind destTypeKind) |
| 3067 |
: MUnaryInstruction(classOpcode, ref), destTypeKind_(destTypeKind) { |
| 3068 |
MOZ_ASSERT(destTypeKind_ == wasm::RefType::Kind::Any || |
| 3069 |
destTypeKind_ == wasm::RefType::Kind::Extern); |
| 3070 |
setResultType(MIRType::WasmAnyRef); |
| 3071 |
setMovable(); |
| 3072 |
} |
| 3073 |
|
| 3074 |
public: |
| 3075 |
INSTRUCTION_HEADER(WasmRefConvertAnyExtern) |
| 3076 |
TRIVIAL_NEW_WRAPPERS |
| 3077 |
NAMED_OPERANDS((0, ref)) |
| 3078 |
|
| 3079 |
wasm::RefType::Kind destTypeKind() const { return destTypeKind_; } |
| 3080 |
|
| 3081 |
wasm::MaybeRefType computeWasmRefType() const override { |
| 3082 |
bool nullable = true; |
| 3083 |
if (ref()->wasmRefType().isSome()) { |
| 3084 |
nullable = ref()->wasmRefType().value().isNullable(); |
| 3085 |
}; |
| 3086 |
return wasm::MaybeRefType(wasm::RefType::fromKind(destTypeKind_, nullable)); |
| 3087 |
} |
| 3088 |
|
| 3089 |
bool congruentTo(const MDefinition* ins) const override { |
| 3090 |
return congruentIfOperandsEqual(ins) && |
| 3091 |
destTypeKind() == ins->toWasmRefConvertAnyExtern()->destTypeKind(); |
| 3092 |
} |
| 3093 |
|
| 3094 |
HashNumber valueHash() const override { |
| 3095 |
HashNumber hn = MUnaryInstruction::valueHash(); |
| 3096 |
hn = addU32ToHash(hn, destTypeKind()); |
| 3097 |
return hn; |
| 3098 |
} |
| 3099 |
|
| 3100 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3101 |
}; |
| 3102 |
|
| 3103 |
// Represents the contents of all fields of a wasm struct. |
| 3104 |
// This class will be used for scalar replacement of wasm structs. |
| 3105 |
class MWasmStructState : public TempObject { |
| 3106 |
private: |
| 3107 |
MDefinition* wasmStruct_; |
| 3108 |
// Represents the fields of this struct. |
| 3109 |
Vector<MDefinition*, 0, JitAllocPolicy> fields_; |
| 3110 |
|
| 3111 |
explicit MWasmStructState(TempAllocator& alloc, MDefinition* structObject) |
| 3112 |
: wasmStruct_(structObject), fields_(alloc) {} |
| 3113 |
|
| 3114 |
public: |
| 3115 |
static MWasmStructState* New(TempAllocator& alloc, MDefinition* structObject); |
| 3116 |
static MWasmStructState* Copy(TempAllocator& alloc, MWasmStructState* state); |
| 3117 |
|
| 3118 |
// Init the fields_ vector. |
| 3119 |
[[nodiscard]] bool init(); |
| 3120 |
|
| 3121 |
size_t numFields() const { return fields_.length(); } |
| 3122 |
MDefinition* wasmStruct() const { return wasmStruct_; } |
| 3123 |
|
| 3124 |
// Get the field value based on the position of the field in the struct. |
| 3125 |
MDefinition* getField(uint32_t index) const { return fields_[index]; } |
| 3126 |
// Set the field offset based on the position of the field in the struct. |
| 3127 |
void setField(uint32_t index, MDefinition* def) { fields_[index] = def; } |
| 3128 |
}; |
| 3129 |
|
| 3130 |
class MWasmNewStructObject : public MBinaryInstruction, |
| 3131 |
public NoTypePolicy::Data { |
| 3132 |
private: |
| 3133 |
const wasm::TypeDef* typeDef_; |
| 3134 |
bool zeroFields_; |
| 3135 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 3136 |
|
| 3137 |
MWasmNewStructObject(MDefinition* instance, MDefinition* allocSite, |
| 3138 |
const wasm::TypeDef* typeDef, bool zeroFields, |
| 3139 |
const wasm::TrapSiteDesc& trapSiteDesc) |
| 3140 |
: MBinaryInstruction(classOpcode, instance, allocSite), |
| 3141 |
typeDef_(typeDef), |
| 3142 |
zeroFields_(zeroFields), |
| 3143 |
trapSiteDesc_(trapSiteDesc) { |
| 3144 |
MOZ_ASSERT(typeDef->isStructType()); |
| 3145 |
setResultType(MIRType::WasmAnyRef); |
| 3146 |
initWasmRefType( |
| 3147 |
wasm::MaybeRefType(wasm::RefType::fromTypeDef(typeDef_, false))); |
| 3148 |
} |
| 3149 |
|
| 3150 |
public: |
| 3151 |
INSTRUCTION_HEADER(WasmNewStructObject) |
| 3152 |
TRIVIAL_NEW_WRAPPERS |
| 3153 |
NAMED_OPERANDS((0, instance), (1, allocSite)) |
| 3154 |
|
| 3155 |
AliasSet getAliasSet() const override { |
| 3156 |
if (js::SupportDifferentialTesting()) { |
| 3157 |
// Consider allocations effectful for differential testing. |
| 3158 |
return MDefinition::getAliasSet(); |
| 3159 |
} |
| 3160 |
return AliasSet::None(); |
| 3161 |
} |
| 3162 |
const wasm::TypeDef& typeDef() { return *typeDef_; } |
| 3163 |
const wasm::StructType& structType() const { return typeDef_->structType(); } |
| 3164 |
bool isOutline() const { |
| 3165 |
return WasmStructObject::requiresOutlineBytes(typeDef_->structType().size_); |
| 3166 |
} |
| 3167 |
bool zeroFields() const { return zeroFields_; } |
| 3168 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 3169 |
gc::AllocKind allocKind() const { |
| 3170 |
return WasmStructObject::allocKindForTypeDef(typeDef_); |
| 3171 |
} |
| 3172 |
}; |
| 3173 |
|
| 3174 |
class MWasmNewArrayObject : public MTernaryInstruction, |
| 3175 |
public NoTypePolicy::Data { |
| 3176 |
private: |
| 3177 |
const wasm::TypeDef* typeDef_; |
| 3178 |
bool zeroFields_; |
| 3179 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 3180 |
|
| 3181 |
MWasmNewArrayObject(MDefinition* instance, MDefinition* numElements, |
| 3182 |
MDefinition* allocSite, const wasm::TypeDef* typeDef, |
| 3183 |
bool zeroFields, const wasm::TrapSiteDesc& trapSiteDesc) |
| 3184 |
: MTernaryInstruction(classOpcode, instance, numElements, allocSite), |
| 3185 |
typeDef_(typeDef), |
| 3186 |
zeroFields_(zeroFields), |
| 3187 |
trapSiteDesc_(trapSiteDesc) { |
| 3188 |
MOZ_ASSERT(typeDef->isArrayType()); |
| 3189 |
setResultType(MIRType::WasmAnyRef); |
| 3190 |
initWasmRefType( |
| 3191 |
wasm::MaybeRefType(wasm::RefType::fromTypeDef(typeDef_, false))); |
| 3192 |
} |
| 3193 |
|
| 3194 |
public: |
| 3195 |
INSTRUCTION_HEADER(WasmNewArrayObject) |
| 3196 |
TRIVIAL_NEW_WRAPPERS |
| 3197 |
NAMED_OPERANDS((0, instance), (1, numElements), (2, allocSite)) |
| 3198 |
|
| 3199 |
AliasSet getAliasSet() const override { |
| 3200 |
if (js::SupportDifferentialTesting()) { |
| 3201 |
// Consider allocations effectful for differential testing. |
| 3202 |
return MDefinition::getAliasSet(); |
| 3203 |
} |
| 3204 |
return AliasSet::None(); |
| 3205 |
} |
| 3206 |
const wasm::TypeDef& typeDef() { return *typeDef_; } |
| 3207 |
const wasm::ArrayType& arrayType() const { return typeDef_->arrayType(); } |
| 3208 |
uint32_t elemSize() const { |
| 3209 |
return typeDef_->arrayType().elementType().size(); |
| 3210 |
} |
| 3211 |
bool zeroFields() const { return zeroFields_; } |
| 3212 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 3213 |
}; |
| 3214 |
|
| 3215 |
#undef INSTRUCTION_HEADER |
| 3216 |
|
| 3217 |
#ifdef ENABLE_WASM_SIMD |
| 3218 |
MWasmShuffleSimd128* BuildWasmShuffleSimd128(TempAllocator& alloc, |
| 3219 |
const int8_t* control, |
| 3220 |
MDefinition* lhs, |
| 3221 |
MDefinition* rhs); |
| 3222 |
#endif // ENABLE_WASM_SIMD |
| 3223 |
|
| 3224 |
} // namespace jit |
| 3225 |
} // namespace js |
| 3226 |
|
| 3227 |
#endif /* jit_MIR_wasm_h */ |