2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 "hphp/runtime/vm/jit/ir-opcode.h"
19 #include "hphp/runtime/base/string-data.h"
20 #include "hphp/runtime/vm/jit/cfg.h"
21 #include "hphp/runtime/vm/jit/extra-data.h"
22 #include "hphp/runtime/vm/jit/ir-instruction.h"
23 #include "hphp/runtime/vm/jit/ir-unit.h"
24 #include "hphp/runtime/vm/jit/ssa-tmp.h"
25 #include "hphp/runtime/vm/jit/print.h"
26 #include "hphp/runtime/vm/jit/type.h"
27 #include "hphp/runtime/vm/runtime.h"
29 #include "hphp/util/trace.h"
31 // Include last to localize effects to this file
32 #include "hphp/util/assert-throw.h"
34 namespace HPHP
{ namespace jit
{
35 ///////////////////////////////////////////////////////////////////////////////
40 #define Er MayRaiseError
41 #define PRc ProducesRC
42 #define CRc ConsumesRC
46 #define K KillsSources
47 #define MProp MInstrProp
48 #define MElem MInstrElem
52 #define DofS(n) HasDest
53 #define DRefineS(n) HasDest
54 #define DParamMayRelax HasDest
55 #define DParam HasDest
56 #define DParamPtr(k) HasDest
57 #define DUnboxPtr HasDest
58 #define DBoxPtr HasDest
59 #define DAllocObj HasDest
60 #define DArrElem HasDest
61 #define DArrPacked HasDest
65 #define DMulti NaryDest
66 #define DSetElem HasDest
67 #define DPtrToParam HasDest
68 #define DBuiltin HasDest
69 #define DSubtract(n,t) HasDest
73 #define O(name, dsts, srcs, flags) \
75 (OpHasExtraData<name>::value ? HasExtra : 0) | \
100 #undef DParamMayRelax
118 ///////////////////////////////////////////////////////////////////////////////
120 const StringData
* findClassName(SSATmp
* cls
) {
121 assertx(cls
->isA(TCls
));
123 if (cls
->hasConstVal()) {
124 return cls
->clsVal()->preClass()->name();
126 // Try to get the class name from a LdCls
127 IRInstruction
* clsInst
= cls
->inst();
128 if (clsInst
->op() == LdCls
|| clsInst
->op() == LdClsCached
) {
129 SSATmp
* clsName
= clsInst
->src(0);
130 assertx(clsName
->isA(TStr
));
131 if (clsName
->hasConstVal()) {
132 return clsName
->strVal();
138 bool isCallOp(Opcode opc
) {
139 // CallBuiltin doesn't count because it is not a php-level call. (It will
140 // call a C++ helper and we can push/pop around it normally.)
151 bool isGuardOp(Opcode opc
) {
163 bool isQueryOp(Opcode opc
) {
185 case InstanceOfBitmask
:
186 case NInstanceOfBitmask
:
195 bool isIntQueryOp(Opcode opc
) {
209 bool isDblQueryOp(Opcode opc
) {
223 Opcode
negateQueryOp(Opcode opc
) {
224 assertx(isQueryOp(opc
));
232 case GtInt
: return LteInt
;
233 case GteInt
: return LtInt
;
234 case LtInt
: return GteInt
;
235 case LteInt
: return GtInt
;
236 case EqInt
: return NeqInt
;
237 case NeqInt
: return EqInt
;
238 case EqDbl
: return NeqDbl
;
239 case NeqDbl
: return EqDbl
;
240 case Same
: return NSame
;
241 case NSame
: return Same
;
242 case InstanceOfBitmask
: return NInstanceOfBitmask
;
243 case NInstanceOfBitmask
: return InstanceOfBitmask
;
244 case IsType
: return IsNType
;
245 case IsNType
: return IsType
;
250 // Negating dbl relational ops probably isn't what you want:
251 // (X < Y) != !(X >= Y) -- when NaN gets involved
252 always_assert(false);
253 default: always_assert(0);
257 Opcode
commuteQueryOp(Opcode opc
) {
258 assertx(isQueryOp(opc
));
261 case Gte
: return Lte
;
263 case Lte
: return Gte
;
265 case Neq
: return Neq
;
266 case GtInt
: return LtInt
;
267 case GteInt
:return LteInt
;
268 case LtInt
: return GtInt
;
269 case LteInt
:return GteInt
;
270 case EqInt
: return EqInt
;
271 case NeqInt
:return NeqInt
;
272 case GtDbl
: return LtDbl
;
273 case GteDbl
:return LteDbl
;
274 case LtDbl
: return GtDbl
;
275 case LteDbl
:return GteDbl
;
276 case EqDbl
: return EqDbl
;
277 case NeqDbl
:return NeqDbl
;
278 case Same
: return Same
;
279 case NSame
: return NSame
;
280 default: always_assert(0);
284 Opcode
queryToIntQueryOp(Opcode opc
) {
285 assertx(isQueryOp(opc
));
287 case Gt
: return GtInt
;
288 case Gte
: return GteInt
;
289 case Lt
: return LtInt
;
290 case Lte
: return LteInt
;
291 case Eq
: return EqInt
;
292 case Neq
: return NeqInt
;
293 case GtDbl
: return GtInt
;
294 case GteDbl
:return GteInt
;
295 case LtDbl
: return LtInt
;
296 case LteDbl
:return LteInt
;
297 case EqDbl
: return EqInt
;
298 case NeqDbl
:return NeqInt
;
299 default: always_assert(0);
303 Opcode
queryToDblQueryOp(Opcode opc
) {
304 assertx(isQueryOp(opc
));
306 case Gt
: return GtDbl
;
307 case Gte
: return GteDbl
;
308 case Lt
: return LtDbl
;
309 case Lte
: return LteDbl
;
310 case Eq
: return EqDbl
;
311 case Neq
: return NeqDbl
;
312 case GtInt
: return GtDbl
;
313 case GteInt
:return GteDbl
;
314 case LtInt
: return LtDbl
;
315 case LteInt
:return LteDbl
;
316 case EqInt
: return EqDbl
;
317 case NeqInt
:return NeqDbl
;
318 default: always_assert(0);
322 ///////////////////////////////////////////////////////////////////////////////