Remove SpillFrame, merge its memory effects into CallEffects and InlineEnterEffects
[hiphop-php.git] / hphp / runtime / vm / jit / translator-runtime.h
blob2efa7635f5fd8470556d4679829ca5b28181e4dc
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 #ifndef incl_HPHP_TRANSLATOR_RUNTIME_H_
18 #define incl_HPHP_TRANSLATOR_RUNTIME_H_
20 #include "hphp/runtime/base/datatype.h"
21 #include "hphp/runtime/base/rds.h"
22 #include "hphp/runtime/base/req-root.h"
23 #include "hphp/runtime/base/typed-value.h"
24 #include "hphp/runtime/vm/bytecode.h"
26 #include "hphp/runtime/vm/jit/types.h"
28 struct _Unwind_Exception;
30 namespace HPHP {
31 //////////////////////////////////////////////////////////////////////
33 struct Func;
34 struct ClsMethDataRef;
35 struct Iter;
36 struct MInstrState;
37 struct TypeConstraint;
38 struct c_Pair;
39 struct c_Vector;
41 namespace jit {
42 //////////////////////////////////////////////////////////////////////
44 struct ArrayKindProfile;
46 //////////////////////////////////////////////////////////////////////
48 /* Helper functions for translated code */
50 ArrayData* addNewElemHelper(ArrayData* a, TypedValue value);
51 ArrayData* addElemIntKeyHelper(ArrayData* ad, int64_t key, TypedValue val);
52 ArrayData* addElemStringKeyHelper(ArrayData* ad, StringData* key,
53 TypedValue val);
54 ArrayData* dictAddElemIntKeyHelper(ArrayData* ad, int64_t key, TypedValue val);
55 ArrayData* dictAddElemStringKeyHelper(ArrayData* ad, StringData* key,
56 TypedValue val);
57 RefData* boxValue(TypedValue tv);
58 ArrayData* arrayAdd(ArrayData* a1, ArrayData* a2);
59 /* Helper functions for conversion instructions that are too
60 * complicated to inline
62 ArrayData* convCellToArrHelper(TypedValue tv);
63 ArrayData* convArrToNonDVArrHelper(ArrayData* a);
64 ArrayData* convVecToArrHelper(ArrayData* a);
65 ArrayData* convDictToArrHelper(ArrayData* a);
66 ArrayData* convKeysetToArrHelper(ArrayData* a);
67 ArrayData* convArrToVecHelper(ArrayData* a);
68 ArrayData* convDictToVecHelper(ArrayData* a);
69 ArrayData* convKeysetToVecHelper(ArrayData* a);
70 ArrayData* convObjToVecHelper(ObjectData* o);
71 ArrayData* convCellToVecHelper(TypedValue tv);
72 ArrayData* convArrToDictHelper(ArrayData* a);
73 ArrayData* convVecToDictHelper(ArrayData* a);
74 ArrayData* convKeysetToDictHelper(ArrayData* a);
75 ArrayData* convObjToDictHelper(ObjectData* o);
76 ArrayData* convCellToDictHelper(TypedValue tv);
77 ArrayData* convArrToKeysetHelper(ArrayData* a);
78 ArrayData* convVecToKeysetHelper(ArrayData* a);
79 ArrayData* convDictToKeysetHelper(ArrayData* a);
80 ArrayData* convObjToKeysetHelper(ObjectData* o);
81 ArrayData* convCellToKeysetHelper(TypedValue tv);
82 ArrayData* convClsMethToArrHealper(ClsMethDataRef clsmeth);
83 ArrayData* convClsMethToVArrHealper(ClsMethDataRef clsmeth);
84 ArrayData* convClsMethToVecHealper(ClsMethDataRef clsmeth);
85 ArrayData* convClsMethToDArrHealper(ClsMethDataRef clsmeth);
86 ArrayData* convClsMethToDictHealper(ClsMethDataRef clsmeth);
87 ArrayData* convClsMethToKeysetHealper(ClsMethDataRef clsmeth);
88 double convObjToDblHelper(const ObjectData* o);
89 double convArrToDblHelper(ArrayData* a);
90 double convStrToDblHelper(const StringData* s);
91 double convResToDblHelper(const ResourceHdr* r);
92 double convCellToDblHelper(TypedValue tv);
93 StringData* convDblToStrHelper(double i);
94 StringData* convIntToStrHelper(int64_t i);
95 StringData* convObjToStrHelper(ObjectData* o);
96 StringData* convResToStrHelper(ResourceHdr* o);
98 void raiseUndefProp(ObjectData* base, const StringData* name);
99 void raiseUndefVariable(StringData* nm);
100 void VerifyParamTypeSlow(const Class* cls,
101 const Class* constraint,
102 const TypeConstraint* expected,
103 int param);
104 void VerifyParamTypeCallable(TypedValue value, int param);
105 void VerifyParamTypeFail(int param);
106 void VerifyRetTypeSlow(int32_t id,
107 const Class* cls,
108 const Class* constraint,
109 const TypeConstraint* expected,
110 const TypedValue value);
111 void VerifyRetTypeCallable(int32_t id, TypedValue value);
112 void VerifyRetTypeFail(int32_t id, TypedValue* value);
114 void VerifyReifiedLocalTypeImpl(int32_t, ArrayData*);
115 void VerifyReifiedReturnTypeImpl(TypedValue, ArrayData*);
117 void VerifyParamRecDescImpl(const RecordDesc* rec,
118 const RecordDesc* constraint,
119 const TypeConstraint* expected,
120 int param);
121 void VerifyRetRecDescImpl(int32_t id,
122 const RecordDesc* rec,
123 const RecordDesc* constraint,
124 const TypeConstraint* expected,
125 TypedValue val);
127 void raise_error_sd(const StringData* sd);
129 TypedValue arrayIdxI(ArrayData*, int64_t, TypedValue);
130 TypedValue arrayIdxS(ArrayData*, StringData*, TypedValue);
131 TypedValue arrayIdxScan(ArrayData*, StringData*, TypedValue);
133 TypedValue dictIdxI(ArrayData*, int64_t, TypedValue);
134 TypedValue dictIdxS(ArrayData*, StringData*, TypedValue);
135 TypedValue dictIdxScan(ArrayData*, StringData*, TypedValue);
137 TypedValue keysetIdxI(ArrayData*, int64_t, TypedValue);
138 TypedValue keysetIdxS(ArrayData*, StringData*, TypedValue);
140 // Get the first/last key or value from ArrLike type.
141 template <bool isFirst>
142 TypedValue vecFirstLast(ArrayData* a);
143 template <bool isFirst, bool isKey>
144 TypedValue arrFirstLast(ArrayData* a);
146 TypedValue* ldGblAddrDefHelper(StringData* name);
148 TypedValue* getSPropOrNull(const Class* cls,
149 const StringData* name,
150 Class* ctx,
151 bool ignoreLateInit,
152 bool disallowConst);
153 TypedValue* getSPropOrRaise(const Class* cls,
154 const StringData* name,
155 Class* ctx,
156 bool ignoreLateInit,
157 bool disallowConst);
159 int64_t switchDoubleHelper(double val, int64_t base, int64_t nTargets);
160 int64_t switchStringHelper(StringData* s, int64_t base, int64_t nTargets);
161 int64_t switchObjHelper(ObjectData* o, int64_t base, int64_t nTargets);
163 void checkFrame(ActRec* fp, Cell* sp, bool fullCheck);
165 void loadArrayFunctionContext(ArrayData*, ActRec* preLiveAR, ActRec* fp);
167 const Func* loadClassCtor(Class* cls, ActRec* fp);
168 const Func* lookupClsMethodHelper(const Class* cls, const StringData* methName,
169 ObjectData* obj, const Class* ctx);
171 // These shuffle* functions are the JIT's version of bytecode.cpp's
172 // shuffleExtraStackArgs
173 void trimExtraArgs(ActRec* ar);
174 void shuffleExtraArgsVariadic(ActRec* ar);
176 void raiseMissingArgument(const Func* func, int got);
177 void raiseTooManyArguments(const Func* func, int got);
179 Class* lookupClsRDS(const StringData* name);
181 /* Check if a method of the given name exists on the class. */
182 bool methodExistsHelper(Class*, StringData*);
184 /* Is/As Helpers */
185 ArrayData* resolveTypeStructHelper(
186 uint32_t n,
187 const TypedValue* values,
188 const Class* declaringCls,
189 const Class* calledCls,
190 bool suppress,
191 bool isOrAsOp
193 bool isTypeStructHelper(ArrayData*, Cell);
194 [[noreturn]] void throwAsTypeStructExceptionHelper(ArrayData*, Cell);
195 ArrayData* errorOnIsAsExpressionInvalidTypesHelper(ArrayData*);
197 /* Reified generics helpers
198 * Both functions decref the input array by turning it into a static array
200 ArrayData* recordReifiedGenericsAndGetTSList(ArrayData*);
202 * Throw a VMSwitchMode exception.
204 [[noreturn]] void throwSwitchMode();
206 [[noreturn]] void throwOOBException(TypedValue base, TypedValue key);
207 [[noreturn]] void invalidArrayKeyHelper(const ArrayData* ad, TypedValue key);
209 namespace MInstrHelpers {
210 void setNewElem(tv_lval base, Cell val, const MInstrPropState*);
211 void setNewElemArray(tv_lval base, Cell val);
212 void setNewElemVec(tv_lval base, Cell val);
213 TypedValue setOpElem(tv_lval base, TypedValue key, Cell val, SetOpOp op,
214 const MInstrPropState*);
215 StringData* stringGetI(StringData*, uint64_t);
216 uint64_t pairIsset(c_Pair*, int64_t);
217 uint64_t vectorIsset(c_Vector*, int64_t);
218 TypedValue incDecElem(tv_lval base, TypedValue key, IncDecOp op,
219 const MInstrPropState*);
220 tv_lval elemVecID(tv_lval base, int64_t key);
221 tv_lval elemVecIU(tv_lval base, int64_t key);
225 * Just calls tlsBase, but not inlined, so it can be called from the TC.
227 uintptr_t tlsBaseNoInline();
229 //////////////////////////////////////////////////////////////////////
233 #endif