]> git.saurik.com Git - apple/javascriptcore.git/blame - jit/RegisterSet.cpp
JavaScriptCore-7600.1.4.11.8.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);
89 result.set(ARMRegisters::r9);
90 result.set(ARMRegisters::r10);
91 result.set(ARMRegisters::r11);
92#elif CPU(ARM64)
93 // We don't include LR in the set of callee-save registers even though it technically belongs
94 // there. This is because we use this set to describe the set of registers that need to be saved
95 // beyond what you would save by the platform-agnostic "preserve return address" and "restore
96 // return address" operations in CCallHelpers.
97 for (
98 ARM64Registers::RegisterID reg = ARM64Registers::x19;
99 reg <= ARM64Registers::x28;
100 reg = static_cast<ARM64Registers::RegisterID>(reg + 1))
101 result.set(reg);
102 result.set(ARM64Registers::fp);
103 for (
104 ARM64Registers::FPRegisterID reg = ARM64Registers::q8;
105 reg <= ARM64Registers::q15;
106 reg = static_cast<ARM64Registers::FPRegisterID>(reg + 1))
107 result.set(reg);
108#else
109 UNREACHABLE_FOR_PLATFORM();
110#endif
111 return result;
112}
113
114RegisterSet RegisterSet::allGPRs()
115{
116 RegisterSet result;
117 for (MacroAssembler::RegisterID reg = MacroAssembler::firstRegister(); reg <= MacroAssembler::lastRegister(); reg = static_cast<MacroAssembler::RegisterID>(reg + 1))
118 result.set(reg);
119 return result;
120}
121
122RegisterSet RegisterSet::allFPRs()
123{
124 RegisterSet result;
125 for (MacroAssembler::FPRegisterID reg = MacroAssembler::firstFPRegister(); reg <= MacroAssembler::lastFPRegister(); reg = static_cast<MacroAssembler::FPRegisterID>(reg + 1))
126 result.set(reg);
127 return result;
128}
129
130RegisterSet RegisterSet::allRegisters()
131{
132 RegisterSet result;
133 result.merge(allGPRs());
134 result.merge(allFPRs());
135 return result;
136}
137
138size_t RegisterSet::numberOfSetGPRs() const
139{
140 RegisterSet temp = *this;
141 temp.filter(allGPRs());
142 return temp.numberOfSetRegisters();
143}
144
145size_t RegisterSet::numberOfSetFPRs() const
146{
147 RegisterSet temp = *this;
148 temp.filter(allFPRs());
149 return temp.numberOfSetRegisters();
150}
151
152void RegisterSet::dump(PrintStream& out) const
153{
154 CommaPrinter comma;
155 out.print("[");
156 for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
157 if (get(reg))
158 out.print(comma, reg);
159 }
160 out.print("]");
161}
162
163} // namespace JSC
164
165#endif // ENABLE(JIT)
166