From de2681c1a8fea8d2f8da2424863714f4652b0b76 Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Tue, 20 Nov 2018 11:58:12 +0100 Subject: [PATCH] Print readable register names This adds a {PrintRegister} method which prints the given register in a readable way (e.g. "eax", ... on ia32). This is currently only used in Liftoff. The {RegisterConfiguration} class has the same functionality, and I plan to make {RegisterConfiguration} also use the new {RegisterName} functions in a follow-up CL. R=mstarzinger@chromium.org Bug: v8:8238, v8:8423, v8:6600 Change-Id: If03901f1d8c5b043e0097e63920ab711bd7e2d17 Reviewed-on: https://chromium-review.googlesource.com/c/1340041 Reviewed-by: Michael Starzinger Commit-Queue: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#57646} --- src/arm/assembler-arm.h | 8 ++++++++ src/arm64/assembler-arm64.h | 3 +++ src/assembler.h | 18 ++++++++++++++---- src/ia32/assembler-ia32.h | 4 ++++ src/mips/assembler-mips.h | 5 +++++ src/mips64/assembler-mips64.h | 5 +++++ src/wasm/baseline/liftoff-register.h | 7 +++---- src/x64/assembler-x64.h | 4 ++++ 8 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/arm/assembler-arm.h b/src/arm/assembler-arm.h index 795f56d8a0..e3404a944d 100644 --- a/src/arm/assembler-arm.h +++ b/src/arm/assembler-arm.h @@ -1757,6 +1757,14 @@ class UseScratchRegisterScope { VfpRegList old_available_vfp_; }; +// Define {RegisterName} methods for the register types. +DEFINE_REGISTER_NAMES(Register, GENERAL_REGISTERS); +DEFINE_REGISTER_NAMES(SwVfpRegister, FLOAT_REGISTERS); +DEFINE_REGISTER_NAMES(DwVfpRegister, DOUBLE_REGISTERS); +DEFINE_REGISTER_NAMES(LowDwVfpRegister, LOW_DOUBLE_REGISTERS); +DEFINE_REGISTER_NAMES(QwNeonRegister, SIMD128_REGISTERS); +DEFINE_REGISTER_NAMES(CRegister, C_REGISTERS); + } // namespace internal } // namespace v8 diff --git a/src/arm64/assembler-arm64.h b/src/arm64/assembler-arm64.h index 87a28f5ddc..16a0c047bf 100644 --- a/src/arm64/assembler-arm64.h +++ b/src/arm64/assembler-arm64.h @@ -3645,6 +3645,9 @@ class EnsureSpace { } }; +// Define a {RegisterName} method for {CPURegister}. +DEFINE_REGISTER_NAMES(CPURegister, GENERAL_REGISTERS); + } // namespace internal } // namespace v8 diff --git a/src/assembler.h b/src/assembler.h index 57f52183aa..9691053ef8 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -526,10 +526,20 @@ class RegisterBase { int reg_code_; }; -template -inline std::ostream& operator<<(std::ostream& os, - RegisterBase reg) { - return reg.is_valid() ? os << "r" << reg.code() : os << ""; +// Helper macros to define a {RegisterName} method based on a macro list +// containing all names. +#define DEFINE_REGISTER_NAMES_NAME(name) #name, +#define DEFINE_REGISTER_NAMES(RegType, LIST) \ + inline const char* RegisterName(RegType reg) { \ + static constexpr const char* Names[] = {LIST(DEFINE_REGISTER_NAMES_NAME)}; \ + STATIC_ASSERT(arraysize(Names) == RegType::kNumRegisters); \ + return reg.is_valid() ? Names[reg.code()] : "invalid"; \ + } + +template ()))> +inline std::ostream& operator<<(std::ostream& os, RegType reg) { + return os << RegisterName(reg); } } // namespace internal diff --git a/src/ia32/assembler-ia32.h b/src/ia32/assembler-ia32.h index 0f43ce8d0d..3d95367489 100644 --- a/src/ia32/assembler-ia32.h +++ b/src/ia32/assembler-ia32.h @@ -1895,6 +1895,10 @@ class EnsureSpace { #endif }; +// Define {RegisterName} methods for the register types. +DEFINE_REGISTER_NAMES(Register, GENERAL_REGISTERS) +DEFINE_REGISTER_NAMES(XMMRegister, DOUBLE_REGISTERS) + } // namespace internal } // namespace v8 diff --git a/src/mips/assembler-mips.h b/src/mips/assembler-mips.h index 4b65cfa706..f3c355808f 100644 --- a/src/mips/assembler-mips.h +++ b/src/mips/assembler-mips.h @@ -2257,6 +2257,11 @@ class UseScratchRegisterScope { RegList old_available_; }; +// Define {RegisterName} methods for the register types. +DEFINE_REGISTER_NAMES(Register, GENERAL_REGISTERS) +DEFINE_REGISTER_NAMES(FPURegister, DOUBLE_REGISTERS) +DEFINE_REGISTER_NAMES(MSARegister, SIMD128_REGISTERS) + } // namespace internal } // namespace v8 diff --git a/src/mips64/assembler-mips64.h b/src/mips64/assembler-mips64.h index a6785b5d91..e05d106f47 100644 --- a/src/mips64/assembler-mips64.h +++ b/src/mips64/assembler-mips64.h @@ -2292,6 +2292,11 @@ class UseScratchRegisterScope { RegList old_available_; }; +// Define {RegisterName} methods for the register types. +DEFINE_REGISTER_NAMES(Register, GENERAL_REGISTERS) +DEFINE_REGISTER_NAMES(FPURegister, DOUBLE_REGISTERS) +DEFINE_REGISTER_NAMES(MSARegister, SIMD128_REGISTERS) + } // namespace internal } // namespace v8 diff --git a/src/wasm/baseline/liftoff-register.h b/src/wasm/baseline/liftoff-register.h index 5654bd882d..da0f00ab51 100644 --- a/src/wasm/baseline/liftoff-register.h +++ b/src/wasm/baseline/liftoff-register.h @@ -185,12 +185,11 @@ ASSERT_TRIVIALLY_COPYABLE(LiftoffRegister); inline std::ostream& operator<<(std::ostream& os, LiftoffRegister reg) { if (reg.is_pair()) { - return os << ""; + return os << "<" << reg.low_gp() << "+" << reg.high_gp() << ">"; } else if (reg.is_gp()) { - return os << "gp" << reg.gp().code(); + return os << reg.gp(); } else { - return os << "fp" << reg.fp().code(); + return os << reg.fp(); } } diff --git a/src/x64/assembler-x64.h b/src/x64/assembler-x64.h index c09ffdf477..688533ddfa 100644 --- a/src/x64/assembler-x64.h +++ b/src/x64/assembler-x64.h @@ -2455,6 +2455,10 @@ class EnsureSpace { #endif }; +// Define {RegisterName} methods for the register types. +DEFINE_REGISTER_NAMES(Register, GENERAL_REGISTERS) +DEFINE_REGISTER_NAMES(XMMRegister, DOUBLE_REGISTERS) + } // namespace internal } // namespace v8