| 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_h |
| 13 |
#define jit_MIR_h |
| 14 |
|
| 15 |
#include "mozilla/Array.h" |
| 16 |
#include "mozilla/EnumSet.h" |
| 17 |
#include "mozilla/HashFunctions.h" |
| 18 |
#ifdef JS_JITSPEW |
| 19 |
# include "mozilla/Attributes.h" // MOZ_STACK_CLASS |
| 20 |
#endif |
| 21 |
#include "mozilla/MacroForEach.h" |
| 22 |
#ifdef JS_JITSPEW |
| 23 |
# include "mozilla/Sprintf.h" |
| 24 |
# include "mozilla/Vector.h" |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <algorithm> |
| 28 |
#include <initializer_list> |
| 29 |
|
| 30 |
#include "NamespaceImports.h" |
| 31 |
|
| 32 |
#include "jit/AtomicOp.h" |
| 33 |
#include "jit/FixedList.h" |
| 34 |
#include "jit/InlineList.h" |
| 35 |
#include "jit/JitAllocPolicy.h" |
| 36 |
#include "jit/MacroAssembler.h" |
| 37 |
#include "jit/MIROpsGenerated.h" |
| 38 |
#include "jit/ShuffleAnalysis.h" |
| 39 |
#include "jit/TypeData.h" |
| 40 |
#include "jit/TypePolicy.h" |
| 41 |
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter}Op, JSJitInfo |
| 42 |
#include "js/HeapAPI.h" |
| 43 |
#include "js/ScalarType.h" // js::Scalar::Type |
| 44 |
#include "js/Value.h" |
| 45 |
#include "js/Vector.h" |
| 46 |
#include "vm/BigIntType.h" |
| 47 |
#include "vm/EnvironmentObject.h" |
| 48 |
#include "vm/FunctionFlags.h" // js::FunctionFlags |
| 49 |
#include "vm/JSContext.h" |
| 50 |
#include "vm/RegExpObject.h" |
| 51 |
#include "vm/TypedArrayObject.h" |
| 52 |
#include "wasm/WasmJS.h" // for WasmInstanceObject |
| 53 |
#include "wasm/WasmValType.h" |
| 54 |
|
| 55 |
namespace JS { |
| 56 |
struct ExpandoAndGeneration; |
| 57 |
} |
| 58 |
|
| 59 |
namespace js { |
| 60 |
|
| 61 |
namespace wasm { |
| 62 |
class FuncExport; |
| 63 |
extern uint32_t MIRTypeToABIResultSize(jit::MIRType); |
| 64 |
} // namespace wasm |
| 65 |
|
| 66 |
class JS_PUBLIC_API GenericPrinter; |
| 67 |
class NativeIteratorListHead; |
| 68 |
class StringObject; |
| 69 |
|
| 70 |
enum class UnaryMathFunction : uint8_t; |
| 71 |
|
| 72 |
bool CurrentThreadIsIonCompiling(); |
| 73 |
|
| 74 |
namespace jit { |
| 75 |
|
| 76 |
class CallInfo; |
| 77 |
|
| 78 |
#ifdef JS_JITSPEW |
| 79 |
// Helper for debug printing. Avoids creating a MIR.h <--> MIRGraph.h cycle. |
| 80 |
// Implementation of this needs to see inside `MBasicBlock`; that is possible |
| 81 |
// in MIR.cpp since it also includes MIRGraph.h, whereas this file does not. |
| 82 |
class MBasicBlock; |
| 83 |
uint32_t GetMBasicBlockId(const MBasicBlock* block); |
| 84 |
|
| 85 |
// Helper class for debug printing. This class allows `::getExtras` methods |
| 86 |
// to add strings to be printed, on a per-MIR-node basis. The strings are |
| 87 |
// copied into storage owned by this class when `::add` is called, so the |
| 88 |
// `::getExtras` methods do not need to be concerned about storage management. |
| 89 |
class MOZ_STACK_CLASS ExtrasCollector { |
| 90 |
mozilla::Vector<UniqueChars, 4> strings_; |
| 91 |
|
| 92 |
public: |
| 93 |
// Add `str` to the collection. A copy, owned by this object, is made. In |
| 94 |
// case of OOM the call has no effect. |
| 95 |
void add(const char* str) { |
| 96 |
UniqueChars dup = DuplicateString(str); |
| 97 |
if (dup) { |
| 98 |
(void)strings_.append(std::move(dup)); |
| 99 |
} |
| 100 |
} |
| 101 |
size_t count() const { return strings_.length(); } |
| 102 |
UniqueChars get(size_t ix) { return std::move(strings_[ix]); } |
| 103 |
}; |
| 104 |
#endif |
| 105 |
|
| 106 |
// Forward declarations of MIR types. |
| 107 |
#define FORWARD_DECLARE(op) class M##op; |
| 108 |
MIR_OPCODE_LIST(FORWARD_DECLARE) |
| 109 |
#undef FORWARD_DECLARE |
| 110 |
|
| 111 |
// MDefinition visitor which ignores non-overloaded visit functions. |
| 112 |
class MDefinitionVisitorDefaultNoop { |
| 113 |
public: |
| 114 |
#define VISIT_INS(op) \ |
| 115 |
void visit##op(M##op*) {} |
| 116 |
MIR_OPCODE_LIST(VISIT_INS) |
| 117 |
#undef VISIT_INS |
| 118 |
}; |
| 119 |
|
| 120 |
class BytecodeSite; |
| 121 |
class CompactBufferWriter; |
| 122 |
class Range; |
| 123 |
|
| 124 |
#define MIR_FLAG_LIST(_) \ |
| 125 |
_(InWorklist) \ |
| 126 |
_(EmittedAtUses) \ |
| 127 |
_(Commutative) \ |
| 128 |
_(Movable) /* Allow passes like LICM to move this instruction */ \ |
| 129 |
_(Lowered) /* (Debug only) has a virtual register */ \ |
| 130 |
_(Guard) /* Not removable if uses == 0 */ \ |
| 131 |
\ |
| 132 |
/* Flag an instruction to be considered as a Guard if the instructions \ |
| 133 |
* bails out on some inputs. \ |
| 134 |
* \ |
| 135 |
* Some optimizations can replace an instruction, and leave its operands \ |
| 136 |
* unused. When the type information of the operand got used as a \ |
| 137 |
* predicate of the transformation, then we have to flag the operands as \ |
| 138 |
* GuardRangeBailouts. \ |
| 139 |
* \ |
| 140 |
* This flag prevents further optimization of instructions, which \ |
| 141 |
* might remove the run-time checks (bailout conditions) used as a \ |
| 142 |
* predicate of the previous transformation. \ |
| 143 |
*/ \ |
| 144 |
_(GuardRangeBailouts) \ |
| 145 |
\ |
| 146 |
/* Some instructions have uses that aren't directly represented in the \ |
| 147 |
* graph, and need to be handled specially. As an example, this is used to \ |
| 148 |
* keep the flagged instruction in resume points, not substituting with an \ |
| 149 |
* UndefinedValue. This can be used by call inlining when a function \ |
| 150 |
* argument is not used by the inlined instructions. It is also used \ |
| 151 |
* to annotate instructions which were used in removed branches. \ |
| 152 |
*/ \ |
| 153 |
_(ImplicitlyUsed) \ |
| 154 |
\ |
| 155 |
/* The instruction has been marked dead for lazy removal from resume \ |
| 156 |
* points. \ |
| 157 |
*/ \ |
| 158 |
_(Unused) \ |
| 159 |
\ |
| 160 |
/* Marks if the current instruction should go to the bailout paths instead \ |
| 161 |
* of producing code as part of the control flow. This flag can only be set \ |
| 162 |
* on instructions which are only used by ResumePoint or by other flagged \ |
| 163 |
* instructions. \ |
| 164 |
*/ \ |
| 165 |
_(RecoveredOnBailout) \ |
| 166 |
\ |
| 167 |
/* Some instructions might represent an object, but the memory of these \ |
| 168 |
* objects might be incomplete if we have not recovered all the stores which \ |
| 169 |
* were supposed to happen before. This flag is used to annotate \ |
| 170 |
* instructions which might return a pointer to a memory area which is not \ |
| 171 |
* yet fully initialized. This flag is used to ensure that stores are \ |
| 172 |
* executed before returning the value. \ |
| 173 |
*/ \ |
| 174 |
_(IncompleteObject) \ |
| 175 |
\ |
| 176 |
/* For WebAssembly, there are functions with multiple results. Instead of \ |
| 177 |
* having the results defined by one call instruction, they are instead \ |
| 178 |
* captured in subsequent result capture instructions, because modelling \ |
| 179 |
* multi-value results in Ion is too complicated. However since they \ |
| 180 |
* capture ambient live registers, it would be an error to move an unrelated \ |
| 181 |
* instruction between the call and the result capture. This flag is used \ |
| 182 |
* to prevent code motion from moving instructions in invalid ways. \ |
| 183 |
*/ \ |
| 184 |
_(CallResultCapture) \ |
| 185 |
\ |
| 186 |
/* The current instruction got discarded from the MIR Graph. This is useful \ |
| 187 |
* when we want to iterate over resume points and instructions, while \ |
| 188 |
* handling instructions which are discarded without reporting to the \ |
| 189 |
* iterator. \ |
| 190 |
*/ \ |
| 191 |
_(Discarded) |
| 192 |
|
| 193 |
class MDefinition; |
| 194 |
class MInstruction; |
| 195 |
class MBasicBlock; |
| 196 |
class MNode; |
| 197 |
class MUse; |
| 198 |
class MPhi; |
| 199 |
class MIRGraph; |
| 200 |
class MResumePoint; |
| 201 |
class MControlInstruction; |
| 202 |
|
| 203 |
// Represents a use of a node. |
| 204 |
class MUse : public TempObject, public InlineListNode<MUse> { |
| 205 |
// Grant access to setProducerUnchecked. |
| 206 |
friend class MDefinition; |
| 207 |
friend class MPhi; |
| 208 |
|
| 209 |
MDefinition* producer_; // MDefinition that is being used. |
| 210 |
MNode* consumer_; // The node that is using this operand. |
| 211 |
|
| 212 |
// Low-level unchecked edit method for replaceAllUsesWith and |
| 213 |
// MPhi::removeOperand. This doesn't update use lists! |
| 214 |
// replaceAllUsesWith and MPhi::removeOperand do that manually. |
| 215 |
void setProducerUnchecked(MDefinition* producer) { |
| 216 |
MOZ_ASSERT(consumer_); |
| 217 |
MOZ_ASSERT(producer_); |
| 218 |
MOZ_ASSERT(producer); |
| 219 |
producer_ = producer; |
| 220 |
} |
| 221 |
|
| 222 |
public: |
| 223 |
// Default constructor for use in vectors. |
| 224 |
MUse() : producer_(nullptr), consumer_(nullptr) {} |
| 225 |
|
| 226 |
// Move constructor for use in vectors. When an MUse is moved, it stays |
| 227 |
// in its containing use list. |
| 228 |
MUse(MUse&& other) |
| 229 |
: InlineListNode<MUse>(std::move(other)), |
| 230 |
producer_(other.producer_), |
| 231 |
consumer_(other.consumer_) {} |
| 232 |
|
| 233 |
// Construct an MUse initialized with |producer| and |consumer|. |
| 234 |
MUse(MDefinition* producer, MNode* consumer) { |
| 235 |
initUnchecked(producer, consumer); |
| 236 |
} |
| 237 |
|
| 238 |
// Set this use, which was previously clear. |
| 239 |
inline void init(MDefinition* producer, MNode* consumer); |
| 240 |
// Like init, but works even when the use contains uninitialized data. |
| 241 |
inline void initUnchecked(MDefinition* producer, MNode* consumer); |
| 242 |
// Like initUnchecked, but set the producer to nullptr. |
| 243 |
inline void initUncheckedWithoutProducer(MNode* consumer); |
| 244 |
// Set this use, which was not previously clear. |
| 245 |
inline void replaceProducer(MDefinition* producer); |
| 246 |
// Clear this use. |
| 247 |
inline void releaseProducer(); |
| 248 |
|
| 249 |
MDefinition* producer() const { |
| 250 |
MOZ_ASSERT(producer_ != nullptr); |
| 251 |
return producer_; |
| 252 |
} |
| 253 |
bool hasProducer() const { return producer_ != nullptr; } |
| 254 |
MNode* consumer() const { |
| 255 |
MOZ_ASSERT(consumer_ != nullptr); |
| 256 |
return consumer_; |
| 257 |
} |
| 258 |
|
| 259 |
#ifdef DEBUG |
| 260 |
// Return the operand index of this MUse in its consumer. This is DEBUG-only |
| 261 |
// as normal code should instead call indexOf on the cast consumer directly, |
| 262 |
// to allow it to be devirtualized and inlined. |
| 263 |
size_t index() const; |
| 264 |
#endif |
| 265 |
}; |
| 266 |
|
| 267 |
using MUseIterator = InlineList<MUse>::iterator; |
| 268 |
|
| 269 |
// A node is an entry in the MIR graph. It has two kinds: |
| 270 |
// MInstruction: an instruction which appears in the IR stream. |
| 271 |
// MResumePoint: a list of instructions that correspond to the state of the |
| 272 |
// interpreter/Baseline stack. |
| 273 |
// |
| 274 |
// Nodes can hold references to MDefinitions. Each MDefinition has a list of |
| 275 |
// nodes holding such a reference (its use chain). |
| 276 |
class MNode : public TempObject { |
| 277 |
protected: |
| 278 |
enum class Kind { Definition = 0, ResumePoint }; |
| 279 |
|
| 280 |
private: |
| 281 |
static const uintptr_t KindMask = 0x1; |
| 282 |
uintptr_t blockAndKind_; |
| 283 |
|
| 284 |
Kind kind() const { return Kind(blockAndKind_ & KindMask); } |
| 285 |
|
| 286 |
protected: |
| 287 |
explicit MNode(const MNode& other) : blockAndKind_(other.blockAndKind_) {} |
| 288 |
|
| 289 |
MNode(MBasicBlock* block, Kind kind) { setBlockAndKind(block, kind); } |
| 290 |
|
| 291 |
void setBlockAndKind(MBasicBlock* block, Kind kind) { |
| 292 |
blockAndKind_ = uintptr_t(block) | uintptr_t(kind); |
| 293 |
MOZ_ASSERT(this->block() == block); |
| 294 |
} |
| 295 |
|
| 296 |
MBasicBlock* definitionBlock() const { |
| 297 |
MOZ_ASSERT(isDefinition()); |
| 298 |
static_assert(unsigned(Kind::Definition) == 0, |
| 299 |
"Code below relies on low bit being 0"); |
| 300 |
return reinterpret_cast<MBasicBlock*>(blockAndKind_); |
| 301 |
} |
| 302 |
MBasicBlock* resumePointBlock() const { |
| 303 |
MOZ_ASSERT(isResumePoint()); |
| 304 |
static_assert(unsigned(Kind::ResumePoint) == 1, |
| 305 |
"Code below relies on low bit being 1"); |
| 306 |
// Use a subtraction: if the caller does block()->foo, the compiler |
| 307 |
// will be able to fold it with the load. |
| 308 |
return reinterpret_cast<MBasicBlock*>(blockAndKind_ - 1); |
| 309 |
} |
| 310 |
|
| 311 |
public: |
| 312 |
// Returns the definition at a given operand. |
| 313 |
virtual MDefinition* getOperand(size_t index) const = 0; |
| 314 |
virtual size_t numOperands() const = 0; |
| 315 |
virtual size_t indexOf(const MUse* u) const = 0; |
| 316 |
|
| 317 |
bool isDefinition() const { return kind() == Kind::Definition; } |
| 318 |
bool isResumePoint() const { return kind() == Kind::ResumePoint; } |
| 319 |
MBasicBlock* block() const { |
| 320 |
return reinterpret_cast<MBasicBlock*>(blockAndKind_ & ~KindMask); |
| 321 |
} |
| 322 |
MBasicBlock* caller() const; |
| 323 |
|
| 324 |
// Sets an already set operand, updating use information. If you're looking |
| 325 |
// for setOperand, this is probably what you want. |
| 326 |
virtual void replaceOperand(size_t index, MDefinition* operand) = 0; |
| 327 |
|
| 328 |
// Resets the operand to an uninitialized state, breaking the link |
| 329 |
// with the previous operand's producer. |
| 330 |
void releaseOperand(size_t index) { getUseFor(index)->releaseProducer(); } |
| 331 |
bool hasOperand(size_t index) const { |
| 332 |
return getUseFor(index)->hasProducer(); |
| 333 |
} |
| 334 |
|
| 335 |
inline MDefinition* toDefinition(); |
| 336 |
inline MResumePoint* toResumePoint(); |
| 337 |
|
| 338 |
[[nodiscard]] virtual bool writeRecoverData( |
| 339 |
CompactBufferWriter& writer) const; |
| 340 |
|
| 341 |
#ifdef JS_JITSPEW |
| 342 |
virtual void dump(GenericPrinter& out) const = 0; |
| 343 |
virtual void dump() const = 0; |
| 344 |
#endif |
| 345 |
|
| 346 |
protected: |
| 347 |
// Need visibility on getUseFor to avoid O(n^2) complexity. |
| 348 |
friend void AssertBasicGraphCoherency(MIRGraph& graph, bool force); |
| 349 |
|
| 350 |
// Gets the MUse corresponding to given operand. |
| 351 |
virtual MUse* getUseFor(size_t index) = 0; |
| 352 |
virtual const MUse* getUseFor(size_t index) const = 0; |
| 353 |
}; |
| 354 |
|
| 355 |
class AliasSet { |
| 356 |
private: |
| 357 |
uint32_t flags_; |
| 358 |
|
| 359 |
public: |
| 360 |
enum Flag { |
| 361 |
None_ = 0, |
| 362 |
ObjectFields = 1 << 0, // shape, class, slots, length etc. |
| 363 |
Element = 1 << 1, // A Value member of obj->elements or |
| 364 |
// a typed object. |
| 365 |
UnboxedElement = 1 << 2, // An unboxed scalar or reference member of |
| 366 |
// typed object. |
| 367 |
DynamicSlot = 1 << 3, // A Value member of obj->slots. |
| 368 |
FixedSlot = 1 << 4, // A Value member of obj->fixedSlots(). |
| 369 |
DOMProperty = 1 << 5, // A DOM property |
| 370 |
WasmInstanceData = 1 << 6, // An asm.js/wasm private global var |
| 371 |
WasmHeap = 1 << 7, // An asm.js/wasm heap load |
| 372 |
WasmHeapMeta = 1 << 8, // The asm.js/wasm heap base pointer and |
| 373 |
// bounds check limit, in Instance. |
| 374 |
ArrayBufferViewLengthOrOffset = |
| 375 |
1 << 9, // An array buffer view's length or byteOffset |
| 376 |
WasmGlobalCell = 1 << 10, // A wasm global cell |
| 377 |
WasmTableElement = 1 << 11, // An element of a wasm table |
| 378 |
WasmTableMeta = 1 << 12, // A wasm table elements pointer and |
| 379 |
// length field, in instance data. |
| 380 |
WasmStackResult = 1 << 13, // A stack result from the current function |
| 381 |
|
| 382 |
// JSContext's exception state. This is used on instructions like MThrow |
| 383 |
// or MNewArrayDynamicLength that throw exceptions (other than OOM) but have |
| 384 |
// no other side effect, to ensure that they get their own up-to-date resume |
| 385 |
// point. (This resume point will be used when constructing the Baseline |
| 386 |
// frame during exception bailouts.) |
| 387 |
ExceptionState = 1 << 14, |
| 388 |
|
| 389 |
// Used for instructions that load the privateSlot of DOM proxies and |
| 390 |
// the ExpandoAndGeneration. |
| 391 |
DOMProxyExpando = 1 << 15, |
| 392 |
|
| 393 |
// Hash table of a Map or Set object. |
| 394 |
MapOrSetHashTable = 1 << 16, |
| 395 |
|
| 396 |
// Internal state of the random number generator |
| 397 |
RNG = 1 << 17, |
| 398 |
|
| 399 |
// The pendingException slot on the wasm instance object. |
| 400 |
WasmPendingException = 1 << 18, |
| 401 |
|
| 402 |
// The fuzzilliHash slot |
| 403 |
FuzzilliHash = 1 << 19, |
| 404 |
|
| 405 |
// The WasmStructObject::inlineData_[..] storage area |
| 406 |
WasmStructInlineDataArea = 1 << 20, |
| 407 |
|
| 408 |
// The WasmStructObject::outlineData_ pointer only |
| 409 |
WasmStructOutlineDataPointer = 1 << 21, |
| 410 |
|
| 411 |
// The malloc'd block that WasmStructObject::outlineData_ points at |
| 412 |
WasmStructOutlineDataArea = 1 << 22, |
| 413 |
|
| 414 |
// The WasmArrayObject::numElements_ field |
| 415 |
WasmArrayNumElements = 1 << 23, |
| 416 |
|
| 417 |
// The WasmArrayObject::data_ pointer only |
| 418 |
WasmArrayDataPointer = 1 << 24, |
| 419 |
|
| 420 |
// The malloc'd block that WasmArrayObject::data_ points at |
| 421 |
WasmArrayDataArea = 1 << 25, |
| 422 |
|
| 423 |
// The generation counter associated with the global object |
| 424 |
GlobalGenerationCounter = 1 << 26, |
| 425 |
|
| 426 |
// The SharedArrayRawBuffer::length field. |
| 427 |
SharedArrayRawBufferLength = 1 << 27, |
| 428 |
|
| 429 |
Last = SharedArrayRawBufferLength, |
| 430 |
|
| 431 |
Any = Last | (Last - 1), |
| 432 |
NumCategories = 28, |
| 433 |
|
| 434 |
// Indicates load or store. |
| 435 |
Store_ = 1 << 31 |
| 436 |
}; |
| 437 |
|
| 438 |
static_assert((1 << NumCategories) - 1 == Any, |
| 439 |
"NumCategories must include all flags present in Any"); |
| 440 |
|
| 441 |
explicit AliasSet(uint32_t flags) : flags_(flags) {} |
| 442 |
|
| 443 |
public: |
| 444 |
inline bool isNone() const { return flags_ == None_; } |
| 445 |
uint32_t flags() const { return flags_ & Any; } |
| 446 |
inline bool isStore() const { return !!(flags_ & Store_); } |
| 447 |
inline bool isLoad() const { return !isStore() && !isNone(); } |
| 448 |
inline AliasSet operator|(const AliasSet& other) const { |
| 449 |
return AliasSet(flags_ | other.flags_); |
| 450 |
} |
| 451 |
inline AliasSet operator&(const AliasSet& other) const { |
| 452 |
return AliasSet(flags_ & other.flags_); |
| 453 |
} |
| 454 |
inline AliasSet operator~() const { return AliasSet(~flags_); } |
| 455 |
static AliasSet None() { return AliasSet(None_); } |
| 456 |
static AliasSet Load(uint32_t flags) { |
| 457 |
MOZ_ASSERT(flags && !(flags & Store_)); |
| 458 |
return AliasSet(flags); |
| 459 |
} |
| 460 |
static AliasSet Store(uint32_t flags) { |
| 461 |
MOZ_ASSERT(flags && !(flags & Store_)); |
| 462 |
return AliasSet(flags | Store_); |
| 463 |
} |
| 464 |
}; |
| 465 |
|
| 466 |
using MDefinitionVector = Vector<MDefinition*, 6, JitAllocPolicy>; |
| 467 |
using MInstructionVector = Vector<MInstruction*, 6, JitAllocPolicy>; |
| 468 |
|
| 469 |
// When a floating-point value is used by nodes which would prefer to |
| 470 |
// receive integer inputs, we may be able to help by computing our result |
| 471 |
// into an integer directly. |
| 472 |
// |
| 473 |
// A value can be truncated in 4 differents ways: |
| 474 |
// 1. Ignore Infinities (x / 0 --> 0). |
| 475 |
// 2. Ignore overflow (INT_MIN / -1 == (INT_MAX + 1) --> INT_MIN) |
| 476 |
// 3. Ignore negative zeros. (-0 --> 0) |
| 477 |
// 4. Ignore remainder. (3 / 4 --> 0) |
| 478 |
// |
| 479 |
// Indirect truncation is used to represent that we are interested in the |
| 480 |
// truncated result, but only if it can safely flow into operations which |
| 481 |
// are computed modulo 2^32, such as (2) and (3). Infinities are not safe, |
| 482 |
// as they would have absorbed other math operations. Remainders are not |
| 483 |
// safe, as fractions can be scaled up by multiplication. |
| 484 |
// |
| 485 |
// Division is a particularly interesting node here because it covers all 4 |
| 486 |
// cases even when its own operands are integers. |
| 487 |
// |
| 488 |
// Note that these enum values are ordered from least value-modifying to |
| 489 |
// most value-modifying, and code relies on this ordering. |
| 490 |
enum class TruncateKind { |
| 491 |
// No correction. |
| 492 |
NoTruncate = 0, |
| 493 |
// An integer is desired, but we can't skip bailout checks. |
| 494 |
TruncateAfterBailouts = 1, |
| 495 |
// The value will be truncated after some arithmetic (see above). |
| 496 |
IndirectTruncate = 2, |
| 497 |
// Direct and infallible truncation to int32. |
| 498 |
Truncate = 3 |
| 499 |
}; |
| 500 |
|
| 501 |
// An MDefinition is an SSA name. |
| 502 |
class MDefinition : public MNode { |
| 503 |
friend class MBasicBlock; |
| 504 |
|
| 505 |
public: |
| 506 |
enum class Opcode : uint16_t { |
| 507 |
#define DEFINE_OPCODES(op) op, |
| 508 |
MIR_OPCODE_LIST(DEFINE_OPCODES) |
| 509 |
#undef DEFINE_OPCODES |
| 510 |
}; |
| 511 |
|
| 512 |
private: |
| 513 |
InlineList<MUse> uses_; // Use chain. |
| 514 |
uint32_t id_; // Instruction ID, which after block re-ordering |
| 515 |
// is sorted within a basic block. |
| 516 |
Opcode op_; // Opcode. |
| 517 |
uint16_t flags_; // Bit flags. |
| 518 |
Range* range_; // Any computed range for this def. |
| 519 |
union { |
| 520 |
MDefinition* |
| 521 |
loadDependency_; // Implicit dependency (store, call, etc.) of this |
| 522 |
// instruction. Used by alias analysis, GVN and LICM. |
| 523 |
uint32_t virtualRegister_; // Used by lowering to map definitions to |
| 524 |
// virtual registers. |
| 525 |
}; |
| 526 |
|
| 527 |
// Track bailouts by storing the current pc in MIR instruction. Also used |
| 528 |
// for profiling and keeping track of what the last known pc was. |
| 529 |
const BytecodeSite* trackedSite_; |
| 530 |
|
| 531 |
// For nodes of MIRType::WasmAnyRef, a type precisely describing the value of |
| 532 |
// the node. It is set by the "Track wasm ref types" pass in Ion, and enables |
| 533 |
// GVN and LICM to perform more advanced optimizations (such as allowing |
| 534 |
// instructions to move if the source values are non-null, or omitting casts |
| 535 |
// that are statically known to succeed or fail). |
| 536 |
wasm::MaybeRefType wasmRefType_; |
| 537 |
|
| 538 |
// If we generate a bailout path for this instruction, this is the |
| 539 |
// bailout kind that will be encoded in the snapshot. When we bail out, |
| 540 |
// FinishBailoutToBaseline may take action based on the bailout kind to |
| 541 |
// prevent bailout loops. (For example, if an instruction bails out after |
| 542 |
// being hoisted by LICM, we will disable LICM when recompiling the script.) |
| 543 |
BailoutKind bailoutKind_; |
| 544 |
|
| 545 |
MIRType resultType_; // Representation of result type. |
| 546 |
|
| 547 |
private: |
| 548 |
enum Flag { |
| 549 |
None = 0, |
| 550 |
#define DEFINE_FLAG(flag) flag, |
| 551 |
MIR_FLAG_LIST(DEFINE_FLAG) |
| 552 |
#undef DEFINE_FLAG |
| 553 |
Total |
| 554 |
}; |
| 555 |
|
| 556 |
bool hasFlags(uint32_t flags) const { return (flags_ & flags) == flags; } |
| 557 |
void removeFlags(uint32_t flags) { flags_ &= ~flags; } |
| 558 |
void setFlags(uint32_t flags) { flags_ |= flags; } |
| 559 |
|
| 560 |
// Calling isDefinition or isResumePoint on MDefinition is unnecessary. |
| 561 |
bool isDefinition() const = delete; |
| 562 |
bool isResumePoint() const = delete; |
| 563 |
|
| 564 |
protected: |
| 565 |
void setInstructionBlock(MBasicBlock* block, const BytecodeSite* site) { |
| 566 |
MOZ_ASSERT(isInstruction()); |
| 567 |
setBlockAndKind(block, Kind::Definition); |
| 568 |
setTrackedSite(site); |
| 569 |
} |
| 570 |
|
| 571 |
void setPhiBlock(MBasicBlock* block) { |
| 572 |
MOZ_ASSERT(isPhi()); |
| 573 |
setBlockAndKind(block, Kind::Definition); |
| 574 |
} |
| 575 |
|
| 576 |
static HashNumber addU32ToHash(HashNumber hash, uint32_t data) { |
| 577 |
return data + (hash << 6) + (hash << 16) - hash; |
| 578 |
} |
| 579 |
|
| 580 |
static HashNumber addU64ToHash(HashNumber hash, uint64_t data) { |
| 581 |
hash = addU32ToHash(hash, uint32_t(data)); |
| 582 |
hash = addU32ToHash(hash, uint32_t(data >> 32)); |
| 583 |
return hash; |
| 584 |
} |
| 585 |
|
| 586 |
public: |
| 587 |
explicit MDefinition(Opcode op) |
| 588 |
: MNode(nullptr, Kind::Definition), |
| 589 |
id_(0), |
| 590 |
op_(op), |
| 591 |
flags_(0), |
| 592 |
range_(nullptr), |
| 593 |
loadDependency_(nullptr), |
| 594 |
trackedSite_(nullptr), |
| 595 |
bailoutKind_(BailoutKind::Unknown), |
| 596 |
resultType_(MIRType::None) {} |
| 597 |
|
| 598 |
// Copying a definition leaves the list of uses empty. |
| 599 |
explicit MDefinition(const MDefinition& other) |
| 600 |
: MNode(other), |
| 601 |
id_(0), |
| 602 |
op_(other.op_), |
| 603 |
flags_(other.flags_), |
| 604 |
range_(other.range_), |
| 605 |
loadDependency_(other.loadDependency_), |
| 606 |
trackedSite_(other.trackedSite_), |
| 607 |
bailoutKind_(other.bailoutKind_), |
| 608 |
resultType_(other.resultType_) {} |
| 609 |
|
| 610 |
Opcode op() const { return op_; } |
| 611 |
|
| 612 |
#ifdef JS_JITSPEW |
| 613 |
const char* opName() const; |
| 614 |
void printName(GenericPrinter& out) const; |
| 615 |
static void PrintOpcodeName(GenericPrinter& out, Opcode op); |
| 616 |
virtual void printOpcode(GenericPrinter& out) const; |
| 617 |
void dump(GenericPrinter& out) const override; |
| 618 |
void dump() const override; |
| 619 |
void dumpLocation(GenericPrinter& out) const; |
| 620 |
void dumpLocation() const; |
| 621 |
// Dump any other stuff the node wants to have printed in `extras`. The |
| 622 |
// added strings are copied, with the `ExtrasCollector` taking ownership of |
| 623 |
// the copies. |
| 624 |
virtual void getExtras(ExtrasCollector* extras) const {} |
| 625 |
#endif |
| 626 |
|
| 627 |
// Also for LICM. Test whether this definition is likely to be a call, which |
| 628 |
// would clobber all or many of the floating-point registers, such that |
| 629 |
// hoisting floating-point constants out of containing loops isn't likely to |
| 630 |
// be worthwhile. |
| 631 |
virtual bool possiblyCalls() const { return false; } |
| 632 |
|
| 633 |
MBasicBlock* block() const { return definitionBlock(); } |
| 634 |
|
| 635 |
private: |
| 636 |
void setTrackedSite(const BytecodeSite* site) { |
| 637 |
MOZ_ASSERT(site); |
| 638 |
trackedSite_ = site; |
| 639 |
} |
| 640 |
|
| 641 |
public: |
| 642 |
const BytecodeSite* trackedSite() const { |
| 643 |
MOZ_ASSERT(trackedSite_, |
| 644 |
"missing tracked bytecode site; node not assigned to a block?"); |
| 645 |
return trackedSite_; |
| 646 |
} |
| 647 |
|
| 648 |
BailoutKind bailoutKind() const { return bailoutKind_; } |
| 649 |
void setBailoutKind(BailoutKind kind) { bailoutKind_ = kind; } |
| 650 |
|
| 651 |
// Return the range of this value, *before* any bailout checks. Contrast |
| 652 |
// this with the type() method, and the Range constructor which takes an |
| 653 |
// MDefinition*, which describe the value *after* any bailout checks. |
| 654 |
// |
| 655 |
// Warning: Range analysis is removing the bit-operations such as '| 0' at |
| 656 |
// the end of the transformations. Using this function to analyse any |
| 657 |
// operands after the truncate phase of the range analysis will lead to |
| 658 |
// errors. Instead, one should define the collectRangeInfoPreTrunc() to set |
| 659 |
// the right set of flags which are dependent on the range of the inputs. |
| 660 |
Range* range() const { |
| 661 |
MOZ_ASSERT(type() != MIRType::None); |
| 662 |
return range_; |
| 663 |
} |
| 664 |
void setRange(Range* range) { |
| 665 |
MOZ_ASSERT(type() != MIRType::None); |
| 666 |
range_ = range; |
| 667 |
} |
| 668 |
|
| 669 |
virtual HashNumber valueHash() const; |
| 670 |
virtual bool congruentTo(const MDefinition* ins) const { return false; } |
| 671 |
const MDefinition* skipObjectGuards() const; |
| 672 |
|
| 673 |
// Note that, for a call `congruentIfOperandsEqual(ins)` inside some class |
| 674 |
// MFoo, if `true` is returned then we are ensured that `ins` is also an |
| 675 |
// MFoo, so it is safe to do `ins->toMFoo()` without first checking whether |
| 676 |
// `ins->isMFoo()`. |
| 677 |
bool congruentIfOperandsEqual(const MDefinition* ins) const; |
| 678 |
|
| 679 |
virtual MDefinition* foldsTo(TempAllocator& alloc); |
| 680 |
virtual void analyzeEdgeCasesForward(); |
| 681 |
virtual void analyzeEdgeCasesBackward(); |
| 682 |
|
| 683 |
// |canTruncate| reports if this instruction supports truncation. If |
| 684 |
// |canTruncate| function returns true, then the |truncate| function is |
| 685 |
// called on the same instruction to mutate the instruction, such as updating |
| 686 |
// the return type, the range and the specialization of the instruction. |
| 687 |
virtual bool canTruncate() const; |
| 688 |
virtual void truncate(TruncateKind kind); |
| 689 |
|
| 690 |
// Determine what kind of truncate this node prefers for the operand at the |
| 691 |
// given index. |
| 692 |
virtual TruncateKind operandTruncateKind(size_t index) const; |
| 693 |
|
| 694 |
// Compute an absolute or symbolic range for the value of this node. |
| 695 |
virtual void computeRange(TempAllocator& alloc) {} |
| 696 |
|
| 697 |
// Collect information from the pre-truncated ranges. |
| 698 |
virtual void collectRangeInfoPreTrunc() {} |
| 699 |
|
| 700 |
uint32_t id() const { |
| 701 |
MOZ_ASSERT(block()); |
| 702 |
return id_; |
| 703 |
} |
| 704 |
void setId(uint32_t id) { id_ = id; } |
| 705 |
|
| 706 |
#define FLAG_ACCESSOR(flag) \ |
| 707 |
bool is##flag() const { \ |
| 708 |
static_assert(Flag::Total <= sizeof(flags_) * 8, \ |
| 709 |
"Flags should fit in flags_ field"); \ |
| 710 |
return hasFlags(1 << flag); \ |
| 711 |
} \ |
| 712 |
void set##flag() { \ |
| 713 |
MOZ_ASSERT(!hasFlags(1 << flag)); \ |
| 714 |
setFlags(1 << flag); \ |
| 715 |
} \ |
| 716 |
void setNot##flag() { \ |
| 717 |
MOZ_ASSERT(hasFlags(1 << flag)); \ |
| 718 |
removeFlags(1 << flag); \ |
| 719 |
} \ |
| 720 |
void set##flag##Unchecked() { setFlags(1 << flag); } \ |
| 721 |
void setNot##flag##Unchecked() { removeFlags(1 << flag); } |
| 722 |
|
| 723 |
MIR_FLAG_LIST(FLAG_ACCESSOR) |
| 724 |
#undef FLAG_ACCESSOR |
| 725 |
|
| 726 |
// Return the type of this value. This may be speculative, and enforced |
| 727 |
// dynamically with the use of bailout checks. If all the bailout checks |
| 728 |
// pass, the value will have this type. |
| 729 |
// |
| 730 |
// Unless this is an MUrsh that has bailouts disabled, which, as a special |
| 731 |
// case, may return a value in (INT32_MAX,UINT32_MAX] even when its type() |
| 732 |
// is MIRType::Int32. |
| 733 |
MIRType type() const { return resultType_; } |
| 734 |
|
| 735 |
// Default EnumSet serialization is based on the enum's underlying type, which |
| 736 |
// means uint8_t for MIRType. To store all possible MIRType values we need at |
| 737 |
// least uint32_t. |
| 738 |
using MIRTypeEnumSet = mozilla::EnumSet<MIRType, uint32_t>; |
| 739 |
static_assert(static_cast<size_t>(MIRType::Last) < |
| 740 |
sizeof(MIRTypeEnumSet::serializedType) * CHAR_BIT); |
| 741 |
|
| 742 |
// Get the wasm reference type stored on the node. Do NOT use in congruentTo, |
| 743 |
// as this value can change throughout the optimization process. See |
| 744 |
// ReplaceAllUsesWith in ValueNumbering.cpp. |
| 745 |
wasm::MaybeRefType wasmRefType() const { return wasmRefType_; } |
| 746 |
|
| 747 |
// Sets the wasm reference type stored on the node. Does not check if there |
| 748 |
// was already a type on the node, which may lead to bugs; consider using |
| 749 |
// `initWasmRefType` instead if it applies. |
| 750 |
void setWasmRefType(wasm::MaybeRefType refType) { wasmRefType_ = refType; } |
| 751 |
|
| 752 |
// Sets the wasm reference type stored on the node. To be used for nodes that |
| 753 |
// have a fixed ref type that is set up front, which is a common case. Must be |
| 754 |
// called only during the node constructor and never again afterward. |
| 755 |
void initWasmRefType(wasm::MaybeRefType refType) { |
| 756 |
MOZ_ASSERT(!wasmRefType_); |
| 757 |
setWasmRefType(refType); |
| 758 |
} |
| 759 |
|
| 760 |
// Compute the wasm reference type for this node. This method is called by |
| 761 |
// updateWasmRefType. By default it returns the ref type stored on the node, |
| 762 |
// which means it will return either Nothing or a value set by |
| 763 |
// initWasmRefType. |
| 764 |
virtual wasm::MaybeRefType computeWasmRefType() const { return wasmRefType_; } |
| 765 |
|
| 766 |
// Return true if the result type is a member of the given types. |
| 767 |
bool typeIsOneOf(MIRTypeEnumSet types) const { |
| 768 |
MOZ_ASSERT(!types.isEmpty()); |
| 769 |
return types.contains(type()); |
| 770 |
} |
| 771 |
|
| 772 |
// Float32 specialization operations (see big comment in IonAnalysis before |
| 773 |
// the Float32 specialization algorithm). |
| 774 |
virtual bool isFloat32Commutative() const { return false; } |
| 775 |
virtual bool canProduceFloat32() const { return false; } |
| 776 |
virtual bool canConsumeFloat32(MUse* use) const { return false; } |
| 777 |
virtual void trySpecializeFloat32(TempAllocator& alloc) {} |
| 778 |
#ifdef DEBUG |
| 779 |
// Used during the pass that checks that Float32 flow into valid MDefinitions |
| 780 |
virtual bool isConsistentFloat32Use(MUse* use) const { |
| 781 |
return type() == MIRType::Float32 || canConsumeFloat32(use); |
| 782 |
} |
| 783 |
#endif |
| 784 |
|
| 785 |
// Returns the beginning of this definition's use chain. |
| 786 |
MUseIterator usesBegin() const { return uses_.begin(); } |
| 787 |
|
| 788 |
// Returns the end of this definition's use chain. |
| 789 |
MUseIterator usesEnd() const { return uses_.end(); } |
| 790 |
|
| 791 |
bool canEmitAtUses() const { return !isEmittedAtUses(); } |
| 792 |
|
| 793 |
// Removes a use at the given position |
| 794 |
void removeUse(MUse* use) { uses_.remove(use); } |
| 795 |
|
| 796 |
#if defined(DEBUG) || defined(JS_JITSPEW) |
| 797 |
// Number of uses of this instruction. This function is only available |
| 798 |
// in DEBUG mode since it requires traversing the list. Most users should |
| 799 |
// use hasUses() or hasOneUse() instead. |
| 800 |
size_t useCount() const; |
| 801 |
|
| 802 |
// Number of uses of this instruction (only counting MDefinitions, ignoring |
| 803 |
// MResumePoints). This function is only available in DEBUG mode since it |
| 804 |
// requires traversing the list. Most users should use hasUses() or |
| 805 |
// hasOneUse() instead. |
| 806 |
size_t defUseCount() const; |
| 807 |
#endif |
| 808 |
|
| 809 |
// Test whether this MDefinition has exactly one use. |
| 810 |
bool hasOneUse() const; |
| 811 |
|
| 812 |
// Test whether this MDefinition has exactly one use. |
| 813 |
// (only counting MDefinitions, ignoring MResumePoints) |
| 814 |
bool hasOneDefUse() const; |
| 815 |
|
| 816 |
// Test whether this MDefinition has exactly one live use. (only counting |
| 817 |
// MDefinitions which are not recovered on bailout and ignoring MResumePoints) |
| 818 |
bool hasOneLiveDefUse() const; |
| 819 |
|
| 820 |
// Test whether this MDefinition has at least one use. |
| 821 |
// (only counting MDefinitions, ignoring MResumePoints) |
| 822 |
bool hasDefUses() const; |
| 823 |
|
| 824 |
// Test whether this MDefinition has at least one non-recovered use. |
| 825 |
// (only counting MDefinitions, ignoring MResumePoints) |
| 826 |
bool hasLiveDefUses() const; |
| 827 |
|
| 828 |
bool hasUses() const { return !uses_.empty(); } |
| 829 |
|
| 830 |
// If this MDefinition has a single use (ignoring MResumePoints), returns that |
| 831 |
// use's definition. Else returns nullptr. |
| 832 |
MDefinition* maybeSingleDefUse() const; |
| 833 |
|
| 834 |
// Returns the most recently added use (ignoring MResumePoints) for this |
| 835 |
// MDefinition. Returns nullptr if there are no uses. Note that this relies on |
| 836 |
// addUse adding new uses to the front of the list, and should only be called |
| 837 |
// during MIR building (before optimization passes make changes to the uses). |
| 838 |
MDefinition* maybeMostRecentlyAddedDefUse() const; |
| 839 |
|
| 840 |
void addUse(MUse* use) { |
| 841 |
MOZ_ASSERT(use->producer() == this); |
| 842 |
uses_.pushFront(use); |
| 843 |
} |
| 844 |
void addUseUnchecked(MUse* use) { |
| 845 |
MOZ_ASSERT(use->producer() == this); |
| 846 |
uses_.pushFrontUnchecked(use); |
| 847 |
} |
| 848 |
void replaceUse(MUse* old, MUse* now) { |
| 849 |
MOZ_ASSERT(now->producer() == this); |
| 850 |
uses_.replace(old, now); |
| 851 |
} |
| 852 |
|
| 853 |
// Replace the current instruction by a dominating instruction |dom| in all |
| 854 |
// uses of the current instruction. |
| 855 |
void replaceAllUsesWith(MDefinition* dom); |
| 856 |
|
| 857 |
// Like replaceAllUsesWith, but doesn't set ImplicitlyUsed on |this|'s |
| 858 |
// operands. |
| 859 |
void justReplaceAllUsesWith(MDefinition* dom); |
| 860 |
|
| 861 |
// Replace the current instruction by an optimized-out constant in all uses |
| 862 |
// of the current instruction. Note, that optimized-out constant should not |
| 863 |
// be observed, and thus they should not flow in any computation. |
| 864 |
[[nodiscard]] bool optimizeOutAllUses(TempAllocator& alloc); |
| 865 |
|
| 866 |
// Replace the current instruction by a dominating instruction |dom| in all |
| 867 |
// instruction, but keep the current instruction for resume point and |
| 868 |
// instruction which are recovered on bailouts. |
| 869 |
void replaceAllLiveUsesWith(MDefinition* dom); |
| 870 |
|
| 871 |
void setVirtualRegister(uint32_t vreg) { |
| 872 |
virtualRegister_ = vreg; |
| 873 |
setLoweredUnchecked(); |
| 874 |
} |
| 875 |
uint32_t virtualRegister() const { |
| 876 |
MOZ_ASSERT(isLowered()); |
| 877 |
return virtualRegister_; |
| 878 |
} |
| 879 |
|
| 880 |
public: |
| 881 |
// Opcode testing and casts. |
| 882 |
template <typename MIRType> |
| 883 |
bool is() const { |
| 884 |
return op() == MIRType::classOpcode; |
| 885 |
} |
| 886 |
template <typename MIRType> |
| 887 |
MIRType* to() { |
| 888 |
MOZ_ASSERT(this->is<MIRType>()); |
| 889 |
return static_cast<MIRType*>(this); |
| 890 |
} |
| 891 |
template <typename MIRType> |
| 892 |
const MIRType* to() const { |
| 893 |
MOZ_ASSERT(this->is<MIRType>()); |
| 894 |
return static_cast<const MIRType*>(this); |
| 895 |
} |
| 896 |
#define OPCODE_CASTS(opcode) \ |
| 897 |
bool is##opcode() const { return this->is<M##opcode>(); } \ |
| 898 |
M##opcode* to##opcode() { return this->to<M##opcode>(); } \ |
| 899 |
const M##opcode* to##opcode() const { return this->to<M##opcode>(); } |
| 900 |
MIR_OPCODE_LIST(OPCODE_CASTS) |
| 901 |
#undef OPCODE_CASTS |
| 902 |
|
| 903 |
inline MConstant* maybeConstantValue(); |
| 904 |
|
| 905 |
inline MInstruction* toInstruction(); |
| 906 |
inline const MInstruction* toInstruction() const; |
| 907 |
bool isInstruction() const { return !isPhi(); } |
| 908 |
|
| 909 |
virtual bool isControlInstruction() const { return false; } |
| 910 |
inline MControlInstruction* toControlInstruction(); |
| 911 |
|
| 912 |
void setResultType(MIRType type) { resultType_ = type; } |
| 913 |
virtual AliasSet getAliasSet() const { |
| 914 |
// Instructions are effectful by default. |
| 915 |
return AliasSet::Store(AliasSet::Any); |
| 916 |
} |
| 917 |
|
| 918 |
#ifdef DEBUG |
| 919 |
bool hasDefaultAliasSet() const { |
| 920 |
AliasSet set = getAliasSet(); |
| 921 |
return set.isStore() && set.flags() == AliasSet::Flag::Any; |
| 922 |
} |
| 923 |
#endif |
| 924 |
|
| 925 |
MDefinition* dependency() const { |
| 926 |
if (getAliasSet().isStore()) { |
| 927 |
return nullptr; |
| 928 |
} |
| 929 |
return loadDependency_; |
| 930 |
} |
| 931 |
void setDependency(MDefinition* dependency) { |
| 932 |
MOZ_ASSERT(!getAliasSet().isStore()); |
| 933 |
loadDependency_ = dependency; |
| 934 |
} |
| 935 |
bool isEffectful() const { return getAliasSet().isStore(); } |
| 936 |
|
| 937 |
#ifdef DEBUG |
| 938 |
bool needsResumePoint() const { |
| 939 |
// Return whether this instruction should have its own resume point. |
| 940 |
return isEffectful(); |
| 941 |
} |
| 942 |
#endif |
| 943 |
|
| 944 |
enum class AliasType : uint32_t { NoAlias = 0, MayAlias = 1, MustAlias = 2 }; |
| 945 |
virtual AliasType mightAlias(const MDefinition* store) const { |
| 946 |
// Return whether this load may depend on the specified store, given |
| 947 |
// that the alias sets intersect. This may be refined to exclude |
| 948 |
// possible aliasing in cases where alias set flags are too imprecise. |
| 949 |
if (!(getAliasSet().flags() & store->getAliasSet().flags())) { |
| 950 |
return AliasType::NoAlias; |
| 951 |
} |
| 952 |
MOZ_ASSERT(!isEffectful() && store->isEffectful()); |
| 953 |
return AliasType::MayAlias; |
| 954 |
} |
| 955 |
|
| 956 |
virtual bool canRecoverOnBailout() const { return false; } |
| 957 |
}; |
| 958 |
|
| 959 |
// An MUseDefIterator walks over uses in a definition, skipping any use that is |
| 960 |
// not a definition. Items from the use list must not be deleted during |
| 961 |
// iteration. |
| 962 |
class MUseDefIterator { |
| 963 |
const MDefinition* def_; |
| 964 |
MUseIterator current_; |
| 965 |
|
| 966 |
MUseIterator search(MUseIterator start) { |
| 967 |
MUseIterator i(start); |
| 968 |
for (; i != def_->usesEnd(); i++) { |
| 969 |
if (i->consumer()->isDefinition()) { |
| 970 |
return i; |
| 971 |
} |
| 972 |
} |
| 973 |
return def_->usesEnd(); |
| 974 |
} |
| 975 |
|
| 976 |
public: |
| 977 |
explicit MUseDefIterator(const MDefinition* def) |
| 978 |
: def_(def), current_(search(def->usesBegin())) {} |
| 979 |
|
| 980 |
explicit operator bool() const { return current_ != def_->usesEnd(); } |
| 981 |
MUseDefIterator operator++() { |
| 982 |
MOZ_ASSERT(current_ != def_->usesEnd()); |
| 983 |
++current_; |
| 984 |
current_ = search(current_); |
| 985 |
return *this; |
| 986 |
} |
| 987 |
MUseDefIterator operator++(int) { |
| 988 |
MUseDefIterator old(*this); |
| 989 |
operator++(); |
| 990 |
return old; |
| 991 |
} |
| 992 |
MUse* use() const { return *current_; } |
| 993 |
MDefinition* def() const { return current_->consumer()->toDefinition(); } |
| 994 |
}; |
| 995 |
|
| 996 |
// Helper class to check that GC pointers embedded in MIR instructions are not |
| 997 |
// in the nursery. Off-thread compilation and nursery GCs can happen in |
| 998 |
// parallel. Nursery pointers are handled with MNurseryObject and the |
| 999 |
// nurseryObjects lists in WarpSnapshot and IonScript. |
| 1000 |
// |
| 1001 |
// These GC things are rooted through the WarpSnapshot. Compacting GCs cancel |
| 1002 |
// off-thread compilations. |
| 1003 |
template <typename T> |
| 1004 |
class CompilerGCPointer { |
| 1005 |
js::gc::Cell* ptr_; |
| 1006 |
|
| 1007 |
public: |
| 1008 |
explicit CompilerGCPointer(T ptr) : ptr_(ptr) { |
| 1009 |
MOZ_ASSERT_IF(ptr, !IsInsideNursery(ptr)); |
| 1010 |
MOZ_ASSERT_IF(!CurrentThreadIsIonCompiling(), TlsContext.get()->suppressGC); |
| 1011 |
} |
| 1012 |
|
| 1013 |
operator T() const { return static_cast<T>(ptr_); } |
| 1014 |
T operator->() const { return static_cast<T>(ptr_); } |
| 1015 |
|
| 1016 |
private: |
| 1017 |
CompilerGCPointer() = delete; |
| 1018 |
CompilerGCPointer(const CompilerGCPointer<T>&) = delete; |
| 1019 |
CompilerGCPointer<T>& operator=(const CompilerGCPointer<T>&) = delete; |
| 1020 |
}; |
| 1021 |
|
| 1022 |
using CompilerObject = CompilerGCPointer<JSObject*>; |
| 1023 |
using CompilerNativeObject = CompilerGCPointer<NativeObject*>; |
| 1024 |
using CompilerFunction = CompilerGCPointer<JSFunction*>; |
| 1025 |
using CompilerBaseScript = CompilerGCPointer<BaseScript*>; |
| 1026 |
using CompilerPropertyName = CompilerGCPointer<PropertyName*>; |
| 1027 |
using CompilerShape = CompilerGCPointer<Shape*>; |
| 1028 |
using CompilerGetterSetter = CompilerGCPointer<GetterSetter*>; |
| 1029 |
|
| 1030 |
// An instruction is an SSA name that is inserted into a basic block's IR |
| 1031 |
// stream. |
| 1032 |
class MInstruction : public MDefinition, public InlineListNode<MInstruction> { |
| 1033 |
MResumePoint* resumePoint_; |
| 1034 |
|
| 1035 |
protected: |
| 1036 |
// All MInstructions are using the "MFoo::New(alloc)" notation instead of |
| 1037 |
// the TempObject new operator. This code redefines the new operator as |
| 1038 |
// protected, and delegates to the TempObject new operator. Thus, the |
| 1039 |
// following code prevents calls to "new(alloc) MFoo" outside the MFoo |
| 1040 |
// members. |
| 1041 |
inline void* operator new(size_t nbytes, |
| 1042 |
TempAllocator::Fallible view) noexcept(true) { |
| 1043 |
return TempObject::operator new(nbytes, view); |
| 1044 |
} |
| 1045 |
inline void* operator new(size_t nbytes, TempAllocator& alloc) { |
| 1046 |
return TempObject::operator new(nbytes, alloc); |
| 1047 |
} |
| 1048 |
template <class T> |
| 1049 |
inline void* operator new(size_t nbytes, T* pos) { |
| 1050 |
return TempObject::operator new(nbytes, pos); |
| 1051 |
} |
| 1052 |
|
| 1053 |
public: |
| 1054 |
explicit MInstruction(Opcode op) : MDefinition(op), resumePoint_(nullptr) {} |
| 1055 |
|
| 1056 |
// Copying an instruction leaves the resume point as empty. |
| 1057 |
explicit MInstruction(const MInstruction& other) |
| 1058 |
: MDefinition(other), resumePoint_(nullptr) {} |
| 1059 |
|
| 1060 |
// Convenient function used for replacing a load by the value of the store |
| 1061 |
// if the types are match, and boxing the value if they do not match. |
| 1062 |
MDefinition* foldsToStore(TempAllocator& alloc); |
| 1063 |
|
| 1064 |
void setResumePoint(MResumePoint* resumePoint); |
| 1065 |
void stealResumePoint(MInstruction* other); |
| 1066 |
|
| 1067 |
void moveResumePointAsEntry(); |
| 1068 |
void clearResumePoint(); |
| 1069 |
MResumePoint* resumePoint() const { return resumePoint_; } |
| 1070 |
|
| 1071 |
// For instructions which can be cloned with new inputs, with all other |
| 1072 |
// information being the same. clone() implementations do not need to worry |
| 1073 |
// about cloning generic MInstruction/MDefinition state like flags and |
| 1074 |
// resume points. |
| 1075 |
virtual bool canClone() const { return false; } |
| 1076 |
virtual MInstruction* clone(TempAllocator& alloc, |
| 1077 |
const MDefinitionVector& inputs) const { |
| 1078 |
MOZ_CRASH(); |
| 1079 |
} |
| 1080 |
|
| 1081 |
// Instructions needing to hook into type analysis should return a |
| 1082 |
// TypePolicy. |
| 1083 |
virtual const TypePolicy* typePolicy() = 0; |
| 1084 |
virtual MIRType typePolicySpecialization() = 0; |
| 1085 |
}; |
| 1086 |
|
| 1087 |
// Note: GenerateOpcodeFiles.py generates MOpcodesGenerated.h based on the |
| 1088 |
// INSTRUCTION_HEADER* macros. |
| 1089 |
#define INSTRUCTION_HEADER_WITHOUT_TYPEPOLICY(opcode) \ |
| 1090 |
static const Opcode classOpcode = Opcode::opcode; \ |
| 1091 |
using MThisOpcode = M##opcode; |
| 1092 |
|
| 1093 |
#define INSTRUCTION_HEADER(opcode) \ |
| 1094 |
INSTRUCTION_HEADER_WITHOUT_TYPEPOLICY(opcode) \ |
| 1095 |
virtual const TypePolicy* typePolicy() override; \ |
| 1096 |
virtual MIRType typePolicySpecialization() override; |
| 1097 |
|
| 1098 |
#define ALLOW_CLONE(typename) \ |
| 1099 |
bool canClone() const override { return true; } \ |
| 1100 |
MInstruction* clone(TempAllocator& alloc, const MDefinitionVector& inputs) \ |
| 1101 |
const override { \ |
| 1102 |
MOZ_ASSERT(numOperands() == inputs.length()); \ |
| 1103 |
MInstruction* res = new (alloc) typename(*this); \ |
| 1104 |
if (!res) { \ |
| 1105 |
return nullptr; \ |
| 1106 |
} \ |
| 1107 |
for (size_t i = 0; i < numOperands(); i++) { \ |
| 1108 |
res->replaceOperand(i, inputs[i]); \ |
| 1109 |
} \ |
| 1110 |
return res; \ |
| 1111 |
} |
| 1112 |
|
| 1113 |
// Adds MFoo::New functions which are mirroring the arguments of the |
| 1114 |
// constructors. Opcodes which are using this macro can be called with a |
| 1115 |
// TempAllocator, or the fallible version of the TempAllocator. |
| 1116 |
#define TRIVIAL_NEW_WRAPPERS \ |
| 1117 |
template <typename... Args> \ |
| 1118 |
static MThisOpcode* New(TempAllocator& alloc, Args&&... args) { \ |
| 1119 |
return new (alloc) MThisOpcode(std::forward<Args>(args)...); \ |
| 1120 |
} \ |
| 1121 |
template <typename... Args> \ |
| 1122 |
static MThisOpcode* New(TempAllocator::Fallible alloc, Args&&... args) { \ |
| 1123 |
return new (alloc) MThisOpcode(std::forward<Args>(args)...); \ |
| 1124 |
} |
| 1125 |
|
| 1126 |
// These macros are used as a syntactic sugar for writting getOperand |
| 1127 |
// accessors. They are meant to be used in the body of MIR Instructions as |
| 1128 |
// follows: |
| 1129 |
// |
| 1130 |
// public: |
| 1131 |
// INSTRUCTION_HEADER(Foo) |
| 1132 |
// NAMED_OPERANDS((0, lhs), (1, rhs)) |
| 1133 |
// |
| 1134 |
// The above example defines 2 accessors, one named "lhs" accessing the first |
| 1135 |
// operand, and a one named "rhs" accessing the second operand. It also defines |
| 1136 |
// the operand indices as |lhsOperand| and |rhsOperand|. |
| 1137 |
#define NAMED_OPERAND_ACCESSOR(Index, Name) \ |
| 1138 |
static constexpr size_t Name##Operand = Index; \ |
| 1139 |
MDefinition* Name() const { return getOperand(Index); } |
| 1140 |
#define NAMED_OPERAND_ACCESSOR_APPLY(Args) NAMED_OPERAND_ACCESSOR Args |
| 1141 |
#define NAMED_OPERANDS(...) \ |
| 1142 |
MOZ_FOR_EACH(NAMED_OPERAND_ACCESSOR_APPLY, (), (__VA_ARGS__)) |
| 1143 |
|
| 1144 |
template <size_t Arity> |
| 1145 |
class MAryInstruction : public MInstruction { |
| 1146 |
mozilla::Array<MUse, Arity> operands_; |
| 1147 |
|
| 1148 |
protected: |
| 1149 |
MUse* getUseFor(size_t index) final { return &operands_[index]; } |
| 1150 |
const MUse* getUseFor(size_t index) const final { return &operands_[index]; } |
| 1151 |
void initOperand(size_t index, MDefinition* operand) { |
| 1152 |
operands_[index].init(operand, this); |
| 1153 |
} |
| 1154 |
|
| 1155 |
public: |
| 1156 |
MDefinition* getOperand(size_t index) const final { |
| 1157 |
return operands_[index].producer(); |
| 1158 |
} |
| 1159 |
size_t numOperands() const final { return Arity; } |
| 1160 |
#ifdef DEBUG |
| 1161 |
static const size_t staticNumOperands = Arity; |
| 1162 |
#endif |
| 1163 |
size_t indexOf(const MUse* u) const final { |
| 1164 |
MOZ_ASSERT(u >= &operands_[0]); |
| 1165 |
MOZ_ASSERT(u <= &operands_[numOperands() - 1]); |
| 1166 |
return u - &operands_[0]; |
| 1167 |
} |
| 1168 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 1169 |
operands_[index].replaceProducer(operand); |
| 1170 |
} |
| 1171 |
|
| 1172 |
explicit MAryInstruction(Opcode op) : MInstruction(op) {} |
| 1173 |
|
| 1174 |
explicit MAryInstruction(const MAryInstruction<Arity>& other) |
| 1175 |
: MInstruction(other) { |
| 1176 |
for (int i = 0; i < (int)Arity; |
| 1177 |
i++) { // N.B. use |int| to avoid warnings when Arity == 0 |
| 1178 |
operands_[i].init(other.operands_[i].producer(), this); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
}; |
| 1182 |
|
| 1183 |
class MNullaryInstruction : public MAryInstruction<0>, |
| 1184 |
public NoTypePolicy::Data { |
| 1185 |
protected: |
| 1186 |
explicit MNullaryInstruction(Opcode op) : MAryInstruction(op) {} |
| 1187 |
|
| 1188 |
HashNumber valueHash() const override; |
| 1189 |
}; |
| 1190 |
|
| 1191 |
class MUnaryInstruction : public MAryInstruction<1> { |
| 1192 |
protected: |
| 1193 |
MUnaryInstruction(Opcode op, MDefinition* ins) : MAryInstruction(op) { |
| 1194 |
initOperand(0, ins); |
| 1195 |
} |
| 1196 |
|
| 1197 |
HashNumber valueHash() const override; |
| 1198 |
|
| 1199 |
public: |
| 1200 |
NAMED_OPERANDS((0, input)) |
| 1201 |
}; |
| 1202 |
|
| 1203 |
class MBinaryInstruction : public MAryInstruction<2> { |
| 1204 |
protected: |
| 1205 |
MBinaryInstruction(Opcode op, MDefinition* left, MDefinition* right) |
| 1206 |
: MAryInstruction(op) { |
| 1207 |
initOperand(0, left); |
| 1208 |
initOperand(1, right); |
| 1209 |
} |
| 1210 |
|
| 1211 |
public: |
| 1212 |
NAMED_OPERANDS((0, lhs), (1, rhs)) |
| 1213 |
|
| 1214 |
protected: |
| 1215 |
HashNumber valueHash() const override; |
| 1216 |
|
| 1217 |
bool binaryCongruentTo(const MDefinition* ins) const { |
| 1218 |
if (op() != ins->op()) { |
| 1219 |
return false; |
| 1220 |
} |
| 1221 |
|
| 1222 |
if (type() != ins->type()) { |
| 1223 |
return false; |
| 1224 |
} |
| 1225 |
|
| 1226 |
if (isEffectful() || ins->isEffectful()) { |
| 1227 |
return false; |
| 1228 |
} |
| 1229 |
|
| 1230 |
const MDefinition* left = getOperand(0); |
| 1231 |
const MDefinition* right = getOperand(1); |
| 1232 |
if (isCommutative() && left->id() > right->id()) { |
| 1233 |
std::swap(left, right); |
| 1234 |
} |
| 1235 |
|
| 1236 |
const MBinaryInstruction* bi = static_cast<const MBinaryInstruction*>(ins); |
| 1237 |
const MDefinition* insLeft = bi->getOperand(0); |
| 1238 |
const MDefinition* insRight = bi->getOperand(1); |
| 1239 |
if (bi->isCommutative() && insLeft->id() > insRight->id()) { |
| 1240 |
std::swap(insLeft, insRight); |
| 1241 |
} |
| 1242 |
|
| 1243 |
return left == insLeft && right == insRight; |
| 1244 |
} |
| 1245 |
|
| 1246 |
public: |
| 1247 |
// Return if the operands to this instruction are both unsigned. |
| 1248 |
static bool unsignedOperands(MDefinition* left, MDefinition* right); |
| 1249 |
bool unsignedOperands(); |
| 1250 |
|
| 1251 |
// Replace any wrapping operands with the underlying int32 operands |
| 1252 |
// in case of unsigned operands. |
| 1253 |
void replaceWithUnsignedOperands(); |
| 1254 |
}; |
| 1255 |
|
| 1256 |
class MTernaryInstruction : public MAryInstruction<3> { |
| 1257 |
protected: |
| 1258 |
MTernaryInstruction(Opcode op, MDefinition* first, MDefinition* second, |
| 1259 |
MDefinition* third) |
| 1260 |
: MAryInstruction(op) { |
| 1261 |
initOperand(0, first); |
| 1262 |
initOperand(1, second); |
| 1263 |
initOperand(2, third); |
| 1264 |
} |
| 1265 |
|
| 1266 |
HashNumber valueHash() const override; |
| 1267 |
}; |
| 1268 |
|
| 1269 |
class MQuaternaryInstruction : public MAryInstruction<4> { |
| 1270 |
protected: |
| 1271 |
MQuaternaryInstruction(Opcode op, MDefinition* first, MDefinition* second, |
| 1272 |
MDefinition* third, MDefinition* fourth) |
| 1273 |
: MAryInstruction(op) { |
| 1274 |
initOperand(0, first); |
| 1275 |
initOperand(1, second); |
| 1276 |
initOperand(2, third); |
| 1277 |
initOperand(3, fourth); |
| 1278 |
} |
| 1279 |
|
| 1280 |
HashNumber valueHash() const override; |
| 1281 |
}; |
| 1282 |
|
| 1283 |
template <class T> |
| 1284 |
class MVariadicT : public T { |
| 1285 |
FixedList<MUse> operands_; |
| 1286 |
|
| 1287 |
protected: |
| 1288 |
explicit MVariadicT(typename T::Opcode op) : T(op) {} |
| 1289 |
[[nodiscard]] bool init(TempAllocator& alloc, size_t length) { |
| 1290 |
return operands_.init(alloc, length); |
| 1291 |
} |
| 1292 |
void initOperand(size_t index, MDefinition* operand) { |
| 1293 |
// FixedList doesn't initialize its elements, so do an unchecked init. |
| 1294 |
operands_[index].initUnchecked(operand, this); |
| 1295 |
} |
| 1296 |
MUse* getUseFor(size_t index) final { return &operands_[index]; } |
| 1297 |
const MUse* getUseFor(size_t index) const final { return &operands_[index]; } |
| 1298 |
|
| 1299 |
// The MWasmCallBase mixin performs initialization for it's subclasses. |
| 1300 |
friend class MWasmCallBase; |
| 1301 |
|
| 1302 |
public: |
| 1303 |
// Will assert if called before initialization. |
| 1304 |
MDefinition* getOperand(size_t index) const final { |
| 1305 |
return operands_[index].producer(); |
| 1306 |
} |
| 1307 |
size_t numOperands() const final { return operands_.length(); } |
| 1308 |
size_t indexOf(const MUse* u) const final { |
| 1309 |
MOZ_ASSERT(u >= &operands_[0]); |
| 1310 |
MOZ_ASSERT(u <= &operands_[numOperands() - 1]); |
| 1311 |
return u - &operands_[0]; |
| 1312 |
} |
| 1313 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 1314 |
operands_[index].replaceProducer(operand); |
| 1315 |
} |
| 1316 |
}; |
| 1317 |
|
| 1318 |
// An instruction with a variable number of operands. Note that the |
| 1319 |
// MFoo::New constructor for variadic instructions fallibly |
| 1320 |
// initializes the operands_ array and must be checked for OOM. |
| 1321 |
using MVariadicInstruction = MVariadicT<MInstruction>; |
| 1322 |
|
| 1323 |
// All barriered operations: |
| 1324 |
// - MCompareExchangeTypedArrayElement |
| 1325 |
// - MExchangeTypedArrayElement |
| 1326 |
// - MAtomicTypedArrayElementBinop |
| 1327 |
// - MGrowableSharedArrayBufferByteLength |
| 1328 |
// |
| 1329 |
// And operations which are optionally barriered: |
| 1330 |
// - MLoadUnboxedScalar |
| 1331 |
// - MStoreUnboxedScalar |
| 1332 |
// - MResizableTypedArrayLength |
| 1333 |
// - MResizableDataViewByteLength |
| 1334 |
// |
| 1335 |
// Must have the following attributes: |
| 1336 |
// |
| 1337 |
// - Not movable |
| 1338 |
// - Not removable |
| 1339 |
// - Not congruent with any other instruction |
| 1340 |
// - Effectful (they alias every TypedArray store) |
| 1341 |
// |
| 1342 |
// The intended effect of those constraints is to prevent all loads and stores |
| 1343 |
// preceding the barriered operation from being moved to after the barriered |
| 1344 |
// operation, and vice versa, and to prevent the barriered operation from being |
| 1345 |
// removed or hoisted. |
| 1346 |
|
| 1347 |
enum class MemoryBarrierRequirement : bool { |
| 1348 |
NotRequired, |
| 1349 |
Required, |
| 1350 |
}; |
| 1351 |
|
| 1352 |
MIR_OPCODE_CLASS_GENERATED |
| 1353 |
|
| 1354 |
// Truncation barrier. This is intended for protecting its input against |
| 1355 |
// follow-up truncation optimizations. |
| 1356 |
class MLimitedTruncate : public MUnaryInstruction, |
| 1357 |
public ConvertToInt32Policy<0>::Data { |
| 1358 |
TruncateKind truncate_; |
| 1359 |
TruncateKind truncateLimit_; |
| 1360 |
|
| 1361 |
MLimitedTruncate(MDefinition* input, TruncateKind limit) |
| 1362 |
: MUnaryInstruction(classOpcode, input), |
| 1363 |
truncate_(TruncateKind::NoTruncate), |
| 1364 |
truncateLimit_(limit) { |
| 1365 |
setResultType(MIRType::Int32); |
| 1366 |
setMovable(); |
| 1367 |
} |
| 1368 |
|
| 1369 |
public: |
| 1370 |
INSTRUCTION_HEADER(LimitedTruncate) |
| 1371 |
TRIVIAL_NEW_WRAPPERS |
| 1372 |
|
| 1373 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1374 |
|
| 1375 |
void computeRange(TempAllocator& alloc) override; |
| 1376 |
bool canTruncate() const override; |
| 1377 |
void truncate(TruncateKind kind) override; |
| 1378 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 1379 |
TruncateKind truncateKind() const { return truncate_; } |
| 1380 |
void setTruncateKind(TruncateKind kind) { truncate_ = kind; } |
| 1381 |
}; |
| 1382 |
|
| 1383 |
// Truncation barrier. This is intended for protecting its input against |
| 1384 |
// follow-up truncation optimizations. |
| 1385 |
class MIntPtrLimitedTruncate : public MUnaryInstruction, |
| 1386 |
public NoTypePolicy::Data { |
| 1387 |
explicit MIntPtrLimitedTruncate(MDefinition* input) |
| 1388 |
: MUnaryInstruction(classOpcode, input) { |
| 1389 |
MOZ_ASSERT(input->type() == MIRType::IntPtr); |
| 1390 |
setResultType(MIRType::IntPtr); |
| 1391 |
setMovable(); |
| 1392 |
} |
| 1393 |
|
| 1394 |
public: |
| 1395 |
INSTRUCTION_HEADER(IntPtrLimitedTruncate) |
| 1396 |
TRIVIAL_NEW_WRAPPERS |
| 1397 |
|
| 1398 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1399 |
}; |
| 1400 |
|
| 1401 |
// Truncation barrier. This is intended for protecting its input against |
| 1402 |
// follow-up truncation optimizations. |
| 1403 |
class MInt64LimitedTruncate : public MUnaryInstruction, |
| 1404 |
public NoTypePolicy::Data { |
| 1405 |
explicit MInt64LimitedTruncate(MDefinition* input) |
| 1406 |
: MUnaryInstruction(classOpcode, input) { |
| 1407 |
MOZ_ASSERT(input->type() == MIRType::Int64); |
| 1408 |
setResultType(MIRType::Int64); |
| 1409 |
setMovable(); |
| 1410 |
} |
| 1411 |
|
| 1412 |
public: |
| 1413 |
INSTRUCTION_HEADER(Int64LimitedTruncate) |
| 1414 |
TRIVIAL_NEW_WRAPPERS |
| 1415 |
|
| 1416 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1417 |
}; |
| 1418 |
|
| 1419 |
// A constant js::Value. |
| 1420 |
class MConstant : public MNullaryInstruction { |
| 1421 |
struct Payload { |
| 1422 |
union { |
| 1423 |
bool b; |
| 1424 |
int32_t i32; |
| 1425 |
int64_t i64; |
| 1426 |
intptr_t iptr; |
| 1427 |
float f; |
| 1428 |
double d; |
| 1429 |
JSString* str; |
| 1430 |
JS::Symbol* sym; |
| 1431 |
BigInt* bi; |
| 1432 |
JSObject* obj; |
| 1433 |
Shape* shape; |
| 1434 |
uint64_t asBits; |
| 1435 |
}; |
| 1436 |
Payload() : asBits(0) {} |
| 1437 |
}; |
| 1438 |
|
| 1439 |
Payload payload_; |
| 1440 |
|
| 1441 |
static_assert(sizeof(Payload) == sizeof(uint64_t), |
| 1442 |
"asBits must be big enough for all payload bits"); |
| 1443 |
|
| 1444 |
#ifdef DEBUG |
| 1445 |
void assertInitializedPayload() const; |
| 1446 |
#else |
| 1447 |
void assertInitializedPayload() const {} |
| 1448 |
#endif |
| 1449 |
|
| 1450 |
MConstant(TempAllocator& alloc, const Value& v); |
| 1451 |
explicit MConstant(JSObject* obj); |
| 1452 |
explicit MConstant(Shape* shape); |
| 1453 |
explicit MConstant(float f); |
| 1454 |
explicit MConstant(MIRType type, int64_t i); |
| 1455 |
|
| 1456 |
public: |
| 1457 |
INSTRUCTION_HEADER(Constant) |
| 1458 |
static MConstant* New(TempAllocator& alloc, const Value& v); |
| 1459 |
static MConstant* New(TempAllocator::Fallible alloc, const Value& v); |
| 1460 |
static MConstant* New(TempAllocator& alloc, const Value& v, MIRType type); |
| 1461 |
static MConstant* NewFloat32(TempAllocator& alloc, double d); |
| 1462 |
static MConstant* NewInt64(TempAllocator& alloc, int64_t i); |
| 1463 |
static MConstant* NewIntPtr(TempAllocator& alloc, intptr_t i); |
| 1464 |
static MConstant* NewObject(TempAllocator& alloc, JSObject* v); |
| 1465 |
static MConstant* NewShape(TempAllocator& alloc, Shape* s); |
| 1466 |
static MConstant* Copy(TempAllocator& alloc, MConstant* src) { |
| 1467 |
return new (alloc) MConstant(*src); |
| 1468 |
} |
| 1469 |
|
| 1470 |
// Try to convert this constant to boolean, similar to js::ToBoolean. |
| 1471 |
// Returns false if the type is MIRType::Magic* or MIRType::Object. |
| 1472 |
[[nodiscard]] bool valueToBoolean(bool* res) const; |
| 1473 |
|
| 1474 |
#ifdef JS_JITSPEW |
| 1475 |
void printOpcode(GenericPrinter& out) const override; |
| 1476 |
#endif |
| 1477 |
|
| 1478 |
HashNumber valueHash() const override; |
| 1479 |
bool congruentTo(const MDefinition* ins) const override; |
| 1480 |
|
| 1481 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1482 |
|
| 1483 |
void computeRange(TempAllocator& alloc) override; |
| 1484 |
bool canTruncate() const override; |
| 1485 |
void truncate(TruncateKind kind) override; |
| 1486 |
|
| 1487 |
bool canProduceFloat32() const override; |
| 1488 |
|
| 1489 |
ALLOW_CLONE(MConstant) |
| 1490 |
|
| 1491 |
bool equals(const MConstant* other) const { |
| 1492 |
assertInitializedPayload(); |
| 1493 |
return type() == other->type() && payload_.asBits == other->payload_.asBits; |
| 1494 |
} |
| 1495 |
|
| 1496 |
bool toBoolean() const { |
| 1497 |
MOZ_ASSERT(type() == MIRType::Boolean); |
| 1498 |
return payload_.b; |
| 1499 |
} |
| 1500 |
int32_t toInt32() const { |
| 1501 |
MOZ_ASSERT(type() == MIRType::Int32); |
| 1502 |
return payload_.i32; |
| 1503 |
} |
| 1504 |
int64_t toInt64() const { |
| 1505 |
MOZ_ASSERT(type() == MIRType::Int64); |
| 1506 |
return payload_.i64; |
| 1507 |
} |
| 1508 |
intptr_t toIntPtr() const { |
| 1509 |
MOZ_ASSERT(type() == MIRType::IntPtr); |
| 1510 |
return payload_.iptr; |
| 1511 |
} |
| 1512 |
bool isInt32(int32_t i) const { |
| 1513 |
return type() == MIRType::Int32 && payload_.i32 == i; |
| 1514 |
} |
| 1515 |
bool isInt64(int64_t i) const { |
| 1516 |
return type() == MIRType::Int64 && payload_.i64 == i; |
| 1517 |
} |
| 1518 |
const double& toDouble() const { |
| 1519 |
MOZ_ASSERT(type() == MIRType::Double); |
| 1520 |
return payload_.d; |
| 1521 |
} |
| 1522 |
const float& toFloat32() const { |
| 1523 |
MOZ_ASSERT(type() == MIRType::Float32); |
| 1524 |
return payload_.f; |
| 1525 |
} |
| 1526 |
JSString* toString() const { |
| 1527 |
MOZ_ASSERT(type() == MIRType::String); |
| 1528 |
return payload_.str; |
| 1529 |
} |
| 1530 |
JS::Symbol* toSymbol() const { |
| 1531 |
MOZ_ASSERT(type() == MIRType::Symbol); |
| 1532 |
return payload_.sym; |
| 1533 |
} |
| 1534 |
BigInt* toBigInt() const { |
| 1535 |
MOZ_ASSERT(type() == MIRType::BigInt); |
| 1536 |
return payload_.bi; |
| 1537 |
} |
| 1538 |
JSObject& toObject() const { |
| 1539 |
MOZ_ASSERT(type() == MIRType::Object); |
| 1540 |
return *payload_.obj; |
| 1541 |
} |
| 1542 |
JSObject* toObjectOrNull() const { |
| 1543 |
if (type() == MIRType::Object) { |
| 1544 |
return payload_.obj; |
| 1545 |
} |
| 1546 |
MOZ_ASSERT(type() == MIRType::Null); |
| 1547 |
return nullptr; |
| 1548 |
} |
| 1549 |
Shape* toShape() const { |
| 1550 |
MOZ_ASSERT(type() == MIRType::Shape); |
| 1551 |
return payload_.shape; |
| 1552 |
} |
| 1553 |
|
| 1554 |
bool isTypeRepresentableAsDouble() const { |
| 1555 |
return IsTypeRepresentableAsDouble(type()); |
| 1556 |
} |
| 1557 |
double numberToDouble() const { |
| 1558 |
MOZ_ASSERT(isTypeRepresentableAsDouble()); |
| 1559 |
if (type() == MIRType::Int32) { |
| 1560 |
return toInt32(); |
| 1561 |
} |
| 1562 |
if (type() == MIRType::Double) { |
| 1563 |
return toDouble(); |
| 1564 |
} |
| 1565 |
return toFloat32(); |
| 1566 |
} |
| 1567 |
|
| 1568 |
// Convert this constant to a js::Value. Float32 constants will be stored |
| 1569 |
// as DoubleValue and NaNs are canonicalized. Callers must be careful: not |
| 1570 |
// all constants can be represented by js::Value (wasm supports int64). |
| 1571 |
Value toJSValue() const; |
| 1572 |
}; |
| 1573 |
|
| 1574 |
inline HashNumber ConstantValueHash(MIRType type, uint64_t payload) { |
| 1575 |
// Build a 64-bit value holding both the payload and the type. |
| 1576 |
static const size_t TypeBits = 8; |
| 1577 |
static const size_t TypeShift = 64 - TypeBits; |
| 1578 |
MOZ_ASSERT(uintptr_t(type) <= (1 << TypeBits) - 1); |
| 1579 |
uint64_t bits = (uint64_t(type) << TypeShift) ^ payload; |
| 1580 |
|
| 1581 |
// Fold all 64 bits into the 32-bit result. It's tempting to just discard |
| 1582 |
// half of the bits, as this is just a hash, however there are many common |
| 1583 |
// patterns of values where only the low or the high bits vary, so |
| 1584 |
// discarding either side would lead to excessive hash collisions. |
| 1585 |
return (HashNumber)bits ^ (HashNumber)(bits >> 32); |
| 1586 |
} |
| 1587 |
|
| 1588 |
class MParameter : public MNullaryInstruction { |
| 1589 |
int32_t index_; |
| 1590 |
|
| 1591 |
explicit MParameter(int32_t index) |
| 1592 |
: MNullaryInstruction(classOpcode), index_(index) { |
| 1593 |
setResultType(MIRType::Value); |
| 1594 |
} |
| 1595 |
|
| 1596 |
public: |
| 1597 |
INSTRUCTION_HEADER(Parameter) |
| 1598 |
TRIVIAL_NEW_WRAPPERS |
| 1599 |
|
| 1600 |
static const int32_t THIS_SLOT = -1; |
| 1601 |
int32_t index() const { return index_; } |
| 1602 |
#ifdef JS_JITSPEW |
| 1603 |
void printOpcode(GenericPrinter& out) const override; |
| 1604 |
#endif |
| 1605 |
HashNumber valueHash() const override; |
| 1606 |
bool congruentTo(const MDefinition* ins) const override; |
| 1607 |
}; |
| 1608 |
|
| 1609 |
class MControlInstruction : public MInstruction { |
| 1610 |
protected: |
| 1611 |
explicit MControlInstruction(Opcode op) : MInstruction(op) {} |
| 1612 |
|
| 1613 |
public: |
| 1614 |
virtual size_t numSuccessors() const = 0; |
| 1615 |
virtual MBasicBlock* getSuccessor(size_t i) const = 0; |
| 1616 |
virtual void replaceSuccessor(size_t i, MBasicBlock* successor) = 0; |
| 1617 |
|
| 1618 |
void initSuccessor(size_t i, MBasicBlock* successor) { |
| 1619 |
MOZ_ASSERT(!getSuccessor(i)); |
| 1620 |
replaceSuccessor(i, successor); |
| 1621 |
} |
| 1622 |
|
| 1623 |
bool isControlInstruction() const override { return true; } |
| 1624 |
|
| 1625 |
#ifdef JS_JITSPEW |
| 1626 |
void printOpcode(GenericPrinter& out) const override; |
| 1627 |
#endif |
| 1628 |
}; |
| 1629 |
|
| 1630 |
class MTableSwitch final : public MControlInstruction, |
| 1631 |
public NoFloatPolicy<0>::Data { |
| 1632 |
// The successors of the tableswitch |
| 1633 |
// - First successor = the default case |
| 1634 |
// - Successors 2 and higher = the cases |
| 1635 |
Vector<MBasicBlock*, 0, JitAllocPolicy> successors_; |
| 1636 |
// Index into successors_ sorted on case index |
| 1637 |
Vector<size_t, 0, JitAllocPolicy> cases_; |
| 1638 |
|
| 1639 |
MUse operand_; |
| 1640 |
int32_t low_; |
| 1641 |
int32_t high_; |
| 1642 |
|
| 1643 |
void initOperand(size_t index, MDefinition* operand) { |
| 1644 |
MOZ_ASSERT(index == 0); |
| 1645 |
operand_.init(operand, this); |
| 1646 |
} |
| 1647 |
|
| 1648 |
MTableSwitch(TempAllocator& alloc, MDefinition* ins, int32_t low, |
| 1649 |
int32_t high) |
| 1650 |
: MControlInstruction(classOpcode), |
| 1651 |
successors_(alloc), |
| 1652 |
cases_(alloc), |
| 1653 |
low_(low), |
| 1654 |
high_(high) { |
| 1655 |
initOperand(0, ins); |
| 1656 |
} |
| 1657 |
|
| 1658 |
protected: |
| 1659 |
MUse* getUseFor(size_t index) override { |
| 1660 |
MOZ_ASSERT(index == 0); |
| 1661 |
return &operand_; |
| 1662 |
} |
| 1663 |
|
| 1664 |
const MUse* getUseFor(size_t index) const override { |
| 1665 |
MOZ_ASSERT(index == 0); |
| 1666 |
return &operand_; |
| 1667 |
} |
| 1668 |
|
| 1669 |
public: |
| 1670 |
INSTRUCTION_HEADER(TableSwitch) |
| 1671 |
|
| 1672 |
static MTableSwitch* New(TempAllocator& alloc, MDefinition* ins, int32_t low, |
| 1673 |
int32_t high) { |
| 1674 |
return new (alloc) MTableSwitch(alloc, ins, low, high); |
| 1675 |
} |
| 1676 |
|
| 1677 |
size_t numSuccessors() const override { return successors_.length(); } |
| 1678 |
|
| 1679 |
[[nodiscard]] bool addSuccessor(MBasicBlock* successor, size_t* index) { |
| 1680 |
MOZ_ASSERT(successors_.length() < (size_t)(high_ - low_ + 2)); |
| 1681 |
MOZ_ASSERT(!successors_.empty()); |
| 1682 |
*index = successors_.length(); |
| 1683 |
return successors_.append(successor); |
| 1684 |
} |
| 1685 |
|
| 1686 |
MBasicBlock* getSuccessor(size_t i) const override { |
| 1687 |
MOZ_ASSERT(i < numSuccessors()); |
| 1688 |
return successors_[i]; |
| 1689 |
} |
| 1690 |
|
| 1691 |
void replaceSuccessor(size_t i, MBasicBlock* successor) override { |
| 1692 |
MOZ_ASSERT(i < numSuccessors()); |
| 1693 |
successors_[i] = successor; |
| 1694 |
} |
| 1695 |
|
| 1696 |
int32_t low() const { return low_; } |
| 1697 |
|
| 1698 |
int32_t high() const { return high_; } |
| 1699 |
|
| 1700 |
MBasicBlock* getDefault() const { return getSuccessor(0); } |
| 1701 |
|
| 1702 |
MBasicBlock* getCase(size_t i) const { return getSuccessor(cases_[i]); } |
| 1703 |
|
| 1704 |
[[nodiscard]] bool addDefault(MBasicBlock* block, size_t* index = nullptr) { |
| 1705 |
MOZ_ASSERT(successors_.empty()); |
| 1706 |
if (index) { |
| 1707 |
*index = 0; |
| 1708 |
} |
| 1709 |
return successors_.append(block); |
| 1710 |
} |
| 1711 |
|
| 1712 |
[[nodiscard]] bool addCase(size_t successorIndex) { |
| 1713 |
return cases_.append(successorIndex); |
| 1714 |
} |
| 1715 |
|
| 1716 |
size_t numCases() const { return high() - low() + 1; } |
| 1717 |
|
| 1718 |
MDefinition* getOperand(size_t index) const override { |
| 1719 |
MOZ_ASSERT(index == 0); |
| 1720 |
return operand_.producer(); |
| 1721 |
} |
| 1722 |
|
| 1723 |
size_t numOperands() const override { return 1; } |
| 1724 |
|
| 1725 |
size_t indexOf(const MUse* u) const final { |
| 1726 |
MOZ_ASSERT(u == getUseFor(0)); |
| 1727 |
return 0; |
| 1728 |
} |
| 1729 |
|
| 1730 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 1731 |
MOZ_ASSERT(index == 0); |
| 1732 |
operand_.replaceProducer(operand); |
| 1733 |
} |
| 1734 |
|
| 1735 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 1736 |
|
| 1737 |
// It does read memory in that it must read an entry from the jump table, |
| 1738 |
// but that's effectively data that is private to this MIR. And it should |
| 1739 |
// certainly never be modified by any other MIR. Hence it is effect-free |
| 1740 |
// from an alias-analysis standpoint. |
| 1741 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1742 |
}; |
| 1743 |
|
| 1744 |
template <size_t Arity, size_t Successors> |
| 1745 |
class MAryControlInstruction : public MControlInstruction { |
| 1746 |
mozilla::Array<MUse, Arity> operands_; |
| 1747 |
mozilla::Array<MBasicBlock*, Successors> successors_; |
| 1748 |
|
| 1749 |
protected: |
| 1750 |
explicit MAryControlInstruction(Opcode op) : MControlInstruction(op) {} |
| 1751 |
void setSuccessor(size_t index, MBasicBlock* successor) { |
| 1752 |
successors_[index] = successor; |
| 1753 |
} |
| 1754 |
|
| 1755 |
MUse* getUseFor(size_t index) final { return &operands_[index]; } |
| 1756 |
const MUse* getUseFor(size_t index) const final { return &operands_[index]; } |
| 1757 |
void initOperand(size_t index, MDefinition* operand) { |
| 1758 |
operands_[index].init(operand, this); |
| 1759 |
} |
| 1760 |
|
| 1761 |
public: |
| 1762 |
MDefinition* getOperand(size_t index) const final { |
| 1763 |
return operands_[index].producer(); |
| 1764 |
} |
| 1765 |
size_t numOperands() const final { return Arity; } |
| 1766 |
size_t indexOf(const MUse* u) const final { |
| 1767 |
MOZ_ASSERT(u >= &operands_[0]); |
| 1768 |
MOZ_ASSERT(u <= &operands_[numOperands() - 1]); |
| 1769 |
return u - &operands_[0]; |
| 1770 |
} |
| 1771 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 1772 |
operands_[index].replaceProducer(operand); |
| 1773 |
} |
| 1774 |
size_t numSuccessors() const final { return Successors; } |
| 1775 |
MBasicBlock* getSuccessor(size_t i) const final { return successors_[i]; } |
| 1776 |
void replaceSuccessor(size_t i, MBasicBlock* succ) final { |
| 1777 |
successors_[i] = succ; |
| 1778 |
} |
| 1779 |
}; |
| 1780 |
|
| 1781 |
template <size_t Successors> |
| 1782 |
class MVariadicControlInstruction : public MVariadicT<MControlInstruction> { |
| 1783 |
mozilla::Array<MBasicBlock*, Successors> successors_; |
| 1784 |
|
| 1785 |
protected: |
| 1786 |
explicit MVariadicControlInstruction(Opcode op) |
| 1787 |
: MVariadicT<MControlInstruction>(op) {} |
| 1788 |
void setSuccessor(size_t index, MBasicBlock* successor) { |
| 1789 |
successors_[index] = successor; |
| 1790 |
} |
| 1791 |
|
| 1792 |
public: |
| 1793 |
size_t numSuccessors() const final { return Successors; } |
| 1794 |
MBasicBlock* getSuccessor(size_t i) const final { return successors_[i]; } |
| 1795 |
void replaceSuccessor(size_t i, MBasicBlock* succ) final { |
| 1796 |
successors_[i] = succ; |
| 1797 |
} |
| 1798 |
}; |
| 1799 |
|
| 1800 |
// Jump to the start of another basic block. |
| 1801 |
class MGoto : public MAryControlInstruction<0, 1>, public NoTypePolicy::Data { |
| 1802 |
explicit MGoto(MBasicBlock* target) : MAryControlInstruction(classOpcode) { |
| 1803 |
setSuccessor(TargetIndex, target); |
| 1804 |
} |
| 1805 |
|
| 1806 |
public: |
| 1807 |
INSTRUCTION_HEADER(Goto) |
| 1808 |
static MGoto* New(TempAllocator& alloc, MBasicBlock* target); |
| 1809 |
static MGoto* New(TempAllocator::Fallible alloc, MBasicBlock* target); |
| 1810 |
|
| 1811 |
// Variant that may patch the target later. |
| 1812 |
static MGoto* New(TempAllocator& alloc); |
| 1813 |
|
| 1814 |
static constexpr size_t TargetIndex = 0; |
| 1815 |
|
| 1816 |
MBasicBlock* target() const { return getSuccessor(TargetIndex); } |
| 1817 |
void setTarget(MBasicBlock* target) { setSuccessor(TargetIndex, target); } |
| 1818 |
|
| 1819 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1820 |
|
| 1821 |
#ifdef JS_JITSPEW |
| 1822 |
void getExtras(ExtrasCollector* extras) const override { |
| 1823 |
char buf[64]; |
| 1824 |
SprintfLiteral(buf, "Block%u", GetMBasicBlockId(target())); |
| 1825 |
extras->add(buf); |
| 1826 |
} |
| 1827 |
#endif |
| 1828 |
|
| 1829 |
ALLOW_CLONE(MGoto) |
| 1830 |
}; |
| 1831 |
|
| 1832 |
// Tests if the input instruction evaluates to true or false, and jumps to the |
| 1833 |
// start of a corresponding basic block. |
| 1834 |
class MTest : public MAryControlInstruction<1, 2>, public TestPolicy::Data { |
| 1835 |
// It is allowable to specify `trueBranch` or `falseBranch` as nullptr and |
| 1836 |
// patch it in later. |
| 1837 |
MTest(MDefinition* ins, MBasicBlock* trueBranch, MBasicBlock* falseBranch) |
| 1838 |
: MAryControlInstruction(classOpcode) { |
| 1839 |
initOperand(0, ins); |
| 1840 |
setSuccessor(TrueBranchIndex, trueBranch); |
| 1841 |
setSuccessor(FalseBranchIndex, falseBranch); |
| 1842 |
} |
| 1843 |
|
| 1844 |
TypeDataList observedTypes_; |
| 1845 |
|
| 1846 |
public: |
| 1847 |
INSTRUCTION_HEADER(Test) |
| 1848 |
TRIVIAL_NEW_WRAPPERS |
| 1849 |
NAMED_OPERANDS((0, input)) |
| 1850 |
|
| 1851 |
const TypeDataList& observedTypes() const { return observedTypes_; } |
| 1852 |
void setObservedTypes(const TypeDataList& observed) { |
| 1853 |
observedTypes_ = observed; |
| 1854 |
} |
| 1855 |
|
| 1856 |
static constexpr size_t TrueBranchIndex = 0; |
| 1857 |
static constexpr size_t FalseBranchIndex = 1; |
| 1858 |
|
| 1859 |
MBasicBlock* ifTrue() const { return getSuccessor(TrueBranchIndex); } |
| 1860 |
MBasicBlock* ifFalse() const { return getSuccessor(FalseBranchIndex); } |
| 1861 |
void setIfTrue(MBasicBlock* target) { setSuccessor(TrueBranchIndex, target); } |
| 1862 |
void setIfFalse(MBasicBlock* target) { |
| 1863 |
setSuccessor(FalseBranchIndex, target); |
| 1864 |
} |
| 1865 |
|
| 1866 |
MBasicBlock* branchSuccessor(BranchDirection dir) const { |
| 1867 |
return (dir == TRUE_BRANCH) ? ifTrue() : ifFalse(); |
| 1868 |
} |
| 1869 |
|
| 1870 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1871 |
|
| 1872 |
MDefinition* foldsDoubleNegation(TempAllocator& alloc); |
| 1873 |
MDefinition* foldsConstant(TempAllocator& alloc); |
| 1874 |
MDefinition* foldsTypes(TempAllocator& alloc); |
| 1875 |
MDefinition* foldsNeedlessControlFlow(TempAllocator& alloc); |
| 1876 |
MDefinition* foldsRedundantTest(TempAllocator& alloc); |
| 1877 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 1878 |
|
| 1879 |
#ifdef DEBUG |
| 1880 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 1881 |
#endif |
| 1882 |
|
| 1883 |
#ifdef JS_JITSPEW |
| 1884 |
void getExtras(ExtrasCollector* extras) const override { |
| 1885 |
char buf[64]; |
| 1886 |
SprintfLiteral(buf, "true->Block%u false->Block%u", |
| 1887 |
GetMBasicBlockId(ifTrue()), GetMBasicBlockId(ifFalse())); |
| 1888 |
extras->add(buf); |
| 1889 |
} |
| 1890 |
#endif |
| 1891 |
|
| 1892 |
bool canClone() const override { return true; } |
| 1893 |
MInstruction* clone(TempAllocator& alloc, |
| 1894 |
const MDefinitionVector& inputs) const override { |
| 1895 |
MInstruction* res = new (alloc) MTest(input(), ifTrue(), ifFalse()); |
| 1896 |
if (!res) { |
| 1897 |
return nullptr; |
| 1898 |
} |
| 1899 |
for (size_t i = 0; i < numOperands(); i++) { |
| 1900 |
res->replaceOperand(i, inputs[i]); |
| 1901 |
} |
| 1902 |
return res; |
| 1903 |
} |
| 1904 |
}; |
| 1905 |
|
| 1906 |
// Returns from this function to the previous caller. |
| 1907 |
class MReturn : public MAryControlInstruction<1, 0>, |
| 1908 |
public BoxInputsPolicy::Data { |
| 1909 |
explicit MReturn(MDefinition* ins) : MAryControlInstruction(classOpcode) { |
| 1910 |
initOperand(0, ins); |
| 1911 |
} |
| 1912 |
|
| 1913 |
public: |
| 1914 |
INSTRUCTION_HEADER(Return) |
| 1915 |
TRIVIAL_NEW_WRAPPERS |
| 1916 |
NAMED_OPERANDS((0, input)) |
| 1917 |
|
| 1918 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1919 |
}; |
| 1920 |
|
| 1921 |
class MNewArray : public MUnaryInstruction, public NoTypePolicy::Data { |
| 1922 |
private: |
| 1923 |
// Number of elements to allocate for the array. |
| 1924 |
uint32_t length_; |
| 1925 |
|
| 1926 |
// Heap where the array should be allocated. |
| 1927 |
gc::Heap initialHeap_; |
| 1928 |
|
| 1929 |
bool vmCall_; |
| 1930 |
|
| 1931 |
MNewArray(uint32_t length, MConstant* templateConst, gc::Heap initialHeap, |
| 1932 |
bool vmCall = false); |
| 1933 |
|
| 1934 |
public: |
| 1935 |
INSTRUCTION_HEADER(NewArray) |
| 1936 |
TRIVIAL_NEW_WRAPPERS |
| 1937 |
|
| 1938 |
static MNewArray* NewVM(TempAllocator& alloc, uint32_t length, |
| 1939 |
MConstant* templateConst, gc::Heap initialHeap) { |
| 1940 |
return new (alloc) MNewArray(length, templateConst, initialHeap, true); |
| 1941 |
} |
| 1942 |
|
| 1943 |
uint32_t length() const { return length_; } |
| 1944 |
|
| 1945 |
JSObject* templateObject() const { |
| 1946 |
return getOperand(0)->toConstant()->toObjectOrNull(); |
| 1947 |
} |
| 1948 |
|
| 1949 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 1950 |
|
| 1951 |
bool isVMCall() const { return vmCall_; } |
| 1952 |
|
| 1953 |
// NewArray is marked as non-effectful because all our allocations are |
| 1954 |
// either lazy when we are using "new Array(length)" or bounded by the |
| 1955 |
// script or the stack size when we are using "new Array(...)" or "[...]" |
| 1956 |
// notations. So we might have to allocate the array twice if we bail |
| 1957 |
// during the computation of the first element of the square braket |
| 1958 |
// notation. |
| 1959 |
virtual AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1960 |
|
| 1961 |
[[nodiscard]] bool writeRecoverData( |
| 1962 |
CompactBufferWriter& writer) const override; |
| 1963 |
bool canRecoverOnBailout() const override { |
| 1964 |
// The template object can safely be used in the recover instruction |
| 1965 |
// because it can never be mutated by any other function execution. |
| 1966 |
return templateObject() != nullptr; |
| 1967 |
} |
| 1968 |
}; |
| 1969 |
|
| 1970 |
class MNewTypedArray : public MUnaryInstruction, public NoTypePolicy::Data { |
| 1971 |
gc::Heap initialHeap_; |
| 1972 |
|
| 1973 |
MNewTypedArray(MConstant* templateConst, gc::Heap initialHeap) |
| 1974 |
: MUnaryInstruction(classOpcode, templateConst), |
| 1975 |
initialHeap_(initialHeap) { |
| 1976 |
setResultType(MIRType::Object); |
| 1977 |
} |
| 1978 |
|
| 1979 |
public: |
| 1980 |
INSTRUCTION_HEADER(NewTypedArray) |
| 1981 |
TRIVIAL_NEW_WRAPPERS |
| 1982 |
|
| 1983 |
TypedArrayObject* templateObject() const { |
| 1984 |
return &getOperand(0)->toConstant()->toObject().as<TypedArrayObject>(); |
| 1985 |
} |
| 1986 |
|
| 1987 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 1988 |
|
| 1989 |
virtual AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 1990 |
|
| 1991 |
[[nodiscard]] bool writeRecoverData( |
| 1992 |
CompactBufferWriter& writer) const override; |
| 1993 |
bool canRecoverOnBailout() const override { return true; } |
| 1994 |
}; |
| 1995 |
|
| 1996 |
class MNewObject : public MUnaryInstruction, public NoTypePolicy::Data { |
| 1997 |
public: |
| 1998 |
enum Mode { ObjectLiteral, ObjectCreate }; |
| 1999 |
|
| 2000 |
private: |
| 2001 |
gc::Heap initialHeap_; |
| 2002 |
Mode mode_; |
| 2003 |
bool vmCall_; |
| 2004 |
|
| 2005 |
MNewObject(MConstant* templateConst, gc::Heap initialHeap, Mode mode, |
| 2006 |
bool vmCall = false) |
| 2007 |
: MUnaryInstruction(classOpcode, templateConst), |
| 2008 |
initialHeap_(initialHeap), |
| 2009 |
mode_(mode), |
| 2010 |
vmCall_(vmCall) { |
| 2011 |
if (mode == ObjectLiteral) { |
| 2012 |
MOZ_ASSERT(!templateObject()); |
| 2013 |
} else { |
| 2014 |
MOZ_ASSERT(templateObject()); |
| 2015 |
} |
| 2016 |
setResultType(MIRType::Object); |
| 2017 |
|
| 2018 |
// The constant is kept separated in a MConstant, this way we can safely |
| 2019 |
// mark it during GC if we recover the object allocation. Otherwise, by |
| 2020 |
// making it emittedAtUses, we do not produce register allocations for |
| 2021 |
// it and inline its content inside the code produced by the |
| 2022 |
// CodeGenerator. |
| 2023 |
if (templateConst->toConstant()->type() == MIRType::Object) { |
| 2024 |
templateConst->setEmittedAtUses(); |
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
public: |
| 2029 |
INSTRUCTION_HEADER(NewObject) |
| 2030 |
TRIVIAL_NEW_WRAPPERS |
| 2031 |
|
| 2032 |
static MNewObject* NewVM(TempAllocator& alloc, MConstant* templateConst, |
| 2033 |
gc::Heap initialHeap, Mode mode) { |
| 2034 |
return new (alloc) MNewObject(templateConst, initialHeap, mode, true); |
| 2035 |
} |
| 2036 |
|
| 2037 |
Mode mode() const { return mode_; } |
| 2038 |
|
| 2039 |
JSObject* templateObject() const { |
| 2040 |
return getOperand(0)->toConstant()->toObjectOrNull(); |
| 2041 |
} |
| 2042 |
|
| 2043 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 2044 |
|
| 2045 |
bool isVMCall() const { return vmCall_; } |
| 2046 |
|
| 2047 |
[[nodiscard]] bool writeRecoverData( |
| 2048 |
CompactBufferWriter& writer) const override; |
| 2049 |
bool canRecoverOnBailout() const override { |
| 2050 |
// The template object can safely be used in the recover instruction |
| 2051 |
// because it can never be mutated by any other function execution. |
| 2052 |
return templateObject() != nullptr; |
| 2053 |
} |
| 2054 |
}; |
| 2055 |
|
| 2056 |
class MNewPlainObject : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2057 |
private: |
| 2058 |
uint32_t numFixedSlots_; |
| 2059 |
uint32_t numDynamicSlots_; |
| 2060 |
gc::AllocKind allocKind_; |
| 2061 |
gc::Heap initialHeap_; |
| 2062 |
|
| 2063 |
MNewPlainObject(MConstant* shapeConst, uint32_t numFixedSlots, |
| 2064 |
uint32_t numDynamicSlots, gc::AllocKind allocKind, |
| 2065 |
gc::Heap initialHeap) |
| 2066 |
: MUnaryInstruction(classOpcode, shapeConst), |
| 2067 |
numFixedSlots_(numFixedSlots), |
| 2068 |
numDynamicSlots_(numDynamicSlots), |
| 2069 |
allocKind_(allocKind), |
| 2070 |
initialHeap_(initialHeap) { |
| 2071 |
setResultType(MIRType::Object); |
| 2072 |
|
| 2073 |
// The shape constant is kept separated in a MConstant. This way we can |
| 2074 |
// safely mark it during GC if we recover the object allocation. Otherwise, |
| 2075 |
// by making it emittedAtUses, we do not produce register allocations for it |
| 2076 |
// and inline its content inside the code produced by the CodeGenerator. |
| 2077 |
MOZ_ASSERT(shapeConst->toConstant()->type() == MIRType::Shape); |
| 2078 |
shapeConst->setEmittedAtUses(); |
| 2079 |
} |
| 2080 |
|
| 2081 |
public: |
| 2082 |
INSTRUCTION_HEADER(NewPlainObject) |
| 2083 |
TRIVIAL_NEW_WRAPPERS |
| 2084 |
|
| 2085 |
const Shape* shape() const { return getOperand(0)->toConstant()->toShape(); } |
| 2086 |
|
| 2087 |
uint32_t numFixedSlots() const { return numFixedSlots_; } |
| 2088 |
uint32_t numDynamicSlots() const { return numDynamicSlots_; } |
| 2089 |
gc::AllocKind allocKind() const { return allocKind_; } |
| 2090 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 2091 |
|
| 2092 |
[[nodiscard]] bool writeRecoverData( |
| 2093 |
CompactBufferWriter& writer) const override; |
| 2094 |
bool canRecoverOnBailout() const override { return true; } |
| 2095 |
|
| 2096 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2097 |
}; |
| 2098 |
|
| 2099 |
class MNewArrayObject : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2100 |
private: |
| 2101 |
uint32_t length_; |
| 2102 |
gc::Heap initialHeap_; |
| 2103 |
|
| 2104 |
MNewArrayObject(TempAllocator& alloc, MConstant* shapeConst, uint32_t length, |
| 2105 |
gc::Heap initialHeap) |
| 2106 |
: MUnaryInstruction(classOpcode, shapeConst), |
| 2107 |
length_(length), |
| 2108 |
initialHeap_(initialHeap) { |
| 2109 |
setResultType(MIRType::Object); |
| 2110 |
MOZ_ASSERT(shapeConst->toConstant()->type() == MIRType::Shape); |
| 2111 |
shapeConst->setEmittedAtUses(); |
| 2112 |
} |
| 2113 |
|
| 2114 |
public: |
| 2115 |
INSTRUCTION_HEADER(NewArrayObject) |
| 2116 |
TRIVIAL_NEW_WRAPPERS |
| 2117 |
|
| 2118 |
static MNewArrayObject* New(TempAllocator& alloc, MConstant* shapeConst, |
| 2119 |
uint32_t length, gc::Heap initialHeap) { |
| 2120 |
return new (alloc) MNewArrayObject(alloc, shapeConst, length, initialHeap); |
| 2121 |
} |
| 2122 |
|
| 2123 |
const Shape* shape() const { return getOperand(0)->toConstant()->toShape(); } |
| 2124 |
|
| 2125 |
// See MNewArray::getAliasSet comment. |
| 2126 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2127 |
|
| 2128 |
uint32_t length() const { return length_; } |
| 2129 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 2130 |
|
| 2131 |
[[nodiscard]] bool writeRecoverData( |
| 2132 |
CompactBufferWriter& writer) const override; |
| 2133 |
bool canRecoverOnBailout() const override { return true; } |
| 2134 |
}; |
| 2135 |
|
| 2136 |
class MNewIterator : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2137 |
public: |
| 2138 |
enum Type { |
| 2139 |
ArrayIterator, |
| 2140 |
StringIterator, |
| 2141 |
RegExpStringIterator, |
| 2142 |
}; |
| 2143 |
|
| 2144 |
private: |
| 2145 |
Type type_; |
| 2146 |
|
| 2147 |
MNewIterator(MConstant* templateConst, Type type) |
| 2148 |
: MUnaryInstruction(classOpcode, templateConst), type_(type) { |
| 2149 |
setResultType(MIRType::Object); |
| 2150 |
templateConst->setEmittedAtUses(); |
| 2151 |
} |
| 2152 |
|
| 2153 |
public: |
| 2154 |
INSTRUCTION_HEADER(NewIterator) |
| 2155 |
TRIVIAL_NEW_WRAPPERS |
| 2156 |
|
| 2157 |
Type type() const { return type_; } |
| 2158 |
|
| 2159 |
JSObject* templateObject() { |
| 2160 |
return getOperand(0)->toConstant()->toObjectOrNull(); |
| 2161 |
} |
| 2162 |
|
| 2163 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2164 |
|
| 2165 |
[[nodiscard]] bool writeRecoverData( |
| 2166 |
CompactBufferWriter& writer) const override; |
| 2167 |
bool canRecoverOnBailout() const override { return true; } |
| 2168 |
}; |
| 2169 |
|
| 2170 |
// Represent the content of all slots of an object. This instruction is not |
| 2171 |
// lowered and is not used to generate code. |
| 2172 |
class MObjectState : public MVariadicInstruction, |
| 2173 |
public NoFloatPolicyAfter<1>::Data { |
| 2174 |
private: |
| 2175 |
uint32_t numSlots_; |
| 2176 |
uint32_t numFixedSlots_; |
| 2177 |
|
| 2178 |
explicit MObjectState(JSObject* templateObject); |
| 2179 |
explicit MObjectState(const Shape* shape); |
| 2180 |
explicit MObjectState(MObjectState* state); |
| 2181 |
|
| 2182 |
[[nodiscard]] bool init(TempAllocator& alloc, MDefinition* obj); |
| 2183 |
|
| 2184 |
void initSlot(uint32_t slot, MDefinition* def) { initOperand(slot + 1, def); } |
| 2185 |
|
| 2186 |
public: |
| 2187 |
INSTRUCTION_HEADER(ObjectState) |
| 2188 |
NAMED_OPERANDS((0, object)) |
| 2189 |
|
| 2190 |
// Return the template object of any object creation which can be recovered |
| 2191 |
// on bailout. |
| 2192 |
static JSObject* templateObjectOf(MDefinition* obj); |
| 2193 |
|
| 2194 |
static MObjectState* New(TempAllocator& alloc, MDefinition* obj); |
| 2195 |
static MObjectState* Copy(TempAllocator& alloc, MObjectState* state); |
| 2196 |
|
| 2197 |
// As we might do read of uninitialized properties, we have to copy the |
| 2198 |
// initial values from the template object. |
| 2199 |
void initFromTemplateObject(TempAllocator& alloc, MDefinition* undefinedVal); |
| 2200 |
|
| 2201 |
size_t numFixedSlots() const { return numFixedSlots_; } |
| 2202 |
size_t numSlots() const { return numSlots_; } |
| 2203 |
|
| 2204 |
MDefinition* getSlot(uint32_t slot) const { return getOperand(slot + 1); } |
| 2205 |
void setSlot(uint32_t slot, MDefinition* def) { |
| 2206 |
replaceOperand(slot + 1, def); |
| 2207 |
} |
| 2208 |
|
| 2209 |
bool hasFixedSlot(uint32_t slot) const { |
| 2210 |
return slot < numSlots() && slot < numFixedSlots(); |
| 2211 |
} |
| 2212 |
MDefinition* getFixedSlot(uint32_t slot) const { |
| 2213 |
MOZ_ASSERT(slot < numFixedSlots()); |
| 2214 |
return getSlot(slot); |
| 2215 |
} |
| 2216 |
void setFixedSlot(uint32_t slot, MDefinition* def) { |
| 2217 |
MOZ_ASSERT(slot < numFixedSlots()); |
| 2218 |
setSlot(slot, def); |
| 2219 |
} |
| 2220 |
|
| 2221 |
bool hasDynamicSlot(uint32_t slot) const { |
| 2222 |
return numFixedSlots() < numSlots() && slot < numSlots() - numFixedSlots(); |
| 2223 |
} |
| 2224 |
MDefinition* getDynamicSlot(uint32_t slot) const { |
| 2225 |
return getSlot(slot + numFixedSlots()); |
| 2226 |
} |
| 2227 |
void setDynamicSlot(uint32_t slot, MDefinition* def) { |
| 2228 |
setSlot(slot + numFixedSlots(), def); |
| 2229 |
} |
| 2230 |
|
| 2231 |
[[nodiscard]] bool writeRecoverData( |
| 2232 |
CompactBufferWriter& writer) const override; |
| 2233 |
bool canRecoverOnBailout() const override { return true; } |
| 2234 |
}; |
| 2235 |
|
| 2236 |
// Represent the contents of all elements of an array. This instruction is not |
| 2237 |
// lowered and is not used to generate code. |
| 2238 |
class MArrayState : public MVariadicInstruction, |
| 2239 |
public NoFloatPolicyAfter<2>::Data { |
| 2240 |
private: |
| 2241 |
uint32_t numElements_; |
| 2242 |
|
| 2243 |
explicit MArrayState(MDefinition* arr); |
| 2244 |
|
| 2245 |
[[nodiscard]] bool init(TempAllocator& alloc, MDefinition* obj, |
| 2246 |
MDefinition* len); |
| 2247 |
|
| 2248 |
void initElement(uint32_t index, MDefinition* def) { |
| 2249 |
initOperand(index + 2, def); |
| 2250 |
} |
| 2251 |
|
| 2252 |
public: |
| 2253 |
INSTRUCTION_HEADER(ArrayState) |
| 2254 |
NAMED_OPERANDS((0, array), (1, initializedLength)) |
| 2255 |
|
| 2256 |
static MArrayState* New(TempAllocator& alloc, MDefinition* arr, |
| 2257 |
MDefinition* initLength); |
| 2258 |
static MArrayState* Copy(TempAllocator& alloc, MArrayState* state); |
| 2259 |
|
| 2260 |
void initFromTemplateObject(TempAllocator& alloc, MDefinition* undefinedVal); |
| 2261 |
|
| 2262 |
void setInitializedLength(MDefinition* def) { replaceOperand(1, def); } |
| 2263 |
|
| 2264 |
size_t numElements() const { return numElements_; } |
| 2265 |
|
| 2266 |
MDefinition* getElement(uint32_t index) const { |
| 2267 |
return getOperand(index + 2); |
| 2268 |
} |
| 2269 |
void setElement(uint32_t index, MDefinition* def) { |
| 2270 |
replaceOperand(index + 2, def); |
| 2271 |
} |
| 2272 |
|
| 2273 |
[[nodiscard]] bool writeRecoverData( |
| 2274 |
CompactBufferWriter& writer) const override; |
| 2275 |
bool canRecoverOnBailout() const override { return true; } |
| 2276 |
}; |
| 2277 |
|
| 2278 |
// WrappedFunction stores information about a function that can safely be used |
| 2279 |
// off-thread. In particular, a function's flags can be modified on the main |
| 2280 |
// thread as functions are relazified and delazified, so we must be careful not |
| 2281 |
// to access these flags off-thread. |
| 2282 |
class WrappedFunction : public TempObject { |
| 2283 |
// If this is a native function without a JitEntry, the JSFunction*. |
| 2284 |
CompilerFunction nativeFun_; |
| 2285 |
uint16_t nargs_; |
| 2286 |
js::FunctionFlags flags_; |
| 2287 |
|
| 2288 |
public: |
| 2289 |
WrappedFunction(JSFunction* nativeFun, uint16_t nargs, FunctionFlags flags); |
| 2290 |
|
| 2291 |
// Note: When adding new accessors be sure to add consistency asserts |
| 2292 |
// to the constructor. |
| 2293 |
|
| 2294 |
size_t nargs() const { return nargs_; } |
| 2295 |
|
| 2296 |
bool isNativeWithoutJitEntry() const { |
| 2297 |
return flags_.isNativeWithoutJitEntry(); |
| 2298 |
} |
| 2299 |
bool hasJitEntry() const { return flags_.hasJitEntry(); } |
| 2300 |
bool isConstructor() const { return flags_.isConstructor(); } |
| 2301 |
bool isClassConstructor() const { return flags_.isClassConstructor(); } |
| 2302 |
|
| 2303 |
// These fields never change, they can be accessed off-main thread. |
| 2304 |
JSNative native() const { |
| 2305 |
MOZ_ASSERT(isNativeWithoutJitEntry()); |
| 2306 |
return nativeFun_->nativeUnchecked(); |
| 2307 |
} |
| 2308 |
bool hasJitInfo() const { |
| 2309 |
return flags_.canHaveJitInfo() && nativeFun_->jitInfoUnchecked(); |
| 2310 |
} |
| 2311 |
const JSJitInfo* jitInfo() const { |
| 2312 |
MOZ_ASSERT(hasJitInfo()); |
| 2313 |
return nativeFun_->jitInfoUnchecked(); |
| 2314 |
} |
| 2315 |
|
| 2316 |
JSFunction* rawNativeJSFunction() const { return nativeFun_; } |
| 2317 |
}; |
| 2318 |
|
| 2319 |
enum class DOMObjectKind : uint8_t { Proxy, Native }; |
| 2320 |
|
| 2321 |
class MCallBase : public MVariadicInstruction, public CallPolicy::Data { |
| 2322 |
protected: |
| 2323 |
// The callee, this, and the actual arguments are all operands of MCall. |
| 2324 |
static const size_t CalleeOperandIndex = 0; |
| 2325 |
static const size_t NumNonArgumentOperands = 1; |
| 2326 |
|
| 2327 |
explicit MCallBase(Opcode op) : MVariadicInstruction(op) {} |
| 2328 |
|
| 2329 |
public: |
| 2330 |
void initCallee(MDefinition* func) { initOperand(CalleeOperandIndex, func); } |
| 2331 |
MDefinition* getCallee() const { return getOperand(CalleeOperandIndex); } |
| 2332 |
|
| 2333 |
void replaceCallee(MInstruction* newfunc) { |
| 2334 |
replaceOperand(CalleeOperandIndex, newfunc); |
| 2335 |
} |
| 2336 |
|
| 2337 |
void addArg(size_t argnum, MDefinition* arg); |
| 2338 |
|
| 2339 |
MDefinition* getArg(uint32_t index) const { |
| 2340 |
return getOperand(NumNonArgumentOperands + index); |
| 2341 |
} |
| 2342 |
|
| 2343 |
// The number of stack arguments is the max between the number of formal |
| 2344 |
// arguments and the number of actual arguments. The number of stack |
| 2345 |
// argument includes the |undefined| padding added in case of underflow. |
| 2346 |
// Includes |this|. |
| 2347 |
uint32_t numStackArgs() const { |
| 2348 |
return numOperands() - NumNonArgumentOperands; |
| 2349 |
} |
| 2350 |
uint32_t paddedNumStackArgs() const { |
| 2351 |
if (JitStackValueAlignment > 1) { |
| 2352 |
return AlignBytes(numStackArgs(), JitStackValueAlignment); |
| 2353 |
} |
| 2354 |
return numStackArgs(); |
| 2355 |
} |
| 2356 |
|
| 2357 |
static size_t IndexOfThis() { return NumNonArgumentOperands; } |
| 2358 |
static size_t IndexOfArgument(size_t index) { |
| 2359 |
return NumNonArgumentOperands + index + 1; // +1 to skip |this|. |
| 2360 |
} |
| 2361 |
static size_t IndexOfStackArg(size_t index) { |
| 2362 |
return NumNonArgumentOperands + index; |
| 2363 |
} |
| 2364 |
}; |
| 2365 |
|
| 2366 |
class MCall : public MCallBase { |
| 2367 |
protected: |
| 2368 |
// Monomorphic cache for MCalls with a single JSFunction target. |
| 2369 |
WrappedFunction* target_; |
| 2370 |
|
| 2371 |
// Original value of argc from the bytecode. |
| 2372 |
uint32_t numActualArgs_; |
| 2373 |
|
| 2374 |
// True if the call is for JSOp::New or JSOp::SuperCall. |
| 2375 |
bool construct_ : 1; |
| 2376 |
|
| 2377 |
// True if the caller does not use the return value. |
| 2378 |
bool ignoresReturnValue_ : 1; |
| 2379 |
|
| 2380 |
bool needsClassCheck_ : 1; |
| 2381 |
bool maybeCrossRealm_ : 1; |
| 2382 |
bool needsThisCheck_ : 1; |
| 2383 |
|
| 2384 |
MCall(WrappedFunction* target, uint32_t numActualArgs, bool construct, |
| 2385 |
bool ignoresReturnValue) |
| 2386 |
: MCallBase(classOpcode), |
| 2387 |
target_(target), |
| 2388 |
numActualArgs_(numActualArgs), |
| 2389 |
construct_(construct), |
| 2390 |
ignoresReturnValue_(ignoresReturnValue), |
| 2391 |
needsClassCheck_(true), |
| 2392 |
maybeCrossRealm_(true), |
| 2393 |
needsThisCheck_(false) { |
| 2394 |
setResultType(MIRType::Value); |
| 2395 |
} |
| 2396 |
|
| 2397 |
public: |
| 2398 |
INSTRUCTION_HEADER(Call) |
| 2399 |
static MCall* New(TempAllocator& alloc, WrappedFunction* target, |
| 2400 |
size_t maxArgc, size_t numActualArgs, bool construct, |
| 2401 |
bool ignoresReturnValue, bool isDOMCall, |
| 2402 |
mozilla::Maybe<DOMObjectKind> objectKind, |
| 2403 |
mozilla::Maybe<gc::Heap> initialHeap); |
| 2404 |
|
| 2405 |
bool needsClassCheck() const { return needsClassCheck_; } |
| 2406 |
void disableClassCheck() { needsClassCheck_ = false; } |
| 2407 |
|
| 2408 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2409 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2410 |
|
| 2411 |
bool needsThisCheck() const { return needsThisCheck_; } |
| 2412 |
void setNeedsThisCheck() { |
| 2413 |
MOZ_ASSERT(construct_); |
| 2414 |
needsThisCheck_ = true; |
| 2415 |
} |
| 2416 |
|
| 2417 |
// For monomorphic callsites. |
| 2418 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2419 |
|
| 2420 |
bool isConstructing() const { return construct_; } |
| 2421 |
|
| 2422 |
bool ignoresReturnValue() const { return ignoresReturnValue_; } |
| 2423 |
|
| 2424 |
// Does not include |this|. |
| 2425 |
uint32_t numActualArgs() const { return numActualArgs_; } |
| 2426 |
|
| 2427 |
bool possiblyCalls() const override { return true; } |
| 2428 |
|
| 2429 |
virtual bool isCallDOMNative() const { return false; } |
| 2430 |
|
| 2431 |
// A method that can be called to tell the MCall to figure out whether it's |
| 2432 |
// movable or not. This can't be done in the constructor, because it |
| 2433 |
// depends on the arguments to the call, and those aren't passed to the |
| 2434 |
// constructor but are set up later via addArg. |
| 2435 |
virtual void computeMovable() {} |
| 2436 |
}; |
| 2437 |
|
| 2438 |
class MCallDOMNative : public MCall { |
| 2439 |
// A helper class for MCalls for DOM natives. Note that this is NOT |
| 2440 |
// actually a separate MIR op from MCall, because all sorts of places use |
| 2441 |
// isCall() to check for calls and all we really want is to overload a few |
| 2442 |
// virtual things from MCall. |
| 2443 |
|
| 2444 |
DOMObjectKind objectKind_; |
| 2445 |
|
| 2446 |
// Allow wrapper pre-tenuring |
| 2447 |
gc::Heap initialHeap_ = gc::Heap::Default; |
| 2448 |
|
| 2449 |
MCallDOMNative(WrappedFunction* target, uint32_t numActualArgs, |
| 2450 |
DOMObjectKind objectKind, gc::Heap initialHeap) |
| 2451 |
: MCall(target, numActualArgs, false, false), |
| 2452 |
objectKind_(objectKind), |
| 2453 |
initialHeap_(initialHeap) { |
| 2454 |
MOZ_ASSERT(getJitInfo()->type() != JSJitInfo::InlinableNative); |
| 2455 |
|
| 2456 |
// If our jitinfo is not marked eliminatable, that means that our C++ |
| 2457 |
// implementation is fallible or that it never wants to be eliminated or |
| 2458 |
// that we have no hope of ever doing the sort of argument analysis that |
| 2459 |
// would allow us to detemine that we're side-effect-free. In the |
| 2460 |
// latter case we wouldn't get DCEd no matter what, but for the former |
| 2461 |
// two cases we have to explicitly say that we can't be DCEd. |
| 2462 |
if (!getJitInfo()->isEliminatable) { |
| 2463 |
setGuard(); |
| 2464 |
} |
| 2465 |
} |
| 2466 |
|
| 2467 |
friend MCall* MCall::New(TempAllocator& alloc, WrappedFunction* target, |
| 2468 |
size_t maxArgc, size_t numActualArgs, bool construct, |
| 2469 |
bool ignoresReturnValue, bool isDOMCall, |
| 2470 |
mozilla::Maybe<DOMObjectKind> objectKind, |
| 2471 |
mozilla::Maybe<gc::Heap> initalHeap); |
| 2472 |
|
| 2473 |
const JSJitInfo* getJitInfo() const; |
| 2474 |
|
| 2475 |
public: |
| 2476 |
DOMObjectKind objectKind() const { return objectKind_; } |
| 2477 |
|
| 2478 |
virtual AliasSet getAliasSet() const override; |
| 2479 |
|
| 2480 |
virtual bool congruentTo(const MDefinition* ins) const override; |
| 2481 |
|
| 2482 |
virtual bool isCallDOMNative() const override { return true; } |
| 2483 |
|
| 2484 |
virtual void computeMovable() override; |
| 2485 |
|
| 2486 |
gc::Heap initialHeap() { return initialHeap_; } |
| 2487 |
}; |
| 2488 |
|
| 2489 |
// Used to invoke a JSClass call/construct hook. |
| 2490 |
class MCallClassHook : public MCallBase { |
| 2491 |
const JSNative target_; |
| 2492 |
bool constructing_ : 1; |
| 2493 |
bool ignoresReturnValue_ : 1; |
| 2494 |
|
| 2495 |
MCallClassHook(JSNative target, bool constructing) |
| 2496 |
: MCallBase(classOpcode), |
| 2497 |
target_(target), |
| 2498 |
constructing_(constructing), |
| 2499 |
ignoresReturnValue_(false) { |
| 2500 |
setResultType(MIRType::Value); |
| 2501 |
} |
| 2502 |
|
| 2503 |
public: |
| 2504 |
INSTRUCTION_HEADER(CallClassHook) |
| 2505 |
static MCallClassHook* New(TempAllocator& alloc, JSNative target, |
| 2506 |
uint32_t argc, bool constructing); |
| 2507 |
|
| 2508 |
JSNative target() const { return target_; } |
| 2509 |
bool isConstructing() const { return constructing_; } |
| 2510 |
|
| 2511 |
uint32_t numActualArgs() const { |
| 2512 |
uint32_t thisAndNewTarget = 1 + constructing_; |
| 2513 |
MOZ_ASSERT(numStackArgs() >= thisAndNewTarget); |
| 2514 |
return numStackArgs() - thisAndNewTarget; |
| 2515 |
} |
| 2516 |
|
| 2517 |
bool maybeCrossRealm() const { return true; } |
| 2518 |
|
| 2519 |
bool ignoresReturnValue() const { return ignoresReturnValue_; } |
| 2520 |
void setIgnoresReturnValue() { ignoresReturnValue_ = true; } |
| 2521 |
|
| 2522 |
bool possiblyCalls() const override { return true; } |
| 2523 |
}; |
| 2524 |
|
| 2525 |
// fun.apply(self, arguments) |
| 2526 |
class MApplyArgs : public MTernaryInstruction, |
| 2527 |
public MixPolicy<ObjectPolicy<0>, UnboxedInt32Policy<1>, |
| 2528 |
BoxPolicy<2>>::Data { |
| 2529 |
// Single target from CacheIR, or nullptr |
| 2530 |
WrappedFunction* target_; |
| 2531 |
// Number of extra initial formals to skip. |
| 2532 |
uint32_t numExtraFormals_; |
| 2533 |
bool maybeCrossRealm_ = true; |
| 2534 |
bool ignoresReturnValue_ = false; |
| 2535 |
|
| 2536 |
MApplyArgs(WrappedFunction* target, MDefinition* fun, MDefinition* argc, |
| 2537 |
MDefinition* self, uint32_t numExtraFormals = 0) |
| 2538 |
: MTernaryInstruction(classOpcode, fun, argc, self), |
| 2539 |
target_(target), |
| 2540 |
numExtraFormals_(numExtraFormals) { |
| 2541 |
MOZ_ASSERT(argc->type() == MIRType::Int32); |
| 2542 |
setResultType(MIRType::Value); |
| 2543 |
} |
| 2544 |
|
| 2545 |
public: |
| 2546 |
INSTRUCTION_HEADER(ApplyArgs) |
| 2547 |
TRIVIAL_NEW_WRAPPERS |
| 2548 |
NAMED_OPERANDS((0, getFunction), (1, getArgc), (2, getThis)) |
| 2549 |
|
| 2550 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2551 |
|
| 2552 |
uint32_t numExtraFormals() const { return numExtraFormals_; } |
| 2553 |
|
| 2554 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2555 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2556 |
|
| 2557 |
bool ignoresReturnValue() const { return ignoresReturnValue_; } |
| 2558 |
void setIgnoresReturnValue() { ignoresReturnValue_ = true; } |
| 2559 |
|
| 2560 |
bool isConstructing() const { return false; } |
| 2561 |
|
| 2562 |
bool possiblyCalls() const override { return true; } |
| 2563 |
}; |
| 2564 |
|
| 2565 |
class MApplyArgsObj |
| 2566 |
: public MTernaryInstruction, |
| 2567 |
public MixPolicy<ObjectPolicy<0>, ObjectPolicy<1>, BoxPolicy<2>>::Data { |
| 2568 |
WrappedFunction* target_; |
| 2569 |
bool maybeCrossRealm_ = true; |
| 2570 |
bool ignoresReturnValue_ = false; |
| 2571 |
|
| 2572 |
MApplyArgsObj(WrappedFunction* target, MDefinition* fun, MDefinition* argsObj, |
| 2573 |
MDefinition* thisArg) |
| 2574 |
: MTernaryInstruction(classOpcode, fun, argsObj, thisArg), |
| 2575 |
target_(target) { |
| 2576 |
MOZ_ASSERT(argsObj->type() == MIRType::Object); |
| 2577 |
setResultType(MIRType::Value); |
| 2578 |
} |
| 2579 |
|
| 2580 |
public: |
| 2581 |
INSTRUCTION_HEADER(ApplyArgsObj) |
| 2582 |
TRIVIAL_NEW_WRAPPERS |
| 2583 |
NAMED_OPERANDS((0, getFunction), (1, getArgsObj), (2, getThis)) |
| 2584 |
|
| 2585 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2586 |
|
| 2587 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2588 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2589 |
|
| 2590 |
bool ignoresReturnValue() const { return ignoresReturnValue_; } |
| 2591 |
void setIgnoresReturnValue() { ignoresReturnValue_ = true; } |
| 2592 |
|
| 2593 |
bool isConstructing() const { return false; } |
| 2594 |
|
| 2595 |
bool possiblyCalls() const override { return true; } |
| 2596 |
}; |
| 2597 |
|
| 2598 |
// fun.apply(fn, array) |
| 2599 |
class MApplyArray : public MTernaryInstruction, |
| 2600 |
public MixPolicy<ObjectPolicy<0>, BoxPolicy<2>>::Data { |
| 2601 |
// Single target from CacheIR, or nullptr |
| 2602 |
WrappedFunction* target_; |
| 2603 |
bool maybeCrossRealm_ = true; |
| 2604 |
bool ignoresReturnValue_ = false; |
| 2605 |
|
| 2606 |
MApplyArray(WrappedFunction* target, MDefinition* fun, MDefinition* elements, |
| 2607 |
MDefinition* self) |
| 2608 |
: MTernaryInstruction(classOpcode, fun, elements, self), target_(target) { |
| 2609 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 2610 |
setResultType(MIRType::Value); |
| 2611 |
} |
| 2612 |
|
| 2613 |
public: |
| 2614 |
INSTRUCTION_HEADER(ApplyArray) |
| 2615 |
TRIVIAL_NEW_WRAPPERS |
| 2616 |
NAMED_OPERANDS((0, getFunction), (1, getElements), (2, getThis)) |
| 2617 |
|
| 2618 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2619 |
|
| 2620 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2621 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2622 |
|
| 2623 |
bool ignoresReturnValue() const { return ignoresReturnValue_; } |
| 2624 |
void setIgnoresReturnValue() { ignoresReturnValue_ = true; } |
| 2625 |
|
| 2626 |
bool isConstructing() const { return false; } |
| 2627 |
|
| 2628 |
bool possiblyCalls() const override { return true; } |
| 2629 |
}; |
| 2630 |
|
| 2631 |
// |new F(...arguments)| and |super(...arguments)|. |
| 2632 |
class MConstructArgs : public MQuaternaryInstruction, |
| 2633 |
public MixPolicy<ObjectPolicy<0>, UnboxedInt32Policy<1>, |
| 2634 |
BoxPolicy<2>, ObjectPolicy<3>>::Data { |
| 2635 |
// Single target from CacheIR, or nullptr |
| 2636 |
WrappedFunction* target_; |
| 2637 |
// Number of extra initial formals to skip. |
| 2638 |
uint32_t numExtraFormals_; |
| 2639 |
bool maybeCrossRealm_ = true; |
| 2640 |
|
| 2641 |
MConstructArgs(WrappedFunction* target, MDefinition* fun, MDefinition* argc, |
| 2642 |
MDefinition* thisValue, MDefinition* newTarget, |
| 2643 |
uint32_t numExtraFormals = 0) |
| 2644 |
: MQuaternaryInstruction(classOpcode, fun, argc, thisValue, newTarget), |
| 2645 |
target_(target), |
| 2646 |
numExtraFormals_(numExtraFormals) { |
| 2647 |
MOZ_ASSERT(argc->type() == MIRType::Int32); |
| 2648 |
setResultType(MIRType::Value); |
| 2649 |
} |
| 2650 |
|
| 2651 |
public: |
| 2652 |
INSTRUCTION_HEADER(ConstructArgs) |
| 2653 |
TRIVIAL_NEW_WRAPPERS |
| 2654 |
NAMED_OPERANDS((0, getFunction), (1, getArgc), (2, getThis), |
| 2655 |
(3, getNewTarget)) |
| 2656 |
|
| 2657 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2658 |
|
| 2659 |
uint32_t numExtraFormals() const { return numExtraFormals_; } |
| 2660 |
|
| 2661 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2662 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2663 |
|
| 2664 |
bool ignoresReturnValue() const { return false; } |
| 2665 |
bool isConstructing() const { return true; } |
| 2666 |
|
| 2667 |
bool possiblyCalls() const override { return true; } |
| 2668 |
}; |
| 2669 |
|
| 2670 |
// |new F(...args)| and |super(...args)|. |
| 2671 |
class MConstructArray |
| 2672 |
: public MQuaternaryInstruction, |
| 2673 |
public MixPolicy<ObjectPolicy<0>, BoxPolicy<2>, ObjectPolicy<3>>::Data { |
| 2674 |
// Single target from CacheIR, or nullptr |
| 2675 |
WrappedFunction* target_; |
| 2676 |
bool maybeCrossRealm_ = true; |
| 2677 |
bool needsThisCheck_ = false; |
| 2678 |
|
| 2679 |
MConstructArray(WrappedFunction* target, MDefinition* fun, |
| 2680 |
MDefinition* elements, MDefinition* thisValue, |
| 2681 |
MDefinition* newTarget) |
| 2682 |
: MQuaternaryInstruction(classOpcode, fun, elements, thisValue, |
| 2683 |
newTarget), |
| 2684 |
target_(target) { |
| 2685 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 2686 |
setResultType(MIRType::Value); |
| 2687 |
} |
| 2688 |
|
| 2689 |
public: |
| 2690 |
INSTRUCTION_HEADER(ConstructArray) |
| 2691 |
TRIVIAL_NEW_WRAPPERS |
| 2692 |
NAMED_OPERANDS((0, getFunction), (1, getElements), (2, getThis), |
| 2693 |
(3, getNewTarget)) |
| 2694 |
|
| 2695 |
WrappedFunction* getSingleTarget() const { return target_; } |
| 2696 |
|
| 2697 |
bool maybeCrossRealm() const { return maybeCrossRealm_; } |
| 2698 |
void setNotCrossRealm() { maybeCrossRealm_ = false; } |
| 2699 |
|
| 2700 |
bool needsThisCheck() const { return needsThisCheck_; } |
| 2701 |
void setNeedsThisCheck() { needsThisCheck_ = true; } |
| 2702 |
|
| 2703 |
bool ignoresReturnValue() const { return false; } |
| 2704 |
bool isConstructing() const { return true; } |
| 2705 |
|
| 2706 |
bool possiblyCalls() const override { return true; } |
| 2707 |
}; |
| 2708 |
|
| 2709 |
class MBail : public MNullaryInstruction { |
| 2710 |
explicit MBail(BailoutKind kind) : MNullaryInstruction(classOpcode) { |
| 2711 |
setBailoutKind(kind); |
| 2712 |
setGuard(); |
| 2713 |
} |
| 2714 |
|
| 2715 |
public: |
| 2716 |
INSTRUCTION_HEADER(Bail) |
| 2717 |
|
| 2718 |
static MBail* New(TempAllocator& alloc, BailoutKind kind) { |
| 2719 |
return new (alloc) MBail(kind); |
| 2720 |
} |
| 2721 |
static MBail* New(TempAllocator& alloc) { |
| 2722 |
return new (alloc) MBail(BailoutKind::Inevitable); |
| 2723 |
} |
| 2724 |
|
| 2725 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2726 |
}; |
| 2727 |
|
| 2728 |
class MUnreachable : public MAryControlInstruction<0, 0>, |
| 2729 |
public NoTypePolicy::Data { |
| 2730 |
MUnreachable() : MAryControlInstruction(classOpcode) {} |
| 2731 |
|
| 2732 |
public: |
| 2733 |
INSTRUCTION_HEADER(Unreachable) |
| 2734 |
TRIVIAL_NEW_WRAPPERS |
| 2735 |
|
| 2736 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2737 |
}; |
| 2738 |
|
| 2739 |
class MAssertRecoveredOnBailout : public MUnaryInstruction, |
| 2740 |
public NoTypePolicy::Data { |
| 2741 |
bool mustBeRecovered_; |
| 2742 |
|
| 2743 |
MAssertRecoveredOnBailout(MDefinition* ins, bool mustBeRecovered) |
| 2744 |
: MUnaryInstruction(classOpcode, ins), mustBeRecovered_(mustBeRecovered) { |
| 2745 |
setResultType(MIRType::Value); |
| 2746 |
setRecoveredOnBailout(); |
| 2747 |
setGuard(); |
| 2748 |
} |
| 2749 |
|
| 2750 |
public: |
| 2751 |
INSTRUCTION_HEADER(AssertRecoveredOnBailout) |
| 2752 |
TRIVIAL_NEW_WRAPPERS |
| 2753 |
|
| 2754 |
// Needed to assert that float32 instructions are correctly recovered. |
| 2755 |
bool canConsumeFloat32(MUse* use) const override { return true; } |
| 2756 |
|
| 2757 |
[[nodiscard]] bool writeRecoverData( |
| 2758 |
CompactBufferWriter& writer) const override; |
| 2759 |
bool canRecoverOnBailout() const override { return true; } |
| 2760 |
}; |
| 2761 |
|
| 2762 |
class MAssertFloat32 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 2763 |
bool mustBeFloat32_; |
| 2764 |
|
| 2765 |
MAssertFloat32(MDefinition* value, bool mustBeFloat32) |
| 2766 |
: MUnaryInstruction(classOpcode, value), mustBeFloat32_(mustBeFloat32) {} |
| 2767 |
|
| 2768 |
public: |
| 2769 |
INSTRUCTION_HEADER(AssertFloat32) |
| 2770 |
TRIVIAL_NEW_WRAPPERS |
| 2771 |
|
| 2772 |
bool canConsumeFloat32(MUse* use) const override { return true; } |
| 2773 |
|
| 2774 |
bool mustBeFloat32() const { return mustBeFloat32_; } |
| 2775 |
}; |
| 2776 |
|
| 2777 |
class MCompare : public MBinaryInstruction, public ComparePolicy::Data { |
| 2778 |
public: |
| 2779 |
enum CompareType { |
| 2780 |
|
| 2781 |
// Anything compared to Undefined |
| 2782 |
Compare_Undefined, |
| 2783 |
|
| 2784 |
// Anything compared to Null |
| 2785 |
Compare_Null, |
| 2786 |
|
| 2787 |
// Int32 compared to Int32 |
| 2788 |
// Boolean compared to Boolean |
| 2789 |
Compare_Int32, |
| 2790 |
|
| 2791 |
// Int32 compared as unsigneds |
| 2792 |
Compare_UInt32, |
| 2793 |
|
| 2794 |
// Int64 compared to Int64. |
| 2795 |
Compare_Int64, |
| 2796 |
|
| 2797 |
// Int64 compared as unsigneds. |
| 2798 |
Compare_UInt64, |
| 2799 |
|
| 2800 |
// IntPtr compared to IntPtr. |
| 2801 |
Compare_IntPtr, |
| 2802 |
|
| 2803 |
// IntPtr compared as unsigneds. |
| 2804 |
Compare_UIntPtr, |
| 2805 |
|
| 2806 |
// Double compared to Double |
| 2807 |
Compare_Double, |
| 2808 |
|
| 2809 |
// Float compared to Float |
| 2810 |
Compare_Float32, |
| 2811 |
|
| 2812 |
// String compared to String |
| 2813 |
Compare_String, |
| 2814 |
|
| 2815 |
// Symbol compared to Symbol |
| 2816 |
Compare_Symbol, |
| 2817 |
|
| 2818 |
// Object compared to Object |
| 2819 |
Compare_Object, |
| 2820 |
|
| 2821 |
// BigInt compared to BigInt |
| 2822 |
Compare_BigInt, |
| 2823 |
|
| 2824 |
// BigInt compared to Int32 |
| 2825 |
Compare_BigInt_Int32, |
| 2826 |
|
| 2827 |
// BigInt compared to Double |
| 2828 |
Compare_BigInt_Double, |
| 2829 |
|
| 2830 |
// BigInt compared to String |
| 2831 |
Compare_BigInt_String, |
| 2832 |
|
| 2833 |
// Wasm Ref/AnyRef/NullRef compared to Ref/AnyRef/NullRef |
| 2834 |
Compare_WasmAnyRef, |
| 2835 |
}; |
| 2836 |
|
| 2837 |
private: |
| 2838 |
CompareType compareType_; |
| 2839 |
JSOp jsop_; |
| 2840 |
bool operandsAreNeverNaN_; |
| 2841 |
|
| 2842 |
// When a floating-point comparison is converted to an integer comparison |
| 2843 |
// (when range analysis proves it safe), we need to convert the operands |
| 2844 |
// to integer as well. |
| 2845 |
bool truncateOperands_; |
| 2846 |
|
| 2847 |
MCompare(MDefinition* left, MDefinition* right, JSOp jsop, |
| 2848 |
CompareType compareType) |
| 2849 |
: MBinaryInstruction(classOpcode, left, right), |
| 2850 |
compareType_(compareType), |
| 2851 |
jsop_(jsop), |
| 2852 |
operandsAreNeverNaN_(false), |
| 2853 |
truncateOperands_(false) { |
| 2854 |
setResultType(MIRType::Boolean); |
| 2855 |
setMovable(); |
| 2856 |
} |
| 2857 |
|
| 2858 |
public: |
| 2859 |
INSTRUCTION_HEADER(Compare) |
| 2860 |
TRIVIAL_NEW_WRAPPERS |
| 2861 |
|
| 2862 |
static MCompare* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 2863 |
MDefinition* right, JSOp jsop, |
| 2864 |
CompareType compareType) { |
| 2865 |
MOZ_ASSERT(compareType == Compare_Int32 || compareType == Compare_UInt32 || |
| 2866 |
compareType == Compare_Int64 || compareType == Compare_UInt64 || |
| 2867 |
compareType == Compare_Double || |
| 2868 |
compareType == Compare_Float32 || |
| 2869 |
compareType == Compare_WasmAnyRef); |
| 2870 |
auto* ins = MCompare::New(alloc, left, right, jsop, compareType); |
| 2871 |
ins->setResultType(MIRType::Int32); |
| 2872 |
return ins; |
| 2873 |
} |
| 2874 |
|
| 2875 |
[[nodiscard]] bool tryFold(bool* result); |
| 2876 |
[[nodiscard]] bool evaluateConstantOperands(TempAllocator& alloc, |
| 2877 |
bool* result); |
| 2878 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 2879 |
|
| 2880 |
CompareType compareType() const { return compareType_; } |
| 2881 |
bool isInt32Comparison() const { return compareType() == Compare_Int32; } |
| 2882 |
bool isDoubleComparison() const { return compareType() == Compare_Double; } |
| 2883 |
bool isFloat32Comparison() const { return compareType() == Compare_Float32; } |
| 2884 |
bool isNumericComparison() const { |
| 2885 |
return isInt32Comparison() || isDoubleComparison() || isFloat32Comparison(); |
| 2886 |
} |
| 2887 |
|
| 2888 |
JSOp jsop() const { return jsop_; } |
| 2889 |
bool operandsAreNeverNaN() const { return operandsAreNeverNaN_; } |
| 2890 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 2891 |
|
| 2892 |
#ifdef JS_JITSPEW |
| 2893 |
void printOpcode(GenericPrinter& out) const override; |
| 2894 |
#endif |
| 2895 |
void collectRangeInfoPreTrunc() override; |
| 2896 |
|
| 2897 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 2898 |
bool isFloat32Commutative() const override { return true; } |
| 2899 |
bool canTruncate() const override; |
| 2900 |
void truncate(TruncateKind kind) override; |
| 2901 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 2902 |
|
| 2903 |
#ifdef DEBUG |
| 2904 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 2905 |
// Both sides of the compare can be Float32 |
| 2906 |
return compareType_ == Compare_Float32; |
| 2907 |
} |
| 2908 |
#endif |
| 2909 |
|
| 2910 |
ALLOW_CLONE(MCompare) |
| 2911 |
|
| 2912 |
private: |
| 2913 |
[[nodiscard]] bool tryFoldEqualOperands(bool* result); |
| 2914 |
[[nodiscard]] bool tryFoldTypeOf(bool* result); |
| 2915 |
[[nodiscard]] MDefinition* tryFoldTypeOf(TempAllocator& alloc); |
| 2916 |
[[nodiscard]] MDefinition* tryFoldCharCompare(TempAllocator& alloc); |
| 2917 |
[[nodiscard]] MDefinition* tryFoldStringCompare(TempAllocator& alloc); |
| 2918 |
[[nodiscard]] MDefinition* tryFoldStringSubstring(TempAllocator& alloc); |
| 2919 |
[[nodiscard]] MDefinition* tryFoldStringIndexOf(TempAllocator& alloc); |
| 2920 |
[[nodiscard]] MDefinition* tryFoldBigInt64(TempAllocator& alloc); |
| 2921 |
[[nodiscard]] MDefinition* tryFoldBigIntPtr(TempAllocator& alloc); |
| 2922 |
[[nodiscard]] MDefinition* tryFoldBigInt(TempAllocator& alloc); |
| 2923 |
|
| 2924 |
public: |
| 2925 |
bool congruentTo(const MDefinition* ins) const override { |
| 2926 |
if (!binaryCongruentTo(ins)) { |
| 2927 |
return false; |
| 2928 |
} |
| 2929 |
return compareType() == ins->toCompare()->compareType() && |
| 2930 |
jsop() == ins->toCompare()->jsop(); |
| 2931 |
} |
| 2932 |
|
| 2933 |
[[nodiscard]] bool writeRecoverData( |
| 2934 |
CompactBufferWriter& writer) const override; |
| 2935 |
bool canRecoverOnBailout() const override { |
| 2936 |
switch (compareType_) { |
| 2937 |
case Compare_Undefined: |
| 2938 |
case Compare_Null: |
| 2939 |
case Compare_Int32: |
| 2940 |
case Compare_UInt32: |
| 2941 |
case Compare_Double: |
| 2942 |
case Compare_Float32: |
| 2943 |
case Compare_String: |
| 2944 |
case Compare_Symbol: |
| 2945 |
case Compare_Object: |
| 2946 |
case Compare_BigInt: |
| 2947 |
case Compare_BigInt_Int32: |
| 2948 |
case Compare_BigInt_Double: |
| 2949 |
case Compare_BigInt_String: |
| 2950 |
return true; |
| 2951 |
|
| 2952 |
case Compare_Int64: |
| 2953 |
case Compare_UInt64: |
| 2954 |
case Compare_IntPtr: |
| 2955 |
case Compare_UIntPtr: |
| 2956 |
case Compare_WasmAnyRef: |
| 2957 |
return false; |
| 2958 |
} |
| 2959 |
MOZ_CRASH("unexpected compare type"); |
| 2960 |
} |
| 2961 |
|
| 2962 |
#ifdef JS_JITSPEW |
| 2963 |
void getExtras(ExtrasCollector* extras) const override { |
| 2964 |
const char* ty = nullptr; |
| 2965 |
switch (compareType_) { |
| 2966 |
case Compare_Undefined: |
| 2967 |
ty = "Undefined"; |
| 2968 |
break; |
| 2969 |
case Compare_Null: |
| 2970 |
ty = "Null"; |
| 2971 |
break; |
| 2972 |
case Compare_Int32: |
| 2973 |
ty = "Int32"; |
| 2974 |
break; |
| 2975 |
case Compare_UInt32: |
| 2976 |
ty = "UInt32"; |
| 2977 |
break; |
| 2978 |
case Compare_Int64: |
| 2979 |
ty = "Int64"; |
| 2980 |
break; |
| 2981 |
case Compare_UInt64: |
| 2982 |
ty = "UInt64"; |
| 2983 |
break; |
| 2984 |
case Compare_IntPtr: |
| 2985 |
ty = "IntPtr"; |
| 2986 |
break; |
| 2987 |
case Compare_UIntPtr: |
| 2988 |
ty = "UIntPtr"; |
| 2989 |
break; |
| 2990 |
case Compare_Double: |
| 2991 |
ty = "Double"; |
| 2992 |
break; |
| 2993 |
case Compare_Float32: |
| 2994 |
ty = "Float32"; |
| 2995 |
break; |
| 2996 |
case Compare_String: |
| 2997 |
ty = "String"; |
| 2998 |
break; |
| 2999 |
case Compare_Symbol: |
| 3000 |
ty = "Symbol"; |
| 3001 |
break; |
| 3002 |
case Compare_Object: |
| 3003 |
ty = "Object"; |
| 3004 |
break; |
| 3005 |
case Compare_BigInt: |
| 3006 |
ty = "BigInt"; |
| 3007 |
break; |
| 3008 |
case Compare_BigInt_Int32: |
| 3009 |
ty = "BigInt_Int32"; |
| 3010 |
break; |
| 3011 |
case Compare_BigInt_Double: |
| 3012 |
ty = "BigInt_Double"; |
| 3013 |
break; |
| 3014 |
case Compare_BigInt_String: |
| 3015 |
ty = "BigInt_String"; |
| 3016 |
break; |
| 3017 |
case Compare_WasmAnyRef: |
| 3018 |
ty = "WasmAnyRef"; |
| 3019 |
break; |
| 3020 |
default: |
| 3021 |
ty = "!!unknown!!"; |
| 3022 |
break; |
| 3023 |
}; |
| 3024 |
char buf[64]; |
| 3025 |
SprintfLiteral(buf, "ty=%s jsop=%s", ty, CodeName(jsop())); |
| 3026 |
extras->add(buf); |
| 3027 |
} |
| 3028 |
#endif |
| 3029 |
}; |
| 3030 |
|
| 3031 |
// Takes a typed value and returns an untyped value. |
| 3032 |
class MBox : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3033 |
explicit MBox(MDefinition* ins) : MUnaryInstruction(classOpcode, ins) { |
| 3034 |
// Cannot box a box. |
| 3035 |
MOZ_ASSERT(ins->type() != MIRType::Value); |
| 3036 |
|
| 3037 |
setResultType(MIRType::Value); |
| 3038 |
setMovable(); |
| 3039 |
} |
| 3040 |
|
| 3041 |
public: |
| 3042 |
INSTRUCTION_HEADER(Box) |
| 3043 |
TRIVIAL_NEW_WRAPPERS |
| 3044 |
|
| 3045 |
bool congruentTo(const MDefinition* ins) const override { |
| 3046 |
return congruentIfOperandsEqual(ins); |
| 3047 |
} |
| 3048 |
|
| 3049 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3050 |
|
| 3051 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3052 |
|
| 3053 |
ALLOW_CLONE(MBox) |
| 3054 |
}; |
| 3055 |
|
| 3056 |
// Note: the op may have been inverted during lowering (to put constants in a |
| 3057 |
// position where they can be immediates), so it is important to use the |
| 3058 |
// lir->jsop() instead of the mir->jsop() when it is present. |
| 3059 |
static inline Assembler::Condition JSOpToCondition( |
| 3060 |
MCompare::CompareType compareType, JSOp op) { |
| 3061 |
bool isSigned = (compareType != MCompare::Compare_UInt32 && |
| 3062 |
compareType != MCompare::Compare_UInt64 && |
| 3063 |
compareType != MCompare::Compare_UIntPtr); |
| 3064 |
return JSOpToCondition(op, isSigned); |
| 3065 |
} |
| 3066 |
|
| 3067 |
// Takes a typed value and checks if it is a certain type. If so, the payload |
| 3068 |
// is unpacked and returned as that type. Otherwise, it is considered a |
| 3069 |
// deoptimization. |
| 3070 |
class MUnbox final : public MUnaryInstruction, public BoxInputsPolicy::Data { |
| 3071 |
public: |
| 3072 |
enum Mode { |
| 3073 |
Fallible, // Check the type, and deoptimize if unexpected. |
| 3074 |
Infallible, // Type guard is not necessary. |
| 3075 |
}; |
| 3076 |
|
| 3077 |
private: |
| 3078 |
Mode mode_; |
| 3079 |
|
| 3080 |
MUnbox(MDefinition* ins, MIRType type, Mode mode) |
| 3081 |
: MUnaryInstruction(classOpcode, ins), mode_(mode) { |
| 3082 |
// Only allow unboxing a non MIRType::Value when input and output types |
| 3083 |
// don't match. This is often used to force a bailout. Boxing happens |
| 3084 |
// during type analysis. |
| 3085 |
MOZ_ASSERT_IF(ins->type() != MIRType::Value, type != ins->type()); |
| 3086 |
|
| 3087 |
MOZ_ASSERT(type == MIRType::Boolean || type == MIRType::Int32 || |
| 3088 |
type == MIRType::Double || type == MIRType::String || |
| 3089 |
type == MIRType::Symbol || type == MIRType::BigInt || |
| 3090 |
type == MIRType::Object); |
| 3091 |
|
| 3092 |
setResultType(type); |
| 3093 |
setMovable(); |
| 3094 |
|
| 3095 |
if (mode_ == Fallible) { |
| 3096 |
setGuard(); |
| 3097 |
} |
| 3098 |
} |
| 3099 |
|
| 3100 |
public: |
| 3101 |
INSTRUCTION_HEADER(Unbox) |
| 3102 |
TRIVIAL_NEW_WRAPPERS |
| 3103 |
|
| 3104 |
Mode mode() const { return mode_; } |
| 3105 |
bool fallible() const { return mode() != Infallible; } |
| 3106 |
bool congruentTo(const MDefinition* ins) const override { |
| 3107 |
if (!ins->isUnbox() || ins->toUnbox()->mode() != mode()) { |
| 3108 |
return false; |
| 3109 |
} |
| 3110 |
return congruentIfOperandsEqual(ins); |
| 3111 |
} |
| 3112 |
|
| 3113 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3114 |
|
| 3115 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3116 |
#ifdef JS_JITSPEW |
| 3117 |
void printOpcode(GenericPrinter& out) const override; |
| 3118 |
#endif |
| 3119 |
|
| 3120 |
ALLOW_CLONE(MUnbox) |
| 3121 |
}; |
| 3122 |
|
| 3123 |
class MAssertRange : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3124 |
// This is the range checked by the assertion. Don't confuse this with the |
| 3125 |
// range_ member or the range() accessor. Since MAssertRange doesn't return |
| 3126 |
// a value, it doesn't use those. |
| 3127 |
const Range* assertedRange_; |
| 3128 |
|
| 3129 |
MAssertRange(MDefinition* ins, const Range* assertedRange) |
| 3130 |
: MUnaryInstruction(classOpcode, ins), assertedRange_(assertedRange) { |
| 3131 |
setGuard(); |
| 3132 |
setResultType(MIRType::None); |
| 3133 |
} |
| 3134 |
|
| 3135 |
public: |
| 3136 |
INSTRUCTION_HEADER(AssertRange) |
| 3137 |
TRIVIAL_NEW_WRAPPERS |
| 3138 |
|
| 3139 |
const Range* assertedRange() const { return assertedRange_; } |
| 3140 |
|
| 3141 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3142 |
|
| 3143 |
#ifdef JS_JITSPEW |
| 3144 |
void printOpcode(GenericPrinter& out) const override; |
| 3145 |
#endif |
| 3146 |
}; |
| 3147 |
|
| 3148 |
class MAssertClass : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3149 |
const JSClass* class_; |
| 3150 |
|
| 3151 |
MAssertClass(MDefinition* obj, const JSClass* clasp) |
| 3152 |
: MUnaryInstruction(classOpcode, obj), class_(clasp) { |
| 3153 |
MOZ_ASSERT(obj->type() == MIRType::Object); |
| 3154 |
|
| 3155 |
setGuard(); |
| 3156 |
setResultType(MIRType::None); |
| 3157 |
} |
| 3158 |
|
| 3159 |
public: |
| 3160 |
INSTRUCTION_HEADER(AssertClass) |
| 3161 |
TRIVIAL_NEW_WRAPPERS |
| 3162 |
|
| 3163 |
const JSClass* getClass() const { return class_; } |
| 3164 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3165 |
}; |
| 3166 |
|
| 3167 |
class MAssertShape : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3168 |
CompilerShape shape_; |
| 3169 |
|
| 3170 |
MAssertShape(MDefinition* obj, Shape* shape) |
| 3171 |
: MUnaryInstruction(classOpcode, obj), shape_(shape) { |
| 3172 |
MOZ_ASSERT(obj->type() == MIRType::Object); |
| 3173 |
|
| 3174 |
setGuard(); |
| 3175 |
setResultType(MIRType::None); |
| 3176 |
} |
| 3177 |
|
| 3178 |
public: |
| 3179 |
INSTRUCTION_HEADER(AssertShape) |
| 3180 |
TRIVIAL_NEW_WRAPPERS |
| 3181 |
|
| 3182 |
const Shape* shape() const { return shape_; } |
| 3183 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3184 |
}; |
| 3185 |
|
| 3186 |
// Eager initialization of arguments object. |
| 3187 |
class MCreateArgumentsObject : public MUnaryInstruction, |
| 3188 |
public ObjectPolicy<0>::Data { |
| 3189 |
CompilerGCPointer<ArgumentsObject*> templateObj_; |
| 3190 |
|
| 3191 |
MCreateArgumentsObject(MDefinition* callObj, ArgumentsObject* templateObj) |
| 3192 |
: MUnaryInstruction(classOpcode, callObj), templateObj_(templateObj) { |
| 3193 |
setResultType(MIRType::Object); |
| 3194 |
} |
| 3195 |
|
| 3196 |
public: |
| 3197 |
INSTRUCTION_HEADER(CreateArgumentsObject) |
| 3198 |
TRIVIAL_NEW_WRAPPERS |
| 3199 |
NAMED_OPERANDS((0, getCallObject)) |
| 3200 |
|
| 3201 |
ArgumentsObject* templateObject() const { return templateObj_; } |
| 3202 |
|
| 3203 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3204 |
|
| 3205 |
bool possiblyCalls() const override { return true; } |
| 3206 |
|
| 3207 |
[[nodiscard]] bool writeRecoverData( |
| 3208 |
CompactBufferWriter& writer) const override; |
| 3209 |
bool canRecoverOnBailout() const override { return true; } |
| 3210 |
}; |
| 3211 |
|
| 3212 |
// Eager initialization of arguments object for inlined function |
| 3213 |
class MCreateInlinedArgumentsObject : public MVariadicInstruction, |
| 3214 |
public NoFloatPolicyAfter<0>::Data { |
| 3215 |
CompilerGCPointer<ArgumentsObject*> templateObj_; |
| 3216 |
|
| 3217 |
explicit MCreateInlinedArgumentsObject(ArgumentsObject* templateObj) |
| 3218 |
: MVariadicInstruction(classOpcode), templateObj_(templateObj) { |
| 3219 |
setResultType(MIRType::Object); |
| 3220 |
} |
| 3221 |
|
| 3222 |
static const size_t NumNonArgumentOperands = 2; |
| 3223 |
|
| 3224 |
public: |
| 3225 |
INSTRUCTION_HEADER(CreateInlinedArgumentsObject) |
| 3226 |
static MCreateInlinedArgumentsObject* New(TempAllocator& alloc, |
| 3227 |
MDefinition* callObj, |
| 3228 |
MDefinition* callee, |
| 3229 |
MDefinitionVector& args, |
| 3230 |
ArgumentsObject* templateObj); |
| 3231 |
NAMED_OPERANDS((0, getCallObject), (1, getCallee)) |
| 3232 |
|
| 3233 |
ArgumentsObject* templateObject() const { return templateObj_; } |
| 3234 |
|
| 3235 |
MDefinition* getArg(uint32_t idx) const { |
| 3236 |
return getOperand(idx + NumNonArgumentOperands); |
| 3237 |
} |
| 3238 |
uint32_t numActuals() const { return numOperands() - NumNonArgumentOperands; } |
| 3239 |
|
| 3240 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3241 |
|
| 3242 |
bool possiblyCalls() const override { return true; } |
| 3243 |
|
| 3244 |
[[nodiscard]] bool writeRecoverData( |
| 3245 |
CompactBufferWriter& writer) const override; |
| 3246 |
bool canRecoverOnBailout() const override { return true; } |
| 3247 |
}; |
| 3248 |
|
| 3249 |
class MGetInlinedArgument |
| 3250 |
: public MVariadicInstruction, |
| 3251 |
public MixPolicy<UnboxedInt32Policy<0>, NoFloatPolicyAfter<1>>::Data { |
| 3252 |
MGetInlinedArgument() : MVariadicInstruction(classOpcode) { |
| 3253 |
setResultType(MIRType::Value); |
| 3254 |
} |
| 3255 |
|
| 3256 |
static const size_t NumNonArgumentOperands = 1; |
| 3257 |
|
| 3258 |
public: |
| 3259 |
INSTRUCTION_HEADER(GetInlinedArgument) |
| 3260 |
static MGetInlinedArgument* New(TempAllocator& alloc, MDefinition* index, |
| 3261 |
MCreateInlinedArgumentsObject* args); |
| 3262 |
static MGetInlinedArgument* New(TempAllocator& alloc, MDefinition* index, |
| 3263 |
const CallInfo& callInfo); |
| 3264 |
NAMED_OPERANDS((0, index)) |
| 3265 |
|
| 3266 |
MDefinition* getArg(uint32_t idx) const { |
| 3267 |
return getOperand(idx + NumNonArgumentOperands); |
| 3268 |
} |
| 3269 |
uint32_t numActuals() const { return numOperands() - NumNonArgumentOperands; } |
| 3270 |
|
| 3271 |
bool congruentTo(const MDefinition* ins) const override { |
| 3272 |
return congruentIfOperandsEqual(ins); |
| 3273 |
} |
| 3274 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3275 |
|
| 3276 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3277 |
}; |
| 3278 |
|
| 3279 |
class MGetInlinedArgumentHole |
| 3280 |
: public MVariadicInstruction, |
| 3281 |
public MixPolicy<UnboxedInt32Policy<0>, NoFloatPolicyAfter<1>>::Data { |
| 3282 |
MGetInlinedArgumentHole() : MVariadicInstruction(classOpcode) { |
| 3283 |
setGuard(); |
| 3284 |
setResultType(MIRType::Value); |
| 3285 |
} |
| 3286 |
|
| 3287 |
static const size_t NumNonArgumentOperands = 1; |
| 3288 |
|
| 3289 |
public: |
| 3290 |
INSTRUCTION_HEADER(GetInlinedArgumentHole) |
| 3291 |
static MGetInlinedArgumentHole* New(TempAllocator& alloc, MDefinition* index, |
| 3292 |
MCreateInlinedArgumentsObject* args); |
| 3293 |
NAMED_OPERANDS((0, index)) |
| 3294 |
|
| 3295 |
MDefinition* getArg(uint32_t idx) const { |
| 3296 |
return getOperand(idx + NumNonArgumentOperands); |
| 3297 |
} |
| 3298 |
uint32_t numActuals() const { return numOperands() - NumNonArgumentOperands; } |
| 3299 |
|
| 3300 |
bool congruentTo(const MDefinition* ins) const override { |
| 3301 |
return congruentIfOperandsEqual(ins); |
| 3302 |
} |
| 3303 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3304 |
|
| 3305 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3306 |
}; |
| 3307 |
|
| 3308 |
class MInlineArgumentsSlice |
| 3309 |
: public MVariadicInstruction, |
| 3310 |
public MixPolicy<UnboxedInt32Policy<0>, UnboxedInt32Policy<1>, |
| 3311 |
NoFloatPolicyAfter<2>>::Data { |
| 3312 |
JSObject* templateObj_; |
| 3313 |
gc::Heap initialHeap_; |
| 3314 |
|
| 3315 |
MInlineArgumentsSlice(JSObject* templateObj, gc::Heap initialHeap) |
| 3316 |
: MVariadicInstruction(classOpcode), |
| 3317 |
templateObj_(templateObj), |
| 3318 |
initialHeap_(initialHeap) { |
| 3319 |
setResultType(MIRType::Object); |
| 3320 |
} |
| 3321 |
|
| 3322 |
static const size_t NumNonArgumentOperands = 2; |
| 3323 |
|
| 3324 |
public: |
| 3325 |
INSTRUCTION_HEADER(InlineArgumentsSlice) |
| 3326 |
static MInlineArgumentsSlice* New(TempAllocator& alloc, MDefinition* begin, |
| 3327 |
MDefinition* count, |
| 3328 |
MCreateInlinedArgumentsObject* args, |
| 3329 |
JSObject* templateObj, |
| 3330 |
gc::Heap initialHeap); |
| 3331 |
NAMED_OPERANDS((0, begin), (1, count)) |
| 3332 |
|
| 3333 |
JSObject* templateObj() const { return templateObj_; } |
| 3334 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 3335 |
|
| 3336 |
MDefinition* getArg(uint32_t idx) const { |
| 3337 |
return getOperand(idx + NumNonArgumentOperands); |
| 3338 |
} |
| 3339 |
uint32_t numActuals() const { return numOperands() - NumNonArgumentOperands; } |
| 3340 |
|
| 3341 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3342 |
|
| 3343 |
bool possiblyCalls() const override { return true; } |
| 3344 |
}; |
| 3345 |
|
| 3346 |
// Allocates a new BoundFunctionObject and calls |
| 3347 |
// BoundFunctionObject::functionBindImpl. This instruction can have arbitrary |
| 3348 |
// side-effects because the GetProperty calls for length/name can call into JS. |
| 3349 |
class MBindFunction |
| 3350 |
: public MVariadicInstruction, |
| 3351 |
public MixPolicy<ObjectPolicy<0>, NoFloatPolicyAfter<1>>::Data { |
| 3352 |
CompilerGCPointer<JSObject*> templateObj_; |
| 3353 |
|
| 3354 |
explicit MBindFunction(JSObject* templateObj) |
| 3355 |
: MVariadicInstruction(classOpcode), templateObj_(templateObj) { |
| 3356 |
setResultType(MIRType::Object); |
| 3357 |
} |
| 3358 |
|
| 3359 |
// The target object is operand 0. |
| 3360 |
static const size_t NumNonArgumentOperands = 1; |
| 3361 |
|
| 3362 |
public: |
| 3363 |
INSTRUCTION_HEADER(BindFunction) |
| 3364 |
static MBindFunction* New(TempAllocator& alloc, MDefinition* target, |
| 3365 |
uint32_t argc, JSObject* templateObj); |
| 3366 |
NAMED_OPERANDS((0, target)) |
| 3367 |
|
| 3368 |
JSObject* templateObject() const { return templateObj_; } |
| 3369 |
|
| 3370 |
MDefinition* getArg(uint32_t idx) const { |
| 3371 |
return getOperand(idx + NumNonArgumentOperands); |
| 3372 |
} |
| 3373 |
void initArg(size_t i, MDefinition* arg) { |
| 3374 |
initOperand(NumNonArgumentOperands + i, arg); |
| 3375 |
} |
| 3376 |
uint32_t numStackArgs() const { |
| 3377 |
return numOperands() - NumNonArgumentOperands; |
| 3378 |
} |
| 3379 |
|
| 3380 |
bool possiblyCalls() const override { return true; } |
| 3381 |
}; |
| 3382 |
|
| 3383 |
class MToFPInstruction : public MUnaryInstruction, public ToDoublePolicy::Data { |
| 3384 |
protected: |
| 3385 |
MToFPInstruction(Opcode op, MDefinition* def, MIRType resultType) |
| 3386 |
: MUnaryInstruction(op, def) { |
| 3387 |
setResultType(resultType); |
| 3388 |
setMovable(); |
| 3389 |
|
| 3390 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 3391 |
if (!def->typeIsOneOf({MIRType::Undefined, MIRType::Null, MIRType::Boolean, |
| 3392 |
MIRType::Int32, MIRType::Double, MIRType::Float32, |
| 3393 |
MIRType::String})) { |
| 3394 |
setGuard(); |
| 3395 |
} |
| 3396 |
} |
| 3397 |
}; |
| 3398 |
|
| 3399 |
// Converts a primitive (either typed or untyped) to a double. If the input is |
| 3400 |
// not primitive at runtime, a bailout occurs. |
| 3401 |
class MToDouble : public MToFPInstruction { |
| 3402 |
private: |
| 3403 |
TruncateKind implicitTruncate_ = TruncateKind::NoTruncate; |
| 3404 |
|
| 3405 |
explicit MToDouble(MDefinition* def) |
| 3406 |
: MToFPInstruction(classOpcode, def, MIRType::Double) {} |
| 3407 |
|
| 3408 |
public: |
| 3409 |
INSTRUCTION_HEADER(ToDouble) |
| 3410 |
TRIVIAL_NEW_WRAPPERS |
| 3411 |
|
| 3412 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3413 |
bool congruentTo(const MDefinition* ins) const override { |
| 3414 |
return congruentIfOperandsEqual(ins); |
| 3415 |
} |
| 3416 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3417 |
|
| 3418 |
void computeRange(TempAllocator& alloc) override; |
| 3419 |
bool canTruncate() const override; |
| 3420 |
void truncate(TruncateKind kind) override; |
| 3421 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 3422 |
|
| 3423 |
#ifdef DEBUG |
| 3424 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 3425 |
#endif |
| 3426 |
|
| 3427 |
TruncateKind truncateKind() const { return implicitTruncate_; } |
| 3428 |
void setTruncateKind(TruncateKind kind) { |
| 3429 |
implicitTruncate_ = std::max(implicitTruncate_, kind); |
| 3430 |
} |
| 3431 |
|
| 3432 |
[[nodiscard]] bool writeRecoverData( |
| 3433 |
CompactBufferWriter& writer) const override; |
| 3434 |
bool canRecoverOnBailout() const override { |
| 3435 |
if (input()->type() == MIRType::Value) { |
| 3436 |
return false; |
| 3437 |
} |
| 3438 |
if (input()->type() == MIRType::Symbol) { |
| 3439 |
return false; |
| 3440 |
} |
| 3441 |
if (input()->type() == MIRType::BigInt) { |
| 3442 |
return false; |
| 3443 |
} |
| 3444 |
|
| 3445 |
return true; |
| 3446 |
} |
| 3447 |
|
| 3448 |
ALLOW_CLONE(MToDouble) |
| 3449 |
}; |
| 3450 |
|
| 3451 |
// Converts a primitive (either typed or untyped) to a float32. If the input is |
| 3452 |
// not primitive at runtime, a bailout occurs. |
| 3453 |
class MToFloat32 : public MToFPInstruction { |
| 3454 |
bool mustPreserveNaN_ = false; |
| 3455 |
|
| 3456 |
explicit MToFloat32(MDefinition* def) |
| 3457 |
: MToFPInstruction(classOpcode, def, MIRType::Float32) {} |
| 3458 |
|
| 3459 |
explicit MToFloat32(MDefinition* def, bool mustPreserveNaN) |
| 3460 |
: MToFloat32(def) { |
| 3461 |
mustPreserveNaN_ = mustPreserveNaN; |
| 3462 |
} |
| 3463 |
|
| 3464 |
public: |
| 3465 |
INSTRUCTION_HEADER(ToFloat32) |
| 3466 |
TRIVIAL_NEW_WRAPPERS |
| 3467 |
|
| 3468 |
virtual MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3469 |
bool congruentTo(const MDefinition* ins) const override { |
| 3470 |
if (!congruentIfOperandsEqual(ins)) { |
| 3471 |
return false; |
| 3472 |
} |
| 3473 |
return ins->toToFloat32()->mustPreserveNaN_ == mustPreserveNaN_; |
| 3474 |
} |
| 3475 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3476 |
|
| 3477 |
void computeRange(TempAllocator& alloc) override; |
| 3478 |
|
| 3479 |
bool canConsumeFloat32(MUse* use) const override { return true; } |
| 3480 |
bool canProduceFloat32() const override { return true; } |
| 3481 |
|
| 3482 |
[[nodiscard]] bool writeRecoverData( |
| 3483 |
CompactBufferWriter& writer) const override; |
| 3484 |
bool canRecoverOnBailout() const override { return true; } |
| 3485 |
|
| 3486 |
ALLOW_CLONE(MToFloat32) |
| 3487 |
}; |
| 3488 |
|
| 3489 |
// Converts a primitive (either typed or untyped) to a float16. If the input is |
| 3490 |
// not primitive at runtime, a bailout occurs. |
| 3491 |
class MToFloat16 : public MToFPInstruction { |
| 3492 |
explicit MToFloat16(MDefinition* def) |
| 3493 |
: MToFPInstruction(classOpcode, def, MIRType::Float32) {} |
| 3494 |
|
| 3495 |
public: |
| 3496 |
INSTRUCTION_HEADER(ToFloat16) |
| 3497 |
TRIVIAL_NEW_WRAPPERS |
| 3498 |
|
| 3499 |
virtual MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3500 |
bool congruentTo(const MDefinition* ins) const override { |
| 3501 |
return congruentIfOperandsEqual(ins); |
| 3502 |
} |
| 3503 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3504 |
|
| 3505 |
// This instruction can produce but NOT consume float32. |
| 3506 |
bool canProduceFloat32() const override { return true; } |
| 3507 |
|
| 3508 |
#ifdef DEBUG |
| 3509 |
// Float16 inputs are typed as float32, but this instruction can NOT consume |
| 3510 |
// float32. |
| 3511 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 3512 |
#endif |
| 3513 |
|
| 3514 |
[[nodiscard]] bool writeRecoverData( |
| 3515 |
CompactBufferWriter& writer) const override; |
| 3516 |
bool canRecoverOnBailout() const override { return true; } |
| 3517 |
|
| 3518 |
ALLOW_CLONE(MToFloat16) |
| 3519 |
}; |
| 3520 |
|
| 3521 |
class MWrapInt64ToInt32 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3522 |
bool bottomHalf_; |
| 3523 |
|
| 3524 |
explicit MWrapInt64ToInt32(MDefinition* def, bool bottomHalf = true) |
| 3525 |
: MUnaryInstruction(classOpcode, def), bottomHalf_(bottomHalf) { |
| 3526 |
setResultType(MIRType::Int32); |
| 3527 |
setMovable(); |
| 3528 |
} |
| 3529 |
|
| 3530 |
public: |
| 3531 |
INSTRUCTION_HEADER(WrapInt64ToInt32) |
| 3532 |
TRIVIAL_NEW_WRAPPERS |
| 3533 |
|
| 3534 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3535 |
bool congruentTo(const MDefinition* ins) const override { |
| 3536 |
if (!ins->isWrapInt64ToInt32()) { |
| 3537 |
return false; |
| 3538 |
} |
| 3539 |
if (ins->toWrapInt64ToInt32()->bottomHalf() != bottomHalf()) { |
| 3540 |
return false; |
| 3541 |
} |
| 3542 |
return congruentIfOperandsEqual(ins); |
| 3543 |
} |
| 3544 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3545 |
|
| 3546 |
bool bottomHalf() const { return bottomHalf_; } |
| 3547 |
|
| 3548 |
ALLOW_CLONE(MWrapInt64ToInt32) |
| 3549 |
}; |
| 3550 |
|
| 3551 |
class MExtendInt32ToInt64 : public MUnaryInstruction, |
| 3552 |
public NoTypePolicy::Data { |
| 3553 |
bool isUnsigned_; |
| 3554 |
|
| 3555 |
MExtendInt32ToInt64(MDefinition* def, bool isUnsigned) |
| 3556 |
: MUnaryInstruction(classOpcode, def), isUnsigned_(isUnsigned) { |
| 3557 |
setResultType(MIRType::Int64); |
| 3558 |
setMovable(); |
| 3559 |
} |
| 3560 |
|
| 3561 |
public: |
| 3562 |
INSTRUCTION_HEADER(ExtendInt32ToInt64) |
| 3563 |
TRIVIAL_NEW_WRAPPERS |
| 3564 |
|
| 3565 |
bool isUnsigned() const { return isUnsigned_; } |
| 3566 |
|
| 3567 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3568 |
bool congruentTo(const MDefinition* ins) const override { |
| 3569 |
if (!ins->isExtendInt32ToInt64()) { |
| 3570 |
return false; |
| 3571 |
} |
| 3572 |
if (ins->toExtendInt32ToInt64()->isUnsigned_ != isUnsigned_) { |
| 3573 |
return false; |
| 3574 |
} |
| 3575 |
return congruentIfOperandsEqual(ins); |
| 3576 |
} |
| 3577 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3578 |
|
| 3579 |
ALLOW_CLONE(MExtendInt32ToInt64) |
| 3580 |
}; |
| 3581 |
|
| 3582 |
// Converts an int32 value to intptr by sign-extending it. |
| 3583 |
class MInt32ToIntPtr : public MUnaryInstruction, |
| 3584 |
public UnboxedInt32Policy<0>::Data { |
| 3585 |
bool canBeNegative_ = true; |
| 3586 |
|
| 3587 |
explicit MInt32ToIntPtr(MDefinition* def) |
| 3588 |
: MUnaryInstruction(classOpcode, def) { |
| 3589 |
setResultType(MIRType::IntPtr); |
| 3590 |
setMovable(); |
| 3591 |
} |
| 3592 |
|
| 3593 |
public: |
| 3594 |
INSTRUCTION_HEADER(Int32ToIntPtr) |
| 3595 |
TRIVIAL_NEW_WRAPPERS |
| 3596 |
|
| 3597 |
bool canBeNegative() const { return canBeNegative_; } |
| 3598 |
void setCanNotBeNegative() { canBeNegative_ = false; } |
| 3599 |
|
| 3600 |
void computeRange(TempAllocator& alloc) override; |
| 3601 |
void collectRangeInfoPreTrunc() override; |
| 3602 |
|
| 3603 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3604 |
|
| 3605 |
bool congruentTo(const MDefinition* ins) const override { |
| 3606 |
return congruentIfOperandsEqual(ins); |
| 3607 |
} |
| 3608 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3609 |
}; |
| 3610 |
|
| 3611 |
// Converts an IntPtr value >= 0 to Int32. Bails out if the value > INT32_MAX. |
| 3612 |
class MNonNegativeIntPtrToInt32 : public MUnaryInstruction, |
| 3613 |
public NoTypePolicy::Data { |
| 3614 |
explicit MNonNegativeIntPtrToInt32(MDefinition* def) |
| 3615 |
: MUnaryInstruction(classOpcode, def) { |
| 3616 |
MOZ_ASSERT(def->type() == MIRType::IntPtr); |
| 3617 |
setResultType(MIRType::Int32); |
| 3618 |
setMovable(); |
| 3619 |
} |
| 3620 |
|
| 3621 |
public: |
| 3622 |
INSTRUCTION_HEADER(NonNegativeIntPtrToInt32) |
| 3623 |
TRIVIAL_NEW_WRAPPERS |
| 3624 |
|
| 3625 |
void computeRange(TempAllocator& alloc) override; |
| 3626 |
|
| 3627 |
bool congruentTo(const MDefinition* ins) const override { |
| 3628 |
return congruentIfOperandsEqual(ins); |
| 3629 |
} |
| 3630 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3631 |
}; |
| 3632 |
|
| 3633 |
// Converts an IntPtr value to Double. |
| 3634 |
class MIntPtrToDouble : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3635 |
explicit MIntPtrToDouble(MDefinition* def) |
| 3636 |
: MUnaryInstruction(classOpcode, def) { |
| 3637 |
MOZ_ASSERT(def->type() == MIRType::IntPtr); |
| 3638 |
setResultType(MIRType::Double); |
| 3639 |
setMovable(); |
| 3640 |
} |
| 3641 |
|
| 3642 |
public: |
| 3643 |
INSTRUCTION_HEADER(IntPtrToDouble) |
| 3644 |
TRIVIAL_NEW_WRAPPERS |
| 3645 |
|
| 3646 |
bool congruentTo(const MDefinition* ins) const override { |
| 3647 |
return congruentIfOperandsEqual(ins); |
| 3648 |
} |
| 3649 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3650 |
}; |
| 3651 |
|
| 3652 |
// Subtracts (byteSize - 1) from the input value. Bails out if the result is |
| 3653 |
// negative. This is used to implement bounds checks for DataView accesses. |
| 3654 |
class MAdjustDataViewLength : public MUnaryInstruction, |
| 3655 |
public NoTypePolicy::Data { |
| 3656 |
const uint32_t byteSize_; |
| 3657 |
|
| 3658 |
MAdjustDataViewLength(MDefinition* input, uint32_t byteSize) |
| 3659 |
: MUnaryInstruction(classOpcode, input), byteSize_(byteSize) { |
| 3660 |
MOZ_ASSERT(input->type() == MIRType::IntPtr); |
| 3661 |
MOZ_ASSERT(byteSize > 1); |
| 3662 |
setResultType(MIRType::IntPtr); |
| 3663 |
setMovable(); |
| 3664 |
setGuard(); |
| 3665 |
} |
| 3666 |
|
| 3667 |
public: |
| 3668 |
INSTRUCTION_HEADER(AdjustDataViewLength) |
| 3669 |
TRIVIAL_NEW_WRAPPERS |
| 3670 |
|
| 3671 |
uint32_t byteSize() const { return byteSize_; } |
| 3672 |
|
| 3673 |
bool congruentTo(const MDefinition* ins) const override { |
| 3674 |
if (!ins->isAdjustDataViewLength()) { |
| 3675 |
return false; |
| 3676 |
} |
| 3677 |
if (ins->toAdjustDataViewLength()->byteSize() != byteSize()) { |
| 3678 |
return false; |
| 3679 |
} |
| 3680 |
return congruentIfOperandsEqual(ins); |
| 3681 |
} |
| 3682 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3683 |
}; |
| 3684 |
|
| 3685 |
class MInt64ToFloatingPoint : public MUnaryInstruction, |
| 3686 |
public NoTypePolicy::Data { |
| 3687 |
bool isUnsigned_; |
| 3688 |
wasm::BytecodeOffset bytecodeOffset_; |
| 3689 |
|
| 3690 |
MInt64ToFloatingPoint(MDefinition* def, MIRType type, |
| 3691 |
wasm::BytecodeOffset bytecodeOffset, bool isUnsigned) |
| 3692 |
: MUnaryInstruction(classOpcode, def), |
| 3693 |
isUnsigned_(isUnsigned), |
| 3694 |
bytecodeOffset_(bytecodeOffset) { |
| 3695 |
MOZ_ASSERT(IsFloatingPointType(type)); |
| 3696 |
setResultType(type); |
| 3697 |
setMovable(); |
| 3698 |
} |
| 3699 |
|
| 3700 |
public: |
| 3701 |
INSTRUCTION_HEADER(Int64ToFloatingPoint) |
| 3702 |
TRIVIAL_NEW_WRAPPERS |
| 3703 |
|
| 3704 |
bool isUnsigned() const { return isUnsigned_; } |
| 3705 |
wasm::BytecodeOffset bytecodeOffset() const { return bytecodeOffset_; } |
| 3706 |
|
| 3707 |
bool congruentTo(const MDefinition* ins) const override { |
| 3708 |
if (!ins->isInt64ToFloatingPoint()) { |
| 3709 |
return false; |
| 3710 |
} |
| 3711 |
if (ins->toInt64ToFloatingPoint()->isUnsigned_ != isUnsigned_) { |
| 3712 |
return false; |
| 3713 |
} |
| 3714 |
return congruentIfOperandsEqual(ins); |
| 3715 |
} |
| 3716 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3717 |
}; |
| 3718 |
|
| 3719 |
// It used only for arm now because on arm we need to call builtin to convert |
| 3720 |
// i64 to float. |
| 3721 |
class MBuiltinInt64ToFloatingPoint : public MAryInstruction<2>, |
| 3722 |
public NoTypePolicy::Data { |
| 3723 |
bool isUnsigned_; |
| 3724 |
wasm::BytecodeOffset bytecodeOffset_; |
| 3725 |
|
| 3726 |
MBuiltinInt64ToFloatingPoint(MDefinition* def, MDefinition* instance, |
| 3727 |
MIRType type, |
| 3728 |
wasm::BytecodeOffset bytecodeOffset, |
| 3729 |
bool isUnsigned) |
| 3730 |
: MAryInstruction(classOpcode), |
| 3731 |
isUnsigned_(isUnsigned), |
| 3732 |
bytecodeOffset_(bytecodeOffset) { |
| 3733 |
MOZ_ASSERT(IsFloatingPointType(type)); |
| 3734 |
initOperand(0, def); |
| 3735 |
initOperand(1, instance); |
| 3736 |
setResultType(type); |
| 3737 |
setMovable(); |
| 3738 |
} |
| 3739 |
|
| 3740 |
public: |
| 3741 |
INSTRUCTION_HEADER(BuiltinInt64ToFloatingPoint) |
| 3742 |
NAMED_OPERANDS((0, input), (1, instance)); |
| 3743 |
TRIVIAL_NEW_WRAPPERS |
| 3744 |
|
| 3745 |
bool isUnsigned() const { return isUnsigned_; } |
| 3746 |
wasm::BytecodeOffset bytecodeOffset() const { return bytecodeOffset_; } |
| 3747 |
|
| 3748 |
bool congruentTo(const MDefinition* ins) const override { |
| 3749 |
if (!ins->isBuiltinInt64ToFloatingPoint()) { |
| 3750 |
return false; |
| 3751 |
} |
| 3752 |
if (ins->toBuiltinInt64ToFloatingPoint()->isUnsigned_ != isUnsigned_) { |
| 3753 |
return false; |
| 3754 |
} |
| 3755 |
return congruentIfOperandsEqual(ins); |
| 3756 |
} |
| 3757 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3758 |
}; |
| 3759 |
|
| 3760 |
// Applies ECMA's ToNumber on a primitive (either typed or untyped) and expects |
| 3761 |
// the result to be precisely representable as an Int32, otherwise bails. |
| 3762 |
// |
| 3763 |
// If the input is not primitive at runtime, a bailout occurs. If the input |
| 3764 |
// cannot be converted to an int32 without loss (i.e. 5.5 or undefined) then a |
| 3765 |
// bailout occurs. |
| 3766 |
class MToNumberInt32 : public MUnaryInstruction, public ToInt32Policy::Data { |
| 3767 |
bool needsNegativeZeroCheck_; |
| 3768 |
IntConversionInputKind conversion_; |
| 3769 |
|
| 3770 |
explicit MToNumberInt32(MDefinition* def, IntConversionInputKind conversion = |
| 3771 |
IntConversionInputKind::Any) |
| 3772 |
: MUnaryInstruction(classOpcode, def), |
| 3773 |
needsNegativeZeroCheck_(true), |
| 3774 |
conversion_(conversion) { |
| 3775 |
setResultType(MIRType::Int32); |
| 3776 |
setMovable(); |
| 3777 |
|
| 3778 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 3779 |
if (!def->typeIsOneOf({MIRType::Undefined, MIRType::Null, MIRType::Boolean, |
| 3780 |
MIRType::Int32, MIRType::Double, MIRType::Float32, |
| 3781 |
MIRType::String})) { |
| 3782 |
setGuard(); |
| 3783 |
} |
| 3784 |
} |
| 3785 |
|
| 3786 |
public: |
| 3787 |
INSTRUCTION_HEADER(ToNumberInt32) |
| 3788 |
TRIVIAL_NEW_WRAPPERS |
| 3789 |
|
| 3790 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3791 |
|
| 3792 |
// this only has backwards information flow. |
| 3793 |
void analyzeEdgeCasesBackward() override; |
| 3794 |
|
| 3795 |
bool needsNegativeZeroCheck() const { return needsNegativeZeroCheck_; } |
| 3796 |
void setNeedsNegativeZeroCheck(bool needsCheck) { |
| 3797 |
needsNegativeZeroCheck_ = needsCheck; |
| 3798 |
} |
| 3799 |
|
| 3800 |
IntConversionInputKind conversion() const { return conversion_; } |
| 3801 |
|
| 3802 |
bool congruentTo(const MDefinition* ins) const override { |
| 3803 |
if (!ins->isToNumberInt32() || |
| 3804 |
ins->toToNumberInt32()->conversion() != conversion()) { |
| 3805 |
return false; |
| 3806 |
} |
| 3807 |
return congruentIfOperandsEqual(ins); |
| 3808 |
} |
| 3809 |
|
| 3810 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3811 |
void computeRange(TempAllocator& alloc) override; |
| 3812 |
void collectRangeInfoPreTrunc() override; |
| 3813 |
|
| 3814 |
#ifdef DEBUG |
| 3815 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 3816 |
#endif |
| 3817 |
|
| 3818 |
ALLOW_CLONE(MToNumberInt32) |
| 3819 |
}; |
| 3820 |
|
| 3821 |
// Converts a value or typed input to a truncated int32, for use with bitwise |
| 3822 |
// operations. This is an infallible ValueToECMAInt32. |
| 3823 |
class MTruncateToInt32 : public MUnaryInstruction, public ToInt32Policy::Data { |
| 3824 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 3825 |
|
| 3826 |
explicit MTruncateToInt32( |
| 3827 |
MDefinition* def, wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc()) |
| 3828 |
: MUnaryInstruction(classOpcode, def), trapSiteDesc_(trapSiteDesc) { |
| 3829 |
setResultType(MIRType::Int32); |
| 3830 |
setMovable(); |
| 3831 |
|
| 3832 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 3833 |
if (mightHaveSideEffects(def)) { |
| 3834 |
setGuard(); |
| 3835 |
} |
| 3836 |
} |
| 3837 |
|
| 3838 |
public: |
| 3839 |
INSTRUCTION_HEADER(TruncateToInt32) |
| 3840 |
TRIVIAL_NEW_WRAPPERS |
| 3841 |
|
| 3842 |
static bool mightHaveSideEffects(MDefinition* def) { |
| 3843 |
return !def->typeIsOneOf({MIRType::Undefined, MIRType::Null, |
| 3844 |
MIRType::Boolean, MIRType::Int32, MIRType::Double, |
| 3845 |
MIRType::Float32, MIRType::String}); |
| 3846 |
} |
| 3847 |
|
| 3848 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3849 |
|
| 3850 |
bool congruentTo(const MDefinition* ins) const override { |
| 3851 |
return congruentIfOperandsEqual(ins); |
| 3852 |
} |
| 3853 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3854 |
|
| 3855 |
void computeRange(TempAllocator& alloc) override; |
| 3856 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 3857 |
#ifdef DEBUG |
| 3858 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 3859 |
#endif |
| 3860 |
|
| 3861 |
[[nodiscard]] bool writeRecoverData( |
| 3862 |
CompactBufferWriter& writer) const override; |
| 3863 |
bool canRecoverOnBailout() const override { |
| 3864 |
return input()->type() < MIRType::Symbol; |
| 3865 |
} |
| 3866 |
|
| 3867 |
const wasm::TrapSiteDesc& trapSiteDesc() const { return trapSiteDesc_; } |
| 3868 |
|
| 3869 |
ALLOW_CLONE(MTruncateToInt32) |
| 3870 |
}; |
| 3871 |
|
| 3872 |
// Converts a primitive (either typed or untyped) to a BigInt. If the input is |
| 3873 |
// not primitive at runtime, a bailout occurs. |
| 3874 |
class MToBigInt : public MUnaryInstruction, public ToBigIntPolicy::Data { |
| 3875 |
private: |
| 3876 |
explicit MToBigInt(MDefinition* def) : MUnaryInstruction(classOpcode, def) { |
| 3877 |
setResultType(MIRType::BigInt); |
| 3878 |
setMovable(); |
| 3879 |
|
| 3880 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 3881 |
if (!def->typeIsOneOf({MIRType::Boolean, MIRType::BigInt})) { |
| 3882 |
setGuard(); |
| 3883 |
} |
| 3884 |
} |
| 3885 |
|
| 3886 |
public: |
| 3887 |
INSTRUCTION_HEADER(ToBigInt) |
| 3888 |
TRIVIAL_NEW_WRAPPERS |
| 3889 |
|
| 3890 |
bool congruentTo(const MDefinition* ins) const override { |
| 3891 |
return congruentIfOperandsEqual(ins); |
| 3892 |
} |
| 3893 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3894 |
|
| 3895 |
ALLOW_CLONE(MToBigInt) |
| 3896 |
}; |
| 3897 |
|
| 3898 |
// Takes a Value or typed input and returns a suitable Int64 using the |
| 3899 |
// ToBigInt algorithm, possibly calling out to the VM for string, etc inputs. |
| 3900 |
class MToInt64 : public MUnaryInstruction, public ToInt64Policy::Data { |
| 3901 |
explicit MToInt64(MDefinition* def) : MUnaryInstruction(classOpcode, def) { |
| 3902 |
setResultType(MIRType::Int64); |
| 3903 |
setMovable(); |
| 3904 |
|
| 3905 |
// Guard unless the conversion is known to be non-effectful & non-throwing. |
| 3906 |
if (!def->typeIsOneOf( |
| 3907 |
{MIRType::Boolean, MIRType::BigInt, MIRType::Int64})) { |
| 3908 |
setGuard(); |
| 3909 |
} |
| 3910 |
} |
| 3911 |
|
| 3912 |
public: |
| 3913 |
INSTRUCTION_HEADER(ToInt64) |
| 3914 |
TRIVIAL_NEW_WRAPPERS |
| 3915 |
|
| 3916 |
bool congruentTo(const MDefinition* ins) const override { |
| 3917 |
return congruentIfOperandsEqual(ins); |
| 3918 |
} |
| 3919 |
|
| 3920 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3921 |
|
| 3922 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3923 |
|
| 3924 |
ALLOW_CLONE(MToInt64) |
| 3925 |
}; |
| 3926 |
|
| 3927 |
// Takes a BigInt pointer and returns its toInt64 value. |
| 3928 |
class MTruncateBigIntToInt64 : public MUnaryInstruction, |
| 3929 |
public NoTypePolicy::Data { |
| 3930 |
explicit MTruncateBigIntToInt64(MDefinition* def) |
| 3931 |
: MUnaryInstruction(classOpcode, def) { |
| 3932 |
MOZ_ASSERT(def->type() == MIRType::BigInt); |
| 3933 |
setResultType(MIRType::Int64); |
| 3934 |
setMovable(); |
| 3935 |
} |
| 3936 |
|
| 3937 |
public: |
| 3938 |
INSTRUCTION_HEADER(TruncateBigIntToInt64) |
| 3939 |
TRIVIAL_NEW_WRAPPERS |
| 3940 |
|
| 3941 |
bool congruentTo(const MDefinition* ins) const override { |
| 3942 |
return congruentIfOperandsEqual(ins); |
| 3943 |
} |
| 3944 |
|
| 3945 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3946 |
|
| 3947 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 3948 |
|
| 3949 |
ALLOW_CLONE(MTruncateBigIntToInt64) |
| 3950 |
}; |
| 3951 |
|
| 3952 |
// Takes an Int64 and returns a fresh BigInt pointer. |
| 3953 |
class MInt64ToBigInt : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3954 |
bool isSigned_; |
| 3955 |
|
| 3956 |
MInt64ToBigInt(MDefinition* def, bool isSigned) |
| 3957 |
: MUnaryInstruction(classOpcode, def), isSigned_(isSigned) { |
| 3958 |
MOZ_ASSERT(def->type() == MIRType::Int64); |
| 3959 |
setResultType(MIRType::BigInt); |
| 3960 |
setMovable(); |
| 3961 |
} |
| 3962 |
|
| 3963 |
public: |
| 3964 |
INSTRUCTION_HEADER(Int64ToBigInt) |
| 3965 |
TRIVIAL_NEW_WRAPPERS |
| 3966 |
|
| 3967 |
bool congruentTo(const MDefinition* ins) const override { |
| 3968 |
return congruentIfOperandsEqual(ins) && |
| 3969 |
ins->toInt64ToBigInt()->isSigned() == isSigned(); |
| 3970 |
} |
| 3971 |
|
| 3972 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 3973 |
|
| 3974 |
bool isSigned() const { return isSigned_; } |
| 3975 |
|
| 3976 |
[[nodiscard]] bool writeRecoverData( |
| 3977 |
CompactBufferWriter& writer) const override; |
| 3978 |
bool canRecoverOnBailout() const override { return true; } |
| 3979 |
|
| 3980 |
ALLOW_CLONE(MInt64ToBigInt) |
| 3981 |
}; |
| 3982 |
|
| 3983 |
// Takes an Int64 and returns a IntPtr. |
| 3984 |
class MInt64ToIntPtr : public MUnaryInstruction, public NoTypePolicy::Data { |
| 3985 |
bool isSigned_; |
| 3986 |
|
| 3987 |
MInt64ToIntPtr(MDefinition* def, bool isSigned) |
| 3988 |
: MUnaryInstruction(classOpcode, def), isSigned_(isSigned) { |
| 3989 |
MOZ_ASSERT(def->type() == MIRType::Int64); |
| 3990 |
setResultType(MIRType::IntPtr); |
| 3991 |
setMovable(); |
| 3992 |
} |
| 3993 |
|
| 3994 |
public: |
| 3995 |
INSTRUCTION_HEADER(Int64ToIntPtr) |
| 3996 |
TRIVIAL_NEW_WRAPPERS |
| 3997 |
|
| 3998 |
bool congruentTo(const MDefinition* ins) const override { |
| 3999 |
return congruentIfOperandsEqual(ins) && |
| 4000 |
ins->toInt64ToIntPtr()->isSigned() == isSigned(); |
| 4001 |
} |
| 4002 |
|
| 4003 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4004 |
|
| 4005 |
bool isSigned() const { return isSigned_; } |
| 4006 |
|
| 4007 |
ALLOW_CLONE(MInt64ToIntPtr) |
| 4008 |
}; |
| 4009 |
|
| 4010 |
// Takes a IntPtr and returns an Int64. |
| 4011 |
class MIntPtrToInt64 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 4012 |
explicit MIntPtrToInt64(MDefinition* def) |
| 4013 |
: MUnaryInstruction(classOpcode, def) { |
| 4014 |
MOZ_ASSERT(def->type() == MIRType::IntPtr); |
| 4015 |
setResultType(MIRType::Int64); |
| 4016 |
setMovable(); |
| 4017 |
} |
| 4018 |
|
| 4019 |
public: |
| 4020 |
INSTRUCTION_HEADER(IntPtrToInt64) |
| 4021 |
TRIVIAL_NEW_WRAPPERS |
| 4022 |
|
| 4023 |
bool congruentTo(const MDefinition* ins) const override { |
| 4024 |
return congruentIfOperandsEqual(ins); |
| 4025 |
} |
| 4026 |
|
| 4027 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4028 |
|
| 4029 |
ALLOW_CLONE(MIntPtrToInt64) |
| 4030 |
}; |
| 4031 |
|
| 4032 |
// Converts any type to a string |
| 4033 |
class MToString : public MUnaryInstruction, public ToStringPolicy::Data { |
| 4034 |
public: |
| 4035 |
// MToString has two modes for handling of object/symbol arguments: if the |
| 4036 |
// to-string conversion happens as part of another opcode, we have to bail out |
| 4037 |
// to Baseline. If the conversion is for a stand-alone JSOp we can support |
| 4038 |
// side-effects. |
| 4039 |
enum class SideEffectHandling { Bailout, Supported }; |
| 4040 |
|
| 4041 |
private: |
| 4042 |
SideEffectHandling sideEffects_; |
| 4043 |
bool mightHaveSideEffects_ = false; |
| 4044 |
|
| 4045 |
MToString(MDefinition* def, SideEffectHandling sideEffects) |
| 4046 |
: MUnaryInstruction(classOpcode, def), sideEffects_(sideEffects) { |
| 4047 |
setResultType(MIRType::String); |
| 4048 |
|
| 4049 |
if (!def->typeIsOneOf({MIRType::Undefined, MIRType::Null, MIRType::Boolean, |
| 4050 |
MIRType::Int32, MIRType::Double, MIRType::Float32, |
| 4051 |
MIRType::String, MIRType::BigInt})) { |
| 4052 |
mightHaveSideEffects_ = true; |
| 4053 |
} |
| 4054 |
|
| 4055 |
// If this instruction is not effectful, mark it as movable and set the |
| 4056 |
// Guard flag if needed. If the operation is effectful it won't be |
| 4057 |
// optimized anyway so there's no need to set any flags. |
| 4058 |
if (!isEffectful()) { |
| 4059 |
setMovable(); |
| 4060 |
// Objects might override toString; Symbol throws. We bailout in those |
| 4061 |
// cases and run side-effects in baseline instead. |
| 4062 |
if (mightHaveSideEffects_) { |
| 4063 |
setGuard(); |
| 4064 |
} |
| 4065 |
} |
| 4066 |
} |
| 4067 |
|
| 4068 |
public: |
| 4069 |
INSTRUCTION_HEADER(ToString) |
| 4070 |
TRIVIAL_NEW_WRAPPERS |
| 4071 |
|
| 4072 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4073 |
|
| 4074 |
bool congruentTo(const MDefinition* ins) const override { |
| 4075 |
if (!ins->isToString()) { |
| 4076 |
return false; |
| 4077 |
} |
| 4078 |
if (sideEffects_ != ins->toToString()->sideEffects_) { |
| 4079 |
return false; |
| 4080 |
} |
| 4081 |
return congruentIfOperandsEqual(ins); |
| 4082 |
} |
| 4083 |
|
| 4084 |
AliasSet getAliasSet() const override { |
| 4085 |
if (supportSideEffects() && mightHaveSideEffects_) { |
| 4086 |
return AliasSet::Store(AliasSet::Any); |
| 4087 |
} |
| 4088 |
return AliasSet::None(); |
| 4089 |
} |
| 4090 |
|
| 4091 |
bool mightHaveSideEffects() const { return mightHaveSideEffects_; } |
| 4092 |
|
| 4093 |
bool supportSideEffects() const { |
| 4094 |
return sideEffects_ == SideEffectHandling::Supported; |
| 4095 |
} |
| 4096 |
|
| 4097 |
bool needsSnapshot() const { |
| 4098 |
return sideEffects_ == SideEffectHandling::Bailout && mightHaveSideEffects_; |
| 4099 |
} |
| 4100 |
|
| 4101 |
ALLOW_CLONE(MToString) |
| 4102 |
}; |
| 4103 |
|
| 4104 |
class MBitNot : public MUnaryInstruction, public BitwisePolicy::Data { |
| 4105 |
MBitNot(MDefinition* input, MIRType type) |
| 4106 |
: MUnaryInstruction(classOpcode, input) { |
| 4107 |
MOZ_ASSERT(type == MIRType::Int32 || type == MIRType::Int64); |
| 4108 |
setResultType(type); |
| 4109 |
setMovable(); |
| 4110 |
} |
| 4111 |
|
| 4112 |
public: |
| 4113 |
INSTRUCTION_HEADER(BitNot) |
| 4114 |
TRIVIAL_NEW_WRAPPERS |
| 4115 |
|
| 4116 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4117 |
|
| 4118 |
bool congruentTo(const MDefinition* ins) const override { |
| 4119 |
return congruentIfOperandsEqual(ins); |
| 4120 |
} |
| 4121 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4122 |
void computeRange(TempAllocator& alloc) override; |
| 4123 |
|
| 4124 |
[[nodiscard]] bool writeRecoverData( |
| 4125 |
CompactBufferWriter& writer) const override; |
| 4126 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4127 |
|
| 4128 |
ALLOW_CLONE(MBitNot) |
| 4129 |
}; |
| 4130 |
|
| 4131 |
class MTypeOf : public MUnaryInstruction, |
| 4132 |
public BoxExceptPolicy<0, MIRType::Object>::Data { |
| 4133 |
explicit MTypeOf(MDefinition* def) : MUnaryInstruction(classOpcode, def) { |
| 4134 |
setResultType(MIRType::Int32); |
| 4135 |
setMovable(); |
| 4136 |
} |
| 4137 |
TypeDataList observed_; |
| 4138 |
|
| 4139 |
public: |
| 4140 |
INSTRUCTION_HEADER(TypeOf) |
| 4141 |
TRIVIAL_NEW_WRAPPERS |
| 4142 |
|
| 4143 |
void setObservedTypes(const TypeDataList& observed) { observed_ = observed; } |
| 4144 |
bool hasObservedTypes() const { return observed_.count() > 0; } |
| 4145 |
const TypeDataList& observedTypes() const { return observed_; } |
| 4146 |
|
| 4147 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4148 |
|
| 4149 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4150 |
|
| 4151 |
bool congruentTo(const MDefinition* ins) const override { |
| 4152 |
return congruentIfOperandsEqual(ins); |
| 4153 |
} |
| 4154 |
|
| 4155 |
[[nodiscard]] bool writeRecoverData( |
| 4156 |
CompactBufferWriter& writer) const override; |
| 4157 |
bool canRecoverOnBailout() const override { return true; } |
| 4158 |
}; |
| 4159 |
|
| 4160 |
class MTypeOfIs : public MUnaryInstruction, public NoTypePolicy::Data { |
| 4161 |
JSOp jsop_; |
| 4162 |
JSType jstype_; |
| 4163 |
|
| 4164 |
MTypeOfIs(MDefinition* def, JSOp jsop, JSType jstype) |
| 4165 |
: MUnaryInstruction(classOpcode, def), jsop_(jsop), jstype_(jstype) { |
| 4166 |
MOZ_ASSERT(def->type() == MIRType::Object || def->type() == MIRType::Value); |
| 4167 |
|
| 4168 |
setResultType(MIRType::Boolean); |
| 4169 |
setMovable(); |
| 4170 |
} |
| 4171 |
|
| 4172 |
public: |
| 4173 |
INSTRUCTION_HEADER(TypeOfIs) |
| 4174 |
TRIVIAL_NEW_WRAPPERS |
| 4175 |
|
| 4176 |
JSOp jsop() const { return jsop_; } |
| 4177 |
JSType jstype() const { return jstype_; } |
| 4178 |
|
| 4179 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4180 |
|
| 4181 |
bool congruentTo(const MDefinition* ins) const override { |
| 4182 |
if (!congruentIfOperandsEqual(ins)) { |
| 4183 |
return false; |
| 4184 |
} |
| 4185 |
return jsop() == ins->toTypeOfIs()->jsop() && |
| 4186 |
jstype() == ins->toTypeOfIs()->jstype(); |
| 4187 |
} |
| 4188 |
|
| 4189 |
#ifdef JS_JITSPEW |
| 4190 |
void printOpcode(GenericPrinter& out) const override; |
| 4191 |
#endif |
| 4192 |
}; |
| 4193 |
|
| 4194 |
class MBinaryBitwiseInstruction : public MBinaryInstruction, |
| 4195 |
public BitwisePolicy::Data { |
| 4196 |
protected: |
| 4197 |
MBinaryBitwiseInstruction(Opcode op, MDefinition* left, MDefinition* right, |
| 4198 |
MIRType type) |
| 4199 |
: MBinaryInstruction(op, left, right), |
| 4200 |
maskMatchesLeftRange(false), |
| 4201 |
maskMatchesRightRange(false) { |
| 4202 |
MOZ_ASSERT(type == MIRType::Int32 || type == MIRType::Int64 || |
| 4203 |
(isUrsh() && type == MIRType::Double)); |
| 4204 |
setResultType(type); |
| 4205 |
setMovable(); |
| 4206 |
} |
| 4207 |
|
| 4208 |
bool maskMatchesLeftRange; |
| 4209 |
bool maskMatchesRightRange; |
| 4210 |
|
| 4211 |
public: |
| 4212 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4213 |
MDefinition* foldUnnecessaryBitop(); |
| 4214 |
virtual MDefinition* foldIfZero(size_t operand) = 0; |
| 4215 |
virtual MDefinition* foldIfNegOne(size_t operand) = 0; |
| 4216 |
virtual MDefinition* foldIfEqual() = 0; |
| 4217 |
virtual MDefinition* foldIfAllBitsSet(size_t operand) = 0; |
| 4218 |
void collectRangeInfoPreTrunc() override; |
| 4219 |
|
| 4220 |
bool congruentTo(const MDefinition* ins) const override { |
| 4221 |
return binaryCongruentTo(ins); |
| 4222 |
} |
| 4223 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4224 |
|
| 4225 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 4226 |
}; |
| 4227 |
|
| 4228 |
class MBitAnd : public MBinaryBitwiseInstruction { |
| 4229 |
MBitAnd(MDefinition* left, MDefinition* right, MIRType type) |
| 4230 |
: MBinaryBitwiseInstruction(classOpcode, left, right, type) { |
| 4231 |
setCommutative(); |
| 4232 |
} |
| 4233 |
|
| 4234 |
public: |
| 4235 |
INSTRUCTION_HEADER(BitAnd) |
| 4236 |
TRIVIAL_NEW_WRAPPERS |
| 4237 |
|
| 4238 |
MDefinition* foldIfZero(size_t operand) override { |
| 4239 |
return getOperand(operand); // 0 & x => 0; |
| 4240 |
} |
| 4241 |
MDefinition* foldIfNegOne(size_t operand) override { |
| 4242 |
return getOperand(1 - operand); // x & -1 => x |
| 4243 |
} |
| 4244 |
MDefinition* foldIfEqual() override { |
| 4245 |
return getOperand(0); // x & x => x; |
| 4246 |
} |
| 4247 |
MDefinition* foldIfAllBitsSet(size_t operand) override { |
| 4248 |
// e.g. for uint16: x & 0xffff => x; |
| 4249 |
return getOperand(1 - operand); |
| 4250 |
} |
| 4251 |
void computeRange(TempAllocator& alloc) override; |
| 4252 |
|
| 4253 |
[[nodiscard]] bool writeRecoverData( |
| 4254 |
CompactBufferWriter& writer) const override; |
| 4255 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4256 |
|
| 4257 |
ALLOW_CLONE(MBitAnd) |
| 4258 |
}; |
| 4259 |
|
| 4260 |
class MBitOr : public MBinaryBitwiseInstruction { |
| 4261 |
MBitOr(MDefinition* left, MDefinition* right, MIRType type) |
| 4262 |
: MBinaryBitwiseInstruction(classOpcode, left, right, type) { |
| 4263 |
setCommutative(); |
| 4264 |
} |
| 4265 |
|
| 4266 |
public: |
| 4267 |
INSTRUCTION_HEADER(BitOr) |
| 4268 |
TRIVIAL_NEW_WRAPPERS |
| 4269 |
|
| 4270 |
MDefinition* foldIfZero(size_t operand) override { |
| 4271 |
return getOperand(1 - |
| 4272 |
operand); // 0 | x => x, so if ith is 0, return (1-i)th |
| 4273 |
} |
| 4274 |
MDefinition* foldIfNegOne(size_t operand) override { |
| 4275 |
return getOperand(operand); // x | -1 => -1 |
| 4276 |
} |
| 4277 |
MDefinition* foldIfEqual() override { |
| 4278 |
return getOperand(0); // x | x => x |
| 4279 |
} |
| 4280 |
MDefinition* foldIfAllBitsSet(size_t operand) override { return this; } |
| 4281 |
void computeRange(TempAllocator& alloc) override; |
| 4282 |
[[nodiscard]] bool writeRecoverData( |
| 4283 |
CompactBufferWriter& writer) const override; |
| 4284 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4285 |
|
| 4286 |
ALLOW_CLONE(MBitOr) |
| 4287 |
}; |
| 4288 |
|
| 4289 |
class MBitXor : public MBinaryBitwiseInstruction { |
| 4290 |
MBitXor(MDefinition* left, MDefinition* right, MIRType type) |
| 4291 |
: MBinaryBitwiseInstruction(classOpcode, left, right, type) { |
| 4292 |
setCommutative(); |
| 4293 |
} |
| 4294 |
|
| 4295 |
public: |
| 4296 |
INSTRUCTION_HEADER(BitXor) |
| 4297 |
TRIVIAL_NEW_WRAPPERS |
| 4298 |
|
| 4299 |
MDefinition* foldIfZero(size_t operand) override { |
| 4300 |
return getOperand(1 - operand); // 0 ^ x => x |
| 4301 |
} |
| 4302 |
MDefinition* foldIfNegOne(size_t operand) override { return this; } |
| 4303 |
MDefinition* foldIfEqual() override { return this; } |
| 4304 |
MDefinition* foldIfAllBitsSet(size_t operand) override { return this; } |
| 4305 |
void computeRange(TempAllocator& alloc) override; |
| 4306 |
|
| 4307 |
[[nodiscard]] bool writeRecoverData( |
| 4308 |
CompactBufferWriter& writer) const override; |
| 4309 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4310 |
|
| 4311 |
ALLOW_CLONE(MBitXor) |
| 4312 |
}; |
| 4313 |
|
| 4314 |
class MShiftInstruction : public MBinaryBitwiseInstruction { |
| 4315 |
protected: |
| 4316 |
MShiftInstruction(Opcode op, MDefinition* left, MDefinition* right, |
| 4317 |
MIRType type) |
| 4318 |
: MBinaryBitwiseInstruction(op, left, right, type) {} |
| 4319 |
|
| 4320 |
public: |
| 4321 |
MDefinition* foldIfNegOne(size_t operand) override { return this; } |
| 4322 |
MDefinition* foldIfEqual() override { return this; } |
| 4323 |
MDefinition* foldIfAllBitsSet(size_t operand) override { return this; } |
| 4324 |
}; |
| 4325 |
|
| 4326 |
class MLsh : public MShiftInstruction { |
| 4327 |
MLsh(MDefinition* left, MDefinition* right, MIRType type) |
| 4328 |
: MShiftInstruction(classOpcode, left, right, type) {} |
| 4329 |
|
| 4330 |
public: |
| 4331 |
INSTRUCTION_HEADER(Lsh) |
| 4332 |
TRIVIAL_NEW_WRAPPERS |
| 4333 |
|
| 4334 |
MDefinition* foldIfZero(size_t operand) override { |
| 4335 |
// 0 << x => 0 |
| 4336 |
// x << 0 => x |
| 4337 |
return getOperand(0); |
| 4338 |
} |
| 4339 |
|
| 4340 |
void computeRange(TempAllocator& alloc) override; |
| 4341 |
[[nodiscard]] bool writeRecoverData( |
| 4342 |
CompactBufferWriter& writer) const override; |
| 4343 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4344 |
|
| 4345 |
ALLOW_CLONE(MLsh) |
| 4346 |
}; |
| 4347 |
|
| 4348 |
class MRsh : public MShiftInstruction { |
| 4349 |
MRsh(MDefinition* left, MDefinition* right, MIRType type) |
| 4350 |
: MShiftInstruction(classOpcode, left, right, type) {} |
| 4351 |
|
| 4352 |
public: |
| 4353 |
INSTRUCTION_HEADER(Rsh) |
| 4354 |
TRIVIAL_NEW_WRAPPERS |
| 4355 |
|
| 4356 |
MDefinition* foldIfZero(size_t operand) override { |
| 4357 |
// 0 >> x => 0 |
| 4358 |
// x >> 0 => x |
| 4359 |
return getOperand(0); |
| 4360 |
} |
| 4361 |
void computeRange(TempAllocator& alloc) override; |
| 4362 |
|
| 4363 |
[[nodiscard]] bool writeRecoverData( |
| 4364 |
CompactBufferWriter& writer) const override; |
| 4365 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4366 |
|
| 4367 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4368 |
|
| 4369 |
ALLOW_CLONE(MRsh) |
| 4370 |
}; |
| 4371 |
|
| 4372 |
class MUrsh : public MShiftInstruction { |
| 4373 |
bool bailoutsDisabled_; |
| 4374 |
|
| 4375 |
MUrsh(MDefinition* left, MDefinition* right, MIRType type) |
| 4376 |
: MShiftInstruction(classOpcode, left, right, type), |
| 4377 |
bailoutsDisabled_(false) {} |
| 4378 |
|
| 4379 |
public: |
| 4380 |
INSTRUCTION_HEADER(Ursh) |
| 4381 |
TRIVIAL_NEW_WRAPPERS |
| 4382 |
|
| 4383 |
static MUrsh* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 4384 |
MDefinition* right, MIRType type); |
| 4385 |
|
| 4386 |
MDefinition* foldIfZero(size_t operand) override { |
| 4387 |
// 0 >>> x => 0 |
| 4388 |
if (operand == 0) { |
| 4389 |
return getOperand(0); |
| 4390 |
} |
| 4391 |
|
| 4392 |
return this; |
| 4393 |
} |
| 4394 |
|
| 4395 |
bool bailoutsDisabled() const { return bailoutsDisabled_; } |
| 4396 |
|
| 4397 |
bool fallible() const; |
| 4398 |
|
| 4399 |
void computeRange(TempAllocator& alloc) override; |
| 4400 |
void collectRangeInfoPreTrunc() override; |
| 4401 |
|
| 4402 |
[[nodiscard]] bool writeRecoverData( |
| 4403 |
CompactBufferWriter& writer) const override; |
| 4404 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 4405 |
|
| 4406 |
ALLOW_CLONE(MUrsh) |
| 4407 |
}; |
| 4408 |
|
| 4409 |
class MSignExtendInt32 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 4410 |
public: |
| 4411 |
enum Mode { Byte, Half }; |
| 4412 |
|
| 4413 |
private: |
| 4414 |
Mode mode_; |
| 4415 |
|
| 4416 |
MSignExtendInt32(MDefinition* op, Mode mode) |
| 4417 |
: MUnaryInstruction(classOpcode, op), mode_(mode) { |
| 4418 |
MOZ_ASSERT(op->type() == MIRType::Int32); |
| 4419 |
setResultType(MIRType::Int32); |
| 4420 |
setMovable(); |
| 4421 |
} |
| 4422 |
|
| 4423 |
public: |
| 4424 |
INSTRUCTION_HEADER(SignExtendInt32) |
| 4425 |
TRIVIAL_NEW_WRAPPERS |
| 4426 |
|
| 4427 |
Mode mode() const { return mode_; } |
| 4428 |
|
| 4429 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4430 |
bool congruentTo(const MDefinition* ins) const override { |
| 4431 |
if (!congruentIfOperandsEqual(ins)) { |
| 4432 |
return false; |
| 4433 |
} |
| 4434 |
return ins->toSignExtendInt32()->mode_ == mode_; |
| 4435 |
} |
| 4436 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4437 |
|
| 4438 |
[[nodiscard]] bool writeRecoverData( |
| 4439 |
CompactBufferWriter& writer) const override; |
| 4440 |
bool canRecoverOnBailout() const override { return true; } |
| 4441 |
|
| 4442 |
ALLOW_CLONE(MSignExtendInt32) |
| 4443 |
}; |
| 4444 |
|
| 4445 |
class MSignExtendInt64 : public MUnaryInstruction, public NoTypePolicy::Data { |
| 4446 |
public: |
| 4447 |
enum Mode { Byte, Half, Word }; |
| 4448 |
|
| 4449 |
private: |
| 4450 |
Mode mode_; |
| 4451 |
|
| 4452 |
MSignExtendInt64(MDefinition* op, Mode mode) |
| 4453 |
: MUnaryInstruction(classOpcode, op), mode_(mode) { |
| 4454 |
MOZ_ASSERT(op->type() == MIRType::Int64); |
| 4455 |
setResultType(MIRType::Int64); |
| 4456 |
setMovable(); |
| 4457 |
} |
| 4458 |
|
| 4459 |
public: |
| 4460 |
INSTRUCTION_HEADER(SignExtendInt64) |
| 4461 |
TRIVIAL_NEW_WRAPPERS |
| 4462 |
|
| 4463 |
Mode mode() const { return mode_; } |
| 4464 |
|
| 4465 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4466 |
bool congruentTo(const MDefinition* ins) const override { |
| 4467 |
if (!congruentIfOperandsEqual(ins)) { |
| 4468 |
return false; |
| 4469 |
} |
| 4470 |
return ins->toSignExtendInt64()->mode_ == mode_; |
| 4471 |
} |
| 4472 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4473 |
|
| 4474 |
ALLOW_CLONE(MSignExtendInt64) |
| 4475 |
}; |
| 4476 |
|
| 4477 |
class MSignExtendIntPtr : public MUnaryInstruction, public NoTypePolicy::Data { |
| 4478 |
public: |
| 4479 |
enum Mode { Byte, Half, Word }; |
| 4480 |
|
| 4481 |
private: |
| 4482 |
Mode mode_; |
| 4483 |
|
| 4484 |
MSignExtendIntPtr(MDefinition* op, Mode mode) |
| 4485 |
: MUnaryInstruction(classOpcode, op), mode_(mode) { |
| 4486 |
MOZ_ASSERT(op->type() == MIRType::IntPtr); |
| 4487 |
setResultType(MIRType::IntPtr); |
| 4488 |
setMovable(); |
| 4489 |
} |
| 4490 |
|
| 4491 |
public: |
| 4492 |
INSTRUCTION_HEADER(SignExtendIntPtr) |
| 4493 |
TRIVIAL_NEW_WRAPPERS |
| 4494 |
|
| 4495 |
Mode mode() const { return mode_; } |
| 4496 |
|
| 4497 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4498 |
bool congruentTo(const MDefinition* ins) const override { |
| 4499 |
if (!congruentIfOperandsEqual(ins)) { |
| 4500 |
return false; |
| 4501 |
} |
| 4502 |
return ins->toSignExtendIntPtr()->mode_ == mode_; |
| 4503 |
} |
| 4504 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4505 |
|
| 4506 |
ALLOW_CLONE(MSignExtendIntPtr) |
| 4507 |
}; |
| 4508 |
|
| 4509 |
class MBinaryArithInstruction : public MBinaryInstruction, |
| 4510 |
public ArithPolicy::Data { |
| 4511 |
// Implicit truncate flag is set by the truncate backward range analysis |
| 4512 |
// optimization phase, and by wasm pre-processing. It is used in |
| 4513 |
// NeedNegativeZeroCheck to check if the result of a multiplication needs to |
| 4514 |
// produce -0 double value, and for avoiding overflow checks. |
| 4515 |
|
| 4516 |
// This optimization happens when the multiplication cannot be truncated |
| 4517 |
// even if all uses are truncating its result, such as when the range |
| 4518 |
// analysis detect a precision loss in the multiplication. |
| 4519 |
TruncateKind implicitTruncate_; |
| 4520 |
|
| 4521 |
// Whether we must preserve NaN semantics, and in particular not fold |
| 4522 |
// (x op id) or (id op x) to x, or replace a division by a multiply of the |
| 4523 |
// exact reciprocal. |
| 4524 |
bool mustPreserveNaN_; |
| 4525 |
|
| 4526 |
protected: |
| 4527 |
MBinaryArithInstruction(Opcode op, MDefinition* left, MDefinition* right, |
| 4528 |
MIRType type) |
| 4529 |
: MBinaryInstruction(op, left, right), |
| 4530 |
implicitTruncate_(TruncateKind::NoTruncate), |
| 4531 |
mustPreserveNaN_(false) { |
| 4532 |
MOZ_ASSERT(IsNumberType(type)); |
| 4533 |
setResultType(type); |
| 4534 |
setMovable(); |
| 4535 |
} |
| 4536 |
|
| 4537 |
public: |
| 4538 |
void setMustPreserveNaN(bool b) { mustPreserveNaN_ = b; } |
| 4539 |
bool mustPreserveNaN() const { return mustPreserveNaN_; } |
| 4540 |
|
| 4541 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4542 |
#ifdef JS_JITSPEW |
| 4543 |
void printOpcode(GenericPrinter& out) const override; |
| 4544 |
#endif |
| 4545 |
|
| 4546 |
virtual double getIdentity() = 0; |
| 4547 |
|
| 4548 |
void setSpecialization(MIRType type) { |
| 4549 |
MOZ_ASSERT(IsNumberType(type)); |
| 4550 |
setResultType(type); |
| 4551 |
} |
| 4552 |
|
| 4553 |
virtual void trySpecializeFloat32(TempAllocator& alloc) override; |
| 4554 |
|
| 4555 |
bool congruentTo(const MDefinition* ins) const override { |
| 4556 |
if (!binaryCongruentTo(ins)) { |
| 4557 |
return false; |
| 4558 |
} |
| 4559 |
const auto* other = static_cast<const MBinaryArithInstruction*>(ins); |
| 4560 |
return other->mustPreserveNaN_ == mustPreserveNaN_; |
| 4561 |
} |
| 4562 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4563 |
|
| 4564 |
bool isTruncated() const { |
| 4565 |
return implicitTruncate_ == TruncateKind::Truncate; |
| 4566 |
} |
| 4567 |
TruncateKind truncateKind() const { return implicitTruncate_; } |
| 4568 |
void setTruncateKind(TruncateKind kind) { |
| 4569 |
implicitTruncate_ = std::max(implicitTruncate_, kind); |
| 4570 |
} |
| 4571 |
}; |
| 4572 |
|
| 4573 |
class MMinMax : public MBinaryInstruction, public ArithPolicy::Data { |
| 4574 |
bool isMax_; |
| 4575 |
|
| 4576 |
MMinMax(MDefinition* left, MDefinition* right, MIRType type, bool isMax) |
| 4577 |
: MBinaryInstruction(classOpcode, left, right), isMax_(isMax) { |
| 4578 |
MOZ_ASSERT(IsNumberType(type)); |
| 4579 |
setResultType(type); |
| 4580 |
setMovable(); |
| 4581 |
} |
| 4582 |
|
| 4583 |
public: |
| 4584 |
INSTRUCTION_HEADER(MinMax) |
| 4585 |
TRIVIAL_NEW_WRAPPERS |
| 4586 |
|
| 4587 |
static MMinMax* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 4588 |
MDefinition* right, MIRType type, bool isMax) { |
| 4589 |
return New(alloc, left, right, type, isMax); |
| 4590 |
} |
| 4591 |
|
| 4592 |
bool isMax() const { return isMax_; } |
| 4593 |
|
| 4594 |
bool congruentTo(const MDefinition* ins) const override { |
| 4595 |
if (!congruentIfOperandsEqual(ins)) { |
| 4596 |
return false; |
| 4597 |
} |
| 4598 |
const MMinMax* other = ins->toMinMax(); |
| 4599 |
return other->isMax() == isMax(); |
| 4600 |
} |
| 4601 |
|
| 4602 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4603 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4604 |
void computeRange(TempAllocator& alloc) override; |
| 4605 |
[[nodiscard]] bool writeRecoverData( |
| 4606 |
CompactBufferWriter& writer) const override; |
| 4607 |
bool canRecoverOnBailout() const override { return true; } |
| 4608 |
|
| 4609 |
bool isFloat32Commutative() const override { return true; } |
| 4610 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 4611 |
|
| 4612 |
#ifdef JS_JITSPEW |
| 4613 |
void printOpcode(GenericPrinter& out) const override; |
| 4614 |
#endif |
| 4615 |
|
| 4616 |
ALLOW_CLONE(MMinMax) |
| 4617 |
}; |
| 4618 |
|
| 4619 |
class MMinMaxArray : public MUnaryInstruction, public SingleObjectPolicy::Data { |
| 4620 |
bool isMax_; |
| 4621 |
|
| 4622 |
MMinMaxArray(MDefinition* array, MIRType type, bool isMax) |
| 4623 |
: MUnaryInstruction(classOpcode, array), isMax_(isMax) { |
| 4624 |
MOZ_ASSERT(type == MIRType::Int32 || type == MIRType::Double); |
| 4625 |
setResultType(type); |
| 4626 |
|
| 4627 |
// We can't DCE this, even if the result is unused, in case one of the |
| 4628 |
// elements of the array is an object with a `valueOf` function that |
| 4629 |
// must be called. |
| 4630 |
setGuard(); |
| 4631 |
} |
| 4632 |
|
| 4633 |
public: |
| 4634 |
INSTRUCTION_HEADER(MinMaxArray) |
| 4635 |
TRIVIAL_NEW_WRAPPERS |
| 4636 |
NAMED_OPERANDS((0, array)) |
| 4637 |
|
| 4638 |
bool isMax() const { return isMax_; } |
| 4639 |
|
| 4640 |
bool congruentTo(const MDefinition* ins) const override { |
| 4641 |
if (!ins->isMinMaxArray() || ins->toMinMaxArray()->isMax() != isMax()) { |
| 4642 |
return false; |
| 4643 |
} |
| 4644 |
return congruentIfOperandsEqual(ins); |
| 4645 |
} |
| 4646 |
|
| 4647 |
AliasSet getAliasSet() const override { |
| 4648 |
return AliasSet::Load(AliasSet::ObjectFields | AliasSet::Element); |
| 4649 |
} |
| 4650 |
|
| 4651 |
#ifdef JS_JITSPEW |
| 4652 |
void printOpcode(GenericPrinter& out) const override; |
| 4653 |
#endif |
| 4654 |
}; |
| 4655 |
|
| 4656 |
class MAbs : public MUnaryInstruction, public ArithPolicy::Data { |
| 4657 |
bool implicitTruncate_; |
| 4658 |
|
| 4659 |
MAbs(MDefinition* num, MIRType type) |
| 4660 |
: MUnaryInstruction(classOpcode, num), implicitTruncate_(false) { |
| 4661 |
MOZ_ASSERT(IsNumberType(type)); |
| 4662 |
setResultType(type); |
| 4663 |
setMovable(); |
| 4664 |
} |
| 4665 |
|
| 4666 |
public: |
| 4667 |
INSTRUCTION_HEADER(Abs) |
| 4668 |
TRIVIAL_NEW_WRAPPERS |
| 4669 |
|
| 4670 |
static MAbs* NewWasm(TempAllocator& alloc, MDefinition* num, MIRType type) { |
| 4671 |
auto* ins = new (alloc) MAbs(num, type); |
| 4672 |
if (type == MIRType::Int32) { |
| 4673 |
ins->implicitTruncate_ = true; |
| 4674 |
} |
| 4675 |
return ins; |
| 4676 |
} |
| 4677 |
|
| 4678 |
bool congruentTo(const MDefinition* ins) const override { |
| 4679 |
return congruentIfOperandsEqual(ins); |
| 4680 |
} |
| 4681 |
bool fallible() const; |
| 4682 |
|
| 4683 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4684 |
void computeRange(TempAllocator& alloc) override; |
| 4685 |
bool isFloat32Commutative() const override { return true; } |
| 4686 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 4687 |
|
| 4688 |
[[nodiscard]] bool writeRecoverData( |
| 4689 |
CompactBufferWriter& writer) const override; |
| 4690 |
bool canRecoverOnBailout() const override { return true; } |
| 4691 |
|
| 4692 |
ALLOW_CLONE(MAbs) |
| 4693 |
}; |
| 4694 |
|
| 4695 |
class MClz : public MUnaryInstruction, public BitwisePolicy::Data { |
| 4696 |
bool operandIsNeverZero_; |
| 4697 |
|
| 4698 |
explicit MClz(MDefinition* num, MIRType type) |
| 4699 |
: MUnaryInstruction(classOpcode, num), operandIsNeverZero_(false) { |
| 4700 |
MOZ_ASSERT(IsIntType(type)); |
| 4701 |
MOZ_ASSERT(IsNumberType(num->type())); |
| 4702 |
setResultType(type); |
| 4703 |
setMovable(); |
| 4704 |
} |
| 4705 |
|
| 4706 |
public: |
| 4707 |
INSTRUCTION_HEADER(Clz) |
| 4708 |
TRIVIAL_NEW_WRAPPERS |
| 4709 |
NAMED_OPERANDS((0, num)) |
| 4710 |
|
| 4711 |
bool congruentTo(const MDefinition* ins) const override { |
| 4712 |
return congruentIfOperandsEqual(ins); |
| 4713 |
} |
| 4714 |
|
| 4715 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4716 |
|
| 4717 |
bool operandIsNeverZero() const { return operandIsNeverZero_; } |
| 4718 |
|
| 4719 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4720 |
void computeRange(TempAllocator& alloc) override; |
| 4721 |
void collectRangeInfoPreTrunc() override; |
| 4722 |
|
| 4723 |
ALLOW_CLONE(MClz) |
| 4724 |
}; |
| 4725 |
|
| 4726 |
class MCtz : public MUnaryInstruction, public BitwisePolicy::Data { |
| 4727 |
bool operandIsNeverZero_; |
| 4728 |
|
| 4729 |
explicit MCtz(MDefinition* num, MIRType type) |
| 4730 |
: MUnaryInstruction(classOpcode, num), operandIsNeverZero_(false) { |
| 4731 |
MOZ_ASSERT(IsIntType(type)); |
| 4732 |
MOZ_ASSERT(IsNumberType(num->type())); |
| 4733 |
setResultType(type); |
| 4734 |
setMovable(); |
| 4735 |
} |
| 4736 |
|
| 4737 |
public: |
| 4738 |
INSTRUCTION_HEADER(Ctz) |
| 4739 |
TRIVIAL_NEW_WRAPPERS |
| 4740 |
NAMED_OPERANDS((0, num)) |
| 4741 |
|
| 4742 |
bool congruentTo(const MDefinition* ins) const override { |
| 4743 |
return congruentIfOperandsEqual(ins); |
| 4744 |
} |
| 4745 |
|
| 4746 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4747 |
|
| 4748 |
bool operandIsNeverZero() const { return operandIsNeverZero_; } |
| 4749 |
|
| 4750 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4751 |
void computeRange(TempAllocator& alloc) override; |
| 4752 |
void collectRangeInfoPreTrunc() override; |
| 4753 |
|
| 4754 |
ALLOW_CLONE(MCtz) |
| 4755 |
}; |
| 4756 |
|
| 4757 |
class MPopcnt : public MUnaryInstruction, public BitwisePolicy::Data { |
| 4758 |
explicit MPopcnt(MDefinition* num, MIRType type) |
| 4759 |
: MUnaryInstruction(classOpcode, num) { |
| 4760 |
MOZ_ASSERT(IsNumberType(num->type())); |
| 4761 |
MOZ_ASSERT(IsIntType(type)); |
| 4762 |
setResultType(type); |
| 4763 |
setMovable(); |
| 4764 |
} |
| 4765 |
|
| 4766 |
public: |
| 4767 |
INSTRUCTION_HEADER(Popcnt) |
| 4768 |
TRIVIAL_NEW_WRAPPERS |
| 4769 |
NAMED_OPERANDS((0, num)) |
| 4770 |
|
| 4771 |
bool congruentTo(const MDefinition* ins) const override { |
| 4772 |
return congruentIfOperandsEqual(ins); |
| 4773 |
} |
| 4774 |
|
| 4775 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4776 |
|
| 4777 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4778 |
void computeRange(TempAllocator& alloc) override; |
| 4779 |
|
| 4780 |
ALLOW_CLONE(MPopcnt) |
| 4781 |
}; |
| 4782 |
|
| 4783 |
// Inline implementation of Math.sqrt(). |
| 4784 |
class MSqrt : public MUnaryInstruction, public FloatingPointPolicy<0>::Data { |
| 4785 |
MSqrt(MDefinition* num, MIRType type) : MUnaryInstruction(classOpcode, num) { |
| 4786 |
setResultType(type); |
| 4787 |
specialization_ = type; |
| 4788 |
setMovable(); |
| 4789 |
} |
| 4790 |
|
| 4791 |
public: |
| 4792 |
INSTRUCTION_HEADER(Sqrt) |
| 4793 |
TRIVIAL_NEW_WRAPPERS |
| 4794 |
|
| 4795 |
bool congruentTo(const MDefinition* ins) const override { |
| 4796 |
return congruentIfOperandsEqual(ins); |
| 4797 |
} |
| 4798 |
|
| 4799 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4800 |
void computeRange(TempAllocator& alloc) override; |
| 4801 |
|
| 4802 |
bool isFloat32Commutative() const override { return true; } |
| 4803 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 4804 |
|
| 4805 |
[[nodiscard]] bool writeRecoverData( |
| 4806 |
CompactBufferWriter& writer) const override; |
| 4807 |
bool canRecoverOnBailout() const override { return true; } |
| 4808 |
|
| 4809 |
ALLOW_CLONE(MSqrt) |
| 4810 |
}; |
| 4811 |
|
| 4812 |
class MCopySign : public MBinaryInstruction, public NoTypePolicy::Data { |
| 4813 |
MCopySign(MDefinition* lhs, MDefinition* rhs, MIRType type) |
| 4814 |
: MBinaryInstruction(classOpcode, lhs, rhs) { |
| 4815 |
setResultType(type); |
| 4816 |
setMovable(); |
| 4817 |
} |
| 4818 |
|
| 4819 |
public: |
| 4820 |
INSTRUCTION_HEADER(CopySign) |
| 4821 |
TRIVIAL_NEW_WRAPPERS |
| 4822 |
|
| 4823 |
bool congruentTo(const MDefinition* ins) const override { |
| 4824 |
return congruentIfOperandsEqual(ins); |
| 4825 |
} |
| 4826 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4827 |
|
| 4828 |
ALLOW_CLONE(MCopySign) |
| 4829 |
}; |
| 4830 |
|
| 4831 |
// Inline implementation of Math.hypot(). |
| 4832 |
class MHypot : public MVariadicInstruction, public AllDoublePolicy::Data { |
| 4833 |
MHypot() : MVariadicInstruction(classOpcode) { |
| 4834 |
setResultType(MIRType::Double); |
| 4835 |
setMovable(); |
| 4836 |
} |
| 4837 |
|
| 4838 |
public: |
| 4839 |
INSTRUCTION_HEADER(Hypot) |
| 4840 |
static MHypot* New(TempAllocator& alloc, const MDefinitionVector& vector); |
| 4841 |
|
| 4842 |
bool congruentTo(const MDefinition* ins) const override { |
| 4843 |
return congruentIfOperandsEqual(ins); |
| 4844 |
} |
| 4845 |
|
| 4846 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4847 |
|
| 4848 |
bool possiblyCalls() const override { return true; } |
| 4849 |
|
| 4850 |
[[nodiscard]] bool writeRecoverData( |
| 4851 |
CompactBufferWriter& writer) const override; |
| 4852 |
bool canRecoverOnBailout() const override { return true; } |
| 4853 |
|
| 4854 |
bool canClone() const override { return true; } |
| 4855 |
|
| 4856 |
MInstruction* clone(TempAllocator& alloc, |
| 4857 |
const MDefinitionVector& inputs) const override { |
| 4858 |
return MHypot::New(alloc, inputs); |
| 4859 |
} |
| 4860 |
}; |
| 4861 |
|
| 4862 |
// Inline implementation of Math.pow(). |
| 4863 |
// |
| 4864 |
// Supports the following three specializations: |
| 4865 |
// |
| 4866 |
// 1. MPow(FloatingPoint, FloatingPoint) -> Double |
| 4867 |
// - The most general mode, calls js::ecmaPow. |
| 4868 |
// - Never performs a bailout. |
| 4869 |
// 2. MPow(FloatingPoint, Int32) -> Double |
| 4870 |
// - Optimization to call js::powi instead of js::ecmaPow. |
| 4871 |
// - Never performs a bailout. |
| 4872 |
// 3. MPow(Int32, Int32) -> Int32 |
| 4873 |
// - Performs the complete exponentiation operation in assembly code. |
| 4874 |
// - Bails out if the result doesn't fit in Int32. |
| 4875 |
class MPow : public MBinaryInstruction, public PowPolicy::Data { |
| 4876 |
// If true, the result is guaranteed to never be negative zero, as long as the |
| 4877 |
// power is a positive number. |
| 4878 |
bool canBeNegativeZero_; |
| 4879 |
|
| 4880 |
MPow(MDefinition* input, MDefinition* power, MIRType specialization) |
| 4881 |
: MBinaryInstruction(classOpcode, input, power) { |
| 4882 |
MOZ_ASSERT(specialization == MIRType::Int32 || |
| 4883 |
specialization == MIRType::Double); |
| 4884 |
setResultType(specialization); |
| 4885 |
setMovable(); |
| 4886 |
|
| 4887 |
// The result can't be negative zero if the base is an Int32 value. |
| 4888 |
canBeNegativeZero_ = input->type() != MIRType::Int32; |
| 4889 |
} |
| 4890 |
|
| 4891 |
// Helpers for `foldsTo` |
| 4892 |
MDefinition* foldsConstant(TempAllocator& alloc); |
| 4893 |
MDefinition* foldsConstantPower(TempAllocator& alloc); |
| 4894 |
|
| 4895 |
bool canBeNegativeZero() const { return canBeNegativeZero_; } |
| 4896 |
|
| 4897 |
public: |
| 4898 |
INSTRUCTION_HEADER(Pow) |
| 4899 |
TRIVIAL_NEW_WRAPPERS |
| 4900 |
|
| 4901 |
MDefinition* input() const { return lhs(); } |
| 4902 |
MDefinition* power() const { return rhs(); } |
| 4903 |
|
| 4904 |
bool congruentTo(const MDefinition* ins) const override { |
| 4905 |
return congruentIfOperandsEqual(ins); |
| 4906 |
} |
| 4907 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4908 |
bool possiblyCalls() const override { return type() != MIRType::Int32; } |
| 4909 |
[[nodiscard]] bool writeRecoverData( |
| 4910 |
CompactBufferWriter& writer) const override; |
| 4911 |
bool canRecoverOnBailout() const override { return true; } |
| 4912 |
|
| 4913 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4914 |
|
| 4915 |
ALLOW_CLONE(MPow) |
| 4916 |
}; |
| 4917 |
|
| 4918 |
// Inline implementation of Math.pow(x, 0.5), which subtly differs from |
| 4919 |
// Math.sqrt(x). |
| 4920 |
class MPowHalf : public MUnaryInstruction, public DoublePolicy<0>::Data { |
| 4921 |
bool operandIsNeverNegativeInfinity_; |
| 4922 |
bool operandIsNeverNegativeZero_; |
| 4923 |
bool operandIsNeverNaN_; |
| 4924 |
|
| 4925 |
explicit MPowHalf(MDefinition* input) |
| 4926 |
: MUnaryInstruction(classOpcode, input), |
| 4927 |
operandIsNeverNegativeInfinity_(false), |
| 4928 |
operandIsNeverNegativeZero_(false), |
| 4929 |
operandIsNeverNaN_(false) { |
| 4930 |
setResultType(MIRType::Double); |
| 4931 |
setMovable(); |
| 4932 |
} |
| 4933 |
|
| 4934 |
public: |
| 4935 |
INSTRUCTION_HEADER(PowHalf) |
| 4936 |
TRIVIAL_NEW_WRAPPERS |
| 4937 |
|
| 4938 |
bool congruentTo(const MDefinition* ins) const override { |
| 4939 |
return congruentIfOperandsEqual(ins); |
| 4940 |
} |
| 4941 |
bool operandIsNeverNegativeInfinity() const { |
| 4942 |
return operandIsNeverNegativeInfinity_; |
| 4943 |
} |
| 4944 |
bool operandIsNeverNegativeZero() const { |
| 4945 |
return operandIsNeverNegativeZero_; |
| 4946 |
} |
| 4947 |
bool operandIsNeverNaN() const { return operandIsNeverNaN_; } |
| 4948 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4949 |
void collectRangeInfoPreTrunc() override; |
| 4950 |
[[nodiscard]] bool writeRecoverData( |
| 4951 |
CompactBufferWriter& writer) const override; |
| 4952 |
bool canRecoverOnBailout() const override { return true; } |
| 4953 |
|
| 4954 |
ALLOW_CLONE(MPowHalf) |
| 4955 |
}; |
| 4956 |
|
| 4957 |
class MSign : public MUnaryInstruction, public SignPolicy::Data { |
| 4958 |
private: |
| 4959 |
MSign(MDefinition* input, MIRType resultType) |
| 4960 |
: MUnaryInstruction(classOpcode, input) { |
| 4961 |
MOZ_ASSERT(IsNumberType(input->type())); |
| 4962 |
MOZ_ASSERT(resultType == MIRType::Int32 || resultType == MIRType::Double); |
| 4963 |
specialization_ = input->type(); |
| 4964 |
setResultType(resultType); |
| 4965 |
setMovable(); |
| 4966 |
} |
| 4967 |
|
| 4968 |
public: |
| 4969 |
INSTRUCTION_HEADER(Sign) |
| 4970 |
TRIVIAL_NEW_WRAPPERS |
| 4971 |
|
| 4972 |
bool congruentTo(const MDefinition* ins) const override { |
| 4973 |
return congruentIfOperandsEqual(ins); |
| 4974 |
} |
| 4975 |
|
| 4976 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 4977 |
|
| 4978 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 4979 |
|
| 4980 |
void computeRange(TempAllocator& alloc) override; |
| 4981 |
[[nodiscard]] bool writeRecoverData( |
| 4982 |
CompactBufferWriter& writer) const override; |
| 4983 |
bool canRecoverOnBailout() const override { return true; } |
| 4984 |
|
| 4985 |
ALLOW_CLONE(MSign) |
| 4986 |
}; |
| 4987 |
|
| 4988 |
class MMathFunction : public MUnaryInstruction, |
| 4989 |
public FloatingPointPolicy<0>::Data { |
| 4990 |
UnaryMathFunction function_; |
| 4991 |
|
| 4992 |
// A nullptr cache means this function will neither access nor update the |
| 4993 |
// cache. |
| 4994 |
MMathFunction(MDefinition* input, UnaryMathFunction function) |
| 4995 |
: MUnaryInstruction(classOpcode, input), function_(function) { |
| 4996 |
setResultType(MIRType::Double); |
| 4997 |
specialization_ = MIRType::Double; |
| 4998 |
setMovable(); |
| 4999 |
} |
| 5000 |
|
| 5001 |
public: |
| 5002 |
INSTRUCTION_HEADER(MathFunction) |
| 5003 |
TRIVIAL_NEW_WRAPPERS |
| 5004 |
|
| 5005 |
UnaryMathFunction function() const { return function_; } |
| 5006 |
|
| 5007 |
bool congruentTo(const MDefinition* ins) const override { |
| 5008 |
if (!ins->isMathFunction()) { |
| 5009 |
return false; |
| 5010 |
} |
| 5011 |
if (ins->toMathFunction()->function() != function()) { |
| 5012 |
return false; |
| 5013 |
} |
| 5014 |
return congruentIfOperandsEqual(ins); |
| 5015 |
} |
| 5016 |
|
| 5017 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 5018 |
|
| 5019 |
bool possiblyCalls() const override { return true; } |
| 5020 |
|
| 5021 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5022 |
|
| 5023 |
#ifdef JS_JITSPEW |
| 5024 |
void printOpcode(GenericPrinter& out) const override; |
| 5025 |
#endif |
| 5026 |
|
| 5027 |
static const char* FunctionName(UnaryMathFunction function); |
| 5028 |
|
| 5029 |
bool isFloat32Commutative() const override; |
| 5030 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 5031 |
|
| 5032 |
void computeRange(TempAllocator& alloc) override; |
| 5033 |
|
| 5034 |
[[nodiscard]] bool writeRecoverData( |
| 5035 |
CompactBufferWriter& writer) const override; |
| 5036 |
bool canRecoverOnBailout() const override { return true; } |
| 5037 |
|
| 5038 |
ALLOW_CLONE(MMathFunction) |
| 5039 |
}; |
| 5040 |
|
| 5041 |
class MAdd : public MBinaryArithInstruction { |
| 5042 |
MAdd(MDefinition* left, MDefinition* right, MIRType type) |
| 5043 |
: MBinaryArithInstruction(classOpcode, left, right, type) { |
| 5044 |
setCommutative(); |
| 5045 |
} |
| 5046 |
|
| 5047 |
MAdd(MDefinition* left, MDefinition* right, TruncateKind truncateKind) |
| 5048 |
: MAdd(left, right, MIRType::Int32) { |
| 5049 |
setTruncateKind(truncateKind); |
| 5050 |
} |
| 5051 |
|
| 5052 |
public: |
| 5053 |
INSTRUCTION_HEADER(Add) |
| 5054 |
TRIVIAL_NEW_WRAPPERS |
| 5055 |
|
| 5056 |
static MAdd* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 5057 |
MDefinition* right, MIRType type) { |
| 5058 |
auto* ret = new (alloc) MAdd(left, right, type); |
| 5059 |
if (type == MIRType::Int32) { |
| 5060 |
ret->setTruncateKind(TruncateKind::Truncate); |
| 5061 |
} |
| 5062 |
return ret; |
| 5063 |
} |
| 5064 |
|
| 5065 |
bool isFloat32Commutative() const override { return true; } |
| 5066 |
|
| 5067 |
double getIdentity() override { return 0; } |
| 5068 |
|
| 5069 |
bool fallible() const; |
| 5070 |
void computeRange(TempAllocator& alloc) override; |
| 5071 |
bool canTruncate() const override; |
| 5072 |
void truncate(TruncateKind kind) override; |
| 5073 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 5074 |
|
| 5075 |
[[nodiscard]] bool writeRecoverData( |
| 5076 |
CompactBufferWriter& writer) const override; |
| 5077 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 5078 |
|
| 5079 |
ALLOW_CLONE(MAdd) |
| 5080 |
}; |
| 5081 |
|
| 5082 |
class MSub : public MBinaryArithInstruction { |
| 5083 |
MSub(MDefinition* left, MDefinition* right, MIRType type) |
| 5084 |
: MBinaryArithInstruction(classOpcode, left, right, type) {} |
| 5085 |
|
| 5086 |
public: |
| 5087 |
INSTRUCTION_HEADER(Sub) |
| 5088 |
TRIVIAL_NEW_WRAPPERS |
| 5089 |
|
| 5090 |
static MSub* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 5091 |
MDefinition* right, MIRType type, bool mustPreserveNaN) { |
| 5092 |
auto* ret = new (alloc) MSub(left, right, type); |
| 5093 |
ret->setMustPreserveNaN(mustPreserveNaN); |
| 5094 |
if (type == MIRType::Int32) { |
| 5095 |
ret->setTruncateKind(TruncateKind::Truncate); |
| 5096 |
} |
| 5097 |
return ret; |
| 5098 |
} |
| 5099 |
|
| 5100 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5101 |
|
| 5102 |
double getIdentity() override { return 0; } |
| 5103 |
|
| 5104 |
bool isFloat32Commutative() const override { return true; } |
| 5105 |
|
| 5106 |
bool fallible() const; |
| 5107 |
void computeRange(TempAllocator& alloc) override; |
| 5108 |
bool canTruncate() const override; |
| 5109 |
void truncate(TruncateKind kind) override; |
| 5110 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 5111 |
|
| 5112 |
[[nodiscard]] bool writeRecoverData( |
| 5113 |
CompactBufferWriter& writer) const override; |
| 5114 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 5115 |
|
| 5116 |
ALLOW_CLONE(MSub) |
| 5117 |
}; |
| 5118 |
|
| 5119 |
class MMul : public MBinaryArithInstruction { |
| 5120 |
public: |
| 5121 |
enum Mode { Normal, Integer }; |
| 5122 |
|
| 5123 |
private: |
| 5124 |
// Annotation the result could be a negative zero |
| 5125 |
// and we need to guard this during execution. |
| 5126 |
bool canBeNegativeZero_; |
| 5127 |
|
| 5128 |
Mode mode_; |
| 5129 |
|
| 5130 |
MMul(MDefinition* left, MDefinition* right, MIRType type, Mode mode) |
| 5131 |
: MBinaryArithInstruction(classOpcode, left, right, type), |
| 5132 |
canBeNegativeZero_(true), |
| 5133 |
mode_(mode) { |
| 5134 |
setCommutative(); |
| 5135 |
if (mode == Integer) { |
| 5136 |
// This implements the required behavior for Math.imul, which |
| 5137 |
// can never fail and always truncates its output to int32. |
| 5138 |
canBeNegativeZero_ = false; |
| 5139 |
setTruncateKind(TruncateKind::Truncate); |
| 5140 |
} |
| 5141 |
MOZ_ASSERT_IF(mode != Integer, mode == Normal); |
| 5142 |
} |
| 5143 |
|
| 5144 |
public: |
| 5145 |
INSTRUCTION_HEADER(Mul) |
| 5146 |
|
| 5147 |
static MMul* New(TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 5148 |
MIRType type, Mode mode = Normal) { |
| 5149 |
return new (alloc) MMul(left, right, type, mode); |
| 5150 |
} |
| 5151 |
static MMul* NewWasm(TempAllocator& alloc, MDefinition* left, |
| 5152 |
MDefinition* right, MIRType type, Mode mode, |
| 5153 |
bool mustPreserveNaN) { |
| 5154 |
auto* ret = new (alloc) MMul(left, right, type, mode); |
| 5155 |
ret->setMustPreserveNaN(mustPreserveNaN); |
| 5156 |
return ret; |
| 5157 |
} |
| 5158 |
|
| 5159 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5160 |
void analyzeEdgeCasesForward() override; |
| 5161 |
void analyzeEdgeCasesBackward() override; |
| 5162 |
void collectRangeInfoPreTrunc() override; |
| 5163 |
|
| 5164 |
double getIdentity() override { return 1; } |
| 5165 |
|
| 5166 |
bool congruentTo(const MDefinition* ins) const override { |
| 5167 |
if (!ins->isMul()) { |
| 5168 |
return false; |
| 5169 |
} |
| 5170 |
|
| 5171 |
const MMul* mul = ins->toMul(); |
| 5172 |
if (canBeNegativeZero_ != mul->canBeNegativeZero()) { |
| 5173 |
return false; |
| 5174 |
} |
| 5175 |
|
| 5176 |
if (mode_ != mul->mode()) { |
| 5177 |
return false; |
| 5178 |
} |
| 5179 |
|
| 5180 |
if (mustPreserveNaN() != mul->mustPreserveNaN()) { |
| 5181 |
return false; |
| 5182 |
} |
| 5183 |
|
| 5184 |
return binaryCongruentTo(ins); |
| 5185 |
} |
| 5186 |
|
| 5187 |
bool canOverflow() const; |
| 5188 |
|
| 5189 |
bool canBeNegativeZero() const { return canBeNegativeZero_; } |
| 5190 |
void setCanBeNegativeZero(bool negativeZero) { |
| 5191 |
canBeNegativeZero_ = negativeZero; |
| 5192 |
} |
| 5193 |
|
| 5194 |
bool fallible() const { return canBeNegativeZero_ || canOverflow(); } |
| 5195 |
|
| 5196 |
bool isFloat32Commutative() const override { return true; } |
| 5197 |
|
| 5198 |
void computeRange(TempAllocator& alloc) override; |
| 5199 |
bool canTruncate() const override; |
| 5200 |
void truncate(TruncateKind kind) override; |
| 5201 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 5202 |
|
| 5203 |
Mode mode() const { return mode_; } |
| 5204 |
|
| 5205 |
[[nodiscard]] bool writeRecoverData( |
| 5206 |
CompactBufferWriter& writer) const override; |
| 5207 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 5208 |
|
| 5209 |
ALLOW_CLONE(MMul) |
| 5210 |
}; |
| 5211 |
|
| 5212 |
class MDiv : public MBinaryArithInstruction { |
| 5213 |
bool canBeNegativeZero_; |
| 5214 |
bool canBeNegativeOverflow_; |
| 5215 |
bool canBeDivideByZero_; |
| 5216 |
bool canBeNegativeDividend_; |
| 5217 |
bool unsigned_; // If false, signedness will be derived from operands |
| 5218 |
bool trapOnError_; |
| 5219 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 5220 |
|
| 5221 |
MDiv(MDefinition* left, MDefinition* right, MIRType type) |
| 5222 |
: MBinaryArithInstruction(classOpcode, left, right, type), |
| 5223 |
canBeNegativeZero_(true), |
| 5224 |
canBeNegativeOverflow_(true), |
| 5225 |
canBeDivideByZero_(true), |
| 5226 |
canBeNegativeDividend_(true), |
| 5227 |
unsigned_(false), |
| 5228 |
trapOnError_(false) {} |
| 5229 |
|
| 5230 |
public: |
| 5231 |
INSTRUCTION_HEADER(Div) |
| 5232 |
|
| 5233 |
static MDiv* New(TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 5234 |
MIRType type) { |
| 5235 |
return new (alloc) MDiv(left, right, type); |
| 5236 |
} |
| 5237 |
static MDiv* New(TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 5238 |
MIRType type, bool unsignd, bool trapOnError = false, |
| 5239 |
wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc(), |
| 5240 |
bool mustPreserveNaN = false) { |
| 5241 |
auto* div = new (alloc) MDiv(left, right, type); |
| 5242 |
div->unsigned_ = unsignd; |
| 5243 |
div->trapOnError_ = trapOnError; |
| 5244 |
div->trapSiteDesc_ = trapSiteDesc; |
| 5245 |
if (trapOnError) { |
| 5246 |
div->setGuard(); // not removable because of possible side-effects. |
| 5247 |
div->setNotMovable(); |
| 5248 |
} |
| 5249 |
div->setMustPreserveNaN(mustPreserveNaN); |
| 5250 |
if (type == MIRType::Int32) { |
| 5251 |
div->setTruncateKind(TruncateKind::Truncate); |
| 5252 |
} |
| 5253 |
return div; |
| 5254 |
} |
| 5255 |
|
| 5256 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5257 |
void analyzeEdgeCasesForward() override; |
| 5258 |
void analyzeEdgeCasesBackward() override; |
| 5259 |
|
| 5260 |
double getIdentity() override { MOZ_CRASH("not used"); } |
| 5261 |
|
| 5262 |
bool canBeNegativeZero() const { |
| 5263 |
// This flag is only valid for integer division. |
| 5264 |
MOZ_ASSERT(type() == MIRType::Int32); |
| 5265 |
return canBeNegativeZero_; |
| 5266 |
} |
| 5267 |
void setCanBeNegativeZero(bool negativeZero) { |
| 5268 |
canBeNegativeZero_ = negativeZero; |
| 5269 |
} |
| 5270 |
|
| 5271 |
bool canBeNegativeOverflow() const { return canBeNegativeOverflow_; } |
| 5272 |
|
| 5273 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 5274 |
|
| 5275 |
bool canBeNegativeDividend() const { |
| 5276 |
// "Dividend" is an ambiguous concept for unsigned truncated |
| 5277 |
// division, because of the truncation procedure: |
| 5278 |
// ((x>>>0)/2)|0, for example, gets transformed in |
| 5279 |
// MDiv::truncate into a node with lhs representing x (not |
| 5280 |
// x>>>0) and rhs representing the constant 2; in other words, |
| 5281 |
// the MIR node corresponds to "cast operands to unsigned and |
| 5282 |
// divide" operation. In this case, is the dividend x or is it |
| 5283 |
// x>>>0? In order to resolve such ambiguities, we disallow |
| 5284 |
// the usage of this method for unsigned division. |
| 5285 |
MOZ_ASSERT(!unsigned_); |
| 5286 |
return canBeNegativeDividend_; |
| 5287 |
} |
| 5288 |
|
| 5289 |
bool isUnsigned() const { return unsigned_; } |
| 5290 |
|
| 5291 |
bool isTruncatedIndirectly() const { |
| 5292 |
return truncateKind() >= TruncateKind::IndirectTruncate; |
| 5293 |
} |
| 5294 |
|
| 5295 |
bool canTruncateInfinities() const { return isTruncated(); } |
| 5296 |
bool canTruncateRemainder() const { return isTruncated(); } |
| 5297 |
bool canTruncateOverflow() const { |
| 5298 |
return isTruncated() || isTruncatedIndirectly(); |
| 5299 |
} |
| 5300 |
bool canTruncateNegativeZero() const { |
| 5301 |
return isTruncated() || isTruncatedIndirectly(); |
| 5302 |
} |
| 5303 |
|
| 5304 |
bool trapOnError() const { return trapOnError_; } |
| 5305 |
const wasm::TrapSiteDesc& trapSiteDesc() const { |
| 5306 |
MOZ_ASSERT(trapSiteDesc_.isValid()); |
| 5307 |
return trapSiteDesc_; |
| 5308 |
} |
| 5309 |
|
| 5310 |
bool isFloat32Commutative() const override { return true; } |
| 5311 |
|
| 5312 |
void computeRange(TempAllocator& alloc) override; |
| 5313 |
bool fallible() const; |
| 5314 |
bool canTruncate() const override; |
| 5315 |
void truncate(TruncateKind kind) override; |
| 5316 |
void collectRangeInfoPreTrunc() override; |
| 5317 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 5318 |
|
| 5319 |
[[nodiscard]] bool writeRecoverData( |
| 5320 |
CompactBufferWriter& writer) const override; |
| 5321 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 5322 |
|
| 5323 |
bool congruentTo(const MDefinition* ins) const override { |
| 5324 |
if (!MBinaryArithInstruction::congruentTo(ins)) { |
| 5325 |
return false; |
| 5326 |
} |
| 5327 |
const MDiv* other = ins->toDiv(); |
| 5328 |
MOZ_ASSERT(other->trapOnError() == trapOnError_); |
| 5329 |
return unsigned_ == other->isUnsigned(); |
| 5330 |
} |
| 5331 |
|
| 5332 |
ALLOW_CLONE(MDiv) |
| 5333 |
}; |
| 5334 |
|
| 5335 |
class MMod : public MBinaryArithInstruction { |
| 5336 |
bool unsigned_; // If false, signedness will be derived from operands |
| 5337 |
bool canBeNegativeDividend_; |
| 5338 |
bool canBePowerOfTwoDivisor_; |
| 5339 |
bool canBeDivideByZero_; |
| 5340 |
bool trapOnError_; |
| 5341 |
wasm::TrapSiteDesc trapSiteDesc_; |
| 5342 |
|
| 5343 |
MMod(MDefinition* left, MDefinition* right, MIRType type) |
| 5344 |
: MBinaryArithInstruction(classOpcode, left, right, type), |
| 5345 |
unsigned_(false), |
| 5346 |
canBeNegativeDividend_(true), |
| 5347 |
canBePowerOfTwoDivisor_(true), |
| 5348 |
canBeDivideByZero_(true), |
| 5349 |
trapOnError_(false) {} |
| 5350 |
|
| 5351 |
public: |
| 5352 |
INSTRUCTION_HEADER(Mod) |
| 5353 |
|
| 5354 |
static MMod* New(TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 5355 |
MIRType type) { |
| 5356 |
return new (alloc) MMod(left, right, type); |
| 5357 |
} |
| 5358 |
static MMod* New(TempAllocator& alloc, MDefinition* left, MDefinition* right, |
| 5359 |
MIRType type, bool unsignd, bool trapOnError = false, |
| 5360 |
wasm::TrapSiteDesc trapSiteDesc = wasm::TrapSiteDesc()) { |
| 5361 |
auto* mod = new (alloc) MMod(left, right, type); |
| 5362 |
mod->unsigned_ = unsignd; |
| 5363 |
mod->trapOnError_ = trapOnError; |
| 5364 |
mod->trapSiteDesc_ = trapSiteDesc; |
| 5365 |
if (trapOnError) { |
| 5366 |
mod->setGuard(); // not removable because of possible side-effects. |
| 5367 |
mod->setNotMovable(); |
| 5368 |
} |
| 5369 |
if (type == MIRType::Int32) { |
| 5370 |
mod->setTruncateKind(TruncateKind::Truncate); |
| 5371 |
} |
| 5372 |
return mod; |
| 5373 |
} |
| 5374 |
|
| 5375 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5376 |
|
| 5377 |
double getIdentity() override { MOZ_CRASH("not used"); } |
| 5378 |
|
| 5379 |
bool canBeNegativeDividend() const { |
| 5380 |
MOZ_ASSERT(type() == MIRType::Int32 || type() == MIRType::Int64); |
| 5381 |
MOZ_ASSERT(!unsigned_); |
| 5382 |
return canBeNegativeDividend_; |
| 5383 |
} |
| 5384 |
|
| 5385 |
bool canBeDivideByZero() const { |
| 5386 |
MOZ_ASSERT(type() == MIRType::Int32 || type() == MIRType::Int64); |
| 5387 |
return canBeDivideByZero_; |
| 5388 |
} |
| 5389 |
|
| 5390 |
bool canBePowerOfTwoDivisor() const { |
| 5391 |
MOZ_ASSERT(type() == MIRType::Int32); |
| 5392 |
return canBePowerOfTwoDivisor_; |
| 5393 |
} |
| 5394 |
|
| 5395 |
void analyzeEdgeCasesForward() override; |
| 5396 |
|
| 5397 |
bool isUnsigned() const { return unsigned_; } |
| 5398 |
|
| 5399 |
bool trapOnError() const { return trapOnError_; } |
| 5400 |
const wasm::TrapSiteDesc& trapSiteDesc() const { |
| 5401 |
MOZ_ASSERT(trapSiteDesc_.isValid()); |
| 5402 |
return trapSiteDesc_; |
| 5403 |
} |
| 5404 |
|
| 5405 |
[[nodiscard]] bool writeRecoverData( |
| 5406 |
CompactBufferWriter& writer) const override; |
| 5407 |
bool canRecoverOnBailout() const override { return type() != MIRType::Int64; } |
| 5408 |
|
| 5409 |
bool fallible() const; |
| 5410 |
|
| 5411 |
void computeRange(TempAllocator& alloc) override; |
| 5412 |
bool canTruncate() const override; |
| 5413 |
void truncate(TruncateKind kind) override; |
| 5414 |
void collectRangeInfoPreTrunc() override; |
| 5415 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 5416 |
|
| 5417 |
bool congruentTo(const MDefinition* ins) const override { |
| 5418 |
return MBinaryArithInstruction::congruentTo(ins) && |
| 5419 |
unsigned_ == ins->toMod()->isUnsigned(); |
| 5420 |
} |
| 5421 |
|
| 5422 |
bool possiblyCalls() const override { return type() == MIRType::Double; } |
| 5423 |
|
| 5424 |
ALLOW_CLONE(MMod) |
| 5425 |
}; |
| 5426 |
|
| 5427 |
class MBigIntBinaryArithInstruction : public MBinaryInstruction, |
| 5428 |
public BigIntArithPolicy::Data { |
| 5429 |
protected: |
| 5430 |
MBigIntBinaryArithInstruction(Opcode op, MDefinition* left, |
| 5431 |
MDefinition* right) |
| 5432 |
: MBinaryInstruction(op, left, right) { |
| 5433 |
setResultType(MIRType::BigInt); |
| 5434 |
setMovable(); |
| 5435 |
} |
| 5436 |
|
| 5437 |
public: |
| 5438 |
bool congruentTo(const MDefinition* ins) const override { |
| 5439 |
return binaryCongruentTo(ins); |
| 5440 |
} |
| 5441 |
|
| 5442 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 5443 |
}; |
| 5444 |
|
| 5445 |
class MBigIntAdd : public MBigIntBinaryArithInstruction { |
| 5446 |
MBigIntAdd(MDefinition* left, MDefinition* right) |
| 5447 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5448 |
setCommutative(); |
| 5449 |
|
| 5450 |
// Don't guard this instruction even though adding two BigInts can throw |
| 5451 |
// JSMSG_BIGINT_TOO_LARGE. This matches the behavior when adding too large |
| 5452 |
// strings in MConcat. |
| 5453 |
} |
| 5454 |
|
| 5455 |
public: |
| 5456 |
INSTRUCTION_HEADER(BigIntAdd) |
| 5457 |
TRIVIAL_NEW_WRAPPERS |
| 5458 |
|
| 5459 |
[[nodiscard]] bool writeRecoverData( |
| 5460 |
CompactBufferWriter& writer) const override; |
| 5461 |
bool canRecoverOnBailout() const override { return true; } |
| 5462 |
|
| 5463 |
ALLOW_CLONE(MBigIntAdd) |
| 5464 |
}; |
| 5465 |
|
| 5466 |
class MBigIntSub : public MBigIntBinaryArithInstruction { |
| 5467 |
MBigIntSub(MDefinition* left, MDefinition* right) |
| 5468 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5469 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5470 |
} |
| 5471 |
|
| 5472 |
public: |
| 5473 |
INSTRUCTION_HEADER(BigIntSub) |
| 5474 |
TRIVIAL_NEW_WRAPPERS |
| 5475 |
|
| 5476 |
[[nodiscard]] bool writeRecoverData( |
| 5477 |
CompactBufferWriter& writer) const override; |
| 5478 |
bool canRecoverOnBailout() const override { return true; } |
| 5479 |
|
| 5480 |
ALLOW_CLONE(MBigIntSub) |
| 5481 |
}; |
| 5482 |
|
| 5483 |
class MBigIntMul : public MBigIntBinaryArithInstruction { |
| 5484 |
MBigIntMul(MDefinition* left, MDefinition* right) |
| 5485 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5486 |
setCommutative(); |
| 5487 |
|
| 5488 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5489 |
} |
| 5490 |
|
| 5491 |
public: |
| 5492 |
INSTRUCTION_HEADER(BigIntMul) |
| 5493 |
TRIVIAL_NEW_WRAPPERS |
| 5494 |
|
| 5495 |
[[nodiscard]] bool writeRecoverData( |
| 5496 |
CompactBufferWriter& writer) const override; |
| 5497 |
bool canRecoverOnBailout() const override { return true; } |
| 5498 |
|
| 5499 |
ALLOW_CLONE(MBigIntMul) |
| 5500 |
}; |
| 5501 |
|
| 5502 |
class MBigIntDiv : public MBigIntBinaryArithInstruction { |
| 5503 |
bool canBeDivideByZero_; |
| 5504 |
|
| 5505 |
MBigIntDiv(MDefinition* left, MDefinition* right) |
| 5506 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5507 |
MOZ_ASSERT(right->type() == MIRType::BigInt); |
| 5508 |
canBeDivideByZero_ = |
| 5509 |
!right->isConstant() || right->toConstant()->toBigInt()->isZero(); |
| 5510 |
|
| 5511 |
// Throws when the divisor is zero. |
| 5512 |
if (canBeDivideByZero_) { |
| 5513 |
setGuard(); |
| 5514 |
setNotMovable(); |
| 5515 |
} |
| 5516 |
} |
| 5517 |
|
| 5518 |
public: |
| 5519 |
INSTRUCTION_HEADER(BigIntDiv) |
| 5520 |
TRIVIAL_NEW_WRAPPERS |
| 5521 |
|
| 5522 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 5523 |
|
| 5524 |
AliasSet getAliasSet() const override { |
| 5525 |
if (canBeDivideByZero()) { |
| 5526 |
return AliasSet::Store(AliasSet::ExceptionState); |
| 5527 |
} |
| 5528 |
return AliasSet::None(); |
| 5529 |
} |
| 5530 |
|
| 5531 |
[[nodiscard]] bool writeRecoverData( |
| 5532 |
CompactBufferWriter& writer) const override; |
| 5533 |
bool canRecoverOnBailout() const override { return !canBeDivideByZero(); } |
| 5534 |
|
| 5535 |
ALLOW_CLONE(MBigIntDiv) |
| 5536 |
}; |
| 5537 |
|
| 5538 |
class MBigIntMod : public MBigIntBinaryArithInstruction { |
| 5539 |
bool canBeDivideByZero_; |
| 5540 |
|
| 5541 |
MBigIntMod(MDefinition* left, MDefinition* right) |
| 5542 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5543 |
MOZ_ASSERT(right->type() == MIRType::BigInt); |
| 5544 |
canBeDivideByZero_ = |
| 5545 |
!right->isConstant() || right->toConstant()->toBigInt()->isZero(); |
| 5546 |
|
| 5547 |
// Throws when the divisor is zero. |
| 5548 |
if (canBeDivideByZero_) { |
| 5549 |
setGuard(); |
| 5550 |
setNotMovable(); |
| 5551 |
} |
| 5552 |
} |
| 5553 |
|
| 5554 |
public: |
| 5555 |
INSTRUCTION_HEADER(BigIntMod) |
| 5556 |
TRIVIAL_NEW_WRAPPERS |
| 5557 |
|
| 5558 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 5559 |
|
| 5560 |
AliasSet getAliasSet() const override { |
| 5561 |
if (canBeDivideByZero()) { |
| 5562 |
return AliasSet::Store(AliasSet::ExceptionState); |
| 5563 |
} |
| 5564 |
return AliasSet::None(); |
| 5565 |
} |
| 5566 |
|
| 5567 |
[[nodiscard]] bool writeRecoverData( |
| 5568 |
CompactBufferWriter& writer) const override; |
| 5569 |
bool canRecoverOnBailout() const override { return !canBeDivideByZero(); } |
| 5570 |
|
| 5571 |
ALLOW_CLONE(MBigIntMod) |
| 5572 |
}; |
| 5573 |
|
| 5574 |
class MBigIntPow : public MBigIntBinaryArithInstruction { |
| 5575 |
bool canBeNegativeExponent_; |
| 5576 |
|
| 5577 |
MBigIntPow(MDefinition* left, MDefinition* right) |
| 5578 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5579 |
MOZ_ASSERT(right->type() == MIRType::BigInt); |
| 5580 |
canBeNegativeExponent_ = |
| 5581 |
!right->isConstant() || right->toConstant()->toBigInt()->isNegative(); |
| 5582 |
|
| 5583 |
// Throws when the exponent is negative. |
| 5584 |
if (canBeNegativeExponent_) { |
| 5585 |
setGuard(); |
| 5586 |
setNotMovable(); |
| 5587 |
} |
| 5588 |
} |
| 5589 |
|
| 5590 |
public: |
| 5591 |
INSTRUCTION_HEADER(BigIntPow) |
| 5592 |
TRIVIAL_NEW_WRAPPERS |
| 5593 |
|
| 5594 |
bool canBeNegativeExponent() const { return canBeNegativeExponent_; } |
| 5595 |
|
| 5596 |
AliasSet getAliasSet() const override { |
| 5597 |
if (canBeNegativeExponent()) { |
| 5598 |
return AliasSet::Store(AliasSet::ExceptionState); |
| 5599 |
} |
| 5600 |
return AliasSet::None(); |
| 5601 |
} |
| 5602 |
|
| 5603 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 5604 |
|
| 5605 |
[[nodiscard]] bool writeRecoverData( |
| 5606 |
CompactBufferWriter& writer) const override; |
| 5607 |
bool canRecoverOnBailout() const override { return !canBeNegativeExponent(); } |
| 5608 |
|
| 5609 |
ALLOW_CLONE(MBigIntPow) |
| 5610 |
}; |
| 5611 |
|
| 5612 |
class MBigIntBitAnd : public MBigIntBinaryArithInstruction { |
| 5613 |
MBigIntBitAnd(MDefinition* left, MDefinition* right) |
| 5614 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5615 |
setCommutative(); |
| 5616 |
|
| 5617 |
// We don't need to guard this instruction because it can only fail on OOM. |
| 5618 |
} |
| 5619 |
|
| 5620 |
public: |
| 5621 |
INSTRUCTION_HEADER(BigIntBitAnd) |
| 5622 |
TRIVIAL_NEW_WRAPPERS |
| 5623 |
|
| 5624 |
[[nodiscard]] bool writeRecoverData( |
| 5625 |
CompactBufferWriter& writer) const override; |
| 5626 |
bool canRecoverOnBailout() const override { return true; } |
| 5627 |
|
| 5628 |
ALLOW_CLONE(MBigIntBitAnd) |
| 5629 |
}; |
| 5630 |
|
| 5631 |
class MBigIntBitOr : public MBigIntBinaryArithInstruction { |
| 5632 |
MBigIntBitOr(MDefinition* left, MDefinition* right) |
| 5633 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5634 |
setCommutative(); |
| 5635 |
|
| 5636 |
// We don't need to guard this instruction because it can only fail on OOM. |
| 5637 |
} |
| 5638 |
|
| 5639 |
public: |
| 5640 |
INSTRUCTION_HEADER(BigIntBitOr) |
| 5641 |
TRIVIAL_NEW_WRAPPERS |
| 5642 |
|
| 5643 |
[[nodiscard]] bool writeRecoverData( |
| 5644 |
CompactBufferWriter& writer) const override; |
| 5645 |
bool canRecoverOnBailout() const override { return true; } |
| 5646 |
|
| 5647 |
ALLOW_CLONE(MBigIntBitOr) |
| 5648 |
}; |
| 5649 |
|
| 5650 |
class MBigIntBitXor : public MBigIntBinaryArithInstruction { |
| 5651 |
MBigIntBitXor(MDefinition* left, MDefinition* right) |
| 5652 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5653 |
setCommutative(); |
| 5654 |
|
| 5655 |
// We don't need to guard this instruction because it can only fail on OOM. |
| 5656 |
} |
| 5657 |
|
| 5658 |
public: |
| 5659 |
INSTRUCTION_HEADER(BigIntBitXor) |
| 5660 |
TRIVIAL_NEW_WRAPPERS |
| 5661 |
|
| 5662 |
[[nodiscard]] bool writeRecoverData( |
| 5663 |
CompactBufferWriter& writer) const override; |
| 5664 |
bool canRecoverOnBailout() const override { return true; } |
| 5665 |
|
| 5666 |
ALLOW_CLONE(MBigIntBitXor) |
| 5667 |
}; |
| 5668 |
|
| 5669 |
class MBigIntLsh : public MBigIntBinaryArithInstruction { |
| 5670 |
MBigIntLsh(MDefinition* left, MDefinition* right) |
| 5671 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5672 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5673 |
} |
| 5674 |
|
| 5675 |
public: |
| 5676 |
INSTRUCTION_HEADER(BigIntLsh) |
| 5677 |
TRIVIAL_NEW_WRAPPERS |
| 5678 |
|
| 5679 |
[[nodiscard]] bool writeRecoverData( |
| 5680 |
CompactBufferWriter& writer) const override; |
| 5681 |
bool canRecoverOnBailout() const override { return true; } |
| 5682 |
|
| 5683 |
ALLOW_CLONE(MBigIntLsh) |
| 5684 |
}; |
| 5685 |
|
| 5686 |
class MBigIntRsh : public MBigIntBinaryArithInstruction { |
| 5687 |
MBigIntRsh(MDefinition* left, MDefinition* right) |
| 5688 |
: MBigIntBinaryArithInstruction(classOpcode, left, right) { |
| 5689 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5690 |
} |
| 5691 |
|
| 5692 |
public: |
| 5693 |
INSTRUCTION_HEADER(BigIntRsh) |
| 5694 |
TRIVIAL_NEW_WRAPPERS |
| 5695 |
|
| 5696 |
[[nodiscard]] bool writeRecoverData( |
| 5697 |
CompactBufferWriter& writer) const override; |
| 5698 |
bool canRecoverOnBailout() const override { return true; } |
| 5699 |
|
| 5700 |
ALLOW_CLONE(MBigIntRsh) |
| 5701 |
}; |
| 5702 |
|
| 5703 |
class MBigIntUnaryArithInstruction : public MUnaryInstruction, |
| 5704 |
public BigIntArithPolicy::Data { |
| 5705 |
protected: |
| 5706 |
MBigIntUnaryArithInstruction(Opcode op, MDefinition* input) |
| 5707 |
: MUnaryInstruction(op, input) { |
| 5708 |
setResultType(MIRType::BigInt); |
| 5709 |
setMovable(); |
| 5710 |
} |
| 5711 |
|
| 5712 |
public: |
| 5713 |
bool congruentTo(const MDefinition* ins) const override { |
| 5714 |
return congruentIfOperandsEqual(ins); |
| 5715 |
} |
| 5716 |
|
| 5717 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 5718 |
}; |
| 5719 |
|
| 5720 |
class MBigIntIncrement : public MBigIntUnaryArithInstruction { |
| 5721 |
explicit MBigIntIncrement(MDefinition* input) |
| 5722 |
: MBigIntUnaryArithInstruction(classOpcode, input) { |
| 5723 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5724 |
} |
| 5725 |
|
| 5726 |
public: |
| 5727 |
INSTRUCTION_HEADER(BigIntIncrement) |
| 5728 |
TRIVIAL_NEW_WRAPPERS |
| 5729 |
|
| 5730 |
[[nodiscard]] bool writeRecoverData( |
| 5731 |
CompactBufferWriter& writer) const override; |
| 5732 |
bool canRecoverOnBailout() const override { return true; } |
| 5733 |
|
| 5734 |
ALLOW_CLONE(MBigIntIncrement) |
| 5735 |
}; |
| 5736 |
|
| 5737 |
class MBigIntDecrement : public MBigIntUnaryArithInstruction { |
| 5738 |
explicit MBigIntDecrement(MDefinition* input) |
| 5739 |
: MBigIntUnaryArithInstruction(classOpcode, input) { |
| 5740 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5741 |
} |
| 5742 |
|
| 5743 |
public: |
| 5744 |
INSTRUCTION_HEADER(BigIntDecrement) |
| 5745 |
TRIVIAL_NEW_WRAPPERS |
| 5746 |
|
| 5747 |
[[nodiscard]] bool writeRecoverData( |
| 5748 |
CompactBufferWriter& writer) const override; |
| 5749 |
bool canRecoverOnBailout() const override { return true; } |
| 5750 |
|
| 5751 |
ALLOW_CLONE(MBigIntDecrement) |
| 5752 |
}; |
| 5753 |
|
| 5754 |
class MBigIntNegate : public MBigIntUnaryArithInstruction { |
| 5755 |
explicit MBigIntNegate(MDefinition* input) |
| 5756 |
: MBigIntUnaryArithInstruction(classOpcode, input) { |
| 5757 |
// We don't need to guard this instruction because it can only fail on OOM. |
| 5758 |
} |
| 5759 |
|
| 5760 |
public: |
| 5761 |
INSTRUCTION_HEADER(BigIntNegate) |
| 5762 |
TRIVIAL_NEW_WRAPPERS |
| 5763 |
|
| 5764 |
[[nodiscard]] bool writeRecoverData( |
| 5765 |
CompactBufferWriter& writer) const override; |
| 5766 |
bool canRecoverOnBailout() const override { return true; } |
| 5767 |
|
| 5768 |
ALLOW_CLONE(MBigIntNegate) |
| 5769 |
}; |
| 5770 |
|
| 5771 |
class MBigIntBitNot : public MBigIntUnaryArithInstruction { |
| 5772 |
explicit MBigIntBitNot(MDefinition* input) |
| 5773 |
: MBigIntUnaryArithInstruction(classOpcode, input) { |
| 5774 |
// See MBigIntAdd for why we don't guard this instruction. |
| 5775 |
} |
| 5776 |
|
| 5777 |
public: |
| 5778 |
INSTRUCTION_HEADER(BigIntBitNot) |
| 5779 |
TRIVIAL_NEW_WRAPPERS |
| 5780 |
|
| 5781 |
[[nodiscard]] bool writeRecoverData( |
| 5782 |
CompactBufferWriter& writer) const override; |
| 5783 |
bool canRecoverOnBailout() const override { return true; } |
| 5784 |
|
| 5785 |
ALLOW_CLONE(MBigIntBitNot) |
| 5786 |
}; |
| 5787 |
|
| 5788 |
class MBigIntPtrBinaryArithInstruction : public MBinaryInstruction, |
| 5789 |
public NoTypePolicy::Data { |
| 5790 |
protected: |
| 5791 |
MBigIntPtrBinaryArithInstruction(Opcode op, MDefinition* left, |
| 5792 |
MDefinition* right) |
| 5793 |
: MBinaryInstruction(op, left, right) { |
| 5794 |
MOZ_ASSERT(left->type() == MIRType::IntPtr); |
| 5795 |
MOZ_ASSERT(right->type() == MIRType::IntPtr); |
| 5796 |
setResultType(MIRType::IntPtr); |
| 5797 |
setMovable(); |
| 5798 |
} |
| 5799 |
|
| 5800 |
static bool isMaybeZero(MDefinition* ins); |
| 5801 |
static bool isMaybeNegative(MDefinition* ins); |
| 5802 |
|
| 5803 |
public: |
| 5804 |
bool congruentTo(const MDefinition* ins) const override { |
| 5805 |
return binaryCongruentTo(ins); |
| 5806 |
} |
| 5807 |
|
| 5808 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 5809 |
}; |
| 5810 |
|
| 5811 |
class MBigIntPtrAdd : public MBigIntPtrBinaryArithInstruction { |
| 5812 |
MBigIntPtrAdd(MDefinition* left, MDefinition* right) |
| 5813 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) { |
| 5814 |
setCommutative(); |
| 5815 |
} |
| 5816 |
|
| 5817 |
public: |
| 5818 |
INSTRUCTION_HEADER(BigIntPtrAdd) |
| 5819 |
TRIVIAL_NEW_WRAPPERS |
| 5820 |
|
| 5821 |
[[nodiscard]] bool writeRecoverData( |
| 5822 |
CompactBufferWriter& writer) const override; |
| 5823 |
bool canRecoverOnBailout() const override { return true; } |
| 5824 |
|
| 5825 |
ALLOW_CLONE(MBigIntPtrAdd) |
| 5826 |
}; |
| 5827 |
|
| 5828 |
class MBigIntPtrSub : public MBigIntPtrBinaryArithInstruction { |
| 5829 |
MBigIntPtrSub(MDefinition* left, MDefinition* right) |
| 5830 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) {} |
| 5831 |
|
| 5832 |
public: |
| 5833 |
INSTRUCTION_HEADER(BigIntPtrSub) |
| 5834 |
TRIVIAL_NEW_WRAPPERS |
| 5835 |
|
| 5836 |
[[nodiscard]] bool writeRecoverData( |
| 5837 |
CompactBufferWriter& writer) const override; |
| 5838 |
bool canRecoverOnBailout() const override { return true; } |
| 5839 |
|
| 5840 |
ALLOW_CLONE(MBigIntPtrSub) |
| 5841 |
}; |
| 5842 |
|
| 5843 |
class MBigIntPtrMul : public MBigIntPtrBinaryArithInstruction { |
| 5844 |
MBigIntPtrMul(MDefinition* left, MDefinition* right) |
| 5845 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) { |
| 5846 |
setCommutative(); |
| 5847 |
} |
| 5848 |
|
| 5849 |
public: |
| 5850 |
INSTRUCTION_HEADER(BigIntPtrMul) |
| 5851 |
TRIVIAL_NEW_WRAPPERS |
| 5852 |
|
| 5853 |
[[nodiscard]] bool writeRecoverData( |
| 5854 |
CompactBufferWriter& writer) const override; |
| 5855 |
bool canRecoverOnBailout() const override { return true; } |
| 5856 |
|
| 5857 |
ALLOW_CLONE(MBigIntPtrMul) |
| 5858 |
}; |
| 5859 |
|
| 5860 |
class MBigIntPtrDiv : public MBigIntPtrBinaryArithInstruction { |
| 5861 |
bool canBeDivideByZero_; |
| 5862 |
|
| 5863 |
MBigIntPtrDiv(MDefinition* left, MDefinition* right) |
| 5864 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) { |
| 5865 |
canBeDivideByZero_ = isMaybeZero(right); |
| 5866 |
|
| 5867 |
// Bails when the divisor is zero. |
| 5868 |
if (canBeDivideByZero_) { |
| 5869 |
setGuard(); |
| 5870 |
} |
| 5871 |
} |
| 5872 |
|
| 5873 |
public: |
| 5874 |
INSTRUCTION_HEADER(BigIntPtrDiv) |
| 5875 |
TRIVIAL_NEW_WRAPPERS |
| 5876 |
|
| 5877 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 5878 |
|
| 5879 |
[[nodiscard]] bool writeRecoverData( |
| 5880 |
CompactBufferWriter& writer) const override; |
| 5881 |
bool canRecoverOnBailout() const override { return true; } |
| 5882 |
|
| 5883 |
ALLOW_CLONE(MBigIntPtrDiv) |
| 5884 |
}; |
| 5885 |
|
| 5886 |
class MBigIntPtrMod : public MBigIntPtrBinaryArithInstruction { |
| 5887 |
bool canBeDivideByZero_; |
| 5888 |
|
| 5889 |
MBigIntPtrMod(MDefinition* left, MDefinition* right) |
| 5890 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) { |
| 5891 |
canBeDivideByZero_ = isMaybeZero(right); |
| 5892 |
|
| 5893 |
// Bails when the divisor is zero. |
| 5894 |
if (canBeDivideByZero_) { |
| 5895 |
setGuard(); |
| 5896 |
} |
| 5897 |
} |
| 5898 |
|
| 5899 |
public: |
| 5900 |
INSTRUCTION_HEADER(BigIntPtrMod) |
| 5901 |
TRIVIAL_NEW_WRAPPERS |
| 5902 |
|
| 5903 |
bool canBeDivideByZero() const { return canBeDivideByZero_; } |
| 5904 |
|
| 5905 |
[[nodiscard]] bool writeRecoverData( |
| 5906 |
CompactBufferWriter& writer) const override; |
| 5907 |
bool canRecoverOnBailout() const override { return true; } |
| 5908 |
|
| 5909 |
ALLOW_CLONE(MBigIntPtrMod) |
| 5910 |
}; |
| 5911 |
|
| 5912 |
class MBigIntPtrPow : public MBigIntPtrBinaryArithInstruction { |
| 5913 |
bool canBeNegativeExponent_; |
| 5914 |
|
| 5915 |
MBigIntPtrPow(MDefinition* left, MDefinition* right) |
| 5916 |
: MBigIntPtrBinaryArithInstruction(classOpcode, left, right) { |
| 5917 |
canBeNegativeExponent_ = isMaybeNegative(right); |
| 5918 |
|
| 5919 |
// Bails when the exponent is negative. |
| 5920 |
if (canBeNegativeExponent_) { |
| 5921 |
setGuard(); |
| 5922 |
} |
| 5923 |
} |
| 5924 |
|
| 5925 |
public: |
| 5926 |
INSTRUCTION_HEADER(BigIntPtrPow) |
| 5927 |
TRIVIAL_NEW_WRAPPERS |
| 5928 |
|
| 5929 |
bool canBeNegativeExponent() const { return canBeNegativeExponent_; } |
| 5930 |
|
| 5931 |
[[nodiscard]] bool writeRecoverData( |
| 5932 |
CompactBufferWriter& writer) const override; |
| 5933 |
bool canRecoverOnBailout() const override { return true; } |
| 5934 |
|
| 5935 |
ALLOW_CLONE(MBigIntPtrPow) |
| 5936 |
}; |
| 5937 |
|
| 5938 |
class MBigIntPtrBinaryBitwiseInstruction : public MBinaryInstruction, |
| 5939 |
public NoTypePolicy::Data { |
| 5940 |
protected: |
| 5941 |
MBigIntPtrBinaryBitwiseInstruction(Opcode op, MDefinition* left, |
| 5942 |
MDefinition* right) |
| 5943 |
: MBinaryInstruction(op, left, right) { |
| 5944 |
MOZ_ASSERT(left->type() == MIRType::IntPtr); |
| 5945 |
MOZ_ASSERT(right->type() == MIRType::IntPtr); |
| 5946 |
setResultType(MIRType::IntPtr); |
| 5947 |
setMovable(); |
| 5948 |
} |
| 5949 |
|
| 5950 |
public: |
| 5951 |
bool congruentTo(const MDefinition* ins) const override { |
| 5952 |
return binaryCongruentTo(ins); |
| 5953 |
} |
| 5954 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 5955 |
}; |
| 5956 |
|
| 5957 |
class MBigIntPtrBitAnd : public MBigIntPtrBinaryBitwiseInstruction { |
| 5958 |
MBigIntPtrBitAnd(MDefinition* left, MDefinition* right) |
| 5959 |
: MBigIntPtrBinaryBitwiseInstruction(classOpcode, left, right) { |
| 5960 |
setCommutative(); |
| 5961 |
} |
| 5962 |
|
| 5963 |
public: |
| 5964 |
INSTRUCTION_HEADER(BigIntPtrBitAnd) |
| 5965 |
TRIVIAL_NEW_WRAPPERS |
| 5966 |
|
| 5967 |
[[nodiscard]] bool writeRecoverData( |
| 5968 |
CompactBufferWriter& writer) const override; |
| 5969 |
bool canRecoverOnBailout() const override { return true; } |
| 5970 |
|
| 5971 |
ALLOW_CLONE(MBigIntPtrBitAnd) |
| 5972 |
}; |
| 5973 |
|
| 5974 |
class MBigIntPtrBitOr : public MBigIntPtrBinaryBitwiseInstruction { |
| 5975 |
MBigIntPtrBitOr(MDefinition* left, MDefinition* right) |
| 5976 |
: MBigIntPtrBinaryBitwiseInstruction(classOpcode, left, right) { |
| 5977 |
setCommutative(); |
| 5978 |
} |
| 5979 |
|
| 5980 |
public: |
| 5981 |
INSTRUCTION_HEADER(BigIntPtrBitOr) |
| 5982 |
TRIVIAL_NEW_WRAPPERS |
| 5983 |
|
| 5984 |
[[nodiscard]] bool writeRecoverData( |
| 5985 |
CompactBufferWriter& writer) const override; |
| 5986 |
bool canRecoverOnBailout() const override { return true; } |
| 5987 |
|
| 5988 |
ALLOW_CLONE(MBigIntPtrBitOr) |
| 5989 |
}; |
| 5990 |
|
| 5991 |
class MBigIntPtrBitXor : public MBigIntPtrBinaryBitwiseInstruction { |
| 5992 |
MBigIntPtrBitXor(MDefinition* left, MDefinition* right) |
| 5993 |
: MBigIntPtrBinaryBitwiseInstruction(classOpcode, left, right) { |
| 5994 |
setCommutative(); |
| 5995 |
} |
| 5996 |
|
| 5997 |
public: |
| 5998 |
INSTRUCTION_HEADER(BigIntPtrBitXor) |
| 5999 |
TRIVIAL_NEW_WRAPPERS |
| 6000 |
|
| 6001 |
[[nodiscard]] bool writeRecoverData( |
| 6002 |
CompactBufferWriter& writer) const override; |
| 6003 |
bool canRecoverOnBailout() const override { return true; } |
| 6004 |
|
| 6005 |
ALLOW_CLONE(MBigIntPtrBitXor) |
| 6006 |
}; |
| 6007 |
|
| 6008 |
class MBigIntPtrLsh : public MBigIntPtrBinaryBitwiseInstruction { |
| 6009 |
MBigIntPtrLsh(MDefinition* left, MDefinition* right) |
| 6010 |
: MBigIntPtrBinaryBitwiseInstruction(classOpcode, left, right) {} |
| 6011 |
|
| 6012 |
public: |
| 6013 |
INSTRUCTION_HEADER(BigIntPtrLsh) |
| 6014 |
TRIVIAL_NEW_WRAPPERS |
| 6015 |
|
| 6016 |
bool fallible() const { |
| 6017 |
return !rhs()->isConstant() || rhs()->toConstant()->toIntPtr() > 0; |
| 6018 |
} |
| 6019 |
|
| 6020 |
[[nodiscard]] bool writeRecoverData( |
| 6021 |
CompactBufferWriter& writer) const override; |
| 6022 |
bool canRecoverOnBailout() const override { return true; } |
| 6023 |
|
| 6024 |
ALLOW_CLONE(MBigIntPtrLsh) |
| 6025 |
}; |
| 6026 |
|
| 6027 |
class MBigIntPtrRsh : public MBigIntPtrBinaryBitwiseInstruction { |
| 6028 |
MBigIntPtrRsh(MDefinition* left, MDefinition* right) |
| 6029 |
: MBigIntPtrBinaryBitwiseInstruction(classOpcode, left, right) {} |
| 6030 |
|
| 6031 |
public: |
| 6032 |
INSTRUCTION_HEADER(BigIntPtrRsh) |
| 6033 |
TRIVIAL_NEW_WRAPPERS |
| 6034 |
|
| 6035 |
bool fallible() const { |
| 6036 |
return !rhs()->isConstant() || rhs()->toConstant()->toIntPtr() < 0; |
| 6037 |
} |
| 6038 |
|
| 6039 |
[[nodiscard]] bool writeRecoverData( |
| 6040 |
CompactBufferWriter& writer) const override; |
| 6041 |
bool canRecoverOnBailout() const override { return true; } |
| 6042 |
|
| 6043 |
ALLOW_CLONE(MBigIntPtrRsh) |
| 6044 |
}; |
| 6045 |
|
| 6046 |
class MBigIntPtrBitNot : public MUnaryInstruction, public NoTypePolicy::Data { |
| 6047 |
explicit MBigIntPtrBitNot(MDefinition* input) |
| 6048 |
: MUnaryInstruction(classOpcode, input) { |
| 6049 |
MOZ_ASSERT(input->type() == MIRType::IntPtr); |
| 6050 |
setResultType(MIRType::IntPtr); |
| 6051 |
setMovable(); |
| 6052 |
} |
| 6053 |
|
| 6054 |
public: |
| 6055 |
INSTRUCTION_HEADER(BigIntPtrBitNot) |
| 6056 |
TRIVIAL_NEW_WRAPPERS |
| 6057 |
|
| 6058 |
bool congruentTo(const MDefinition* ins) const override { |
| 6059 |
return congruentIfOperandsEqual(ins); |
| 6060 |
} |
| 6061 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6062 |
|
| 6063 |
[[nodiscard]] bool writeRecoverData( |
| 6064 |
CompactBufferWriter& writer) const override; |
| 6065 |
bool canRecoverOnBailout() const override { return true; } |
| 6066 |
|
| 6067 |
ALLOW_CLONE(MBigIntPtrBitNot) |
| 6068 |
}; |
| 6069 |
|
| 6070 |
class MConcat : public MBinaryInstruction, |
| 6071 |
public MixPolicy<ConvertToStringPolicy<0>, |
| 6072 |
ConvertToStringPolicy<1>>::Data { |
| 6073 |
MConcat(MDefinition* left, MDefinition* right) |
| 6074 |
: MBinaryInstruction(classOpcode, left, right) { |
| 6075 |
// At least one input should be definitely string |
| 6076 |
MOZ_ASSERT(left->type() == MIRType::String || |
| 6077 |
right->type() == MIRType::String); |
| 6078 |
|
| 6079 |
setMovable(); |
| 6080 |
setResultType(MIRType::String); |
| 6081 |
} |
| 6082 |
|
| 6083 |
public: |
| 6084 |
INSTRUCTION_HEADER(Concat) |
| 6085 |
TRIVIAL_NEW_WRAPPERS |
| 6086 |
|
| 6087 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6088 |
bool congruentTo(const MDefinition* ins) const override { |
| 6089 |
return congruentIfOperandsEqual(ins); |
| 6090 |
} |
| 6091 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6092 |
|
| 6093 |
[[nodiscard]] bool writeRecoverData( |
| 6094 |
CompactBufferWriter& writer) const override; |
| 6095 |
bool canRecoverOnBailout() const override { return true; } |
| 6096 |
|
| 6097 |
ALLOW_CLONE(MConcat) |
| 6098 |
}; |
| 6099 |
|
| 6100 |
class MStringConvertCase : public MUnaryInstruction, |
| 6101 |
public StringPolicy<0>::Data { |
| 6102 |
public: |
| 6103 |
enum Mode { LowerCase, UpperCase }; |
| 6104 |
|
| 6105 |
private: |
| 6106 |
Mode mode_; |
| 6107 |
|
| 6108 |
MStringConvertCase(MDefinition* string, Mode mode) |
| 6109 |
: MUnaryInstruction(classOpcode, string), mode_(mode) { |
| 6110 |
setResultType(MIRType::String); |
| 6111 |
setMovable(); |
| 6112 |
} |
| 6113 |
|
| 6114 |
public: |
| 6115 |
INSTRUCTION_HEADER(StringConvertCase) |
| 6116 |
TRIVIAL_NEW_WRAPPERS |
| 6117 |
NAMED_OPERANDS((0, string)) |
| 6118 |
|
| 6119 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6120 |
bool congruentTo(const MDefinition* ins) const override { |
| 6121 |
return congruentIfOperandsEqual(ins) && |
| 6122 |
ins->toStringConvertCase()->mode() == mode(); |
| 6123 |
} |
| 6124 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6125 |
bool possiblyCalls() const override { return true; } |
| 6126 |
Mode mode() const { return mode_; } |
| 6127 |
}; |
| 6128 |
|
| 6129 |
class MCharCodeConvertCase : public MUnaryInstruction, |
| 6130 |
public UnboxedInt32Policy<0>::Data { |
| 6131 |
public: |
| 6132 |
enum Mode { LowerCase, UpperCase }; |
| 6133 |
|
| 6134 |
private: |
| 6135 |
Mode mode_; |
| 6136 |
|
| 6137 |
MCharCodeConvertCase(MDefinition* code, Mode mode) |
| 6138 |
: MUnaryInstruction(classOpcode, code), mode_(mode) { |
| 6139 |
setResultType(MIRType::String); |
| 6140 |
setMovable(); |
| 6141 |
} |
| 6142 |
|
| 6143 |
public: |
| 6144 |
INSTRUCTION_HEADER(CharCodeConvertCase) |
| 6145 |
TRIVIAL_NEW_WRAPPERS |
| 6146 |
NAMED_OPERANDS((0, code)) |
| 6147 |
|
| 6148 |
bool congruentTo(const MDefinition* ins) const override { |
| 6149 |
return congruentIfOperandsEqual(ins) && |
| 6150 |
ins->toCharCodeConvertCase()->mode() == mode(); |
| 6151 |
} |
| 6152 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6153 |
Mode mode() const { return mode_; } |
| 6154 |
}; |
| 6155 |
|
| 6156 |
// This is a 3 state flag used by FlagPhiInputsAsImplicitlyUsed to record and |
| 6157 |
// propagate the information about the consumers of a Phi instruction. This is |
| 6158 |
// then used to set ImplicitlyUsed flags on the inputs of such Phi instructions. |
| 6159 |
enum class PhiUsage : uint8_t { Unknown, Unused, Used }; |
| 6160 |
|
| 6161 |
using PhiVector = Vector<MPhi*, 4, JitAllocPolicy>; |
| 6162 |
|
| 6163 |
class MPhi final : public MDefinition, |
| 6164 |
public InlineListNode<MPhi>, |
| 6165 |
public NoTypePolicy::Data { |
| 6166 |
using InputVector = js::Vector<MUse, 2, JitAllocPolicy>; |
| 6167 |
InputVector inputs_; |
| 6168 |
|
| 6169 |
// Important: if you add fields to this class, be sure to update its ::clone |
| 6170 |
// method accordingly. |
| 6171 |
TruncateKind truncateKind_; |
| 6172 |
bool triedToSpecialize_; |
| 6173 |
bool isIterator_; |
| 6174 |
bool canProduceFloat32_; |
| 6175 |
bool canConsumeFloat32_; |
| 6176 |
// Record the state of the data flow before any mutation made to the control |
| 6177 |
// flow, such that removing branches is properly accounted for. |
| 6178 |
PhiUsage usageAnalysis_; |
| 6179 |
|
| 6180 |
protected: |
| 6181 |
MUse* getUseFor(size_t index) override { |
| 6182 |
MOZ_ASSERT(index < numOperands()); |
| 6183 |
return &inputs_[index]; |
| 6184 |
} |
| 6185 |
const MUse* getUseFor(size_t index) const override { return &inputs_[index]; } |
| 6186 |
|
| 6187 |
public: |
| 6188 |
INSTRUCTION_HEADER_WITHOUT_TYPEPOLICY(Phi) |
| 6189 |
virtual const TypePolicy* typePolicy(); |
| 6190 |
virtual MIRType typePolicySpecialization(); |
| 6191 |
|
| 6192 |
MPhi(TempAllocator& alloc, MIRType resultType) |
| 6193 |
: MDefinition(classOpcode), |
| 6194 |
inputs_(alloc), |
| 6195 |
truncateKind_(TruncateKind::NoTruncate), |
| 6196 |
triedToSpecialize_(false), |
| 6197 |
isIterator_(false), |
| 6198 |
canProduceFloat32_(false), |
| 6199 |
canConsumeFloat32_(false), |
| 6200 |
usageAnalysis_(PhiUsage::Unknown) { |
| 6201 |
setResultType(resultType); |
| 6202 |
} |
| 6203 |
|
| 6204 |
static MPhi* New(TempAllocator& alloc, MIRType resultType = MIRType::Value) { |
| 6205 |
return new (alloc) MPhi(alloc, resultType); |
| 6206 |
} |
| 6207 |
static MPhi* New(TempAllocator::Fallible alloc, |
| 6208 |
MIRType resultType = MIRType::Value) { |
| 6209 |
return new (alloc) MPhi(alloc.alloc, resultType); |
| 6210 |
} |
| 6211 |
|
| 6212 |
MPhi* clone(TempAllocator& alloc, const MDefinitionVector& inputs) const { |
| 6213 |
MOZ_ASSERT(inputs.length() == inputs_.length()); |
| 6214 |
MPhi* phi = MPhi::New(alloc); |
| 6215 |
if (!phi || !phi->reserveLength(inputs.length())) { |
| 6216 |
return nullptr; |
| 6217 |
} |
| 6218 |
for (const auto& inp : inputs) { |
| 6219 |
phi->addInput(inp); |
| 6220 |
} |
| 6221 |
phi->truncateKind_ = truncateKind_; |
| 6222 |
phi->triedToSpecialize_ = triedToSpecialize_; |
| 6223 |
phi->isIterator_ = isIterator_; |
| 6224 |
phi->canProduceFloat32_ = canProduceFloat32_; |
| 6225 |
phi->canConsumeFloat32_ = canConsumeFloat32_; |
| 6226 |
phi->usageAnalysis_ = usageAnalysis_; |
| 6227 |
phi->setResultType(type()); |
| 6228 |
return phi; |
| 6229 |
} |
| 6230 |
|
| 6231 |
void removeOperand(size_t index); |
| 6232 |
void removeAllOperands(); |
| 6233 |
|
| 6234 |
MDefinition* getOperand(size_t index) const override { |
| 6235 |
return inputs_[index].producer(); |
| 6236 |
} |
| 6237 |
size_t numOperands() const override { return inputs_.length(); } |
| 6238 |
size_t indexOf(const MUse* u) const final { |
| 6239 |
MOZ_ASSERT(u >= &inputs_[0]); |
| 6240 |
MOZ_ASSERT(u <= &inputs_[numOperands() - 1]); |
| 6241 |
return u - &inputs_[0]; |
| 6242 |
} |
| 6243 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 6244 |
inputs_[index].replaceProducer(operand); |
| 6245 |
} |
| 6246 |
bool triedToSpecialize() const { return triedToSpecialize_; } |
| 6247 |
void specialize(MIRType type) { |
| 6248 |
triedToSpecialize_ = true; |
| 6249 |
setResultType(type); |
| 6250 |
} |
| 6251 |
|
| 6252 |
#ifdef DEBUG |
| 6253 |
// Assert that this is a phi in a loop header with a unique predecessor and |
| 6254 |
// a unique backedge. |
| 6255 |
void assertLoopPhi() const; |
| 6256 |
#else |
| 6257 |
void assertLoopPhi() const {} |
| 6258 |
#endif |
| 6259 |
|
| 6260 |
// Assuming this phi is in a loop header with a unique loop entry, return |
| 6261 |
// the phi operand along the loop entry. |
| 6262 |
MDefinition* getLoopPredecessorOperand() const; |
| 6263 |
|
| 6264 |
// Assuming this phi is in a loop header with a unique loop entry, return |
| 6265 |
// the phi operand along the loop backedge. |
| 6266 |
MDefinition* getLoopBackedgeOperand() const; |
| 6267 |
|
| 6268 |
// Whether this phi's type already includes information for def. |
| 6269 |
bool typeIncludes(MDefinition* def); |
| 6270 |
|
| 6271 |
// Mark all phis in |iterators|, and the phis they flow into, as having |
| 6272 |
// implicit uses. |
| 6273 |
[[nodiscard]] static bool markIteratorPhis(const PhiVector& iterators); |
| 6274 |
|
| 6275 |
// Initializes the operands vector to the given capacity, |
| 6276 |
// permitting use of addInput() instead of addInputSlow(). |
| 6277 |
[[nodiscard]] bool reserveLength(size_t length) { |
| 6278 |
return inputs_.reserve(length); |
| 6279 |
} |
| 6280 |
|
| 6281 |
// Use only if capacity has been reserved by reserveLength |
| 6282 |
void addInput(MDefinition* ins) { |
| 6283 |
MOZ_ASSERT_IF(type() != MIRType::Value, ins->type() == type()); |
| 6284 |
inputs_.infallibleEmplaceBack(ins, this); |
| 6285 |
} |
| 6286 |
|
| 6287 |
// Append a new input to the input vector. May fail. |
| 6288 |
[[nodiscard]] bool addInputFallible(MDefinition* ins) { |
| 6289 |
MOZ_ASSERT_IF(type() != MIRType::Value, ins->type() == type()); |
| 6290 |
return inputs_.emplaceBack(ins, this); |
| 6291 |
} |
| 6292 |
|
| 6293 |
// Appends a new input to the input vector. May perform reallocation. |
| 6294 |
// Prefer reserveLength() and addInput() instead, where possible. |
| 6295 |
[[nodiscard]] bool addInputSlow(MDefinition* ins) { |
| 6296 |
MOZ_ASSERT_IF(type() != MIRType::Value, ins->type() == type()); |
| 6297 |
return inputs_.emplaceBack(ins, this); |
| 6298 |
} |
| 6299 |
|
| 6300 |
// Appends a new input to the input vector. Infallible because |
| 6301 |
// we know the inputs fits in the vector's inline storage. |
| 6302 |
void addInlineInput(MDefinition* ins) { |
| 6303 |
MOZ_ASSERT(inputs_.length() < InputVector::InlineLength); |
| 6304 |
MOZ_ALWAYS_TRUE(addInputSlow(ins)); |
| 6305 |
} |
| 6306 |
|
| 6307 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6308 |
MDefinition* foldsTernary(TempAllocator& alloc); |
| 6309 |
|
| 6310 |
bool congruentTo(const MDefinition* ins) const override; |
| 6311 |
|
| 6312 |
// Mark this phi-node as having replaced all uses of |other|, as during GVN. |
| 6313 |
// For use when GVN eliminates phis which are not equivalent to one another. |
| 6314 |
void updateForReplacement(MPhi* other); |
| 6315 |
|
| 6316 |
bool isIterator() const { return isIterator_; } |
| 6317 |
void setIterator() { isIterator_ = true; } |
| 6318 |
|
| 6319 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6320 |
void computeRange(TempAllocator& alloc) override; |
| 6321 |
|
| 6322 |
MDefinition* operandIfRedundant(); |
| 6323 |
|
| 6324 |
bool canProduceFloat32() const override { return canProduceFloat32_; } |
| 6325 |
|
| 6326 |
void setCanProduceFloat32(bool can) { canProduceFloat32_ = can; } |
| 6327 |
|
| 6328 |
bool canConsumeFloat32(MUse* use) const override { |
| 6329 |
return canConsumeFloat32_; |
| 6330 |
} |
| 6331 |
|
| 6332 |
void setCanConsumeFloat32(bool can) { canConsumeFloat32_ = can; } |
| 6333 |
|
| 6334 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 6335 |
bool canTruncate() const override; |
| 6336 |
void truncate(TruncateKind kind) override; |
| 6337 |
|
| 6338 |
PhiUsage getUsageAnalysis() const { return usageAnalysis_; } |
| 6339 |
void setUsageAnalysis(PhiUsage pu) { |
| 6340 |
MOZ_ASSERT(usageAnalysis_ == PhiUsage::Unknown); |
| 6341 |
usageAnalysis_ = pu; |
| 6342 |
MOZ_ASSERT(usageAnalysis_ != PhiUsage::Unknown); |
| 6343 |
} |
| 6344 |
|
| 6345 |
wasm::MaybeRefType computeWasmRefType() const override { |
| 6346 |
if (numOperands() == 0) { |
| 6347 |
return wasm::MaybeRefType(); |
| 6348 |
} |
| 6349 |
wasm::MaybeRefType firstRefType = getOperand(0)->wasmRefType(); |
| 6350 |
if (firstRefType.isNothing()) { |
| 6351 |
return wasm::MaybeRefType(); |
| 6352 |
} |
| 6353 |
|
| 6354 |
wasm::RefType topTypeOfOperands = firstRefType.value(); |
| 6355 |
for (size_t i = 1; i < numOperands(); i++) { |
| 6356 |
MDefinition* op = getOperand(i); |
| 6357 |
wasm::MaybeRefType opType = op->wasmRefType(); |
| 6358 |
if (opType.isNothing()) { |
| 6359 |
return wasm::MaybeRefType(); |
| 6360 |
} |
| 6361 |
topTypeOfOperands = |
| 6362 |
wasm::RefType::leastUpperBound(topTypeOfOperands, opType.value()); |
| 6363 |
} |
| 6364 |
return wasm::MaybeRefType(topTypeOfOperands); |
| 6365 |
} |
| 6366 |
}; |
| 6367 |
|
| 6368 |
// The goal of a Beta node is to split a def at a conditionally taken |
| 6369 |
// branch, so that uses dominated by it have a different name. |
| 6370 |
class MBeta : public MUnaryInstruction, public NoTypePolicy::Data { |
| 6371 |
private: |
| 6372 |
// This is the range induced by a comparison and branch in a preceding |
| 6373 |
// block. Note that this does not reflect any range constraints from |
| 6374 |
// the input value itself, so this value may differ from the range() |
| 6375 |
// range after it is computed. |
| 6376 |
const Range* comparison_; |
| 6377 |
|
| 6378 |
MBeta(MDefinition* val, const Range* comp) |
| 6379 |
: MUnaryInstruction(classOpcode, val), comparison_(comp) { |
| 6380 |
setResultType(val->type()); |
| 6381 |
} |
| 6382 |
|
| 6383 |
public: |
| 6384 |
INSTRUCTION_HEADER(Beta) |
| 6385 |
TRIVIAL_NEW_WRAPPERS |
| 6386 |
|
| 6387 |
#ifdef JS_JITSPEW |
| 6388 |
void printOpcode(GenericPrinter& out) const override; |
| 6389 |
#endif |
| 6390 |
|
| 6391 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6392 |
|
| 6393 |
void computeRange(TempAllocator& alloc) override; |
| 6394 |
}; |
| 6395 |
|
| 6396 |
// If input evaluates to false (i.e. it's NaN, 0 or -0), 0 is returned, else the |
| 6397 |
// input is returned |
| 6398 |
class MNaNToZero : public MUnaryInstruction, public DoublePolicy<0>::Data { |
| 6399 |
bool operandIsNeverNaN_; |
| 6400 |
bool operandIsNeverNegativeZero_; |
| 6401 |
|
| 6402 |
explicit MNaNToZero(MDefinition* input) |
| 6403 |
: MUnaryInstruction(classOpcode, input), |
| 6404 |
operandIsNeverNaN_(false), |
| 6405 |
operandIsNeverNegativeZero_(false) { |
| 6406 |
setResultType(MIRType::Double); |
| 6407 |
setMovable(); |
| 6408 |
} |
| 6409 |
|
| 6410 |
public: |
| 6411 |
INSTRUCTION_HEADER(NaNToZero) |
| 6412 |
TRIVIAL_NEW_WRAPPERS |
| 6413 |
|
| 6414 |
bool operandIsNeverNaN() const { return operandIsNeverNaN_; } |
| 6415 |
|
| 6416 |
bool operandIsNeverNegativeZero() const { |
| 6417 |
return operandIsNeverNegativeZero_; |
| 6418 |
} |
| 6419 |
|
| 6420 |
void collectRangeInfoPreTrunc() override; |
| 6421 |
|
| 6422 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6423 |
|
| 6424 |
void computeRange(TempAllocator& alloc) override; |
| 6425 |
|
| 6426 |
bool writeRecoverData(CompactBufferWriter& writer) const override; |
| 6427 |
bool canRecoverOnBailout() const override { return true; } |
| 6428 |
|
| 6429 |
ALLOW_CLONE(MNaNToZero) |
| 6430 |
}; |
| 6431 |
|
| 6432 |
// MIR representation of a Value on the OSR BaselineFrame. |
| 6433 |
// The Value is indexed off of OsrFrameReg. |
| 6434 |
class MOsrValue : public MUnaryInstruction, public NoTypePolicy::Data { |
| 6435 |
private: |
| 6436 |
ptrdiff_t frameOffset_; |
| 6437 |
|
| 6438 |
MOsrValue(MOsrEntry* entry, ptrdiff_t frameOffset) |
| 6439 |
: MUnaryInstruction(classOpcode, entry), frameOffset_(frameOffset) { |
| 6440 |
setResultType(MIRType::Value); |
| 6441 |
} |
| 6442 |
|
| 6443 |
public: |
| 6444 |
INSTRUCTION_HEADER(OsrValue) |
| 6445 |
TRIVIAL_NEW_WRAPPERS |
| 6446 |
|
| 6447 |
ptrdiff_t frameOffset() const { return frameOffset_; } |
| 6448 |
|
| 6449 |
MOsrEntry* entry() { return getOperand(0)->toOsrEntry(); } |
| 6450 |
|
| 6451 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6452 |
}; |
| 6453 |
|
| 6454 |
// MIR representation of a JSObject scope chain pointer on the OSR |
| 6455 |
// BaselineFrame. The pointer is indexed off of OsrFrameReg. |
| 6456 |
class MOsrEnvironmentChain : public MUnaryInstruction, |
| 6457 |
public NoTypePolicy::Data { |
| 6458 |
private: |
| 6459 |
explicit MOsrEnvironmentChain(MOsrEntry* entry) |
| 6460 |
: MUnaryInstruction(classOpcode, entry) { |
| 6461 |
setResultType(MIRType::Object); |
| 6462 |
} |
| 6463 |
|
| 6464 |
public: |
| 6465 |
INSTRUCTION_HEADER(OsrEnvironmentChain) |
| 6466 |
TRIVIAL_NEW_WRAPPERS |
| 6467 |
|
| 6468 |
MOsrEntry* entry() { return getOperand(0)->toOsrEntry(); } |
| 6469 |
}; |
| 6470 |
|
| 6471 |
// MIR representation of a JSObject ArgumentsObject pointer on the OSR |
| 6472 |
// BaselineFrame. The pointer is indexed off of OsrFrameReg. |
| 6473 |
class MOsrArgumentsObject : public MUnaryInstruction, |
| 6474 |
public NoTypePolicy::Data { |
| 6475 |
private: |
| 6476 |
explicit MOsrArgumentsObject(MOsrEntry* entry) |
| 6477 |
: MUnaryInstruction(classOpcode, entry) { |
| 6478 |
setResultType(MIRType::Object); |
| 6479 |
} |
| 6480 |
|
| 6481 |
public: |
| 6482 |
INSTRUCTION_HEADER(OsrArgumentsObject) |
| 6483 |
TRIVIAL_NEW_WRAPPERS |
| 6484 |
|
| 6485 |
MOsrEntry* entry() { return getOperand(0)->toOsrEntry(); } |
| 6486 |
}; |
| 6487 |
|
| 6488 |
// MIR representation of the return value on the OSR BaselineFrame. |
| 6489 |
// The Value is indexed off of OsrFrameReg. |
| 6490 |
class MOsrReturnValue : public MUnaryInstruction, public NoTypePolicy::Data { |
| 6491 |
private: |
| 6492 |
explicit MOsrReturnValue(MOsrEntry* entry) |
| 6493 |
: MUnaryInstruction(classOpcode, entry) { |
| 6494 |
setResultType(MIRType::Value); |
| 6495 |
} |
| 6496 |
|
| 6497 |
public: |
| 6498 |
INSTRUCTION_HEADER(OsrReturnValue) |
| 6499 |
TRIVIAL_NEW_WRAPPERS |
| 6500 |
|
| 6501 |
MOsrEntry* entry() { return getOperand(0)->toOsrEntry(); } |
| 6502 |
}; |
| 6503 |
|
| 6504 |
class MBinaryCache : public MBinaryInstruction, |
| 6505 |
public MixPolicy<BoxPolicy<0>, BoxPolicy<1>>::Data { |
| 6506 |
explicit MBinaryCache(MDefinition* left, MDefinition* right, MIRType resType) |
| 6507 |
: MBinaryInstruction(classOpcode, left, right) { |
| 6508 |
setResultType(resType); |
| 6509 |
} |
| 6510 |
|
| 6511 |
public: |
| 6512 |
INSTRUCTION_HEADER(BinaryCache) |
| 6513 |
TRIVIAL_NEW_WRAPPERS |
| 6514 |
}; |
| 6515 |
|
| 6516 |
// Checks if a value is JS_UNINITIALIZED_LEXICAL, bailout out if so, leaving |
| 6517 |
// it to baseline to throw at the correct pc. |
| 6518 |
class MLexicalCheck : public MUnaryInstruction, public BoxPolicy<0>::Data { |
| 6519 |
explicit MLexicalCheck(MDefinition* input) |
| 6520 |
: MUnaryInstruction(classOpcode, input) { |
| 6521 |
setResultType(MIRType::Value); |
| 6522 |
setMovable(); |
| 6523 |
setGuard(); |
| 6524 |
|
| 6525 |
// If this instruction bails out, we will set a flag to prevent |
| 6526 |
// lexical checks in this script from being moved. |
| 6527 |
setBailoutKind(BailoutKind::UninitializedLexical); |
| 6528 |
} |
| 6529 |
|
| 6530 |
public: |
| 6531 |
INSTRUCTION_HEADER(LexicalCheck) |
| 6532 |
TRIVIAL_NEW_WRAPPERS |
| 6533 |
|
| 6534 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6535 |
|
| 6536 |
bool congruentTo(const MDefinition* ins) const override { |
| 6537 |
return congruentIfOperandsEqual(ins); |
| 6538 |
} |
| 6539 |
}; |
| 6540 |
|
| 6541 |
// Unconditionally throw a known error number. |
| 6542 |
class MThrowMsg : public MNullaryInstruction { |
| 6543 |
const ThrowMsgKind throwMsgKind_; |
| 6544 |
|
| 6545 |
explicit MThrowMsg(ThrowMsgKind throwMsgKind) |
| 6546 |
: MNullaryInstruction(classOpcode), throwMsgKind_(throwMsgKind) { |
| 6547 |
setGuard(); |
| 6548 |
setResultType(MIRType::None); |
| 6549 |
} |
| 6550 |
|
| 6551 |
public: |
| 6552 |
INSTRUCTION_HEADER(ThrowMsg) |
| 6553 |
TRIVIAL_NEW_WRAPPERS |
| 6554 |
|
| 6555 |
ThrowMsgKind throwMsgKind() const { return throwMsgKind_; } |
| 6556 |
|
| 6557 |
AliasSet getAliasSet() const override { |
| 6558 |
return AliasSet::Store(AliasSet::ExceptionState); |
| 6559 |
} |
| 6560 |
}; |
| 6561 |
|
| 6562 |
class MGetFirstDollarIndex : public MUnaryInstruction, |
| 6563 |
public StringPolicy<0>::Data { |
| 6564 |
explicit MGetFirstDollarIndex(MDefinition* str) |
| 6565 |
: MUnaryInstruction(classOpcode, str) { |
| 6566 |
setResultType(MIRType::Int32); |
| 6567 |
|
| 6568 |
// Codegen assumes string length > 0. Don't allow LICM to move this |
| 6569 |
// before the .length > 1 check in RegExpReplace in RegExp.js. |
| 6570 |
MOZ_ASSERT(!isMovable()); |
| 6571 |
} |
| 6572 |
|
| 6573 |
public: |
| 6574 |
INSTRUCTION_HEADER(GetFirstDollarIndex) |
| 6575 |
TRIVIAL_NEW_WRAPPERS |
| 6576 |
NAMED_OPERANDS((0, str)) |
| 6577 |
|
| 6578 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6579 |
|
| 6580 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6581 |
}; |
| 6582 |
|
| 6583 |
class MStringReplace : public MTernaryInstruction, |
| 6584 |
public MixPolicy<StringPolicy<0>, StringPolicy<1>, |
| 6585 |
StringPolicy<2>>::Data { |
| 6586 |
private: |
| 6587 |
bool isFlatReplacement_; |
| 6588 |
|
| 6589 |
MStringReplace(MDefinition* string, MDefinition* pattern, |
| 6590 |
MDefinition* replacement) |
| 6591 |
: MTernaryInstruction(classOpcode, string, pattern, replacement), |
| 6592 |
isFlatReplacement_(false) { |
| 6593 |
setMovable(); |
| 6594 |
setResultType(MIRType::String); |
| 6595 |
} |
| 6596 |
|
| 6597 |
public: |
| 6598 |
INSTRUCTION_HEADER(StringReplace) |
| 6599 |
TRIVIAL_NEW_WRAPPERS |
| 6600 |
NAMED_OPERANDS((0, string), (1, pattern), (2, replacement)) |
| 6601 |
|
| 6602 |
void setFlatReplacement() { |
| 6603 |
MOZ_ASSERT(!isFlatReplacement_); |
| 6604 |
isFlatReplacement_ = true; |
| 6605 |
} |
| 6606 |
|
| 6607 |
bool isFlatReplacement() const { return isFlatReplacement_; } |
| 6608 |
|
| 6609 |
bool congruentTo(const MDefinition* ins) const override { |
| 6610 |
if (!ins->isStringReplace()) { |
| 6611 |
return false; |
| 6612 |
} |
| 6613 |
if (isFlatReplacement_ != ins->toStringReplace()->isFlatReplacement()) { |
| 6614 |
return false; |
| 6615 |
} |
| 6616 |
return congruentIfOperandsEqual(ins); |
| 6617 |
} |
| 6618 |
|
| 6619 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6620 |
|
| 6621 |
[[nodiscard]] bool writeRecoverData( |
| 6622 |
CompactBufferWriter& writer) const override; |
| 6623 |
bool canRecoverOnBailout() const override { |
| 6624 |
if (isFlatReplacement_) { |
| 6625 |
MOZ_ASSERT(!pattern()->isRegExp()); |
| 6626 |
return true; |
| 6627 |
} |
| 6628 |
return false; |
| 6629 |
} |
| 6630 |
|
| 6631 |
bool possiblyCalls() const override { return true; } |
| 6632 |
}; |
| 6633 |
|
| 6634 |
class MLambda : public MBinaryInstruction, public SingleObjectPolicy::Data { |
| 6635 |
MLambda(MDefinition* envChain, MConstant* cst, gc::Heap initialHeap) |
| 6636 |
: MBinaryInstruction(classOpcode, envChain, cst), |
| 6637 |
initialHeap_(initialHeap) { |
| 6638 |
setResultType(MIRType::Object); |
| 6639 |
} |
| 6640 |
|
| 6641 |
// Heap where the lambda should be allocated. |
| 6642 |
gc::Heap initialHeap_; |
| 6643 |
|
| 6644 |
public: |
| 6645 |
INSTRUCTION_HEADER(Lambda) |
| 6646 |
TRIVIAL_NEW_WRAPPERS |
| 6647 |
NAMED_OPERANDS((0, environmentChain)) |
| 6648 |
|
| 6649 |
MConstant* functionOperand() const { return getOperand(1)->toConstant(); } |
| 6650 |
JSFunction* templateFunction() const { |
| 6651 |
return &functionOperand()->toObject().as<JSFunction>(); |
| 6652 |
} |
| 6653 |
|
| 6654 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 6655 |
|
| 6656 |
[[nodiscard]] bool writeRecoverData( |
| 6657 |
CompactBufferWriter& writer) const override; |
| 6658 |
bool canRecoverOnBailout() const override { return true; } |
| 6659 |
}; |
| 6660 |
|
| 6661 |
class MFunctionWithProto : public MTernaryInstruction, |
| 6662 |
public MixPolicy<ObjectPolicy<0>, ObjectPolicy<1>, |
| 6663 |
ObjectPolicy<2>>::Data { |
| 6664 |
CompilerFunction fun_; |
| 6665 |
|
| 6666 |
MFunctionWithProto(MDefinition* envChain, MDefinition* prototype, |
| 6667 |
MConstant* cst) |
| 6668 |
: MTernaryInstruction(classOpcode, envChain, prototype, cst), |
| 6669 |
fun_(&cst->toObject().as<JSFunction>()) { |
| 6670 |
setResultType(MIRType::Object); |
| 6671 |
} |
| 6672 |
|
| 6673 |
public: |
| 6674 |
INSTRUCTION_HEADER(FunctionWithProto) |
| 6675 |
TRIVIAL_NEW_WRAPPERS |
| 6676 |
NAMED_OPERANDS((0, environmentChain), (1, prototype)) |
| 6677 |
|
| 6678 |
MConstant* functionOperand() const { return getOperand(2)->toConstant(); } |
| 6679 |
JSFunction* function() const { return fun_; } |
| 6680 |
[[nodiscard]] bool writeRecoverData( |
| 6681 |
CompactBufferWriter& writer) const override; |
| 6682 |
bool canRecoverOnBailout() const override { return true; } |
| 6683 |
|
| 6684 |
bool possiblyCalls() const override { return true; } |
| 6685 |
}; |
| 6686 |
|
| 6687 |
class MGetNextEntryForIterator |
| 6688 |
: public MBinaryInstruction, |
| 6689 |
public MixPolicy<ObjectPolicy<0>, ObjectPolicy<1>>::Data { |
| 6690 |
public: |
| 6691 |
enum Mode { Map, Set }; |
| 6692 |
|
| 6693 |
private: |
| 6694 |
Mode mode_; |
| 6695 |
|
| 6696 |
explicit MGetNextEntryForIterator(MDefinition* iter, MDefinition* result, |
| 6697 |
Mode mode) |
| 6698 |
: MBinaryInstruction(classOpcode, iter, result), mode_(mode) { |
| 6699 |
setResultType(MIRType::Boolean); |
| 6700 |
} |
| 6701 |
|
| 6702 |
public: |
| 6703 |
INSTRUCTION_HEADER(GetNextEntryForIterator) |
| 6704 |
TRIVIAL_NEW_WRAPPERS |
| 6705 |
NAMED_OPERANDS((0, iter), (1, result)) |
| 6706 |
|
| 6707 |
Mode mode() const { return mode_; } |
| 6708 |
}; |
| 6709 |
|
| 6710 |
// Convert a Double into an IntPtr value for accessing a TypedArray or DataView |
| 6711 |
// element. If the input is non-finite, not an integer, negative, or outside the |
| 6712 |
// IntPtr range, either bails out or produces a value which is known to trigger |
| 6713 |
// an out-of-bounds access (this depends on the supportOOB flag). |
| 6714 |
class MGuardNumberToIntPtrIndex : public MUnaryInstruction, |
| 6715 |
public DoublePolicy<0>::Data { |
| 6716 |
// If true, produce an out-of-bounds index for non-IntPtr doubles instead of |
| 6717 |
// bailing out. |
| 6718 |
const bool supportOOB_; |
| 6719 |
|
| 6720 |
MGuardNumberToIntPtrIndex(MDefinition* def, bool supportOOB) |
| 6721 |
: MUnaryInstruction(classOpcode, def), supportOOB_(supportOOB) { |
| 6722 |
MOZ_ASSERT(IsNumberType(def->type())); |
| 6723 |
setResultType(MIRType::IntPtr); |
| 6724 |
setMovable(); |
| 6725 |
if (!supportOOB) { |
| 6726 |
setGuard(); |
| 6727 |
} |
| 6728 |
} |
| 6729 |
|
| 6730 |
public: |
| 6731 |
INSTRUCTION_HEADER(GuardNumberToIntPtrIndex) |
| 6732 |
TRIVIAL_NEW_WRAPPERS |
| 6733 |
|
| 6734 |
bool supportOOB() const { return supportOOB_; } |
| 6735 |
|
| 6736 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6737 |
|
| 6738 |
bool congruentTo(const MDefinition* ins) const override { |
| 6739 |
if (!ins->isGuardNumberToIntPtrIndex()) { |
| 6740 |
return false; |
| 6741 |
} |
| 6742 |
if (ins->toGuardNumberToIntPtrIndex()->supportOOB() != supportOOB()) { |
| 6743 |
return false; |
| 6744 |
} |
| 6745 |
return congruentIfOperandsEqual(ins); |
| 6746 |
} |
| 6747 |
|
| 6748 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6749 |
|
| 6750 |
ALLOW_CLONE(MGuardNumberToIntPtrIndex) |
| 6751 |
}; |
| 6752 |
|
| 6753 |
// Perform !-operation |
| 6754 |
class MNot : public MUnaryInstruction, public TestPolicy::Data { |
| 6755 |
bool operandIsNeverNaN_; |
| 6756 |
TypeDataList observedTypes_; |
| 6757 |
|
| 6758 |
explicit MNot(MDefinition* input) |
| 6759 |
: MUnaryInstruction(classOpcode, input), operandIsNeverNaN_(false) { |
| 6760 |
setResultType(MIRType::Boolean); |
| 6761 |
setMovable(); |
| 6762 |
} |
| 6763 |
|
| 6764 |
public: |
| 6765 |
static MNot* NewInt32(TempAllocator& alloc, MDefinition* input) { |
| 6766 |
MOZ_ASSERT(input->type() == MIRType::Int32 || |
| 6767 |
input->type() == MIRType::Int64); |
| 6768 |
auto* ins = new (alloc) MNot(input); |
| 6769 |
ins->setResultType(MIRType::Int32); |
| 6770 |
return ins; |
| 6771 |
} |
| 6772 |
|
| 6773 |
INSTRUCTION_HEADER(Not) |
| 6774 |
TRIVIAL_NEW_WRAPPERS |
| 6775 |
|
| 6776 |
void setObservedTypes(const TypeDataList& observed) { |
| 6777 |
observedTypes_ = observed; |
| 6778 |
} |
| 6779 |
const TypeDataList& observedTypes() const { return observedTypes_; } |
| 6780 |
|
| 6781 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6782 |
|
| 6783 |
bool operandIsNeverNaN() const { return operandIsNeverNaN_; } |
| 6784 |
|
| 6785 |
virtual AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6786 |
void collectRangeInfoPreTrunc() override; |
| 6787 |
|
| 6788 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 6789 |
bool isFloat32Commutative() const override { return true; } |
| 6790 |
#ifdef DEBUG |
| 6791 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 6792 |
#endif |
| 6793 |
bool congruentTo(const MDefinition* ins) const override { |
| 6794 |
return congruentIfOperandsEqual(ins); |
| 6795 |
} |
| 6796 |
[[nodiscard]] bool writeRecoverData( |
| 6797 |
CompactBufferWriter& writer) const override; |
| 6798 |
bool canRecoverOnBailout() const override { |
| 6799 |
return type() == MIRType::Boolean; |
| 6800 |
} |
| 6801 |
|
| 6802 |
ALLOW_CLONE(MNot) |
| 6803 |
}; |
| 6804 |
|
| 6805 |
// Bailout if index + minimum < 0 or index + maximum >= length. The length used |
| 6806 |
// in a bounds check must not be negative, or the wrong result may be computed |
| 6807 |
// (unsigned comparisons may be used). |
| 6808 |
class MBoundsCheck |
| 6809 |
: public MBinaryInstruction, |
| 6810 |
public MixPolicy<Int32OrIntPtrPolicy<0>, Int32OrIntPtrPolicy<1>>::Data { |
| 6811 |
// Range over which to perform the bounds check, may be modified by GVN. |
| 6812 |
int32_t minimum_; |
| 6813 |
int32_t maximum_; |
| 6814 |
bool fallible_; |
| 6815 |
|
| 6816 |
MBoundsCheck(MDefinition* index, MDefinition* length) |
| 6817 |
: MBinaryInstruction(classOpcode, index, length), |
| 6818 |
minimum_(0), |
| 6819 |
maximum_(0), |
| 6820 |
fallible_(true) { |
| 6821 |
setGuard(); |
| 6822 |
setMovable(); |
| 6823 |
MOZ_ASSERT(index->type() == MIRType::Int32 || |
| 6824 |
index->type() == MIRType::IntPtr); |
| 6825 |
MOZ_ASSERT(index->type() == length->type()); |
| 6826 |
|
| 6827 |
// Returns the checked index. |
| 6828 |
setResultType(index->type()); |
| 6829 |
} |
| 6830 |
|
| 6831 |
public: |
| 6832 |
INSTRUCTION_HEADER(BoundsCheck) |
| 6833 |
TRIVIAL_NEW_WRAPPERS |
| 6834 |
NAMED_OPERANDS((0, index), (1, length)) |
| 6835 |
|
| 6836 |
int32_t minimum() const { return minimum_; } |
| 6837 |
void setMinimum(int32_t n) { |
| 6838 |
MOZ_ASSERT(fallible_); |
| 6839 |
minimum_ = n; |
| 6840 |
} |
| 6841 |
int32_t maximum() const { return maximum_; } |
| 6842 |
void setMaximum(int32_t n) { |
| 6843 |
MOZ_ASSERT(fallible_); |
| 6844 |
maximum_ = n; |
| 6845 |
} |
| 6846 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6847 |
bool congruentTo(const MDefinition* ins) const override { |
| 6848 |
if (!ins->isBoundsCheck()) { |
| 6849 |
return false; |
| 6850 |
} |
| 6851 |
const MBoundsCheck* other = ins->toBoundsCheck(); |
| 6852 |
if (minimum() != other->minimum() || maximum() != other->maximum()) { |
| 6853 |
return false; |
| 6854 |
} |
| 6855 |
if (fallible() != other->fallible()) { |
| 6856 |
return false; |
| 6857 |
} |
| 6858 |
return congruentIfOperandsEqual(other); |
| 6859 |
} |
| 6860 |
virtual AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6861 |
void computeRange(TempAllocator& alloc) override; |
| 6862 |
bool fallible() const { return fallible_; } |
| 6863 |
void collectRangeInfoPreTrunc() override; |
| 6864 |
|
| 6865 |
ALLOW_CLONE(MBoundsCheck) |
| 6866 |
}; |
| 6867 |
|
| 6868 |
// Bailout if index < minimum. |
| 6869 |
class MBoundsCheckLower : public MUnaryInstruction, |
| 6870 |
public UnboxedInt32Policy<0>::Data { |
| 6871 |
int32_t minimum_; |
| 6872 |
bool fallible_; |
| 6873 |
|
| 6874 |
explicit MBoundsCheckLower(MDefinition* index) |
| 6875 |
: MUnaryInstruction(classOpcode, index), minimum_(0), fallible_(true) { |
| 6876 |
setGuard(); |
| 6877 |
setMovable(); |
| 6878 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 6879 |
} |
| 6880 |
|
| 6881 |
public: |
| 6882 |
INSTRUCTION_HEADER(BoundsCheckLower) |
| 6883 |
TRIVIAL_NEW_WRAPPERS |
| 6884 |
NAMED_OPERANDS((0, index)) |
| 6885 |
|
| 6886 |
int32_t minimum() const { return minimum_; } |
| 6887 |
void setMinimum(int32_t n) { minimum_ = n; } |
| 6888 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6889 |
bool fallible() const { return fallible_; } |
| 6890 |
void collectRangeInfoPreTrunc() override; |
| 6891 |
}; |
| 6892 |
|
| 6893 |
class MSpectreMaskIndex |
| 6894 |
: public MBinaryInstruction, |
| 6895 |
public MixPolicy<Int32OrIntPtrPolicy<0>, Int32OrIntPtrPolicy<1>>::Data { |
| 6896 |
MSpectreMaskIndex(MDefinition* index, MDefinition* length) |
| 6897 |
: MBinaryInstruction(classOpcode, index, length) { |
| 6898 |
// Note: this instruction does not need setGuard(): if there are no uses |
| 6899 |
// it's fine for DCE to eliminate this instruction. |
| 6900 |
setMovable(); |
| 6901 |
MOZ_ASSERT(index->type() == MIRType::Int32 || |
| 6902 |
index->type() == MIRType::IntPtr); |
| 6903 |
MOZ_ASSERT(index->type() == length->type()); |
| 6904 |
|
| 6905 |
// Returns the masked index. |
| 6906 |
setResultType(index->type()); |
| 6907 |
} |
| 6908 |
|
| 6909 |
public: |
| 6910 |
INSTRUCTION_HEADER(SpectreMaskIndex) |
| 6911 |
TRIVIAL_NEW_WRAPPERS |
| 6912 |
NAMED_OPERANDS((0, index), (1, length)) |
| 6913 |
|
| 6914 |
bool congruentTo(const MDefinition* ins) const override { |
| 6915 |
return congruentIfOperandsEqual(ins); |
| 6916 |
} |
| 6917 |
virtual AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 6918 |
void computeRange(TempAllocator& alloc) override; |
| 6919 |
|
| 6920 |
ALLOW_CLONE(MSpectreMaskIndex) |
| 6921 |
}; |
| 6922 |
|
| 6923 |
// Load a value from a dense array's element vector. Bails out if the element is |
| 6924 |
// a hole. |
| 6925 |
class MLoadElement : public MBinaryInstruction, public NoTypePolicy::Data { |
| 6926 |
MLoadElement(MDefinition* elements, MDefinition* index) |
| 6927 |
: MBinaryInstruction(classOpcode, elements, index) { |
| 6928 |
// Uses may be optimized away based on this instruction's result |
| 6929 |
// type. This means it's invalid to DCE this instruction, as we |
| 6930 |
// have to invalidate when we read a hole. |
| 6931 |
setGuard(); |
| 6932 |
setResultType(MIRType::Value); |
| 6933 |
setMovable(); |
| 6934 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 6935 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 6936 |
} |
| 6937 |
|
| 6938 |
public: |
| 6939 |
INSTRUCTION_HEADER(LoadElement) |
| 6940 |
TRIVIAL_NEW_WRAPPERS |
| 6941 |
NAMED_OPERANDS((0, elements), (1, index)) |
| 6942 |
|
| 6943 |
bool congruentTo(const MDefinition* ins) const override { |
| 6944 |
return congruentIfOperandsEqual(ins); |
| 6945 |
} |
| 6946 |
AliasType mightAlias(const MDefinition* store) const override; |
| 6947 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 6948 |
AliasSet getAliasSet() const override { |
| 6949 |
return AliasSet::Load(AliasSet::Element); |
| 6950 |
} |
| 6951 |
|
| 6952 |
ALLOW_CLONE(MLoadElement) |
| 6953 |
}; |
| 6954 |
|
| 6955 |
class MLoadElementAndUnbox : public MBinaryInstruction, |
| 6956 |
public NoTypePolicy::Data { |
| 6957 |
MUnbox::Mode mode_; |
| 6958 |
|
| 6959 |
MLoadElementAndUnbox(MDefinition* elements, MDefinition* index, |
| 6960 |
MUnbox::Mode mode, MIRType type) |
| 6961 |
: MBinaryInstruction(classOpcode, elements, index), mode_(mode) { |
| 6962 |
setResultType(type); |
| 6963 |
setMovable(); |
| 6964 |
if (mode_ == MUnbox::Fallible) { |
| 6965 |
setGuard(); |
| 6966 |
} |
| 6967 |
} |
| 6968 |
|
| 6969 |
public: |
| 6970 |
INSTRUCTION_HEADER(LoadElementAndUnbox) |
| 6971 |
TRIVIAL_NEW_WRAPPERS |
| 6972 |
NAMED_OPERANDS((0, elements), (1, index)) |
| 6973 |
|
| 6974 |
MUnbox::Mode mode() const { return mode_; } |
| 6975 |
bool fallible() const { return mode_ != MUnbox::Infallible; } |
| 6976 |
|
| 6977 |
bool congruentTo(const MDefinition* ins) const override { |
| 6978 |
if (!ins->isLoadElementAndUnbox() || |
| 6979 |
mode() != ins->toLoadElementAndUnbox()->mode()) { |
| 6980 |
return false; |
| 6981 |
} |
| 6982 |
return congruentIfOperandsEqual(ins); |
| 6983 |
} |
| 6984 |
|
| 6985 |
AliasSet getAliasSet() const override { |
| 6986 |
return AliasSet::Load(AliasSet::Element); |
| 6987 |
} |
| 6988 |
|
| 6989 |
ALLOW_CLONE(MLoadElementAndUnbox); |
| 6990 |
}; |
| 6991 |
|
| 6992 |
// Load a value from the elements vector of a native object. If the index is |
| 6993 |
// out-of-bounds, or the indexed slot has a hole, undefined is returned instead. |
| 6994 |
class MLoadElementHole : public MTernaryInstruction, public NoTypePolicy::Data { |
| 6995 |
bool needsNegativeIntCheck_ = true; |
| 6996 |
|
| 6997 |
MLoadElementHole(MDefinition* elements, MDefinition* index, |
| 6998 |
MDefinition* initLength) |
| 6999 |
: MTernaryInstruction(classOpcode, elements, index, initLength) { |
| 7000 |
setResultType(MIRType::Value); |
| 7001 |
setMovable(); |
| 7002 |
|
| 7003 |
// Set the guard flag to make sure we bail when we see a negative |
| 7004 |
// index. We can clear this flag (and needsNegativeIntCheck_) in |
| 7005 |
// collectRangeInfoPreTrunc. |
| 7006 |
setGuard(); |
| 7007 |
|
| 7008 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7009 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 7010 |
MOZ_ASSERT(initLength->type() == MIRType::Int32); |
| 7011 |
} |
| 7012 |
|
| 7013 |
public: |
| 7014 |
INSTRUCTION_HEADER(LoadElementHole) |
| 7015 |
TRIVIAL_NEW_WRAPPERS |
| 7016 |
NAMED_OPERANDS((0, elements), (1, index), (2, initLength)) |
| 7017 |
|
| 7018 |
bool needsNegativeIntCheck() const { return needsNegativeIntCheck_; } |
| 7019 |
bool congruentTo(const MDefinition* ins) const override { |
| 7020 |
if (!ins->isLoadElementHole()) { |
| 7021 |
return false; |
| 7022 |
} |
| 7023 |
const MLoadElementHole* other = ins->toLoadElementHole(); |
| 7024 |
if (needsNegativeIntCheck() != other->needsNegativeIntCheck()) { |
| 7025 |
return false; |
| 7026 |
} |
| 7027 |
return congruentIfOperandsEqual(other); |
| 7028 |
} |
| 7029 |
AliasSet getAliasSet() const override { |
| 7030 |
return AliasSet::Load(AliasSet::Element); |
| 7031 |
} |
| 7032 |
void collectRangeInfoPreTrunc() override; |
| 7033 |
|
| 7034 |
ALLOW_CLONE(MLoadElementHole) |
| 7035 |
}; |
| 7036 |
|
| 7037 |
// Store a value to a dense array slots vector. |
| 7038 |
class MStoreElement : public MTernaryInstruction, |
| 7039 |
public NoFloatPolicy<2>::Data { |
| 7040 |
bool needsHoleCheck_; |
| 7041 |
bool needsBarrier_; |
| 7042 |
|
| 7043 |
MStoreElement(MDefinition* elements, MDefinition* index, MDefinition* value, |
| 7044 |
bool needsHoleCheck, bool needsBarrier) |
| 7045 |
: MTernaryInstruction(classOpcode, elements, index, value) { |
| 7046 |
needsHoleCheck_ = needsHoleCheck; |
| 7047 |
needsBarrier_ = needsBarrier; |
| 7048 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7049 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 7050 |
MOZ_ASSERT(value->type() != MIRType::MagicHole); |
| 7051 |
} |
| 7052 |
|
| 7053 |
public: |
| 7054 |
INSTRUCTION_HEADER(StoreElement) |
| 7055 |
TRIVIAL_NEW_WRAPPERS |
| 7056 |
NAMED_OPERANDS((0, elements), (1, index), (2, value)) |
| 7057 |
|
| 7058 |
static MStoreElement* NewUnbarriered(TempAllocator& alloc, |
| 7059 |
MDefinition* elements, |
| 7060 |
MDefinition* index, MDefinition* value, |
| 7061 |
bool needsHoleCheck) { |
| 7062 |
return new (alloc) |
| 7063 |
MStoreElement(elements, index, value, needsHoleCheck, false); |
| 7064 |
} |
| 7065 |
|
| 7066 |
static MStoreElement* NewBarriered(TempAllocator& alloc, |
| 7067 |
MDefinition* elements, MDefinition* index, |
| 7068 |
MDefinition* value, bool needsHoleCheck) { |
| 7069 |
return new (alloc) |
| 7070 |
MStoreElement(elements, index, value, needsHoleCheck, true); |
| 7071 |
} |
| 7072 |
|
| 7073 |
AliasSet getAliasSet() const override { |
| 7074 |
return AliasSet::Store(AliasSet::Element); |
| 7075 |
} |
| 7076 |
bool needsBarrier() const { return needsBarrier_; } |
| 7077 |
bool needsHoleCheck() const { return needsHoleCheck_; } |
| 7078 |
bool fallible() const { return needsHoleCheck(); } |
| 7079 |
|
| 7080 |
ALLOW_CLONE(MStoreElement) |
| 7081 |
}; |
| 7082 |
|
| 7083 |
// Stores MagicValue(JS_ELEMENTS_HOLE) and marks the elements as non-packed. |
| 7084 |
class MStoreHoleValueElement : public MBinaryInstruction, |
| 7085 |
public NoTypePolicy::Data { |
| 7086 |
MStoreHoleValueElement(MDefinition* elements, MDefinition* index) |
| 7087 |
: MBinaryInstruction(classOpcode, elements, index) { |
| 7088 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7089 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 7090 |
} |
| 7091 |
|
| 7092 |
public: |
| 7093 |
INSTRUCTION_HEADER(StoreHoleValueElement) |
| 7094 |
TRIVIAL_NEW_WRAPPERS |
| 7095 |
NAMED_OPERANDS((0, elements), (1, index)) |
| 7096 |
|
| 7097 |
AliasSet getAliasSet() const override { |
| 7098 |
return AliasSet::Store(AliasSet::Element | AliasSet::ObjectFields); |
| 7099 |
} |
| 7100 |
|
| 7101 |
ALLOW_CLONE(MStoreHoleValueElement) |
| 7102 |
}; |
| 7103 |
|
| 7104 |
// Like MStoreElement, but also supports index == initialized length. The |
| 7105 |
// downside is that we cannot hoist the elements vector and bounds check, since |
| 7106 |
// this instruction may update the (initialized) length and reallocate the |
| 7107 |
// elements vector. |
| 7108 |
class MStoreElementHole |
| 7109 |
: public MQuaternaryInstruction, |
| 7110 |
public MixPolicy<SingleObjectPolicy, NoFloatPolicy<3>>::Data { |
| 7111 |
MStoreElementHole(MDefinition* object, MDefinition* elements, |
| 7112 |
MDefinition* index, MDefinition* value) |
| 7113 |
: MQuaternaryInstruction(classOpcode, object, elements, index, value) { |
| 7114 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7115 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 7116 |
MOZ_ASSERT(value->type() != MIRType::MagicHole); |
| 7117 |
} |
| 7118 |
|
| 7119 |
public: |
| 7120 |
INSTRUCTION_HEADER(StoreElementHole) |
| 7121 |
TRIVIAL_NEW_WRAPPERS |
| 7122 |
NAMED_OPERANDS((0, object), (1, elements), (2, index), (3, value)) |
| 7123 |
|
| 7124 |
AliasSet getAliasSet() const override { |
| 7125 |
// StoreElementHole can update the initialized length, the array length |
| 7126 |
// or reallocate obj->elements. |
| 7127 |
return AliasSet::Store(AliasSet::ObjectFields | AliasSet::Element); |
| 7128 |
} |
| 7129 |
|
| 7130 |
ALLOW_CLONE(MStoreElementHole) |
| 7131 |
}; |
| 7132 |
|
| 7133 |
// Array.prototype.pop or Array.prototype.shift on a dense array. |
| 7134 |
class MArrayPopShift : public MUnaryInstruction, |
| 7135 |
public SingleObjectPolicy::Data { |
| 7136 |
public: |
| 7137 |
enum Mode { Pop, Shift }; |
| 7138 |
|
| 7139 |
private: |
| 7140 |
Mode mode_; |
| 7141 |
|
| 7142 |
MArrayPopShift(MDefinition* object, Mode mode) |
| 7143 |
: MUnaryInstruction(classOpcode, object), mode_(mode) { |
| 7144 |
setResultType(MIRType::Value); |
| 7145 |
} |
| 7146 |
|
| 7147 |
public: |
| 7148 |
INSTRUCTION_HEADER(ArrayPopShift) |
| 7149 |
TRIVIAL_NEW_WRAPPERS |
| 7150 |
NAMED_OPERANDS((0, object)) |
| 7151 |
|
| 7152 |
bool mode() const { return mode_; } |
| 7153 |
AliasSet getAliasSet() const override { |
| 7154 |
return AliasSet::Store(AliasSet::ObjectFields | AliasSet::Element); |
| 7155 |
} |
| 7156 |
|
| 7157 |
ALLOW_CLONE(MArrayPopShift) |
| 7158 |
}; |
| 7159 |
|
| 7160 |
// Load an unboxed scalar value from an array buffer view or other object. |
| 7161 |
class MLoadUnboxedScalar : public MBinaryInstruction, |
| 7162 |
public NoTypePolicy::Data { |
| 7163 |
int32_t offsetAdjustment_ = 0; |
| 7164 |
Scalar::Type storageType_; |
| 7165 |
MemoryBarrierRequirement requiresBarrier_; |
| 7166 |
|
| 7167 |
MLoadUnboxedScalar(MDefinition* elements, MDefinition* index, |
| 7168 |
Scalar::Type storageType, |
| 7169 |
MemoryBarrierRequirement requiresBarrier = |
| 7170 |
MemoryBarrierRequirement::NotRequired) |
| 7171 |
: MBinaryInstruction(classOpcode, elements, index), |
| 7172 |
storageType_(storageType), |
| 7173 |
requiresBarrier_(requiresBarrier) { |
| 7174 |
setResultType(MIRType::Value); |
| 7175 |
if (requiresBarrier_ == MemoryBarrierRequirement::Required) { |
| 7176 |
setGuard(); // Not removable or movable |
| 7177 |
} else { |
| 7178 |
setMovable(); |
| 7179 |
} |
| 7180 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7181 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7182 |
MOZ_ASSERT(storageType >= 0 && storageType < Scalar::MaxTypedArrayViewType); |
| 7183 |
} |
| 7184 |
|
| 7185 |
public: |
| 7186 |
INSTRUCTION_HEADER(LoadUnboxedScalar) |
| 7187 |
TRIVIAL_NEW_WRAPPERS |
| 7188 |
NAMED_OPERANDS((0, elements), (1, index)) |
| 7189 |
|
| 7190 |
Scalar::Type storageType() const { return storageType_; } |
| 7191 |
bool fallible() const { |
| 7192 |
// Bailout if the result does not fit in an int32. |
| 7193 |
return storageType_ == Scalar::Uint32 && type() == MIRType::Int32; |
| 7194 |
} |
| 7195 |
auto requiresMemoryBarrier() const { return requiresBarrier_; } |
| 7196 |
int32_t offsetAdjustment() const { return offsetAdjustment_; } |
| 7197 |
void setOffsetAdjustment(int32_t offsetAdjustment) { |
| 7198 |
offsetAdjustment_ = offsetAdjustment; |
| 7199 |
} |
| 7200 |
AliasSet getAliasSet() const override { |
| 7201 |
// When a barrier is needed make the instruction effectful by |
| 7202 |
// giving it a "store" effect. |
| 7203 |
if (requiresBarrier_ == MemoryBarrierRequirement::Required) { |
| 7204 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 7205 |
} |
| 7206 |
return AliasSet::Load(AliasSet::UnboxedElement); |
| 7207 |
} |
| 7208 |
|
| 7209 |
bool congruentTo(const MDefinition* ins) const override { |
| 7210 |
if (requiresBarrier_ == MemoryBarrierRequirement::Required) { |
| 7211 |
return false; |
| 7212 |
} |
| 7213 |
if (!ins->isLoadUnboxedScalar()) { |
| 7214 |
return false; |
| 7215 |
} |
| 7216 |
const MLoadUnboxedScalar* other = ins->toLoadUnboxedScalar(); |
| 7217 |
if (storageType_ != other->storageType_) { |
| 7218 |
return false; |
| 7219 |
} |
| 7220 |
if (offsetAdjustment() != other->offsetAdjustment()) { |
| 7221 |
return false; |
| 7222 |
} |
| 7223 |
return congruentIfOperandsEqual(other); |
| 7224 |
} |
| 7225 |
|
| 7226 |
#ifdef JS_JITSPEW |
| 7227 |
void printOpcode(GenericPrinter& out) const override; |
| 7228 |
#endif |
| 7229 |
|
| 7230 |
void computeRange(TempAllocator& alloc) override; |
| 7231 |
|
| 7232 |
bool canProduceFloat32() const override { |
| 7233 |
return storageType_ == Scalar::Float32 || storageType_ == Scalar::Float16; |
| 7234 |
} |
| 7235 |
|
| 7236 |
ALLOW_CLONE(MLoadUnboxedScalar) |
| 7237 |
}; |
| 7238 |
|
| 7239 |
// Load an unboxed scalar value from a dataview object. |
| 7240 |
class MLoadDataViewElement : public MTernaryInstruction, |
| 7241 |
public NoTypePolicy::Data { |
| 7242 |
Scalar::Type storageType_; |
| 7243 |
|
| 7244 |
MLoadDataViewElement(MDefinition* elements, MDefinition* index, |
| 7245 |
MDefinition* littleEndian, Scalar::Type storageType) |
| 7246 |
: MTernaryInstruction(classOpcode, elements, index, littleEndian), |
| 7247 |
storageType_(storageType) { |
| 7248 |
setResultType(MIRType::Value); |
| 7249 |
setMovable(); |
| 7250 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7251 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7252 |
MOZ_ASSERT(littleEndian->type() == MIRType::Boolean); |
| 7253 |
MOZ_ASSERT(storageType >= 0 && storageType < Scalar::MaxTypedArrayViewType); |
| 7254 |
MOZ_ASSERT(Scalar::byteSize(storageType) > 1); |
| 7255 |
} |
| 7256 |
|
| 7257 |
public: |
| 7258 |
INSTRUCTION_HEADER(LoadDataViewElement) |
| 7259 |
TRIVIAL_NEW_WRAPPERS |
| 7260 |
NAMED_OPERANDS((0, elements), (1, index), (2, littleEndian)) |
| 7261 |
|
| 7262 |
Scalar::Type storageType() const { return storageType_; } |
| 7263 |
bool fallible() const { |
| 7264 |
// Bailout if the result does not fit in an int32. |
| 7265 |
return storageType_ == Scalar::Uint32 && type() == MIRType::Int32; |
| 7266 |
} |
| 7267 |
AliasSet getAliasSet() const override { |
| 7268 |
return AliasSet::Load(AliasSet::UnboxedElement); |
| 7269 |
} |
| 7270 |
|
| 7271 |
bool congruentTo(const MDefinition* ins) const override { |
| 7272 |
if (!ins->isLoadDataViewElement()) { |
| 7273 |
return false; |
| 7274 |
} |
| 7275 |
const MLoadDataViewElement* other = ins->toLoadDataViewElement(); |
| 7276 |
if (storageType_ != other->storageType_) { |
| 7277 |
return false; |
| 7278 |
} |
| 7279 |
return congruentIfOperandsEqual(other); |
| 7280 |
} |
| 7281 |
|
| 7282 |
#ifdef JS_JITSPEW |
| 7283 |
void printOpcode(GenericPrinter& out) const override; |
| 7284 |
#endif |
| 7285 |
|
| 7286 |
void computeRange(TempAllocator& alloc) override; |
| 7287 |
|
| 7288 |
bool canProduceFloat32() const override { |
| 7289 |
return storageType_ == Scalar::Float32 || storageType_ == Scalar::Float16; |
| 7290 |
} |
| 7291 |
|
| 7292 |
ALLOW_CLONE(MLoadDataViewElement) |
| 7293 |
}; |
| 7294 |
|
| 7295 |
// Load a value from a typed array. Out-of-bounds accesses are handled in-line. |
| 7296 |
class MLoadTypedArrayElementHole : public MTernaryInstruction, |
| 7297 |
public NoTypePolicy::Data { |
| 7298 |
Scalar::Type arrayType_; |
| 7299 |
bool forceDouble_; |
| 7300 |
|
| 7301 |
MLoadTypedArrayElementHole(MDefinition* elements, MDefinition* index, |
| 7302 |
MDefinition* length, Scalar::Type arrayType, |
| 7303 |
bool forceDouble) |
| 7304 |
: MTernaryInstruction(classOpcode, elements, index, length), |
| 7305 |
arrayType_(arrayType), |
| 7306 |
forceDouble_(forceDouble) { |
| 7307 |
setResultType(MIRType::Value); |
| 7308 |
setMovable(); |
| 7309 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7310 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7311 |
MOZ_ASSERT(length->type() == MIRType::IntPtr); |
| 7312 |
MOZ_ASSERT(arrayType >= 0 && arrayType < Scalar::MaxTypedArrayViewType); |
| 7313 |
} |
| 7314 |
|
| 7315 |
public: |
| 7316 |
INSTRUCTION_HEADER(LoadTypedArrayElementHole) |
| 7317 |
TRIVIAL_NEW_WRAPPERS |
| 7318 |
NAMED_OPERANDS((0, elements), (1, index), (2, length)) |
| 7319 |
|
| 7320 |
Scalar::Type arrayType() const { return arrayType_; } |
| 7321 |
bool forceDouble() const { return forceDouble_; } |
| 7322 |
bool fallible() const { |
| 7323 |
return arrayType_ == Scalar::Uint32 && !forceDouble_; |
| 7324 |
} |
| 7325 |
bool congruentTo(const MDefinition* ins) const override { |
| 7326 |
if (!ins->isLoadTypedArrayElementHole()) { |
| 7327 |
return false; |
| 7328 |
} |
| 7329 |
const MLoadTypedArrayElementHole* other = |
| 7330 |
ins->toLoadTypedArrayElementHole(); |
| 7331 |
if (arrayType() != other->arrayType()) { |
| 7332 |
return false; |
| 7333 |
} |
| 7334 |
if (forceDouble() != other->forceDouble()) { |
| 7335 |
return false; |
| 7336 |
} |
| 7337 |
return congruentIfOperandsEqual(other); |
| 7338 |
} |
| 7339 |
AliasSet getAliasSet() const override { |
| 7340 |
return AliasSet::Load(AliasSet::UnboxedElement); |
| 7341 |
} |
| 7342 |
bool canProduceFloat32() const override { |
| 7343 |
return arrayType_ == Scalar::Float32 || arrayType_ == Scalar::Float16; |
| 7344 |
} |
| 7345 |
|
| 7346 |
ALLOW_CLONE(MLoadTypedArrayElementHole) |
| 7347 |
}; |
| 7348 |
|
| 7349 |
// Base class for MIR ops that write unboxed scalar values. |
| 7350 |
class StoreUnboxedScalarBase { |
| 7351 |
Scalar::Type writeType_; |
| 7352 |
|
| 7353 |
protected: |
| 7354 |
explicit StoreUnboxedScalarBase(Scalar::Type writeType) |
| 7355 |
: writeType_(writeType) { |
| 7356 |
MOZ_ASSERT(isIntegerWrite() || isFloatWrite() || isBigIntWrite()); |
| 7357 |
} |
| 7358 |
|
| 7359 |
public: |
| 7360 |
Scalar::Type writeType() const { return writeType_; } |
| 7361 |
bool isByteWrite() const { |
| 7362 |
return writeType_ == Scalar::Int8 || writeType_ == Scalar::Uint8 || |
| 7363 |
writeType_ == Scalar::Uint8Clamped; |
| 7364 |
} |
| 7365 |
bool isIntegerWrite() const { |
| 7366 |
return isByteWrite() || writeType_ == Scalar::Int16 || |
| 7367 |
writeType_ == Scalar::Uint16 || writeType_ == Scalar::Int32 || |
| 7368 |
writeType_ == Scalar::Uint32; |
| 7369 |
} |
| 7370 |
bool isFloatWrite() const { |
| 7371 |
return writeType_ == Scalar::Float16 || writeType_ == Scalar::Float32 || |
| 7372 |
writeType_ == Scalar::Float64; |
| 7373 |
} |
| 7374 |
bool isBigIntWrite() const { return Scalar::isBigIntType(writeType_); } |
| 7375 |
}; |
| 7376 |
|
| 7377 |
// Store an unboxed scalar value to an array buffer view or other object. |
| 7378 |
class MStoreUnboxedScalar : public MTernaryInstruction, |
| 7379 |
public StoreUnboxedScalarBase, |
| 7380 |
public StoreUnboxedScalarPolicy::Data { |
| 7381 |
MemoryBarrierRequirement requiresBarrier_; |
| 7382 |
|
| 7383 |
MStoreUnboxedScalar(MDefinition* elements, MDefinition* index, |
| 7384 |
MDefinition* value, Scalar::Type storageType, |
| 7385 |
MemoryBarrierRequirement requiresBarrier = |
| 7386 |
MemoryBarrierRequirement::NotRequired) |
| 7387 |
: MTernaryInstruction(classOpcode, elements, index, value), |
| 7388 |
StoreUnboxedScalarBase(storageType), |
| 7389 |
requiresBarrier_(requiresBarrier) { |
| 7390 |
if (requiresBarrier_ == MemoryBarrierRequirement::Required) { |
| 7391 |
setGuard(); // Not removable or movable |
| 7392 |
} |
| 7393 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7394 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7395 |
MOZ_ASSERT(storageType >= 0 && storageType < Scalar::MaxTypedArrayViewType); |
| 7396 |
} |
| 7397 |
|
| 7398 |
public: |
| 7399 |
INSTRUCTION_HEADER(StoreUnboxedScalar) |
| 7400 |
TRIVIAL_NEW_WRAPPERS |
| 7401 |
NAMED_OPERANDS((0, elements), (1, index), (2, value)) |
| 7402 |
|
| 7403 |
AliasSet getAliasSet() const override { |
| 7404 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 7405 |
} |
| 7406 |
auto requiresMemoryBarrier() const { return requiresBarrier_; } |
| 7407 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 7408 |
|
| 7409 |
bool canConsumeFloat32(MUse* use) const override { |
| 7410 |
return use == getUseFor(2) && writeType() == Scalar::Float32; |
| 7411 |
} |
| 7412 |
|
| 7413 |
#ifdef DEBUG |
| 7414 |
// Float16 inputs are typed as float32, but this instruction can NOT consume |
| 7415 |
// float32 when its write-type is float16. |
| 7416 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 7417 |
return use == getUseFor(2) && |
| 7418 |
(writeType() == Scalar::Float32 || writeType() == Scalar::Float16); |
| 7419 |
} |
| 7420 |
#endif |
| 7421 |
|
| 7422 |
ALLOW_CLONE(MStoreUnboxedScalar) |
| 7423 |
}; |
| 7424 |
|
| 7425 |
// Store an unboxed scalar value to a dataview object. |
| 7426 |
class MStoreDataViewElement : public MQuaternaryInstruction, |
| 7427 |
public StoreUnboxedScalarBase, |
| 7428 |
public StoreDataViewElementPolicy::Data { |
| 7429 |
MStoreDataViewElement(MDefinition* elements, MDefinition* index, |
| 7430 |
MDefinition* value, MDefinition* littleEndian, |
| 7431 |
Scalar::Type storageType) |
| 7432 |
: MQuaternaryInstruction(classOpcode, elements, index, value, |
| 7433 |
littleEndian), |
| 7434 |
StoreUnboxedScalarBase(storageType) { |
| 7435 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7436 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7437 |
MOZ_ASSERT(storageType >= 0 && storageType < Scalar::MaxTypedArrayViewType); |
| 7438 |
MOZ_ASSERT(Scalar::byteSize(storageType) > 1); |
| 7439 |
} |
| 7440 |
|
| 7441 |
public: |
| 7442 |
INSTRUCTION_HEADER(StoreDataViewElement) |
| 7443 |
TRIVIAL_NEW_WRAPPERS |
| 7444 |
NAMED_OPERANDS((0, elements), (1, index), (2, value), (3, littleEndian)) |
| 7445 |
|
| 7446 |
AliasSet getAliasSet() const override { |
| 7447 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 7448 |
} |
| 7449 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 7450 |
|
| 7451 |
bool canConsumeFloat32(MUse* use) const override { |
| 7452 |
return use == getUseFor(2) && writeType() == Scalar::Float32; |
| 7453 |
} |
| 7454 |
|
| 7455 |
#ifdef DEBUG |
| 7456 |
// Float16 inputs are typed as float32, but this instruction can NOT consume |
| 7457 |
// float32 when its write-type is float16. |
| 7458 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 7459 |
return use == getUseFor(2) && |
| 7460 |
(writeType() == Scalar::Float32 || writeType() == Scalar::Float16); |
| 7461 |
} |
| 7462 |
#endif |
| 7463 |
|
| 7464 |
ALLOW_CLONE(MStoreDataViewElement) |
| 7465 |
}; |
| 7466 |
|
| 7467 |
class MStoreTypedArrayElementHole : public MQuaternaryInstruction, |
| 7468 |
public StoreUnboxedScalarBase, |
| 7469 |
public StoreTypedArrayHolePolicy::Data { |
| 7470 |
MStoreTypedArrayElementHole(MDefinition* elements, MDefinition* length, |
| 7471 |
MDefinition* index, MDefinition* value, |
| 7472 |
Scalar::Type arrayType) |
| 7473 |
: MQuaternaryInstruction(classOpcode, elements, length, index, value), |
| 7474 |
StoreUnboxedScalarBase(arrayType) { |
| 7475 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 7476 |
MOZ_ASSERT(length->type() == MIRType::IntPtr); |
| 7477 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 7478 |
MOZ_ASSERT(arrayType >= 0 && arrayType < Scalar::MaxTypedArrayViewType); |
| 7479 |
} |
| 7480 |
|
| 7481 |
public: |
| 7482 |
INSTRUCTION_HEADER(StoreTypedArrayElementHole) |
| 7483 |
TRIVIAL_NEW_WRAPPERS |
| 7484 |
NAMED_OPERANDS((0, elements), (1, length), (2, index), (3, value)) |
| 7485 |
|
| 7486 |
Scalar::Type arrayType() const { return writeType(); } |
| 7487 |
AliasSet getAliasSet() const override { |
| 7488 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 7489 |
} |
| 7490 |
TruncateKind operandTruncateKind(size_t index) const override; |
| 7491 |
|
| 7492 |
bool canConsumeFloat32(MUse* use) const override { |
| 7493 |
return use == getUseFor(3) && arrayType() == Scalar::Float32; |
| 7494 |
} |
| 7495 |
|
| 7496 |
#ifdef DEBUG |
| 7497 |
// Float16 inputs are typed as float32, but this instruction can NOT consume |
| 7498 |
// float32 when its array-type is float16. |
| 7499 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 7500 |
return use == getUseFor(3) && |
| 7501 |
(arrayType() == Scalar::Float32 || arrayType() == Scalar::Float16); |
| 7502 |
} |
| 7503 |
#endif |
| 7504 |
|
| 7505 |
ALLOW_CLONE(MStoreTypedArrayElementHole) |
| 7506 |
}; |
| 7507 |
|
| 7508 |
// Compute an "effective address", i.e., a compound computation of the form: |
| 7509 |
// base + index * scale + displacement |
| 7510 |
class MEffectiveAddress : public MBinaryInstruction, public NoTypePolicy::Data { |
| 7511 |
MEffectiveAddress(MDefinition* base, MDefinition* index, Scale scale, |
| 7512 |
int32_t displacement) |
| 7513 |
: MBinaryInstruction(classOpcode, base, index), |
| 7514 |
scale_(scale), |
| 7515 |
displacement_(displacement) { |
| 7516 |
MOZ_ASSERT(base->type() == MIRType::Int32); |
| 7517 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 7518 |
setMovable(); |
| 7519 |
setResultType(MIRType::Int32); |
| 7520 |
} |
| 7521 |
|
| 7522 |
Scale scale_; |
| 7523 |
int32_t displacement_; |
| 7524 |
|
| 7525 |
public: |
| 7526 |
INSTRUCTION_HEADER(EffectiveAddress) |
| 7527 |
TRIVIAL_NEW_WRAPPERS |
| 7528 |
|
| 7529 |
MDefinition* base() const { return lhs(); } |
| 7530 |
MDefinition* index() const { return rhs(); } |
| 7531 |
Scale scale() const { return scale_; } |
| 7532 |
int32_t displacement() const { return displacement_; } |
| 7533 |
|
| 7534 |
ALLOW_CLONE(MEffectiveAddress) |
| 7535 |
}; |
| 7536 |
|
| 7537 |
// Clamp input to range [0, 255] for Uint8ClampedArray. |
| 7538 |
class MClampToUint8 : public MUnaryInstruction, public ClampPolicy::Data { |
| 7539 |
explicit MClampToUint8(MDefinition* input) |
| 7540 |
: MUnaryInstruction(classOpcode, input) { |
| 7541 |
setResultType(MIRType::Int32); |
| 7542 |
setMovable(); |
| 7543 |
} |
| 7544 |
|
| 7545 |
public: |
| 7546 |
INSTRUCTION_HEADER(ClampToUint8) |
| 7547 |
TRIVIAL_NEW_WRAPPERS |
| 7548 |
|
| 7549 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7550 |
|
| 7551 |
bool congruentTo(const MDefinition* ins) const override { |
| 7552 |
return congruentIfOperandsEqual(ins); |
| 7553 |
} |
| 7554 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 7555 |
void computeRange(TempAllocator& alloc) override; |
| 7556 |
|
| 7557 |
ALLOW_CLONE(MClampToUint8) |
| 7558 |
}; |
| 7559 |
|
| 7560 |
class MLoadFixedSlot : public MUnaryInstruction, |
| 7561 |
public SingleObjectPolicy::Data { |
| 7562 |
size_t slot_; |
| 7563 |
bool usedAsPropertyKey_ = false; |
| 7564 |
|
| 7565 |
protected: |
| 7566 |
MLoadFixedSlot(MDefinition* obj, size_t slot) |
| 7567 |
: MUnaryInstruction(classOpcode, obj), slot_(slot) { |
| 7568 |
setResultType(MIRType::Value); |
| 7569 |
setMovable(); |
| 7570 |
} |
| 7571 |
|
| 7572 |
public: |
| 7573 |
INSTRUCTION_HEADER(LoadFixedSlot) |
| 7574 |
TRIVIAL_NEW_WRAPPERS |
| 7575 |
NAMED_OPERANDS((0, object)) |
| 7576 |
|
| 7577 |
size_t slot() const { return slot_; } |
| 7578 |
bool congruentTo(const MDefinition* ins) const override { |
| 7579 |
if (!ins->isLoadFixedSlot()) { |
| 7580 |
return false; |
| 7581 |
} |
| 7582 |
if (slot() != ins->toLoadFixedSlot()->slot()) { |
| 7583 |
return false; |
| 7584 |
} |
| 7585 |
return congruentIfOperandsEqual(ins); |
| 7586 |
} |
| 7587 |
|
| 7588 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7589 |
|
| 7590 |
AliasSet getAliasSet() const override { |
| 7591 |
return AliasSet::Load(AliasSet::FixedSlot); |
| 7592 |
} |
| 7593 |
|
| 7594 |
AliasType mightAlias(const MDefinition* store) const override; |
| 7595 |
|
| 7596 |
#ifdef JS_JITSPEW |
| 7597 |
void printOpcode(GenericPrinter& out) const override; |
| 7598 |
#endif |
| 7599 |
|
| 7600 |
void setUsedAsPropertyKey() { usedAsPropertyKey_ = true; } |
| 7601 |
bool usedAsPropertyKey() const { return usedAsPropertyKey_; } |
| 7602 |
|
| 7603 |
ALLOW_CLONE(MLoadFixedSlot) |
| 7604 |
}; |
| 7605 |
|
| 7606 |
class MLoadFixedSlotAndUnbox : public MUnaryInstruction, |
| 7607 |
public SingleObjectPolicy::Data { |
| 7608 |
size_t slot_; |
| 7609 |
MUnbox::Mode mode_; |
| 7610 |
bool usedAsPropertyKey_; |
| 7611 |
|
| 7612 |
MLoadFixedSlotAndUnbox(MDefinition* obj, size_t slot, MUnbox::Mode mode, |
| 7613 |
MIRType type, bool usedAsPropertyKey = false) |
| 7614 |
: MUnaryInstruction(classOpcode, obj), |
| 7615 |
slot_(slot), |
| 7616 |
mode_(mode), |
| 7617 |
usedAsPropertyKey_(usedAsPropertyKey) { |
| 7618 |
setResultType(type); |
| 7619 |
setMovable(); |
| 7620 |
if (mode_ == MUnbox::Fallible) { |
| 7621 |
setGuard(); |
| 7622 |
} |
| 7623 |
} |
| 7624 |
|
| 7625 |
public: |
| 7626 |
INSTRUCTION_HEADER(LoadFixedSlotAndUnbox) |
| 7627 |
TRIVIAL_NEW_WRAPPERS |
| 7628 |
NAMED_OPERANDS((0, object)) |
| 7629 |
|
| 7630 |
size_t slot() const { return slot_; } |
| 7631 |
MUnbox::Mode mode() const { return mode_; } |
| 7632 |
bool fallible() const { return mode_ != MUnbox::Infallible; } |
| 7633 |
bool congruentTo(const MDefinition* ins) const override { |
| 7634 |
if (!ins->isLoadFixedSlotAndUnbox() || |
| 7635 |
slot() != ins->toLoadFixedSlotAndUnbox()->slot() || |
| 7636 |
mode() != ins->toLoadFixedSlotAndUnbox()->mode()) { |
| 7637 |
return false; |
| 7638 |
} |
| 7639 |
return congruentIfOperandsEqual(ins); |
| 7640 |
} |
| 7641 |
|
| 7642 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7643 |
|
| 7644 |
AliasSet getAliasSet() const override { |
| 7645 |
return AliasSet::Load(AliasSet::FixedSlot); |
| 7646 |
} |
| 7647 |
|
| 7648 |
AliasType mightAlias(const MDefinition* store) const override; |
| 7649 |
|
| 7650 |
#ifdef JS_JITSPEW |
| 7651 |
void printOpcode(GenericPrinter& out) const override; |
| 7652 |
#endif |
| 7653 |
|
| 7654 |
bool usedAsPropertyKey() const { return usedAsPropertyKey_; } |
| 7655 |
|
| 7656 |
ALLOW_CLONE(MLoadFixedSlotAndUnbox); |
| 7657 |
}; |
| 7658 |
|
| 7659 |
class MLoadDynamicSlotAndUnbox : public MUnaryInstruction, |
| 7660 |
public NoTypePolicy::Data { |
| 7661 |
size_t slot_; |
| 7662 |
MUnbox::Mode mode_; |
| 7663 |
bool usedAsPropertyKey_ = false; |
| 7664 |
|
| 7665 |
MLoadDynamicSlotAndUnbox(MDefinition* slots, size_t slot, MUnbox::Mode mode, |
| 7666 |
MIRType type, bool usedAsPropertyKey = false) |
| 7667 |
: MUnaryInstruction(classOpcode, slots), |
| 7668 |
slot_(slot), |
| 7669 |
mode_(mode), |
| 7670 |
usedAsPropertyKey_(usedAsPropertyKey) { |
| 7671 |
setResultType(type); |
| 7672 |
setMovable(); |
| 7673 |
if (mode_ == MUnbox::Fallible) { |
| 7674 |
setGuard(); |
| 7675 |
} |
| 7676 |
} |
| 7677 |
|
| 7678 |
public: |
| 7679 |
INSTRUCTION_HEADER(LoadDynamicSlotAndUnbox) |
| 7680 |
TRIVIAL_NEW_WRAPPERS |
| 7681 |
NAMED_OPERANDS((0, slots)) |
| 7682 |
|
| 7683 |
size_t slot() const { return slot_; } |
| 7684 |
MUnbox::Mode mode() const { return mode_; } |
| 7685 |
bool fallible() const { return mode_ != MUnbox::Infallible; } |
| 7686 |
|
| 7687 |
bool congruentTo(const MDefinition* ins) const override { |
| 7688 |
if (!ins->isLoadDynamicSlotAndUnbox() || |
| 7689 |
slot() != ins->toLoadDynamicSlotAndUnbox()->slot() || |
| 7690 |
mode() != ins->toLoadDynamicSlotAndUnbox()->mode()) { |
| 7691 |
return false; |
| 7692 |
} |
| 7693 |
return congruentIfOperandsEqual(ins); |
| 7694 |
} |
| 7695 |
|
| 7696 |
AliasSet getAliasSet() const override { |
| 7697 |
return AliasSet::Load(AliasSet::DynamicSlot); |
| 7698 |
} |
| 7699 |
|
| 7700 |
#ifdef JS_JITSPEW |
| 7701 |
void printOpcode(GenericPrinter& out) const override; |
| 7702 |
#endif |
| 7703 |
|
| 7704 |
bool usedAsPropertyKey() const { return usedAsPropertyKey_; } |
| 7705 |
|
| 7706 |
ALLOW_CLONE(MLoadDynamicSlotAndUnbox); |
| 7707 |
}; |
| 7708 |
|
| 7709 |
class MStoreFixedSlot |
| 7710 |
: public MBinaryInstruction, |
| 7711 |
public MixPolicy<SingleObjectPolicy, NoFloatPolicy<1>>::Data { |
| 7712 |
bool needsBarrier_; |
| 7713 |
size_t slot_; |
| 7714 |
|
| 7715 |
MStoreFixedSlot(MDefinition* obj, MDefinition* rval, size_t slot, |
| 7716 |
bool barrier) |
| 7717 |
: MBinaryInstruction(classOpcode, obj, rval), |
| 7718 |
needsBarrier_(barrier), |
| 7719 |
slot_(slot) {} |
| 7720 |
|
| 7721 |
public: |
| 7722 |
INSTRUCTION_HEADER(StoreFixedSlot) |
| 7723 |
NAMED_OPERANDS((0, object), (1, value)) |
| 7724 |
|
| 7725 |
static MStoreFixedSlot* NewUnbarriered(TempAllocator& alloc, MDefinition* obj, |
| 7726 |
size_t slot, MDefinition* rval) { |
| 7727 |
return new (alloc) MStoreFixedSlot(obj, rval, slot, false); |
| 7728 |
} |
| 7729 |
static MStoreFixedSlot* NewBarriered(TempAllocator& alloc, MDefinition* obj, |
| 7730 |
size_t slot, MDefinition* rval) { |
| 7731 |
return new (alloc) MStoreFixedSlot(obj, rval, slot, true); |
| 7732 |
} |
| 7733 |
|
| 7734 |
size_t slot() const { return slot_; } |
| 7735 |
|
| 7736 |
AliasSet getAliasSet() const override { |
| 7737 |
return AliasSet::Store(AliasSet::FixedSlot); |
| 7738 |
} |
| 7739 |
bool needsBarrier() const { return needsBarrier_; } |
| 7740 |
void setNeedsBarrier(bool needsBarrier = true) { |
| 7741 |
needsBarrier_ = needsBarrier; |
| 7742 |
} |
| 7743 |
|
| 7744 |
#ifdef JS_JITSPEW |
| 7745 |
void printOpcode(GenericPrinter& out) const override; |
| 7746 |
#endif |
| 7747 |
|
| 7748 |
ALLOW_CLONE(MStoreFixedSlot) |
| 7749 |
}; |
| 7750 |
|
| 7751 |
class MGetPropertyCache : public MBinaryInstruction, |
| 7752 |
public MixPolicy<BoxExceptPolicy<0, MIRType::Object>, |
| 7753 |
CacheIdPolicy<1>>::Data { |
| 7754 |
MGetPropertyCache(MDefinition* obj, MDefinition* id) |
| 7755 |
: MBinaryInstruction(classOpcode, obj, id) { |
| 7756 |
setResultType(MIRType::Value); |
| 7757 |
} |
| 7758 |
|
| 7759 |
public: |
| 7760 |
INSTRUCTION_HEADER(GetPropertyCache) |
| 7761 |
TRIVIAL_NEW_WRAPPERS |
| 7762 |
NAMED_OPERANDS((0, value), (1, idval)) |
| 7763 |
}; |
| 7764 |
|
| 7765 |
class MGetPropSuperCache |
| 7766 |
: public MTernaryInstruction, |
| 7767 |
public MixPolicy<ObjectPolicy<0>, BoxExceptPolicy<1, MIRType::Object>, |
| 7768 |
CacheIdPolicy<2>>::Data { |
| 7769 |
MGetPropSuperCache(MDefinition* obj, MDefinition* receiver, MDefinition* id) |
| 7770 |
: MTernaryInstruction(classOpcode, obj, receiver, id) { |
| 7771 |
setResultType(MIRType::Value); |
| 7772 |
setGuard(); |
| 7773 |
} |
| 7774 |
|
| 7775 |
public: |
| 7776 |
INSTRUCTION_HEADER(GetPropSuperCache) |
| 7777 |
TRIVIAL_NEW_WRAPPERS |
| 7778 |
NAMED_OPERANDS((0, object), (1, receiver), (2, idval)) |
| 7779 |
}; |
| 7780 |
|
| 7781 |
// Guard the object's proto is |expected|. |
| 7782 |
class MGuardProto : public MBinaryInstruction, public SingleObjectPolicy::Data { |
| 7783 |
MGuardProto(MDefinition* obj, MDefinition* expected) |
| 7784 |
: MBinaryInstruction(classOpcode, obj, expected) { |
| 7785 |
MOZ_ASSERT(expected->isConstant() || expected->isNurseryObject()); |
| 7786 |
setGuard(); |
| 7787 |
setMovable(); |
| 7788 |
setResultType(MIRType::Object); |
| 7789 |
} |
| 7790 |
|
| 7791 |
public: |
| 7792 |
INSTRUCTION_HEADER(GuardProto) |
| 7793 |
TRIVIAL_NEW_WRAPPERS |
| 7794 |
NAMED_OPERANDS((0, object), (1, expected)) |
| 7795 |
|
| 7796 |
bool congruentTo(const MDefinition* ins) const override { |
| 7797 |
return congruentIfOperandsEqual(ins); |
| 7798 |
} |
| 7799 |
|
| 7800 |
AliasSet getAliasSet() const override { |
| 7801 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 7802 |
} |
| 7803 |
AliasType mightAlias(const MDefinition* def) const override { |
| 7804 |
// These instructions never modify the [[Prototype]]. |
| 7805 |
if (def->isAddAndStoreSlot() || def->isAllocateAndStoreSlot()) { |
| 7806 |
return AliasType::NoAlias; |
| 7807 |
} |
| 7808 |
return AliasType::MayAlias; |
| 7809 |
} |
| 7810 |
}; |
| 7811 |
|
| 7812 |
// Guard the object has no proto. |
| 7813 |
class MGuardNullProto : public MUnaryInstruction, |
| 7814 |
public SingleObjectPolicy::Data { |
| 7815 |
explicit MGuardNullProto(MDefinition* obj) |
| 7816 |
: MUnaryInstruction(classOpcode, obj) { |
| 7817 |
setGuard(); |
| 7818 |
setMovable(); |
| 7819 |
setResultType(MIRType::Object); |
| 7820 |
} |
| 7821 |
|
| 7822 |
public: |
| 7823 |
INSTRUCTION_HEADER(GuardNullProto) |
| 7824 |
TRIVIAL_NEW_WRAPPERS |
| 7825 |
NAMED_OPERANDS((0, object)) |
| 7826 |
|
| 7827 |
bool congruentTo(const MDefinition* ins) const override { |
| 7828 |
return congruentIfOperandsEqual(ins); |
| 7829 |
} |
| 7830 |
AliasSet getAliasSet() const override { |
| 7831 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 7832 |
} |
| 7833 |
AliasType mightAlias(const MDefinition* def) const override { |
| 7834 |
// These instructions never modify the [[Prototype]]. |
| 7835 |
if (def->isAddAndStoreSlot() || def->isAllocateAndStoreSlot()) { |
| 7836 |
return AliasType::NoAlias; |
| 7837 |
} |
| 7838 |
return AliasType::MayAlias; |
| 7839 |
} |
| 7840 |
}; |
| 7841 |
|
| 7842 |
// Guard on a specific Value. |
| 7843 |
class MGuardValue : public MUnaryInstruction, public BoxInputsPolicy::Data { |
| 7844 |
Value expected_; |
| 7845 |
|
| 7846 |
MGuardValue(MDefinition* val, const Value& expected) |
| 7847 |
: MUnaryInstruction(classOpcode, val), expected_(expected) { |
| 7848 |
setGuard(); |
| 7849 |
setMovable(); |
| 7850 |
setResultType(MIRType::Value); |
| 7851 |
} |
| 7852 |
|
| 7853 |
public: |
| 7854 |
INSTRUCTION_HEADER(GuardValue) |
| 7855 |
TRIVIAL_NEW_WRAPPERS |
| 7856 |
NAMED_OPERANDS((0, value)) |
| 7857 |
|
| 7858 |
Value expected() const { return expected_; } |
| 7859 |
|
| 7860 |
bool congruentTo(const MDefinition* ins) const override { |
| 7861 |
if (!ins->isGuardValue()) { |
| 7862 |
return false; |
| 7863 |
} |
| 7864 |
if (expected() != ins->toGuardValue()->expected()) { |
| 7865 |
return false; |
| 7866 |
} |
| 7867 |
return congruentIfOperandsEqual(ins); |
| 7868 |
} |
| 7869 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7870 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 7871 |
}; |
| 7872 |
|
| 7873 |
// Guard on function flags |
| 7874 |
class MGuardFunctionFlags : public MUnaryInstruction, |
| 7875 |
public SingleObjectPolicy::Data { |
| 7876 |
// At least one of the expected flags must be set, but not necessarily all |
| 7877 |
// expected flags. |
| 7878 |
uint16_t expectedFlags_; |
| 7879 |
|
| 7880 |
// None of the unexpected flags must be set. |
| 7881 |
uint16_t unexpectedFlags_; |
| 7882 |
|
| 7883 |
explicit MGuardFunctionFlags(MDefinition* fun, uint16_t expectedFlags, |
| 7884 |
uint16_t unexpectedFlags) |
| 7885 |
: MUnaryInstruction(classOpcode, fun), |
| 7886 |
expectedFlags_(expectedFlags), |
| 7887 |
unexpectedFlags_(unexpectedFlags) { |
| 7888 |
MOZ_ASSERT((expectedFlags & unexpectedFlags) == 0, |
| 7889 |
"Can't guard inconsistent flags"); |
| 7890 |
MOZ_ASSERT((expectedFlags | unexpectedFlags) != 0, |
| 7891 |
"Can't guard zero flags"); |
| 7892 |
setGuard(); |
| 7893 |
setMovable(); |
| 7894 |
setResultType(MIRType::Object); |
| 7895 |
} |
| 7896 |
|
| 7897 |
public: |
| 7898 |
INSTRUCTION_HEADER(GuardFunctionFlags) |
| 7899 |
TRIVIAL_NEW_WRAPPERS |
| 7900 |
NAMED_OPERANDS((0, function)) |
| 7901 |
|
| 7902 |
uint16_t expectedFlags() const { return expectedFlags_; }; |
| 7903 |
uint16_t unexpectedFlags() const { return unexpectedFlags_; }; |
| 7904 |
|
| 7905 |
bool congruentTo(const MDefinition* ins) const override { |
| 7906 |
if (!ins->isGuardFunctionFlags()) { |
| 7907 |
return false; |
| 7908 |
} |
| 7909 |
if (expectedFlags() != ins->toGuardFunctionFlags()->expectedFlags()) { |
| 7910 |
return false; |
| 7911 |
} |
| 7912 |
if (unexpectedFlags() != ins->toGuardFunctionFlags()->unexpectedFlags()) { |
| 7913 |
return false; |
| 7914 |
} |
| 7915 |
return congruentIfOperandsEqual(ins); |
| 7916 |
} |
| 7917 |
AliasSet getAliasSet() const override { |
| 7918 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 7919 |
} |
| 7920 |
}; |
| 7921 |
|
| 7922 |
// Guard on an object's identity, inclusively or exclusively. |
| 7923 |
class MGuardObjectIdentity : public MBinaryInstruction, |
| 7924 |
public SingleObjectPolicy::Data { |
| 7925 |
bool bailOnEquality_; |
| 7926 |
|
| 7927 |
MGuardObjectIdentity(MDefinition* obj, MDefinition* expected, |
| 7928 |
bool bailOnEquality) |
| 7929 |
: MBinaryInstruction(classOpcode, obj, expected), |
| 7930 |
bailOnEquality_(bailOnEquality) { |
| 7931 |
setGuard(); |
| 7932 |
setMovable(); |
| 7933 |
setResultType(MIRType::Object); |
| 7934 |
} |
| 7935 |
|
| 7936 |
public: |
| 7937 |
INSTRUCTION_HEADER(GuardObjectIdentity) |
| 7938 |
TRIVIAL_NEW_WRAPPERS |
| 7939 |
NAMED_OPERANDS((0, object), (1, expected)) |
| 7940 |
|
| 7941 |
bool bailOnEquality() const { return bailOnEquality_; } |
| 7942 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7943 |
bool congruentTo(const MDefinition* ins) const override { |
| 7944 |
if (!ins->isGuardObjectIdentity()) { |
| 7945 |
return false; |
| 7946 |
} |
| 7947 |
if (bailOnEquality() != ins->toGuardObjectIdentity()->bailOnEquality()) { |
| 7948 |
return false; |
| 7949 |
} |
| 7950 |
return congruentIfOperandsEqual(ins); |
| 7951 |
} |
| 7952 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 7953 |
}; |
| 7954 |
|
| 7955 |
// Guard on a specific JSFunction. Used instead of MGuardObjectIdentity, |
| 7956 |
// so we can store some metadata related to the expected function. |
| 7957 |
class MGuardSpecificFunction : public MBinaryInstruction, |
| 7958 |
public SingleObjectPolicy::Data { |
| 7959 |
uint16_t nargs_; |
| 7960 |
FunctionFlags flags_; |
| 7961 |
|
| 7962 |
MGuardSpecificFunction(MDefinition* obj, MDefinition* expected, |
| 7963 |
uint16_t nargs, FunctionFlags flags) |
| 7964 |
: MBinaryInstruction(classOpcode, obj, expected), |
| 7965 |
nargs_(nargs), |
| 7966 |
flags_(flags) { |
| 7967 |
MOZ_ASSERT(expected->isConstant() || expected->isNurseryObject()); |
| 7968 |
setGuard(); |
| 7969 |
setMovable(); |
| 7970 |
setResultType(MIRType::Object); |
| 7971 |
} |
| 7972 |
|
| 7973 |
public: |
| 7974 |
INSTRUCTION_HEADER(GuardSpecificFunction) |
| 7975 |
TRIVIAL_NEW_WRAPPERS |
| 7976 |
NAMED_OPERANDS((0, function), (1, expected)) |
| 7977 |
|
| 7978 |
uint16_t nargs() const { return nargs_; } |
| 7979 |
FunctionFlags flags() const { return flags_; } |
| 7980 |
|
| 7981 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 7982 |
bool congruentTo(const MDefinition* ins) const override { |
| 7983 |
if (!ins->isGuardSpecificFunction()) { |
| 7984 |
return false; |
| 7985 |
} |
| 7986 |
|
| 7987 |
auto* other = ins->toGuardSpecificFunction(); |
| 7988 |
if (nargs() != other->nargs() || |
| 7989 |
flags().toRaw() != other->flags().toRaw()) { |
| 7990 |
return false; |
| 7991 |
} |
| 7992 |
return congruentIfOperandsEqual(other); |
| 7993 |
} |
| 7994 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 7995 |
}; |
| 7996 |
|
| 7997 |
class MGuardSpecificSymbol : public MUnaryInstruction, |
| 7998 |
public SymbolPolicy<0>::Data { |
| 7999 |
CompilerGCPointer<JS::Symbol*> expected_; |
| 8000 |
|
| 8001 |
MGuardSpecificSymbol(MDefinition* symbol, JS::Symbol* expected) |
| 8002 |
: MUnaryInstruction(classOpcode, symbol), expected_(expected) { |
| 8003 |
setGuard(); |
| 8004 |
setMovable(); |
| 8005 |
setResultType(MIRType::Symbol); |
| 8006 |
} |
| 8007 |
|
| 8008 |
public: |
| 8009 |
INSTRUCTION_HEADER(GuardSpecificSymbol) |
| 8010 |
TRIVIAL_NEW_WRAPPERS |
| 8011 |
NAMED_OPERANDS((0, symbol)) |
| 8012 |
|
| 8013 |
JS::Symbol* expected() const { return expected_; } |
| 8014 |
|
| 8015 |
bool congruentTo(const MDefinition* ins) const override { |
| 8016 |
if (!ins->isGuardSpecificSymbol()) { |
| 8017 |
return false; |
| 8018 |
} |
| 8019 |
if (expected() != ins->toGuardSpecificSymbol()->expected()) { |
| 8020 |
return false; |
| 8021 |
} |
| 8022 |
return congruentIfOperandsEqual(ins); |
| 8023 |
} |
| 8024 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 8025 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8026 |
}; |
| 8027 |
|
| 8028 |
class MGuardTagNotEqual |
| 8029 |
: public MBinaryInstruction, |
| 8030 |
public MixPolicy<UnboxedInt32Policy<0>, UnboxedInt32Policy<1>>::Data { |
| 8031 |
MGuardTagNotEqual(MDefinition* left, MDefinition* right) |
| 8032 |
: MBinaryInstruction(classOpcode, left, right) { |
| 8033 |
setGuard(); |
| 8034 |
setMovable(); |
| 8035 |
setCommutative(); |
| 8036 |
} |
| 8037 |
|
| 8038 |
public: |
| 8039 |
INSTRUCTION_HEADER(GuardTagNotEqual) |
| 8040 |
TRIVIAL_NEW_WRAPPERS |
| 8041 |
|
| 8042 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8043 |
|
| 8044 |
bool congruentTo(const MDefinition* ins) const override { |
| 8045 |
return binaryCongruentTo(ins); |
| 8046 |
} |
| 8047 |
}; |
| 8048 |
|
| 8049 |
// Load from vp[slot] (slots that are not inline in an object). |
| 8050 |
class MLoadDynamicSlot : public MUnaryInstruction, public NoTypePolicy::Data { |
| 8051 |
uint32_t slot_; |
| 8052 |
bool usedAsPropertyKey_ = false; |
| 8053 |
|
| 8054 |
MLoadDynamicSlot(MDefinition* slots, uint32_t slot) |
| 8055 |
: MUnaryInstruction(classOpcode, slots), slot_(slot) { |
| 8056 |
setResultType(MIRType::Value); |
| 8057 |
setMovable(); |
| 8058 |
MOZ_ASSERT(slots->type() == MIRType::Slots); |
| 8059 |
} |
| 8060 |
|
| 8061 |
public: |
| 8062 |
INSTRUCTION_HEADER(LoadDynamicSlot) |
| 8063 |
TRIVIAL_NEW_WRAPPERS |
| 8064 |
NAMED_OPERANDS((0, slots)) |
| 8065 |
|
| 8066 |
uint32_t slot() const { return slot_; } |
| 8067 |
|
| 8068 |
HashNumber valueHash() const override; |
| 8069 |
bool congruentTo(const MDefinition* ins) const override { |
| 8070 |
if (!ins->isLoadDynamicSlot()) { |
| 8071 |
return false; |
| 8072 |
} |
| 8073 |
if (slot() != ins->toLoadDynamicSlot()->slot()) { |
| 8074 |
return false; |
| 8075 |
} |
| 8076 |
return congruentIfOperandsEqual(ins); |
| 8077 |
} |
| 8078 |
|
| 8079 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 8080 |
|
| 8081 |
AliasSet getAliasSet() const override { |
| 8082 |
MOZ_ASSERT(slots()->type() == MIRType::Slots); |
| 8083 |
return AliasSet::Load(AliasSet::DynamicSlot); |
| 8084 |
} |
| 8085 |
AliasType mightAlias(const MDefinition* store) const override; |
| 8086 |
|
| 8087 |
#ifdef JS_JITSPEW |
| 8088 |
void printOpcode(GenericPrinter& out) const override; |
| 8089 |
#endif |
| 8090 |
|
| 8091 |
void setUsedAsPropertyKey() { usedAsPropertyKey_ = true; } |
| 8092 |
bool usedAsPropertyKey() const { return usedAsPropertyKey_; } |
| 8093 |
|
| 8094 |
ALLOW_CLONE(MLoadDynamicSlot) |
| 8095 |
}; |
| 8096 |
|
| 8097 |
class MAddAndStoreSlot |
| 8098 |
: public MBinaryInstruction, |
| 8099 |
public MixPolicy<SingleObjectPolicy, BoxPolicy<1>>::Data { |
| 8100 |
public: |
| 8101 |
enum class Kind { |
| 8102 |
FixedSlot, |
| 8103 |
DynamicSlot, |
| 8104 |
}; |
| 8105 |
|
| 8106 |
private: |
| 8107 |
Kind kind_; |
| 8108 |
uint32_t slotOffset_; |
| 8109 |
CompilerShape shape_; |
| 8110 |
|
| 8111 |
MAddAndStoreSlot(MDefinition* obj, MDefinition* value, Kind kind, |
| 8112 |
uint32_t slotOffset, Shape* shape) |
| 8113 |
: MBinaryInstruction(classOpcode, obj, value), |
| 8114 |
kind_(kind), |
| 8115 |
slotOffset_(slotOffset), |
| 8116 |
shape_(shape) {} |
| 8117 |
|
| 8118 |
public: |
| 8119 |
INSTRUCTION_HEADER(AddAndStoreSlot) |
| 8120 |
TRIVIAL_NEW_WRAPPERS |
| 8121 |
NAMED_OPERANDS((0, object), (1, value)) |
| 8122 |
|
| 8123 |
Kind kind() const { return kind_; } |
| 8124 |
uint32_t slotOffset() const { return slotOffset_; } |
| 8125 |
Shape* shape() const { return shape_; } |
| 8126 |
|
| 8127 |
AliasSet getAliasSet() const override { |
| 8128 |
return AliasSet::Store(AliasSet::ObjectFields | |
| 8129 |
(kind() == Kind::FixedSlot ? AliasSet::FixedSlot |
| 8130 |
: AliasSet::DynamicSlot)); |
| 8131 |
} |
| 8132 |
}; |
| 8133 |
|
| 8134 |
// Store to vp[slot] (slots that are not inline in an object). |
| 8135 |
class MStoreDynamicSlot : public MBinaryInstruction, |
| 8136 |
public NoFloatPolicy<1>::Data { |
| 8137 |
uint32_t slot_; |
| 8138 |
bool needsBarrier_; |
| 8139 |
|
| 8140 |
MStoreDynamicSlot(MDefinition* slots, uint32_t slot, MDefinition* value, |
| 8141 |
bool barrier) |
| 8142 |
: MBinaryInstruction(classOpcode, slots, value), |
| 8143 |
slot_(slot), |
| 8144 |
needsBarrier_(barrier) { |
| 8145 |
MOZ_ASSERT(slots->type() == MIRType::Slots); |
| 8146 |
} |
| 8147 |
|
| 8148 |
public: |
| 8149 |
INSTRUCTION_HEADER(StoreDynamicSlot) |
| 8150 |
NAMED_OPERANDS((0, slots), (1, value)) |
| 8151 |
|
| 8152 |
static MStoreDynamicSlot* NewUnbarriered(TempAllocator& alloc, |
| 8153 |
MDefinition* slots, uint32_t slot, |
| 8154 |
MDefinition* value) { |
| 8155 |
return new (alloc) MStoreDynamicSlot(slots, slot, value, false); |
| 8156 |
} |
| 8157 |
static MStoreDynamicSlot* NewBarriered(TempAllocator& alloc, |
| 8158 |
MDefinition* slots, uint32_t slot, |
| 8159 |
MDefinition* value) { |
| 8160 |
return new (alloc) MStoreDynamicSlot(slots, slot, value, true); |
| 8161 |
} |
| 8162 |
|
| 8163 |
uint32_t slot() const { return slot_; } |
| 8164 |
bool needsBarrier() const { return needsBarrier_; } |
| 8165 |
AliasSet getAliasSet() const override { |
| 8166 |
return AliasSet::Store(AliasSet::DynamicSlot); |
| 8167 |
} |
| 8168 |
|
| 8169 |
#ifdef JS_JITSPEW |
| 8170 |
void printOpcode(GenericPrinter& out) const override; |
| 8171 |
#endif |
| 8172 |
|
| 8173 |
ALLOW_CLONE(MStoreDynamicSlot) |
| 8174 |
}; |
| 8175 |
|
| 8176 |
class MSetPropertyCache : public MTernaryInstruction, |
| 8177 |
public MixPolicy<SingleObjectPolicy, CacheIdPolicy<1>, |
| 8178 |
NoFloatPolicy<2>>::Data { |
| 8179 |
bool strict_ : 1; |
| 8180 |
|
| 8181 |
MSetPropertyCache(MDefinition* obj, MDefinition* id, MDefinition* value, |
| 8182 |
bool strict) |
| 8183 |
: MTernaryInstruction(classOpcode, obj, id, value), strict_(strict) {} |
| 8184 |
|
| 8185 |
public: |
| 8186 |
INSTRUCTION_HEADER(SetPropertyCache) |
| 8187 |
TRIVIAL_NEW_WRAPPERS |
| 8188 |
NAMED_OPERANDS((0, object), (1, idval), (2, value)) |
| 8189 |
|
| 8190 |
bool strict() const { return strict_; } |
| 8191 |
}; |
| 8192 |
|
| 8193 |
class MMegamorphicSetElement : public MTernaryInstruction, |
| 8194 |
public MegamorphicSetElementPolicy::Data { |
| 8195 |
bool strict_; |
| 8196 |
|
| 8197 |
MMegamorphicSetElement(MDefinition* object, MDefinition* index, |
| 8198 |
MDefinition* value, bool strict) |
| 8199 |
: MTernaryInstruction(classOpcode, object, index, value), |
| 8200 |
strict_(strict) {} |
| 8201 |
|
| 8202 |
public: |
| 8203 |
INSTRUCTION_HEADER(MegamorphicSetElement) |
| 8204 |
TRIVIAL_NEW_WRAPPERS |
| 8205 |
NAMED_OPERANDS((0, object), (1, index), (2, value)) |
| 8206 |
|
| 8207 |
bool strict() const { return strict_; } |
| 8208 |
|
| 8209 |
bool possiblyCalls() const override { return true; } |
| 8210 |
}; |
| 8211 |
|
| 8212 |
class MSetDOMProperty : public MBinaryInstruction, |
| 8213 |
public MixPolicy<ObjectPolicy<0>, BoxPolicy<1>>::Data { |
| 8214 |
const JSJitSetterOp func_; |
| 8215 |
Realm* setterRealm_; |
| 8216 |
DOMObjectKind objectKind_; |
| 8217 |
|
| 8218 |
MSetDOMProperty(const JSJitSetterOp func, DOMObjectKind objectKind, |
| 8219 |
Realm* setterRealm, MDefinition* obj, MDefinition* val) |
| 8220 |
: MBinaryInstruction(classOpcode, obj, val), |
| 8221 |
func_(func), |
| 8222 |
setterRealm_(setterRealm), |
| 8223 |
objectKind_(objectKind) {} |
| 8224 |
|
| 8225 |
public: |
| 8226 |
INSTRUCTION_HEADER(SetDOMProperty) |
| 8227 |
TRIVIAL_NEW_WRAPPERS |
| 8228 |
NAMED_OPERANDS((0, object), (1, value)) |
| 8229 |
|
| 8230 |
JSJitSetterOp fun() const { return func_; } |
| 8231 |
Realm* setterRealm() const { return setterRealm_; } |
| 8232 |
DOMObjectKind objectKind() const { return objectKind_; } |
| 8233 |
|
| 8234 |
bool possiblyCalls() const override { return true; } |
| 8235 |
}; |
| 8236 |
|
| 8237 |
class MGetDOMPropertyBase : public MVariadicInstruction, |
| 8238 |
public ObjectPolicy<0>::Data { |
| 8239 |
const JSJitInfo* info_; |
| 8240 |
|
| 8241 |
protected: |
| 8242 |
MGetDOMPropertyBase(Opcode op, const JSJitInfo* jitinfo) |
| 8243 |
: MVariadicInstruction(op), info_(jitinfo) { |
| 8244 |
MOZ_ASSERT(jitinfo); |
| 8245 |
MOZ_ASSERT(jitinfo->type() == JSJitInfo::Getter); |
| 8246 |
|
| 8247 |
// We are movable iff the jitinfo says we can be. |
| 8248 |
if (isDomMovable()) { |
| 8249 |
MOZ_ASSERT(jitinfo->aliasSet() != JSJitInfo::AliasEverything); |
| 8250 |
setMovable(); |
| 8251 |
} else { |
| 8252 |
// If we're not movable, that means we shouldn't be DCEd either, |
| 8253 |
// because we might throw an exception when called, and getting rid |
| 8254 |
// of that is observable. |
| 8255 |
setGuard(); |
| 8256 |
} |
| 8257 |
|
| 8258 |
setResultType(MIRType::Value); |
| 8259 |
} |
| 8260 |
|
| 8261 |
const JSJitInfo* info() const { return info_; } |
| 8262 |
|
| 8263 |
[[nodiscard]] bool init(TempAllocator& alloc, MDefinition* obj, |
| 8264 |
MDefinition* guard, MDefinition* globalGuard) { |
| 8265 |
MOZ_ASSERT(obj); |
| 8266 |
// guard can be null. |
| 8267 |
// globalGuard can be null. |
| 8268 |
size_t operandCount = 1; |
| 8269 |
if (guard) { |
| 8270 |
++operandCount; |
| 8271 |
} |
| 8272 |
if (globalGuard) { |
| 8273 |
++operandCount; |
| 8274 |
} |
| 8275 |
if (!MVariadicInstruction::init(alloc, operandCount)) { |
| 8276 |
return false; |
| 8277 |
} |
| 8278 |
initOperand(0, obj); |
| 8279 |
|
| 8280 |
size_t operandIndex = 1; |
| 8281 |
// Pin the guard, if we have one as an operand if we want to hoist later. |
| 8282 |
if (guard) { |
| 8283 |
initOperand(operandIndex++, guard); |
| 8284 |
} |
| 8285 |
|
| 8286 |
// And the same for the global guard, if we have one. |
| 8287 |
if (globalGuard) { |
| 8288 |
initOperand(operandIndex, globalGuard); |
| 8289 |
} |
| 8290 |
|
| 8291 |
return true; |
| 8292 |
} |
| 8293 |
|
| 8294 |
public: |
| 8295 |
NAMED_OPERANDS((0, object)) |
| 8296 |
|
| 8297 |
JSJitGetterOp fun() const { return info_->getter; } |
| 8298 |
bool isInfallible() const { return info_->isInfallible; } |
| 8299 |
bool isDomMovable() const { return info_->isMovable; } |
| 8300 |
JSJitInfo::AliasSet domAliasSet() const { return info_->aliasSet(); } |
| 8301 |
size_t domMemberSlotIndex() const { |
| 8302 |
MOZ_ASSERT(info_->isAlwaysInSlot || info_->isLazilyCachedInSlot); |
| 8303 |
return info_->slotIndex; |
| 8304 |
} |
| 8305 |
bool valueMayBeInSlot() const { return info_->isLazilyCachedInSlot; } |
| 8306 |
|
| 8307 |
bool baseCongruentTo(const MGetDOMPropertyBase* ins) const { |
| 8308 |
if (!isDomMovable()) { |
| 8309 |
return false; |
| 8310 |
} |
| 8311 |
|
| 8312 |
// Checking the jitinfo is the same as checking the constant function |
| 8313 |
if (!(info() == ins->info())) { |
| 8314 |
return false; |
| 8315 |
} |
| 8316 |
|
| 8317 |
return congruentIfOperandsEqual(ins); |
| 8318 |
} |
| 8319 |
|
| 8320 |
AliasSet getAliasSet() const override { |
| 8321 |
JSJitInfo::AliasSet aliasSet = domAliasSet(); |
| 8322 |
if (aliasSet == JSJitInfo::AliasNone) { |
| 8323 |
return AliasSet::None(); |
| 8324 |
} |
| 8325 |
if (aliasSet == JSJitInfo::AliasDOMSets) { |
| 8326 |
return AliasSet::Load(AliasSet::DOMProperty); |
| 8327 |
} |
| 8328 |
MOZ_ASSERT(aliasSet == JSJitInfo::AliasEverything); |
| 8329 |
return AliasSet::Store(AliasSet::Any); |
| 8330 |
} |
| 8331 |
}; |
| 8332 |
|
| 8333 |
class MGetDOMProperty : public MGetDOMPropertyBase { |
| 8334 |
Realm* getterRealm_; |
| 8335 |
DOMObjectKind objectKind_; |
| 8336 |
|
| 8337 |
MGetDOMProperty(const JSJitInfo* jitinfo, DOMObjectKind objectKind, |
| 8338 |
Realm* getterRealm) |
| 8339 |
: MGetDOMPropertyBase(classOpcode, jitinfo), |
| 8340 |
getterRealm_(getterRealm), |
| 8341 |
objectKind_(objectKind) {} |
| 8342 |
|
| 8343 |
public: |
| 8344 |
INSTRUCTION_HEADER(GetDOMProperty) |
| 8345 |
|
| 8346 |
static MGetDOMProperty* New(TempAllocator& alloc, const JSJitInfo* info, |
| 8347 |
DOMObjectKind objectKind, Realm* getterRealm, |
| 8348 |
MDefinition* obj, MDefinition* guard, |
| 8349 |
MDefinition* globalGuard) { |
| 8350 |
auto* res = new (alloc) MGetDOMProperty(info, objectKind, getterRealm); |
| 8351 |
if (!res || !res->init(alloc, obj, guard, globalGuard)) { |
| 8352 |
return nullptr; |
| 8353 |
} |
| 8354 |
return res; |
| 8355 |
} |
| 8356 |
|
| 8357 |
Realm* getterRealm() const { return getterRealm_; } |
| 8358 |
DOMObjectKind objectKind() const { return objectKind_; } |
| 8359 |
|
| 8360 |
bool congruentTo(const MDefinition* ins) const override { |
| 8361 |
if (!ins->isGetDOMProperty()) { |
| 8362 |
return false; |
| 8363 |
} |
| 8364 |
|
| 8365 |
if (ins->toGetDOMProperty()->getterRealm() != getterRealm()) { |
| 8366 |
return false; |
| 8367 |
} |
| 8368 |
|
| 8369 |
return baseCongruentTo(ins->toGetDOMProperty()); |
| 8370 |
} |
| 8371 |
|
| 8372 |
bool possiblyCalls() const override { return true; } |
| 8373 |
}; |
| 8374 |
|
| 8375 |
class MGetDOMMember : public MGetDOMPropertyBase { |
| 8376 |
explicit MGetDOMMember(const JSJitInfo* jitinfo) |
| 8377 |
: MGetDOMPropertyBase(classOpcode, jitinfo) { |
| 8378 |
setResultType(MIRTypeFromValueType(jitinfo->returnType())); |
| 8379 |
} |
| 8380 |
|
| 8381 |
public: |
| 8382 |
INSTRUCTION_HEADER(GetDOMMember) |
| 8383 |
|
| 8384 |
static MGetDOMMember* New(TempAllocator& alloc, const JSJitInfo* info, |
| 8385 |
MDefinition* obj, MDefinition* guard, |
| 8386 |
MDefinition* globalGuard) { |
| 8387 |
auto* res = new (alloc) MGetDOMMember(info); |
| 8388 |
if (!res || !res->init(alloc, obj, guard, globalGuard)) { |
| 8389 |
return nullptr; |
| 8390 |
} |
| 8391 |
return res; |
| 8392 |
} |
| 8393 |
|
| 8394 |
bool possiblyCalls() const override { return false; } |
| 8395 |
|
| 8396 |
bool congruentTo(const MDefinition* ins) const override { |
| 8397 |
if (!ins->isGetDOMMember()) { |
| 8398 |
return false; |
| 8399 |
} |
| 8400 |
|
| 8401 |
return baseCongruentTo(ins->toGetDOMMember()); |
| 8402 |
} |
| 8403 |
}; |
| 8404 |
|
| 8405 |
class MLoadDOMExpandoValueGuardGeneration : public MUnaryInstruction, |
| 8406 |
public SingleObjectPolicy::Data { |
| 8407 |
JS::ExpandoAndGeneration* expandoAndGeneration_; |
| 8408 |
uint64_t generation_; |
| 8409 |
|
| 8410 |
MLoadDOMExpandoValueGuardGeneration( |
| 8411 |
MDefinition* proxy, JS::ExpandoAndGeneration* expandoAndGeneration, |
| 8412 |
uint64_t generation) |
| 8413 |
: MUnaryInstruction(classOpcode, proxy), |
| 8414 |
expandoAndGeneration_(expandoAndGeneration), |
| 8415 |
generation_(generation) { |
| 8416 |
setGuard(); |
| 8417 |
setMovable(); |
| 8418 |
setResultType(MIRType::Value); |
| 8419 |
} |
| 8420 |
|
| 8421 |
public: |
| 8422 |
INSTRUCTION_HEADER(LoadDOMExpandoValueGuardGeneration) |
| 8423 |
TRIVIAL_NEW_WRAPPERS |
| 8424 |
NAMED_OPERANDS((0, proxy)) |
| 8425 |
|
| 8426 |
JS::ExpandoAndGeneration* expandoAndGeneration() const { |
| 8427 |
return expandoAndGeneration_; |
| 8428 |
} |
| 8429 |
uint64_t generation() const { return generation_; } |
| 8430 |
|
| 8431 |
bool congruentTo(const MDefinition* ins) const override { |
| 8432 |
if (!ins->isLoadDOMExpandoValueGuardGeneration()) { |
| 8433 |
return false; |
| 8434 |
} |
| 8435 |
const auto* other = ins->toLoadDOMExpandoValueGuardGeneration(); |
| 8436 |
if (expandoAndGeneration() != other->expandoAndGeneration() || |
| 8437 |
generation() != other->generation()) { |
| 8438 |
return false; |
| 8439 |
} |
| 8440 |
return congruentIfOperandsEqual(ins); |
| 8441 |
} |
| 8442 |
AliasSet getAliasSet() const override { |
| 8443 |
return AliasSet::Load(AliasSet::DOMProxyExpando); |
| 8444 |
} |
| 8445 |
}; |
| 8446 |
|
| 8447 |
// Inlined assembly for Math.floor(double | float32) -> int32. |
| 8448 |
class MFloor : public MUnaryInstruction, public FloatingPointPolicy<0>::Data { |
| 8449 |
explicit MFloor(MDefinition* num) : MUnaryInstruction(classOpcode, num) { |
| 8450 |
setResultType(MIRType::Int32); |
| 8451 |
specialization_ = MIRType::Double; |
| 8452 |
setMovable(); |
| 8453 |
} |
| 8454 |
|
| 8455 |
public: |
| 8456 |
INSTRUCTION_HEADER(Floor) |
| 8457 |
TRIVIAL_NEW_WRAPPERS |
| 8458 |
|
| 8459 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8460 |
bool isFloat32Commutative() const override { return true; } |
| 8461 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 8462 |
#ifdef DEBUG |
| 8463 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 8464 |
#endif |
| 8465 |
bool congruentTo(const MDefinition* ins) const override { |
| 8466 |
return congruentIfOperandsEqual(ins); |
| 8467 |
} |
| 8468 |
void computeRange(TempAllocator& alloc) override; |
| 8469 |
[[nodiscard]] bool writeRecoverData( |
| 8470 |
CompactBufferWriter& writer) const override; |
| 8471 |
bool canRecoverOnBailout() const override { return true; } |
| 8472 |
|
| 8473 |
ALLOW_CLONE(MFloor) |
| 8474 |
}; |
| 8475 |
|
| 8476 |
// Inlined assembly version for Math.ceil(double | float32) -> int32. |
| 8477 |
class MCeil : public MUnaryInstruction, public FloatingPointPolicy<0>::Data { |
| 8478 |
explicit MCeil(MDefinition* num) : MUnaryInstruction(classOpcode, num) { |
| 8479 |
setResultType(MIRType::Int32); |
| 8480 |
specialization_ = MIRType::Double; |
| 8481 |
setMovable(); |
| 8482 |
} |
| 8483 |
|
| 8484 |
public: |
| 8485 |
INSTRUCTION_HEADER(Ceil) |
| 8486 |
TRIVIAL_NEW_WRAPPERS |
| 8487 |
|
| 8488 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8489 |
bool isFloat32Commutative() const override { return true; } |
| 8490 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 8491 |
#ifdef DEBUG |
| 8492 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 8493 |
#endif |
| 8494 |
bool congruentTo(const MDefinition* ins) const override { |
| 8495 |
return congruentIfOperandsEqual(ins); |
| 8496 |
} |
| 8497 |
void computeRange(TempAllocator& alloc) override; |
| 8498 |
[[nodiscard]] bool writeRecoverData( |
| 8499 |
CompactBufferWriter& writer) const override; |
| 8500 |
bool canRecoverOnBailout() const override { return true; } |
| 8501 |
|
| 8502 |
ALLOW_CLONE(MCeil) |
| 8503 |
}; |
| 8504 |
|
| 8505 |
// Inlined version of Math.round(double | float32) -> int32. |
| 8506 |
class MRound : public MUnaryInstruction, public FloatingPointPolicy<0>::Data { |
| 8507 |
explicit MRound(MDefinition* num) : MUnaryInstruction(classOpcode, num) { |
| 8508 |
setResultType(MIRType::Int32); |
| 8509 |
specialization_ = MIRType::Double; |
| 8510 |
setMovable(); |
| 8511 |
} |
| 8512 |
|
| 8513 |
public: |
| 8514 |
INSTRUCTION_HEADER(Round) |
| 8515 |
TRIVIAL_NEW_WRAPPERS |
| 8516 |
|
| 8517 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8518 |
|
| 8519 |
bool isFloat32Commutative() const override { return true; } |
| 8520 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 8521 |
#ifdef DEBUG |
| 8522 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 8523 |
#endif |
| 8524 |
bool congruentTo(const MDefinition* ins) const override { |
| 8525 |
return congruentIfOperandsEqual(ins); |
| 8526 |
} |
| 8527 |
|
| 8528 |
[[nodiscard]] bool writeRecoverData( |
| 8529 |
CompactBufferWriter& writer) const override; |
| 8530 |
bool canRecoverOnBailout() const override { return true; } |
| 8531 |
|
| 8532 |
ALLOW_CLONE(MRound) |
| 8533 |
}; |
| 8534 |
|
| 8535 |
// Inlined version of Math.trunc(double | float32) -> int32. |
| 8536 |
class MTrunc : public MUnaryInstruction, public FloatingPointPolicy<0>::Data { |
| 8537 |
explicit MTrunc(MDefinition* num) : MUnaryInstruction(classOpcode, num) { |
| 8538 |
setResultType(MIRType::Int32); |
| 8539 |
specialization_ = MIRType::Double; |
| 8540 |
setMovable(); |
| 8541 |
} |
| 8542 |
|
| 8543 |
public: |
| 8544 |
INSTRUCTION_HEADER(Trunc) |
| 8545 |
TRIVIAL_NEW_WRAPPERS |
| 8546 |
|
| 8547 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8548 |
|
| 8549 |
bool isFloat32Commutative() const override { return true; } |
| 8550 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 8551 |
#ifdef DEBUG |
| 8552 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 8553 |
#endif |
| 8554 |
bool congruentTo(const MDefinition* ins) const override { |
| 8555 |
return congruentIfOperandsEqual(ins); |
| 8556 |
} |
| 8557 |
|
| 8558 |
[[nodiscard]] bool writeRecoverData( |
| 8559 |
CompactBufferWriter& writer) const override; |
| 8560 |
bool canRecoverOnBailout() const override { return true; } |
| 8561 |
|
| 8562 |
ALLOW_CLONE(MTrunc) |
| 8563 |
}; |
| 8564 |
|
| 8565 |
// NearbyInt rounds the floating-point input to the nearest integer, according |
| 8566 |
// to the RoundingMode. |
| 8567 |
class MNearbyInt : public MUnaryInstruction, |
| 8568 |
public FloatingPointPolicy<0>::Data { |
| 8569 |
RoundingMode roundingMode_; |
| 8570 |
|
| 8571 |
explicit MNearbyInt(MDefinition* num, MIRType resultType, |
| 8572 |
RoundingMode roundingMode) |
| 8573 |
: MUnaryInstruction(classOpcode, num), roundingMode_(roundingMode) { |
| 8574 |
MOZ_ASSERT(HasAssemblerSupport(roundingMode)); |
| 8575 |
|
| 8576 |
MOZ_ASSERT(IsFloatingPointType(resultType)); |
| 8577 |
setResultType(resultType); |
| 8578 |
specialization_ = resultType; |
| 8579 |
|
| 8580 |
setMovable(); |
| 8581 |
} |
| 8582 |
|
| 8583 |
public: |
| 8584 |
INSTRUCTION_HEADER(NearbyInt) |
| 8585 |
TRIVIAL_NEW_WRAPPERS |
| 8586 |
|
| 8587 |
static bool HasAssemblerSupport(RoundingMode mode) { |
| 8588 |
return Assembler::HasRoundInstruction(mode); |
| 8589 |
} |
| 8590 |
|
| 8591 |
RoundingMode roundingMode() const { return roundingMode_; } |
| 8592 |
|
| 8593 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8594 |
|
| 8595 |
bool isFloat32Commutative() const override { return true; } |
| 8596 |
void trySpecializeFloat32(TempAllocator& alloc) override; |
| 8597 |
#ifdef DEBUG |
| 8598 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 8599 |
#endif |
| 8600 |
|
| 8601 |
bool congruentTo(const MDefinition* ins) const override { |
| 8602 |
return congruentIfOperandsEqual(ins) && |
| 8603 |
ins->toNearbyInt()->roundingMode() == roundingMode_; |
| 8604 |
} |
| 8605 |
|
| 8606 |
#ifdef JS_JITSPEW |
| 8607 |
void printOpcode(GenericPrinter& out) const override; |
| 8608 |
#endif |
| 8609 |
|
| 8610 |
[[nodiscard]] bool writeRecoverData( |
| 8611 |
CompactBufferWriter& writer) const override; |
| 8612 |
|
| 8613 |
bool canRecoverOnBailout() const override { |
| 8614 |
switch (roundingMode_) { |
| 8615 |
case RoundingMode::Up: |
| 8616 |
case RoundingMode::Down: |
| 8617 |
case RoundingMode::TowardsZero: |
| 8618 |
return true; |
| 8619 |
default: |
| 8620 |
return false; |
| 8621 |
} |
| 8622 |
} |
| 8623 |
|
| 8624 |
ALLOW_CLONE(MNearbyInt) |
| 8625 |
}; |
| 8626 |
|
| 8627 |
class MGetIteratorCache : public MUnaryInstruction, |
| 8628 |
public BoxExceptPolicy<0, MIRType::Object>::Data { |
| 8629 |
explicit MGetIteratorCache(MDefinition* val) |
| 8630 |
: MUnaryInstruction(classOpcode, val) { |
| 8631 |
setResultType(MIRType::Object); |
| 8632 |
} |
| 8633 |
|
| 8634 |
public: |
| 8635 |
INSTRUCTION_HEADER(GetIteratorCache) |
| 8636 |
TRIVIAL_NEW_WRAPPERS |
| 8637 |
NAMED_OPERANDS((0, value)) |
| 8638 |
}; |
| 8639 |
|
| 8640 |
// Implementation for 'in' operator using instruction cache |
| 8641 |
class MInCache : public MBinaryInstruction, |
| 8642 |
public MixPolicy<CacheIdPolicy<0>, ObjectPolicy<1>>::Data { |
| 8643 |
MInCache(MDefinition* key, MDefinition* obj) |
| 8644 |
: MBinaryInstruction(classOpcode, key, obj) { |
| 8645 |
setResultType(MIRType::Boolean); |
| 8646 |
} |
| 8647 |
|
| 8648 |
public: |
| 8649 |
INSTRUCTION_HEADER(InCache) |
| 8650 |
TRIVIAL_NEW_WRAPPERS |
| 8651 |
NAMED_OPERANDS((0, key), (1, object)) |
| 8652 |
}; |
| 8653 |
|
| 8654 |
// Test whether the index is in the array bounds or a hole. |
| 8655 |
class MInArray : public MTernaryInstruction, public NoTypePolicy::Data { |
| 8656 |
bool needsNegativeIntCheck_ = true; |
| 8657 |
|
| 8658 |
MInArray(MDefinition* elements, MDefinition* index, MDefinition* initLength) |
| 8659 |
: MTernaryInstruction(classOpcode, elements, index, initLength) { |
| 8660 |
setResultType(MIRType::Boolean); |
| 8661 |
setMovable(); |
| 8662 |
|
| 8663 |
// Set the guard flag to make sure we bail when we see a negative index. |
| 8664 |
// We can clear this flag (and needsNegativeIntCheck_) in |
| 8665 |
// collectRangeInfoPreTrunc. |
| 8666 |
setGuard(); |
| 8667 |
|
| 8668 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 8669 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 8670 |
MOZ_ASSERT(initLength->type() == MIRType::Int32); |
| 8671 |
} |
| 8672 |
|
| 8673 |
public: |
| 8674 |
INSTRUCTION_HEADER(InArray) |
| 8675 |
TRIVIAL_NEW_WRAPPERS |
| 8676 |
NAMED_OPERANDS((0, elements), (1, index), (2, initLength)) |
| 8677 |
|
| 8678 |
bool needsNegativeIntCheck() const { return needsNegativeIntCheck_; } |
| 8679 |
void collectRangeInfoPreTrunc() override; |
| 8680 |
AliasSet getAliasSet() const override { |
| 8681 |
return AliasSet::Load(AliasSet::Element); |
| 8682 |
} |
| 8683 |
bool congruentTo(const MDefinition* ins) const override { |
| 8684 |
if (!ins->isInArray()) { |
| 8685 |
return false; |
| 8686 |
} |
| 8687 |
const MInArray* other = ins->toInArray(); |
| 8688 |
if (needsNegativeIntCheck() != other->needsNegativeIntCheck()) { |
| 8689 |
return false; |
| 8690 |
} |
| 8691 |
return congruentIfOperandsEqual(other); |
| 8692 |
} |
| 8693 |
}; |
| 8694 |
|
| 8695 |
// Bail when the element is a hole. |
| 8696 |
class MGuardElementNotHole : public MBinaryInstruction, |
| 8697 |
public NoTypePolicy::Data { |
| 8698 |
MGuardElementNotHole(MDefinition* elements, MDefinition* index) |
| 8699 |
: MBinaryInstruction(classOpcode, elements, index) { |
| 8700 |
setMovable(); |
| 8701 |
setGuard(); |
| 8702 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 8703 |
MOZ_ASSERT(index->type() == MIRType::Int32); |
| 8704 |
} |
| 8705 |
|
| 8706 |
public: |
| 8707 |
INSTRUCTION_HEADER(GuardElementNotHole) |
| 8708 |
TRIVIAL_NEW_WRAPPERS |
| 8709 |
NAMED_OPERANDS((0, elements), (1, index)) |
| 8710 |
|
| 8711 |
AliasSet getAliasSet() const override { |
| 8712 |
return AliasSet::Load(AliasSet::Element); |
| 8713 |
} |
| 8714 |
bool congruentTo(const MDefinition* ins) const override { |
| 8715 |
return congruentIfOperandsEqual(ins); |
| 8716 |
} |
| 8717 |
}; |
| 8718 |
|
| 8719 |
class MCheckPrivateFieldCache |
| 8720 |
: public MBinaryInstruction, |
| 8721 |
public MixPolicy<BoxExceptPolicy<0, MIRType::Object>, |
| 8722 |
CacheIdPolicy<1>>::Data { |
| 8723 |
MCheckPrivateFieldCache(MDefinition* obj, MDefinition* id) |
| 8724 |
: MBinaryInstruction(classOpcode, obj, id) { |
| 8725 |
setResultType(MIRType::Boolean); |
| 8726 |
} |
| 8727 |
|
| 8728 |
public: |
| 8729 |
INSTRUCTION_HEADER(CheckPrivateFieldCache) |
| 8730 |
TRIVIAL_NEW_WRAPPERS |
| 8731 |
NAMED_OPERANDS((0, value), (1, idval)) |
| 8732 |
}; |
| 8733 |
|
| 8734 |
class MHasOwnCache : public MBinaryInstruction, |
| 8735 |
public MixPolicy<BoxExceptPolicy<0, MIRType::Object>, |
| 8736 |
CacheIdPolicy<1>>::Data { |
| 8737 |
MHasOwnCache(MDefinition* obj, MDefinition* id) |
| 8738 |
: MBinaryInstruction(classOpcode, obj, id) { |
| 8739 |
setResultType(MIRType::Boolean); |
| 8740 |
} |
| 8741 |
|
| 8742 |
public: |
| 8743 |
INSTRUCTION_HEADER(HasOwnCache) |
| 8744 |
TRIVIAL_NEW_WRAPPERS |
| 8745 |
NAMED_OPERANDS((0, value), (1, idval)) |
| 8746 |
}; |
| 8747 |
|
| 8748 |
// Implementation for instanceof operator with specific rhs. |
| 8749 |
class MInstanceOf : public MBinaryInstruction, |
| 8750 |
public MixPolicy<BoxExceptPolicy<0, MIRType::Object>, |
| 8751 |
ObjectPolicy<1>>::Data { |
| 8752 |
MInstanceOf(MDefinition* obj, MDefinition* proto) |
| 8753 |
: MBinaryInstruction(classOpcode, obj, proto) { |
| 8754 |
setResultType(MIRType::Boolean); |
| 8755 |
} |
| 8756 |
|
| 8757 |
public: |
| 8758 |
INSTRUCTION_HEADER(InstanceOf) |
| 8759 |
TRIVIAL_NEW_WRAPPERS |
| 8760 |
}; |
| 8761 |
|
| 8762 |
// Given a value being written to another object, update the generational store |
| 8763 |
// buffer if the value is in the nursery and object is in the tenured heap. |
| 8764 |
class MPostWriteBarrier : public MBinaryInstruction, |
| 8765 |
public ObjectPolicy<0>::Data { |
| 8766 |
MPostWriteBarrier(MDefinition* obj, MDefinition* value) |
| 8767 |
: MBinaryInstruction(classOpcode, obj, value) { |
| 8768 |
setGuard(); |
| 8769 |
} |
| 8770 |
|
| 8771 |
public: |
| 8772 |
INSTRUCTION_HEADER(PostWriteBarrier) |
| 8773 |
TRIVIAL_NEW_WRAPPERS |
| 8774 |
NAMED_OPERANDS((0, object), (1, value)) |
| 8775 |
|
| 8776 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8777 |
|
| 8778 |
#ifdef DEBUG |
| 8779 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 8780 |
// During lowering, values that neither have object nor value MIR type |
| 8781 |
// are ignored, thus Float32 can show up at this point without any issue. |
| 8782 |
return use == getUseFor(1); |
| 8783 |
} |
| 8784 |
#endif |
| 8785 |
|
| 8786 |
ALLOW_CLONE(MPostWriteBarrier) |
| 8787 |
}; |
| 8788 |
|
| 8789 |
// Given a value being written to another object's elements at the specified |
| 8790 |
// index, update the generational store buffer if the value is in the nursery |
| 8791 |
// and object is in the tenured heap. |
| 8792 |
class MPostWriteElementBarrier |
| 8793 |
: public MTernaryInstruction, |
| 8794 |
public MixPolicy<ObjectPolicy<0>, UnboxedInt32Policy<2>>::Data { |
| 8795 |
MPostWriteElementBarrier(MDefinition* obj, MDefinition* value, |
| 8796 |
MDefinition* index) |
| 8797 |
: MTernaryInstruction(classOpcode, obj, value, index) { |
| 8798 |
setGuard(); |
| 8799 |
} |
| 8800 |
|
| 8801 |
public: |
| 8802 |
INSTRUCTION_HEADER(PostWriteElementBarrier) |
| 8803 |
TRIVIAL_NEW_WRAPPERS |
| 8804 |
NAMED_OPERANDS((0, object), (1, value), (2, index)) |
| 8805 |
|
| 8806 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8807 |
|
| 8808 |
#ifdef DEBUG |
| 8809 |
bool isConsistentFloat32Use(MUse* use) const override { |
| 8810 |
// During lowering, values that neither have object nor value MIR type |
| 8811 |
// are ignored, thus Float32 can show up at this point without any issue. |
| 8812 |
return use == getUseFor(1); |
| 8813 |
} |
| 8814 |
#endif |
| 8815 |
|
| 8816 |
ALLOW_CLONE(MPostWriteElementBarrier) |
| 8817 |
}; |
| 8818 |
|
| 8819 |
class MNewCallObject : public MUnaryInstruction, |
| 8820 |
public SingleObjectPolicy::Data { |
| 8821 |
gc::Heap initialHeap_; |
| 8822 |
|
| 8823 |
public: |
| 8824 |
INSTRUCTION_HEADER(NewCallObject) |
| 8825 |
TRIVIAL_NEW_WRAPPERS |
| 8826 |
|
| 8827 |
explicit MNewCallObject(MConstant* templateObj, gc::Heap initialHeap) |
| 8828 |
: MUnaryInstruction(classOpcode, templateObj), initialHeap_(initialHeap) { |
| 8829 |
setResultType(MIRType::Object); |
| 8830 |
} |
| 8831 |
|
| 8832 |
CallObject* templateObject() const { |
| 8833 |
return &getOperand(0)->toConstant()->toObject().as<CallObject>(); |
| 8834 |
} |
| 8835 |
gc::Heap initialHeap() const { return initialHeap_; } |
| 8836 |
|
| 8837 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 8838 |
|
| 8839 |
[[nodiscard]] bool writeRecoverData( |
| 8840 |
CompactBufferWriter& writer) const override; |
| 8841 |
bool canRecoverOnBailout() const override { return true; } |
| 8842 |
}; |
| 8843 |
|
| 8844 |
class MNewStringObject : public MUnaryInstruction, |
| 8845 |
public ConvertToStringPolicy<0>::Data { |
| 8846 |
CompilerObject templateObj_; |
| 8847 |
|
| 8848 |
MNewStringObject(MDefinition* input, JSObject* templateObj) |
| 8849 |
: MUnaryInstruction(classOpcode, input), templateObj_(templateObj) { |
| 8850 |
setResultType(MIRType::Object); |
| 8851 |
} |
| 8852 |
|
| 8853 |
public: |
| 8854 |
INSTRUCTION_HEADER(NewStringObject) |
| 8855 |
TRIVIAL_NEW_WRAPPERS |
| 8856 |
|
| 8857 |
StringObject* templateObj() const; |
| 8858 |
}; |
| 8859 |
|
| 8860 |
// This is an alias for MLoadFixedSlot. |
| 8861 |
class MEnclosingEnvironment : public MLoadFixedSlot { |
| 8862 |
explicit MEnclosingEnvironment(MDefinition* obj) |
| 8863 |
: MLoadFixedSlot(obj, EnvironmentObject::enclosingEnvironmentSlot()) { |
| 8864 |
setResultType(MIRType::Object); |
| 8865 |
} |
| 8866 |
|
| 8867 |
public: |
| 8868 |
static MEnclosingEnvironment* New(TempAllocator& alloc, MDefinition* obj) { |
| 8869 |
return new (alloc) MEnclosingEnvironment(obj); |
| 8870 |
} |
| 8871 |
|
| 8872 |
AliasSet getAliasSet() const override { |
| 8873 |
// EnvironmentObject reserved slots are immutable. |
| 8874 |
return AliasSet::None(); |
| 8875 |
} |
| 8876 |
}; |
| 8877 |
|
| 8878 |
// This is an element of a spaghetti stack which is used to represent the memory |
| 8879 |
// context which has to be restored in case of a bailout. |
| 8880 |
struct MStoreToRecover : public TempObject, |
| 8881 |
public InlineSpaghettiStackNode<MStoreToRecover> { |
| 8882 |
MDefinition* operand; |
| 8883 |
|
| 8884 |
explicit MStoreToRecover(MDefinition* operand) : operand(operand) {} |
| 8885 |
}; |
| 8886 |
|
| 8887 |
using MStoresToRecoverList = InlineSpaghettiStack<MStoreToRecover>; |
| 8888 |
|
| 8889 |
// A resume point contains the information needed to reconstruct the Baseline |
| 8890 |
// Interpreter state from a position in Warp JIT code. A resume point is a |
| 8891 |
// mapping of stack slots to MDefinitions. |
| 8892 |
// |
| 8893 |
// We capture stack state at critical points: |
| 8894 |
// * (1) At the beginning of every basic block. |
| 8895 |
// * (2) After every effectful operation. |
| 8896 |
// |
| 8897 |
// As long as these two properties are maintained, instructions can be moved, |
| 8898 |
// hoisted, or, eliminated without problems, and ops without side effects do not |
| 8899 |
// need to worry about capturing state at precisely the right point in time. |
| 8900 |
// |
| 8901 |
// Effectful instructions, of course, need to capture state after completion, |
| 8902 |
// where the interpreter will not attempt to repeat the operation. For this, |
| 8903 |
// ResumeAfter must be used. The state is attached directly to the effectful |
| 8904 |
// instruction to ensure that no intermediate instructions could be injected |
| 8905 |
// in between by a future analysis pass. |
| 8906 |
// |
| 8907 |
// During LIR construction, if an instruction can bail back to the interpreter, |
| 8908 |
// we create an LSnapshot, which uses the last known resume point to request |
| 8909 |
// register/stack assignments for every live value. |
| 8910 |
class MResumePoint final : public MNode |
| 8911 |
#ifdef DEBUG |
| 8912 |
, |
| 8913 |
public InlineForwardListNode<MResumePoint> |
| 8914 |
#endif |
| 8915 |
{ |
| 8916 |
private: |
| 8917 |
friend class MBasicBlock; |
| 8918 |
friend void AssertBasicGraphCoherency(MIRGraph& graph, bool force); |
| 8919 |
|
| 8920 |
// List of stack slots needed to reconstruct the BaselineFrame. |
| 8921 |
FixedList<MUse> operands_; |
| 8922 |
|
| 8923 |
// List of stores needed to reconstruct the content of objects which are |
| 8924 |
// emulated by EmulateStateOf variants. |
| 8925 |
MStoresToRecoverList stores_; |
| 8926 |
|
| 8927 |
jsbytecode* pc_; |
| 8928 |
MInstruction* instruction_; |
| 8929 |
ResumeMode mode_; |
| 8930 |
bool isDiscarded_ = false; |
| 8931 |
|
| 8932 |
MResumePoint(MBasicBlock* block, jsbytecode* pc, ResumeMode mode); |
| 8933 |
void inherit(MBasicBlock* state); |
| 8934 |
|
| 8935 |
// Calling isDefinition or isResumePoint on MResumePoint is unnecessary. |
| 8936 |
bool isDefinition() const = delete; |
| 8937 |
bool isResumePoint() const = delete; |
| 8938 |
|
| 8939 |
void setBlock(MBasicBlock* block) { |
| 8940 |
setBlockAndKind(block, Kind::ResumePoint); |
| 8941 |
} |
| 8942 |
|
| 8943 |
protected: |
| 8944 |
// Initializes operands_ to an empty array of a fixed length. |
| 8945 |
// The array may then be filled in by inherit(). |
| 8946 |
[[nodiscard]] bool init(TempAllocator& alloc); |
| 8947 |
|
| 8948 |
void clearOperand(size_t index) { |
| 8949 |
// FixedList doesn't initialize its elements, so do an unchecked init. |
| 8950 |
operands_[index].initUncheckedWithoutProducer(this); |
| 8951 |
} |
| 8952 |
|
| 8953 |
MUse* getUseFor(size_t index) override { return &operands_[index]; } |
| 8954 |
const MUse* getUseFor(size_t index) const override { |
| 8955 |
return &operands_[index]; |
| 8956 |
} |
| 8957 |
|
| 8958 |
public: |
| 8959 |
static MResumePoint* New(TempAllocator& alloc, MBasicBlock* block, |
| 8960 |
jsbytecode* pc, ResumeMode mode); |
| 8961 |
|
| 8962 |
MBasicBlock* block() const { return resumePointBlock(); } |
| 8963 |
|
| 8964 |
size_t numAllocatedOperands() const { return operands_.length(); } |
| 8965 |
uint32_t stackDepth() const { return numAllocatedOperands(); } |
| 8966 |
size_t numOperands() const override { return numAllocatedOperands(); } |
| 8967 |
size_t indexOf(const MUse* u) const final { |
| 8968 |
MOZ_ASSERT(u >= &operands_[0]); |
| 8969 |
MOZ_ASSERT(u <= &operands_[numOperands() - 1]); |
| 8970 |
return u - &operands_[0]; |
| 8971 |
} |
| 8972 |
void initOperand(size_t index, MDefinition* operand) { |
| 8973 |
// FixedList doesn't initialize its elements, so do an unchecked init. |
| 8974 |
operands_[index].initUnchecked(operand, this); |
| 8975 |
} |
| 8976 |
void replaceOperand(size_t index, MDefinition* operand) final { |
| 8977 |
operands_[index].replaceProducer(operand); |
| 8978 |
} |
| 8979 |
|
| 8980 |
bool isObservableOperand(MUse* u) const; |
| 8981 |
bool isObservableOperand(size_t index) const; |
| 8982 |
bool isRecoverableOperand(MUse* u) const; |
| 8983 |
|
| 8984 |
MDefinition* getOperand(size_t index) const override { |
| 8985 |
return operands_[index].producer(); |
| 8986 |
} |
| 8987 |
jsbytecode* pc() const { return pc_; } |
| 8988 |
MResumePoint* caller() const; |
| 8989 |
uint32_t frameCount() const { |
| 8990 |
uint32_t count = 1; |
| 8991 |
for (MResumePoint* it = caller(); it; it = it->caller()) { |
| 8992 |
count++; |
| 8993 |
} |
| 8994 |
return count; |
| 8995 |
} |
| 8996 |
MInstruction* instruction() { return instruction_; } |
| 8997 |
void setInstruction(MInstruction* ins) { |
| 8998 |
MOZ_ASSERT(!instruction_); |
| 8999 |
instruction_ = ins; |
| 9000 |
} |
| 9001 |
void resetInstruction() { |
| 9002 |
MOZ_ASSERT(instruction_); |
| 9003 |
instruction_ = nullptr; |
| 9004 |
} |
| 9005 |
ResumeMode mode() const { return mode_; } |
| 9006 |
|
| 9007 |
void releaseUses() { |
| 9008 |
for (size_t i = 0, e = numOperands(); i < e; i++) { |
| 9009 |
if (operands_[i].hasProducer()) { |
| 9010 |
operands_[i].releaseProducer(); |
| 9011 |
} |
| 9012 |
} |
| 9013 |
} |
| 9014 |
|
| 9015 |
[[nodiscard]] bool writeRecoverData( |
| 9016 |
CompactBufferWriter& writer) const override; |
| 9017 |
|
| 9018 |
// Register a store instruction on the current resume point. This |
| 9019 |
// instruction would be recovered when we are bailing out. The |cache| |
| 9020 |
// argument can be any resume point, it is used to share memory if we are |
| 9021 |
// doing the same modification. |
| 9022 |
void addStore(TempAllocator& alloc, MDefinition* store, |
| 9023 |
const MResumePoint* cache = nullptr); |
| 9024 |
|
| 9025 |
MStoresToRecoverList::iterator storesBegin() const { return stores_.begin(); } |
| 9026 |
MStoresToRecoverList::iterator storesEnd() const { return stores_.end(); } |
| 9027 |
bool storesEmpty() const { return stores_.empty(); } |
| 9028 |
|
| 9029 |
void setDiscarded() { isDiscarded_ = true; } |
| 9030 |
bool isDiscarded() const { return isDiscarded_; } |
| 9031 |
|
| 9032 |
#ifdef JS_JITSPEW |
| 9033 |
virtual void dump(GenericPrinter& out) const override; |
| 9034 |
virtual void dump() const override; |
| 9035 |
#endif |
| 9036 |
}; |
| 9037 |
|
| 9038 |
class MIsCallable : public MUnaryInstruction, |
| 9039 |
public BoxExceptPolicy<0, MIRType::Object>::Data { |
| 9040 |
explicit MIsCallable(MDefinition* object) |
| 9041 |
: MUnaryInstruction(classOpcode, object) { |
| 9042 |
setResultType(MIRType::Boolean); |
| 9043 |
setMovable(); |
| 9044 |
} |
| 9045 |
|
| 9046 |
public: |
| 9047 |
INSTRUCTION_HEADER(IsCallable) |
| 9048 |
TRIVIAL_NEW_WRAPPERS |
| 9049 |
NAMED_OPERANDS((0, object)) |
| 9050 |
|
| 9051 |
bool congruentTo(const MDefinition* ins) const override { |
| 9052 |
return congruentIfOperandsEqual(ins); |
| 9053 |
} |
| 9054 |
|
| 9055 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9056 |
AliasSet getAliasSet() const override { |
| 9057 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 9058 |
} |
| 9059 |
}; |
| 9060 |
|
| 9061 |
class MHasClass : public MUnaryInstruction, public SingleObjectPolicy::Data { |
| 9062 |
const JSClass* class_; |
| 9063 |
|
| 9064 |
MHasClass(MDefinition* object, const JSClass* clasp) |
| 9065 |
: MUnaryInstruction(classOpcode, object), class_(clasp) { |
| 9066 |
MOZ_ASSERT(object->type() == MIRType::Object); |
| 9067 |
setResultType(MIRType::Boolean); |
| 9068 |
setMovable(); |
| 9069 |
} |
| 9070 |
|
| 9071 |
public: |
| 9072 |
INSTRUCTION_HEADER(HasClass) |
| 9073 |
TRIVIAL_NEW_WRAPPERS |
| 9074 |
NAMED_OPERANDS((0, object)) |
| 9075 |
|
| 9076 |
const JSClass* getClass() const { return class_; } |
| 9077 |
|
| 9078 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9079 |
AliasSet getAliasSet() const override { |
| 9080 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 9081 |
} |
| 9082 |
bool congruentTo(const MDefinition* ins) const override { |
| 9083 |
if (!ins->isHasClass()) { |
| 9084 |
return false; |
| 9085 |
} |
| 9086 |
if (getClass() != ins->toHasClass()->getClass()) { |
| 9087 |
return false; |
| 9088 |
} |
| 9089 |
return congruentIfOperandsEqual(ins); |
| 9090 |
} |
| 9091 |
}; |
| 9092 |
|
| 9093 |
class MGuardToClass : public MUnaryInstruction, |
| 9094 |
public SingleObjectPolicy::Data { |
| 9095 |
const JSClass* class_; |
| 9096 |
|
| 9097 |
MGuardToClass(MDefinition* object, const JSClass* clasp) |
| 9098 |
: MUnaryInstruction(classOpcode, object), class_(clasp) { |
| 9099 |
MOZ_ASSERT(object->type() == MIRType::Object); |
| 9100 |
MOZ_ASSERT(!clasp->isJSFunction(), "Use MGuardToFunction instead"); |
| 9101 |
setResultType(MIRType::Object); |
| 9102 |
setMovable(); |
| 9103 |
|
| 9104 |
// We will bail out if the class type is incorrect, so we need to ensure we |
| 9105 |
// don't eliminate this instruction |
| 9106 |
setGuard(); |
| 9107 |
} |
| 9108 |
|
| 9109 |
public: |
| 9110 |
INSTRUCTION_HEADER(GuardToClass) |
| 9111 |
TRIVIAL_NEW_WRAPPERS |
| 9112 |
NAMED_OPERANDS((0, object)) |
| 9113 |
|
| 9114 |
const JSClass* getClass() const { return class_; } |
| 9115 |
bool isArgumentsObjectClass() const { |
| 9116 |
return class_ == &MappedArgumentsObject::class_ || |
| 9117 |
class_ == &UnmappedArgumentsObject::class_; |
| 9118 |
} |
| 9119 |
|
| 9120 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9121 |
AliasSet getAliasSet() const override { |
| 9122 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 9123 |
} |
| 9124 |
bool congruentTo(const MDefinition* ins) const override { |
| 9125 |
if (!ins->isGuardToClass()) { |
| 9126 |
return false; |
| 9127 |
} |
| 9128 |
if (getClass() != ins->toGuardToClass()->getClass()) { |
| 9129 |
return false; |
| 9130 |
} |
| 9131 |
return congruentIfOperandsEqual(ins); |
| 9132 |
} |
| 9133 |
}; |
| 9134 |
|
| 9135 |
class MGuardToEitherClass : public MUnaryInstruction, |
| 9136 |
public SingleObjectPolicy::Data { |
| 9137 |
const JSClass* class1_; |
| 9138 |
const JSClass* class2_; |
| 9139 |
|
| 9140 |
MGuardToEitherClass(MDefinition* object, const JSClass* clasp1, |
| 9141 |
const JSClass* clasp2) |
| 9142 |
: MUnaryInstruction(classOpcode, object), |
| 9143 |
class1_(clasp1), |
| 9144 |
class2_(clasp2) { |
| 9145 |
MOZ_ASSERT(object->type() == MIRType::Object); |
| 9146 |
MOZ_ASSERT(clasp1 != clasp2, "Use MGuardToClass instead"); |
| 9147 |
MOZ_ASSERT(!clasp1->isJSFunction(), "Use MGuardToFunction instead"); |
| 9148 |
MOZ_ASSERT(!clasp2->isJSFunction(), "Use MGuardToFunction instead"); |
| 9149 |
setResultType(MIRType::Object); |
| 9150 |
setMovable(); |
| 9151 |
|
| 9152 |
// We will bail out if the class type is incorrect, so we need to ensure we |
| 9153 |
// don't eliminate this instruction |
| 9154 |
setGuard(); |
| 9155 |
} |
| 9156 |
|
| 9157 |
public: |
| 9158 |
INSTRUCTION_HEADER(GuardToEitherClass) |
| 9159 |
TRIVIAL_NEW_WRAPPERS |
| 9160 |
NAMED_OPERANDS((0, object)) |
| 9161 |
|
| 9162 |
const JSClass* getClass1() const { return class1_; } |
| 9163 |
const JSClass* getClass2() const { return class2_; } |
| 9164 |
|
| 9165 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9166 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9167 |
bool congruentTo(const MDefinition* ins) const override { |
| 9168 |
if (!ins->isGuardToEitherClass()) { |
| 9169 |
return false; |
| 9170 |
} |
| 9171 |
const auto* other = ins->toGuardToEitherClass(); |
| 9172 |
if (getClass1() != other->getClass1() && |
| 9173 |
getClass1() != other->getClass2()) { |
| 9174 |
return false; |
| 9175 |
} |
| 9176 |
if (getClass2() != other->getClass1() && |
| 9177 |
getClass2() != other->getClass2()) { |
| 9178 |
return false; |
| 9179 |
} |
| 9180 |
return congruentIfOperandsEqual(ins); |
| 9181 |
} |
| 9182 |
}; |
| 9183 |
|
| 9184 |
class MGuardToFunction : public MUnaryInstruction, |
| 9185 |
public SingleObjectPolicy::Data { |
| 9186 |
explicit MGuardToFunction(MDefinition* object) |
| 9187 |
: MUnaryInstruction(classOpcode, object) { |
| 9188 |
MOZ_ASSERT(object->type() == MIRType::Object); |
| 9189 |
setResultType(MIRType::Object); |
| 9190 |
setMovable(); |
| 9191 |
|
| 9192 |
// We will bail out if the class type is incorrect, so we need to ensure we |
| 9193 |
// don't eliminate this instruction |
| 9194 |
setGuard(); |
| 9195 |
} |
| 9196 |
|
| 9197 |
public: |
| 9198 |
INSTRUCTION_HEADER(GuardToFunction) |
| 9199 |
TRIVIAL_NEW_WRAPPERS |
| 9200 |
NAMED_OPERANDS((0, object)) |
| 9201 |
|
| 9202 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9203 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9204 |
bool congruentTo(const MDefinition* ins) const override { |
| 9205 |
if (!ins->isGuardToFunction()) { |
| 9206 |
return false; |
| 9207 |
} |
| 9208 |
return congruentIfOperandsEqual(ins); |
| 9209 |
} |
| 9210 |
}; |
| 9211 |
|
| 9212 |
// Note: we might call a proxy trap, so this instruction is effectful. |
| 9213 |
class MIsArray : public MUnaryInstruction, |
| 9214 |
public BoxExceptPolicy<0, MIRType::Object>::Data { |
| 9215 |
explicit MIsArray(MDefinition* value) |
| 9216 |
: MUnaryInstruction(classOpcode, value) { |
| 9217 |
setResultType(MIRType::Boolean); |
| 9218 |
} |
| 9219 |
|
| 9220 |
public: |
| 9221 |
INSTRUCTION_HEADER(IsArray) |
| 9222 |
TRIVIAL_NEW_WRAPPERS |
| 9223 |
NAMED_OPERANDS((0, value)) |
| 9224 |
|
| 9225 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9226 |
}; |
| 9227 |
|
| 9228 |
class MIsTypedArray : public MUnaryInstruction, |
| 9229 |
public SingleObjectPolicy::Data { |
| 9230 |
bool possiblyWrapped_; |
| 9231 |
|
| 9232 |
explicit MIsTypedArray(MDefinition* value, bool possiblyWrapped) |
| 9233 |
: MUnaryInstruction(classOpcode, value), |
| 9234 |
possiblyWrapped_(possiblyWrapped) { |
| 9235 |
setResultType(MIRType::Boolean); |
| 9236 |
|
| 9237 |
if (possiblyWrapped) { |
| 9238 |
// Proxy checks may throw, so we're neither removable nor movable. |
| 9239 |
setGuard(); |
| 9240 |
} else { |
| 9241 |
setMovable(); |
| 9242 |
} |
| 9243 |
} |
| 9244 |
|
| 9245 |
public: |
| 9246 |
INSTRUCTION_HEADER(IsTypedArray) |
| 9247 |
TRIVIAL_NEW_WRAPPERS |
| 9248 |
NAMED_OPERANDS((0, value)) |
| 9249 |
|
| 9250 |
bool isPossiblyWrapped() const { return possiblyWrapped_; } |
| 9251 |
AliasSet getAliasSet() const override { |
| 9252 |
if (isPossiblyWrapped()) { |
| 9253 |
return AliasSet::Store(AliasSet::Any); |
| 9254 |
} |
| 9255 |
return AliasSet::None(); |
| 9256 |
} |
| 9257 |
}; |
| 9258 |
|
| 9259 |
// Allocate the generator object for a frame. |
| 9260 |
class MGenerator : public MTernaryInstruction, |
| 9261 |
public MixPolicy<ObjectPolicy<0>, ObjectPolicy<1>>::Data { |
| 9262 |
explicit MGenerator(MDefinition* callee, MDefinition* environmentChain, |
| 9263 |
MDefinition* argsObject) |
| 9264 |
: MTernaryInstruction(classOpcode, callee, environmentChain, argsObject) { |
| 9265 |
setResultType(MIRType::Object); |
| 9266 |
}; |
| 9267 |
|
| 9268 |
public: |
| 9269 |
INSTRUCTION_HEADER(Generator) |
| 9270 |
TRIVIAL_NEW_WRAPPERS |
| 9271 |
NAMED_OPERANDS((0, callee), (1, environmentChain), (2, argsObject)) |
| 9272 |
}; |
| 9273 |
|
| 9274 |
class MMaybeExtractAwaitValue : public MBinaryInstruction, |
| 9275 |
public BoxPolicy<0>::Data { |
| 9276 |
explicit MMaybeExtractAwaitValue(MDefinition* value, MDefinition* canSkip) |
| 9277 |
: MBinaryInstruction(classOpcode, value, canSkip) { |
| 9278 |
setResultType(MIRType::Value); |
| 9279 |
} |
| 9280 |
|
| 9281 |
public: |
| 9282 |
INSTRUCTION_HEADER(MaybeExtractAwaitValue) |
| 9283 |
TRIVIAL_NEW_WRAPPERS |
| 9284 |
NAMED_OPERANDS((0, value), (1, canSkip)) |
| 9285 |
}; |
| 9286 |
|
| 9287 |
class MAtomicIsLockFree : public MUnaryInstruction, |
| 9288 |
public ConvertToInt32Policy<0>::Data { |
| 9289 |
explicit MAtomicIsLockFree(MDefinition* value) |
| 9290 |
: MUnaryInstruction(classOpcode, value) { |
| 9291 |
setResultType(MIRType::Boolean); |
| 9292 |
setMovable(); |
| 9293 |
} |
| 9294 |
|
| 9295 |
public: |
| 9296 |
INSTRUCTION_HEADER(AtomicIsLockFree) |
| 9297 |
TRIVIAL_NEW_WRAPPERS |
| 9298 |
|
| 9299 |
MDefinition* foldsTo(TempAllocator& alloc) override; |
| 9300 |
|
| 9301 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9302 |
|
| 9303 |
bool congruentTo(const MDefinition* ins) const override { |
| 9304 |
return congruentIfOperandsEqual(ins); |
| 9305 |
} |
| 9306 |
|
| 9307 |
[[nodiscard]] bool writeRecoverData( |
| 9308 |
CompactBufferWriter& writer) const override; |
| 9309 |
bool canRecoverOnBailout() const override { return true; } |
| 9310 |
|
| 9311 |
ALLOW_CLONE(MAtomicIsLockFree) |
| 9312 |
}; |
| 9313 |
|
| 9314 |
class MCompareExchangeTypedArrayElement |
| 9315 |
: public MQuaternaryInstruction, |
| 9316 |
public MixPolicy<TruncateToInt32OrToInt64Policy<2>, |
| 9317 |
TruncateToInt32OrToInt64Policy<3>>::Data { |
| 9318 |
Scalar::Type arrayType_; |
| 9319 |
|
| 9320 |
explicit MCompareExchangeTypedArrayElement(MDefinition* elements, |
| 9321 |
MDefinition* index, |
| 9322 |
Scalar::Type arrayType, |
| 9323 |
MDefinition* oldval, |
| 9324 |
MDefinition* newval) |
| 9325 |
: MQuaternaryInstruction(classOpcode, elements, index, oldval, newval), |
| 9326 |
arrayType_(arrayType) { |
| 9327 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 9328 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 9329 |
setGuard(); // Not removable |
| 9330 |
} |
| 9331 |
|
| 9332 |
public: |
| 9333 |
INSTRUCTION_HEADER(CompareExchangeTypedArrayElement) |
| 9334 |
TRIVIAL_NEW_WRAPPERS |
| 9335 |
NAMED_OPERANDS((0, elements), (1, index), (2, oldval), (3, newval)) |
| 9336 |
|
| 9337 |
bool isByteArray() const { |
| 9338 |
return (arrayType_ == Scalar::Int8 || arrayType_ == Scalar::Uint8); |
| 9339 |
} |
| 9340 |
Scalar::Type arrayType() const { return arrayType_; } |
| 9341 |
AliasSet getAliasSet() const override { |
| 9342 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 9343 |
} |
| 9344 |
}; |
| 9345 |
|
| 9346 |
class MAtomicExchangeTypedArrayElement |
| 9347 |
: public MTernaryInstruction, |
| 9348 |
public TruncateToInt32OrToInt64Policy<2>::Data { |
| 9349 |
Scalar::Type arrayType_; |
| 9350 |
|
| 9351 |
MAtomicExchangeTypedArrayElement(MDefinition* elements, MDefinition* index, |
| 9352 |
MDefinition* value, Scalar::Type arrayType) |
| 9353 |
: MTernaryInstruction(classOpcode, elements, index, value), |
| 9354 |
arrayType_(arrayType) { |
| 9355 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 9356 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 9357 |
MOZ_ASSERT(arrayType <= Scalar::Uint32 || Scalar::isBigIntType(arrayType)); |
| 9358 |
setGuard(); // Not removable |
| 9359 |
} |
| 9360 |
|
| 9361 |
public: |
| 9362 |
INSTRUCTION_HEADER(AtomicExchangeTypedArrayElement) |
| 9363 |
TRIVIAL_NEW_WRAPPERS |
| 9364 |
NAMED_OPERANDS((0, elements), (1, index), (2, value)) |
| 9365 |
|
| 9366 |
bool isByteArray() const { |
| 9367 |
return (arrayType_ == Scalar::Int8 || arrayType_ == Scalar::Uint8); |
| 9368 |
} |
| 9369 |
Scalar::Type arrayType() const { return arrayType_; } |
| 9370 |
AliasSet getAliasSet() const override { |
| 9371 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 9372 |
} |
| 9373 |
}; |
| 9374 |
|
| 9375 |
class MAtomicTypedArrayElementBinop |
| 9376 |
: public MTernaryInstruction, |
| 9377 |
public TruncateToInt32OrToInt64Policy<2>::Data { |
| 9378 |
private: |
| 9379 |
AtomicOp op_; |
| 9380 |
Scalar::Type arrayType_; |
| 9381 |
bool forEffect_; |
| 9382 |
|
| 9383 |
explicit MAtomicTypedArrayElementBinop(AtomicOp op, MDefinition* elements, |
| 9384 |
MDefinition* index, |
| 9385 |
Scalar::Type arrayType, |
| 9386 |
MDefinition* value, bool forEffect) |
| 9387 |
: MTernaryInstruction(classOpcode, elements, index, value), |
| 9388 |
op_(op), |
| 9389 |
arrayType_(arrayType), |
| 9390 |
forEffect_(forEffect) { |
| 9391 |
MOZ_ASSERT(elements->type() == MIRType::Elements); |
| 9392 |
MOZ_ASSERT(index->type() == MIRType::IntPtr); |
| 9393 |
MOZ_ASSERT(arrayType <= Scalar::Uint32 || Scalar::isBigIntType(arrayType)); |
| 9394 |
setGuard(); // Not removable |
| 9395 |
} |
| 9396 |
|
| 9397 |
public: |
| 9398 |
INSTRUCTION_HEADER(AtomicTypedArrayElementBinop) |
| 9399 |
TRIVIAL_NEW_WRAPPERS |
| 9400 |
NAMED_OPERANDS((0, elements), (1, index), (2, value)) |
| 9401 |
|
| 9402 |
bool isByteArray() const { |
| 9403 |
return (arrayType_ == Scalar::Int8 || arrayType_ == Scalar::Uint8); |
| 9404 |
} |
| 9405 |
AtomicOp operation() const { return op_; } |
| 9406 |
Scalar::Type arrayType() const { return arrayType_; } |
| 9407 |
bool isForEffect() const { return forEffect_; } |
| 9408 |
AliasSet getAliasSet() const override { |
| 9409 |
return AliasSet::Store(AliasSet::UnboxedElement); |
| 9410 |
} |
| 9411 |
}; |
| 9412 |
|
| 9413 |
class MDebugger : public MNullaryInstruction { |
| 9414 |
MDebugger() : MNullaryInstruction(classOpcode) { |
| 9415 |
setBailoutKind(BailoutKind::Debugger); |
| 9416 |
} |
| 9417 |
|
| 9418 |
public: |
| 9419 |
INSTRUCTION_HEADER(Debugger) |
| 9420 |
TRIVIAL_NEW_WRAPPERS |
| 9421 |
}; |
| 9422 |
|
| 9423 |
// Used to load the prototype of an object known to have |
| 9424 |
// a static prototype. |
| 9425 |
class MObjectStaticProto : public MUnaryInstruction, |
| 9426 |
public SingleObjectPolicy::Data { |
| 9427 |
explicit MObjectStaticProto(MDefinition* object) |
| 9428 |
: MUnaryInstruction(classOpcode, object) { |
| 9429 |
setResultType(MIRType::Object); |
| 9430 |
setMovable(); |
| 9431 |
} |
| 9432 |
|
| 9433 |
public: |
| 9434 |
INSTRUCTION_HEADER(ObjectStaticProto) |
| 9435 |
TRIVIAL_NEW_WRAPPERS |
| 9436 |
NAMED_OPERANDS((0, object)) |
| 9437 |
|
| 9438 |
bool congruentTo(const MDefinition* ins) const override { |
| 9439 |
return congruentIfOperandsEqual(ins); |
| 9440 |
} |
| 9441 |
|
| 9442 |
AliasSet getAliasSet() const override { |
| 9443 |
return AliasSet::Load(AliasSet::ObjectFields); |
| 9444 |
} |
| 9445 |
AliasType mightAlias(const MDefinition* def) const override { |
| 9446 |
// These instructions never modify the [[Prototype]]. |
| 9447 |
if (def->isAddAndStoreSlot() || def->isAllocateAndStoreSlot() || |
| 9448 |
def->isStoreElementHole() || def->isArrayPush()) { |
| 9449 |
return AliasType::NoAlias; |
| 9450 |
} |
| 9451 |
return AliasType::MayAlias; |
| 9452 |
} |
| 9453 |
}; |
| 9454 |
|
| 9455 |
class MConstantProto : public MUnaryInstruction, |
| 9456 |
public SingleObjectPolicy::Data { |
| 9457 |
// NOTE: we're not going to actually use the underlying receiver object for |
| 9458 |
// anything. This is just here for giving extra information to MGuardShape |
| 9459 |
// to MGuardShape::mightAlias. Accordingly, we don't take it as an operand, |
| 9460 |
// but instead just keep a pointer to it. This means we need to ensure it's |
| 9461 |
// not discarded before we try to access it. If this is discarded, we |
| 9462 |
// basically just become an MConstant for the object's proto, which is fine. |
| 9463 |
const MDefinition* receiverObject_; |
| 9464 |
|
| 9465 |
explicit MConstantProto(MDefinition* protoObject, |
| 9466 |
const MDefinition* receiverObject) |
| 9467 |
: MUnaryInstruction(classOpcode, protoObject), |
| 9468 |
receiverObject_(receiverObject) { |
| 9469 |
MOZ_ASSERT(protoObject->isConstant()); |
| 9470 |
setResultType(MIRType::Object); |
| 9471 |
setMovable(); |
| 9472 |
} |
| 9473 |
|
| 9474 |
ALLOW_CLONE(MConstantProto) |
| 9475 |
|
| 9476 |
public: |
| 9477 |
INSTRUCTION_HEADER(ConstantProto) |
| 9478 |
TRIVIAL_NEW_WRAPPERS |
| 9479 |
NAMED_OPERANDS((0, protoObject)) |
| 9480 |
|
| 9481 |
HashNumber valueHash() const override; |
| 9482 |
|
| 9483 |
bool congruentTo(const MDefinition* ins) const override { |
| 9484 |
if (this == ins) { |
| 9485 |
return true; |
| 9486 |
} |
| 9487 |
const MDefinition* receiverObject = getReceiverObject(); |
| 9488 |
return congruentIfOperandsEqual(ins) && receiverObject && |
| 9489 |
receiverObject == ins->toConstantProto()->getReceiverObject(); |
| 9490 |
} |
| 9491 |
|
| 9492 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9493 |
|
| 9494 |
const MDefinition* getReceiverObject() const { |
| 9495 |
if (receiverObject_->isDiscarded()) { |
| 9496 |
return nullptr; |
| 9497 |
} |
| 9498 |
return receiverObject_; |
| 9499 |
} |
| 9500 |
}; |
| 9501 |
|
| 9502 |
class MObjectToIterator : public MUnaryInstruction, |
| 9503 |
public ObjectPolicy<0>::Data { |
| 9504 |
NativeIteratorListHead* enumeratorsAddr_; |
| 9505 |
bool wantsIndices_ = false; |
| 9506 |
|
| 9507 |
explicit MObjectToIterator(MDefinition* object, |
| 9508 |
NativeIteratorListHead* enumeratorsAddr) |
| 9509 |
: MUnaryInstruction(classOpcode, object), |
| 9510 |
enumeratorsAddr_(enumeratorsAddr) { |
| 9511 |
setResultType(MIRType::Object); |
| 9512 |
} |
| 9513 |
|
| 9514 |
public: |
| 9515 |
NativeIteratorListHead* enumeratorsAddr() const { return enumeratorsAddr_; } |
| 9516 |
INSTRUCTION_HEADER(ObjectToIterator) |
| 9517 |
TRIVIAL_NEW_WRAPPERS |
| 9518 |
NAMED_OPERANDS((0, object)) |
| 9519 |
|
| 9520 |
bool wantsIndices() const { return wantsIndices_; } |
| 9521 |
void setWantsIndices(bool value) { wantsIndices_ = value; } |
| 9522 |
}; |
| 9523 |
|
| 9524 |
class MPostIntPtrConversion : public MUnaryInstruction, |
| 9525 |
public NoTypePolicy::Data { |
| 9526 |
explicit MPostIntPtrConversion(MDefinition* input) |
| 9527 |
: MUnaryInstruction(classOpcode, input) { |
| 9528 |
// Passes through the input. |
| 9529 |
setResultType(input->type()); |
| 9530 |
|
| 9531 |
// Note: Must be non-movable so we can attach a resume point. |
| 9532 |
} |
| 9533 |
|
| 9534 |
public: |
| 9535 |
INSTRUCTION_HEADER(PostIntPtrConversion) |
| 9536 |
TRIVIAL_NEW_WRAPPERS |
| 9537 |
|
| 9538 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9539 |
}; |
| 9540 |
|
| 9541 |
class MCanonicalizeNaN : public MUnaryInstruction, public NoTypePolicy::Data { |
| 9542 |
explicit MCanonicalizeNaN(MDefinition* input) |
| 9543 |
: MUnaryInstruction(classOpcode, input) { |
| 9544 |
MOZ_ASSERT(IsFloatingPointType(input->type())); |
| 9545 |
setResultType(input->type()); |
| 9546 |
setMovable(); |
| 9547 |
} |
| 9548 |
|
| 9549 |
public: |
| 9550 |
INSTRUCTION_HEADER(CanonicalizeNaN) |
| 9551 |
TRIVIAL_NEW_WRAPPERS |
| 9552 |
|
| 9553 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9554 |
|
| 9555 |
bool congruentTo(const MDefinition* ins) const override { |
| 9556 |
return congruentIfOperandsEqual(ins); |
| 9557 |
} |
| 9558 |
|
| 9559 |
bool canProduceFloat32() const override { return type() == MIRType::Float32; } |
| 9560 |
|
| 9561 |
ALLOW_CLONE(MCanonicalizeNaN) |
| 9562 |
}; |
| 9563 |
|
| 9564 |
class MRotate : public MBinaryInstruction, public NoTypePolicy::Data { |
| 9565 |
bool isLeftRotate_; |
| 9566 |
|
| 9567 |
MRotate(MDefinition* input, MDefinition* count, MIRType type, |
| 9568 |
bool isLeftRotate) |
| 9569 |
: MBinaryInstruction(classOpcode, input, count), |
| 9570 |
isLeftRotate_(isLeftRotate) { |
| 9571 |
setMovable(); |
| 9572 |
setResultType(type); |
| 9573 |
// Prevent reordering. Although there's no problem eliding call result |
| 9574 |
// definitions, there's also no need, as they cause no codegen. |
| 9575 |
setGuard(); |
| 9576 |
} |
| 9577 |
|
| 9578 |
public: |
| 9579 |
INSTRUCTION_HEADER(Rotate) |
| 9580 |
TRIVIAL_NEW_WRAPPERS |
| 9581 |
NAMED_OPERANDS((0, input), (1, count)) |
| 9582 |
|
| 9583 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9584 |
bool congruentTo(const MDefinition* ins) const override { |
| 9585 |
return congruentIfOperandsEqual(ins) && |
| 9586 |
ins->toRotate()->isLeftRotate() == isLeftRotate_; |
| 9587 |
} |
| 9588 |
|
| 9589 |
bool isLeftRotate() const { return isLeftRotate_; } |
| 9590 |
|
| 9591 |
ALLOW_CLONE(MRotate) |
| 9592 |
}; |
| 9593 |
|
| 9594 |
class MReinterpretCast : public MUnaryInstruction, public NoTypePolicy::Data { |
| 9595 |
MReinterpretCast(MDefinition* val, MIRType toType) |
| 9596 |
: MUnaryInstruction(classOpcode, val) { |
| 9597 |
switch (val->type()) { |
| 9598 |
case MIRType::Int32: |
| 9599 |
MOZ_ASSERT(toType == MIRType::Float32); |
| 9600 |
break; |
| 9601 |
case MIRType::Float32: |
| 9602 |
MOZ_ASSERT(toType == MIRType::Int32); |
| 9603 |
break; |
| 9604 |
case MIRType::Double: |
| 9605 |
MOZ_ASSERT(toType == MIRType::Int64); |
| 9606 |
break; |
| 9607 |
case MIRType::Int64: |
| 9608 |
MOZ_ASSERT(toType == MIRType::Double); |
| 9609 |
break; |
| 9610 |
default: |
| 9611 |
MOZ_CRASH("unexpected reinterpret conversion"); |
| 9612 |
} |
| 9613 |
setMovable(); |
| 9614 |
setResultType(toType); |
| 9615 |
} |
| 9616 |
|
| 9617 |
public: |
| 9618 |
INSTRUCTION_HEADER(ReinterpretCast) |
| 9619 |
TRIVIAL_NEW_WRAPPERS |
| 9620 |
|
| 9621 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9622 |
bool congruentTo(const MDefinition* ins) const override { |
| 9623 |
// No need to check type() here, because congruentIfOperandsEqual will |
| 9624 |
// check it. |
| 9625 |
return congruentIfOperandsEqual(ins); |
| 9626 |
} |
| 9627 |
|
| 9628 |
ALLOW_CLONE(MReinterpretCast) |
| 9629 |
}; |
| 9630 |
|
| 9631 |
// Used by MIR building to represent the bytecode result of an operation for |
| 9632 |
// which an MBail was generated, to balance the basic block's MDefinition stack. |
| 9633 |
class MUnreachableResult : public MNullaryInstruction { |
| 9634 |
explicit MUnreachableResult(MIRType type) : MNullaryInstruction(classOpcode) { |
| 9635 |
MOZ_ASSERT(type != MIRType::None); |
| 9636 |
setResultType(type); |
| 9637 |
} |
| 9638 |
|
| 9639 |
public: |
| 9640 |
INSTRUCTION_HEADER(UnreachableResult) |
| 9641 |
TRIVIAL_NEW_WRAPPERS |
| 9642 |
|
| 9643 |
bool congruentTo(const MDefinition* ins) const override { |
| 9644 |
return congruentIfOperandsEqual(ins); |
| 9645 |
} |
| 9646 |
AliasSet getAliasSet() const override { return AliasSet::None(); } |
| 9647 |
}; |
| 9648 |
|
| 9649 |
#ifdef FUZZING_JS_FUZZILLI |
| 9650 |
class MFuzzilliHash : public MUnaryInstruction, public NoTypePolicy::Data { |
| 9651 |
explicit MFuzzilliHash(MDefinition* obj) |
| 9652 |
: MUnaryInstruction(classOpcode, obj) { |
| 9653 |
setResultType(MIRType::Int32); |
| 9654 |
setMovable(); |
| 9655 |
} |
| 9656 |
|
| 9657 |
public: |
| 9658 |
INSTRUCTION_HEADER(FuzzilliHash); |
| 9659 |
TRIVIAL_NEW_WRAPPERS |
| 9660 |
ALLOW_CLONE(MFuzzilliHash) |
| 9661 |
|
| 9662 |
# ifdef DEBUG |
| 9663 |
bool isConsistentFloat32Use(MUse* use) const override { return true; } |
| 9664 |
# endif |
| 9665 |
|
| 9666 |
AliasSet getAliasSet() const override { |
| 9667 |
MDefinition* obj = getOperand(0); |
| 9668 |
if (obj->type() == MIRType::Object || obj->type() == MIRType::Value) { |
| 9669 |
return AliasSet::Load(AliasSet::ObjectFields | AliasSet::FixedSlot | |
| 9670 |
AliasSet::DynamicSlot | AliasSet::Element | |
| 9671 |
AliasSet::UnboxedElement); |
| 9672 |
} |
| 9673 |
return AliasSet::None(); |
| 9674 |
} |
| 9675 |
}; |
| 9676 |
|
| 9677 |
class MFuzzilliHashStore : public MUnaryInstruction, public NoTypePolicy::Data { |
| 9678 |
explicit MFuzzilliHashStore(MDefinition* obj) |
| 9679 |
: MUnaryInstruction(classOpcode, obj) { |
| 9680 |
MOZ_ASSERT(obj->type() == MIRType::Int32); |
| 9681 |
|
| 9682 |
setResultType(MIRType::None); |
| 9683 |
} |
| 9684 |
|
| 9685 |
public: |
| 9686 |
INSTRUCTION_HEADER(FuzzilliHashStore); |
| 9687 |
TRIVIAL_NEW_WRAPPERS |
| 9688 |
ALLOW_CLONE(MFuzzilliHashStore) |
| 9689 |
|
| 9690 |
// this is a store and hence effectful, however no other load can |
| 9691 |
// alias with the store |
| 9692 |
AliasSet getAliasSet() const override { |
| 9693 |
return AliasSet::Store(AliasSet::FuzzilliHash); |
| 9694 |
} |
| 9695 |
}; |
| 9696 |
#endif |
| 9697 |
|
| 9698 |
void MUse::init(MDefinition* producer, MNode* consumer) { |
| 9699 |
MOZ_ASSERT(!consumer_, "Initializing MUse that already has a consumer"); |
| 9700 |
MOZ_ASSERT(!producer_, "Initializing MUse that already has a producer"); |
| 9701 |
initUnchecked(producer, consumer); |
| 9702 |
} |
| 9703 |
|
| 9704 |
void MUse::initUnchecked(MDefinition* producer, MNode* consumer) { |
| 9705 |
MOZ_ASSERT(consumer, "Initializing to null consumer"); |
| 9706 |
consumer_ = consumer; |
| 9707 |
producer_ = producer; |
| 9708 |
producer_->addUseUnchecked(this); |
| 9709 |
} |
| 9710 |
|
| 9711 |
void MUse::initUncheckedWithoutProducer(MNode* consumer) { |
| 9712 |
MOZ_ASSERT(consumer, "Initializing to null consumer"); |
| 9713 |
consumer_ = consumer; |
| 9714 |
producer_ = nullptr; |
| 9715 |
} |
| 9716 |
|
| 9717 |
void MUse::replaceProducer(MDefinition* producer) { |
| 9718 |
MOZ_ASSERT(consumer_, "Resetting MUse without a consumer"); |
| 9719 |
producer_->removeUse(this); |
| 9720 |
producer_ = producer; |
| 9721 |
producer_->addUse(this); |
| 9722 |
} |
| 9723 |
|
| 9724 |
void MUse::releaseProducer() { |
| 9725 |
MOZ_ASSERT(consumer_, "Clearing MUse without a consumer"); |
| 9726 |
producer_->removeUse(this); |
| 9727 |
producer_ = nullptr; |
| 9728 |
} |
| 9729 |
|
| 9730 |
// Implement cast functions now that the compiler can see the inheritance. |
| 9731 |
|
| 9732 |
MDefinition* MNode::toDefinition() { |
| 9733 |
MOZ_ASSERT(isDefinition()); |
| 9734 |
return (MDefinition*)this; |
| 9735 |
} |
| 9736 |
|
| 9737 |
MResumePoint* MNode::toResumePoint() { |
| 9738 |
MOZ_ASSERT(isResumePoint()); |
| 9739 |
return (MResumePoint*)this; |
| 9740 |
} |
| 9741 |
|
| 9742 |
MInstruction* MDefinition::toInstruction() { |
| 9743 |
MOZ_ASSERT(!isPhi()); |
| 9744 |
return (MInstruction*)this; |
| 9745 |
} |
| 9746 |
|
| 9747 |
const MInstruction* MDefinition::toInstruction() const { |
| 9748 |
MOZ_ASSERT(!isPhi()); |
| 9749 |
return (const MInstruction*)this; |
| 9750 |
} |
| 9751 |
|
| 9752 |
MControlInstruction* MDefinition::toControlInstruction() { |
| 9753 |
MOZ_ASSERT(isControlInstruction()); |
| 9754 |
return (MControlInstruction*)this; |
| 9755 |
} |
| 9756 |
|
| 9757 |
MConstant* MDefinition::maybeConstantValue() { |
| 9758 |
MDefinition* op = this; |
| 9759 |
if (op->isBox()) { |
| 9760 |
op = op->toBox()->input(); |
| 9761 |
} |
| 9762 |
if (op->isConstant()) { |
| 9763 |
return op->toConstant(); |
| 9764 |
} |
| 9765 |
return nullptr; |
| 9766 |
} |
| 9767 |
|
| 9768 |
} // namespace jit |
| 9769 |
} // namespace js |
| 9770 |
|
| 9771 |
#endif /* jit_MIR_h */ |