11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_
61cb0ef41Sopenharmony_ci#define V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/codegen/register-configuration.h"
91cb0ef41Sopenharmony_ci#include "src/zone/zone.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cinamespace v8 {
121cb0ef41Sopenharmony_cinamespace internal {
131cb0ef41Sopenharmony_cinamespace compiler {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cienum class RegisterKind { kGeneral, kDouble, kSimd128 };
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciinline int GetRegisterCount(const RegisterConfiguration* config,
181cb0ef41Sopenharmony_ci                            RegisterKind kind) {
191cb0ef41Sopenharmony_ci  switch (kind) {
201cb0ef41Sopenharmony_ci    case RegisterKind::kGeneral:
211cb0ef41Sopenharmony_ci      return config->num_general_registers();
221cb0ef41Sopenharmony_ci    case RegisterKind::kDouble:
231cb0ef41Sopenharmony_ci      return config->num_double_registers();
241cb0ef41Sopenharmony_ci    case RegisterKind::kSimd128:
251cb0ef41Sopenharmony_ci      return config->num_simd128_registers();
261cb0ef41Sopenharmony_ci  }
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciinline int GetAllocatableRegisterCount(const RegisterConfiguration* config,
301cb0ef41Sopenharmony_ci                                       RegisterKind kind) {
311cb0ef41Sopenharmony_ci  switch (kind) {
321cb0ef41Sopenharmony_ci    case RegisterKind::kGeneral:
331cb0ef41Sopenharmony_ci      return config->num_allocatable_general_registers();
341cb0ef41Sopenharmony_ci    case RegisterKind::kDouble:
351cb0ef41Sopenharmony_ci      return config->num_allocatable_double_registers();
361cb0ef41Sopenharmony_ci    case RegisterKind::kSimd128:
371cb0ef41Sopenharmony_ci      return config->num_allocatable_simd128_registers();
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciinline const int* GetAllocatableRegisterCodes(
421cb0ef41Sopenharmony_ci    const RegisterConfiguration* config, RegisterKind kind) {
431cb0ef41Sopenharmony_ci  switch (kind) {
441cb0ef41Sopenharmony_ci    case RegisterKind::kGeneral:
451cb0ef41Sopenharmony_ci      return config->allocatable_general_codes();
461cb0ef41Sopenharmony_ci    case RegisterKind::kDouble:
471cb0ef41Sopenharmony_ci      return config->allocatable_double_codes();
481cb0ef41Sopenharmony_ci    case RegisterKind::kSimd128:
491cb0ef41Sopenharmony_ci      return config->allocatable_simd128_codes();
501cb0ef41Sopenharmony_ci  }
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciinline int ByteWidthForStackSlot(MachineRepresentation rep) {
541cb0ef41Sopenharmony_ci  switch (rep) {
551cb0ef41Sopenharmony_ci    case MachineRepresentation::kBit:
561cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord8:
571cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord16:
581cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord32:
591cb0ef41Sopenharmony_ci    case MachineRepresentation::kFloat32:
601cb0ef41Sopenharmony_ci    case MachineRepresentation::kSandboxedPointer:
611cb0ef41Sopenharmony_ci      return kSystemPointerSize;
621cb0ef41Sopenharmony_ci    case MachineRepresentation::kTaggedSigned:
631cb0ef41Sopenharmony_ci    case MachineRepresentation::kTaggedPointer:
641cb0ef41Sopenharmony_ci    case MachineRepresentation::kTagged:
651cb0ef41Sopenharmony_ci    case MachineRepresentation::kCompressedPointer:
661cb0ef41Sopenharmony_ci    case MachineRepresentation::kCompressed:
671cb0ef41Sopenharmony_ci      // TODO(ishell): kTaggedSize once half size locations are supported.
681cb0ef41Sopenharmony_ci      return kSystemPointerSize;
691cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord64:
701cb0ef41Sopenharmony_ci    case MachineRepresentation::kFloat64:
711cb0ef41Sopenharmony_ci      return kDoubleSize;
721cb0ef41Sopenharmony_ci    case MachineRepresentation::kSimd128:
731cb0ef41Sopenharmony_ci      return kSimd128Size;
741cb0ef41Sopenharmony_ci    case MachineRepresentation::kNone:
751cb0ef41Sopenharmony_ci    case MachineRepresentation::kMapWord:
761cb0ef41Sopenharmony_ci      break;
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci  UNREACHABLE();
791cb0ef41Sopenharmony_ci}
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ciclass RegisterAllocationData : public ZoneObject {
821cb0ef41Sopenharmony_ci public:
831cb0ef41Sopenharmony_ci  enum Type {
841cb0ef41Sopenharmony_ci    kTopTier,
851cb0ef41Sopenharmony_ci    kMidTier,
861cb0ef41Sopenharmony_ci  };
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci  Type type() const { return type_; }
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci protected:
911cb0ef41Sopenharmony_ci  explicit RegisterAllocationData(Type type) : type_(type) {}
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci private:
941cb0ef41Sopenharmony_ci  Type type_;
951cb0ef41Sopenharmony_ci};
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci}  // namespace compiler
981cb0ef41Sopenharmony_ci}  // namespace internal
991cb0ef41Sopenharmony_ci}  // namespace v8
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci#endif  // V8_COMPILER_BACKEND_REGISTER_ALLOCATION_H_
102