Commit 12ecb4f5 authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

[regexp] Various refactors

No functional changes.

- Removed unused Isolate* argument from regexp extrefs.
- Added const where possible.
- Removed unused functions.
- Shuffled declarations for better readability.
- ...

Change-Id: I6d9093052e8de4e33e9411541a691d0bab7b20c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3217193
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPatrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77316}
parent 3e9ba672
......@@ -296,12 +296,6 @@ struct IsValidExternalReferenceType<Result (Class::*)(Args...)> {
return ExternalReference(Redirect(FUNCTION_ADDR(Target))); \
}
#define FUNCTION_REFERENCE_WITH_ISOLATE(Name, Target) \
ExternalReference ExternalReference::Name(Isolate* isolate) { \
STATIC_ASSERT(IsValidExternalReferenceType<decltype(&Target)>::value); \
return ExternalReference(Redirect(FUNCTION_ADDR(Target))); \
}
#define FUNCTION_REFERENCE_WITH_TYPE(Name, Target, Type) \
ExternalReference ExternalReference::Name() { \
STATIC_ASSERT(IsValidExternalReferenceType<decltype(&Target)>::value); \
......@@ -719,11 +713,10 @@ ExternalReference ExternalReference::invoke_accessor_getter_callback() {
UNREACHABLE();
#endif
FUNCTION_REFERENCE_WITH_ISOLATE(re_check_stack_guard_state, re_stack_check_func)
FUNCTION_REFERENCE(re_check_stack_guard_state, re_stack_check_func)
#undef re_stack_check_func
FUNCTION_REFERENCE_WITH_ISOLATE(re_grow_stack,
NativeRegExpMacroAssembler::GrowStack)
FUNCTION_REFERENCE(re_grow_stack, NativeRegExpMacroAssembler::GrowStack)
FUNCTION_REFERENCE(re_match_for_call_from_js,
IrregexpInterpreter::MatchForCallFromJs)
......@@ -731,15 +724,13 @@ FUNCTION_REFERENCE(re_match_for_call_from_js,
FUNCTION_REFERENCE(re_experimental_match_for_call_from_js,
ExperimentalRegExp::MatchForCallFromJs)
FUNCTION_REFERENCE_WITH_ISOLATE(
re_case_insensitive_compare_unicode,
NativeRegExpMacroAssembler::CaseInsensitiveCompareUnicode)
FUNCTION_REFERENCE(re_case_insensitive_compare_unicode,
NativeRegExpMacroAssembler::CaseInsensitiveCompareUnicode)
FUNCTION_REFERENCE_WITH_ISOLATE(
re_case_insensitive_compare_non_unicode,
NativeRegExpMacroAssembler::CaseInsensitiveCompareNonUnicode)
FUNCTION_REFERENCE(re_case_insensitive_compare_non_unicode,
NativeRegExpMacroAssembler::CaseInsensitiveCompareNonUnicode)
ExternalReference ExternalReference::re_word_character_map(Isolate* isolate) {
ExternalReference ExternalReference::re_word_character_map() {
return ExternalReference(
NativeRegExpMacroAssembler::word_character_map_address());
}
......@@ -1380,7 +1371,6 @@ void abort_with_reason(int reason) {
}
#undef FUNCTION_REFERENCE
#undef FUNCTION_REFERENCE_WITH_ISOLATE
#undef FUNCTION_REFERENCE_WITH_TYPE
} // namespace internal
......
......@@ -77,14 +77,6 @@ class StatsCounter;
V(address_of_static_offsets_vector, "OffsetsVector::static_offsets_vector") \
V(thread_in_wasm_flag_address_address, \
"Isolate::thread_in_wasm_flag_address_address") \
V(re_case_insensitive_compare_unicode, \
"NativeRegExpMacroAssembler::CaseInsensitiveCompareUnicode()") \
V(re_case_insensitive_compare_non_unicode, \
"NativeRegExpMacroAssembler::CaseInsensitiveCompareNonUnicode()") \
V(re_check_stack_guard_state, \
"RegExpMacroAssembler*::CheckStackGuardState()") \
V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()") \
V(re_word_character_map, "NativeRegExpMacroAssembler::word_character_map") \
V(javascript_execution_assert, "javascript_execution_assert") \
EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V)
......@@ -292,6 +284,14 @@ class StatsCounter;
"tsan_relaxed_load_function_64_bits") \
V(js_finalization_registry_remove_cell_from_unregister_token_map, \
"JSFinalizationRegistry::RemoveCellFromUnregisterTokenMap") \
V(re_case_insensitive_compare_unicode, \
"RegExpMacroAssembler::CaseInsensitiveCompareUnicode()") \
V(re_case_insensitive_compare_non_unicode, \
"RegExpMacroAssembler::CaseInsensitiveCompareNonUnicode()") \
V(re_check_stack_guard_state, \
"RegExpMacroAssembler*::CheckStackGuardState()") \
V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()") \
V(re_word_character_map, "NativeRegExpMacroAssembler::word_character_map") \
V(re_match_for_call_from_js, "IrregexpInterpreter::MatchForCallFromJs") \
V(re_experimental_match_for_call_from_js, \
"ExperimentalRegExp::MatchForCallFromJs") \
......
......@@ -336,10 +336,9 @@ void RegExpMacroAssemblerARM::CheckNotBackReferenceIgnoreCase(
{
AllowExternalCallThatCantCauseGC scope(masm_.get());
ExternalReference function =
unicode ? ExternalReference::re_case_insensitive_compare_unicode(
isolate())
: ExternalReference::re_case_insensitive_compare_non_unicode(
isolate());
unicode
? ExternalReference::re_case_insensitive_compare_unicode()
: ExternalReference::re_case_insensitive_compare_non_unicode();
__ CallCFunction(function, argument_count);
}
......@@ -577,7 +576,7 @@ bool RegExpMacroAssemblerARM::CheckSpecialCharacterClass(base::uc16 type,
__ cmp(current_character(), Operand('z'));
BranchOrBacktrack(hi, on_no_match);
}
ExternalReference map = ExternalReference::re_word_character_map(isolate());
ExternalReference map = ExternalReference::re_word_character_map();
__ mov(r0, Operand(map));
__ ldrb(r0, MemOperand(r0, current_character()));
__ cmp(r0, Operand::Zero());
......@@ -591,7 +590,7 @@ bool RegExpMacroAssemblerARM::CheckSpecialCharacterClass(base::uc16 type,
__ cmp(current_character(), Operand('z'));
__ b(hi, &done);
}
ExternalReference map = ExternalReference::re_word_character_map(isolate());
ExternalReference map = ExternalReference::re_word_character_map();
__ mov(r0, Operand(map));
__ ldrb(r0, MemOperand(r0, current_character()));
__ cmp(r0, Operand::Zero());
......@@ -931,8 +930,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
static constexpr int kNumArguments = 1;
__ PrepareCallCFunction(kNumArguments);
__ mov(r0, Operand(ExternalReference::isolate_address(isolate())));
ExternalReference grow_stack =
ExternalReference::re_grow_stack(isolate());
ExternalReference grow_stack = ExternalReference::re_grow_stack();
__ CallCFunction(grow_stack, kNumArguments);
// If nullptr is returned, we have failed to grow the stack, and must exit
// with a stack-overflow exception.
......@@ -1127,7 +1125,7 @@ void RegExpMacroAssemblerARM::CallCheckStackGuardState() {
__ mov(r0, sp);
ExternalReference stack_guard_check =
ExternalReference::re_check_stack_guard_state(isolate());
ExternalReference::re_check_stack_guard_state();
__ mov(ip, Operand(stack_guard_check));
EmbeddedData d = EmbeddedData::FromBlob();
......
......@@ -425,10 +425,9 @@ void RegExpMacroAssemblerARM64::CheckNotBackReferenceIgnoreCase(
{
AllowExternalCallThatCantCauseGC scope(masm_.get());
ExternalReference function =
unicode ? ExternalReference::re_case_insensitive_compare_unicode(
isolate())
: ExternalReference::re_case_insensitive_compare_non_unicode(
isolate());
unicode
? ExternalReference::re_case_insensitive_compare_unicode()
: ExternalReference::re_case_insensitive_compare_non_unicode();
__ CallCFunction(function, argument_count);
}
......@@ -663,7 +662,7 @@ bool RegExpMacroAssemblerARM64::CheckSpecialCharacterClass(base::uc16 type,
// Table is 256 entries, so all Latin1 characters can be tested.
CompareAndBranchOrBacktrack(current_character(), 'z', hi, on_no_match);
}
ExternalReference map = ExternalReference::re_word_character_map(isolate());
ExternalReference map = ExternalReference::re_word_character_map();
__ Mov(x10, map);
__ Ldrb(w10, MemOperand(x10, current_character(), UXTW));
CompareAndBranchOrBacktrack(w10, 0, eq, on_no_match);
......@@ -676,7 +675,7 @@ bool RegExpMacroAssemblerARM64::CheckSpecialCharacterClass(base::uc16 type,
__ Cmp(current_character(), 'z');
__ B(hi, &done);
}
ExternalReference map = ExternalReference::re_word_character_map(isolate());
ExternalReference map = ExternalReference::re_word_character_map();
__ Mov(x10, map);
__ Ldrb(w10, MemOperand(x10, current_character(), UXTW));
CompareAndBranchOrBacktrack(w10, 0, ne, on_no_match);
......@@ -1121,8 +1120,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM64::GetCode(Handle<String> source) {
// Call GrowStack(isolate)
static constexpr int kNumArguments = 1;
__ Mov(x0, ExternalReference::isolate_address(isolate()));
__ CallCFunction(ExternalReference::re_grow_stack(isolate()),
kNumArguments);
__ CallCFunction(ExternalReference::re_grow_stack(), kNumArguments);
// If return nullptr, we have failed to grow the stack, and must exit with
// a stack-overflow exception. Returning from the regexp code restores the
// stack (sp <- fp) so we don't need to drop the link register from it
......@@ -1447,7 +1445,7 @@ void RegExpMacroAssemblerARM64::CallCheckStackGuardState(Register scratch) {
DCHECK_EQ(scratch, x10);
ExternalReference check_stack_guard_state =
ExternalReference::re_check_stack_guard_state(isolate());
ExternalReference::re_check_stack_guard_state();
__ Mov(scratch, check_stack_guard_state);
__ CallBuiltin(Builtin::kDirectCEntry);
......
......@@ -336,10 +336,9 @@ void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
{
AllowExternalCallThatCantCauseGC scope(masm_.get());
ExternalReference compare =
unicode ? ExternalReference::re_case_insensitive_compare_unicode(
isolate())
: ExternalReference::re_case_insensitive_compare_non_unicode(
isolate());
unicode
? ExternalReference::re_case_insensitive_compare_unicode()
: ExternalReference::re_case_insensitive_compare_non_unicode();
__ CallCFunction(compare, argument_count);
}
// Pop original values before reacting on result value.
......@@ -581,8 +580,7 @@ bool RegExpMacroAssemblerIA32::CheckSpecialCharacterClass(base::uc16 type,
BranchOrBacktrack(above, on_no_match);
}
DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
ExternalReference word_map =
ExternalReference::re_word_character_map(isolate());
ExternalReference word_map = ExternalReference::re_word_character_map();
__ test_b(current_character(),
Operand(current_character(), times_1, word_map.address(),
RelocInfo::EXTERNAL_REFERENCE));
......@@ -597,8 +595,7 @@ bool RegExpMacroAssemblerIA32::CheckSpecialCharacterClass(base::uc16 type,
__ j(above, &done);
}
DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
ExternalReference word_map =
ExternalReference::re_word_character_map(isolate());
ExternalReference word_map = ExternalReference::re_word_character_map();
__ test_b(current_character(),
Operand(current_character(), times_1, word_map.address(),
RelocInfo::EXTERNAL_REFERENCE));
......@@ -969,8 +966,7 @@ Handle<HeapObject> RegExpMacroAssemblerIA32::GetCode(Handle<String> source) {
__ PrepareCallCFunction(kNumArguments, ebx);
__ mov(Operand(esp, 0 * kSystemPointerSize),
Immediate(ExternalReference::isolate_address(isolate())));
__ CallCFunction(ExternalReference::re_grow_stack(isolate()),
kNumArguments);
__ CallCFunction(ExternalReference::re_grow_stack(), kNumArguments);
// If return nullptr, we have failed to grow the stack, and
// must exit with a stack-overflow exception.
__ or_(eax, eax);
......@@ -1151,7 +1147,7 @@ void RegExpMacroAssemblerIA32::CallCheckStackGuardState(Register scratch) {
__ lea(eax, Operand(esp, -kSystemPointerSize));
__ mov(Operand(esp, 0 * kSystemPointerSize), eax);
ExternalReference check_stack_guard =
ExternalReference::re_check_stack_guard_state(isolate());
ExternalReference::re_check_stack_guard_state();
__ CallCFunction(check_stack_guard, num_arguments);
}
......
This diff is collapsed.
......@@ -27,7 +27,7 @@ class V8_EXPORT_PRIVATE RegExpBytecodeGenerator : public RegExpMacroAssembler {
~RegExpBytecodeGenerator() override;
// The byte-code interpreter checks on each push anyway.
int stack_limit_slack() override { return 1; }
bool CanReadUnaligned() override { return false; }
bool CanReadUnaligned() const override { return false; }
void Bind(Label* label) override;
void AdvanceCurrentPosition(int by) override; // Signed cp change.
void PopCurrentPosition() override;
......
......@@ -845,6 +845,11 @@ RegExpNode* RegExpEmpty::ToNode(RegExpCompiler* compiler,
return on_success;
}
RegExpNode* RegExpGroup::ToNode(RegExpCompiler* compiler,
RegExpNode* on_success) {
return body_->ToNode(compiler, on_success);
}
RegExpLookaround::Builder::Builder(bool is_positive, RegExpNode* on_success,
int stack_pointer_register,
int position_register,
......@@ -1116,10 +1121,6 @@ void CharacterRange::AddClassEscape(char type, ZoneList<CharacterRange>* ranges,
}
}
base::Vector<const int> CharacterRange::GetWordBounds() {
return base::Vector<const int>(kWordRanges, kWordRangeCount - 1);
}
// static
void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone,
ZoneList<CharacterRange>* ranges,
......
......@@ -18,7 +18,9 @@ class RegExpMacroAssemblerTracer: public RegExpMacroAssembler {
~RegExpMacroAssemblerTracer() override;
void AbortedCodeGeneration() override;
int stack_limit_slack() override { return assembler_->stack_limit_slack(); }
bool CanReadUnaligned() override { return assembler_->CanReadUnaligned(); }
bool CanReadUnaligned() const override {
return assembler_->CanReadUnaligned();
}
void AdvanceCurrentPosition(int by) override; // Signed cp change.
void AdvanceRegister(int reg, int by) override; // r[reg] += by.
void Backtrack() override;
......
......@@ -28,12 +28,11 @@ RegExpMacroAssembler::RegExpMacroAssembler(Isolate* isolate, Zone* zone)
isolate_(isolate),
zone_(zone) {}
RegExpMacroAssembler::~RegExpMacroAssembler() = default;
bool RegExpMacroAssembler::has_backtrack_limit() const {
return backtrack_limit_ != JSRegExp::kNoBacktrackLimit;
}
// static
int RegExpMacroAssembler::CaseInsensitiveCompareNonUnicode(Address byte_offset1,
Address byte_offset2,
size_t byte_length,
......@@ -62,6 +61,7 @@ int RegExpMacroAssembler::CaseInsensitiveCompareNonUnicode(Address byte_offset1,
#endif
}
// static
int RegExpMacroAssembler::CaseInsensitiveCompareUnicode(Address byte_offset1,
Address byte_offset2,
size_t byte_length,
......@@ -135,17 +135,6 @@ void RegExpMacroAssembler::LoadCurrentCharacter(int cp_offset,
eats_at_least);
}
bool RegExpMacroAssembler::CheckSpecialCharacterClass(base::uc16 type,
Label* on_no_match) {
return false;
}
NativeRegExpMacroAssembler::NativeRegExpMacroAssembler(Isolate* isolate,
Zone* zone)
: RegExpMacroAssembler(isolate, zone) {}
NativeRegExpMacroAssembler::~NativeRegExpMacroAssembler() = default;
void NativeRegExpMacroAssembler::LoadCurrentCharacterImpl(
int cp_offset, Label* on_end_of_input, bool check_bounds, int characters,
int eats_at_least) {
......@@ -164,13 +153,14 @@ void NativeRegExpMacroAssembler::LoadCurrentCharacterImpl(
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
bool NativeRegExpMacroAssembler::CanReadUnaligned() {
bool NativeRegExpMacroAssembler::CanReadUnaligned() const {
return FLAG_enable_regexp_unaligned_accesses && !slow_safe();
}
#ifndef COMPILING_IRREGEXP_FOR_EXTERNAL_EMBEDDER
// This method may only be called after an interrupt.
// static
int NativeRegExpMacroAssembler::CheckStackGuardState(
Isolate* isolate, int start_index, RegExp::CallOrigin call_origin,
Address* return_address, Code re_code, Address* subject,
......@@ -298,6 +288,15 @@ int NativeRegExpMacroAssembler::Match(Handle<JSRegExp> regexp,
offsets_vector_length, isolate, *regexp);
}
// static
int NativeRegExpMacroAssembler::ExecuteForTesting(
String input, int start_offset, const byte* input_start,
const byte* input_end, int* output, int output_size, Isolate* isolate,
JSRegExp regexp) {
return Execute(input, start_offset, input_start, input_end, output,
output_size, isolate, regexp);
}
// Returns a {Result} sentinel, or the number of successful matches.
// TODO(pthier): The JSRegExp object is passed to native irregexp code to match
// the signature of the interpreter. We should get rid of JS objects passed to
......@@ -380,6 +379,7 @@ const byte NativeRegExpMacroAssembler::word_character_map[] = {
};
// clang-format on
// static
Address NativeRegExpMacroAssembler::GrowStack(Isolate* isolate) {
DisallowGarbageCollection no_gc;
......
This diff is collapsed.
......@@ -355,10 +355,9 @@ void RegExpMacroAssemblerX64::CheckNotBackReferenceIgnoreCase(
{
AllowExternalCallThatCantCauseGC scope(&masm_);
ExternalReference compare =
unicode ? ExternalReference::re_case_insensitive_compare_unicode(
isolate())
: ExternalReference::re_case_insensitive_compare_non_unicode(
isolate());
unicode
? ExternalReference::re_case_insensitive_compare_unicode()
: ExternalReference::re_case_insensitive_compare_non_unicode();
__ CallCFunction(compare, num_arguments);
}
......@@ -619,7 +618,7 @@ bool RegExpMacroAssemblerX64::CheckSpecialCharacterClass(base::uc16 type,
__ cmpl(current_character(), Immediate('z'));
BranchOrBacktrack(above, on_no_match);
}
__ Move(rbx, ExternalReference::re_word_character_map(isolate()));
__ Move(rbx, ExternalReference::re_word_character_map());
DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
__ testb(Operand(rbx, current_character(), times_1, 0),
current_character());
......@@ -633,7 +632,7 @@ bool RegExpMacroAssemblerX64::CheckSpecialCharacterClass(base::uc16 type,
__ cmpl(current_character(), Immediate('z'));
__ j(above, &done);
}
__ Move(rbx, ExternalReference::re_word_character_map(isolate()));
__ Move(rbx, ExternalReference::re_word_character_map());
DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
__ testb(Operand(rbx, current_character(), times_1, 0),
current_character());
......@@ -1023,8 +1022,7 @@ Handle<HeapObject> RegExpMacroAssemblerX64::GetCode(Handle<String> source) {
__ PrepareCallCFunction(kNumArguments);
__ LoadAddress(arg_reg_1, ExternalReference::isolate_address(isolate()));
ExternalReference grow_stack =
ExternalReference::re_grow_stack(isolate());
ExternalReference grow_stack = ExternalReference::re_grow_stack();
__ CallCFunction(grow_stack, kNumArguments);
// If nullptr is returned, we have failed to grow the stack, and must exit
// with a stack-overflow exception.
......@@ -1229,7 +1227,7 @@ void RegExpMacroAssemblerX64::CallCheckStackGuardState() {
__ leaq(rdi, Operand(rsp, -kSystemPointerSize));
#endif
ExternalReference stack_check =
ExternalReference::re_check_stack_guard_state(isolate());
ExternalReference::re_check_stack_guard_state();
__ CallCFunction(stack_check, num_arguments);
}
......
......@@ -655,7 +655,7 @@ static ArchRegExpMacroAssembler::Result Execute(JSRegExp regexp, String input,
Address input_end,
int* captures) {
return static_cast<NativeRegExpMacroAssembler::Result>(
NativeRegExpMacroAssembler::Execute(
NativeRegExpMacroAssembler::ExecuteForTesting(
input, start_offset, reinterpret_cast<byte*>(input_start),
reinterpret_cast<byte*>(input_end), captures, 0, CcTest::i_isolate(),
regexp));
......
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