blob: ab5c6926a7a5bcbae62d46c137f9b28922143e82 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/register-configuration.h"
6#include "src/globals.h"
7#include "src/macro-assembler.h"
8
9namespace v8 {
10namespace internal {
11
12namespace {
13
14#define REGISTER_COUNT(R) 1 +
15static const int kMaxAllocatableGeneralRegisterCount =
16 ALLOCATABLE_GENERAL_REGISTERS(REGISTER_COUNT)0;
17static const int kMaxAllocatableDoubleRegisterCount =
18 ALLOCATABLE_DOUBLE_REGISTERS(REGISTER_COUNT)0;
19
20static const int kAllocatableGeneralCodes[] = {
21#define REGISTER_CODE(R) Register::kCode_##R,
22 ALLOCATABLE_GENERAL_REGISTERS(REGISTER_CODE)};
23#undef REGISTER_CODE
24
25static const int kAllocatableDoubleCodes[] = {
26#define REGISTER_CODE(R) DoubleRegister::kCode_##R,
27 ALLOCATABLE_DOUBLE_REGISTERS(REGISTER_CODE)};
28#undef REGISTER_CODE
29
30static const char* const kGeneralRegisterNames[] = {
31#define REGISTER_NAME(R) #R,
32 GENERAL_REGISTERS(REGISTER_NAME)
33#undef REGISTER_NAME
34};
35
36static const char* const kDoubleRegisterNames[] = {
37#define REGISTER_NAME(R) #R,
38 DOUBLE_REGISTERS(REGISTER_NAME)
39#undef REGISTER_NAME
40};
41
42STATIC_ASSERT(RegisterConfiguration::kMaxGeneralRegisters >=
43 Register::kNumRegisters);
Ben Murdochc5610432016-08-08 18:44:38 +010044STATIC_ASSERT(RegisterConfiguration::kMaxFPRegisters >=
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 DoubleRegister::kMaxNumRegisters);
46
47class ArchDefaultRegisterConfiguration : public RegisterConfiguration {
48 public:
49 explicit ArchDefaultRegisterConfiguration(CompilerSelector compiler)
50 : RegisterConfiguration(Register::kNumRegisters,
51 DoubleRegister::kMaxNumRegisters,
52#if V8_TARGET_ARCH_IA32
53 kMaxAllocatableGeneralRegisterCount,
54 kMaxAllocatableDoubleRegisterCount,
55 kMaxAllocatableDoubleRegisterCount,
56#elif V8_TARGET_ARCH_X87
57 kMaxAllocatableGeneralRegisterCount,
58 compiler == TURBOFAN
59 ? 1
60 : kMaxAllocatableDoubleRegisterCount,
61 compiler == TURBOFAN
62 ? 1
63 : kMaxAllocatableDoubleRegisterCount,
64#elif V8_TARGET_ARCH_X64
65 kMaxAllocatableGeneralRegisterCount,
66 kMaxAllocatableDoubleRegisterCount,
67 kMaxAllocatableDoubleRegisterCount,
68#elif V8_TARGET_ARCH_ARM
69 FLAG_enable_embedded_constant_pool
70 ? (kMaxAllocatableGeneralRegisterCount - 1)
71 : kMaxAllocatableGeneralRegisterCount,
72 CpuFeatures::IsSupported(VFP32DREGS)
73 ? kMaxAllocatableDoubleRegisterCount
74 : (ALLOCATABLE_NO_VFP32_DOUBLE_REGISTERS(
75 REGISTER_COUNT)0),
76 ALLOCATABLE_NO_VFP32_DOUBLE_REGISTERS(
77 REGISTER_COUNT)0,
78#elif V8_TARGET_ARCH_ARM64
79 kMaxAllocatableGeneralRegisterCount,
80 kMaxAllocatableDoubleRegisterCount,
81 kMaxAllocatableDoubleRegisterCount,
82#elif V8_TARGET_ARCH_MIPS
83 kMaxAllocatableGeneralRegisterCount,
84 kMaxAllocatableDoubleRegisterCount,
85 kMaxAllocatableDoubleRegisterCount,
86#elif V8_TARGET_ARCH_MIPS64
87 kMaxAllocatableGeneralRegisterCount,
88 kMaxAllocatableDoubleRegisterCount,
89 kMaxAllocatableDoubleRegisterCount,
90#elif V8_TARGET_ARCH_PPC
91 kMaxAllocatableGeneralRegisterCount,
92 kMaxAllocatableDoubleRegisterCount,
93 kMaxAllocatableDoubleRegisterCount,
Ben Murdochda12d292016-06-02 14:46:10 +010094#elif V8_TARGET_ARCH_S390
95 kMaxAllocatableGeneralRegisterCount,
96 kMaxAllocatableDoubleRegisterCount,
97 kMaxAllocatableDoubleRegisterCount,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098#else
99#error Unsupported target architecture.
100#endif
101 kAllocatableGeneralCodes, kAllocatableDoubleCodes,
102 kGeneralRegisterNames, kDoubleRegisterNames) {
103 }
104};
105
106
107template <RegisterConfiguration::CompilerSelector compiler>
108struct RegisterConfigurationInitializer {
109 static void Construct(ArchDefaultRegisterConfiguration* config) {
110 new (config) ArchDefaultRegisterConfiguration(compiler);
111 }
112};
113
114static base::LazyInstance<
115 ArchDefaultRegisterConfiguration,
116 RegisterConfigurationInitializer<RegisterConfiguration::CRANKSHAFT>>::type
117 kDefaultRegisterConfigurationForCrankshaft = LAZY_INSTANCE_INITIALIZER;
118
119
120static base::LazyInstance<
121 ArchDefaultRegisterConfiguration,
122 RegisterConfigurationInitializer<RegisterConfiguration::TURBOFAN>>::type
123 kDefaultRegisterConfigurationForTurboFan = LAZY_INSTANCE_INITIALIZER;
124
125} // namespace
126
127
128const RegisterConfiguration* RegisterConfiguration::ArchDefault(
129 CompilerSelector compiler) {
130 return compiler == TURBOFAN
131 ? &kDefaultRegisterConfigurationForTurboFan.Get()
132 : &kDefaultRegisterConfigurationForCrankshaft.Get();
133}
134
135
136RegisterConfiguration::RegisterConfiguration(
137 int num_general_registers, int num_double_registers,
138 int num_allocatable_general_registers, int num_allocatable_double_registers,
139 int num_allocatable_aliased_double_registers,
140 const int* allocatable_general_codes, const int* allocatable_double_codes,
141 const char* const* general_register_names,
142 const char* const* double_register_names)
143 : num_general_registers_(num_general_registers),
144 num_double_registers_(num_double_registers),
145 num_allocatable_general_registers_(num_allocatable_general_registers),
146 num_allocatable_double_registers_(num_allocatable_double_registers),
147 num_allocatable_aliased_double_registers_(
148 num_allocatable_aliased_double_registers),
149 allocatable_general_codes_mask_(0),
150 allocatable_double_codes_mask_(0),
151 allocatable_general_codes_(allocatable_general_codes),
152 allocatable_double_codes_(allocatable_double_codes),
153 general_register_names_(general_register_names),
154 double_register_names_(double_register_names) {
Ben Murdochc5610432016-08-08 18:44:38 +0100155 DCHECK(num_general_registers_ <= RegisterConfiguration::kMaxGeneralRegisters);
156 DCHECK(num_double_registers_ <= RegisterConfiguration::kMaxFPRegisters);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157 for (int i = 0; i < num_allocatable_general_registers_; ++i) {
158 allocatable_general_codes_mask_ |= (1 << allocatable_general_codes_[i]);
159 }
160 for (int i = 0; i < num_allocatable_double_registers_; ++i) {
161 allocatable_double_codes_mask_ |= (1 << allocatable_double_codes_[i]);
162 }
163}
164
165#undef REGISTER_COUNT
166
167} // namespace internal
168} // namespace v8