Debian Codegraph @

js/src/jit/CacheIRGenerator.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_CacheIRGenerator_h
8 #define jit_CacheIRGenerator_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Maybe.h"
13
14 #include <stdint.h>
15
16 #include "jstypes.h"
17 #include "NamespaceImports.h"
18
19 #include "jit/CacheIR.h"
20 #include "jit/CacheIRWriter.h"
21 #include "jit/ICState.h"
22 #include "js/Id.h"
23 #include "js/RootingAPI.h"
24 #include "js/ScalarType.h"
25 #include "js/TypeDecls.h"
26 #include "js/Value.h"
27 #include "js/ValueArray.h"
28 #include "vm/Opcodes.h"
29
30 class JSFunction;
31
32 namespace JS {
33 struct XrayJitInfo;
34 }
35
36 namespace js {
37
38 class BoundFunctionObject;
39 class NativeObject;
40 class PropertyResult;
41 class ProxyObject;
42 enum class UnaryMathFunction : uint8_t;
43
44 namespace jit {
45
46 class BaselineFrame;
47 class Label;
48 class MacroAssembler;
49 struct Register;
50 enum class InlinableNative : uint16_t;
51
52 // Some ops refer to shapes that might be in other zones. Instead of putting
53 // cross-zone pointers in the caches themselves (which would complicate tracing
54 // enormously), these ops instead contain wrappers for objects in the target
55 // zone, which refer to the actual shape via a reserved slot.
56 void LoadShapeWrapperContents(MacroAssembler& masm, Register obj, Register dst,
57 Label* failure);
58
59 class MOZ_RAII IRGenerator {
60 protected:
61 CacheIRWriter writer;
62 JSContext* cx_;
63 HandleScript script_;
64 jsbytecode* pc_;
65 BaselineFrame* maybeFrame_;
66 CacheKind cacheKind_;
67 ICState::Mode mode_;
68 bool isFirstStub_;
69 uint8_t numOptimizedStubs_;
70
71 // Important: This pointer may be passed to the profiler. If this is non-null,
72 // it must point to a C string literal with static lifetime, not a heap- or
73 // stack- allocated string.
74 const char* stubName_ = nullptr;
75
76 IRGenerator(const IRGenerator&) = delete;
77 IRGenerator& operator=(const IRGenerator&) = delete;
78
79 bool maybeGuardInt32Index(const Value& index, ValOperandId indexId,
80 uint32_t* int32Index, Int32OperandId* int32IndexId);
81
82 IntPtrOperandId guardToIntPtrIndex(const Value& index, ValOperandId indexId,
83 bool supportOOB);
84
85 ObjOperandId guardDOMProxyExpandoObjectAndShape(ProxyObject* obj,
86 ObjOperandId objId,
87 const Value& expandoVal,
88 NativeObject* expandoObj);
89
90 void emitIdGuard(ValOperandId valId, const Value& idVal, jsid id);
91
92 OperandId emitNumericGuard(ValOperandId valId, const Value& v,
93 Scalar::Type type);
94
95 StringOperandId emitToStringGuard(ValOperandId id, const Value& v);
96
97 void emitCalleeGuard(ObjOperandId calleeId, JSFunction* callee);
98
99 void emitOptimisticClassGuard(ObjOperandId objId, JSObject* obj,
100 GuardClassKind kind);
101
102 gc::AllocSite* maybeCreateAllocSite();
103
104 friend class CacheIRSpewer;
105
106 public:
107 explicit IRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
108 CacheKind cacheKind, ICState state,
109 BaselineFrame* maybeFrame = nullptr);
110
111 const CacheIRWriter& writerRef() const { return writer; }
112 CacheKind cacheKind() const { return cacheKind_; }
113
114 // See comment on `stubName_` above.
115 const char* stubName() const { return stubName_; }
116
117 static constexpr char* NotAttached = nullptr;
118 };
119
120 // GetPropIRGenerator generates CacheIR for a GetProp IC.
121 class MOZ_RAII GetPropIRGenerator : public IRGenerator {
122 HandleValue val_;
123 HandleValue idVal_;
124
125 AttachDecision tryAttachNative(HandleObject obj, ObjOperandId objId,
126 HandleId id, ValOperandId receiverId);
127 AttachDecision tryAttachObjectLength(HandleObject obj, ObjOperandId objId,
128 HandleId id);
129 AttachDecision tryAttachTypedArray(HandleObject obj, ObjOperandId objId,
130 HandleId id);
131 AttachDecision tryAttachDataView(HandleObject obj, ObjOperandId objId,
132 HandleId id);
133 AttachDecision tryAttachArrayBufferMaybeShared(HandleObject obj,
134 ObjOperandId objId,
135 HandleId id);
136 AttachDecision tryAttachRegExp(HandleObject obj, ObjOperandId objId,
137 HandleId id);
138 AttachDecision tryAttachMap(HandleObject obj, ObjOperandId objId,
139 HandleId id);
140 AttachDecision tryAttachSet(HandleObject obj, ObjOperandId objId,
141 HandleId id);
142 AttachDecision tryAttachModuleNamespace(HandleObject obj, ObjOperandId objId,
143 HandleId id);
144 AttachDecision tryAttachWindowProxy(HandleObject obj, ObjOperandId objId,
145 HandleId id);
146 AttachDecision tryAttachCrossCompartmentWrapper(HandleObject obj,
147 ObjOperandId objId,
148 HandleId id);
149 AttachDecision tryAttachXrayCrossCompartmentWrapper(HandleObject obj,
150 ObjOperandId objId,
151 HandleId id,
152 ValOperandId receiverId);
153 AttachDecision tryAttachFunction(HandleObject obj, ObjOperandId objId,
154 HandleId id);
155 AttachDecision tryAttachArgumentsObjectIterator(HandleObject obj,
156 ObjOperandId objId,
157 HandleId id);
158
159 AttachDecision tryAttachGenericProxy(Handle<ProxyObject*> obj,
160 ObjOperandId objId, HandleId id,
161 bool handleDOMProxies);
162 #ifdef JS_PUNBOX64
163 AttachDecision tryAttachScriptedProxy(Handle<ProxyObject*> obj,
164 ObjOperandId objId, HandleId id);
165 #endif
166 AttachDecision tryAttachDOMProxyExpando(Handle<ProxyObject*> obj,
167 ObjOperandId objId, HandleId id,
168 ValOperandId receiverId);
169 AttachDecision tryAttachDOMProxyShadowed(Handle<ProxyObject*> obj,
170 ObjOperandId objId, HandleId id);
171 AttachDecision tryAttachDOMProxyUnshadowed(Handle<ProxyObject*> obj,
172 ObjOperandId objId, HandleId id,
173 ValOperandId receiverId);
174 AttachDecision tryAttachProxy(HandleObject obj, ObjOperandId objId,
175 HandleId id, ValOperandId receiverId);
176
177 AttachDecision tryAttachPrimitive(ValOperandId valId, HandleId id);
178 AttachDecision tryAttachStringChar(ValOperandId valId, ValOperandId indexId);
179 AttachDecision tryAttachStringLength(ValOperandId valId, HandleId id);
180
181 AttachDecision tryAttachArgumentsObjectArg(HandleObject obj,
182 ObjOperandId objId, uint32_t index,
183 Int32OperandId indexId);
184 AttachDecision tryAttachArgumentsObjectArgHole(HandleObject obj,
185 ObjOperandId objId,
186 uint32_t index,
187 Int32OperandId indexId);
188 AttachDecision tryAttachArgumentsObjectCallee(HandleObject obj,
189 ObjOperandId objId,
190 HandleId id);
191
192 AttachDecision tryAttachDenseElement(HandleObject obj, ObjOperandId objId,
193 uint32_t index, Int32OperandId indexId);
194 AttachDecision tryAttachDenseElementHole(HandleObject obj, ObjOperandId objId,
195 uint32_t index,
196 Int32OperandId indexId);
197 AttachDecision tryAttachSparseElement(HandleObject obj, ObjOperandId objId,
198 uint32_t index, Int32OperandId indexId);
199 AttachDecision tryAttachTypedArrayElement(HandleObject obj,
200 ObjOperandId objId);
201
202 AttachDecision tryAttachGenericElement(HandleObject obj, ObjOperandId objId,
203 uint32_t index, Int32OperandId indexId,
204 ValOperandId receiverId);
205
206 AttachDecision tryAttachProxyElement(HandleObject obj, ObjOperandId objId);
207
208 void attachMegamorphicNativeSlot(ObjOperandId objId, jsid id);
209
210 void attachMegamorphicNativeSlotPermissive(ObjOperandId objId, jsid id);
211
212 ValOperandId getElemKeyValueId() const {
213 MOZ_ASSERT(cacheKind_ == CacheKind::GetElem ||
214 cacheKind_ == CacheKind::GetElemSuper);
215 return ValOperandId(1);
216 }
217
218 ValOperandId getSuperReceiverValueId() const {
219 if (cacheKind_ == CacheKind::GetPropSuper) {
220 return ValOperandId(1);
221 }
222
223 MOZ_ASSERT(cacheKind_ == CacheKind::GetElemSuper);
224 return ValOperandId(2);
225 }
226
227 bool isSuper() const {
228 return (cacheKind_ == CacheKind::GetPropSuper ||
229 cacheKind_ == CacheKind::GetElemSuper);
230 }
231
232 // If this is a GetElem cache, emit instructions to guard the incoming Value
233 // matches |id|.
234 void maybeEmitIdGuard(jsid id);
235
236 void trackAttached(const char* name /* must be a C string literal */);
237
238 public:
239 GetPropIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
240 ICState state, CacheKind cacheKind, HandleValue val,
241 HandleValue idVal);
242
243 AttachDecision tryAttachStub();
244 };
245
246 // GetNameIRGenerator generates CacheIR for a GetName IC.
247 class MOZ_RAII GetNameIRGenerator : public IRGenerator {
248 HandleObject env_;
249 Handle<PropertyName*> name_;
250
251 AttachDecision tryAttachGlobalNameValue(ObjOperandId objId, HandleId id);
252 AttachDecision tryAttachGlobalNameGetter(ObjOperandId objId, HandleId id);
253 AttachDecision tryAttachEnvironmentName(ObjOperandId objId, HandleId id);
254
255 void trackAttached(const char* name /* must be a C string literal */);
256
257 public:
258 GetNameIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
259 ICState state, HandleObject env,
260 Handle<PropertyName*> name);
261
262 AttachDecision tryAttachStub();
263 };
264
265 // BindNameIRGenerator generates CacheIR for a BindName IC.
266 class MOZ_RAII BindNameIRGenerator : public IRGenerator {
267 HandleObject env_;
268 Handle<PropertyName*> name_;
269
270 AttachDecision tryAttachGlobalName(ObjOperandId objId, HandleId id);
271 AttachDecision tryAttachEnvironmentName(ObjOperandId objId, HandleId id);
272
273 void trackAttached(const char* name /* must be a C string literal */);
274
275 public:
276 BindNameIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
277 ICState state, HandleObject env,
278 Handle<PropertyName*> name);
279
280 AttachDecision tryAttachStub();
281 };
282
283 // SetPropIRGenerator generates CacheIR for a SetProp IC.
284 class MOZ_RAII SetPropIRGenerator : public IRGenerator {
285 HandleValue lhsVal_;
286 HandleValue idVal_;
287 HandleValue rhsVal_;
288
289 public:
290 enum class DeferType { None, AddSlot };
291
292 private:
293 DeferType deferType_ = DeferType::None;
294
295 ValOperandId setElemKeyValueId() const {
296 MOZ_ASSERT(cacheKind_ == CacheKind::SetElem);
297 return ValOperandId(1);
298 }
299
300 ValOperandId rhsValueId() const {
301 if (cacheKind_ == CacheKind::SetProp) {
302 return ValOperandId(1);
303 }
304 MOZ_ASSERT(cacheKind_ == CacheKind::SetElem);
305 return ValOperandId(2);
306 }
307
308 // If this is a SetElem cache, emit instructions to guard the incoming Value
309 // matches |id|.
310 void maybeEmitIdGuard(jsid id);
311
312 AttachDecision tryAttachNativeSetSlot(HandleObject obj, ObjOperandId objId,
313 HandleId id, ValOperandId rhsId);
314 AttachDecision tryAttachMegamorphicSetSlot(HandleObject obj,
315 ObjOperandId objId, HandleId id,
316 ValOperandId rhsId);
317 AttachDecision tryAttachSetter(HandleObject obj, ObjOperandId objId,
318 HandleId id, ValOperandId rhsId);
319 AttachDecision tryAttachSetArrayLength(HandleObject obj, ObjOperandId objId,
320 HandleId id, ValOperandId rhsId);
321 AttachDecision tryAttachWindowProxy(HandleObject obj, ObjOperandId objId,
322 HandleId id, ValOperandId rhsId);
323
324 AttachDecision tryAttachSetDenseElement(HandleObject obj, ObjOperandId objId,
325 uint32_t index,
326 Int32OperandId indexId,
327 ValOperandId rhsId);
328 AttachDecision tryAttachSetTypedArrayElement(HandleObject obj,
329 ObjOperandId objId,
330 ValOperandId rhsId);
331
332 AttachDecision tryAttachSetDenseElementHole(HandleObject obj,
333 ObjOperandId objId,
334 uint32_t index,
335 Int32OperandId indexId,
336 ValOperandId rhsId);
337
338 AttachDecision tryAttachAddOrUpdateSparseElement(HandleObject obj,
339 ObjOperandId objId,
340 uint32_t index,
341 Int32OperandId indexId,
342 ValOperandId rhsId);
343
344 AttachDecision tryAttachGenericProxy(Handle<ProxyObject*> obj,
345 ObjOperandId objId, HandleId id,
346 ValOperandId rhsId,
347 bool handleDOMProxies);
348 AttachDecision tryAttachDOMProxyShadowed(Handle<ProxyObject*> obj,
349 ObjOperandId objId, HandleId id,
350 ValOperandId rhsId);
351 AttachDecision tryAttachDOMProxyUnshadowed(Handle<ProxyObject*> obj,
352 ObjOperandId objId, HandleId id,
353 ValOperandId rhsId);
354 AttachDecision tryAttachDOMProxyExpando(Handle<ProxyObject*> obj,
355 ObjOperandId objId, HandleId id,
356 ValOperandId rhsId);
357 AttachDecision tryAttachProxy(HandleObject obj, ObjOperandId objId,
358 HandleId id, ValOperandId rhsId);
359 AttachDecision tryAttachProxyElement(HandleObject obj, ObjOperandId objId,
360 ValOperandId rhsId);
361 AttachDecision tryAttachMegamorphicSetElement(HandleObject obj,
362 ObjOperandId objId,
363 ValOperandId rhsId);
364
365 bool canAttachAddSlotStub(HandleObject obj, HandleId id);
366
367 public:
368 SetPropIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
369 CacheKind cacheKind, ICState state, HandleValue lhsVal,
370 HandleValue idVal, HandleValue rhsVal);
371
372 AttachDecision tryAttachStub();
373 AttachDecision tryAttachAddSlotStub(Handle<Shape*> oldShape);
374 void trackAttached(const char* name /* must be a C string literal */);
375
376 DeferType deferType() const { return deferType_; }
377 };
378
379 // HasPropIRGenerator generates CacheIR for a HasProp IC. Used for
380 // CacheKind::In / CacheKind::HasOwn.
381 class MOZ_RAII HasPropIRGenerator : public IRGenerator {
382 HandleValue val_;
383 HandleValue idVal_;
384
385 AttachDecision tryAttachDense(HandleObject obj, ObjOperandId objId,
386 uint32_t index, Int32OperandId indexId);
387 AttachDecision tryAttachDenseHole(HandleObject obj, ObjOperandId objId,
388 uint32_t index, Int32OperandId indexId);
389 AttachDecision tryAttachTypedArray(HandleObject obj, ObjOperandId objId,
390 ValOperandId keyId);
391 AttachDecision tryAttachSparse(HandleObject obj, ObjOperandId objId,
392 Int32OperandId indexId);
393 AttachDecision tryAttachArgumentsObjectArg(HandleObject obj,
394 ObjOperandId objId,
395 Int32OperandId indexId);
396 AttachDecision tryAttachNamedProp(HandleObject obj, ObjOperandId objId,
397 HandleId key, ValOperandId keyId);
398 AttachDecision tryAttachMegamorphic(ObjOperandId objId, ValOperandId keyId);
399 AttachDecision tryAttachSmallObjectVariableKey(HandleObject obj,
400 ObjOperandId objId, jsid key,
401 ValOperandId keyId);
402 AttachDecision tryAttachNative(NativeObject* obj, ObjOperandId objId,
403 jsid key, ValOperandId keyId,
404 PropertyResult prop, NativeObject* holder);
405 AttachDecision tryAttachSlotDoesNotExist(NativeObject* obj,
406 ObjOperandId objId, jsid key,
407 ValOperandId keyId);
408 AttachDecision tryAttachDoesNotExist(HandleObject obj, ObjOperandId objId,
409 HandleId key, ValOperandId keyId);
410 AttachDecision tryAttachProxyElement(HandleObject obj, ObjOperandId objId,
411 ValOperandId keyId);
412
413 void trackAttached(const char* name /* must be a C string literal */);
414
415 public:
416 // NOTE: Argument order is PROPERTY, OBJECT
417 HasPropIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
418 ICState state, CacheKind cacheKind, HandleValue idVal,
419 HandleValue val);
420
421 AttachDecision tryAttachStub();
422 };
423
424 class MOZ_RAII CheckPrivateFieldIRGenerator : public IRGenerator {
425 HandleValue val_;
426 HandleValue idVal_;
427
428 AttachDecision tryAttachNative(NativeObject* obj, ObjOperandId objId,
429 jsid key, ValOperandId keyId,
430 PropertyResult prop);
431
432 void trackAttached(const char* name /* must be a C string literal */);
433
434 public:
435 CheckPrivateFieldIRGenerator(JSContext* cx, HandleScript script,
436 jsbytecode* pc, ICState state,
437 CacheKind cacheKind, HandleValue idVal,
438 HandleValue val);
439 AttachDecision tryAttachStub();
440 };
441
442 class MOZ_RAII InstanceOfIRGenerator : public IRGenerator {
443 HandleValue lhsVal_;
444 HandleObject rhsObj_;
445
446 void trackAttached(const char* name /* must be a C string literal */);
447
448 public:
449 InstanceOfIRGenerator(JSContext*, HandleScript, jsbytecode*, ICState,
450 HandleValue, HandleObject);
451
452 AttachDecision tryAttachStub();
453 };
454
455 class MOZ_RAII TypeOfIRGenerator : public IRGenerator {
456 HandleValue val_;
457
458 AttachDecision tryAttachPrimitive(ValOperandId valId);
459 AttachDecision tryAttachObject(ValOperandId valId);
460 void trackAttached(const char* name /* must be a C string literal */);
461
462 public:
463 TypeOfIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc, ICState state,
464 HandleValue value);
465
466 AttachDecision tryAttachStub();
467 };
468
469 class MOZ_RAII TypeOfEqIRGenerator : public IRGenerator {
470 HandleValue val_;
471 JSType type_;
472 JSOp compareOp_;
473
474 AttachDecision tryAttachPrimitive(ValOperandId valId);
475 AttachDecision tryAttachObject(ValOperandId valId);
476 void trackAttached(const char* name /* must be a C string literal */);
477
478 public:
479 TypeOfEqIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
480 ICState state, HandleValue value, JSType type,
481 JSOp compareOp);
482
483 AttachDecision tryAttachStub();
484 };
485
486 class MOZ_RAII GetIteratorIRGenerator : public IRGenerator {
487 HandleValue val_;
488
489 AttachDecision tryAttachObject(ValOperandId valId);
490 AttachDecision tryAttachNullOrUndefined(ValOperandId valId);
491 AttachDecision tryAttachGeneric(ValOperandId valId);
492
493 public:
494 GetIteratorIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
495 ICState state, HandleValue value);
496
497 AttachDecision tryAttachStub();
498
499 void trackAttached(const char* name /* must be a C string literal */);
500 };
501
502 class MOZ_RAII OptimizeSpreadCallIRGenerator : public IRGenerator {
503 HandleValue val_;
504
505 AttachDecision tryAttachArray();
506 AttachDecision tryAttachArguments();
507 AttachDecision tryAttachNotOptimizable();
508
509 public:
510 OptimizeSpreadCallIRGenerator(JSContext* cx, HandleScript script,
511 jsbytecode* pc, ICState state,
512 HandleValue value);
513
514 AttachDecision tryAttachStub();
515
516 void trackAttached(const char* name /* must be a C string literal */);
517 };
518
519 class MOZ_RAII OptimizeGetIteratorIRGenerator : public IRGenerator {
520 HandleValue val_;
521
522 AttachDecision tryAttachArray();
523 AttachDecision tryAttachNotOptimizable();
524
525 public:
526 OptimizeGetIteratorIRGenerator(JSContext* cx, HandleScript script,
527 jsbytecode* pc, ICState state,
528 HandleValue value);
529
530 AttachDecision tryAttachStub();
531
532 void trackAttached(const char* name /* must be a C string literal */);
533 };
534
535 enum class StringChar { CharCodeAt, CodePointAt, CharAt, At };
536 enum class ScriptedThisResult { NoAction, UninitializedThis, PlainObjectShape };
537
538 class MOZ_RAII CallIRGenerator : public IRGenerator {
539 private:
540 JSOp op_;
541 uint32_t argc_;
542 HandleValue callee_;
543 HandleValue thisval_;
544 HandleValue newTarget_;
545 HandleValueArray args_;
546
547 friend class InlinableNativeIRGenerator;
548
549 ScriptedThisResult getThisShapeForScripted(HandleFunction calleeFunc,
550 Handle<JSObject*> newTarget,
551 MutableHandle<Shape*> result);
552
553 ObjOperandId emitFunCallOrApplyGuard(Int32OperandId argcId);
554 ObjOperandId emitFunCallGuard(Int32OperandId argcId);
555 ObjOperandId emitFunApplyGuard(Int32OperandId argcId);
556 mozilla::Maybe<ObjOperandId> emitFunApplyArgsGuard(
557 CallFlags::ArgFormat format);
558
559 void emitCallScriptedGuards(ObjOperandId calleeObjId, JSFunction* calleeFunc,
560 Int32OperandId argcId, CallFlags flags,
561 Shape* thisShape, bool isBoundFunction);
562
563 AttachDecision tryAttachFunCall(HandleFunction calleeFunc);
564 AttachDecision tryAttachFunApply(HandleFunction calleeFunc);
565 AttachDecision tryAttachCallScripted(HandleFunction calleeFunc);
566 AttachDecision tryAttachInlinableNative(HandleFunction calleeFunc,
567 CallFlags flags);
568 AttachDecision tryAttachWasmCall(HandleFunction calleeFunc);
569 AttachDecision tryAttachCallNative(HandleFunction calleeFunc);
570 AttachDecision tryAttachCallHook(HandleObject calleeObj);
571 AttachDecision tryAttachBoundFunction(Handle<BoundFunctionObject*> calleeObj);
572 AttachDecision tryAttachBoundNative(Handle<BoundFunctionObject*> calleeObj);
573 AttachDecision tryAttachBoundFunCall(Handle<BoundFunctionObject*> calleeObj);
574 AttachDecision tryAttachBoundFunApply(Handle<BoundFunctionObject*> calleeObj);
575 AttachDecision tryAttachFunCallBound(Handle<JSFunction*> callee);
576 AttachDecision tryAttachFunApplyBound(Handle<JSFunction*> callee);
577
578 void trackAttached(const char* name /* must be a C string literal */);
579
580 public:
581 CallIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc, JSOp op,
582 ICState state, BaselineFrame* frame, uint32_t argc,
583 HandleValue callee, HandleValue thisval,
584 HandleValue newTarget, HandleValueArray args);
585
586 AttachDecision tryAttachStub();
587 };
588
589 class MOZ_RAII InlinableNativeIRGenerator {
590 CallIRGenerator& generator_;
591 CacheIRWriter& writer;
592 JSContext* cx_;
593
594 HandleFunction target_;
595 HandleValue newTarget_;
596 HandleValue thisval_;
597 HandleValueArray args_;
598 CallFlags flags_;
599
600 HandleScript script() const { return generator_.script_; }
601 JSObject* callee() const { return &generator_.callee_.toObject(); }
602 bool isFirstStub() const { return generator_.isFirstStub_; }
603 bool ignoresResult() const { return generator_.op_ == JSOp::CallIgnoresRv; }
604 JSOp op() const { return generator_.op_; }
605 uint32_t stackArgc() const { return generator_.argc_; }
606
607 bool isCalleeBoundFunction() const;
608 BoundFunctionObject* boundCallee() const;
609
610 bool isTargetBoundFunction() const;
611 BoundFunctionObject* boundTarget() const;
612
613 ObjOperandId emitNativeCalleeGuard(Int32OperandId argcId);
614 void emitOptimisticClassGuard(ObjOperandId objId, JSObject* obj,
615 GuardClassKind kind) {
616 generator_.emitOptimisticClassGuard(objId, obj, kind);
617 }
618
619 ObjOperandId emitLoadArgsArray();
620
621 ValOperandId loadBoundArgument(ObjOperandId calleeId, size_t argIndex);
622
623 ValOperandId loadThis(ObjOperandId calleeId);
624
625 ValOperandId loadArgument(ObjOperandId calleeId, ArgumentKind kind);
626
627 ValOperandId loadArgumentIntrinsic(ArgumentKind kind) {
628 // Intrinsics can't be called through bound functions
629 MOZ_ASSERT(target_->isIntrinsic());
630 MOZ_ASSERT(flags_.getArgFormat() == CallFlags::Standard);
631 return writer.loadArgumentFixedSlot(kind, stackArgc(), flags_);
632 }
633
634 bool hasBoundArguments() const;
635
636 Int32OperandId initializeInputOperand() {
637 return Int32OperandId(writer.setInputOperandId(0));
638 }
639
640 auto emitToStringGuard(ValOperandId id, const Value& v) {
641 return generator_.emitToStringGuard(id, v);
642 }
643
644 auto emitNumericGuard(ValOperandId valId, const Value& v, Scalar::Type type) {
645 return generator_.emitNumericGuard(valId, v, type);
646 }
647
648 auto guardToIntPtrIndex(const Value& index, ValOperandId indexId,
649 bool supportOOB) {
650 return generator_.guardToIntPtrIndex(index, indexId, supportOOB);
651 }
652
653 bool canAttachAtomicsReadWriteModify();
654
655 struct AtomicsReadWriteModifyOperands {
656 ObjOperandId objId;
657 IntPtrOperandId intPtrIndexId;
658 OperandId numericValueId;
659 };
660
661 AtomicsReadWriteModifyOperands emitAtomicsReadWriteModifyOperands();
662
663 enum class DateComponent {
664 FullYear,
665 Month,
666 Date,
667 Day,
668 Hours,
669 Minutes,
670 Seconds,
671 };
672
673 AttachDecision tryAttachArrayPush();
674 AttachDecision tryAttachArrayPopShift(InlinableNative native);
675 AttachDecision tryAttachArrayJoin();
676 AttachDecision tryAttachArraySlice();
677 AttachDecision tryAttachArrayIsArray();
678 AttachDecision tryAttachDataViewGet(Scalar::Type type);
679 AttachDecision tryAttachDataViewSet(Scalar::Type type);
680 AttachDecision tryAttachFunctionBind();
681 AttachDecision tryAttachSpecializedFunctionBind(
682 Handle<JSObject*> target, Handle<BoundFunctionObject*> templateObj);
683 AttachDecision tryAttachUnsafeGetReservedSlot(InlinableNative native);
684 AttachDecision tryAttachUnsafeSetReservedSlot();
685 AttachDecision tryAttachIsSuspendedGenerator();
686 AttachDecision tryAttachToObject();
687 AttachDecision tryAttachToInteger();
688 AttachDecision tryAttachToLength();
689 AttachDecision tryAttachIsObject();
690 AttachDecision tryAttachIsPackedArray();
691 AttachDecision tryAttachIsCallable();
692 AttachDecision tryAttachIsConstructor();
693 AttachDecision tryAttachIsCrossRealmArrayConstructor();
694 AttachDecision tryAttachCanOptimizeArraySpecies();
695 AttachDecision tryAttachCanOptimizeStringProtoSymbolLookup();
696 AttachDecision tryAttachGuardToClass(InlinableNative native);
697 AttachDecision tryAttachGuardToClass(GuardClassKind kind);
698 AttachDecision tryAttachGuardToEitherClass(GuardClassKind kind1,
699 GuardClassKind kind2);
700 AttachDecision tryAttachGuardToArrayBuffer();
701 AttachDecision tryAttachGuardToSharedArrayBuffer();
702 AttachDecision tryAttachHasClass(const JSClass* clasp,
703 bool isPossiblyWrapped);
704 AttachDecision tryAttachRegExpMatcherSearcher(InlinableNative native);
705 AttachDecision tryAttachRegExpSearcherLastLimit();
706 AttachDecision tryAttachRegExpHasCaptureGroups();
707 AttachDecision tryAttachIsRegExpPrototypeOptimizable();
708 AttachDecision tryAttachIsOptimizableRegExpObject();
709 AttachDecision tryAttachIntrinsicRegExpBuiltinExec(InlinableNative native);
710 AttachDecision tryAttachIntrinsicRegExpExec(InlinableNative native);
711 AttachDecision tryAttachGetFirstDollarIndex();
712 AttachDecision tryAttachSubstringKernel();
713 AttachDecision tryAttachString();
714 AttachDecision tryAttachStringConstructor();
715 AttachDecision tryAttachStringToStringValueOf();
716 AttachDecision tryAttachStringChar(StringChar kind);
717 AttachDecision tryAttachStringCharCodeAt();
718 AttachDecision tryAttachStringCodePointAt();
719 AttachDecision tryAttachStringCharAt();
720 AttachDecision tryAttachStringAt();
721 AttachDecision tryAttachStringFromCharCode();
722 AttachDecision tryAttachStringFromCodePoint();
723 AttachDecision tryAttachStringIncludes();
724 AttachDecision tryAttachStringIndexOf();
725 AttachDecision tryAttachStringLastIndexOf();
726 AttachDecision tryAttachStringStartsWith();
727 AttachDecision tryAttachStringEndsWith();
728 AttachDecision tryAttachStringToLowerCase();
729 AttachDecision tryAttachStringToUpperCase();
730 AttachDecision tryAttachStringTrim();
731 AttachDecision tryAttachStringTrimStart();
732 AttachDecision tryAttachStringTrimEnd();
733 AttachDecision tryAttachStringReplaceString();
734 AttachDecision tryAttachStringSplitString();
735 AttachDecision tryAttachMathRandom();
736 AttachDecision tryAttachMathAbs();
737 AttachDecision tryAttachMathClz32();
738 AttachDecision tryAttachMathSign();
739 AttachDecision tryAttachMathImul();
740 AttachDecision tryAttachMathFloor();
741 AttachDecision tryAttachMathCeil();
742 AttachDecision tryAttachMathTrunc();
743 AttachDecision tryAttachMathRound();
744 AttachDecision tryAttachMathSqrt();
745 AttachDecision tryAttachMathFRound();
746 AttachDecision tryAttachMathF16Round();
747 AttachDecision tryAttachMathHypot();
748 AttachDecision tryAttachMathATan2();
749 AttachDecision tryAttachMathFunction(UnaryMathFunction fun);
750 AttachDecision tryAttachMathPow();
751 AttachDecision tryAttachMathMinMax(bool isMax);
752 AttachDecision tryAttachSpreadMathMinMax(bool isMax);
753 AttachDecision tryAttachIsTypedArray(bool isPossiblyWrapped);
754 AttachDecision tryAttachIsTypedArrayConstructor();
755 AttachDecision tryAttachTypedArrayByteOffset();
756 AttachDecision tryAttachTypedArrayElementSize();
757 AttachDecision tryAttachTypedArrayLength(bool isPossiblyWrapped,
758 bool allowOutOfBounds);
759 AttachDecision tryAttachIsConstructing();
760 AttachDecision tryAttachGetNextMapSetEntryForIterator(bool isMap);
761 AttachDecision tryAttachNewArrayIterator();
762 AttachDecision tryAttachNewStringIterator();
763 AttachDecision tryAttachNewRegExpStringIterator();
764 AttachDecision tryAttachArrayIteratorPrototypeOptimizable();
765 AttachDecision tryAttachObjectCreate();
766 AttachDecision tryAttachObjectConstructor();
767 AttachDecision tryAttachArrayConstructor();
768 AttachDecision tryAttachTypedArrayConstructor();
769 AttachDecision tryAttachMapSetConstructor(InlinableNative native);
770 AttachDecision tryAttachNumber();
771 AttachDecision tryAttachNumberParseInt();
772 AttachDecision tryAttachNumberToString();
773 AttachDecision tryAttachReflectGetPrototypeOf();
774 AttachDecision tryAttachAtomicsCompareExchange();
775 AttachDecision tryAttachAtomicsExchange();
776 AttachDecision tryAttachAtomicsAdd();
777 AttachDecision tryAttachAtomicsSub();
778 AttachDecision tryAttachAtomicsAnd();
779 AttachDecision tryAttachAtomicsOr();
780 AttachDecision tryAttachAtomicsXor();
781 AttachDecision tryAttachAtomicsLoad();
782 AttachDecision tryAttachAtomicsStore();
783 AttachDecision tryAttachAtomicsIsLockFree();
784 AttachDecision tryAttachAtomicsPause();
785 AttachDecision tryAttachBoolean();
786 AttachDecision tryAttachBailout();
787 AttachDecision tryAttachAssertFloat32();
788 AttachDecision tryAttachAssertRecoveredOnBailout();
789 AttachDecision tryAttachObjectIs();
790 AttachDecision tryAttachObjectIsPrototypeOf();
791 AttachDecision tryAttachObjectKeys();
792 AttachDecision tryAttachObjectToString();
793 AttachDecision tryAttachBigInt();
794 AttachDecision tryAttachBigIntAsIntN();
795 AttachDecision tryAttachBigIntAsUintN();
796 AttachDecision tryAttachSetHas();
797 AttachDecision tryAttachSetDelete();
798 AttachDecision tryAttachSetAdd();
799 AttachDecision tryAttachSetSize();
800 AttachDecision tryAttachMapHas();
801 AttachDecision tryAttachMapGet();
802 AttachDecision tryAttachMapDelete();
803 AttachDecision tryAttachMapSet();
804 AttachDecision tryAttachDateGetTime(InlinableNative native);
805 AttachDecision tryAttachDateGet(DateComponent component);
806 #ifdef FUZZING_JS_FUZZILLI
807 AttachDecision tryAttachFuzzilliHash();
808 #endif
809
810 void trackAttached(const char* name /* must be a C string literal */) {
811 return generator_.trackAttached(name);
812 }
813
814 public:
815 InlinableNativeIRGenerator(CallIRGenerator& generator, HandleFunction target,
816 HandleValue newTarget, HandleValue thisValue,
817 HandleValueArray args, CallFlags flags)
818 : generator_(generator),
819 writer(generator.writer),
820 cx_(generator.cx_),
821 target_(target),
822 newTarget_(newTarget),
823 thisval_(thisValue),
824 args_(args),
825 flags_(flags) {}
826
827 AttachDecision tryAttachStub();
828 };
829
830 class MOZ_RAII CompareIRGenerator : public IRGenerator {
831 JSOp op_;
832 HandleValue lhsVal_;
833 HandleValue rhsVal_;
834
835 AttachDecision tryAttachString(ValOperandId lhsId, ValOperandId rhsId);
836 AttachDecision tryAttachObject(ValOperandId lhsId, ValOperandId rhsId);
837 AttachDecision tryAttachSymbol(ValOperandId lhsId, ValOperandId rhsId);
838 AttachDecision tryAttachStrictDifferentTypes(ValOperandId lhsId,
839 ValOperandId rhsId);
840 AttachDecision tryAttachInt32(ValOperandId lhsId, ValOperandId rhsId);
841 AttachDecision tryAttachNumber(ValOperandId lhsId, ValOperandId rhsId);
842 AttachDecision tryAttachBigInt(ValOperandId lhsId, ValOperandId rhsId);
843 AttachDecision tryAttachAnyNullUndefined(ValOperandId lhsId,
844 ValOperandId rhsId);
845 AttachDecision tryAttachNullUndefined(ValOperandId lhsId, ValOperandId rhsId);
846 AttachDecision tryAttachStringNumber(ValOperandId lhsId, ValOperandId rhsId);
847 AttachDecision tryAttachPrimitiveSymbol(ValOperandId lhsId,
848 ValOperandId rhsId);
849 AttachDecision tryAttachBigIntInt32(ValOperandId lhsId, ValOperandId rhsId);
850 AttachDecision tryAttachBigIntNumber(ValOperandId lhsId, ValOperandId rhsId);
851 AttachDecision tryAttachBigIntString(ValOperandId lhsId, ValOperandId rhsId);
852
853 void trackAttached(const char* name /* must be a C string literal */);
854
855 public:
856 CompareIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc, ICState state,
857 JSOp op, HandleValue lhsVal, HandleValue rhsVal);
858
859 AttachDecision tryAttachStub();
860 };
861
862 class MOZ_RAII ToBoolIRGenerator : public IRGenerator {
863 HandleValue val_;
864
865 AttachDecision tryAttachBool();
866 AttachDecision tryAttachInt32();
867 AttachDecision tryAttachNumber();
868 AttachDecision tryAttachString();
869 AttachDecision tryAttachSymbol();
870 AttachDecision tryAttachNullOrUndefined();
871 AttachDecision tryAttachObject();
872 AttachDecision tryAttachBigInt();
873
874 void trackAttached(const char* name /* must be a C string literal */);
875
876 public:
877 ToBoolIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc, ICState state,
878 HandleValue val);
879
880 AttachDecision tryAttachStub();
881 };
882
883 class MOZ_RAII LazyConstantIRGenerator : public IRGenerator {
884 HandleValue val_;
885
886 void trackAttached(const char* name /* must be a C string literal */);
887
888 public:
889 LazyConstantIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
890 ICState state, HandleValue val);
891
892 AttachDecision tryAttachStub();
893 };
894
895 class MOZ_RAII UnaryArithIRGenerator : public IRGenerator {
896 JSOp op_;
897 HandleValue val_;
898 HandleValue res_;
899
900 AttachDecision tryAttachInt32();
901 AttachDecision tryAttachNumber();
902 AttachDecision tryAttachBitwise();
903 AttachDecision tryAttachBigInt();
904 AttachDecision tryAttachBigIntPtr();
905 AttachDecision tryAttachStringInt32();
906 AttachDecision tryAttachStringNumber();
907
908 void trackAttached(const char* name /* must be a C string literal */);
909
910 public:
911 UnaryArithIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
912 ICState state, JSOp op, HandleValue val,
913 HandleValue res);
914
915 AttachDecision tryAttachStub();
916 };
917
918 class MOZ_RAII ToPropertyKeyIRGenerator : public IRGenerator {
919 HandleValue val_;
920
921 AttachDecision tryAttachInt32();
922 AttachDecision tryAttachNumber();
923 AttachDecision tryAttachString();
924 AttachDecision tryAttachSymbol();
925
926 void trackAttached(const char* name /* must be a C string literal */);
927
928 public:
929 ToPropertyKeyIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
930 ICState state, HandleValue val);
931
932 AttachDecision tryAttachStub();
933 };
934
935 class MOZ_RAII BinaryArithIRGenerator : public IRGenerator {
936 JSOp op_;
937 HandleValue lhs_;
938 HandleValue rhs_;
939 HandleValue res_;
940
941 void trackAttached(const char* name /* must be a C string literal */);
942
943 AttachDecision tryAttachInt32();
944 AttachDecision tryAttachDouble();
945 AttachDecision tryAttachBitwise();
946 AttachDecision tryAttachStringConcat();
947 AttachDecision tryAttachStringObjectConcat();
948 AttachDecision tryAttachBigInt();
949 AttachDecision tryAttachBigIntPtr();
950 AttachDecision tryAttachStringInt32Arith();
951 AttachDecision tryAttachStringNumberArith();
952 AttachDecision tryAttachDateArith();
953
954 public:
955 BinaryArithIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
956 ICState state, JSOp op, HandleValue lhs,
957 HandleValue rhs, HandleValue res);
958
959 AttachDecision tryAttachStub();
960 };
961
962 class MOZ_RAII NewArrayIRGenerator : public IRGenerator {
963 #ifdef JS_CACHEIR_SPEW
964 JSOp op_;
965 #endif
966 HandleObject templateObject_;
967
968 void trackAttached(const char* name /* must be a C string literal */);
969
970 public:
971 NewArrayIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
972 ICState state, JSOp op, HandleObject templateObj,
973 BaselineFrame* frame);
974
975 AttachDecision tryAttachStub();
976 AttachDecision tryAttachArrayObject();
977 };
978
979 class MOZ_RAII NewObjectIRGenerator : public IRGenerator {
980 #ifdef JS_CACHEIR_SPEW
981 JSOp op_;
982 #endif
983 HandleObject templateObject_;
984
985 void trackAttached(const char* name /* must be a C string literal */);
986
987 public:
988 NewObjectIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
989 ICState state, JSOp op, HandleObject templateObj,
990 BaselineFrame* frame);
991
992 AttachDecision tryAttachStub();
993 AttachDecision tryAttachPlainObject();
994 };
995
996 class MOZ_RAII LambdaIRGenerator : public IRGenerator {
997 #ifdef JS_CACHEIR_SPEW
998 JSOp op_;
999 #endif
1000 Handle<JSFunction*> canonicalFunction_;
1001
1002 void trackAttached(const char* name /* must be a C string literal */);
1003
1004 public:
1005 LambdaIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
1006 ICState state, JSOp op,
1007 Handle<JSFunction*> canonicalFunction,
1008 BaselineFrame* frame);
1009
1010 AttachDecision tryAttachStub();
1011 AttachDecision tryAttachFunctionClone();
1012 };
1013
1014 // Returns true for bytecode ops that can use InlinableNativeIRGenerator.
1015 inline bool BytecodeCallOpCanHaveInlinableNative(JSOp op) {
1016 return op == JSOp::Call || op == JSOp::CallContent || op == JSOp::New ||
1017 op == JSOp::NewContent || op == JSOp::CallIgnoresRv ||
1018 op == JSOp::SpreadCall;
1019 }
1020
1021 inline bool BytecodeOpCanHaveAllocSite(JSOp op) {
1022 return BytecodeCallOpCanHaveInlinableNative(op) || op == JSOp::NewArray ||
1023 op == JSOp::NewObject || op == JSOp::NewInit || op == JSOp::CallIter ||
1024 op == JSOp::CallContentIter || op == JSOp::Lambda;
1025 }
1026
1027 class MOZ_RAII CloseIterIRGenerator : public IRGenerator {
1028 HandleObject iter_;
1029 CompletionKind kind_;
1030
1031 void trackAttached(const char* name /* must be a C string literal */);
1032
1033 public:
1034 CloseIterIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,
1035 ICState state, HandleObject iter, CompletionKind kind);
1036
1037 AttachDecision tryAttachStub();
1038 AttachDecision tryAttachNoReturnMethod();
1039 AttachDecision tryAttachScriptedReturn();
1040 };
1041
1042 class MOZ_RAII GetImportIRGenerator : public IRGenerator {
1043 void trackAttached(const char* name /* must be a C string literal */);
1044
1045 public:
1046 GetImportIRGenerator(JSContext* cx, HandleScript script, jsbytecode* pc,
1047 ICState state);
1048
1049 AttachDecision tryAttachStub();
1050 AttachDecision tryAttachInitialized();
1051 };
1052
1053 // Retrieve Xray JIT info set by the embedder.
1054 extern JS::XrayJitInfo* GetXrayJitInfo();
1055
1056 } // namespace jit
1057 } // namespace js
1058
1059 #endif /* jit_CacheIRGenerator_h */