• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14 
15 enum class RegisterKind { kGeneral, kDouble };
16 
GetRegisterCount(const RegisterConfiguration * config,RegisterKind kind)17 inline 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   }
25 }
26 
GetAllocatableRegisterCount(const RegisterConfiguration * config,RegisterKind kind)27 inline int GetAllocatableRegisterCount(const RegisterConfiguration* config,
28                                        RegisterKind kind) {
29   switch (kind) {
30     case RegisterKind::kGeneral:
31       return config->num_allocatable_general_registers();
32     case RegisterKind::kDouble:
33       return config->num_allocatable_double_registers();
34   }
35 }
36 
GetAllocatableRegisterCodes(const RegisterConfiguration * config,RegisterKind kind)37 inline const int* GetAllocatableRegisterCodes(
38     const RegisterConfiguration* config, RegisterKind kind) {
39   switch (kind) {
40     case RegisterKind::kGeneral:
41       return config->allocatable_general_codes();
42     case RegisterKind::kDouble:
43       return config->allocatable_double_codes();
44   }
45 }
46 
ByteWidthForStackSlot(MachineRepresentation rep)47 inline int ByteWidthForStackSlot(MachineRepresentation rep) {
48   switch (rep) {
49     case MachineRepresentation::kBit:
50     case MachineRepresentation::kWord8:
51     case MachineRepresentation::kWord16:
52     case MachineRepresentation::kWord32:
53     case MachineRepresentation::kFloat32:
54       return kSystemPointerSize;
55     case MachineRepresentation::kTaggedSigned:
56     case MachineRepresentation::kTaggedPointer:
57     case MachineRepresentation::kTagged:
58     case MachineRepresentation::kCompressedPointer:
59     case MachineRepresentation::kCompressed:
60       // TODO(ishell): kTaggedSize once half size locations are supported.
61       return kSystemPointerSize;
62     case MachineRepresentation::kWord64:
63     case MachineRepresentation::kFloat64:
64       return kDoubleSize;
65     case MachineRepresentation::kSimd128:
66       return kSimd128Size;
67     case MachineRepresentation::kNone:
68       break;
69   }
70   UNREACHABLE();
71 }
72 
73 class RegisterAllocationData : public ZoneObject {
74  public:
75   enum Type {
76     kTopTier,
77     kMidTier,
78   };
79 
type()80   Type type() const { return type_; }
81 
82  protected:
RegisterAllocationData(Type type)83   explicit RegisterAllocationData(Type type) : type_(type) {}
84 
85  private:
86   Type type_;
87 };
88 
89 }  // namespace compiler
90 }  // namespace internal
91 }  // namespace v8
92 
93 #endif  // V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_
94