Commit d3ba602f authored by Patrick Thier's avatar Patrick Thier Committed by V8 LUCI CQ

[regexp][interpreter] Extend RegExp-Flags to 2 Bytes

In preparation for the new `v`-flag, extend RegExp flags from 1-byte to
2-byte.

Bug: v8:11935
Change-Id: I2dacb5e8dba889947054aa5c155708b8d315b898
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3857561Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82863}
parent 46d54b02
......@@ -402,8 +402,11 @@ int32_t BaselineCompiler::Int(int operand_index) {
uint32_t BaselineCompiler::Index(int operand_index) {
return iterator().GetIndexOperand(operand_index);
}
uint32_t BaselineCompiler::Flag(int operand_index) {
return iterator().GetFlagOperand(operand_index);
uint32_t BaselineCompiler::Flag8(int operand_index) {
return iterator().GetFlag8Operand(operand_index);
}
uint32_t BaselineCompiler::Flag16(int operand_index) {
return iterator().GetFlag16Operand(operand_index);
}
uint32_t BaselineCompiler::RegisterCount(int operand_index) {
return iterator().GetRegisterCountOperand(operand_index);
......@@ -420,8 +423,11 @@ Smi BaselineCompiler::IndexAsSmi(int operand_index) {
Smi BaselineCompiler::IntAsSmi(int operand_index) {
return Smi::FromInt(Int(operand_index));
}
Smi BaselineCompiler::FlagAsSmi(int operand_index) {
return Smi::FromInt(Flag(operand_index));
Smi BaselineCompiler::Flag8AsSmi(int operand_index) {
return Smi::FromInt(Flag8(operand_index));
}
Smi BaselineCompiler::Flag16AsSmi(int operand_index) {
return Smi::FromInt(Flag16(operand_index));
}
MemOperand BaselineCompiler::FeedbackVector() {
......@@ -808,7 +814,7 @@ void BaselineCompiler::VisitLdaLookupGlobalSlotInsideTypeof() {
}
void BaselineCompiler::VisitStaLookupSlot() {
uint32_t flags = Flag(1);
uint32_t flags = Flag8(1);
Runtime::FunctionId function_id;
if (flags & interpreter::StoreLookupSlotFlags::LanguageModeBit::kMask) {
function_id = Runtime::kStoreLookupSlot_Strict;
......@@ -958,7 +964,7 @@ void BaselineCompiler::VisitDefineKeyedOwnPropertyInLiteral() {
RegisterOperand(0), // object
RegisterOperand(1), // name
kInterpreterAccumulatorRegister, // value
FlagAsSmi(2), // flags
Flag8AsSmi(2), // flags
FeedbackVector(), // feedback vector
IndexAsTagged(3)); // slot
}
......@@ -1551,7 +1557,7 @@ void BaselineCompiler::VisitTestTypeOf() {
BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_);
auto literal_flag =
static_cast<interpreter::TestTypeOfFlags::LiteralFlag>(Flag(0));
static_cast<interpreter::TestTypeOfFlags::LiteralFlag>(Flag8(0));
Label done;
switch (literal_flag) {
......@@ -1750,11 +1756,11 @@ void BaselineCompiler::VisitCreateRegExpLiteral() {
FeedbackVector(), // feedback vector
IndexAsTagged(1), // slot
Constant<HeapObject>(0), // pattern
FlagAsSmi(2)); // flags
Flag16AsSmi(2)); // flags
}
void BaselineCompiler::VisitCreateArrayLiteral() {
uint32_t flags = Flag(2);
uint32_t flags = Flag8(2);
int32_t flags_raw = static_cast<int32_t>(
interpreter::CreateArrayLiteralFlags::FlagsBits::decode(flags));
if (flags &
......@@ -1784,7 +1790,7 @@ void BaselineCompiler::VisitCreateEmptyArrayLiteral() {
}
void BaselineCompiler::VisitCreateObjectLiteral() {
uint32_t flags = Flag(2);
uint32_t flags = Flag8(2);
int32_t flags_raw = static_cast<int32_t>(
interpreter::CreateObjectLiteralFlags::FlagsBits::decode(flags));
if (flags &
......@@ -1808,7 +1814,7 @@ void BaselineCompiler::VisitCreateEmptyObjectLiteral() {
}
void BaselineCompiler::VisitCloneObject() {
uint32_t flags = Flag(1);
uint32_t flags = Flag8(1);
int32_t raw_flags =
interpreter::CreateObjectLiteralFlags::FlagsBits::decode(flags);
CallBuiltin<Builtin::kCloneObjectICBaseline>(
......@@ -1833,7 +1839,7 @@ void BaselineCompiler::VisitCreateClosure() {
LoadClosureFeedbackArray(feedback_cell);
__ LoadFixedArrayElement(feedback_cell, feedback_cell, Index(1));
uint32_t flags = Flag(2);
uint32_t flags = Flag8(2);
if (interpreter::CreateClosureFlags::FastNewClosureBit::decode(flags)) {
CallBuiltin<Builtin::kFastNewClosureBaseline>(
Constant<SharedFunctionInfo>(0), feedback_cell);
......
......@@ -89,13 +89,15 @@ class BaselineCompiler {
uint32_t Uint(int operand_index);
int32_t Int(int operand_index);
uint32_t Index(int operand_index);
uint32_t Flag(int operand_index);
uint32_t Flag8(int operand_index);
uint32_t Flag16(int operand_index);
uint32_t RegisterCount(int operand_index);
TaggedIndex IndexAsTagged(int operand_index);
TaggedIndex UintAsTagged(int operand_index);
Smi IndexAsSmi(int operand_index);
Smi IntAsSmi(int operand_index);
Smi FlagAsSmi(int operand_index);
Smi Flag8AsSmi(int operand_index);
Smi Flag16AsSmi(int operand_index);
// Jump helpers.
Label* NewLabel();
......
......@@ -1650,7 +1650,7 @@ void BytecodeGraphBuilder::VisitDefineKeyedOwnPropertyInLiteral() {
Node* name =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(1));
Node* value = environment()->LookupAccumulator();
int flags = bytecode_iterator().GetFlagOperand(2);
int flags = bytecode_iterator().GetFlag8Operand(2);
FeedbackSource feedback =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(3));
const Operator* op = javascript()->DefineKeyedOwnPropertyInLiteral(feedback);
......@@ -1974,7 +1974,7 @@ void BytecodeGraphBuilder::VisitStaLookupSlot() {
PrepareEagerCheckpoint();
Node* value = environment()->LookupAccumulator();
Node* name = jsgraph()->Constant(MakeRefForConstantForIndexOperand(0));
int bytecode_flags = bytecode_iterator().GetFlagOperand(1);
int bytecode_flags = bytecode_iterator().GetFlag8Operand(1);
LanguageMode language_mode = static_cast<LanguageMode>(
interpreter::StoreLookupSlotFlags::LanguageModeBit::decode(
bytecode_flags));
......@@ -2219,7 +2219,7 @@ void BytecodeGraphBuilder::VisitCreateClosure() {
MakeRefForConstantForIndexOperand<SharedFunctionInfo>(0);
AllocationType allocation =
interpreter::CreateClosureFlags::PretenuredBit::decode(
bytecode_iterator().GetFlagOperand(2))
bytecode_iterator().GetFlag8Operand(2))
? AllocationType::kOld
: AllocationType::kYoung;
CodeTRef compile_lazy =
......@@ -2298,7 +2298,7 @@ void BytecodeGraphBuilder::VisitCreateRegExpLiteral() {
StringRef constant_pattern = MakeRefForConstantForIndexOperand<String>(0);
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int literal_flags = bytecode_iterator().GetFlagOperand(2);
int literal_flags = bytecode_iterator().GetFlag16Operand(2);
static_assert(JSCreateLiteralRegExpNode::FeedbackVectorIndex() == 0);
const Operator* op =
javascript()->CreateLiteralRegExp(constant_pattern, pair, literal_flags);
......@@ -2312,7 +2312,7 @@ void BytecodeGraphBuilder::VisitCreateArrayLiteral() {
MakeRefForConstantForIndexOperand<ArrayBoilerplateDescription>(0);
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int bytecode_flags = bytecode_iterator().GetFlagOperand(2);
int bytecode_flags = bytecode_iterator().GetFlag8Operand(2);
int literal_flags =
interpreter::CreateArrayLiteralFlags::FlagsBits::decode(bytecode_flags);
// Disable allocation site mementos. Only unoptimized code will collect
......@@ -2350,7 +2350,7 @@ void BytecodeGraphBuilder::VisitCreateObjectLiteral() {
MakeRefForConstantForIndexOperand<ObjectBoilerplateDescription>(0);
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int bytecode_flags = bytecode_iterator().GetFlagOperand(2);
int bytecode_flags = bytecode_iterator().GetFlag8Operand(2);
int literal_flags =
interpreter::CreateObjectLiteralFlags::FlagsBits::decode(bytecode_flags);
int number_of_properties = constant_properties.size();
......@@ -2371,7 +2371,7 @@ void BytecodeGraphBuilder::VisitCloneObject() {
PrepareEagerCheckpoint();
Node* source =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
int flags = bytecode_iterator().GetFlagOperand(1);
int flags = bytecode_iterator().GetFlag8Operand(1);
int slot = bytecode_iterator().GetIndexOperand(2);
const Operator* op =
javascript()->CloneObject(CreateFeedbackSource(slot), flags);
......@@ -3347,7 +3347,7 @@ void BytecodeGraphBuilder::VisitTestUndefined() {
void BytecodeGraphBuilder::VisitTestTypeOf() {
Node* object = environment()->LookupAccumulator();
auto literal_flag = interpreter::TestTypeOfFlags::Decode(
bytecode_iterator().GetFlagOperand(0));
bytecode_iterator().GetFlag8Operand(0));
Node* result;
switch (literal_flag) {
case interpreter::TestTypeOfFlags::LiteralFlag::kNumber:
......
......@@ -93,12 +93,18 @@ int32_t BytecodeArrayIterator::GetSignedOperand(
current_operand_scale());
}
uint32_t BytecodeArrayIterator::GetFlagOperand(int operand_index) const {
uint32_t BytecodeArrayIterator::GetFlag8Operand(int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kFlag8);
return GetUnsignedOperand(operand_index, OperandType::kFlag8);
}
uint32_t BytecodeArrayIterator::GetFlag16Operand(int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kFlag16);
return GetUnsignedOperand(operand_index, OperandType::kFlag16);
}
uint32_t BytecodeArrayIterator::GetUnsignedImmediateOperand(
int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
......
......@@ -118,7 +118,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayIterator {
OperandScale current_operand_scale() const { return operand_scale_; }
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
uint32_t GetFlagOperand(int operand_index) const;
uint32_t GetFlag8Operand(int operand_index) const;
uint32_t GetFlag16Operand(int operand_index) const;
uint32_t GetUnsignedImmediateOperand(int operand_index) const;
int32_t GetImmediateOperand(int operand_index) const;
uint32_t GetIndexOperand(int operand_index) const;
......
......@@ -165,6 +165,7 @@ std::ostream& BytecodeDecoder::Decode(std::ostream& os,
<< "]";
break;
case interpreter::OperandType::kFlag8:
case interpreter::OperandType::kFlag16:
os << "#"
<< DecodeUnsignedOperand(operand_start, op_type, operand_scale);
break;
......
......@@ -35,6 +35,7 @@ namespace interpreter {
#define UNSIGNED_FIXED_SCALAR_OPERAND_TYPE_LIST(V) \
V(Flag8, OperandTypeInfo::kFixedUnsignedByte) \
V(Flag16, OperandTypeInfo::kFixedUnsignedShort) \
V(IntrinsicId, OperandTypeInfo::kFixedUnsignedByte) \
V(RuntimeId, OperandTypeInfo::kFixedUnsignedShort) \
V(NativeContextIndex, OperandTypeInfo::kFixedUnsignedByte)
......
......@@ -300,7 +300,7 @@ namespace interpreter {
\
/* Literals */ \
V(CreateRegExpLiteral, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8) \
OperandType::kIdx, OperandType::kIdx, OperandType::kFlag16) \
V(CreateArrayLiteral, ImplicitRegisterUse::kWriteAccumulator, \
OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8) \
V(CreateArrayFromIterable, ImplicitRegisterUse::kReadWriteAccumulator) \
......
......@@ -550,6 +550,16 @@ TNode<Uint32T> InterpreterAssembler::BytecodeOperandFlag(int operand_index) {
return BytecodeUnsignedOperand(operand_index, operand_size);
}
TNode<Uint32T> InterpreterAssembler::BytecodeOperandWideFlag(
int operand_index) {
DCHECK_EQ(OperandType::kFlag16,
Bytecodes::GetOperandType(bytecode_, operand_index));
OperandSize operand_size =
Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
DCHECK_EQ(operand_size, OperandSize::kShort);
return BytecodeUnsignedOperand(operand_index, operand_size);
}
TNode<Uint32T> InterpreterAssembler::BytecodeOperandUImm(int operand_index) {
DCHECK_EQ(OperandType::kUImm,
Bytecodes::GetOperandType(bytecode_, operand_index));
......
......@@ -29,6 +29,9 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
// Returns the 32-bit unsigned flag for bytecode operand |operand_index|
// in the current bytecode.
TNode<Uint32T> BytecodeOperandFlag(int operand_index);
// Returns the 32-bit unsigned 2-byte flag for bytecode operand
// |operand_index| in the current bytecode.
TNode<Uint32T> BytecodeOperandWideFlag(int operand_index);
// Returns the 32-bit zero-extended index immediate for bytecode operand
// |operand_index| in the current bytecode.
TNode<Uint32T> BytecodeOperandIdxInt32(int operand_index);
......
......@@ -2260,7 +2260,7 @@ IGNITION_HANDLER(CreateRegExpLiteral, InterpreterAssembler) {
TNode<HeapObject> feedback_vector = LoadFeedbackVector();
TNode<TaggedIndex> slot = BytecodeOperandIdxTaggedIndex(1);
TNode<Smi> flags =
SmiFromInt32(UncheckedCast<Int32T>(BytecodeOperandFlag(2)));
SmiFromInt32(UncheckedCast<Int32T>(BytecodeOperandWideFlag(2)));
TNode<Context> context = GetContext();
TVARIABLE(JSRegExp, result);
......
......@@ -710,7 +710,8 @@ void MaglevGraphBuilder::VisitTestTypeOf() {
using LiteralFlag = interpreter::TestTypeOfFlags::LiteralFlag;
// TODO(v8:7700): Add a branch version of TestTypeOf that does not need to
// materialise the boolean value.
LiteralFlag literal = interpreter::TestTypeOfFlags::Decode(GetFlagOperand(0));
LiteralFlag literal =
interpreter::TestTypeOfFlags::Decode(GetFlag8Operand(0));
if (literal == LiteralFlag::kOther) {
SetAccumulator(GetRootConstant(RootIndex::kFalseValue));
return;
......@@ -875,7 +876,7 @@ void MaglevGraphBuilder::VisitStaLookupSlot() {
// StaLookupSlot <name_index> <flags>
ValueNode* value = GetAccumulatorTagged();
ValueNode* name = GetConstant(GetRefOperand<Name>(0));
uint32_t flags = GetFlagOperand(1);
uint32_t flags = GetFlag8Operand(1);
SetAccumulator(BuildCallRuntime(StaLookupSlotFunction(flags), {name, value}));
}
......@@ -1410,7 +1411,7 @@ void MaglevGraphBuilder::VisitDefineKeyedOwnPropertyInLiteral() {
ValueNode* object = LoadRegisterTagged(0);
ValueNode* name = LoadRegisterTagged(1);
ValueNode* value = GetAccumulatorTagged();
ValueNode* flags = GetSmiConstant(GetFlagOperand(2));
ValueNode* flags = GetSmiConstant(GetFlag8Operand(2));
ValueNode* slot = GetSmiConstant(GetSlotOperand(3).ToInt());
ValueNode* feedback_vector = GetConstant(feedback());
SetAccumulator(
......@@ -1419,7 +1420,7 @@ void MaglevGraphBuilder::VisitDefineKeyedOwnPropertyInLiteral() {
}
void MaglevGraphBuilder::VisitCollectTypeProfile() {
ValueNode* position = GetSmiConstant(GetFlagOperand(0));
ValueNode* position = GetSmiConstant(GetFlag8Operand(0));
ValueNode* value = GetAccumulatorTagged();
ValueNode* feedback_vector = GetConstant(feedback());
SetAccumulator(BuildCallRuntime(Runtime::kCollectTypeProfile,
......@@ -2160,7 +2161,7 @@ void MaglevGraphBuilder::VisitCreateRegExpLiteral() {
// CreateRegExpLiteral <pattern_idx> <literal_idx> <flags>
compiler::StringRef pattern = GetRefOperand<String>(0);
FeedbackSlot slot = GetSlotOperand(1);
uint32_t flags = GetFlagOperand(2);
uint32_t flags = GetFlag16Operand(2);
compiler::FeedbackSource feedback_source{feedback(), slot};
// TODO(victorgomes): Inline allocation if feedback has a RegExpLiteral.
SetAccumulator(
......@@ -2170,7 +2171,7 @@ void MaglevGraphBuilder::VisitCreateRegExpLiteral() {
void MaglevGraphBuilder::VisitCreateArrayLiteral() {
compiler::HeapObjectRef constant_elements = GetRefOperand<HeapObject>(0);
FeedbackSlot slot_index = GetSlotOperand(1);
int bytecode_flags = GetFlagOperand(2);
int bytecode_flags = GetFlag8Operand(2);
int literal_flags =
interpreter::CreateArrayLiteralFlags::FlagsBits::decode(bytecode_flags);
ValueNode* result;
......@@ -2207,7 +2208,7 @@ void MaglevGraphBuilder::VisitCreateObjectLiteral() {
compiler::ObjectBoilerplateDescriptionRef boilerplate_desc =
GetRefOperand<ObjectBoilerplateDescription>(0);
FeedbackSlot slot_index = GetSlotOperand(1);
int bytecode_flags = GetFlagOperand(2);
int bytecode_flags = GetFlag8Operand(2);
int literal_flags =
interpreter::CreateObjectLiteralFlags::FlagsBits::decode(bytecode_flags);
ValueNode* result;
......@@ -2241,7 +2242,7 @@ void MaglevGraphBuilder::VisitCloneObject() {
ValueNode* source = LoadRegisterTagged(0);
ValueNode* flags =
GetSmiConstant(interpreter::CreateObjectLiteralFlags::FlagsBits::decode(
GetFlagOperand(1)));
GetFlag8Operand(1)));
FeedbackSlot slot = GetSlotOperand(2);
compiler::FeedbackSource feedback_source{feedback(), slot};
SetAccumulator(BuildCallBuiltin<Builtin::kCloneObjectIC>({source, flags},
......@@ -2271,7 +2272,7 @@ void MaglevGraphBuilder::VisitCreateClosure() {
GetRefOperand<SharedFunctionInfo>(0);
compiler::FeedbackCellRef feedback_cell =
feedback().GetClosureFeedbackCell(iterator_.GetIndexOperand(1));
uint32_t flags = GetFlagOperand(2);
uint32_t flags = GetFlag8Operand(2);
if (interpreter::CreateClosureFlags::FastNewClosureBit::decode(flags)) {
SetAccumulator(AddNewNode<FastCreateClosure>(
......@@ -2843,7 +2844,7 @@ void MaglevGraphBuilder::VisitIncBlockCounter() {
}
void MaglevGraphBuilder::VisitAbort() {
AbortReason reason = static_cast<AbortReason>(GetFlagOperand(0));
AbortReason reason = static_cast<AbortReason>(GetFlag8Operand(0));
BuildAbort(reason);
}
......
......@@ -432,8 +432,12 @@ class MaglevGraphBuilder {
return iterator_.GetSlotOperand(operand_index);
}
uint32_t GetFlagOperand(int operand_index) const {
return iterator_.GetFlagOperand(operand_index);
uint32_t GetFlag8Operand(int operand_index) const {
return iterator_.GetFlag8Operand(operand_index);
}
uint32_t GetFlag16Operand(int operand_index) const {
return iterator_.GetFlag16Operand(operand_index);
}
template <class T, typename = std::enable_if_t<
......
......@@ -196,7 +196,11 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
switch (op_type) {
case OperandType::kFlag8:
*stream << 'U' << size_tag << '(';
*stream << bytecode_iterator.GetFlagOperand(op_index);
*stream << bytecode_iterator.GetFlag8Operand(op_index);
break;
case OperandType::kFlag16:
*stream << 'U' << size_tag << '(';
*stream << bytecode_iterator.GetFlag16Operand(op_index);
break;
case OperandType::kIdx: {
*stream << 'U' << size_tag << '(';
......
......@@ -11,9 +11,9 @@ snippet: "
"
frame size: 0
parameter count: 1
bytecode array length: 5
bytecode array length: 6
bytecodes: [
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U8(0),
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U16(0),
/* 48 S> */ B(Return),
]
constant pool: [
......@@ -28,9 +28,9 @@ snippet: "
"
frame size: 0
parameter count: 1
bytecode array length: 5
bytecode array length: 6
bytecodes: [
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U8(2),
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U16(2),
/* 57 S> */ B(Return),
]
constant pool: [
......@@ -45,9 +45,9 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 19
bytecode array length: 20
bytecodes: [
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U8(0),
/* 34 S> */ B(CreateRegExpLiteral), U8(0), U8(0), U16(0),
B(Star1),
/* 48 E> */ B(GetNamedProperty), R(1), U8(1), U8(1),
B(Star0),
......
......@@ -320,6 +320,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
EXPECT_THAT(m.BytecodeOperandFlag(i),
m.IsUnsignedOperand(offset, operand_size));
break;
case interpreter::OperandType::kFlag16:
EXPECT_THAT(m.BytecodeOperandWideFlag(i),
m.IsUnsignedOperand(offset, operand_size));
break;
case interpreter::OperandType::kIdx:
EXPECT_THAT(m.BytecodeOperandIdx(i),
c::IsChangeUint32ToWord(
......
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