Reland "[x64] Make {Assembler::GrowBuffer} preserve most registers"

This is a reland of commit 8fe57bf641.
We restrict the use of "preserve_most" to x64 and arm64 in
non-component builds for now.

Original change's description:
> [x64] Make {Assembler::GrowBuffer} preserve most registers
>
> This makes many callers of {GrowBuffer} a lot slimmer, by avoiding the
> need to push and pop all values in otherwise caller-saved registers.
> E.g. {emit_mov(Register, Operand)} was measured to be ~2x faster (from
> 2.3% of Liftoff compilation time to 1.2%).
>
> R=bikineev@chromium.org
> CC=dlehmann@chromium.org
>
> Bug: v8:13565
> Change-Id: I681747a491548adf1374187cd9f37520c153ef1a
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4127230
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Reviewed-by: Anton Bikineev <bikineev@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#85147}

Bug: v8:13565
Change-Id: I273e222b423786fdc0338c7dfab3d95c8af6ff13
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4147788
Reviewed-by: Anton Bikineev <bikineev@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85231}
This commit is contained in:
Clemens Backes 2023-01-09 17:30:09 +01:00 committed by V8 LUCI CQ
parent 78717ce93d
commit 080e281820
2 changed files with 24 additions and 1 deletions

View File

@ -346,6 +346,14 @@ path. Add it with -I<path> to the command line
# define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull))
# define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
# define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
// Support for the "preserve_most" attribute is incomplete on 32-bit, and we see
// failures in component builds. Thus only use it in 64-bit non-component builds
// for now.
#if (defined(_M_X64) || defined(__x86_64__) || defined(__AARCH64EL__) || \
defined(_M_ARM64)) /* x64 or arm64 */ \
&& !defined(BUILDING_V8_SHARED) && !defined(USING_V8_SHARED)
# define V8_HAS_ATTRIBUTE_PRESERVE_MOST (__has_attribute(preserve_most))
#endif
# define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
(__has_attribute(warn_unused_result))
@ -504,6 +512,21 @@ path. Add it with -I<path> to the command line
#endif
// A macro used to change the calling conventions to preserve all registers (no
// caller-saved registers). Use this for cold functions called from hot
// functions.
// Note: The attribute is considered experimental, so apply with care. Also,
// "preserve_most" is currently not handling the return value correctly, so only
// use it for functions returning void (see https://reviews.llvm.org/D141020).
// Use like:
// V8_NOINLINE V8_PRESERVE_MOST void UnlikelyMethod();
#if V8_HAS_ATTRIBUTE_PRESERVE_MOST
# define V8_PRESERVE_MOST __attribute__((preserve_most))
#else
# define V8_PRESERVE_MOST /* NOT SUPPORTED */
#endif
// A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
#if defined(V8_DEPRECATION_WARNINGS)
# define V8_DEPRECATED(message) [[deprecated(message)]]

View File

@ -2131,7 +2131,7 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
}
// Code emission.
void GrowBuffer();
V8_NOINLINE V8_PRESERVE_MOST void GrowBuffer();
template <typename T>
static uint8_t* emit(uint8_t* __restrict pc, T t) {