2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
33 #include "MacroAssembler.h"
35 #include "TempRegisterSet.h"
36 #include <wtf/BitVector.h>
42 template<typename
... Regs
>
43 explicit RegisterSet(Regs
... regs
)
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();
57 void set(Reg reg
, bool value
= true)
60 m_vector
.set(reg
.index(), value
);
63 void set(JSValueRegs regs
)
65 if (regs
.tagGPR() != InvalidGPRReg
)
67 set(regs
.payloadGPR());
76 bool get(Reg reg
) const
79 return m_vector
.get(reg
.index());
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
); }
86 size_t numberOfSetGPRs() const;
87 size_t numberOfSetFPRs() const;
88 size_t numberOfSetRegisters() const { return m_vector
.bitCount(); }
90 void dump(PrintStream
&) const;
92 enum EmptyValueTag
{ EmptyValue
};
93 enum DeletedValueTag
{ DeletedValue
};
95 RegisterSet(EmptyValueTag
)
96 : m_vector(BitVector::EmptyValue
)
100 RegisterSet(DeletedValueTag
)
101 : m_vector(BitVector::DeletedValue
)
105 bool isEmptyValue() const { return m_vector
.isEmptyValue(); }
106 bool isDeletedValue() const { return m_vector
.isDeletedValue(); }
108 bool operator==(const RegisterSet
& other
) const { return m_vector
== other
.m_vector
; }
109 unsigned hash() const { return m_vector
.hash(); }
112 void setAny(Reg reg
) { set(reg
); }
113 void setAny(const RegisterSet
& set
) { merge(set
); }
115 template<typename RegType
, typename
... Regs
>
116 void setMany(RegType reg
, Regs
... regs
)
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;
135 template<typename T
> struct DefaultHash
;
136 template<> struct DefaultHash
<JSC::RegisterSet
> {
137 typedef JSC::RegisterSetHash Hash
;
140 template<typename T
> struct HashTraits
;
141 template<> struct HashTraits
<JSC::RegisterSet
> : public CustomHashTraits
<JSC::RegisterSet
> { };
145 #endif // ENABLE(JIT)
147 #endif // RegisterSet_h