forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir-opcode.h
More file actions
202 lines (174 loc) · 6.6 KB
/
ir-opcode.h
File metadata and controls
202 lines (174 loc) · 6.6 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
/*
+----------------------------------------------------------------------+
| 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. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_VM_IR_OPCODE_H_
#define incl_HPHP_VM_IR_OPCODE_H_
#include <type_traits>
#include <vector>
#include <folly/Range.h>
#include "hphp/runtime/vm/jit/types.h"
#include "hphp/runtime/vm/jit/type.h"
namespace HPHP {
//////////////////////////////////////////////////////////////////////
struct StringData;
namespace jit {
//////////////////////////////////////////////////////////////////////
struct IRUnit;
struct IRInstruction;
struct SSATmp;
//////////////////////////////////////////////////////////////////////
/*
* The instruction table below uses the following notation. To use
* it, you have to define these symbols to do what you want, and then
* instantiate IR_OPCODES.
*
* dstinfo:
*
* Contains a description of how to compute the type of the
* destination(s) of an instruction from its sources.
*
* ND instruction has no destination
* D(type) single dst has a specific type
* DofS(N) single dst has the type of src N
* DRefineS(N) single dst's type is intersection of src N and paramType
* DParam single dst has type of the instruction's type parameter
* DParamMayRelax like DParam, except type may relax
* DParamPtr(k) like DParam, but the param must be a PtrTo* of kind k
* DUnboxPtr Unboxed PtrTo*T; adds possibility of pointing into a ref
* DBoxPtr Boxed PtrTo*T
* DAllocObj single dst has a type of a newly allocated object; may be a
* specialized object type if the class is known
* DArrPacked single dst has a packed array type
* DArrVec single dst has a vec array type
* DArrElem single dst has type based on reading an array element,
* intersected with an optional type parameter
* DThis single dst has type Obj<ctx>, where ctx is the
* current context class
* DCtx single dst has type Cctx|Obj<=ctx, where ctx is the
* current context class
* DMulti multiple dests. type and number depend on instruction
* DSetElem single dst is a subset of CountedStr|Nullptr depending on
* sources
* DBuiltin single dst for CallBuiltin. This can return complex data
* types such as (TStr | TNull)
* DSubtract(N,t) single dest has type of src N with t removed
* DCns single dst's type is the union of legal types for PHP
* constants
*
* srcinfo:
*
* Contains a series of tests on the source parameters in order.
*
* NA instruction takes no sources
* S(t1,...,tn) source must be a subtype of {t1|..|tn}
* AK(<kind>) source must be an array with specified kind
* C(type) source must be a constant, and subtype of type
* CStr same as C(StaticStr)
* SVar(t1,...,tn) variadic source list, all subtypes of {t1|..|tn}
*
* flags:
*
* See doc/ir.specification for the meaning of these flags.
*
* The flags in this opcode table supply default values for the
* querying functions in IRInstruction---those functions involve
* additional logic (based on operand types, etc) on a
* per-instruction basis.
*
* The following abbreviations are used in this table:
*
* NF no flags
* Er mayRaiseError
* PRc producesRC
* CRc consumesRC
* T isTerminal
* B isBranch
* P passthrough
* K killsSource
* MProp MInstrProp
* MElem MInstrElem
*/
// The IR opcode table is generated from lines that start with | in
// hphp/doc/ir.specification.
#include "hphp/runtime/ir-opcode-generated.h"
enum class Opcode : uint16_t {
#define O(name, ...) name,
IR_OPCODES
#undef O
};
#define O(name, ...) UNUSED auto constexpr name = Opcode::name;
IR_OPCODES
#undef O
#define O(...) +1
size_t constexpr kNumOpcodes = IR_OPCODES;
#undef O
/*
* Returns true for instructions that perform calls.
*/
bool isCallOp(Opcode opc);
/*
* Returns true for instructions that refine the types of values with
* a runtime check.
*/
bool isGuardOp(Opcode opc);
/*
* Returns the negated version of the specified opcode, if its a comparison
* opcode and can be negated (not all comparisons can be negated).
*/
folly::Optional<Opcode> negateCmpOp(Opcode opc);
const char* opcodeName(Opcode opcode);
bool opHasExtraData(Opcode op);
enum OpcodeFlag : uint64_t {
NoFlags = 0,
HasDest = 1ULL << 0,
Branch = 1ULL << 1,
ConsumesRC = 1ULL << 2,
ProducesRC = 1ULL << 3,
MInstrProp = 1ULL << 4,
MInstrElem = 1ULL << 5,
MayRaiseError = 1ULL << 6,
Terminal = 1ULL << 7, // has no next instruction
NaryDest = 1ULL << 8, // has 0 or more destinations
HasExtra = 1ULL << 9,
Passthrough = 1ULL << 10,
};
bool hasEdges(Opcode opc);
bool opcodeHasFlags(Opcode opc, uint64_t flags);
/*
* Given an SSATmp of type Cls, try to find the name of the class.
* Returns nullptr if can't find it.
*/
const StringData* findClassName(SSATmp* cls);
using TcaRange = folly::Range<TCA>;
} // namespace jit
} // namespace HPHP
namespace std {
template<> struct hash<HPHP::jit::Opcode> {
size_t operator()(HPHP::jit::Opcode op) const { return uint16_t(op); }
};
}
namespace folly {
template<> class FormatValue<HPHP::jit::Opcode> {
public:
explicit FormatValue(HPHP::jit::Opcode op) : m_op(op) {}
template<typename Callback> void format(FormatArg& arg, Callback& cb) const {
format_value::formatString(opcodeName(m_op), arg, cb);
}
private:
HPHP::jit::Opcode m_op;
};
}
#include "hphp/runtime/vm/jit/ir-opcode-inl.h"
#endif