1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_IonIC_h
#define jit_IonIC_h
#include "jit/CacheIR.h"
#include "jit/ICState.h"
#include "jit/shared/Assembler-shared.h"
namespace js {
namespace jit {
class CacheIRStubInfo;
class CacheIRWriter;
class IonScript;
// An optimized stub attached to an IonIC.
class IonICStub {
// Code to jump to when this stub fails. This is either the next optimized
// stub or the OOL fallback path.
uint8_t* nextCodeRaw_;
// The next optimized stub in this chain, or nullptr if this is the last
// one.
IonICStub* next_;
// Info about this stub.
CacheIRStubInfo* stubInfo_;
#ifndef JS_64BIT
protected: // Silence Clang warning about unused private fields.
// Ensure stub data is 8-byte aligned on 32-bit.
uintptr_t padding_ = 0;
#endif
public:
IonICStub(uint8_t* fallbackCode, CacheIRStubInfo* stubInfo)
: nextCodeRaw_(fallbackCode), next_(nullptr), stubInfo_(stubInfo) {}
uint8_t* nextCodeRaw() const { return nextCodeRaw_; }
uint8_t** nextCodeRawPtr() { return &nextCodeRaw_; }
CacheIRStubInfo* stubInfo() const { return stubInfo_; }
IonICStub* next() const { return next_; }
uint8_t* stubDataStart();
void setNext(IonICStub* next, uint8_t* nextCodeRaw) {
MOZ_ASSERT(!next_);
MOZ_ASSERT(next && nextCodeRaw);
next_ = next;
nextCodeRaw_ = nextCodeRaw;
}
// Null out pointers when we unlink stubs, to ensure we never use
// discarded stubs.
void poison() {
nextCodeRaw_ = nullptr;
next_ = nullptr;
stubInfo_ = nullptr;
}
};
class IonGetPropertyIC;
class IonSetPropertyIC;
class IonGetPropSuperIC;
class IonGetNameIC;
class IonBindNameIC;
class IonGetIteratorIC;
class IonHasOwnIC;
class IonCheckPrivateFieldIC;
class IonInIC;
class IonInstanceOfIC;
class IonCompareIC;
class IonUnaryArithIC;
class IonBinaryArithIC;
class IonToPropertyKeyIC;
class IonOptimizeSpreadCallIC;
class IonCloseIterIC;
class IonIC {
// This either points at the OOL path for the fallback path, or the code for
// the first stub.
uint8_t* codeRaw_;
// The first optimized stub, or nullptr.
IonICStub* firstStub_;
// Location of this IC.
JSScript* script_;
jsbytecode* pc_;
// The offset of the rejoin location in the IonScript's code (stubs jump to
// this location).
uint32_t rejoinOffset_;
// The offset of the OOL path in the IonScript's code that calls the IC's
// update function.
uint32_t fallbackOffset_;
CacheKind kind_;
ICState state_;
protected:
explicit IonIC(CacheKind kind)
: codeRaw_(nullptr),
firstStub_(nullptr),
script_(nullptr),
pc_(nullptr),
rejoinOffset_(0),
fallbackOffset_(0),
kind_(kind),
state_() {}
void attachStub(IonICStub* newStub, JitCode* code);
public:
void setScriptedLocation(JSScript* script, jsbytecode* pc) {
MOZ_ASSERT(!script_ && !pc_);
MOZ_ASSERT(script && pc);
script_ = script;
pc_ = pc;
}
JSScript* script() const {
MOZ_ASSERT(script_);
return script_;
}
jsbytecode* pc() const {
MOZ_ASSERT(pc_);
return pc_;
}
// Discard all stubs.
void discardStubs(Zone* zone, IonScript* ionScript);
// Discard all stubs and reset the ICState.
void reset(Zone* zone, IonScript* ionScript);
ICState& state() { return state_; }
CacheKind kind() const { return kind_; }
uint8_t** codeRawPtr() { return &codeRaw_; }
void setFallbackOffset(CodeOffset offset) {
fallbackOffset_ = offset.offset();
}
void setRejoinOffset(CodeOffset offset) { rejoinOffset_ = offset.offset(); }
void resetCodeRaw(IonScript* ionScript);
uint8_t* fallbackAddr(IonScript* ionScript) const;
uint8_t* rejoinAddr(IonScript* ionScript) const;
IonGetPropertyIC* asGetPropertyIC() {
MOZ_ASSERT(kind_ == CacheKind::GetProp || kind_ == CacheKind::GetElem);
return (IonGetPropertyIC*)this;
}
IonSetPropertyIC* asSetPropertyIC() {
MOZ_ASSERT(kind_ == CacheKind::SetProp || kind_ == CacheKind::SetElem);
return (IonSetPropertyIC*)this;
}
IonGetPropSuperIC* asGetPropSuperIC() {
MOZ_ASSERT(kind_ == CacheKind::GetPropSuper ||
kind_ == CacheKind::GetElemSuper);
return (IonGetPropSuperIC*)this;
}
IonGetNameIC* asGetNameIC() {
MOZ_ASSERT(kind_ == CacheKind::GetName);
return (IonGetNameIC*)this;
}
IonBindNameIC* asBindNameIC() {
MOZ_ASSERT(kind_ == CacheKind::BindName);
return (IonBindNameIC*)this;
}
IonGetIteratorIC* asGetIteratorIC() {
MOZ_ASSERT(kind_ == CacheKind::GetIterator);
return (IonGetIteratorIC*)this;
}
IonOptimizeSpreadCallIC* asOptimizeSpreadCallIC() {
MOZ_ASSERT(kind_ == CacheKind::OptimizeSpreadCall);
return (IonOptimizeSpreadCallIC*)this;
}
IonHasOwnIC* asHasOwnIC() {
MOZ_ASSERT(kind_ == CacheKind::HasOwn);
return (IonHasOwnIC*)this;
}
IonCheckPrivateFieldIC* asCheckPrivateFieldIC() {
MOZ_ASSERT(kind_ == CacheKind::CheckPrivateField);
return (IonCheckPrivateFieldIC*)this;
}
IonInIC* asInIC() {
MOZ_ASSERT(kind_ == CacheKind::In);
return (IonInIC*)this;
}
IonInstanceOfIC* asInstanceOfIC() {
MOZ_ASSERT(kind_ == CacheKind::InstanceOf);
return (IonInstanceOfIC*)this;
}
IonCompareIC* asCompareIC() {
MOZ_ASSERT(kind_ == CacheKind::Compare);
return (IonCompareIC*)this;
}
IonUnaryArithIC* asUnaryArithIC() {
MOZ_ASSERT(kind_ == CacheKind::UnaryArith);
return (IonUnaryArithIC*)this;
}
IonBinaryArithIC* asBinaryArithIC() {
MOZ_ASSERT(kind_ == CacheKind::BinaryArith);
return (IonBinaryArithIC*)this;
}
IonToPropertyKeyIC* asToPropertyKeyIC() {
MOZ_ASSERT(kind_ == CacheKind::ToPropertyKey);
return (IonToPropertyKeyIC*)this;
}
IonCloseIterIC* asCloseIterIC() {
MOZ_ASSERT(kind_ == CacheKind::CloseIter);
return (IonCloseIterIC*)this;
}
// Returns the Register to use as scratch when entering IC stubs. This
// should either be an output register or a temp.
Register scratchRegisterForEntryJump();
void trace(JSTracer* trc, IonScript* ionScript);
void attachCacheIRStub(JSContext* cx, const CacheIRWriter& writer,
CacheKind kind, IonScript* ionScript, bool* attached);
};
class IonGetPropertyIC : public IonIC {
private:
LiveRegisterSet liveRegs_;
TypedOrValueRegister value_;
ConstantOrRegister id_;
ValueOperand output_;
public:
IonGetPropertyIC(CacheKind kind, LiveRegisterSet liveRegs,
TypedOrValueRegister value, const ConstantOrRegister& id,
ValueOperand output)
: IonIC(kind),
liveRegs_(liveRegs),
value_(value),
id_(id),
output_(output) {}
TypedOrValueRegister value() const { return value_; }
ConstantOrRegister id() const { return id_; }
ValueOperand output() const { return output_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonGetPropertyIC* ic, HandleValue val,
HandleValue idVal, MutableHandleValue res);
};
class IonGetPropSuperIC : public IonIC {
LiveRegisterSet liveRegs_;
Register object_;
TypedOrValueRegister receiver_;
ConstantOrRegister id_;
ValueOperand output_;
public:
IonGetPropSuperIC(CacheKind kind, LiveRegisterSet liveRegs, Register object,
TypedOrValueRegister receiver, const ConstantOrRegister& id,
ValueOperand output)
: IonIC(kind),
liveRegs_(liveRegs),
object_(object),
receiver_(receiver),
id_(id),
output_(output) {}
Register object() const { return object_; }
TypedOrValueRegister receiver() const { return receiver_; }
ConstantOrRegister id() const { return id_; }
ValueOperand output() const { return output_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonGetPropSuperIC* ic, HandleObject obj,
HandleValue receiver, HandleValue idVal,
MutableHandleValue res);
};
class IonSetPropertyIC : public IonIC {
LiveRegisterSet liveRegs_;
Register object_;
Register temp_;
ConstantOrRegister id_;
ConstantOrRegister rhs_;
bool strict_ : 1;
public:
IonSetPropertyIC(CacheKind kind, LiveRegisterSet liveRegs, Register object,
Register temp, const ConstantOrRegister& id,
const ConstantOrRegister& rhs, bool strict)
: IonIC(kind),
liveRegs_(liveRegs),
object_(object),
temp_(temp),
id_(id),
rhs_(rhs),
strict_(strict) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
Register object() const { return object_; }
ConstantOrRegister id() const { return id_; }
ConstantOrRegister rhs() const { return rhs_; }
Register temp() const { return temp_; }
bool strict() const { return strict_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonSetPropertyIC* ic, HandleObject obj,
HandleValue idVal, HandleValue rhs);
};
class IonGetNameIC : public IonIC {
LiveRegisterSet liveRegs_;
Register environment_;
ValueOperand output_;
Register temp_;
public:
IonGetNameIC(LiveRegisterSet liveRegs, Register environment,
ValueOperand output, Register temp)
: IonIC(CacheKind::GetName),
liveRegs_(liveRegs),
environment_(environment),
output_(output),
temp_(temp) {}
Register environment() const { return environment_; }
ValueOperand output() const { return output_; }
Register temp() const { return temp_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonGetNameIC* ic, HandleObject envChain,
MutableHandleValue res);
};
class IonBindNameIC : public IonIC {
LiveRegisterSet liveRegs_;
Register environment_;
Register output_;
Register temp_;
public:
IonBindNameIC(LiveRegisterSet liveRegs, Register environment, Register output,
Register temp)
: IonIC(CacheKind::BindName),
liveRegs_(liveRegs),
environment_(environment),
output_(output),
temp_(temp) {}
Register environment() const { return environment_; }
Register output() const { return output_; }
Register temp() const { return temp_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
static JSObject* update(JSContext* cx, HandleScript outerScript,
IonBindNameIC* ic, HandleObject envChain);
};
class IonGetIteratorIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister value_;
Register output_;
Register temp1_;
Register temp2_;
public:
IonGetIteratorIC(LiveRegisterSet liveRegs, TypedOrValueRegister value,
Register output, Register temp1, Register temp2)
: IonIC(CacheKind::GetIterator),
liveRegs_(liveRegs),
value_(value),
output_(output),
temp1_(temp1),
temp2_(temp2) {}
TypedOrValueRegister value() const { return value_; }
Register output() const { return output_; }
Register temp1() const { return temp1_; }
Register temp2() const { return temp2_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
static JSObject* update(JSContext* cx, HandleScript outerScript,
IonGetIteratorIC* ic, HandleValue value);
};
class IonOptimizeSpreadCallIC : public IonIC {
LiveRegisterSet liveRegs_;
ValueOperand value_;
ValueOperand output_;
Register temp_;
public:
IonOptimizeSpreadCallIC(LiveRegisterSet liveRegs, ValueOperand value,
ValueOperand output, Register temp)
: IonIC(CacheKind::OptimizeSpreadCall),
liveRegs_(liveRegs),
value_(value),
output_(output),
temp_(temp) {}
ValueOperand value() const { return value_; }
ValueOperand output() const { return output_; }
Register temp() const { return temp_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
static bool update(JSContext* cx, HandleScript outerScript,
IonOptimizeSpreadCallIC* ic, HandleValue value,
MutableHandleValue result);
};
class IonHasOwnIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister value_;
TypedOrValueRegister id_;
Register output_;
public:
IonHasOwnIC(LiveRegisterSet liveRegs, TypedOrValueRegister value,
TypedOrValueRegister id, Register output)
: IonIC(CacheKind::HasOwn),
liveRegs_(liveRegs),
value_(value),
id_(id),
output_(output) {}
TypedOrValueRegister value() const { return value_; }
TypedOrValueRegister id() const { return id_; }
Register output() const { return output_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonHasOwnIC* ic, HandleValue val,
HandleValue idVal, int32_t* res);
};
class IonCheckPrivateFieldIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister value_;
TypedOrValueRegister id_;
Register output_;
public:
IonCheckPrivateFieldIC(LiveRegisterSet liveRegs, TypedOrValueRegister value,
TypedOrValueRegister id, Register output)
: IonIC(CacheKind::CheckPrivateField),
liveRegs_(liveRegs),
value_(value),
id_(id),
output_(output) {}
TypedOrValueRegister value() const { return value_; }
TypedOrValueRegister id() const { return id_; }
Register output() const { return output_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonCheckPrivateFieldIC* ic, HandleValue val,
HandleValue idVal, bool* res);
};
class IonInIC : public IonIC {
LiveRegisterSet liveRegs_;
ConstantOrRegister key_;
Register object_;
Register output_;
Register temp_;
public:
IonInIC(LiveRegisterSet liveRegs, const ConstantOrRegister& key,
Register object, Register output, Register temp)
: IonIC(CacheKind::In),
liveRegs_(liveRegs),
key_(key),
object_(object),
output_(output),
temp_(temp) {}
ConstantOrRegister key() const { return key_; }
Register object() const { return object_; }
Register output() const { return output_; }
Register temp() const { return temp_; }
LiveRegisterSet liveRegs() const { return liveRegs_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonInIC* ic, HandleValue key,
HandleObject obj, bool* res);
};
class IonInstanceOfIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister lhs_;
Register rhs_;
Register output_;
public:
IonInstanceOfIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
Register rhs, Register output)
: IonIC(CacheKind::InstanceOf),
liveRegs_(liveRegs),
lhs_(lhs),
rhs_(rhs),
output_(output) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
TypedOrValueRegister lhs() const { return lhs_; }
Register rhs() const { return rhs_; }
Register output() const { return output_; }
// This signature mimics that of TryAttachInstanceOfStub in baseline
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonInstanceOfIC* ic, HandleValue lhs,
HandleObject rhs, bool* attached);
};
class IonCompareIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister lhs_;
TypedOrValueRegister rhs_;
Register output_;
public:
IonCompareIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
TypedOrValueRegister rhs, Register output)
: IonIC(CacheKind::Compare),
liveRegs_(liveRegs),
lhs_(lhs),
rhs_(rhs),
output_(output) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
TypedOrValueRegister lhs() const { return lhs_; }
TypedOrValueRegister rhs() const { return rhs_; }
Register output() const { return output_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonCompareIC* stub, HandleValue lhs,
HandleValue rhs, bool* res);
};
class IonUnaryArithIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister input_;
ValueOperand output_;
public:
IonUnaryArithIC(LiveRegisterSet liveRegs, TypedOrValueRegister input,
ValueOperand output)
: IonIC(CacheKind::UnaryArith),
liveRegs_(liveRegs),
input_(input),
output_(output) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
TypedOrValueRegister input() const { return input_; }
ValueOperand output() const { return output_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonUnaryArithIC* stub, HandleValue val,
MutableHandleValue res);
};
class IonToPropertyKeyIC : public IonIC {
LiveRegisterSet liveRegs_;
ValueOperand input_;
ValueOperand output_;
public:
IonToPropertyKeyIC(LiveRegisterSet liveRegs, ValueOperand input,
ValueOperand output)
: IonIC(CacheKind::ToPropertyKey),
liveRegs_(liveRegs),
input_(input),
output_(output) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
ValueOperand input() const { return input_; }
ValueOperand output() const { return output_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonToPropertyKeyIC* ic, HandleValue val,
MutableHandleValue res);
};
class IonBinaryArithIC : public IonIC {
LiveRegisterSet liveRegs_;
TypedOrValueRegister lhs_;
TypedOrValueRegister rhs_;
ValueOperand output_;
public:
IonBinaryArithIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
TypedOrValueRegister rhs, ValueOperand output)
: IonIC(CacheKind::BinaryArith),
liveRegs_(liveRegs),
lhs_(lhs),
rhs_(rhs),
output_(output) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
TypedOrValueRegister lhs() const { return lhs_; }
TypedOrValueRegister rhs() const { return rhs_; }
ValueOperand output() const { return output_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonBinaryArithIC* stub, HandleValue lhs,
HandleValue rhs, MutableHandleValue res);
};
class IonCloseIterIC : public IonIC {
LiveRegisterSet liveRegs_;
Register iter_;
Register temp_;
CompletionKind completionKind_;
public:
IonCloseIterIC(LiveRegisterSet liveRegs, Register iter, Register temp,
CompletionKind completionKind)
: IonIC(CacheKind::CloseIter),
liveRegs_(liveRegs),
iter_(iter),
temp_(temp),
completionKind_(completionKind) {}
LiveRegisterSet liveRegs() const { return liveRegs_; }
Register temp() const { return temp_; }
Register iter() const { return iter_; }
CompletionKind completionKind() const { return completionKind_; }
[[nodiscard]] static bool update(JSContext* cx, HandleScript outerScript,
IonCloseIterIC* ic, HandleObject iter);
};
} // namespace jit
} // namespace js
#endif /* jit_IonIC_h */
|