]>
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 | #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 | ||
36 | namespace JSC { | |
37 | ||
38 | RegisterSet RegisterSet::stackRegisters() | |
39 | { | |
40 | return RegisterSet( | |
41 | MacroAssembler::stackPointerRegister, | |
42 | MacroAssembler::framePointerRegister); | |
43 | } | |
44 | ||
45 | RegisterSet RegisterSet::reservedHardwareRegisters() | |
46 | { | |
47 | #if CPU(ARM64) | |
48 | return RegisterSet(ARM64Registers::lr); | |
49 | #else | |
50 | return RegisterSet(); | |
51 | #endif | |
52 | } | |
53 | ||
54 | RegisterSet RegisterSet::runtimeRegisters() | |
55 | { | |
56 | #if USE(JSVALUE64) | |
57 | return RegisterSet(GPRInfo::tagTypeNumberRegister, GPRInfo::tagMaskRegister); | |
58 | #else | |
59 | return RegisterSet(); | |
60 | #endif | |
61 | } | |
62 | ||
63 | RegisterSet RegisterSet::specialRegisters() | |
64 | { | |
65 | return RegisterSet( | |
66 | stackRegisters(), reservedHardwareRegisters(), runtimeRegisters()); | |
67 | } | |
68 | ||
69 | RegisterSet 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); | |
ed1e77d3 A |
89 | #if !PLATFORM(IOS) |
90 | result.set(ARMRegisters::r9); | |
91 | #endif | |
92 | result.set(ARMRegisters::r10); | |
93 | result.set(ARMRegisters::r11); | |
94 | #elif CPU(ARM_TRADITIONAL) | |
95 | result.set(ARMRegisters::r4); | |
96 | result.set(ARMRegisters::r5); | |
97 | result.set(ARMRegisters::r6); | |
98 | result.set(ARMRegisters::r7); | |
99 | result.set(ARMRegisters::r8); | |
100 | result.set(ARMRegisters::r9); | |
81345200 A |
101 | result.set(ARMRegisters::r10); |
102 | result.set(ARMRegisters::r11); | |
103 | #elif CPU(ARM64) | |
104 | // We don't include LR in the set of callee-save registers even though it technically belongs | |
105 | // there. This is because we use this set to describe the set of registers that need to be saved | |
106 | // beyond what you would save by the platform-agnostic "preserve return address" and "restore | |
107 | // return address" operations in CCallHelpers. | |
108 | for ( | |
109 | ARM64Registers::RegisterID reg = ARM64Registers::x19; | |
110 | reg <= ARM64Registers::x28; | |
111 | reg = static_cast<ARM64Registers::RegisterID>(reg + 1)) | |
112 | result.set(reg); | |
113 | result.set(ARM64Registers::fp); | |
114 | for ( | |
115 | ARM64Registers::FPRegisterID reg = ARM64Registers::q8; | |
116 | reg <= ARM64Registers::q15; | |
117 | reg = static_cast<ARM64Registers::FPRegisterID>(reg + 1)) | |
118 | result.set(reg); | |
119 | #else | |
120 | UNREACHABLE_FOR_PLATFORM(); | |
121 | #endif | |
122 | return result; | |
123 | } | |
124 | ||
125 | RegisterSet RegisterSet::allGPRs() | |
126 | { | |
127 | RegisterSet result; | |
128 | for (MacroAssembler::RegisterID reg = MacroAssembler::firstRegister(); reg <= MacroAssembler::lastRegister(); reg = static_cast<MacroAssembler::RegisterID>(reg + 1)) | |
129 | result.set(reg); | |
130 | return result; | |
131 | } | |
132 | ||
133 | RegisterSet RegisterSet::allFPRs() | |
134 | { | |
135 | RegisterSet result; | |
136 | for (MacroAssembler::FPRegisterID reg = MacroAssembler::firstFPRegister(); reg <= MacroAssembler::lastFPRegister(); reg = static_cast<MacroAssembler::FPRegisterID>(reg + 1)) | |
137 | result.set(reg); | |
138 | return result; | |
139 | } | |
140 | ||
141 | RegisterSet RegisterSet::allRegisters() | |
142 | { | |
143 | RegisterSet result; | |
144 | result.merge(allGPRs()); | |
145 | result.merge(allFPRs()); | |
146 | return result; | |
147 | } | |
148 | ||
149 | size_t RegisterSet::numberOfSetGPRs() const | |
150 | { | |
151 | RegisterSet temp = *this; | |
152 | temp.filter(allGPRs()); | |
153 | return temp.numberOfSetRegisters(); | |
154 | } | |
155 | ||
156 | size_t RegisterSet::numberOfSetFPRs() const | |
157 | { | |
158 | RegisterSet temp = *this; | |
159 | temp.filter(allFPRs()); | |
160 | return temp.numberOfSetRegisters(); | |
161 | } | |
162 | ||
163 | void RegisterSet::dump(PrintStream& out) const | |
164 | { | |
165 | CommaPrinter comma; | |
166 | out.print("["); | |
167 | for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) { | |
168 | if (get(reg)) | |
169 | out.print(comma, reg); | |
170 | } | |
171 | out.print("]"); | |
172 | } | |
173 | ||
174 | } // namespace JSC | |
175 | ||
176 | #endif // ENABLE(JIT) | |
177 |