forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir-opcode.cpp
More file actions
236 lines (208 loc) · 6.78 KB
/
ir-opcode.cpp
File metadata and controls
236 lines (208 loc) · 6.78 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
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/vm/jit/ir-opcode.h"
#include "hphp/runtime/base/string-data.h"
#include "hphp/runtime/vm/jit/cfg.h"
#include "hphp/runtime/vm/jit/extra-data.h"
#include "hphp/runtime/vm/jit/ir-instruction.h"
#include "hphp/runtime/vm/jit/ir-unit.h"
#include "hphp/runtime/vm/jit/ssa-tmp.h"
#include "hphp/runtime/vm/jit/print.h"
#include "hphp/runtime/vm/jit/type.h"
#include "hphp/runtime/vm/runtime.h"
#include "hphp/util/trace.h"
namespace HPHP { namespace jit {
///////////////////////////////////////////////////////////////////////////////
TRACE_SET_MOD(hhir);
#define NF 0
#define Er MayRaiseError
#define PRc ProducesRC
#define CRc ConsumesRC
#define T Terminal
#define B Branch
#define P Passthrough
#define MProp MInstrProp
#define MElem MInstrElem
#define ND 0
#define D(n) HasDest
#define DofS(n) HasDest
#define DRefineS(n) HasDest
#define DParamMayRelax HasDest
#define DParam HasDest
#define DParamPtr(k) HasDest
#define DLdObjCls HasDest
#define DUnboxPtr HasDest
#define DBoxPtr HasDest
#define DAllocObj HasDest
#define DArrElem HasDest
#define DArrPacked HasDest
#define DArrVec HasDest
#define DCol HasDest
#define DThis HasDest
#define DCtx HasDest
#define DMulti NaryDest
#define DSetElem HasDest
#define DPtrToParam HasDest
#define DBuiltin HasDest
#define DSubtract(n,t) HasDest
#define DCns HasDest
namespace {
template<Opcode op, uint64_t flags>
struct op_flags {
static constexpr uint64_t value =
(OpHasExtraData<op>::value ? HasExtra : 0) | flags;
static_assert(!(value & ProducesRC) ||
(value & (HasDest | NaryDest)) == HasDest,
"ProducesRC instructions must have exactly one dest");
};
}
OpInfo g_opInfo[] = {
#define O(name, dsts, srcs, flags) \
{ #name, \
op_flags<name, dsts | flags>::value \
},
IR_OPCODES
#undef O
{ 0 }
};
#undef NF
#undef C
#undef E
#undef PRc
#undef CRc
#undef Er
#undef T
#undef B
#undef P
#undef K
#undef MProp
#undef MElem
#undef ND
#undef D
#undef DofS
#undef DRefineS
#undef DParamMayRelax
#undef DParam
#undef DParamPtr
#undef DLdObjCls
#undef DUnboxPtr
#undef DBoxPtr
#undef DArrElem
#undef DArrPacked
#undef DArrVec
#undef DCol
#undef DAllocObj
#undef DThis
#undef DCtx
#undef DMulti
#undef DSetElem
#undef DPtrToParam
#undef DBuiltin
#undef DSubtract
#undef DCns
///////////////////////////////////////////////////////////////////////////////
const StringData* findClassName(SSATmp* cls) {
assertx(cls->isA(TCls));
if (cls->hasConstVal()) {
return cls->clsVal()->preClass()->name();
}
// Try to get the class name from a LdCls
IRInstruction* clsInst = cls->inst();
if (clsInst->op() == LdCls || clsInst->op() == LdClsCached) {
SSATmp* clsName = clsInst->src(0);
assertx(clsName->isA(TStr));
if (clsName->hasConstVal()) {
return clsName->strVal();
}
}
return nullptr;
}
bool isCallOp(Opcode opc) {
// CallBuiltin doesn't count because it is not a php-level call. (It will
// call a C++ helper and we can push/pop around it normally.)
switch (opc) {
case Call:
case CallArray:
case ContEnter:
return true;
default:
return false;
}
}
bool isGuardOp(Opcode opc) {
switch (opc) {
case CheckLoc:
case CheckStk:
case CheckType:
return true;
default:
return false;
}
}
folly::Optional<Opcode> negateCmpOp(Opcode opc) {
switch (opc) {
case GtBool: return LteBool;
case GteBool: return LtBool;
case LtBool: return GteBool;
case LteBool: return GtBool;
case EqBool: return NeqBool;
case NeqBool: return EqBool;
case GtInt: return LteInt;
case GteInt: return LtInt;
case LtInt: return GteInt;
case LteInt: return GtInt;
case EqInt: return NeqInt;
case NeqInt: return EqInt;
// Due to NaN only equality comparisons with doubles can be negated.
case EqDbl: return NeqDbl;
case NeqDbl: return EqDbl;
case GtStr: return LteStr;
case GteStr: return LtStr;
case LtStr: return GteStr;
case LteStr: return GtStr;
case EqStr: return NeqStr;
case NeqStr: return EqStr;
case SameStr: return NSameStr;
case NSameStr: return SameStr;
case GtStrInt: return LteStrInt;
case GteStrInt: return LtStrInt;
case LtStrInt: return GteStrInt;
case LteStrInt: return GtStrInt;
case EqStrInt: return NeqStrInt;
case NeqStrInt: return EqStrInt;
// Objects can contain a property with NaN, so only equality comparisons can
// be negated.
case EqObj: return NeqObj;
case NeqObj: return EqObj;
case SameObj: return NSameObj;
case NSameObj: return SameObj;
// Arrays can contain an element with NaN, so only equality comparisons can
// be negated.
case EqArr: return NeqArr;
case NeqArr: return EqArr;
case SameArr: return NSameArr;
case NSameArr: return SameArr;
case GtRes: return LteRes;
case GteRes: return LtRes;
case LtRes: return GteRes;
case LteRes: return GtRes;
case EqRes: return NeqRes;
case NeqRes: return EqRes;
default: return folly::none;
}
}
///////////////////////////////////////////////////////////////////////////////
}}