1// Copyright 2020 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_BACKEND_REGISTER_ALLOCATION_H_ 6#define V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_ 7 8#include "src/codegen/register-configuration.h" 9#include "src/zone/zone.h" 10 11namespace v8 { 12namespace internal { 13namespace compiler { 14 15enum class RegisterKind { kGeneral, kDouble, kSimd128 }; 16 17inline int GetRegisterCount(const RegisterConfiguration* config, 18 RegisterKind kind) { 19 switch (kind) { 20 case RegisterKind::kGeneral: 21 return config->num_general_registers(); 22 case RegisterKind::kDouble: 23 return config->num_double_registers(); 24 case RegisterKind::kSimd128: 25 return config->num_simd128_registers(); 26 } 27} 28 29inline int GetAllocatableRegisterCount(const RegisterConfiguration* config, 30 RegisterKind kind) { 31 switch (kind) { 32 case RegisterKind::kGeneral: 33 return config->num_allocatable_general_registers(); 34 case RegisterKind::kDouble: 35 return config->num_allocatable_double_registers(); 36 case RegisterKind::kSimd128: 37 return config->num_allocatable_simd128_registers(); 38 } 39} 40 41inline const int* GetAllocatableRegisterCodes( 42 const RegisterConfiguration* config, RegisterKind kind) { 43 switch (kind) { 44 case RegisterKind::kGeneral: 45 return config->allocatable_general_codes(); 46 case RegisterKind::kDouble: 47 return config->allocatable_double_codes(); 48 case RegisterKind::kSimd128: 49 return config->allocatable_simd128_codes(); 50 } 51} 52 53inline int ByteWidthForStackSlot(MachineRepresentation rep) { 54 switch (rep) { 55 case MachineRepresentation::kBit: 56 case MachineRepresentation::kWord8: 57 case MachineRepresentation::kWord16: 58 case MachineRepresentation::kWord32: 59 case MachineRepresentation::kFloat32: 60 case MachineRepresentation::kSandboxedPointer: 61 return kSystemPointerSize; 62 case MachineRepresentation::kTaggedSigned: 63 case MachineRepresentation::kTaggedPointer: 64 case MachineRepresentation::kTagged: 65 case MachineRepresentation::kCompressedPointer: 66 case MachineRepresentation::kCompressed: 67 // TODO(ishell): kTaggedSize once half size locations are supported. 68 return kSystemPointerSize; 69 case MachineRepresentation::kWord64: 70 case MachineRepresentation::kFloat64: 71 return kDoubleSize; 72 case MachineRepresentation::kSimd128: 73 return kSimd128Size; 74 case MachineRepresentation::kNone: 75 case MachineRepresentation::kMapWord: 76 break; 77 } 78 UNREACHABLE(); 79} 80 81class RegisterAllocationData : public ZoneObject { 82 public: 83 enum Type { 84 kTopTier, 85 kMidTier, 86 }; 87 88 Type type() const { return type_; } 89 90 protected: 91 explicit RegisterAllocationData(Type type) : type_(type) {} 92 93 private: 94 Type type_; 95}; 96 97} // namespace compiler 98} // namespace internal 99} // namespace v8 100 101#endif // V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_ 102