blob: 25f3ef5f20b033a47b1df36c5d7e981cd88986d9 [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#ifndef V8_COMPILER_REGISTER_CONFIGURATION_H_
6#define V8_COMPILER_REGISTER_CONFIGURATION_H_
7
8#include "src/base/macros.h"
Ben Murdoch61f157c2016-09-16 13:49:30 +01009#include "src/machine-type.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010
11namespace v8 {
12namespace internal {
13
14// An architecture independent representation of the sets of registers available
15// for instruction creation.
16class RegisterConfiguration {
17 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +010018 enum AliasingKind {
19 // Registers alias a single register of every other size (e.g. Intel).
20 OVERLAP,
21 // Registers alias two registers of the next smaller size (e.g. ARM).
22 COMBINE
23 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024
25 // Architecture independent maxes.
26 static const int kMaxGeneralRegisters = 32;
Ben Murdochc5610432016-08-08 18:44:38 +010027 static const int kMaxFPRegisters = 32;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028
Ben Murdoch61f157c2016-09-16 13:49:30 +010029 // Default RegisterConfigurations for the target architecture.
30 // TODO(X87): This distinction in RegisterConfigurations is temporary
31 // until x87 TF supports all of the registers that Crankshaft does.
32 static const RegisterConfiguration* Crankshaft();
33 static const RegisterConfiguration* Turbofan();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034
35 RegisterConfiguration(int num_general_registers, int num_double_registers,
36 int num_allocatable_general_registers,
37 int num_allocatable_double_registers,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 const int* allocatable_general_codes,
39 const int* allocatable_double_codes,
Ben Murdoch61f157c2016-09-16 13:49:30 +010040 AliasingKind fp_aliasing_kind,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041 char const* const* general_names,
Ben Murdoch61f157c2016-09-16 13:49:30 +010042 char const* const* float_names,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043 char const* const* double_names);
44
45 int num_general_registers() const { return num_general_registers_; }
Ben Murdoch61f157c2016-09-16 13:49:30 +010046 int num_float_registers() const { return num_float_registers_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047 int num_double_registers() const { return num_double_registers_; }
48 int num_allocatable_general_registers() const {
49 return num_allocatable_general_registers_;
50 }
51 int num_allocatable_double_registers() const {
52 return num_allocatable_double_registers_;
53 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010054 int num_allocatable_float_registers() const {
55 return num_allocatable_float_registers_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010057 AliasingKind fp_aliasing_kind() const { return fp_aliasing_kind_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 int32_t allocatable_general_codes_mask() const {
59 return allocatable_general_codes_mask_;
60 }
61 int32_t allocatable_double_codes_mask() const {
62 return allocatable_double_codes_mask_;
63 }
64 int GetAllocatableGeneralCode(int index) const {
65 return allocatable_general_codes_[index];
66 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010067 bool IsAllocatableGeneralCode(int index) const {
68 return ((1 << index) & allocatable_general_codes_mask_) != 0;
69 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 int GetAllocatableDoubleCode(int index) const {
71 return allocatable_double_codes_[index];
72 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010073 bool IsAllocatableDoubleCode(int index) const {
74 return ((1 << index) & allocatable_double_codes_mask_) != 0;
75 }
76 int GetAllocatableFloatCode(int index) const {
77 return allocatable_float_codes_[index];
78 }
79 bool IsAllocatableFloatCode(int index) const {
80 return ((1 << index) & allocatable_float_codes_mask_) != 0;
81 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000082 const char* GetGeneralRegisterName(int code) const {
83 return general_register_names_[code];
84 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010085 const char* GetFloatRegisterName(int code) const {
86 return float_register_names_[code];
87 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000088 const char* GetDoubleRegisterName(int code) const {
89 return double_register_names_[code];
90 }
91 const int* allocatable_general_codes() const {
92 return allocatable_general_codes_;
93 }
94 const int* allocatable_double_codes() const {
95 return allocatable_double_codes_;
96 }
Ben Murdoch61f157c2016-09-16 13:49:30 +010097 const int* allocatable_float_codes() const {
98 return allocatable_float_codes_;
99 }
100
101 // Aliasing calculations for floating point registers, when fp_aliasing_kind()
102 // is COMBINE. Currently only implemented for kFloat32, or kFloat64 reps.
103 // Returns the number of aliases, and if > 0, alias_base_index is set to the
104 // index of the first alias.
105 int GetAliases(MachineRepresentation rep, int index,
106 MachineRepresentation other_rep, int* alias_base_index) const;
107 // Returns a value indicating whether two registers alias each other, when
108 // fp_aliasing_kind() is COMBINE. Currently only implemented for kFloat32, or
109 // kFloat64 reps.
110 bool AreAliases(MachineRepresentation rep, int index,
111 MachineRepresentation other_rep, int other_index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112
113 private:
114 const int num_general_registers_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100115 int num_float_registers_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 const int num_double_registers_;
117 int num_allocatable_general_registers_;
118 int num_allocatable_double_registers_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100119 int num_allocatable_float_registers_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120 int32_t allocatable_general_codes_mask_;
121 int32_t allocatable_double_codes_mask_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100122 int32_t allocatable_float_codes_mask_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123 const int* allocatable_general_codes_;
124 const int* allocatable_double_codes_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100125 int allocatable_float_codes_[kMaxFPRegisters];
126 AliasingKind fp_aliasing_kind_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 char const* const* general_register_names_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100128 char const* const* float_register_names_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000129 char const* const* double_register_names_;
130};
131
132} // namespace internal
133} // namespace v8
134
135#endif // V8_COMPILER_REGISTER_CONFIGURATION_H_