Debian Codegraph @

js/src/jit/CacheIRWriter.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * 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 #ifndef jit_CacheIRWriter_h
8 #define jit_CacheIRWriter_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Casting.h"
13 #include "mozilla/Maybe.h"
14
15 #include <stddef.h>
16 #include <stdint.h>
17
18 #include "jstypes.h"
19 #include "NamespaceImports.h"
20
21 #include "gc/AllocKind.h"
22 #include "jit/ABIFunctions.h"
23 #include "jit/CacheIR.h"
24 #include "jit/CacheIROpsGenerated.h"
25 #include "jit/CompactBuffer.h"
26 #include "jit/ICState.h"
27 #include "jit/Simulator.h"
28 #include "jit/TypeData.h"
29 #include "js/AllocPolicy.h"
30 #include "js/CallArgs.h"
31 #include "js/Class.h"
32 #include "js/experimental/JitInfo.h"
33 #include "js/Id.h"
34 #include "js/RootingAPI.h"
35 #include "js/ScalarType.h"
36 #include "js/Value.h"
37 #include "js/Vector.h"
38 #include "util/Memory.h"
39 #include "vm/GuardFuse.h"
40 #include "vm/JSFunction.h"
41 #include "vm/JSScript.h"
42 #include "vm/List.h"
43 #include "vm/Opcodes.h"
44 #include "vm/RealmFuses.h"
45 #include "vm/Shape.h"
46 #include "vm/TypeofEqOperand.h" // TypeofEqOperand
47 #include "wasm/WasmConstants.h"
48 #include "wasm/WasmValType.h"
49
50 class JS_PUBLIC_API JSTracer;
51 struct JS_PUBLIC_API JSContext;
52
53 class JSObject;
54 class JSString;
55
56 namespace JS {
57 class Symbol;
58 }
59
60 namespace js {
61
62 class GetterSetter;
63 enum class UnaryMathFunction : uint8_t;
64
65 namespace gc {
66 class AllocSite;
67 }
68
69 namespace jit {
70
71 class ICScript;
72 struct CacheIRAOTStub;
73
74 // Class to record CacheIR + some additional metadata for code generation.
75 class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter {
76 #ifdef DEBUG
77 JSContext* cx_;
78 #endif
79 CompactBufferWriter buffer_;
80
81 uint32_t nextOperandId_;
82 uint32_t nextInstructionId_;
83 uint32_t numInputOperands_;
84
85 TypeData typeData_;
86
87 // The data (shapes, slot offsets, etc.) that will be stored in the ICStub.
88 Vector<StubField, 8, SystemAllocPolicy> stubFields_;
89 size_t stubDataSize_;
90
91 // For each operand id, record which instruction accessed it last. This
92 // information greatly improves register allocation.
93 Vector<uint32_t, 8, SystemAllocPolicy> operandLastUsed_;
94
95 // OperandId and stub offsets are stored in a single byte, so make sure
96 // this doesn't overflow. We use a very conservative limit for now.
97 static const size_t MaxOperandIds = 20;
98 static const size_t MaxStubDataSizeInBytes = 20 * sizeof(uintptr_t);
99 bool tooLarge_;
100
101 // Assume this stub can't be trial inlined until we see a scripted call/inline
102 // instruction.
103 TrialInliningState trialInliningState_ = TrialInliningState::Failure;
104
105 // Basic caching to avoid quadatic lookup behaviour in readStubField.
106 mutable uint32_t lastOffset_;
107 mutable uint32_t lastIndex_;
108
109 #ifdef DEBUG
110 // Information for assertLengthMatches.
111 mozilla::Maybe<CacheOp> currentOp_;
112 size_t currentOpArgsStart_ = 0;
113 #endif
114
115 #ifdef DEBUG
116 void assertSameCompartment(JSObject* obj);
117 void assertSameZone(Shape* shape);
118 #else
119 void assertSameCompartment(JSObject* obj) {}
120 void assertSameZone(Shape* shape) {}
121 #endif
122
123 void writeOp(CacheOp op) {
124 buffer_.writeFixedUint16_t(uint16_t(op));
125 nextInstructionId_++;
126 #ifdef DEBUG
127 MOZ_ASSERT(currentOp_.isNothing(), "Missing call to assertLengthMatches?");
128 currentOp_.emplace(op);
129 currentOpArgsStart_ = buffer_.length();
130 #endif
131 }
132
133 void assertLengthMatches() {
134 #ifdef DEBUG
135 // After writing arguments, assert the length matches CacheIROpArgLengths.
136 size_t expectedLen = CacheIROpInfos[size_t(*currentOp_)].argLength;
137 MOZ_ASSERT_IF(!failed(),
138 buffer_.length() - currentOpArgsStart_ == expectedLen);
139 currentOp_.reset();
140 #endif
141 }
142
143 void writeOperandId(OperandId opId) {
144 if (opId.id() < MaxOperandIds) {
145 static_assert(MaxOperandIds <= UINT8_MAX,
146 "operand id must fit in a single byte");
147 buffer_.writeByte(opId.id());
148 } else {
149 tooLarge_ = true;
150 return;
151 }
152 if (opId.id() >= operandLastUsed_.length()) {
153 buffer_.propagateOOM(operandLastUsed_.resize(opId.id() + 1));
154 if (buffer_.oom()) {
155 return;
156 }
157 }
158 MOZ_ASSERT(nextInstructionId_ > 0);
159 operandLastUsed_[opId.id()] = nextInstructionId_ - 1;
160 }
161
162 void writeCallFlagsImm(CallFlags flags) { buffer_.writeByte(flags.toByte()); }
163
164 void addStubField(uint64_t value, StubField::Type fieldType) {
165 size_t fieldOffset = stubDataSize_;
166 #ifndef JS_64BIT
167 // On 32-bit platforms there are two stub field sizes (4 bytes and 8 bytes).
168 // Ensure 8-byte fields are properly aligned.
169 if (StubField::sizeIsInt64(fieldType)) {
170 fieldOffset = AlignBytes(fieldOffset, sizeof(uint64_t));
171 }
172 #endif
173 MOZ_ASSERT((fieldOffset % StubField::sizeInBytes(fieldType)) == 0);
174
175 size_t newStubDataSize = fieldOffset + StubField::sizeInBytes(fieldType);
176 if (newStubDataSize < MaxStubDataSizeInBytes) {
177 #ifndef JS_64BIT
178 // Add a RawInt32 stub field for padding if necessary, because when we
179 // iterate over the stub fields we assume there are no 'holes'.
180 if (fieldOffset != stubDataSize_) {
181 MOZ_ASSERT((stubDataSize_ + sizeof(uintptr_t)) == fieldOffset);
182 buffer_.propagateOOM(
183 stubFields_.append(StubField(0, StubField::Type::RawInt32)));
184 }
185 #endif
186 buffer_.propagateOOM(stubFields_.append(StubField(value, fieldType)));
187 MOZ_ASSERT((fieldOffset % sizeof(uintptr_t)) == 0);
188 buffer_.writeByte(fieldOffset / sizeof(uintptr_t));
189 stubDataSize_ = newStubDataSize;
190 } else {
191 tooLarge_ = true;
192 }
193 }
194
195 void writeShapeField(Shape* shape) {
196 MOZ_ASSERT(shape);
197 assertSameZone(shape);
198 addStubField(uintptr_t(shape), StubField::Type::Shape);
199 }
200 void writeWeakShapeField(Shape* shape) {
201 MOZ_ASSERT(shape);
202 assertSameZone(shape);
203 addStubField(uintptr_t(shape), StubField::Type::WeakShape);
204 }
205 void writeWeakGetterSetterField(GetterSetter* gs) {
206 MOZ_ASSERT(gs);
207 addStubField(uintptr_t(gs), StubField::Type::WeakGetterSetter);
208 }
209 void writeObjectField(JSObject* obj) {
210 MOZ_ASSERT(obj);
211 assertSameCompartment(obj);
212 addStubField(uintptr_t(obj), StubField::Type::JSObject);
213 }
214 void writeWeakObjectField(JSObject* obj) {
215 MOZ_ASSERT(obj);
216 assertSameCompartment(obj);
217 addStubField(uintptr_t(obj), StubField::Type::WeakObject);
218 }
219 void writeStringField(JSString* str) {
220 MOZ_ASSERT(str);
221 addStubField(uintptr_t(str), StubField::Type::String);
222 }
223 void writeSymbolField(JS::Symbol* sym) {
224 MOZ_ASSERT(sym);
225 addStubField(uintptr_t(sym), StubField::Type::Symbol);
226 }
227 void writeWeakBaseScriptField(BaseScript* script) {
228 MOZ_ASSERT(script);
229 addStubField(uintptr_t(script), StubField::Type::WeakBaseScript);
230 }
231 void writeJitCodeField(JitCode* code) {
232 MOZ_ASSERT(code);
233 addStubField(uintptr_t(code), StubField::Type::JitCode);
234 }
235 void writeRawInt32Field(uint32_t val) {
236 addStubField(val, StubField::Type::RawInt32);
237 }
238 void writeRawPointerField(const void* ptr) {
239 addStubField(uintptr_t(ptr), StubField::Type::RawPointer);
240 }
241 void writeICScriptField(const ICScript* icScript) {
242 addStubField(uintptr_t(icScript), StubField::Type::ICScript);
243 }
244 void writeIdField(jsid id) {
245 addStubField(id.asRawBits(), StubField::Type::Id);
246 }
247 void writeValueField(const Value& val) {
248 addStubField(val.asRawBits(), StubField::Type::Value);
249 }
250 void writeRawInt64Field(uint64_t val) {
251 addStubField(val, StubField::Type::RawInt64);
252 }
253 void writeDoubleField(double d) {
254 uint64_t bits = mozilla::BitwiseCast<uint64_t>(d);
255 addStubField(bits, StubField::Type::Double);
256 }
257 void writeAllocSiteField(gc::AllocSite* ptr) {
258 addStubField(uintptr_t(ptr), StubField::Type::AllocSite);
259 }
260
261 void writeJSOpImm(JSOp op) {
262 static_assert(sizeof(JSOp) == sizeof(uint8_t), "JSOp must fit in a byte");
263 buffer_.writeByte(uint8_t(op));
264 }
265 void writeTypeofEqOperandImm(TypeofEqOperand operand) {
266 buffer_.writeByte(operand.rawValue());
267 }
268 void writeGuardClassKindImm(GuardClassKind kind) {
269 static_assert(sizeof(GuardClassKind) == sizeof(uint8_t),
270 "GuardClassKind must fit in a byte");
271 buffer_.writeByte(uint8_t(kind));
272 }
273 void writeArrayBufferViewKindImm(ArrayBufferViewKind kind) {
274 static_assert(sizeof(ArrayBufferViewKind) == sizeof(uint8_t),
275 "ArrayBufferViewKind must fit in a byte");
276 buffer_.writeByte(uint8_t(kind));
277 }
278 void writeValueTypeImm(ValueType type) {
279 static_assert(sizeof(ValueType) == sizeof(uint8_t),
280 "ValueType must fit in uint8_t");
281 buffer_.writeByte(uint8_t(type));
282 }
283 void writeJSWhyMagicImm(JSWhyMagic whyMagic) {
284 static_assert(JS_WHY_MAGIC_COUNT <= UINT8_MAX,
285 "JSWhyMagic must fit in uint8_t");
286 buffer_.writeByte(uint8_t(whyMagic));
287 }
288 void writeScalarTypeImm(Scalar::Type type) {
289 MOZ_ASSERT(size_t(type) <= UINT8_MAX);
290 buffer_.writeByte(uint8_t(type));
291 }
292 void writeUnaryMathFunctionImm(UnaryMathFunction fun) {
293 static_assert(sizeof(UnaryMathFunction) == sizeof(uint8_t),
294 "UnaryMathFunction must fit in a byte");
295 buffer_.writeByte(uint8_t(fun));
296 }
297 void writeCompletionKindImm(CompletionKind kind) {
298 static_assert(sizeof(CompletionKind) == sizeof(uint8_t),
299 "CompletionKind must fit in a byte");
300 buffer_.writeByte(uint8_t(kind));
301 }
302 void writeBoolImm(bool b) { buffer_.writeByte(uint32_t(b)); }
303 void writeRealmFuseIndexImm(RealmFuses::FuseIndex realmFuseIndex) {
304 static_assert(sizeof(RealmFuses::FuseIndex) == sizeof(uint8_t),
305 "RealmFuses::FuseIndex must fit in a byte");
306 buffer_.writeByte(uint8_t(realmFuseIndex));
307 }
308
309 void writeByteImm(uint32_t b) {
310 MOZ_ASSERT(b <= UINT8_MAX);
311 buffer_.writeByte(b);
312 }
313
314 void writeInt32Imm(int32_t i32) { buffer_.writeFixedUint32_t(i32); }
315 void writeUInt32Imm(uint32_t u32) { buffer_.writeFixedUint32_t(u32); }
316 void writePointer(const void* ptr) { buffer_.writeRawPointer(ptr); }
317
318 void writeJSNativeImm(JSNative native) {
319 writePointer(JS_FUNC_TO_DATA_PTR(void*, native));
320 }
321 void writeStaticStringImm(const char* str) { writePointer(str); }
322
323 void writeWasmValTypeImm(wasm::ValType::Kind kind) {
324 static_assert(unsigned(wasm::TypeCode::Limit) <= UINT8_MAX);
325 buffer_.writeByte(uint8_t(kind));
326 }
327
328 void writeAllocKindImm(gc::AllocKind kind) {
329 static_assert(unsigned(gc::AllocKind::LIMIT) <= UINT8_MAX);
330 buffer_.writeByte(uint8_t(kind));
331 }
332
333 uint32_t newOperandId() { return nextOperandId_++; }
334
335 CacheIRWriter(const CacheIRWriter&) = delete;
336 CacheIRWriter& operator=(const CacheIRWriter&) = delete;
337
338 public:
339 explicit CacheIRWriter(JSContext* cx)
340 : CustomAutoRooter(cx),
341 #ifdef DEBUG
342 cx_(cx),
343 #endif
344 nextOperandId_(0),
345 nextInstructionId_(0),
346 numInputOperands_(0),
347 stubDataSize_(0),
348 tooLarge_(false),
349 lastOffset_(0),
350 lastIndex_(0) {
351 }
352
353 #ifdef ENABLE_JS_AOT_ICS
354 CacheIRWriter(JSContext* cx, const CacheIRAOTStub& aot);
355 #endif
356
357 bool tooLarge() const { return tooLarge_; }
358 bool oom() const { return buffer_.oom(); }
359 bool failed() const { return tooLarge() || oom(); }
360
361 TrialInliningState trialInliningState() const { return trialInliningState_; }
362
363 uint32_t numInputOperands() const { return numInputOperands_; }
364 uint32_t numOperandIds() const { return nextOperandId_; }
365 uint32_t numInstructions() const { return nextInstructionId_; }
366
367 size_t numStubFields() const { return stubFields_.length(); }
368 const StubField& stubField(uint32_t i) const { return stubFields_[i]; }
369 StubField::Type stubFieldType(uint32_t i) const {
370 return stubFields_[i].type();
371 }
372
373 uint32_t setInputOperandId(uint32_t op) {
374 MOZ_ASSERT(op == nextOperandId_);
375 nextOperandId_++;
376 numInputOperands_++;
377 return op;
378 }
379
380 TypeData typeData() const { return typeData_; }
381 void setTypeData(TypeData data) { typeData_ = data; }
382
383 void trace(JSTracer* trc) override {
384 // For now, assert we only GC before we append stub fields.
385 MOZ_RELEASE_ASSERT(stubFields_.empty());
386 }
387
388 size_t stubDataSize() const { return stubDataSize_; }
389 void copyStubData(uint8_t* dest) const;
390 bool stubDataEquals(const uint8_t* stubData) const;
391 bool stubDataEqualsIgnoring(const uint8_t* stubData,
392 uint32_t ignoreOffset) const;
393
394 bool operandIsDead(uint32_t operandId, uint32_t currentInstruction) const {
395 if (operandId >= operandLastUsed_.length()) {
396 return false;
397 }
398 return currentInstruction > operandLastUsed_[operandId];
399 }
400 uint32_t operandLastUsed(uint32_t operandId) const {
401 return operandLastUsed_[operandId];
402 }
403
404 const uint8_t* codeStart() const {
405 MOZ_ASSERT(!failed());
406 return buffer_.buffer();
407 }
408
409 const uint8_t* codeEnd() const {
410 MOZ_ASSERT(!failed());
411 return buffer_.buffer() + buffer_.length();
412 }
413
414 uint32_t codeLength() const {
415 MOZ_ASSERT(!failed());
416 return buffer_.length();
417 }
418
419 // This should not be used when compiling Baseline code, as Baseline code
420 // shouldn't bake in stub values.
421 StubField readStubField(uint32_t offset, StubField::Type type) const;
422
423 ObjOperandId guardToObject(ValOperandId input) {
424 guardToObject_(input);
425 return ObjOperandId(input.id());
426 }
427
428 StringOperandId guardToString(ValOperandId input) {
429 guardToString_(input);
430 return StringOperandId(input.id());
431 }
432
433 SymbolOperandId guardToSymbol(ValOperandId input) {
434 guardToSymbol_(input);
435 return SymbolOperandId(input.id());
436 }
437
438 BigIntOperandId guardToBigInt(ValOperandId input) {
439 guardToBigInt_(input);
440 return BigIntOperandId(input.id());
441 }
442
443 BooleanOperandId guardToBoolean(ValOperandId input) {
444 guardToBoolean_(input);
445 return BooleanOperandId(input.id());
446 }
447
448 Int32OperandId guardToInt32(ValOperandId input) {
449 guardToInt32_(input);
450 return Int32OperandId(input.id());
451 }
452
453 NumberOperandId guardIsNumber(ValOperandId input) {
454 guardIsNumber_(input);
455 return NumberOperandId(input.id());
456 }
457
458 StringOperandId stringToAtom(StringOperandId input) {
459 stringToAtom_(input);
460 return input;
461 }
462
463 ValOperandId boxObject(ObjOperandId input) {
464 return ValOperandId(input.id());
465 }
466
467 void guardShapeForClass(ObjOperandId obj, Shape* shape) {
468 // Guard shape to ensure that object class is unchanged. This is true
469 // for all shapes.
470 guardShape(obj, shape);
471 }
472
473 void guardShapeForOwnProperties(ObjOperandId obj, Shape* shape) {
474 // Guard shape to detect changes to (non-dense) own properties. This
475 // also implies |guardShapeForClass|.
476 MOZ_ASSERT(shape->getObjectClass()->isNativeObject());
477 guardShape(obj, shape);
478 }
479
480 public:
481 void guardSpecificFunction(ObjOperandId obj, JSFunction* expected) {
482 // Guard object is a specific function. This implies immutable fields on
483 // the JSFunction struct itself are unchanged.
484 // Bake in the nargs and FunctionFlags so Warp can use them off-main thread,
485 // instead of directly using the JSFunction fields.
486 uint32_t nargsAndFlags = expected->flagsAndArgCountRaw();
487 guardSpecificFunction_(obj, expected, nargsAndFlags);
488 }
489
490 void guardFunctionScript(ObjOperandId fun, BaseScript* expected) {
491 // Guard function has a specific BaseScript. This implies immutable fields
492 // on the JSFunction struct itself are unchanged and are equivalent for
493 // lambda clones.
494 // Bake in the nargs and FunctionFlags so Warp can use them off-main thread,
495 // instead of directly using the JSFunction fields.
496 uint32_t nargsAndFlags = expected->function()->flagsAndArgCountRaw();
497 guardFunctionScript_(fun, expected, nargsAndFlags);
498 }
499
500 ValOperandId loadArgumentFixedSlot(ArgumentKind kind, uint32_t argc,
501 CallFlags flags) {
502 bool addArgc;
503 int32_t slotIndex = GetIndexOfArgument(kind, flags, &addArgc);
504 if (addArgc) {
505 slotIndex += argc;
506 }
507 MOZ_ASSERT(slotIndex >= 0);
508 MOZ_RELEASE_ASSERT(slotIndex <= UINT8_MAX);
509 return loadArgumentFixedSlot_(slotIndex);
510 }
511
512 ValOperandId loadArgumentDynamicSlot(ArgumentKind kind, Int32OperandId argcId,
513 CallFlags flags) {
514 bool addArgc;
515 int32_t slotIndex = GetIndexOfArgument(kind, flags, &addArgc);
516 if (addArgc) {
517 return loadArgumentDynamicSlot_(argcId, slotIndex);
518 }
519 return loadArgumentFixedSlot_(slotIndex);
520 }
521
522 ObjOperandId loadSpreadArgs() {
523 ArgumentKind kind = ArgumentKind::Arg0;
524 uint32_t argc = 1;
525 CallFlags flags(CallFlags::Spread);
526 return ObjOperandId(loadArgumentFixedSlot(kind, argc, flags).id());
527 }
528
529 void callScriptedFunction(ObjOperandId callee, Int32OperandId argc,
530 CallFlags flags, uint32_t argcFixed) {
531 callScriptedFunction_(callee, argc, flags, argcFixed);
532 trialInliningState_ = TrialInliningState::Candidate;
533 }
534
535 void callInlinedFunction(ObjOperandId callee, Int32OperandId argc,
536 ICScript* icScript, CallFlags flags,
537 uint32_t argcFixed) {
538 callInlinedFunction_(callee, argc, icScript, flags, argcFixed);
539 trialInliningState_ = TrialInliningState::Inlined;
540 }
541
542 void callNativeFunction(ObjOperandId calleeId, Int32OperandId argc, JSOp op,
543 JSFunction* calleeFunc, CallFlags flags,
544 uint32_t argcFixed) {
545 // Some native functions can be implemented faster if we know that
546 // the return value is ignored.
547 bool ignoresReturnValue =
548 op == JSOp::CallIgnoresRv && calleeFunc->hasJitInfo() &&
549 calleeFunc->jitInfo()->type() == JSJitInfo::IgnoresReturnValueNative;
550
551 #ifdef JS_SIMULATOR
552 // The simulator requires VM calls to be redirected to a special
553 // swi instruction to handle them, so we store the redirected
554 // pointer in the stub and use that instead of the original one.
555 // If we are calling the ignoresReturnValue version of a native
556 // function, we bake it into the redirected pointer.
557 // (See BaselineCacheIRCompiler::emitCallNativeFunction.)
558 JSNative target = ignoresReturnValue
559 ? calleeFunc->jitInfo()->ignoresReturnValueMethod
560 : calleeFunc->native();
561 void* rawPtr = JS_FUNC_TO_DATA_PTR(void*, target);
562 void* redirected = Simulator::RedirectNativeFunction(rawPtr, Args_General3);
563 callNativeFunction_(calleeId, argc, flags, argcFixed, redirected);
564 #else
565 // If we are not running in the simulator, we generate different jitcode
566 // to find the ignoresReturnValue version of a native function.
567 callNativeFunction_(calleeId, argc, flags, argcFixed, ignoresReturnValue);
568 #endif
569 }
570
571 void callDOMFunction(ObjOperandId calleeId, Int32OperandId argc,
572 ObjOperandId thisObjId, JSFunction* calleeFunc,
573 CallFlags flags, uint32_t argcFixed) {
574 #ifdef JS_SIMULATOR
575 void* rawPtr = JS_FUNC_TO_DATA_PTR(void*, calleeFunc->native());
576 void* redirected = Simulator::RedirectNativeFunction(rawPtr, Args_General3);
577 callDOMFunction_(calleeId, argc, thisObjId, flags, argcFixed, redirected);
578 #else
579 callDOMFunction_(calleeId, argc, thisObjId, flags, argcFixed);
580 #endif
581 }
582
583 void callDOMFunctionWithAllocSite(ObjOperandId calleeId, Int32OperandId argc,
584 ObjOperandId thisObjId,
585 JSFunction* calleeFunc, CallFlags flags,
586 uint32_t argcFixed,
587 gc::AllocSite* allocSite) {
588 #ifdef JS_SIMULATOR
589 void* rawPtr = JS_FUNC_TO_DATA_PTR(void*, calleeFunc->native());
590 void* redirected = Simulator::RedirectNativeFunction(rawPtr, Args_General3);
591 callDOMFunctionWithAllocSite_(calleeId, argc, thisObjId, flags, argcFixed,
592 allocSite, redirected);
593 #else
594 callDOMFunctionWithAllocSite_(calleeId, argc, thisObjId, flags, argcFixed,
595 allocSite);
596 #endif
597 }
598
599 void callAnyNativeFunction(ObjOperandId calleeId, Int32OperandId argc,
600 CallFlags flags, uint32_t argcFixed) {
601 MOZ_ASSERT(!flags.isSameRealm());
602 #ifdef JS_SIMULATOR
603 const void* redirected = RedirectedCallAnyNative();
604 callNativeFunction_(calleeId, argc, flags, argcFixed, redirected);
605 #else
606 callNativeFunction_(calleeId, argc, flags, argcFixed,
607 /* ignoresReturnValue = */ false);
608 #endif
609 }
610
611 void callClassHook(ObjOperandId calleeId, Int32OperandId argc, JSNative hook,
612 CallFlags flags, uint32_t argcFixed) {
613 MOZ_ASSERT(!flags.isSameRealm());
614 void* target = JS_FUNC_TO_DATA_PTR(void*, hook);
615 #ifdef JS_SIMULATOR
616 // The simulator requires VM calls to be redirected to a special
617 // swi instruction to handle them, so we store the redirected
618 // pointer in the stub and use that instead of the original one.
619 target = Simulator::RedirectNativeFunction(target, Args_General3);
620 #endif
621 callClassHook_(calleeId, argc, flags, argcFixed, target);
622 }
623
624 void callScriptedGetterResult(ValOperandId receiver, JSFunction* getter,
625 bool sameRealm) {
626 MOZ_ASSERT(getter->hasJitEntry());
627 uint32_t nargsAndFlags = getter->flagsAndArgCountRaw();
628 callScriptedGetterResult_(receiver, getter, sameRealm, nargsAndFlags);
629 trialInliningState_ = TrialInliningState::Candidate;
630 }
631
632 void callInlinedGetterResult(ValOperandId receiver, JSFunction* getter,
633 ICScript* icScript, bool sameRealm) {
634 MOZ_ASSERT(getter->hasJitEntry());
635 uint32_t nargsAndFlags = getter->flagsAndArgCountRaw();
636 callInlinedGetterResult_(receiver, getter, icScript, sameRealm,
637 nargsAndFlags);
638 trialInliningState_ = TrialInliningState::Inlined;
639 }
640
641 void callNativeGetterResult(ValOperandId receiver, JSFunction* getter,
642 bool sameRealm) {
643 MOZ_ASSERT(getter->isNativeWithoutJitEntry());
644 uint32_t nargsAndFlags = getter->flagsAndArgCountRaw();
645 callNativeGetterResult_(receiver, getter, sameRealm, nargsAndFlags);
646 }
647
648 void callScriptedSetter(ObjOperandId receiver, JSFunction* setter,
649 ValOperandId rhs, bool sameRealm) {
650 MOZ_ASSERT(setter->hasJitEntry());
651 uint32_t nargsAndFlags = setter->flagsAndArgCountRaw();
652 callScriptedSetter_(receiver, setter, rhs, sameRealm, nargsAndFlags);
653 trialInliningState_ = TrialInliningState::Candidate;
654 }
655
656 void callInlinedSetter(ObjOperandId receiver, JSFunction* setter,
657 ValOperandId rhs, ICScript* icScript, bool sameRealm) {
658 MOZ_ASSERT(setter->hasJitEntry());
659 uint32_t nargsAndFlags = setter->flagsAndArgCountRaw();
660 callInlinedSetter_(receiver, setter, rhs, icScript, sameRealm,
661 nargsAndFlags);
662 trialInliningState_ = TrialInliningState::Inlined;
663 }
664
665 void callNativeSetter(ObjOperandId receiver, JSFunction* setter,
666 ValOperandId rhs, bool sameRealm) {
667 MOZ_ASSERT(setter->isNativeWithoutJitEntry());
668 uint32_t nargsAndFlags = setter->flagsAndArgCountRaw();
669 callNativeSetter_(receiver, setter, rhs, sameRealm, nargsAndFlags);
670 }
671
672 #ifdef JS_PUNBOX64
673 void callScriptedProxyGetResult(ValOperandId target, ObjOperandId receiver,
674 ObjOperandId handler, ObjOperandId trapId,
675 JSFunction* trap, HandleId property) {
676 MOZ_ASSERT(trap->hasJitEntry());
677 uint32_t nargsAndFlags = trap->flagsAndArgCountRaw();
678 callScriptedProxyGetResult_(target, receiver, handler, trapId, property,
679 nargsAndFlags);
680 }
681
682 void callScriptedProxyGetByValueResult(
683 ValOperandId target, ObjOperandId receiver, ObjOperandId handler,
684 ValOperandId property, ObjOperandId trapId, JSFunction* trap) {
685 MOZ_ASSERT(trap->hasJitEntry());
686 uint32_t nargsAndFlags = trap->flagsAndArgCountRaw();
687 callScriptedProxyGetByValueResult_(target, receiver, handler, property,
688 trapId, nargsAndFlags);
689 }
690 #endif
691
692 void metaScriptedThisShape(Shape* thisShape) {
693 metaScriptedThisShape_(thisShape);
694 }
695
696 void guardMultipleShapes(ObjOperandId obj, ListObject* shapes) {
697 MOZ_ASSERT(shapes->length() > 0);
698 guardMultipleShapes_(obj, shapes);
699 }
700
701 friend class CacheIRCloner;
702
703 CACHE_IR_WRITER_GENERATED
704 };
705
706 } // namespace jit
707 } // namespace js
708
709 #endif /* jit_CacheIRWriter_h */