2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "runtime/vm/translator/hopt/ir.h"
19 namespace HPHP
{ namespace VM
{ namespace JIT
{
21 //////////////////////////////////////////////////////////////////////
23 Type::Tag
outputType(const IRInstruction
* inst
) {
24 assert(inst
->hasDst() && "outputType requires inst->hasDst()");
26 switch (inst
->getOpcode()) {
28 return Type::unbox(inst
->getSrc(0)->getType());
31 return Type::box(inst
->getSrc(0)->getType());
35 return Type::box(inst
->getSrc(1)->getType());
37 case AddElem
: return Type::Arr
;
38 case AddNewElem
: return Type::Arr
;
39 case ArrayAdd
: return Type::Arr
;
40 case AssertStk
: return Type::StkPtr
;
41 case Call
: return Type::StkPtr
;
42 case Concat
: return Type::Str
;
43 case CreateCont
: return Type::Obj
;
44 case DefActRec
: return Type::ActRec
;
45 case DefCns
: return Type::Bool
;
46 case DefFP
: return Type::StkPtr
;
47 case DefFunc
: return Type::FuncPtr
;
48 case DefSP
: return Type::StkPtr
;
49 case FreeActRec
: return Type::StkPtr
;
50 case GenericRetDecRefs
: return Type::StkPtr
;
51 case GuardStk
: return Type::StkPtr
;
52 case InstanceOf
: return Type::Bool
;
53 case InstanceOfBitmask
: return Type::Bool
;
54 case ExtendsClass
: return Type::Bool
;
55 case InterpOne
: return Type::StkPtr
;
56 case IsNSet
: return Type::Bool
;
57 case IsNType
: return Type::Bool
;
58 case IsSet
: return Type::Bool
;
59 case IsType
: return Type::Bool
;
60 case LdARFuncPtr
: return Type::FuncPtr
;
61 case LdCachedClass
: return Type::ClassPtr
;
62 case LdClsMethodCache
: return Type::FuncClassPtr
;
63 case LdClsMethod
: return Type::FuncPtr
;
64 case LdClsPropAddr
: return Type::PtrToGen
;
65 case LdCls
: return Type::ClassPtr
;
66 case LdContLocalsPtr
: return Type::PtrToCell
;
67 case LdCurFuncPtr
: return Type::FuncPtr
;
68 case LdFixedFunc
: return Type::FuncPtr
;
69 case LdFuncCls
: return Type::ClassPtr
;
70 case LdFunc
: return Type::FuncPtr
;
71 case LdHome
: return Type::Home
;
72 case LdLocAddr
: return Type::PtrToGen
;
73 case LdObjClass
: return Type::ClassPtr
;
74 case LdObjMethod
: return Type::FuncPtr
;
75 case LdPropAddr
: return Type::PtrToGen
;
76 case LdRetAddr
: return Type::RetAddr
;
77 case LdStackAddr
: return Type::PtrToGen
;
78 case LdThis
: return Type::Obj
;
79 case NewArray
: return Type::Arr
;
80 case NewObj
: return Type::StkPtr
;
81 case NewTuple
: return Type::Arr
;
82 case NInstanceOf
: return Type::Bool
;
83 case NInstanceOfBitmask
: return Type::Bool
;
84 case RetAdjustStack
: return Type::StkPtr
;
85 case SpillStack
: return Type::StkPtr
;
86 case UnboxPtr
: return Type::PtrToCell
;
88 // Vector translator opcodes
89 case DefMIStateBase
: return Type::PtrToCell
;
90 case PropX
: return Type::PtrToGen
;
92 case CGetElem
: return Type::Cell
;
116 // Jumps have dests just to allow finding the TCA to patch. The
117 // dest SSATmp doesn't actually carry any value.
130 case JmpInstanceOfBitmask
:
131 case JmpNInstanceOfBitmask
:
139 // Output type is the same as the first input's type.
145 return inst
->getSrc(0)->getType();
147 // Output type is given by a type paramter to the instruction.
159 return inst
->getTypeParam();
162 always_assert(0 && "outputType not known for opcode");
166 void assertOperandTypes(const IRInstruction
* inst
) {
168 auto const tparam
= inst
->getTypeParam();
169 auto const s0
= inst
->getSrc(0);
170 auto const s1
= inst
->getSrc(1);
171 auto const t0
= s0
? s0
->getType() : Type::None
;
172 auto const t1
= s1
? s1
->getType() : Type::None
;
174 auto constStaticStr
= [] (SSATmp
* ssa
) {
175 assert(ssa
->isConst() && ssa
->getType() == Type::StaticStr
);
178 auto constInt
= [] (SSATmp
* ssa
) {
179 assert(ssa
->isConst() && ssa
->getType() == Type::Int
);
182 switch (inst
->getOpcode()) {
189 assert(t0
== Type::Int
|| t0
== Type::Bool
);
190 assert(t1
== Type::Int
|| t1
== Type::Bool
);
194 assert(tparam
== Type::Int
|| tparam
== Type::Bool
||
195 tparam
== Type::StkPtr
|| tparam
== Type::TCA
);
199 assert(t0
== Type::Obj
);
213 assert(t0
== Type::Obj
);
217 auto valT
= inst
->getSrc(2)->getType();
218 assert(valT
== Type::Int
|| valT
== Type::Bool
);
223 assert(t0
== Type::PtrToCell
|| t0
== Type::PtrToGen
);
232 //////////////////////////////////////////////////////////////////////