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 <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57646}
This commit is contained in:
Clemens Hammacher 2018-11-20 11:58:12 +01:00 committed by Commit Bot
parent 00ffe4a613
commit de2681c1a8
8 changed files with 46 additions and 8 deletions

View File

@ -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

View File

@ -3645,6 +3645,9 @@ class EnsureSpace {
}
};
// Define a {RegisterName} method for {CPURegister}.
DEFINE_REGISTER_NAMES(CPURegister, GENERAL_REGISTERS);
} // namespace internal
} // namespace v8

View File

@ -526,10 +526,20 @@ class RegisterBase {
int reg_code_;
};
template <typename SubType, int kAfterLastRegister>
inline std::ostream& operator<<(std::ostream& os,
RegisterBase<SubType, kAfterLastRegister> reg) {
return reg.is_valid() ? os << "r" << reg.code() : os << "<invalid reg>";
// 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 <typename RegType,
typename = decltype(RegisterName(std::declval<RegType>()))>
inline std::ostream& operator<<(std::ostream& os, RegType reg) {
return os << RegisterName(reg);
}
} // namespace internal

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -185,12 +185,11 @@ ASSERT_TRIVIALLY_COPYABLE(LiftoffRegister);
inline std::ostream& operator<<(std::ostream& os, LiftoffRegister reg) {
if (reg.is_pair()) {
return os << "<gp" << reg.low_gp().code() << "+" << reg.high_gp().code()
<< ">";
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();
}
}

View File

@ -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