Commit d8c22181 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[liftoff] Speed up check for supported types

The most common case is still one of the unconditionally supported (MVP)
types. Hence avoid the switch and the flags / CPU features lookup in the
hot function, and offload that to a rarely called function. The fast
path is now just a bit check via an EnumSet.

R=thibaudm@chromium.org

Change-Id: I0cee94640bcc0e5e0fa636e23eb0ba5460d8b8fd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2778271Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73611}
parent 9790f265
......@@ -4,6 +4,7 @@
#include "src/wasm/baseline/liftoff-compiler.h"
#include "src/base/enum-set.h"
#include "src/base/optional.h"
#include "src/base/platform/wrappers.h"
#include "src/codegen/assembler-inl.h"
......@@ -521,17 +522,27 @@ class LiftoffCompiler {
return true;
}
bool CheckSupportedType(FullDecoder* decoder, ValueKind kind,
const char* context) {
LiftoffBailoutReason bailout_reason = kOtherReason;
V8_INLINE bool CheckSupportedType(FullDecoder* decoder, ValueKind kind,
const char* context) {
if (V8_LIKELY(supported_types_.contains(kind))) return true;
return MaybeBailoutForUnsupportedType(decoder, kind, context);
}
V8_NOINLINE bool MaybeBailoutForUnsupportedType(FullDecoder* decoder,
ValueKind kind,
const char* context) {
DCHECK(!supported_types_.contains(kind));
// Lazily update {supported_types_}; then check again.
if (CpuFeatures::SupportsWasmSimd128()) supported_types_.Add(kS128);
if (FLAG_experimental_liftoff_extern_ref) {
supported_types_.Add(kExternRefSupported);
}
if (supported_types_.contains(kind)) return true;
LiftoffBailoutReason bailout_reason;
switch (kind) {
case kI32:
case kI64:
case kF32:
case kF64:
return true;
case kS128:
if (CpuFeatures::SupportsWasmSimd128()) return true;
bailout_reason = kMissingCPUFeature;
break;
case kRef:
......@@ -540,11 +551,9 @@ class LiftoffCompiler {
case kRttWithDepth:
case kI8:
case kI16:
if (FLAG_experimental_liftoff_extern_ref) return true;
bailout_reason = kRefTypes;
break;
case kBottom:
case kVoid:
default:
UNREACHABLE();
}
EmbeddedVector<char, 128> buffer;
......@@ -6038,6 +6047,10 @@ class LiftoffCompiler {
}
static constexpr WasmOpcode kNoOutstandingOp = kExprUnreachable;
static constexpr base::EnumSet<ValueKind> kUnconditionallySupported{
kI32, kI64, kF32, kF64};
static constexpr base::EnumSet<ValueKind> kExternRefSupported{
kRef, kOptRef, kRtt, kRttWithDepth, kI8, kI16};
LiftoffAssembler asm_;
......@@ -6045,6 +6058,8 @@ class LiftoffCompiler {
// Set by the first opcode, reset by the second.
WasmOpcode outstanding_op_ = kNoOutstandingOp;
// {supported_types_} is updated in {MaybeBailoutForUnsupportedType}.
base::EnumSet<ValueKind> supported_types_ = kUnconditionallySupported;
compiler::CallDescriptor* const descriptor_;
CompilationEnv* const env_;
DebugSideTableBuilder* const debug_sidetable_builder_;
......@@ -6135,6 +6150,13 @@ class LiftoffCompiler {
DISALLOW_IMPLICIT_CONSTRUCTORS(LiftoffCompiler);
};
// static
constexpr WasmOpcode LiftoffCompiler::kNoOutstandingOp;
// static
constexpr base::EnumSet<ValueKind> LiftoffCompiler::kUnconditionallySupported;
// static
constexpr base::EnumSet<ValueKind> LiftoffCompiler::kExternRefSupported;
} // namespace
WasmCompilationResult ExecuteLiftoffCompilation(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment