]> git.saurik.com Git - apple/javascriptcore.git/blame - jit/RegisterSet.cpp
JavaScriptCore-7600.1.4.17.5.tar.gz
[apple/javascriptcore.git] / jit / RegisterSet.cpp
CommitLineData
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#include "config.h"
27#include "RegisterSet.h"
28
29#if ENABLE(JIT)
30
31#include "GPRInfo.h"
32#include "MacroAssembler.h"
33#include "JSCInlines.h"
34#include <wtf/CommaPrinter.h>
35
36namespace JSC {
37
38RegisterSet RegisterSet::stackRegisters()
39{
40 return RegisterSet(
41 MacroAssembler::stackPointerRegister,
42 MacroAssembler::framePointerRegister);
43}
44
45RegisterSet RegisterSet::reservedHardwareRegisters()
46{
47#if CPU(ARM64)
48 return RegisterSet(ARM64Registers::lr);
49#else
50 return RegisterSet();
51#endif
52}
53
54RegisterSet RegisterSet::runtimeRegisters()
55{
56#if USE(JSVALUE64)
57 return RegisterSet(GPRInfo::tagTypeNumberRegister, GPRInfo::tagMaskRegister);
58#else
59 return RegisterSet();
60#endif
61}
62
63RegisterSet RegisterSet::specialRegisters()
64{
65 return RegisterSet(
66 stackRegisters(), reservedHardwareRegisters(), runtimeRegisters());
67}
68
69RegisterSet RegisterSet::calleeSaveRegisters()
70{
71 RegisterSet result;
72#if CPU(X86)
73 result.set(X86Registers::ebx);
74 result.set(X86Registers::ebp);
75 result.set(X86Registers::edi);
76 result.set(X86Registers::esi);
77#elif CPU(X86_64)
78 result.set(X86Registers::ebx);
79 result.set(X86Registers::ebp);
80 result.set(X86Registers::r12);
81 result.set(X86Registers::r13);
82 result.set(X86Registers::r14);
83 result.set(X86Registers::r15);
84#elif CPU(ARM_THUMB2)
85 result.set(ARMRegisters::r4);
86 result.set(ARMRegisters::r5);
87 result.set(ARMRegisters::r6);
88 result.set(ARMRegisters::r8);
81345200
A
89 result.set(ARMRegisters::r10);
90 result.set(ARMRegisters::r11);
91#elif CPU(ARM64)
92 // We don't include LR in the set of callee-save registers even though it technically belongs
93 // there. This is because we use this set to describe the set of registers that need to be saved
94 // beyond what you would save by the platform-agnostic "preserve return address" and "restore
95 // return address" operations in CCallHelpers.
96 for (
97 ARM64Registers::RegisterID reg = ARM64Registers::x19;
98 reg <= ARM64Registers::x28;
99 reg = static_cast<ARM64Registers::RegisterID>(reg + 1))
100 result.set(reg);
101 result.set(ARM64Registers::fp);
102 for (
103 ARM64Registers::FPRegisterID reg = ARM64Registers::q8;
104 reg <= ARM64Registers::q15;
105 reg = static_cast<ARM64Registers::FPRegisterID>(reg + 1))
106 result.set(reg);
107#else
108 UNREACHABLE_FOR_PLATFORM();
109#endif
110 return result;
111}
112
113RegisterSet RegisterSet::allGPRs()
114{
115 RegisterSet result;
116 for (MacroAssembler::RegisterID reg = MacroAssembler::firstRegister(); reg <= MacroAssembler::lastRegister(); reg = static_cast<MacroAssembler::RegisterID>(reg + 1))
117 result.set(reg);
118 return result;
119}
120
121RegisterSet RegisterSet::allFPRs()
122{
123 RegisterSet result;
124 for (MacroAssembler::FPRegisterID reg = MacroAssembler::firstFPRegister(); reg <= MacroAssembler::lastFPRegister(); reg = static_cast<MacroAssembler::FPRegisterID>(reg + 1))
125 result.set(reg);
126 return result;
127}
128
129RegisterSet RegisterSet::allRegisters()
130{
131 RegisterSet result;
132 result.merge(allGPRs());
133 result.merge(allFPRs());
134 return result;
135}
136
137size_t RegisterSet::numberOfSetGPRs() const
138{
139 RegisterSet temp = *this;
140 temp.filter(allGPRs());
141 return temp.numberOfSetRegisters();
142}
143
144size_t RegisterSet::numberOfSetFPRs() const
145{
146 RegisterSet temp = *this;
147 temp.filter(allFPRs());
148 return temp.numberOfSetRegisters();
149}
150
151void RegisterSet::dump(PrintStream& out) const
152{
153 CommaPrinter comma;
154 out.print("[");
155 for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
156 if (get(reg))
157 out.print(comma, reg);
158 }
159 out.print("]");
160}
161
162} // namespace JSC
163
164#endif // ENABLE(JIT)
165