11cb0ef41Sopenharmony_ci// Copyright 2018 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_CODEGEN_REGISTER_H_
61cb0ef41Sopenharmony_ci#define V8_CODEGEN_REGISTER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/codegen/register-arch.h"
91cb0ef41Sopenharmony_ci#include "src/codegen/reglist.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cinamespace v8 {
121cb0ef41Sopenharmony_cinamespace internal {
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconstexpr int AddArgumentPaddingSlots(int argument_count) {
151cb0ef41Sopenharmony_ci  return argument_count + ArgumentPaddingSlots(argument_count);
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconstexpr bool ShouldPadArguments(int argument_count) {
191cb0ef41Sopenharmony_ci  return ArgumentPaddingSlots(argument_count) != 0;
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci#ifdef DEBUG
231cb0ef41Sopenharmony_citemplate <typename... RegTypes,
241cb0ef41Sopenharmony_ci          // All arguments must be either Register or DoubleRegister.
251cb0ef41Sopenharmony_ci          typename = typename std::enable_if_t<
261cb0ef41Sopenharmony_ci              std::conjunction_v<std::is_same<Register, RegTypes>...> ||
271cb0ef41Sopenharmony_ci              std::conjunction_v<std::is_same<DoubleRegister, RegTypes>...>>>
281cb0ef41Sopenharmony_ciinline constexpr bool AreAliased(RegTypes... regs) {
291cb0ef41Sopenharmony_ci  using FirstRegType = std::tuple_element_t<0, std::tuple<RegTypes...>>;
301cb0ef41Sopenharmony_ci  int num_different_regs = RegListBase<FirstRegType>{regs...}.Count();
311cb0ef41Sopenharmony_ci  int num_given_regs = (... + (regs.is_valid() ? 1 : 0));
321cb0ef41Sopenharmony_ci  return num_different_regs < num_given_regs;
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci#endif
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci}  // namespace internal
371cb0ef41Sopenharmony_ci}  // namespace v8
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci#endif  // V8_CODEGEN_REGISTER_H_
40