forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir.specification
More file actions
2559 lines (1550 loc) · 86.3 KB
/
Copy pathir.specification
File metadata and controls
2559 lines (1550 loc) · 86.3 KB
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
*******************************************
* HipHop Intermediate Representation (HHIR)
*******************************************
Introduction
------------
The HipHop Intermediate Representation (IR) is a typed, in-memory,
static-single-assignment, intermediate-level representation of HHBC programs
used for just in time compilation, with these goals:
1. Complete. The IR represents a program or program fragment entirely,
without reference to HHBC or other upstream forms of the program.
2. Type-Safe. Since the IR deals directly with refined types and internal VM
types, all operations are typesafe. All instruction parameters have a
parameter type P, and all variables have a type S. Given an instruction
with source parameter type P and variable type S, S must be equal to or
more refined than P (S == P or S <: P).
3. Machine Independent. Since this IR is intended to be used in a JIT
compiler, it will always be used in a machine specific context.
Nevertheless, we rely on machine independence in order to separate
concerns and increase portability of the VM. Passes which manipulate IR
based on PHP or HHBC semantics should be portable. Passes which deal with
machine specifics (such as register allocation) should be done in the
lower level IR (vasm). Types are machine independent.
The unit of compilation is the IRUnit, which is a collection of Blocks
containing IRInstructions that produce and consume SSATmp values. Blocks are
single-entry, single-exit sequences of instructions (i.e. basic
blocks). Instructions may be annotated with Type parameter which modifies the
instruction's behavior, or with additional compile-time constant data (see
extra-data.h). Each SSATmp has a Type which describes the set of values it may
hold, over its entire live range. Instructions may have side effects, which
occur in execution order.
The static single assignment form guarantees the following two invariants for a
well-formed compilation unit:
1. Each SSATmp is assigned to by exactly one IRInstruction.
2. Definitions dominate uses. Every path to an IRInstruction using an SSATmp
first executes the IRInstruction defining the SSATmp.
Any pass that generates or manipulates IR must preserve these invariants,
however it is possible and expected for the invariants to be temporarily broken
during IR generation or during an optimization pass.
Control Flow
------------
IRUnits have one entry block, zero or more exit blocks, and zero or more catch
blocks. Exit blocks leave the compilation unit in the middle of the same PHP
function using one of several instructions that exit a compilation unit
(e.g. ReqBindJmp). Catch blocks are blocks that are reachable from exceptional
control flow edges, and are executed during unwinding if an exception
propagates through the instruction that had it as a `taken' edge.
No SSATmps are defined on entry to the main Block.
Blocks which are join points may start with a DefLabel with destination
SSATmps. In that case, each predecessor must be a Jmp passing a matching number
of sources. In this case the Jmp acts as a tail-call, passing arguments the
same way a plain call would.
Together, the sources of the Jmp instructions and the destinations of the
DefLabel instructions act as traditional SSA Phi pseudo-functions; The type of
the DefLabel's destination is the type-union of the corresponding sources.
Because the Jmp sources are at the ends of blocks, they do not violate the SSA
dominator rule (rule 2, above).
Types
-----
For an overview of the HHIR type system, see the "Type System" section in
hackers-guide/jit-core.md.
SSATmps
-------
An SSATmp represents a virtual register. Since HHIR uses SSA, an SSATmp may
only be assigned to by one instruction. The type of an SSATmp represents the
set of values it may hold at the point it is defined, which is invariant over
the lifetime of the variable (from the definition point to the last use).
IRInstructions
--------------
An instruction is an executable operation with zero or more inputs (sources),
zero or one result (destination), and possible side effects such as accessing
memory, doing I/O, and which may branch or throw an exception. Some
instructions have a Type parameter which modifies its behavior, or other "extra
data" in an arbitrary C++ struct (see extra-data.h).
Each instruction has a signature which describes its effect, parameter types,
and return type, for example:
r:Bool = IsType<T> s:Gen
By convention we use infix; destinations on the left, = represents assignment,
then the opcode name, and source parameters. Types are to the right of the
entities they modify, separated by : for results, sources, and variables, or
delimited by <> for instruction modifiers.
Instruction flags further describe their behavior:
HasDest
NaryDest
The instruction defines exactly one destination variable (HasDest) or a
varying number of destination variables (NaryDest). These flags are mutually
exclusive. An instruction with neither of these flags set has zero
destination variables.
Note that an instruction's destination variable may sometimes be a copy of
one of the input variables. (For example, AddElem returns the array it took
as an input.)
CanCSE
The instruction is safe to elide through common subexpression elimination.
Essential
Whether the instruction is essential indicates whether it can be elided
through certain types of optimizations.
Currently this is just used to flag whether we are allowed to do dead code
elimination on it.
CallsNative
Indicates that the instruction will call a native helper.
The register allocator uses this to optimize register spills around native
calls and to bias register allocation toward arguments and return values.
ConsumesRC
The instruction consumes a reference to one or more of its sources, either by
decreasing its refcount or storing the reference to memory.
KillsSource
The instruction calls decref on one or more of its sources. Unless a source
is known to have a refcount > 1 before the instruction executes, it cannot
safely be used after the instruction has executed.
ProducesRC
The instruction produces an incref'd value.
This flag is currently unused.
MayRaiseError
The instruction may raise an error, and must have an edge to a catch block.
Terminal
The instruction has no next instruction; it either jumps, returns, or throws.
Branch
The instruction has a (sometimes optional) taken edge. Instructions that are
conditional branches (i.e. a Branch that is not Terminal) will also have a
next edge.
Passthrough
The value of the instruction's dest is the same as one of its inputs; it
differs only in the refcount of the underlying object, the type of the
variable, or some other property that doesn't affect the value of the
variable itself.
ModifiesStack
The instruction modifies the in-memory evaluation stack in the process of
performing its primary work. It will have a StkPtr destination in addition to
its primary destination.
HasStackVersion
This instruction has a counterpart that returns a StkPtr in addition to any
primary destination. The behavior of the stack-modifying version is otherwise
identical.
MInstrProp
The instruction may affect the type and/or value of its base operand,
operating on object properties.
MInstrElem
The instruction may affect the type and/or value of its base operand,
operating on array elements.
Instruction set
---------------
1. Checks and Asserts
Note: Instructions that guard or check boxed types only check that the operand
is boxed, and they ignore the type of the value inside the box (the inner
type). The inner type is normally checked when the value within the box is
about to be loaded, using a separate CheckRefInner instruction.
| CheckType<T>, DRefineS(0), S(Gen), B|E|P
Check that the type of the src S0 is T, and if so copy it to D. If S0 is not
type T, branch to block B.
| CheckNullptr, ND, S(CountedStr,Nullptr), B|E|CRc
If S0 is not a null pointer, branch to block B. This is used to check the
return value of a native helper that returns a potentially null StringData*.
| AssertType, DRefineS(0), S(Gen,Cls), C|E|P
Assert that the type of S0 is T, copying it to D.
| CheckTypeMem<T>, ND, S(PtrToGen), B|E
If the value pointed to by S0 is not type T, branch to the block B.
| GuardLoc<T,localId>, ND, S(FramePtr) S(StkPtr), E
Guard that type of the given localId on the frame S0 is a subtype of the type
T; if not, make a fallback jump. (A jump to a service request that chains to
a retranslation for this tracelet.)
Returns a new frame pointer representing the same frame as S0 but with the
knowledge that the guarded local has type T.
| HintLocInner<T,localId>, ND, S(FramePtr), E
Hint that the inner type of a BoxedCell in localId is likely type T, where T
is a subtype of BoxedCell. The type must be guarded on before it is known to
be true (via LdRef).
| CheckLoc<T,localId>, ND, S(FramePtr), B|E
Check that type of the given localId on the frame S0 is T; if not, branch to
block B.
Returns a new frame pointer representing the same frame as S0 but with the
knowledge that the checked local has type T.
| AssertLoc<T,localId>, ND, S(FramePtr), E
Asserts that type of the supplied local on the frame S0 is T. This is used
for local type information, and is similar to GuardLoc except it doesn't
imply a runtime check (the assertion must've already been proven to be true)
and cannot cause control flow.
Returns a new frame pointer representing the same frame as S0 but with the
knowledge that the asserted local has type T.
| GuardStk<T,offset>, D(StkPtr), S(StkPtr) S(FramePtr), E
Guard that the type of the cell on the stack pointed to by S0 at offset (in
cells) is T. If not, make a fallback jump. (A jump to a service request that
chains to a retranslation for this tracelet.)
Returns a new StkPtr that represents the same stack but with the knowledge
that the slot at the index S1 has type T.
| HintStkInner<T,offset>, D(StkPtr), S(StkPtr), E
Hint that the inner type of the BoxedInitCell on the stack pointed to by S0
at offset (in cells) is T. The type must be guarded on before it is known to
be true (via LdRef).
Returns a new StkPtr that represents the same stack but with the prediction
information.
| CheckStk<T,offset>, D(StkPtr), S(StkPtr), B|E
Check that the type of the cell on the stack pointed to by S0 at offset (in
cells) is T; if not, branch to block B.
Returns a new StkPtr that represents the same stack but with the knowledge
that the slot at the index S1 has type T.
| AssertStk<T,offset>, D(StkPtr), S(StkPtr), E
Returns a new StkPtr that represents the same stack as S0, but with the
knowledge that the slot at offset (in cells) has type T. This is similar to a
GuardStk except that it does not imply a runtime check and cannot cause
control flow.
| CastStk<T,offset>, D(StkPtr), S(StkPtr), Er
Returns a new StkPtr that represents the same stack as S0, but with the slot
at offset (in cells) converted to type T.
| CastStkIntToDbl<offset>, D(StkPtr), S(StkPtr), E
Returns a new StkPtr where the slot at offset has been converted from an
integer to double.
The following instructions deal with parameter coercion (the standard type
conversion for arguments to HNI functions). If parameter coercion fails these
functions will throw a TVCoercion exception. They may throw other types of
exceptions depending on how coercion is implemented.
| CoerceStk<T,offset,fn,argNum>, D(StkPtr), S(StkPtr), Er
Returns a new StkPtr that represents the same stack as S0, but with the slot
at offset (in cells) converted to type T. May throw an exception in the case
of failed parameter coercion. The callee is f, and the position of the
argument being coerced is argNum.
| CoerceCellToBool<fn,argNum>, D(Bool), S(Cell), Er
| CoerceCellToInt<fn,argNum>, D(Int), S(Cell), Er
| CoerceStrToInt<fn,argNum>, D(Int), S(Str), Er
| CoerceCellToDbl<fn,argNum>, D(Dbl), S(Cell), Er
| CoerceStrToDbl<fn,argNum>, D(Dbl), S(Str), Er
These instructions convert either a Cell or a Str to a primitive type (Bool,
Int, Dbl) and return the resulting value. They may throw an exception upon
failed type coercion. They are encoded along with callee Func, fn, and the
integer position of the argument, argNum, being coerced.
| CheckInit, ND, S(Gen), B
If S0's type is Uninit, branch to block B.
| CheckInitMem, ND, S(PtrToGen) C(Int), B
If the value at S0 + S1 (in bytes) has type Uninit, branch to block B.
| CheckCold<TransID>, ND, NA, B|E
Check if the counter associated with translation TransID is cold (i.e. within
a fixed threshold). If it's not (i.e. such translation has reached the
"hotness threshold"), then branch to block B.
| GuardRefs, ND, S(Func) S(Int) C(Int) S(Int) S(Int) S(FramePtr) S(StkPtr), E
Perform reffiness guard checks. Operands:
S0 - function pointer for the frame
S1 - num params expected in the func
S2 - first bit to check, must be a multiple of 64
S3 - mask to check (RefDeps::Record::m_mask entries)
S4 - values to check (RefDeps::Record::m_vals entries)
S5 - Pointer to the current frame
S6 - Pointer to the current VM stack
If any of the checks fail, make a fallback jump. (Jump to a service request
that will chain to a retranslation of this tracelet.)
| CheckRefs, ND, S(Func) S(Int) C(Int) S(Int) S(Int), B|E
Perform reffiness guard checks. Operands:
S0 - function pointer for the frame
S1 - num params expected in the func
S2 - first bit to check, must be a multiple of 64
S3 - mask to check (RefDeps::Record::m_mask entries)
S4 - values to check (RefDeps::Record::m_vals entries)
If any of the checks fail, branch to block B.
| EndGuards, ND, NA, E
A no-op at runtime, this instruction serves to mark the end of the initial
sequence of guards in a trace.
| CheckNonNull, DSubtract(0, Nullptr), S(Nullptr,Func,PtrToGen,TCA,Cls), B
If the value in S0 is Nullptr, branch to block B.
| AssertNonNull, DSubtract(0, Nullptr), S(Nullptr,CountedStr,Func), P
Returns S0, with Nullptr removed from its type. This instruction currently
supports a very limited range of types but can be expanded if needed.
| CheckStaticLocInit, ND, S(BoxedCell), B
Check if the static local (RDS) RefData represented by S0 is initialized, and
if not branch to block B.
2. Arithmetic
| AbsDbl, D(Dbl), S(Dbl), C
| AddInt, D(Int), S(Int) S(Int), C
| SubInt, D(Int), S(Int) S(Int), C
| MulInt, D(Int), S(Int) S(Int), C
| AndInt, D(Int), S(Int) S(Int), C
| AddDbl, D(Dbl), S(Dbl) S(Dbl), C
| SubDbl, D(Dbl), S(Dbl) S(Dbl), C
| MulDbl, D(Dbl), S(Dbl) S(Dbl), C
| DivDbl, D(Dbl), S(Dbl) S(Dbl), B|C
| Sqrt, D(Dbl), S(Dbl), C
| OrInt, D(Int), S(Int) S(Int), C
| XorInt, D(Int), S(Int) S(Int), C
| Shl, D(Int), S(Int) S(Int), C
| Shr, D(Int), S(Int) S(Int), C
| Floor, D(Dbl), S(Dbl), C
| Ceil, D(Dbl), S(Dbl), C
| AddIntO, D(Int), S(Int) S(Int), B|C
| SubIntO, D(Int), S(Int) S(Int), B|C
| MulIntO, D(Int), S(Int) S(Int), B|C
Double arithmetic, integer arithmetic, and integer bitwise operations.
Performs the operation described by the opcode name on S0 and S1, and puts
the result in D.
Undefined behavior occurs if Mod is given a divisor of zero, or if the
divisor is -1 and the dividend is the minimum representable integer.
AbsDbl computes the absolute value of a double-precision value.
DivDbl will branch to block B when S1 is zero (signed or unsigned). When the
result of the division is a real valued number DivDbl conforms to IEEE 754.
In particular should the result of a division be zero the sign will follow
normal sign rules for division.
Note that Shr is an arithmetic right shift: The MSB is sign-extended.
Floor and Ceil will return an integral value not greater, or not less
than their input respectively. Their use requires SSE 4.1, availability
should be checked before they are emitted.
AddIntO, SubIntO, MulIntO perform integer arithmetic on S0 and S1, but will
branch to block B on integer overflow.
| XorBool, D(Bool), S(Bool) S(Bool), C
Logical XOR of the two sources. (Note that && and || do not have
corresponding opcodes because they're handled at the bytecode level, to
implement short-circuiting.)
| Mod, D(Int), S(Int) S(Int), C
Compute S0 mod S1. If S1 is -1 or 0 the results are undefined.
3. Type conversions
To array conversions:
| ConvBoolToArr, D(Arr), S(Bool), C|PRc
| ConvDblToArr, D(Arr), S(Dbl), C|PRc
| ConvIntToArr, D(Arr), S(Int), C|PRc
| ConvObjToArr, D(Arr), S(Obj), Er|PRc|CRc|K
| ConvStrToArr, D(Arr), S(Str), PRc|CRc
| ConvCellToArr, D(Arr), S(Cell), Er|PRc|CRc|K
To bool conversions:
| ConvArrToBool, D(Bool), S(Arr), NF
| ConvDblToBool, D(Bool), S(Dbl), C
| ConvIntToBool, D(Bool), S(Int), C
| ConvStrToBool, D(Bool), S(Str), NF
| ConvObjToBool, D(Bool), S(Obj), NF
| ConvCellToBool, D(Bool), S(Cell), NF
To double conversions:
| ConvArrToDbl, D(Dbl), S(Arr), NF
| ConvBoolToDbl, D(Dbl), S(Bool), C
| ConvIntToDbl, D(Dbl), S(Int), C
| ConvObjToDbl, D(Dbl), S(Obj), Er
| ConvStrToDbl, D(Dbl), S(Str), NF
| ConvCellToDbl, D(Dbl), S(Cell), Er
To int conversions:
| ConvArrToInt, D(Int), S(Arr), NF
| ConvBoolToInt, D(Int), S(Bool), C
| ConvDblToInt, D(Int), S(Dbl), C
| ConvObjToInt, D(Int), S(Obj), Er|K
| ConvStrToInt, D(Int), S(Str), NF
| ConvCellToInt, D(Int), S(Cell), Er|K
To object conversions:
| ConvCellToObj, D(Obj), S(Cell), Er|CRc|PRc|K
To string conversions:
| ConvBoolToStr, D(StaticStr), S(Bool), C
| ConvDblToStr, D(Str), S(Dbl), PRc
| ConvIntToStr, D(Str), S(Int), PRc
| ConvObjToStr, D(Str), S(Obj), PRc|Er
| ConvResToStr, D(Str), S(Res), PRc|Er
| ConvCellToStr, D(Str), S(Cell), PRc|Er
All the above opcodes convert S0 from its current type to the destination
type, according to the PHP semantics of such a conversion.
| ConvClsToCctx, D(Cctx), S(Cls), C
Convert a class to a class context (i.e. the class with a 1 or'd into the low
bit).
4. Boolean predicates
| Gt, D(Bool), S(Gen) S(Gen), C
| GtX, D(Bool), S(Gen) S(Gen), Er|C
| Gte, D(Bool), S(Gen) S(Gen), C
| GteX, D(Bool), S(Gen) S(Gen), Er|C
| Lt, D(Bool), S(Gen) S(Gen), C
| LtX, D(Bool), S(Gen) S(Gen), Er|C
| Lte, D(Bool), S(Gen) S(Gen), C
| LteX, D(Bool), S(Gen) S(Gen), Er|C
| Eq, D(Bool), S(Gen) S(Gen), C
| EqX, D(Bool), S(Gen) S(Gen), Er|C
| Neq, D(Bool), S(Gen) S(Gen), C
| NeqX, D(Bool), S(Gen) S(Gen), Er|C
| Same, D(Bool), S(Gen) S(Gen), C
| NSame, D(Bool), S(Gen) S(Gen), C
Perform comparisons with PHP semantics on S0 and S1, and put the result in D.
The -X versions may re-enter the VM when comparing an Object with a string,
and therefore may throw exceptions. The non-X versions must not be passed
(Object,String) pairs, and do not throw. Note that Same and NSame never
re-enter or throw, for any types.
| GtInt, D(Bool), S(Int) S(Int), C
| GteInt, D(Bool), S(Int) S(Int), C
| LtInt, D(Bool), S(Int) S(Int), C
| LteInt, D(Bool), S(Int) S(Int), C
| EqInt, D(Bool), S(Int) S(Int), C
| NeqInt, D(Bool), S(Int) S(Int), C
Perform 64-bit integer comparisons.
| GtDbl, D(Bool), S(Dbl) S(Dbl), C
| GteDbl, D(Bool), S(Dbl) S(Dbl), C
| LtDbl, D(Bool), S(Dbl) S(Dbl), C
| LteDbl, D(Bool), S(Dbl) S(Dbl), C
| EqDbl, D(Bool), S(Dbl) S(Dbl), C
| NeqDbl, D(Bool), S(Dbl) S(Dbl), C
Perform comparisons of doubles. Comparisons that are unordered according to
IEEE 754 (such as when at least one operand is NaN) result in false.
| InstanceOf, D(Bool), S(Cls) S(Cls|Nullptr), C
Sets D based on whether S0 is a descendant of the class, interface, or trait
in S1. (Note that this is always false for a trait). S1 may be null at
runtime if the class is not defined.
| InstanceOfIface, D(Bool), S(Cls) CStr, C
Fast path for interface checks. Sets D based on whether S0 implements S1, but
S1 must be a unique interface. This should only be used in repo-authoritative
mode.
| ExtendsClass, D(Bool), S(Cls) C(Cls), C
A fast-path for instanceof checks. Sets D based on whether S0 is a descendant
of the class in S1, where S1 must be a unique class that is not an interface
or a trait.
| InstanceOfBitmask, D(Bool), S(Cls) CStr, C
| NInstanceOfBitmask, D(Bool), S(Cls) CStr, C
A fast-path for instanceof checks. Sets D based on whether S0 is a descendant
of the class named by S1, where S1 must have a bit allocated for it in the
fast instance check bitvector (see class.h).
| InterfaceSupportsArr, D(Bool), S(Str), C
| InterfaceSupportsStr, D(Bool), S(Str), C
| InterfaceSupportsInt, D(Bool), S(Str), C
| InterfaceSupportsDbl, D(Bool), S(Str), C
Returns whether t instanceof S0 returns true when t is of the given type.
| IsType<T>, D(Bool), S(Cell), C
Sets D to true iff S0 holds a value that is of type T.
| IsNType<T>, D(Bool), S(Cell), C
Sets D to true iff S0 holds a value that is not of type T.
| IsTypeMem<T>, D(Bool), S(PtrToGen), NF
Sets D to true iff the value referenced by S0 is of type T.
The value in S0 must not be a pointer into the evaluation stack or frame
locals.
| IsNTypeMem<T>, D(Bool), S(PtrToGen), NF
Sets D to true iff the value referenced by S0 is not of type T.
| IsScalarType, D(Bool), S(Cell), C
Returns true if S0 is of type Int, Bool, Dbl or Str. Returns false otherwise.
| IsWaitHandle, D(Bool), S(Obj), C
Sets D to true iff S0 is a subclass of WaitHandle.
5. Branches
There is a conditional branch instruction for each predicate above, to enable
generating efficient compare-and-branch instruction sequences.
| JmpGt, ND, S(Gen) S(Gen), B|E
| JmpGte, ND, S(Gen) S(Gen), B|E
| JmpLt, ND, S(Gen) S(Gen), B|E
| JmpLte, ND, S(Gen) S(Gen), B|E
| JmpEq, ND, S(Gen) S(Gen), B|E
| JmpNeq, ND, S(Gen) S(Gen), B|E
| JmpSame, ND, S(Gen) S(Gen), B|E
| JmpNSame, ND, S(Gen) S(Gen), B|E
| JmpGtInt, ND, S(Int) S(Int), B|E
| JmpGteInt, ND, S(Int) S(Int), B|E
| JmpLtInt, ND, S(Int) S(Int), B|E
| JmpLteInt, ND, S(Int) S(Int), B|E
| JmpEqInt, ND, S(Int) S(Int), B|E
| JmpNeqInt, ND, S(Int) S(Int), B|E
| JmpInstanceOfBitmask, ND, S(Cls) CStr, B|E
| JmpNInstanceOfBitmask, ND, S(Cls) CStr, B|E
Fused jump instructions. These all operate exactly as their corresponding
query op, but also take a label to jump to when the condition is true.
| JmpZero, ND, S(Int,Bool), B|E
| JmpNZero, ND, S(Int,Bool), B|E
Conditionally jump to based on S0.
| JmpSSwitchDest, ND, S(TCA), T|E
Jump to the target of a sswitch statement, leaving the tracelet, where the
target TCA is S0.
| JmpSwitchDest, ND, S(Int), T|E
Jump to the target of a switch statement, leaving the tracelet, using table
metadata <JmpSwitchData> and index S0.
| CheckSurpriseFlags, ND, NA, B|E
Tests the implementation-specific surprise flags. If they're true, branches
to block B.
| FunctionReturnHook, ND, S(FramePtr) S(Gen), Er|E
Suprise flag hook for function returns.
| FunctionSuspendHook, ND, S(FramePtr) C(Bool), Er|E
Suprise flag hook for suspending async functions.
| Halt, ND, NA, T|E
Halt execution. Used only in tests, as a terminal instruction that does not
require any inputs or any successors.
| Jmp, ND, SVar(Top), B|T|E
Unconditional jump to block B. In the second form, the target block must
start with a DefLabel with the same number of destinations as Jmp's number of
sources. Jmp parallel-copies its sources to the DefLabel destinations.
| DefLabel, DMulti, NA, E
DefLabel defines variables received from a previous Jmp. A DefLabel with zero
destinations is a no-op, and the predecessor blocks may not necessarily end
in Jmp. A DefLabel with one or more destinations may only be reached by a Jmp
instruction with the same number of sources. Ordinary branch instructions may
not pass values to a DefLabel.
| ClsNeq<class>, D(Bool), S(Cls), C
Compare S0 to the class `class', returning true if it is not the same.
6. Reference manipulation
| Box, DBox(0), S(Gen), E|CRc|PRc
Box S0 if it is unboxed, and put the resulting BoxedCell in D.
| UnboxPtr, DUnboxPtr, S(PtrToGen), NF
If S0 points to a cell that is KindOfRef, dereference the pointer in the
TypedValue and return a pointer to the inner-cell in D.
| BoxPtr, DBoxPtr, S(PtrToGen), NF
Boxes the TypeValue that S0 points to if it is not boxed. The result D points
to the same TypedValue as S0 but has a more refined type.
S0 may not already point into a RefData (due to VM invariants), although the
IR type system does not enforce it.
7. Loads
| LdStack<T,offset>, DParamMayRelax, S(StkPtr), NF
Loads from S0 at offset (in cells), and puts the value in D as type T.
| TakeStack, ND, S(StackElem), E
Does nothing at runtime. Acts as a hint to the optimizer that the code is
taking ownership of a reference to S0.
| LdLoc<T,localId>, DParamMayRelax, S(FramePtr), NF
Loads local slot localId from the frame S0 and puts the value in D as type T.
| LdLocPseudoMain<T,localId>, DParam, S(FramePtr), B
Loads local number localId from frame S0 and puts the value in D if the
local's type is a subtype of T. If the local's type is not a subtype of T,
then the load does not happen, and this instruction branches to B. This
instruction is used for loading locals in pseudo-mains, where they can alias
globals.
| LdStackAddr<T,offset>, DParamPtr(Stk), S(StkPtr), C
Loads the address of the stack slot given by the pointer in S0 at the offset
(in cells). T must be a subtype of PtrToStkGen.
| LdLocAddr<T,localId>, DParamPtr(Frame), S(FramePtr), C
Loads the address of the local slot localId from the frame S0 into D. T must
be a subtype of PtrToFrameGen.
| LdRDSAddr<T,RDSHandle>, DParam, NA, C
Load the address of a Gen that lives at the specified RDS handle. The type
param must be a subtype of PtrToGen.
| LdVectorBase, D(PtrToMembCell), S(Obj), E
| LdPairBase, D(PtrToMembCell), S(Obj), E
Loads the base pointer to an array of Cells from the given collection
instance in S0.
| LdMem<T>, DParam, S(PtrToGen) C(Int), NF
Loads from S0 + S1 (in bytes) and puts the value in D.
| LdContField<T>, DParam, S(Obj) C(Int), NF
Loads a property from the object referenced by S0 at the offset given by S1
and puts the value in D. S0 must be a Generator.
| LdElem, D(Cell), S(PtrToCell) S(Int), NF
Loads the element at index S1 from the base pointer in S0. The index in S1 is
the number of bytes from the base in S0.
| CheckRefInner<T>, ND, S(BoxedCell), B|E
TODO(#2939547): this should take BoxedInitCell
Check that the inner type of the boxed cell in S0 is T, and if not take the
branch to B.
| LdRef<T>, DParam, S(BoxedCell), NF
TODO(#2939547): this should take BoxedInitCell
Loads the value held in the box referenced by S0 and puts the value in D. The
inner type of S0 must be a subtype of T (usually ensured with a previous
CheckRefInner).
| LdCtx, D(Ctx), S(FramePtr), C
Loads into D the value of the m_this/m_cls field out of the frame pointer S0,
which must be a frame for the function in the LdCtx's Marker. The result
could be either an object representing the this pointer or a class context.
| CheckCtxThis, ND, S(Ctx), B|E
Check that the context (m_this or m_cls) in S0 is a non-null $this
pointer. If not, branch to B.
| CastCtxThis, DThis, S(Ctx), C
Convert a Ctx known to contain a $this pointer to a specific object type,
based on the marker func for this instruction.
| LdCctx, D(Cctx), S(FramePtr), C
Loads into D the value of the m_cls field out of the frame pointer S0. The
compiler should generate this only if it can prove that the frame does not
contain a $this pointer.
| LdClsCtx, D(Cls), S(Ctx), C
Loads into D the class representing the current context. Extracts the class
from S0, which can be either the this pointer or the context class.
| LdClsCctx, D(Cls), S(Cctx), C
Loads into D the class representing the current context. Extracts the class
from the S0, which is a context class.
| LdClsCtor, D(Func), S(Cls), C|Er
Loads into D the constructor of class S0. If the constructor cannot be called
from the current context, raise an error.
| DefConst<T>, DParam, NA, C
Define a constant value of type T. D is presumed to be globally available and
the DefConst instruction will not actually appear in the IR instruction
stream.
| Conjure<T>, DParam, NA, NF
Define a value of type T. This instruction aborts at runtime; it is meant to
be used in tests or code that is known to be unreachable.
| LdCls, D(Cls), S(Str) C(Cls), C|E|Er
Loads the class named S0 in the context of the class S1. Invokes autoload and
may raise an error if the class is not defined. The explicit context
parameter allows the compiler to simplify this instruction to a DefConst in
some cases. If S0 is constant, this instruction may be simplified to a
LdClsCached.
| LdClsCached, D(Cls), CStr, C|E|Er
Loads the class named S0 via the RDS. Invokes autoload and may raise an error
if the class is not defined.
| LdClsCachedSafe, D(Cls|Nullptr), CStr, NF
Loads the class whose name is S0 out of the RDS. If the class is not defined,
returns a null pointer.
| LdClsInitData, D(PtrToClsInitCell), S(Cls), C
Loads the pointer to the property initializer array for class S0.
| LookupClsRDSHandle, D(RDSHandle), S(Str), C
Look up the cached-class RDS handle for a given class name.
| DerefClsRDSHandle, D(Cls), S(RDSHandle), NF
Dereference an RDS handle that points to a cached class slot.
| LdCns, DCns, CStr, PRc
Load the constant named S0.
| LookupCns<T,constName>, DCns, CStr, E|Er|PRc
| LookupCnsE<T,constName>, DCns, CStr, E|Er|PRc
Load a constant via the RDS. Raises an undefined constant notice if the
constant cannot be defined. The E variant will instead throw a fatal error if
it cannot define the constant.
| LookupCnsU<T,constName,fallbackName>, DCns, CStr CStr, E|Er|PRc
Load an unqualified constant via the RDS, first by trying constName, then by
trying fallbackName. Raises a notice if neither can be found.
| LookupClsCns<T,className,constName>, DCns, NA, E|Er|PRc
Load a class constant for a class via the RDS, invoking autoload if it is not
defined. This instruction may raise an undefined constant error if autoload
cannot define the constant.
| LdClsMethodFCacheFunc<clsName,methodName>, D(Func|Nullptr), NA, NF
Loads the target cache entry for a forwarding call to clsName::methodName.
May be Nullptr, if the method does not exist or the cache hasn't been filled
yet.
| LookupClsMethodFCache<clsName,methodName>,
| D(Func|Nullptr), C(Cls) S(FramePtr),
| E|Er
Lookup clsName::methodName in the forwarding class method cache. S0 should be
the Class named by clsName and S1 should be the current vm frame pointer. May
return Nullptr if lookup fails using a subset of the required lookup paths,
indicating that a more complete lookup path should be taken. May throw if the
method does not exist.