2 +----------------------------------------------------------------------+
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 #include "hphp/runtime/vm/jit/edge.h"
21 namespace HPHP
{ namespace jit
{
22 ///////////////////////////////////////////////////////////////////////////////
24 inline IRInstruction::IRInstruction(Opcode op
,
30 , m_iroff(bcctx
.iroff
)
33 , m_hasTypeParam
{false}
34 , m_marker(bcctx
.marker
)
40 // DefConst is the only opcode that's allowed to not have a marker, since
41 // it's not part of the instruction stream.
42 assertx(m_marker
.valid());
46 ///////////////////////////////////////////////////////////////////////////////
48 inline bool IRInstruction::hasDst() const {
49 return opcodeHasFlags(op(), HasDest
);
52 inline bool IRInstruction::naryDst() const {
53 return opcodeHasFlags(op(), NaryDest
);
56 inline bool IRInstruction::consumesReferences() const {
57 return opcodeHasFlags(op(), ConsumesRC
);
60 inline bool IRInstruction::mayRaiseError() const {
61 return opcodeHasFlags(op(), MayRaiseError
);
64 inline bool IRInstruction::isTerminal() const {
65 return opcodeHasFlags(op(), Terminal
);
68 inline bool IRInstruction::hasEdges() const {
69 return jit::hasEdges(op());
72 inline bool IRInstruction::isPassthrough() const {
73 return opcodeHasFlags(op(), Passthrough
);
76 inline bool IRInstruction::producesReference() const {
77 return opcodeHasFlags(op(), ProducesRC
);
80 inline SSATmp
* IRInstruction::getPassthroughValue() const {
81 assertx(isPassthrough());
83 CheckType
, AssertType
, AssertNonNull
,
84 MapAddElemC
, ColAddNewElemC
,
89 ///////////////////////////////////////////////////////////////////////////////
91 inline uint32_t IRInstruction::id() const {
92 assertx(m_id
!= kTransient
);
96 inline bool IRInstruction::isTransient() const {
97 return m_id
== kTransient
;
100 inline uint16_t IRInstruction::iroff() const {
104 template<typename
... Args
>
105 bool IRInstruction::is(Opcode op
, Args
&&... args
) const {
106 return m_op
== op
|| is(std::forward
<Args
>(args
)...);
109 inline bool IRInstruction::is() const {
113 inline Opcode
IRInstruction::op() const {
117 inline const BCMarker
& IRInstruction::marker() const {
121 inline BCMarker
& IRInstruction::marker() {
125 inline BCContext
IRInstruction::bcctx() const {
126 return BCContext
{ m_marker
, m_iroff
};
129 inline const Func
* IRInstruction::func() const {
130 return m_marker
.hasFunc() ? m_marker
.func() : nullptr;
133 inline const Class
* IRInstruction::ctx() const {
134 return m_marker
.hasFunc() ? m_marker
.func()->cls() : nullptr;
137 inline bool IRInstruction::hasTypeParam() const { return m_hasTypeParam
; }
139 inline Type
IRInstruction::typeParam() const {
140 assertx(m_hasTypeParam
);
144 inline void IRInstruction::setTypeParam(Type t
) {
145 m_hasTypeParam
= true;
149 ///////////////////////////////////////////////////////////////////////////////
151 inline void IRInstruction::initializeSrcs(uint32_t numSrcs
, SSATmp
** srcs
) {
152 assertx(!m_srcs
&& !m_numSrcs
);
157 inline uint32_t IRInstruction::numSrcs() const {
161 inline uint32_t IRInstruction::numDsts() const {
165 inline SSATmp
* IRInstruction::src(uint32_t i
) const {
166 always_assert(i
< numSrcs());
170 inline SSATmp
* IRInstruction::dst() const {
175 inline folly::Range
<SSATmp
**> IRInstruction::srcs() const {
176 return folly::Range
<SSATmp
**>(m_srcs
, m_numSrcs
);
179 inline folly::Range
<SSATmp
**> IRInstruction::dsts() {
180 assertx(naryDst() || m_numDsts
<= 1);
181 if (hasDst()) return folly::Range
<SSATmp
**>(&m_dest
, m_numDsts
);
182 return folly::Range
<SSATmp
**>(m_dsts
, m_numDsts
);
185 inline void IRInstruction::setSrc(uint32_t i
, SSATmp
* newSrc
) {
186 always_assert(i
< numSrcs());
190 inline void IRInstruction::setSrcs(uint32_t numSrcs
, SSATmp
** newSrcs
) {
195 inline void IRInstruction::deleteSrc(uint32_t i
) {
196 always_assert(i
< numSrcs());
197 std::copy(m_srcs
+ i
+ 1, m_srcs
+ m_numSrcs
, m_srcs
+ i
);
201 inline void IRInstruction::setDst(SSATmp
* newDst
) {
204 m_numDsts
= newDst
? 1 : 0;
207 inline void IRInstruction::setDsts(uint32_t numDsts
, SSATmp
** newDsts
) {
213 inline void IRInstruction::deleteDst(uint32_t i
) {
214 always_assert(i
< numDsts());
216 std::copy(m_dsts
+ i
+ 1, m_dsts
+ m_numDsts
, m_dsts
+ i
);
220 ///////////////////////////////////////////////////////////////////////////////
222 inline bool IRInstruction::hasExtra() const {
227 const typename IRExtraDataType
<opc
>::type
* IRInstruction::extra() const {
228 assertx(opc
== op() && "ExtraData type error");
229 assertx(m_extra
!= nullptr);
230 return static_cast<typename IRExtraDataType
<opc
>::type
*>(m_extra
);
234 typename IRExtraDataType
<opc
>::type
* IRInstruction::extra() {
235 assertx(opc
== op() && "ExtraData type error");
236 return static_cast<typename IRExtraDataType
<opc
>::type
*>(m_extra
);
240 const T
* IRInstruction::extra() const {
241 if (debug
) assert_opcode_extra
<T
>(op());
242 return static_cast<const T
*>(m_extra
);
245 inline const IRExtraData
* IRInstruction::rawExtra() const {
249 inline void IRInstruction::setExtra(IRExtraData
* data
) {
254 inline void IRInstruction::clearExtra() {
258 ///////////////////////////////////////////////////////////////////////////////
260 inline Block
* IRInstruction::block() const {
264 inline void IRInstruction::setBlock(Block
* b
) {
268 inline Block
* IRInstruction::next() const {
272 inline Edge
* IRInstruction::nextEdge() {
276 inline void IRInstruction::setNext(Block
* b
) {
277 return setSucc(0, b
);
280 inline Block
* IRInstruction::taken() const {
284 inline Edge
* IRInstruction::takenEdge() {
288 inline void IRInstruction::setTaken(Block
* b
) {
289 return setSucc(1, b
);
292 inline bool IRInstruction::isControlFlow() const {
293 return bool(taken());
296 inline bool IRInstruction::isBlockEnd() const {
297 return taken() || isTerminal();
300 inline Block
* IRInstruction::succ(int i
) const {
301 assertx(!m_edges
|| hasEdges());
302 return m_edges
? m_edges
[i
].to() : nullptr;
305 inline Edge
* IRInstruction::succEdge(int i
) {
306 assertx(!m_edges
|| hasEdges());
307 return m_edges
&& m_edges
[i
].to() ? &m_edges
[i
] : nullptr;
310 inline void IRInstruction::setSucc(int i
, Block
* b
) {
312 if (isTransient()) m_edges
[i
].setTransientTo(b
);
313 else m_edges
[i
].setTo(b
);
315 assertx(!b
&& !m_edges
);
319 inline void IRInstruction::clearEdges() {
325 ///////////////////////////////////////////////////////////////////////////////