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 #ifndef incl_HPHP_JIT_STATE_MULTIMAP_H_
18 #define incl_HPHP_JIT_STATE_MULTIMAP_H_
20 #include <type_traits>
23 #include "hphp/runtime/vm/jit/ir-unit.h"
25 namespace HPHP
{ namespace jit
{
27 //////////////////////////////////////////////////////////////////////
30 * Utility to keep a multi-map of state about each key, indexed by
31 * key->id(), where key can be an IRInstruction, Block, or SSATmp.
33 template<class Key
, class Info
>
34 struct StateMultiMap
{
35 using InfoMap
= std::multimap
<uint32_t, Info
>;
36 using iterator
= typename
InfoMap::iterator
;
37 using const_iterator
= typename
InfoMap::const_iterator
;
38 using range
= std::pair
<iterator
, iterator
>;
39 using const_range
= std::pair
<const_iterator
, const_iterator
>;
42 std::is_same
<Key
,Block
>::value
||
43 std::is_same
<Key
,IRInstruction
>::value
||
44 std::is_same
<Key
,SSATmp
>::value
,
45 "StateMultiMap can only be used with Block, IRInstruction, or SSATmp"
50 StateMultiMap(const StateMultiMap
&) = default;
51 StateMultiMap(StateMultiMap
&&) = default;
52 StateMultiMap
& operator=(const StateMultiMap
&) = delete;
53 StateMultiMap
& operator=(StateMultiMap
&&) = default;
55 void clear() { m_info
.clear(); }
57 range
operator[](uint32_t id
) {
58 return m_info
.equal_range(id
);
61 const_range
operator[](uint32_t id
) const {
62 return m_info
.equal_range(id
);
65 range
operator[](const Key
& k
) { return (*this)[k
.id()]; }
66 range
operator[](const Key
* k
) { return (*this)[k
->id()]; }
68 const_range
operator[](const Key
& k
) const { return (*this)[k
.id()]; }
69 const_range
operator[](const Key
* k
) const { return (*this)[k
->id()]; }
71 iterator
insert(const Key
& k
, const Info
& info
) {
72 return insert(k
.id(), info
);
74 iterator
insert(uint32_t id
, const Info
& info
) {
75 return m_info
.insert(std::make_pair(id
, info
));
78 iterator
begin() { return m_info
.begin(); }
79 iterator
end() { return m_info
.end(); }
80 const_iterator
begin() const { return m_info
.begin(); }
81 const_iterator
end() const { return m_info
.end(); }
82 const_iterator
cbegin() const { return m_info
.cbegin(); }
83 const_iterator
cend() const { return m_info
.cend(); }
89 //////////////////////////////////////////////////////////////////////