Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 9 | #include "src/machine-type.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | // An architecture independent representation of the sets of registers available |
| 15 | // for instruction creation. |
| 16 | class RegisterConfiguration { |
| 17 | public: |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 18 | 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | |
| 25 | // Architecture independent maxes. |
| 26 | static const int kMaxGeneralRegisters = 32; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 27 | static const int kMaxFPRegisters = 32; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 29 | // 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | |
| 35 | RegisterConfiguration(int num_general_registers, int num_double_registers, |
| 36 | int num_allocatable_general_registers, |
| 37 | int num_allocatable_double_registers, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 38 | const int* allocatable_general_codes, |
| 39 | const int* allocatable_double_codes, |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 40 | AliasingKind fp_aliasing_kind, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | char const* const* general_names, |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 42 | char const* const* float_names, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | char const* const* double_names); |
| 44 | |
| 45 | int num_general_registers() const { return num_general_registers_; } |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 46 | int num_float_registers() const { return num_float_registers_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 47 | 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 54 | int num_allocatable_float_registers() const { |
| 55 | return num_allocatable_float_registers_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | } |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 57 | AliasingKind fp_aliasing_kind() const { return fp_aliasing_kind_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 67 | bool IsAllocatableGeneralCode(int index) const { |
| 68 | return ((1 << index) & allocatable_general_codes_mask_) != 0; |
| 69 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 70 | int GetAllocatableDoubleCode(int index) const { |
| 71 | return allocatable_double_codes_[index]; |
| 72 | } |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 73 | 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 82 | const char* GetGeneralRegisterName(int code) const { |
| 83 | return general_register_names_[code]; |
| 84 | } |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 85 | const char* GetFloatRegisterName(int code) const { |
| 86 | return float_register_names_[code]; |
| 87 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | 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 Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 97 | 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | |
| 113 | private: |
| 114 | const int num_general_registers_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 115 | int num_float_registers_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 116 | const int num_double_registers_; |
| 117 | int num_allocatable_general_registers_; |
| 118 | int num_allocatable_double_registers_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 119 | int num_allocatable_float_registers_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 120 | int32_t allocatable_general_codes_mask_; |
| 121 | int32_t allocatable_double_codes_mask_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 122 | int32_t allocatable_float_codes_mask_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | const int* allocatable_general_codes_; |
| 124 | const int* allocatable_double_codes_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 125 | int allocatable_float_codes_[kMaxFPRegisters]; |
| 126 | AliasingKind fp_aliasing_kind_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | char const* const* general_register_names_; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 128 | char const* const* float_register_names_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 129 | char const* const* double_register_names_; |
| 130 | }; |
| 131 | |
| 132 | } // namespace internal |
| 133 | } // namespace v8 |
| 134 | |
| 135 | #endif // V8_COMPILER_REGISTER_CONFIGURATION_H_ |