Commit 58559fb7 authored by Zhao Jiazhong's avatar Zhao Jiazhong Committed by V8 LUCI CQ

[loong64][mips][regexp] Compact codegen for large character classes

Port commit 8bbb44e5

Bug: v8:11069
Change-Id: I66532e8410390bc220d7811e320bb44181b00d1f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3234303Reviewed-by: 's avatarLiu yu <liuyu@loongson.cn>
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Cr-Commit-Position: refs/heads/main@{#77468}
parent 9e857ef3
......@@ -216,6 +216,21 @@ void RegExpMacroAssemblerLOONG64::CheckGreedyLoop(Label* on_equal) {
BranchOrBacktrack(on_equal, eq, current_input_offset(), Operand(a0));
}
// Push (pop) caller-saved registers used by irregexp.
void RegExpMacroAssemblerLOONG64::PushCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPush(caller_saved_regexp);
}
void RegExpMacroAssemblerLOONG64::PopCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPop(caller_saved_regexp);
}
void RegExpMacroAssemblerLOONG64::CheckNotBackReferenceIgnoreCase(
int start_reg, bool read_backward, bool unicode, Label* on_no_match) {
Label fallthrough;
......@@ -297,11 +312,7 @@ void RegExpMacroAssemblerLOONG64::CheckNotBackReferenceIgnoreCase(
}
} else {
DCHECK(mode_ == UC16);
// Put regexp engine registers on stack.
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() |
backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
int argument_count = 4;
__ PrepareCallCFunction(argument_count, a2);
......@@ -339,8 +350,7 @@ void RegExpMacroAssemblerLOONG64::CheckNotBackReferenceIgnoreCase(
__ CallCFunction(function, argument_count);
}
// Restore regexp engine registers.
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()), CONSTANT_SIZE);
__ Ld_d(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd));
......@@ -461,6 +471,41 @@ void RegExpMacroAssemblerLOONG64::CheckCharacterNotInRange(
BranchOrBacktrack(on_not_in_range, hi, a0, Operand(to - from));
}
void RegExpMacroAssemblerLOONG64::CallIsCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges) {
static const int kNumArguments = 3;
PushCallerSavedRegisters();
__ PrepareCallCFunction(kNumArguments, a0);
__ mov(a0, current_character());
__ li(a1, Operand(GetOrAddRangeArray(ranges)));
__ li(a2, Operand(ExternalReference::isolate_address(isolate())));
{
// We have a frame (set up in GetCode), but the assembler doesn't know.
FrameScope scope(masm_.get(), StackFrame::MANUAL);
__ CallCFunction(ExternalReference::re_is_character_in_range_array(),
kNumArguments);
}
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()));
}
bool RegExpMacroAssemblerLOONG64::CheckCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_in_range, ne, a0, Operand(zero_reg));
return true;
}
bool RegExpMacroAssemblerLOONG64::CheckCharacterNotInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_not_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_not_in_range, eq, a0, Operand(zero_reg));
return true;
}
void RegExpMacroAssemblerLOONG64::CheckBitInTable(Handle<ByteArray> table,
Label* on_bit_set) {
__ li(a0, Operand(table));
......@@ -878,12 +923,9 @@ Handle<HeapObject> RegExpMacroAssemblerLOONG64::GetCode(Handle<String> source) {
// Put regexp engine registers on stack.
StoreRegExpStackPointerToMemory(backtrack_stackpointer(), a1);
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() |
backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
CallCheckStackGuardState(a0);
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
// If returning non-zero, we should end execution with the given
// result as return value.
__ Branch(&return_v0, ne, a0, Operand(zero_reg));
......
......@@ -47,6 +47,10 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerLOONG64
Label* on_in_range) override;
void CheckCharacterNotInRange(base::uc16 from, base::uc16 to,
Label* on_not_in_range) override;
bool CheckCharacterInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_in_range) override;
bool CheckCharacterNotInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_not_in_range) override;
void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set) override;
// Checks whether the given offset from the current position is before
......@@ -129,6 +133,9 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerLOONG64
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
void PushCallerSavedRegisters();
void PopCallerSavedRegisters();
// Check whether preemption has been requested.
void CheckPreemption();
......@@ -137,6 +144,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerLOONG64
// Generate a call to CheckStackGuardState.
void CallCheckStackGuardState(Register scratch);
void CallIsCharacterInRangeArray(const ZoneList<CharacterRange>* ranges);
// The ebp-relative location of a regexp register.
MemOperand register_location(int register_index);
......
......@@ -223,6 +223,21 @@ void RegExpMacroAssemblerMIPS::CheckGreedyLoop(Label* on_equal) {
BranchOrBacktrack(on_equal, eq, current_input_offset(), Operand(a0));
}
// Push (pop) caller-saved registers used by irregexp.
void RegExpMacroAssemblerMIPS::PushCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPush(caller_saved_regexp);
}
void RegExpMacroAssemblerMIPS::PopCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPop(caller_saved_regexp);
}
void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
int start_reg, bool read_backward, bool unicode, Label* on_no_match) {
Label fallthrough;
......@@ -303,10 +318,7 @@ void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
}
} else {
DCHECK_EQ(UC16, mode_);
// Put regexp engine registers on stack.
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() | backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
int argument_count = 4;
__ PrepareCallCFunction(argument_count, a2);
......@@ -345,7 +357,7 @@ void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
}
// Restore regexp engine registers.
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()), CONSTANT_SIZE);
__ lw(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd));
......@@ -476,6 +488,41 @@ void RegExpMacroAssemblerMIPS::CheckCharacterNotInRange(
BranchOrBacktrack(on_not_in_range, hi, a0, Operand(to - from));
}
void RegExpMacroAssemblerMIPS::CallIsCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges) {
static const int kNumArguments = 3;
PushCallerSavedRegisters();
__ PrepareCallCFunction(kNumArguments, a0);
__ mov(a0, current_character());
__ li(a1, Operand(GetOrAddRangeArray(ranges)));
__ li(a2, Operand(ExternalReference::isolate_address(isolate())));
{
// We have a frame (set up in GetCode), but the assembler doesn't know.
FrameScope scope(masm_.get(), StackFrame::MANUAL);
__ CallCFunction(ExternalReference::re_is_character_in_range_array(),
kNumArguments);
}
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()));
}
bool RegExpMacroAssemblerMIPS::CheckCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_in_range, ne, v0, Operand(zero_reg));
return true;
}
bool RegExpMacroAssemblerMIPS::CheckCharacterNotInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_not_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_not_in_range, eq, v0, Operand(zero_reg));
return true;
}
void RegExpMacroAssemblerMIPS::CheckBitInTable(
Handle<ByteArray> table,
Label* on_bit_set) {
......@@ -886,12 +933,9 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) {
if (check_preempt_label_.is_linked()) {
SafeCallTarget(&check_preempt_label_);
StoreRegExpStackPointerToMemory(backtrack_stackpointer(), a0);
// Put regexp engine registers on stack.
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() | backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
CallCheckStackGuardState(a0);
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
// If returning non-zero, we should end execution with the given
// result as return value.
__ Branch(&return_v0, ne, v0, Operand(zero_reg));
......
......@@ -47,6 +47,10 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
Label* on_in_range) override;
void CheckCharacterNotInRange(base::uc16 from, base::uc16 to,
Label* on_not_in_range) override;
bool CheckCharacterInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_in_range) override;
bool CheckCharacterNotInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_not_in_range) override;
void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set) override;
// Checks whether the given offset from the current position is before
......@@ -125,6 +129,9 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
void PushCallerSavedRegisters();
void PopCallerSavedRegisters();
// Check whether preemption has been requested.
void CheckPreemption();
......@@ -133,6 +140,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Generate a call to CheckStackGuardState.
void CallCheckStackGuardState(Register scratch);
void CallIsCharacterInRangeArray(const ZoneList<CharacterRange>* ranges);
// The ebp-relative location of a regexp register.
MemOperand register_location(int register_index);
......
......@@ -261,6 +261,21 @@ void RegExpMacroAssemblerMIPS::CheckGreedyLoop(Label* on_equal) {
BranchOrBacktrack(on_equal, eq, current_input_offset(), Operand(a0));
}
// Push (pop) caller-saved registers used by irregexp.
void RegExpMacroAssemblerMIPS::PushCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPush(caller_saved_regexp);
}
void RegExpMacroAssemblerMIPS::PopCallerSavedRegisters() {
RegList caller_saved_regexp =
current_input_offset().bit() | current_character().bit() |
end_of_input_address().bit() | backtrack_stackpointer().bit();
__ MultiPop(caller_saved_regexp);
}
void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
int start_reg, bool read_backward, bool unicode, Label* on_no_match) {
Label fallthrough;
......@@ -341,10 +356,7 @@ void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
}
} else {
DCHECK(mode_ == UC16);
// Put regexp engine registers on stack.
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() | backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
int argument_count = 4;
__ PrepareCallCFunction(argument_count, a2);
......@@ -382,8 +394,7 @@ void RegExpMacroAssemblerMIPS::CheckNotBackReferenceIgnoreCase(
__ CallCFunction(function, argument_count);
}
// Restore regexp engine registers.
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()), CONSTANT_SIZE);
__ Ld(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd));
......@@ -508,6 +519,41 @@ void RegExpMacroAssemblerMIPS::CheckCharacterNotInRange(
BranchOrBacktrack(on_not_in_range, hi, a0, Operand(to - from));
}
void RegExpMacroAssemblerMIPS::CallIsCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges) {
static const int kNumArguments = 3;
PushCallerSavedRegisters();
__ PrepareCallCFunction(kNumArguments, a0);
__ mov(a0, current_character());
__ li(a1, Operand(GetOrAddRangeArray(ranges)));
__ li(a2, Operand(ExternalReference::isolate_address(isolate())));
{
// We have a frame (set up in GetCode), but the assembler doesn't know.
FrameScope scope(masm_.get(), StackFrame::MANUAL);
__ CallCFunction(ExternalReference::re_is_character_in_range_array(),
kNumArguments);
}
PopCallerSavedRegisters();
__ li(code_pointer(), Operand(masm_->CodeObject()));
}
bool RegExpMacroAssemblerMIPS::CheckCharacterInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_in_range, ne, v0, Operand(zero_reg));
return true;
}
bool RegExpMacroAssemblerMIPS::CheckCharacterNotInRangeArray(
const ZoneList<CharacterRange>* ranges, Label* on_not_in_range) {
CallIsCharacterInRangeArray(ranges);
BranchOrBacktrack(on_not_in_range, eq, v0, Operand(zero_reg));
return true;
}
void RegExpMacroAssemblerMIPS::CheckBitInTable(
Handle<ByteArray> table,
Label* on_bit_set) {
......@@ -925,12 +971,9 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) {
SafeCallTarget(&check_preempt_label_);
StoreRegExpStackPointerToMemory(backtrack_stackpointer(), a0);
// Put regexp engine registers on stack.
RegList regexp_registers_to_retain = current_input_offset().bit() |
current_character().bit() | backtrack_stackpointer().bit();
__ MultiPush(regexp_registers_to_retain);
PushCallerSavedRegisters();
CallCheckStackGuardState(a0);
__ MultiPop(regexp_registers_to_retain);
PopCallerSavedRegisters();
// If returning non-zero, we should end execution with the given
// result as return value.
__ Branch(&return_v0, ne, v0, Operand(zero_reg));
......
......@@ -47,6 +47,10 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
Label* on_in_range) override;
void CheckCharacterNotInRange(base::uc16 from, base::uc16 to,
Label* on_not_in_range) override;
bool CheckCharacterInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_in_range) override;
bool CheckCharacterNotInRangeArray(const ZoneList<CharacterRange>* ranges,
Label* on_not_in_range) override;
void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set) override;
// Checks whether the given offset from the current position is before
......@@ -130,6 +134,9 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
void PushCallerSavedRegisters();
void PopCallerSavedRegisters();
// Check whether preemption has been requested.
void CheckPreemption();
......@@ -139,6 +146,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Generate a call to CheckStackGuardState.
void CallCheckStackGuardState(Register scratch);
void CallIsCharacterInRangeArray(const ZoneList<CharacterRange>* ranges);
// The ebp-relative location of a regexp register.
MemOperand register_location(int register_index);
......
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