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) {
BranchOrBacktrack(gt, on_greater);
}
void RegExpMacroAssemblerARM::CheckAtStart(Label* on_at_start) {
void RegExpMacroAssemblerARM::CheckAtStart(int cp_offset, Label* on_at_start) {
__ 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);
BranchOrBacktrack(eq, on_at_start);
}
void RegExpMacroAssemblerARM::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) {
__ ldr(r1, MemOperand(frame_pointer(), kStringStartMinusOne));
......
......@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM
virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack();
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 CheckCharacterAfterAnd(unsigned c,
unsigned mask,
......
......@@ -201,14 +201,14 @@ void RegExpMacroAssemblerARM64::CheckCharacterGT(uc16 limit,
CompareAndBranchOrBacktrack(current_character(), limit, hi, on_greater);
}
void RegExpMacroAssemblerARM64::CheckAtStart(Label* on_at_start) {
__ Add(w10, current_input_offset(), Operand(-char_size()));
void RegExpMacroAssemblerARM64::CheckAtStart(int cp_offset,
Label* on_at_start) {
__ Add(w10, current_input_offset(),
Operand(-char_size() + cp_offset * char_size()));
__ Cmp(w10, string_start_minus_one());
BranchOrBacktrack(eq, on_at_start);
}
void RegExpMacroAssemblerARM64::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) {
__ Add(w10, current_input_offset(),
......
......@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM64
virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack();
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 CheckCharacterAfterAnd(unsigned c,
unsigned mask,
......
......@@ -161,14 +161,12 @@ void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) {
BranchOrBacktrack(greater, on_greater);
}
void RegExpMacroAssemblerIA32::CheckAtStart(Label* on_at_start) {
__ lea(eax, Operand(edi, -char_size()));
void RegExpMacroAssemblerIA32::CheckAtStart(int cp_offset, Label* on_at_start) {
__ lea(eax, Operand(edi, -char_size() + cp_offset * char_size()));
__ cmp(eax, Operand(ebp, kStringStartMinusOne));
BranchOrBacktrack(equal, on_at_start);
}
void RegExpMacroAssemblerIA32::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) {
__ lea(eax, Operand(edi, -char_size() + cp_offset * char_size()));
......
......@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerIA32
virtual void AdvanceRegister(int reg, int by);
virtual void Backtrack();
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 CheckCharacterAfterAnd(uint32_t c,
uint32_t mask,
......
......@@ -230,8 +230,8 @@ void RegExpBytecodeGenerator::CheckCharacter(uint32_t c, Label* on_equal) {
EmitOrLink(on_equal);
}
void RegExpBytecodeGenerator::CheckAtStart(Label* on_at_start) {
Emit(BC_CHECK_AT_START, 0);
void RegExpBytecodeGenerator::CheckAtStart(int cp_offset, Label* on_at_start) {
Emit(BC_CHECK_AT_START, cp_offset);
EmitOrLink(on_at_start);
}
......
......@@ -55,7 +55,7 @@ class V8_EXPORT_PRIVATE RegExpBytecodeGenerator : public RegExpMacroAssembler {
virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
virtual void CheckCharacterLT(uc16 limit, Label* on_less);
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 CheckNotCharacter(unsigned c, Label* on_not_equal);
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask,
......
......@@ -2083,12 +2083,7 @@ void EmitHat(RegExpCompiler* compiler, RegExpNode* on_success, Trace* trace) {
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
// we are at the start.
// TODO(jgruber): It would be less awkward to use CheckAtStart here, but
// 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);
assembler->CheckAtStart(new_trace.cp_offset(), &ok);
}
// If we've already checked that we are not at the start of input, it's okay
......@@ -2181,12 +2176,7 @@ void AssertionNode::BacktrackIfPrevious(
if (may_be_at_or_before_subject_string_start) {
// The start of input counts as a non-word character, so the question is
// decided if we are at the start.
// TODO(jgruber): It would be less awkward to use CheckAtStart here, but
// 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);
assembler->CheckAtStart(new_trace.cp_offset(), non_word);
}
// 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,
DISPATCH();
}
BYTECODE(CHECK_AT_START) {
if (current == 0) {
if (current + (insn >> BYTECODE_SHIFT) == 0) {
SET_PC_FROM_OFFSET(Load32Aligned(pc + 4));
} else {
ADVANCE(CHECK_AT_START);
......
......@@ -227,13 +227,13 @@ void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) {
assembler_->CheckCharacter(c, on_equal);
}
void RegExpMacroAssemblerTracer::CheckAtStart(Label* on_at_start) {
PrintF(" CheckAtStart(label[%08x]);\n", LabelToInt(on_at_start));
assembler_->CheckAtStart(on_at_start);
void RegExpMacroAssemblerTracer::CheckAtStart(int cp_offset,
Label* on_at_start) {
PrintF(" CheckAtStart(cp_offset=%d, label[%08x]);\n", cp_offset,
LabelToInt(on_at_start));
assembler_->CheckAtStart(cp_offset, on_at_start);
}
void RegExpMacroAssemblerTracer::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) {
PrintF(" CheckNotAtStart(cp_offset=%d, label[%08x]);\n", cp_offset,
......
......@@ -22,13 +22,13 @@ class RegExpMacroAssemblerTracer: public RegExpMacroAssembler {
void AdvanceRegister(int reg, int by) override; // r[reg] += by.
void Backtrack() override;
void Bind(Label* label) override;
void CheckAtStart(Label* on_at_start) override;
void CheckCharacter(unsigned c, Label* on_equal) override;
void CheckCharacterAfterAnd(unsigned c, unsigned and_with,
Label* on_equal) override;
void CheckCharacterGT(uc16 limit, Label* on_greater) override;
void CheckCharacterLT(uc16 limit, Label* on_less) 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 CheckNotBackReference(int start_reg, bool read_backward,
Label* on_no_match) override;
......
......@@ -71,7 +71,6 @@ class RegExpMacroAssembler {
// stack by an earlier PushBacktrack(Label*).
virtual void Backtrack() = 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
// map. The destinations vector has up to 4 labels.
virtual void CheckCharacter(unsigned c, Label* on_equal) = 0;
......@@ -83,6 +82,7 @@ class RegExpMacroAssembler {
virtual void CheckCharacterGT(uc16 limit, Label* on_greater) = 0;
virtual void CheckCharacterLT(uc16 limit, Label* on_less) = 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 CheckNotBackReference(int start_reg, bool read_backward,
Label* on_no_match) = 0;
......
......@@ -172,14 +172,12 @@ void RegExpMacroAssemblerX64::CheckCharacterGT(uc16 limit, Label* on_greater) {
BranchOrBacktrack(greater, on_greater);
}
void RegExpMacroAssemblerX64::CheckAtStart(Label* on_at_start) {
__ leaq(rax, Operand(rdi, -char_size()));
void RegExpMacroAssemblerX64::CheckAtStart(int cp_offset, Label* on_at_start) {
__ leaq(rax, Operand(rdi, -char_size() + cp_offset * char_size()));
__ cmpq(rax, Operand(rbp, kStringStartMinusOne));
BranchOrBacktrack(equal, on_at_start);
}
void RegExpMacroAssemblerX64::CheckNotAtStart(int cp_offset,
Label* on_not_at_start) {
__ leaq(rax, Operand(rdi, -char_size() + cp_offset * char_size()));
......
......@@ -24,7 +24,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerX64
void AdvanceRegister(int reg, int by) override;
void Backtrack() 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 CheckCharacterAfterAnd(uint32_t c, uint32_t mask,
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