-
Notifications
You must be signed in to change notification settings - Fork 30.5k
/
Copy pathinterpreter-generator.cc
3155 lines (2768 loc) Β· 111 KB
/
interpreter-generator.cc
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/interpreter/interpreter-generator.h"
#include <array>
#include <tuple>
#include "src/builtins/builtins-constructor-gen.h"
#include "src/builtins/builtins-iterator-gen.h"
#include "src/builtins/profile-data-reader.h"
#include "src/codegen/code-factory.h"
#include "src/debug/debug.h"
#include "src/ic/accessor-assembler.h"
#include "src/ic/binary-op-assembler.h"
#include "src/ic/ic.h"
#include "src/ic/unary-op-assembler.h"
#include "src/interpreter/bytecode-flags.h"
#include "src/interpreter/bytecodes.h"
#include "src/interpreter/interpreter-assembler.h"
#include "src/interpreter/interpreter-intrinsics-generator.h"
#include "src/objects/cell.h"
#include "src/objects/js-generator.h"
#include "src/objects/objects-inl.h"
#include "src/objects/oddball.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/source-text-module.h"
#include "src/utils/ostreams.h"
#include "torque-generated/exported-macros-assembler.h"
namespace v8 {
namespace internal {
namespace interpreter {
namespace {
using compiler::CodeAssemblerState;
using Label = CodeStubAssembler::Label;
#define IGNITION_HANDLER(Name, BaseAssembler) \
class Name##Assembler : public BaseAssembler { \
public: \
explicit Name##Assembler(compiler::CodeAssemblerState* state, \
Bytecode bytecode, OperandScale scale) \
: BaseAssembler(state, bytecode, scale) {} \
Name##Assembler(const Name##Assembler&) = delete; \
Name##Assembler& operator=(const Name##Assembler&) = delete; \
static void Generate(compiler::CodeAssemblerState* state, \
OperandScale scale); \
\
private: \
void GenerateImpl(); \
}; \
void Name##Assembler::Generate(compiler::CodeAssemblerState* state, \
OperandScale scale) { \
Name##Assembler assembler(state, Bytecode::k##Name, scale); \
state->SetInitialDebugInformation(#Name, __FILE__, __LINE__); \
assembler.GenerateImpl(); \
} \
void Name##Assembler::GenerateImpl()
// LdaZero
//
// Load literal '0' into the accumulator.
IGNITION_HANDLER(LdaZero, InterpreterAssembler) {
TNode<Number> zero_value = NumberConstant(0.0);
SetAccumulator(zero_value);
Dispatch();
}
// LdaSmi <imm>
//
// Load an integer literal into the accumulator as a Smi.
IGNITION_HANDLER(LdaSmi, InterpreterAssembler) {
TNode<Smi> smi_int = BytecodeOperandImmSmi(0);
SetAccumulator(smi_int);
Dispatch();
}
// LdaConstant <idx>
//
// Load constant literal at |idx| in the constant pool into the accumulator.
IGNITION_HANDLER(LdaConstant, InterpreterAssembler) {
TNode<Object> constant = LoadConstantPoolEntryAtOperandIndex(0);
SetAccumulator(constant);
Dispatch();
}
// LdaUndefined
//
// Load Undefined into the accumulator.
IGNITION_HANDLER(LdaUndefined, InterpreterAssembler) {
SetAccumulator(UndefinedConstant());
Dispatch();
}
// LdaNull
//
// Load Null into the accumulator.
IGNITION_HANDLER(LdaNull, InterpreterAssembler) {
SetAccumulator(NullConstant());
Dispatch();
}
// LdaTheHole
//
// Load TheHole into the accumulator.
IGNITION_HANDLER(LdaTheHole, InterpreterAssembler) {
SetAccumulator(TheHoleConstant());
Dispatch();
}
// LdaTrue
//
// Load True into the accumulator.
IGNITION_HANDLER(LdaTrue, InterpreterAssembler) {
SetAccumulator(TrueConstant());
Dispatch();
}
// LdaFalse
//
// Load False into the accumulator.
IGNITION_HANDLER(LdaFalse, InterpreterAssembler) {
SetAccumulator(FalseConstant());
Dispatch();
}
// Ldar <src>
//
// Load accumulator with value from register <src>.
IGNITION_HANDLER(Ldar, InterpreterAssembler) {
TNode<Object> value = LoadRegisterAtOperandIndex(0);
SetAccumulator(value);
Dispatch();
}
// Star <dst>
//
// Store accumulator to register <dst>.
IGNITION_HANDLER(Star, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
StoreRegisterAtOperandIndex(accumulator, 0);
Dispatch();
}
// Star0 - StarN
//
// Store accumulator to one of a special batch of registers, without using a
// second byte to specify the destination.
//
// Even though this handler is declared as Star0, multiple entries in
// the jump table point to this handler.
IGNITION_HANDLER(Star0, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<WordT> opcode = LoadBytecode(BytecodeOffset());
StoreRegisterForShortStar(accumulator, opcode);
Dispatch();
}
// Mov <src> <dst>
//
// Stores the value of register <src> to register <dst>.
IGNITION_HANDLER(Mov, InterpreterAssembler) {
TNode<Object> src_value = LoadRegisterAtOperandIndex(0);
StoreRegisterAtOperandIndex(src_value, 1);
Dispatch();
}
class InterpreterLoadGlobalAssembler : public InterpreterAssembler {
public:
InterpreterLoadGlobalAssembler(CodeAssemblerState* state, Bytecode bytecode,
OperandScale operand_scale)
: InterpreterAssembler(state, bytecode, operand_scale) {}
void LdaGlobal(int slot_operand_index, int name_operand_index,
TypeofMode typeof_mode) {
TNode<HeapObject> maybe_feedback_vector = LoadFeedbackVector();
AccessorAssembler accessor_asm(state());
ExitPoint exit_point(this, [=](TNode<Object> result) {
SetAccumulator(result);
Dispatch();
});
LazyNode<TaggedIndex> lazy_slot = [=] {
return BytecodeOperandIdxTaggedIndex(slot_operand_index);
};
LazyNode<Context> lazy_context = [=] { return GetContext(); };
LazyNode<Name> lazy_name = [=] {
TNode<Name> name =
CAST(LoadConstantPoolEntryAtOperandIndex(name_operand_index));
return name;
};
accessor_asm.LoadGlobalIC(maybe_feedback_vector, lazy_slot, lazy_context,
lazy_name, typeof_mode, &exit_point);
}
};
// LdaGlobal <name_index> <slot>
//
// Load the global with name in constant pool entry <name_index> into the
// accumulator using FeedBackVector slot <slot> outside of a typeof.
IGNITION_HANDLER(LdaGlobal, InterpreterLoadGlobalAssembler) {
static const int kNameOperandIndex = 0;
static const int kSlotOperandIndex = 1;
LdaGlobal(kSlotOperandIndex, kNameOperandIndex, TypeofMode::kNotInside);
}
// LdaGlobalInsideTypeof <name_index> <slot>
//
// Load the global with name in constant pool entry <name_index> into the
// accumulator using FeedBackVector slot <slot> inside of a typeof.
IGNITION_HANDLER(LdaGlobalInsideTypeof, InterpreterLoadGlobalAssembler) {
static const int kNameOperandIndex = 0;
static const int kSlotOperandIndex = 1;
LdaGlobal(kSlotOperandIndex, kNameOperandIndex, TypeofMode::kInside);
}
// StaGlobal <name_index> <slot>
//
// Store the value in the accumulator into the global with name in constant pool
// entry <name_index> using FeedBackVector slot <slot>.
IGNITION_HANDLER(StaGlobal, InterpreterAssembler) {
TNode<Context> context = GetContext();
// Store the global via the StoreGlobalIC.
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Object> value = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(1);
TNode<HeapObject> maybe_vector = LoadFeedbackVector();
TNode<Object> result = CallBuiltin(Builtin::kStoreGlobalIC, context, name,
value, slot, maybe_vector);
// To avoid special logic in the deoptimizer to re-materialize the value in
// the accumulator, we overwrite the accumulator after the IC call. It
// doesn't really matter what we write to the accumulator here, since we
// restore to the correct value on the outside. Storing the result means we
// don't need to keep unnecessary state alive across the callstub.
SetAccumulator(result);
Dispatch();
}
// LdaContextSlot <context> <slot_index> <depth>
//
// Load the object in |slot_index| of the context at |depth| in the context
// chain starting at |context| into the accumulator.
IGNITION_HANDLER(LdaContextSlot, InterpreterAssembler) {
TNode<Context> context = CAST(LoadRegisterAtOperandIndex(0));
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(1));
TNode<Uint32T> depth = BytecodeOperandUImm(2);
TNode<Context> slot_context = GetContextAtDepth(context, depth);
TNode<Object> result = LoadContextElement(slot_context, slot_index);
SetAccumulator(result);
Dispatch();
}
// LdaImmutableContextSlot <context> <slot_index> <depth>
//
// Load the object in |slot_index| of the context at |depth| in the context
// chain starting at |context| into the accumulator.
IGNITION_HANDLER(LdaImmutableContextSlot, InterpreterAssembler) {
TNode<Context> context = CAST(LoadRegisterAtOperandIndex(0));
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(1));
TNode<Uint32T> depth = BytecodeOperandUImm(2);
TNode<Context> slot_context = GetContextAtDepth(context, depth);
TNode<Object> result = LoadContextElement(slot_context, slot_index);
SetAccumulator(result);
Dispatch();
}
// LdaCurrentContextSlot <slot_index>
//
// Load the object in |slot_index| of the current context into the accumulator.
IGNITION_HANDLER(LdaCurrentContextSlot, InterpreterAssembler) {
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(0));
TNode<Context> slot_context = GetContext();
TNode<Object> result = LoadContextElement(slot_context, slot_index);
SetAccumulator(result);
Dispatch();
}
// LdaImmutableCurrentContextSlot <slot_index>
//
// Load the object in |slot_index| of the current context into the accumulator.
IGNITION_HANDLER(LdaImmutableCurrentContextSlot, InterpreterAssembler) {
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(0));
TNode<Context> slot_context = GetContext();
TNode<Object> result = LoadContextElement(slot_context, slot_index);
SetAccumulator(result);
Dispatch();
}
// StaContextSlot <context> <slot_index> <depth>
//
// Stores the object in the accumulator into |slot_index| of the context at
// |depth| in the context chain starting at |context|.
IGNITION_HANDLER(StaContextSlot, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<Context> context = CAST(LoadRegisterAtOperandIndex(0));
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(1));
TNode<Uint32T> depth = BytecodeOperandUImm(2);
TNode<Context> slot_context = GetContextAtDepth(context, depth);
StoreContextElement(slot_context, slot_index, value);
Dispatch();
}
// StaCurrentContextSlot <slot_index>
//
// Stores the object in the accumulator into |slot_index| of the current
// context.
IGNITION_HANDLER(StaCurrentContextSlot, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(0));
TNode<Context> slot_context = GetContext();
StoreContextElement(slot_context, slot_index, value);
Dispatch();
}
// LdaLookupSlot <name_index>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically.
IGNITION_HANDLER(LdaLookupSlot, InterpreterAssembler) {
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Context> context = GetContext();
TNode<Object> result = CallRuntime(Runtime::kLoadLookupSlot, context, name);
SetAccumulator(result);
Dispatch();
}
// LdaLookupSlotInsideTypeof <name_index>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically without causing a NoReferenceError.
IGNITION_HANDLER(LdaLookupSlotInsideTypeof, InterpreterAssembler) {
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Context> context = GetContext();
TNode<Object> result =
CallRuntime(Runtime::kLoadLookupSlotInsideTypeof, context, name);
SetAccumulator(result);
Dispatch();
}
class InterpreterLookupContextSlotAssembler : public InterpreterAssembler {
public:
InterpreterLookupContextSlotAssembler(CodeAssemblerState* state,
Bytecode bytecode,
OperandScale operand_scale)
: InterpreterAssembler(state, bytecode, operand_scale) {}
void LookupContextSlot(Runtime::FunctionId function_id) {
TNode<Context> context = GetContext();
TNode<IntPtrT> slot_index = Signed(BytecodeOperandIdx(1));
TNode<Uint32T> depth = BytecodeOperandUImm(2);
Label slowpath(this, Label::kDeferred);
// Check for context extensions to allow the fast path.
TNode<Context> slot_context =
GotoIfHasContextExtensionUpToDepth(context, depth, &slowpath);
// Fast path does a normal load context.
{
TNode<Object> result = LoadContextElement(slot_context, slot_index);
SetAccumulator(result);
Dispatch();
}
// Slow path when we have to call out to the runtime.
BIND(&slowpath);
{
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Object> result = CallRuntime(function_id, context, name);
SetAccumulator(result);
Dispatch();
}
}
};
// LdaLookupContextSlot <name_index>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically.
IGNITION_HANDLER(LdaLookupContextSlot, InterpreterLookupContextSlotAssembler) {
LookupContextSlot(Runtime::kLoadLookupSlot);
}
// LdaLookupContextSlotInsideTypeof <name_index>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically without causing a NoReferenceError.
IGNITION_HANDLER(LdaLookupContextSlotInsideTypeof,
InterpreterLookupContextSlotAssembler) {
LookupContextSlot(Runtime::kLoadLookupSlotInsideTypeof);
}
class InterpreterLookupGlobalAssembler : public InterpreterLoadGlobalAssembler {
public:
InterpreterLookupGlobalAssembler(CodeAssemblerState* state, Bytecode bytecode,
OperandScale operand_scale)
: InterpreterLoadGlobalAssembler(state, bytecode, operand_scale) {}
void LookupGlobalSlot(Runtime::FunctionId function_id) {
TNode<Context> context = GetContext();
TNode<Uint32T> depth = BytecodeOperandUImm(2);
Label slowpath(this, Label::kDeferred);
// Check for context extensions to allow the fast path
GotoIfHasContextExtensionUpToDepth(context, depth, &slowpath);
// Fast path does a normal load global
{
static const int kNameOperandIndex = 0;
static const int kSlotOperandIndex = 1;
TypeofMode typeof_mode =
function_id == Runtime::kLoadLookupSlotInsideTypeof
? TypeofMode::kInside
: TypeofMode::kNotInside;
LdaGlobal(kSlotOperandIndex, kNameOperandIndex, typeof_mode);
}
// Slow path when we have to call out to the runtime
BIND(&slowpath);
{
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Object> result = CallRuntime(function_id, context, name);
SetAccumulator(result);
Dispatch();
}
}
};
// LdaLookupGlobalSlot <name_index> <feedback_slot> <depth>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically.
IGNITION_HANDLER(LdaLookupGlobalSlot, InterpreterLookupGlobalAssembler) {
LookupGlobalSlot(Runtime::kLoadLookupSlot);
}
// LdaLookupGlobalSlotInsideTypeof <name_index> <feedback_slot> <depth>
//
// Lookup the object with the name in constant pool entry |name_index|
// dynamically without causing a NoReferenceError.
IGNITION_HANDLER(LdaLookupGlobalSlotInsideTypeof,
InterpreterLookupGlobalAssembler) {
LookupGlobalSlot(Runtime::kLoadLookupSlotInsideTypeof);
}
// StaLookupSlot <name_index> <flags>
//
// Store the object in accumulator to the object with the name in constant
// pool entry |name_index|.
IGNITION_HANDLER(StaLookupSlot, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(0));
TNode<Uint32T> bytecode_flags = BytecodeOperandFlag(1);
TNode<Context> context = GetContext();
TVARIABLE(Object, var_result);
Label sloppy(this), strict(this), end(this);
DCHECK_EQ(0, LanguageMode::kSloppy);
DCHECK_EQ(1, LanguageMode::kStrict);
DCHECK_EQ(0, static_cast<int>(LookupHoistingMode::kNormal));
DCHECK_EQ(1, static_cast<int>(LookupHoistingMode::kLegacySloppy));
Branch(IsSetWord32<StoreLookupSlotFlags::LanguageModeBit>(bytecode_flags),
&strict, &sloppy);
BIND(&strict);
{
CSA_DCHECK(this, IsClearWord32<StoreLookupSlotFlags::LookupHoistingModeBit>(
bytecode_flags));
var_result =
CallRuntime(Runtime::kStoreLookupSlot_Strict, context, name, value);
Goto(&end);
}
BIND(&sloppy);
{
Label hoisting(this), ordinary(this);
Branch(IsSetWord32<StoreLookupSlotFlags::LookupHoistingModeBit>(
bytecode_flags),
&hoisting, &ordinary);
BIND(&hoisting);
{
var_result = CallRuntime(Runtime::kStoreLookupSlot_SloppyHoisting,
context, name, value);
Goto(&end);
}
BIND(&ordinary);
{
var_result =
CallRuntime(Runtime::kStoreLookupSlot_Sloppy, context, name, value);
Goto(&end);
}
}
BIND(&end);
{
SetAccumulator(var_result.value());
Dispatch();
}
}
// GetNamedProperty <object> <name_index> <slot>
//
// Calls the LoadIC at FeedBackVector slot <slot> for <object> and the name at
// constant pool entry <name_index>.
IGNITION_HANDLER(GetNamedProperty, InterpreterAssembler) {
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
// Load receiver.
TNode<Object> recv = LoadRegisterAtOperandIndex(0);
// Load the name and context lazily.
LazyNode<TaggedIndex> lazy_slot = [=] {
return BytecodeOperandIdxTaggedIndex(2);
};
LazyNode<Name> lazy_name = [=] {
return CAST(LoadConstantPoolEntryAtOperandIndex(1));
};
LazyNode<Context> lazy_context = [=] { return GetContext(); };
Label done(this);
TVARIABLE(Object, var_result);
ExitPoint exit_point(this, &done, &var_result);
AccessorAssembler::LazyLoadICParameters params(lazy_context, recv, lazy_name,
lazy_slot, feedback_vector);
AccessorAssembler accessor_asm(state());
accessor_asm.LoadIC_BytecodeHandler(¶ms, &exit_point);
BIND(&done);
{
SetAccumulator(var_result.value());
Dispatch();
}
}
// GetNamedPropertyFromSuper <receiver> <name_index> <slot>
//
// Calls the LoadSuperIC at FeedBackVector slot <slot> for <receiver>, home
// object's prototype (home object in the accumulator) and the name at constant
// pool entry <name_index>.
IGNITION_HANDLER(GetNamedPropertyFromSuper, InterpreterAssembler) {
TNode<Object> receiver = LoadRegisterAtOperandIndex(0);
TNode<HeapObject> home_object = CAST(GetAccumulator());
TNode<Object> home_object_prototype = LoadMapPrototype(LoadMap(home_object));
TNode<Object> name = LoadConstantPoolEntryAtOperandIndex(1);
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(2);
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
TNode<Object> result =
CallBuiltin(Builtin::kLoadSuperIC, context, receiver,
home_object_prototype, name, slot, feedback_vector);
SetAccumulator(result);
Dispatch();
}
// GetKeyedProperty <object> <slot>
//
// Calls the KeyedLoadIC at FeedBackVector slot <slot> for <object> and the key
// in the accumulator.
IGNITION_HANDLER(GetKeyedProperty, InterpreterAssembler) {
TNode<Object> object = LoadRegisterAtOperandIndex(0);
TNode<Object> name = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(1);
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
TVARIABLE(Object, var_result);
var_result = CallBuiltin(Builtin::kKeyedLoadIC, context, object, name, slot,
feedback_vector);
SetAccumulator(var_result.value());
Dispatch();
}
class InterpreterSetNamedPropertyAssembler : public InterpreterAssembler {
public:
InterpreterSetNamedPropertyAssembler(CodeAssemblerState* state,
Bytecode bytecode,
OperandScale operand_scale)
: InterpreterAssembler(state, bytecode, operand_scale) {}
void SetNamedProperty(Callable ic, NamedPropertyType property_type) {
TNode<Object> object = LoadRegisterAtOperandIndex(0);
TNode<Name> name = CAST(LoadConstantPoolEntryAtOperandIndex(1));
TNode<Object> value = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(2);
TNode<HeapObject> maybe_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
TNode<Object> result =
CallStub(ic, context, object, name, value, slot, maybe_vector);
// To avoid special logic in the deoptimizer to re-materialize the value in
// the accumulator, we overwrite the accumulator after the IC call. It
// doesn't really matter what we write to the accumulator here, since we
// restore to the correct value on the outside. Storing the result means we
// don't need to keep unnecessary state alive across the callstub.
SetAccumulator(result);
Dispatch();
}
};
// SetNamedProperty <object> <name_index> <slot>
//
// Calls the StoreIC at FeedBackVector slot <slot> for <object> and
// the name in constant pool entry <name_index> with the value in the
// accumulator.
IGNITION_HANDLER(SetNamedProperty, InterpreterSetNamedPropertyAssembler) {
// StoreIC is currently a base class for multiple property store operations
// and contains mixed logic for named and keyed, set and define operations,
// the paths are controlled by feedback.
// TODO(v8:12548): refactor SetNamedIC as a subclass of StoreIC, which can be
// called here.
Callable ic = Builtins::CallableFor(isolate(), Builtin::kStoreIC);
SetNamedProperty(ic, NamedPropertyType::kNotOwn);
}
// DefineNamedOwnProperty <object> <name_index> <slot>
//
// Calls the DefineNamedOwnIC at FeedBackVector slot <slot> for <object> and
// the name in constant pool entry <name_index> with the value in the
// accumulator.
IGNITION_HANDLER(DefineNamedOwnProperty, InterpreterSetNamedPropertyAssembler) {
Callable ic = Builtins::CallableFor(isolate(), Builtin::kDefineNamedOwnIC);
SetNamedProperty(ic, NamedPropertyType::kOwn);
}
// SetKeyedProperty <object> <key> <slot>
//
// Calls the KeyedStoreIC at FeedbackVector slot <slot> for <object> and
// the key <key> with the value in the accumulator. This could trigger
// the setter and the set traps if necessary.
IGNITION_HANDLER(SetKeyedProperty, InterpreterAssembler) {
TNode<Object> object = LoadRegisterAtOperandIndex(0);
TNode<Object> name = LoadRegisterAtOperandIndex(1);
TNode<Object> value = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(2);
TNode<HeapObject> maybe_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
// KeyedStoreIC is currently a base class for multiple keyed property store
// operations and contains mixed logic for set and define operations,
// the paths are controlled by feedback.
// TODO(v8:12548): refactor SetKeyedIC as a subclass of KeyedStoreIC, which
// can be called here.
TNode<Object> result = CallBuiltin(Builtin::kKeyedStoreIC, context, object,
name, value, slot, maybe_vector);
// To avoid special logic in the deoptimizer to re-materialize the value in
// the accumulator, we overwrite the accumulator after the IC call. It
// doesn't really matter what we write to the accumulator here, since we
// restore to the correct value on the outside. Storing the result means we
// don't need to keep unnecessary state alive across the callstub.
SetAccumulator(result);
Dispatch();
}
// DefineKeyedOwnProperty <object> <key> <slot>
//
// Calls the DefineKeyedOwnIC at FeedbackVector slot <slot> for <object> and
// the key <key> with the value in the accumulator.
//
// This is similar to SetKeyedProperty, but avoids checking the prototype
// chain, and in the case of private names, throws if the private name already
// exists.
IGNITION_HANDLER(DefineKeyedOwnProperty, InterpreterAssembler) {
TNode<Object> object = LoadRegisterAtOperandIndex(0);
TNode<Object> name = LoadRegisterAtOperandIndex(1);
TNode<Object> value = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(2);
TNode<HeapObject> maybe_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
TVARIABLE(Object, var_result);
var_result = CallBuiltin(Builtin::kDefineKeyedOwnIC, context, object, name,
value, slot, maybe_vector);
// To avoid special logic in the deoptimizer to re-materialize the value in
// the accumulator, we overwrite the accumulator after the IC call. It
// doesn't really matter what we write to the accumulator here, since we
// restore to the correct value on the outside. Storing the result means we
// don't need to keep unnecessary state alive across the callstub.
SetAccumulator(var_result.value());
Dispatch();
}
// StaInArrayLiteral <array> <index> <slot>
//
// Calls the StoreInArrayLiteralIC at FeedbackVector slot <slot> for <array> and
// the key <index> with the value in the accumulator.
IGNITION_HANDLER(StaInArrayLiteral, InterpreterAssembler) {
TNode<Object> array = LoadRegisterAtOperandIndex(0);
TNode<Object> index = LoadRegisterAtOperandIndex(1);
TNode<Object> value = GetAccumulator();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(2);
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
TNode<Object> result =
CallBuiltin(Builtin::kStoreInArrayLiteralIC, context, array, index, value,
slot, feedback_vector);
// To avoid special logic in the deoptimizer to re-materialize the value in
// the accumulator, we overwrite the accumulator after the IC call. It
// doesn't really matter what we write to the accumulator here, since we
// restore to the correct value on the outside. Storing the result means we
// don't need to keep unnecessary state alive across the callstub.
SetAccumulator(result);
Dispatch();
}
// DefineKeyedOwnPropertyInLiteral <object> <name> <flags> <slot>
//
// Define a property <name> with value from the accumulator in <object>.
// Property attributes and whether set_function_name are stored in
// DefineKeyedOwnPropertyInLiteralFlags <flags>.
//
// This definition is not observable and is used only for definitions
// in object or class literals.
IGNITION_HANDLER(DefineKeyedOwnPropertyInLiteral, InterpreterAssembler) {
TNode<Object> object = LoadRegisterAtOperandIndex(0);
TNode<Object> name = LoadRegisterAtOperandIndex(1);
TNode<Object> value = GetAccumulator();
TNode<Smi> flags =
SmiFromInt32(UncheckedCast<Int32T>(BytecodeOperandFlag(2)));
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(3);
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
CallRuntime(Runtime::kDefineKeyedOwnPropertyInLiteral, context, object, name,
value, flags, feedback_vector, slot);
Dispatch();
}
IGNITION_HANDLER(CollectTypeProfile, InterpreterAssembler) {
TNode<Smi> position = BytecodeOperandImmSmi(0);
TNode<Object> value = GetAccumulator();
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<Context> context = GetContext();
CallRuntime(Runtime::kCollectTypeProfile, context, position, value,
feedback_vector);
Dispatch();
}
// LdaModuleVariable <cell_index> <depth>
//
// Load the contents of a module variable into the accumulator. The variable is
// identified by <cell_index>. <depth> is the depth of the current context
// relative to the module context.
IGNITION_HANDLER(LdaModuleVariable, InterpreterAssembler) {
TNode<IntPtrT> cell_index = BytecodeOperandImmIntPtr(0);
TNode<Uint32T> depth = BytecodeOperandUImm(1);
TNode<Context> module_context = GetContextAtDepth(GetContext(), depth);
TNode<SourceTextModule> module =
CAST(LoadContextElement(module_context, Context::EXTENSION_INDEX));
Label if_export(this), if_import(this), end(this);
Branch(IntPtrGreaterThan(cell_index, IntPtrConstant(0)), &if_export,
&if_import);
BIND(&if_export);
{
TNode<FixedArray> regular_exports = LoadObjectField<FixedArray>(
module, SourceTextModule::kRegularExportsOffset);
// The actual array index is (cell_index - 1).
TNode<IntPtrT> export_index = IntPtrSub(cell_index, IntPtrConstant(1));
TNode<Cell> cell =
CAST(LoadFixedArrayElement(regular_exports, export_index));
SetAccumulator(LoadObjectField(cell, Cell::kValueOffset));
Goto(&end);
}
BIND(&if_import);
{
TNode<FixedArray> regular_imports = LoadObjectField<FixedArray>(
module, SourceTextModule::kRegularImportsOffset);
// The actual array index is (-cell_index - 1).
TNode<IntPtrT> import_index = IntPtrSub(IntPtrConstant(-1), cell_index);
TNode<Cell> cell =
CAST(LoadFixedArrayElement(regular_imports, import_index));
SetAccumulator(LoadObjectField(cell, Cell::kValueOffset));
Goto(&end);
}
BIND(&end);
Dispatch();
}
// StaModuleVariable <cell_index> <depth>
//
// Store accumulator to the module variable identified by <cell_index>.
// <depth> is the depth of the current context relative to the module context.
IGNITION_HANDLER(StaModuleVariable, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> cell_index = BytecodeOperandImmIntPtr(0);
TNode<Uint32T> depth = BytecodeOperandUImm(1);
TNode<Context> module_context = GetContextAtDepth(GetContext(), depth);
TNode<SourceTextModule> module =
CAST(LoadContextElement(module_context, Context::EXTENSION_INDEX));
Label if_export(this), if_import(this), end(this);
Branch(IntPtrGreaterThan(cell_index, IntPtrConstant(0)), &if_export,
&if_import);
BIND(&if_export);
{
TNode<FixedArray> regular_exports = LoadObjectField<FixedArray>(
module, SourceTextModule::kRegularExportsOffset);
// The actual array index is (cell_index - 1).
TNode<IntPtrT> export_index = IntPtrSub(cell_index, IntPtrConstant(1));
TNode<HeapObject> cell =
CAST(LoadFixedArrayElement(regular_exports, export_index));
StoreObjectField(cell, Cell::kValueOffset, value);
Goto(&end);
}
BIND(&if_import);
{
// Not supported (probably never).
Abort(AbortReason::kUnsupportedModuleOperation);
Goto(&end);
}
BIND(&end);
Dispatch();
}
// PushContext <context>
//
// Saves the current context in <context>, and pushes the accumulator as the
// new current context.
IGNITION_HANDLER(PushContext, InterpreterAssembler) {
TNode<Context> new_context = CAST(GetAccumulator());
TNode<Context> old_context = GetContext();
StoreRegisterAtOperandIndex(old_context, 0);
SetContext(new_context);
Dispatch();
}
// PopContext <context>
//
// Pops the current context and sets <context> as the new context.
IGNITION_HANDLER(PopContext, InterpreterAssembler) {
TNode<Context> context = CAST(LoadRegisterAtOperandIndex(0));
SetContext(context);
Dispatch();
}
class InterpreterBinaryOpAssembler : public InterpreterAssembler {
public:
InterpreterBinaryOpAssembler(CodeAssemblerState* state, Bytecode bytecode,
OperandScale operand_scale)
: InterpreterAssembler(state, bytecode, operand_scale) {}
using BinaryOpGenerator = TNode<Object> (BinaryOpAssembler::*)(
const LazyNode<Context>& context, TNode<Object> left, TNode<Object> right,
TNode<UintPtrT> slot, const LazyNode<HeapObject>& maybe_feedback_vector,
UpdateFeedbackMode update_feedback_mode, bool rhs_known_smi);
void BinaryOpWithFeedback(BinaryOpGenerator generator) {
TNode<Object> lhs = LoadRegisterAtOperandIndex(0);
TNode<Object> rhs = GetAccumulator();
TNode<Context> context = GetContext();
TNode<UintPtrT> slot_index = BytecodeOperandIdx(1);
TNode<HeapObject> maybe_feedback_vector = LoadFeedbackVector();
BinaryOpAssembler binop_asm(state());
TNode<Object> result =
(binop_asm.*generator)([=] { return context; }, lhs, rhs, slot_index,
[=] { return maybe_feedback_vector; },
UpdateFeedbackMode::kOptionalFeedback, false);
SetAccumulator(result);
Dispatch();
}
void BinaryOpSmiWithFeedback(BinaryOpGenerator generator) {
TNode<Object> lhs = GetAccumulator();
TNode<Smi> rhs = BytecodeOperandImmSmi(0);
TNode<Context> context = GetContext();
TNode<UintPtrT> slot_index = BytecodeOperandIdx(1);
TNode<HeapObject> maybe_feedback_vector = LoadFeedbackVector();
BinaryOpAssembler binop_asm(state());
TNode<Object> result =
(binop_asm.*generator)([=] { return context; }, lhs, rhs, slot_index,
[=] { return maybe_feedback_vector; },
UpdateFeedbackMode::kOptionalFeedback, true);
SetAccumulator(result);
Dispatch();
}
};
// Add <src>
//
// Add register <src> to accumulator.
IGNITION_HANDLER(Add, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_AddWithFeedback);
}
// Sub <src>
//
// Subtract register <src> from accumulator.
IGNITION_HANDLER(Sub, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_SubtractWithFeedback);
}
// Mul <src>
//
// Multiply accumulator by register <src>.
IGNITION_HANDLER(Mul, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_MultiplyWithFeedback);
}
// Div <src>
//
// Divide register <src> by accumulator.
IGNITION_HANDLER(Div, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_DivideWithFeedback);
}
// Mod <src>
//
// Modulo register <src> by accumulator.
IGNITION_HANDLER(Mod, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_ModulusWithFeedback);
}
// Exp <src>
//
// Exponentiate register <src> (base) with accumulator (exponent).
IGNITION_HANDLER(Exp, InterpreterBinaryOpAssembler) {
BinaryOpWithFeedback(&BinaryOpAssembler::Generate_ExponentiateWithFeedback);
}
// AddSmi <imm>
//
// Adds an immediate value <imm> to the value in the accumulator.
IGNITION_HANDLER(AddSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(&BinaryOpAssembler::Generate_AddWithFeedback);
}
// SubSmi <imm>
//
// Subtracts an immediate value <imm> from the value in the accumulator.
IGNITION_HANDLER(SubSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(&BinaryOpAssembler::Generate_SubtractWithFeedback);
}
// MulSmi <imm>
//
// Multiplies an immediate value <imm> to the value in the accumulator.
IGNITION_HANDLER(MulSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(&BinaryOpAssembler::Generate_MultiplyWithFeedback);
}
// DivSmi <imm>
//
// Divides the value in the accumulator by immediate value <imm>.
IGNITION_HANDLER(DivSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(&BinaryOpAssembler::Generate_DivideWithFeedback);
}
// ModSmi <imm>
//
// Modulo accumulator by immediate value <imm>.
IGNITION_HANDLER(ModSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(&BinaryOpAssembler::Generate_ModulusWithFeedback);
}
// ExpSmi <imm>
//
// Exponentiate accumulator (base) with immediate value <imm> (exponent).
IGNITION_HANDLER(ExpSmi, InterpreterBinaryOpAssembler) {
BinaryOpSmiWithFeedback(
&BinaryOpAssembler::Generate_ExponentiateWithFeedback);
}
class InterpreterBitwiseBinaryOpAssembler : public InterpreterAssembler {
public:
InterpreterBitwiseBinaryOpAssembler(CodeAssemblerState* state,
Bytecode bytecode,
OperandScale operand_scale)