Commit a87eefc8 authored by Ross McIlroy's avatar Ross McIlroy Committed by V8 LUCI CQ

[Interpreter] Optimize IsWithoutExternalSideEffects check

Order the bytecodes to enable range-based checks for
IsWithoutExternalSideEffects. Also remove the now unecessary
macro definitions for Jump bytecodes.

BUG=v8:9684

Change-Id: Id2d7e2e0141b57864c65a752bc233f004f86f760
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2875208
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74397}
parent 13a89b00
...@@ -68,7 +68,9 @@ namespace interpreter { ...@@ -68,7 +68,9 @@ namespace interpreter {
OperandType::kRuntimeId, OperandType::kReg, OperandType::kReg, \ OperandType::kRuntimeId, OperandType::kReg, OperandType::kReg, \
OperandType::kReg) \ OperandType::kReg) \
\ \
/* Loading the accumulator */ \ /* Side-effect-free bytecodes -- carefully ordered for efficient checks */ \
/* - [Loading the accumulator] */ \
V(Ldar, ImplicitRegisterUse::kWriteAccumulator, OperandType::kReg) \
V(LdaZero, ImplicitRegisterUse::kWriteAccumulator) \ V(LdaZero, ImplicitRegisterUse::kWriteAccumulator) \
V(LdaSmi, ImplicitRegisterUse::kWriteAccumulator, OperandType::kImm) \ V(LdaSmi, ImplicitRegisterUse::kWriteAccumulator, OperandType::kImm) \
V(LdaUndefined, ImplicitRegisterUse::kWriteAccumulator) \ V(LdaUndefined, ImplicitRegisterUse::kWriteAccumulator) \
...@@ -77,6 +79,27 @@ namespace interpreter { ...@@ -77,6 +79,27 @@ namespace interpreter {
V(LdaTrue, ImplicitRegisterUse::kWriteAccumulator) \ V(LdaTrue, ImplicitRegisterUse::kWriteAccumulator) \
V(LdaFalse, ImplicitRegisterUse::kWriteAccumulator) \ V(LdaFalse, ImplicitRegisterUse::kWriteAccumulator) \
V(LdaConstant, ImplicitRegisterUse::kWriteAccumulator, OperandType::kIdx) \ V(LdaConstant, ImplicitRegisterUse::kWriteAccumulator, OperandType::kIdx) \
V(LdaContextSlot, ImplicitRegisterUse::kWriteAccumulator, OperandType::kReg, \
OperandType::kIdx, OperandType::kUImm) \
V(LdaImmutableContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kReg, OperandType::kIdx, OperandType::kUImm) \
V(LdaCurrentContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx) \
V(LdaImmutableCurrentContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx) \
/* - [Register Loads ] */ \
V(Star, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \
V(Mov, ImplicitRegisterUse::kNone, OperandType::kReg, OperandType::kRegOut) \
V(PushContext, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \
V(PopContext, ImplicitRegisterUse::kNone, OperandType::kReg) \
/* - [Test Operations ] */ \
V(TestReferenceEqual, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kReg) \
V(TestUndetectable, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestNull, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestUndefined, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestTypeOf, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kFlag8) \
\ \
/* Globals */ \ /* Globals */ \
V(LdaGlobal, ImplicitRegisterUse::kWriteAccumulator, OperandType::kIdx, \ V(LdaGlobal, ImplicitRegisterUse::kWriteAccumulator, OperandType::kIdx, \
...@@ -87,16 +110,6 @@ namespace interpreter { ...@@ -87,16 +110,6 @@ namespace interpreter {
OperandType::kIdx) \ OperandType::kIdx) \
\ \
/* Context operations */ \ /* Context operations */ \
V(PushContext, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \
V(PopContext, ImplicitRegisterUse::kNone, OperandType::kReg) \
V(LdaContextSlot, ImplicitRegisterUse::kWriteAccumulator, OperandType::kReg, \
OperandType::kIdx, OperandType::kUImm) \
V(LdaImmutableContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kReg, OperandType::kIdx, OperandType::kUImm) \
V(LdaCurrentContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx) \
V(LdaImmutableCurrentContextSlot, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx) \
V(StaContextSlot, ImplicitRegisterUse::kReadAccumulator, OperandType::kReg, \ V(StaContextSlot, ImplicitRegisterUse::kReadAccumulator, OperandType::kReg, \
OperandType::kIdx, OperandType::kUImm) \ OperandType::kIdx, OperandType::kUImm) \
V(StaCurrentContextSlot, ImplicitRegisterUse::kReadAccumulator, \ V(StaCurrentContextSlot, ImplicitRegisterUse::kReadAccumulator, \
...@@ -117,13 +130,6 @@ namespace interpreter { ...@@ -117,13 +130,6 @@ namespace interpreter {
V(StaLookupSlot, ImplicitRegisterUse::kReadWriteAccumulator, \ V(StaLookupSlot, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kIdx, OperandType::kFlag8) \ OperandType::kIdx, OperandType::kFlag8) \
\ \
/* Register-accumulator transfers */ \
V(Ldar, ImplicitRegisterUse::kWriteAccumulator, OperandType::kReg) \
V(Star, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \
\
/* Register-register transfers */ \
V(Mov, ImplicitRegisterUse::kNone, OperandType::kReg, OperandType::kRegOut) \
\
/* Property loads (LoadIC) operations */ \ /* Property loads (LoadIC) operations */ \
V(LdaNamedProperty, ImplicitRegisterUse::kWriteAccumulator, \ V(LdaNamedProperty, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kReg, OperandType::kIdx, OperandType::kIdx) \ OperandType::kReg, OperandType::kIdx, OperandType::kIdx) \
...@@ -272,7 +278,7 @@ namespace interpreter { ...@@ -272,7 +278,7 @@ namespace interpreter {
OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, \ OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, \
OperandType::kIdx) \ OperandType::kIdx) \
\ \
/* Test Operators */ \ /* Effectful Test Operators */ \
V(TestEqual, ImplicitRegisterUse::kReadWriteAccumulator, OperandType::kReg, \ V(TestEqual, ImplicitRegisterUse::kReadWriteAccumulator, OperandType::kReg, \
OperandType::kIdx) \ OperandType::kIdx) \
V(TestEqualStrict, ImplicitRegisterUse::kReadWriteAccumulator, \ V(TestEqualStrict, ImplicitRegisterUse::kReadWriteAccumulator, \
...@@ -285,17 +291,10 @@ namespace interpreter { ...@@ -285,17 +291,10 @@ namespace interpreter {
OperandType::kReg, OperandType::kIdx) \ OperandType::kReg, OperandType::kIdx) \
V(TestGreaterThanOrEqual, ImplicitRegisterUse::kReadWriteAccumulator, \ V(TestGreaterThanOrEqual, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kReg, OperandType::kIdx) \ OperandType::kReg, OperandType::kIdx) \
V(TestReferenceEqual, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kReg) \
V(TestInstanceOf, ImplicitRegisterUse::kReadWriteAccumulator, \ V(TestInstanceOf, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kReg, OperandType::kIdx) \ OperandType::kReg, OperandType::kIdx) \
V(TestIn, ImplicitRegisterUse::kReadWriteAccumulator, OperandType::kReg, \ V(TestIn, ImplicitRegisterUse::kReadWriteAccumulator, OperandType::kReg, \
OperandType::kIdx) \ OperandType::kIdx) \
V(TestUndetectable, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestNull, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestUndefined, ImplicitRegisterUse::kReadWriteAccumulator) \
V(TestTypeOf, ImplicitRegisterUse::kReadWriteAccumulator, \
OperandType::kFlag8) \
\ \
/* Cast operators */ \ /* Cast operators */ \
V(ToName, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \ V(ToName, ImplicitRegisterUse::kReadAccumulator, OperandType::kRegOut) \
...@@ -650,25 +649,18 @@ class V8_EXPORT_PRIVATE Bytecodes final : public AllStatic { ...@@ -650,25 +649,18 @@ class V8_EXPORT_PRIVATE Bytecodes final : public AllStatic {
// Return true if |bytecode| is an accumulator load without effects, // Return true if |bytecode| is an accumulator load without effects,
// e.g. LdaConstant, LdaTrue, Ldar. // e.g. LdaConstant, LdaTrue, Ldar.
static constexpr bool IsAccumulatorLoadWithoutEffects(Bytecode bytecode) { static constexpr bool IsAccumulatorLoadWithoutEffects(Bytecode bytecode) {
return bytecode == Bytecode::kLdar || bytecode == Bytecode::kLdaZero || CONSTEXPR_DCHECK(Bytecode::kLdar <
bytecode == Bytecode::kLdaSmi || bytecode == Bytecode::kLdaNull || Bytecode::kLdaImmutableCurrentContextSlot);
bytecode == Bytecode::kLdaTrue || bytecode == Bytecode::kLdaFalse || return bytecode >= Bytecode::kLdar &&
bytecode == Bytecode::kLdaUndefined || bytecode <= Bytecode::kLdaImmutableCurrentContextSlot;
bytecode == Bytecode::kLdaTheHole ||
bytecode == Bytecode::kLdaConstant ||
bytecode == Bytecode::kLdaContextSlot ||
bytecode == Bytecode::kLdaCurrentContextSlot ||
bytecode == Bytecode::kLdaImmutableContextSlot ||
bytecode == Bytecode::kLdaImmutableCurrentContextSlot;
} }
// Returns true if |bytecode| is a compare operation without external effects // Returns true if |bytecode| is a compare operation without external effects
// (e.g., Type cooersion). // (e.g., Type cooersion).
static constexpr bool IsCompareWithoutEffects(Bytecode bytecode) { static constexpr bool IsCompareWithoutEffects(Bytecode bytecode) {
return bytecode == Bytecode::kTestUndetectable || CONSTEXPR_DCHECK(Bytecode::kTestReferenceEqual < Bytecode::kTestTypeOf);
bytecode == Bytecode::kTestNull || return bytecode >= Bytecode::kTestReferenceEqual &&
bytecode == Bytecode::kTestUndefined || bytecode <= Bytecode::kTestTypeOf;
bytecode == Bytecode::kTestTypeOf;
} }
static constexpr bool IsShortStar(Bytecode bytecode) { static constexpr bool IsShortStar(Bytecode bytecode) {
...@@ -683,8 +675,8 @@ class V8_EXPORT_PRIVATE Bytecodes final : public AllStatic { ...@@ -683,8 +675,8 @@ class V8_EXPORT_PRIVATE Bytecodes final : public AllStatic {
// Return true if |bytecode| is a register load without effects, // Return true if |bytecode| is a register load without effects,
// e.g. Mov, Star. // e.g. Mov, Star.
static constexpr bool IsRegisterLoadWithoutEffects(Bytecode bytecode) { static constexpr bool IsRegisterLoadWithoutEffects(Bytecode bytecode) {
return bytecode == Bytecode::kMov || bytecode == Bytecode::kPopContext || return IsShortStar(bytecode) ||
bytecode == Bytecode::kPushContext || IsAnyStar(bytecode); (bytecode >= Bytecode::kStar && bytecode <= Bytecode::kPopContext);
} }
// Returns true if the bytecode is a conditional jump taking // Returns true if the bytecode is a conditional jump taking
......
...@@ -118,14 +118,14 @@ bytecodes: [ ...@@ -118,14 +118,14 @@ bytecodes: [
/* 90 S> */ B(LdaImmutableCurrentContextSlot), U8(2), /* 90 S> */ B(LdaImmutableCurrentContextSlot), U8(2),
B(Star1), B(Star1),
B(LdaCurrentContextSlot), U8(3), B(LdaCurrentContextSlot), U8(3),
/* 94 E> */ B(TestReferenceEqual), R(this), B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0), B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16), B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(272), B(Wide), B(LdaSmi), I16(272),
B(Star2), B(Star2),
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star3), B(Star3),
B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2), /* 94 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2),
B(Throw), B(Throw),
B(CallRuntime), U16(Runtime::kLoadPrivateGetter), R(1), U8(1), B(CallRuntime), U16(Runtime::kLoadPrivateGetter), R(1), U8(1),
B(Star2), B(Star2),
...@@ -140,14 +140,14 @@ bytecodes: [ ...@@ -140,14 +140,14 @@ bytecodes: [
B(LdaImmutableCurrentContextSlot), U8(2), B(LdaImmutableCurrentContextSlot), U8(2),
B(Star2), B(Star2),
B(LdaCurrentContextSlot), U8(3), B(LdaCurrentContextSlot), U8(3),
/* 109 E> */ B(TestReferenceEqual), R(this), B(TestReferenceEqual), R(this),
B(Mov), R(this), R(1), B(Mov), R(this), R(1),
B(JumpIfTrue), U8(16), B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(273), B(Wide), B(LdaSmi), I16(273),
B(Star3), B(Star3),
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star4), B(Star4),
B(CallRuntime), U16(Runtime::kNewTypeError), R(3), U8(2), /* 109 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(3), U8(2),
B(Throw), B(Throw),
B(CallRuntime), U16(Runtime::kLoadPrivateSetter), R(2), U8(1), B(CallRuntime), U16(Runtime::kLoadPrivateSetter), R(2), U8(1),
B(Star3), B(Star3),
...@@ -155,14 +155,14 @@ bytecodes: [ ...@@ -155,14 +155,14 @@ bytecodes: [
/* 122 S> */ B(LdaImmutableCurrentContextSlot), U8(2), /* 122 S> */ B(LdaImmutableCurrentContextSlot), U8(2),
B(Star1), B(Star1),
B(LdaCurrentContextSlot), U8(3), B(LdaCurrentContextSlot), U8(3),
/* 133 E> */ B(TestReferenceEqual), R(this), B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0), B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16), B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(272), B(Wide), B(LdaSmi), I16(272),
B(Star2), B(Star2),
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star3), B(Star3),
B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2), /* 133 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2),
B(Throw), B(Throw),
B(CallRuntime), U16(Runtime::kLoadPrivateGetter), R(1), U8(1), B(CallRuntime), U16(Runtime::kLoadPrivateGetter), R(1), U8(1),
B(Star2), B(Star2),
......
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