]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #ifndef RegisterSet_h | |
27 | #define RegisterSet_h | |
28 | ||
29 | #if ENABLE(JIT) | |
30 | ||
31 | #include "FPRInfo.h" | |
32 | #include "GPRInfo.h" | |
33 | #include "MacroAssembler.h" | |
34 | #include "Reg.h" | |
35 | #include "TempRegisterSet.h" | |
36 | #include <wtf/BitVector.h> | |
37 | ||
38 | namespace JSC { | |
39 | ||
40 | class RegisterSet { | |
41 | public: | |
42 | template<typename... Regs> | |
43 | explicit RegisterSet(Regs... regs) | |
44 | { | |
45 | setMany(regs...); | |
46 | } | |
47 | ||
48 | static RegisterSet stackRegisters(); | |
49 | static RegisterSet reservedHardwareRegisters(); | |
50 | static RegisterSet runtimeRegisters(); | |
51 | static RegisterSet specialRegisters(); // The union of stack, reserved hardware, and runtime registers. | |
52 | static RegisterSet calleeSaveRegisters(); | |
53 | static RegisterSet allGPRs(); | |
54 | static RegisterSet allFPRs(); | |
55 | static RegisterSet allRegisters(); | |
56 | ||
57 | void set(Reg reg, bool value = true) | |
58 | { | |
59 | ASSERT(!!reg); | |
60 | m_vector.set(reg.index(), value); | |
61 | } | |
62 | ||
63 | void set(JSValueRegs regs) | |
64 | { | |
65 | if (regs.tagGPR() != InvalidGPRReg) | |
66 | set(regs.tagGPR()); | |
67 | set(regs.payloadGPR()); | |
68 | } | |
69 | ||
70 | void clear(Reg reg) | |
71 | { | |
72 | ASSERT(!!reg); | |
73 | set(reg, false); | |
74 | } | |
75 | ||
76 | bool get(Reg reg) const | |
77 | { | |
78 | ASSERT(!!reg); | |
79 | return m_vector.get(reg.index()); | |
80 | } | |
81 | ||
82 | void merge(const RegisterSet& other) { m_vector.merge(other.m_vector); } | |
83 | void filter(const RegisterSet& other) { m_vector.filter(other.m_vector); } | |
84 | void exclude(const RegisterSet& other) { m_vector.exclude(other.m_vector); } | |
85 | ||
86 | size_t numberOfSetGPRs() const; | |
87 | size_t numberOfSetFPRs() const; | |
88 | size_t numberOfSetRegisters() const { return m_vector.bitCount(); } | |
89 | ||
90 | void dump(PrintStream&) const; | |
91 | ||
92 | enum EmptyValueTag { EmptyValue }; | |
93 | enum DeletedValueTag { DeletedValue }; | |
94 | ||
95 | RegisterSet(EmptyValueTag) | |
96 | : m_vector(BitVector::EmptyValue) | |
97 | { | |
98 | } | |
99 | ||
100 | RegisterSet(DeletedValueTag) | |
101 | : m_vector(BitVector::DeletedValue) | |
102 | { | |
103 | } | |
104 | ||
105 | bool isEmptyValue() const { return m_vector.isEmptyValue(); } | |
106 | bool isDeletedValue() const { return m_vector.isDeletedValue(); } | |
107 | ||
108 | bool operator==(const RegisterSet& other) const { return m_vector == other.m_vector; } | |
109 | unsigned hash() const { return m_vector.hash(); } | |
110 | ||
111 | private: | |
112 | void setAny(Reg reg) { set(reg); } | |
113 | void setAny(const RegisterSet& set) { merge(set); } | |
114 | void setMany() { } | |
115 | template<typename RegType, typename... Regs> | |
116 | void setMany(RegType reg, Regs... regs) | |
117 | { | |
118 | setAny(reg); | |
119 | setMany(regs...); | |
120 | } | |
121 | ||
122 | BitVector m_vector; | |
123 | }; | |
124 | ||
125 | struct RegisterSetHash { | |
126 | static unsigned hash(const RegisterSet& set) { return set.hash(); } | |
127 | static bool equal(const RegisterSet& a, const RegisterSet& b) { return a == b; } | |
128 | static const bool safeToCompareToEmptyOrDeleted = false; | |
129 | }; | |
130 | ||
131 | } // namespace JSC | |
132 | ||
133 | namespace WTF { | |
134 | ||
135 | template<typename T> struct DefaultHash; | |
136 | template<> struct DefaultHash<JSC::RegisterSet> { | |
137 | typedef JSC::RegisterSetHash Hash; | |
138 | }; | |
139 | ||
140 | template<typename T> struct HashTraits; | |
141 | template<> struct HashTraits<JSC::RegisterSet> : public CustomHashTraits<JSC::RegisterSet> { }; | |
142 | ||
143 | } // namespace WTF | |
144 | ||
145 | #endif // ENABLE(JIT) | |
146 | ||
147 | #endif // RegisterSet_h | |
148 |