Commit 2e0bc516 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Add an offset argument CheckAtStart

Similar to CheckNotAtStart, one can now apply an offset to the
CheckAtStart operation. Due to a recent change, all callsites of
CheckNotAtStart now need to pass an offset, whereas previously the
offset was just assumed to be zero.

Bug: chromium:996391
Change-Id: Ia59a584e93e5384479f05abddef7859b420b023a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1773272
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63444}
parent f48fb8b1
...@@ -172,15 +172,14 @@ void RegExpMacroAssemblerARM::CheckCharacterGT(uc16 limit, Label* on_greater) { ...@@ -172,15 +172,14 @@ void RegExpMacroAssemblerARM::CheckCharacterGT(uc16 limit, Label* on_greater) {
BranchOrBacktrack(gt, on_greater); BranchOrBacktrack(gt, on_greater);
} }
void RegExpMacroAssemblerARM::CheckAtStart(int cp_offset, Label* on_at_start) {
void RegExpMacroAssemblerARM::CheckAtStart(Label* on_at_start) {
__ ldr(r1, MemOperand(frame_pointer(), kStringStartMinusOne)); __ ldr(r1, MemOperand(frame_pointer(), kStringStartMinusOne));
__ add(r0, current_input_offset(), Operand(-char_size())); __ add(r0, current_input_offset(),
Operand(-char_size() + cp_offset * char_size()));
__ cmp(r0, r1); __ cmp(r0, r1);
BranchOrBacktrack(eq, on_at_start); BranchOrBacktrack(eq, on_at_start);
} }
void RegExpMacroAssemblerARM::CheckNotAtStart(int cp_offset, void RegExpMacroAssemblerARM::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) { Label* on_not_at_start) {
__ ldr(r1, MemOperand(frame_pointer(), kStringStartMinusOne)); __ ldr(r1, MemOperand(frame_pointer(), kStringStartMinusOne));
......
...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM ...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM
virtual void AdvanceRegister(int reg, int by); virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack(); virtual void Backtrack();
virtual void Bind(Label* label); virtual void Bind(Label* label);
virtual void CheckAtStart(Label* on_at_start); virtual void CheckAtStart(int cp_offset, Label* on_at_start);
virtual void CheckCharacter(unsigned c, Label* on_equal); virtual void CheckCharacter(unsigned c, Label* on_equal);
virtual void CheckCharacterAfterAnd(unsigned c, virtual void CheckCharacterAfterAnd(unsigned c,
unsigned mask, unsigned mask,
......
...@@ -201,14 +201,14 @@ void RegExpMacroAssemblerARM64::CheckCharacterGT(uc16 limit, ...@@ -201,14 +201,14 @@ void RegExpMacroAssemblerARM64::CheckCharacterGT(uc16 limit,
CompareAndBranchOrBacktrack(current_character(), limit, hi, on_greater); CompareAndBranchOrBacktrack(current_character(), limit, hi, on_greater);
} }
void RegExpMacroAssemblerARM64::CheckAtStart(int cp_offset,
void RegExpMacroAssemblerARM64::CheckAtStart(Label* on_at_start) { Label* on_at_start) {
__ Add(w10, current_input_offset(), Operand(-char_size())); __ Add(w10, current_input_offset(),
Operand(-char_size() + cp_offset * char_size()));
__ Cmp(w10, string_start_minus_one()); __ Cmp(w10, string_start_minus_one());
BranchOrBacktrack(eq, on_at_start); BranchOrBacktrack(eq, on_at_start);
} }
void RegExpMacroAssemblerARM64::CheckNotAtStart(int cp_offset, void RegExpMacroAssemblerARM64::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) { Label* on_not_at_start) {
__ Add(w10, current_input_offset(), __ Add(w10, current_input_offset(),
......
...@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM64 ...@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM64
virtual void AdvanceRegister(int reg, int by); virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack(); virtual void Backtrack();
virtual void Bind(Label* label); virtual void Bind(Label* label);
virtual void CheckAtStart(Label* on_at_start); virtual void CheckAtStart(int cp_offset, Label* on_at_start);
virtual void CheckCharacter(unsigned c, Label* on_equal); virtual void CheckCharacter(unsigned c, Label* on_equal);
virtual void CheckCharacterAfterAnd(unsigned c, virtual void CheckCharacterAfterAnd(unsigned c,
unsigned mask, unsigned mask,
......
...@@ -161,14 +161,12 @@ void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) { ...@@ -161,14 +161,12 @@ void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) {
BranchOrBacktrack(greater, on_greater); BranchOrBacktrack(greater, on_greater);
} }
void RegExpMacroAssemblerIA32::CheckAtStart(int cp_offset, Label* on_at_start) {
void RegExpMacroAssemblerIA32::CheckAtStart(Label* on_at_start) { __ lea(eax, Operand(edi, -char_size() + cp_offset * char_size()));
__ lea(eax, Operand(edi, -char_size()));
__ cmp(eax, Operand(ebp, kStringStartMinusOne)); __ cmp(eax, Operand(ebp, kStringStartMinusOne));
BranchOrBacktrack(equal, on_at_start); BranchOrBacktrack(equal, on_at_start);
} }
void RegExpMacroAssemblerIA32::CheckNotAtStart(int cp_offset, void RegExpMacroAssemblerIA32::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) { Label* on_not_at_start) {
__ lea(eax, Operand(edi, -char_size() + cp_offset * char_size())); __ lea(eax, Operand(edi, -char_size() + cp_offset * char_size()));
......
...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerIA32 ...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerIA32
virtual void AdvanceRegister(int reg, int by); virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack(); virtual void Backtrack();
virtual void Bind(Label* label); virtual void Bind(Label* label);
virtual void CheckAtStart(Label* on_at_start); virtual void CheckAtStart(int cp_offset, Label* on_at_start);
virtual void CheckCharacter(uint32_t c, Label* on_equal); virtual void CheckCharacter(uint32_t c, Label* on_equal);
virtual void CheckCharacterAfterAnd(uint32_t c, virtual void CheckCharacterAfterAnd(uint32_t c,
uint32_t mask, uint32_t mask,
......
...@@ -230,8 +230,8 @@ void RegExpBytecodeGenerator::CheckCharacter(uint32_t c, Label* on_equal) { ...@@ -230,8 +230,8 @@ void RegExpBytecodeGenerator::CheckCharacter(uint32_t c, Label* on_equal) {
EmitOrLink(on_equal); EmitOrLink(on_equal);
} }
void RegExpBytecodeGenerator::CheckAtStart(Label* on_at_start) { void RegExpBytecodeGenerator::CheckAtStart(int cp_offset, Label* on_at_start) {
Emit(BC_CHECK_AT_START, 0); Emit(BC_CHECK_AT_START, cp_offset);
EmitOrLink(on_at_start); EmitOrLink(on_at_start);
} }
......
...@@ -55,7 +55,7 @@ class V8_EXPORT_PRIVATE RegExpBytecodeGenerator : public RegExpMacroAssembler { ...@@ -55,7 +55,7 @@ class V8_EXPORT_PRIVATE RegExpBytecodeGenerator : public RegExpMacroAssembler {
virtual void CheckCharacterGT(uc16 limit, Label* on_greater); virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
virtual void CheckCharacterLT(uc16 limit, Label* on_less); virtual void CheckCharacterLT(uc16 limit, Label* on_less);
virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
virtual void CheckAtStart(Label* on_at_start); virtual void CheckAtStart(int cp_offset, Label* on_at_start);
virtual void CheckNotAtStart(int cp_offset, Label* on_not_at_start); virtual void CheckNotAtStart(int cp_offset, Label* on_not_at_start);
virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); virtual void CheckNotCharacter(unsigned c, Label* on_not_equal);
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask, virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask,
......
...@@ -2083,12 +2083,7 @@ void EmitHat(RegExpCompiler* compiler, RegExpNode* on_success, Trace* trace) { ...@@ -2083,12 +2083,7 @@ void EmitHat(RegExpCompiler* compiler, RegExpNode* on_success, Trace* trace) {
if (may_be_at_or_before_subject_string_start) { if (may_be_at_or_before_subject_string_start) {
// The start of input counts as a newline in this context, so skip to ok if // The start of input counts as a newline in this context, so skip to ok if
// we are at the start. // we are at the start.
// TODO(jgruber): It would be less awkward to use CheckAtStart here, but assembler->CheckAtStart(new_trace.cp_offset(), &ok);
// that currently does not support a non-zero cp_offset.
Label not_at_start;
assembler->CheckNotAtStart(new_trace.cp_offset(), &not_at_start);
assembler->GoTo(&ok);
assembler->Bind(&not_at_start);
} }
// If we've already checked that we are not at the start of input, it's okay // If we've already checked that we are not at the start of input, it's okay
...@@ -2181,12 +2176,7 @@ void AssertionNode::BacktrackIfPrevious( ...@@ -2181,12 +2176,7 @@ void AssertionNode::BacktrackIfPrevious(
if (may_be_at_or_before_subject_string_start) { if (may_be_at_or_before_subject_string_start) {
// The start of input counts as a non-word character, so the question is // The start of input counts as a non-word character, so the question is
// decided if we are at the start. // decided if we are at the start.
// TODO(jgruber): It would be less awkward to use CheckAtStart here, but assembler->CheckAtStart(new_trace.cp_offset(), non_word);
// that currently does not support a non-zero cp_offset.
Label not_at_start;
assembler->CheckNotAtStart(new_trace.cp_offset(), &not_at_start);
assembler->GoTo(non_word);
assembler->Bind(&not_at_start);
} }
// If we've already checked that we are not at the start of input, it's okay // If we've already checked that we are not at the start of input, it's okay
......
...@@ -729,7 +729,7 @@ IrregexpInterpreter::Result RawMatch(Isolate* isolate, ByteArray code_array, ...@@ -729,7 +729,7 @@ IrregexpInterpreter::Result RawMatch(Isolate* isolate, ByteArray code_array,
DISPATCH(); DISPATCH();
} }
BYTECODE(CHECK_AT_START) { BYTECODE(CHECK_AT_START) {
if (current == 0) { if (current + (insn >> BYTECODE_SHIFT) == 0) {
SET_PC_FROM_OFFSET(Load32Aligned(pc + 4)); SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
} else { } else {
ADVANCE(CHECK_AT_START); ADVANCE(CHECK_AT_START);
......
...@@ -227,13 +227,13 @@ void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) { ...@@ -227,13 +227,13 @@ void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) {
assembler_->CheckCharacter(c, on_equal); assembler_->CheckCharacter(c, on_equal);
} }
void RegExpMacroAssemblerTracer::CheckAtStart(int cp_offset,
void RegExpMacroAssemblerTracer::CheckAtStart(Label* on_at_start) { Label* on_at_start) {
PrintF(" CheckAtStart(label[%08x]);\n", LabelToInt(on_at_start)); PrintF(" CheckAtStart(cp_offset=%d, label[%08x]);\n", cp_offset,
assembler_->CheckAtStart(on_at_start); LabelToInt(on_at_start));
assembler_->CheckAtStart(cp_offset, on_at_start);
} }
void RegExpMacroAssemblerTracer::CheckNotAtStart(int cp_offset, void RegExpMacroAssemblerTracer::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) { Label* on_not_at_start) {
PrintF(" CheckNotAtStart(cp_offset=%d, label[%08x]);\n", cp_offset, PrintF(" CheckNotAtStart(cp_offset=%d, label[%08x]);\n", cp_offset,
......
...@@ -22,13 +22,13 @@ class RegExpMacroAssemblerTracer: public RegExpMacroAssembler { ...@@ -22,13 +22,13 @@ class RegExpMacroAssemblerTracer: public RegExpMacroAssembler {
void AdvanceRegister(int reg, int by) override; // r[reg] += by. void AdvanceRegister(int reg, int by) override; // r[reg] += by.
void Backtrack() override; void Backtrack() override;
void Bind(Label* label) override; void Bind(Label* label) override;
void CheckAtStart(Label* on_at_start) override;
void CheckCharacter(unsigned c, Label* on_equal) override; void CheckCharacter(unsigned c, Label* on_equal) override;
void CheckCharacterAfterAnd(unsigned c, unsigned and_with, void CheckCharacterAfterAnd(unsigned c, unsigned and_with,
Label* on_equal) override; Label* on_equal) override;
void CheckCharacterGT(uc16 limit, Label* on_greater) override; void CheckCharacterGT(uc16 limit, Label* on_greater) override;
void CheckCharacterLT(uc16 limit, Label* on_less) override; void CheckCharacterLT(uc16 limit, Label* on_less) override;
void CheckGreedyLoop(Label* on_tos_equals_current_position) override; void CheckGreedyLoop(Label* on_tos_equals_current_position) override;
void CheckAtStart(int cp_offset, Label* on_at_start) override;
void CheckNotAtStart(int cp_offset, Label* on_not_at_start) override; void CheckNotAtStart(int cp_offset, Label* on_not_at_start) override;
void CheckNotBackReference(int start_reg, bool read_backward, void CheckNotBackReference(int start_reg, bool read_backward,
Label* on_no_match) override; Label* on_no_match) override;
......
...@@ -71,7 +71,6 @@ class RegExpMacroAssembler { ...@@ -71,7 +71,6 @@ class RegExpMacroAssembler {
// stack by an earlier PushBacktrack(Label*). // stack by an earlier PushBacktrack(Label*).
virtual void Backtrack() = 0; virtual void Backtrack() = 0;
virtual void Bind(Label* label) = 0; virtual void Bind(Label* label) = 0;
virtual void CheckAtStart(Label* on_at_start) = 0;
// Dispatch after looking the current character up in a 2-bits-per-entry // Dispatch after looking the current character up in a 2-bits-per-entry
// map. The destinations vector has up to 4 labels. // map. The destinations vector has up to 4 labels.
virtual void CheckCharacter(unsigned c, Label* on_equal) = 0; virtual void CheckCharacter(unsigned c, Label* on_equal) = 0;
...@@ -83,6 +82,7 @@ class RegExpMacroAssembler { ...@@ -83,6 +82,7 @@ class RegExpMacroAssembler {
virtual void CheckCharacterGT(uc16 limit, Label* on_greater) = 0; virtual void CheckCharacterGT(uc16 limit, Label* on_greater) = 0;
virtual void CheckCharacterLT(uc16 limit, Label* on_less) = 0; virtual void CheckCharacterLT(uc16 limit, Label* on_less) = 0;
virtual void CheckGreedyLoop(Label* on_tos_equals_current_position) = 0; virtual void CheckGreedyLoop(Label* on_tos_equals_current_position) = 0;
virtual void CheckAtStart(int cp_offset, Label* on_at_start) = 0;
virtual void CheckNotAtStart(int cp_offset, Label* on_not_at_start) = 0; virtual void CheckNotAtStart(int cp_offset, Label* on_not_at_start) = 0;
virtual void CheckNotBackReference(int start_reg, bool read_backward, virtual void CheckNotBackReference(int start_reg, bool read_backward,
Label* on_no_match) = 0; Label* on_no_match) = 0;
......
...@@ -172,14 +172,12 @@ void RegExpMacroAssemblerX64::CheckCharacterGT(uc16 limit, Label* on_greater) { ...@@ -172,14 +172,12 @@ void RegExpMacroAssemblerX64::CheckCharacterGT(uc16 limit, Label* on_greater) {
BranchOrBacktrack(greater, on_greater); BranchOrBacktrack(greater, on_greater);
} }
void RegExpMacroAssemblerX64::CheckAtStart(int cp_offset, Label* on_at_start) {
void RegExpMacroAssemblerX64::CheckAtStart(Label* on_at_start) { __ leaq(rax, Operand(rdi, -char_size() + cp_offset * char_size()));
__ leaq(rax, Operand(rdi, -char_size()));
__ cmpq(rax, Operand(rbp, kStringStartMinusOne)); __ cmpq(rax, Operand(rbp, kStringStartMinusOne));
BranchOrBacktrack(equal, on_at_start); BranchOrBacktrack(equal, on_at_start);
} }
void RegExpMacroAssemblerX64::CheckNotAtStart(int cp_offset, void RegExpMacroAssemblerX64::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) { Label* on_not_at_start) {
__ leaq(rax, Operand(rdi, -char_size() + cp_offset * char_size())); __ leaq(rax, Operand(rdi, -char_size() + cp_offset * char_size()));
......
...@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerX64 ...@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerX64
void AdvanceRegister(int reg, int by) override; void AdvanceRegister(int reg, int by) override;
void Backtrack() override; void Backtrack() override;
void Bind(Label* label) override; void Bind(Label* label) override;
void CheckAtStart(Label* on_at_start) override; void CheckAtStart(int cp_offset, Label* on_at_start) override;
void CheckCharacter(uint32_t c, Label* on_equal) override; void CheckCharacter(uint32_t c, Label* on_equal) override;
void CheckCharacterAfterAnd(uint32_t c, uint32_t mask, void CheckCharacterAfterAnd(uint32_t c, uint32_t mask,
Label* on_equal) override; Label* on_equal) override;
......
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