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 #ifndef incl_HPHP_IR_INSTR_TABLE_H_
18 #define incl_HPHP_IR_INSTR_TABLE_H_
20 #include <unordered_map>
22 #include <folly/Hash.h>
24 #include "hphp/runtime/vm/jit/ir-instruction.h"
25 #include "hphp/runtime/vm/jit/ssa-tmp.h"
27 namespace HPHP
{ namespace jit
{
28 ///////////////////////////////////////////////////////////////////////////////
31 * Hash table used for IRUnit constants.
33 * The table maps IRInstructions to SSATmps. Instructions are considered to
34 * be the same iff their inputs and parameters are the same.
37 SSATmp
* lookup(IRInstruction
* inst
) const {
38 auto const it
= m_map
.find(inst
);
39 if (it
== m_map
.end()) return nullptr;
42 SSATmp
* insert(SSATmp
* opnd
) {
43 return m_map
[opnd
->inst()] = opnd
;
45 void erase(SSATmp
* opnd
) {
46 m_map
.erase(opnd
->inst());
54 bool operator()(const IRInstruction
* i1
,
55 const IRInstruction
* i2
) const {
56 if (i1
->op() != i2
->op() ||
57 i1
->hasTypeParam() != i2
->hasTypeParam() ||
58 i1
->numSrcs() != i2
->numSrcs() ||
59 i1
->hasExtra() != i2
->hasExtra()) {
62 if (i1
->hasTypeParam()) {
63 if (i1
->typeParam() != i2
->typeParam()) return false;
65 for (uint32_t i
= 0; i
< i1
->numSrcs(); ++i
) {
66 if (i1
->src(i
) != i2
->src(i
)) {
71 return equalsExtra(i1
->op(), i1
->rawExtra(), i2
->rawExtra());
78 size_t hash(const IRInstruction
* inst
) const {
80 for (uint32_t i
= 0; i
< inst
->numSrcs(); ++i
) {
81 h
= hash_combine(h
, inst
->src(i
));
83 if (inst
->hasExtra()) {
84 h
= hash_combine(h
, hashExtra(inst
->op(), inst
->rawExtra()));
86 if (inst
->hasTypeParam()) {
87 h
= hash_combine(h
, inst
->typeParam());
89 return hash_combine(h
, inst
->op());
91 size_t operator()(IRInstruction
* inst
) const {
97 static size_t hash_combine(size_t base
, T other
) {
98 return folly::hash::hash_128_to_64(
99 base
, folly::hash::hash_combine(other
));
104 std::unordered_map
<IRInstruction
*,SSATmp
*,HashOp
,EqualsOp
> m_map
;
107 ///////////////////////////////////////////////////////////////////////////////