Commit 4536bb2e authored by Iain Ireland's avatar Iain Ireland Committed by Commit Bot

[regexp] Hoist LoadCurrentCharacterImpl

LoadCurrentCharacterImpl is implemented once in each of the eight
regexp-macro-assembler-<arch>.cc files. Aside from small differences
in comment wording, those eight implementations are identical. The
architecture-specific code for LoadCurrentCharacter is all in
LoadCurrentCharacterUnchecked.

This patch hoists the definition of LoadCurrentCharacterImpl into
NativeRegExpMacroAssembler and turns LoadCurrentCharacterUnchecked
into a virtual function.

Note: The arm64 version of LoadCurrentCharacterImpl contained the
following six-year-old comment, which I don't think is worth
preserving:

// TODO(pielan): Make sure long strings are caught before this, and
// not just asserted in debug mode.

R=jgruber@chromium.org

Bug: v8:10406
Change-Id: Ic81283ad3b618d6b06f4206fb77d30de617dccb7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2140003
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67260}
parent ec362684
......@@ -945,25 +945,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kARMImplementation;
}
void RegExpMacroAssemblerARM::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerARM::PopCurrentPosition() {
Pop(current_input_offset());
......
......@@ -67,9 +67,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -127,10 +126,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM
static const int kBacktrackConstantPoolSize = 4;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -1131,28 +1131,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kARM64Implementation;
}
void RegExpMacroAssemblerARM64::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
// TODO(pielan): Make sure long strings are caught before this, and not
// just asserted in debug mode.
// Be sane! (And ensure that an int32_t can be used to index the string)
DCHECK(cp_offset < (1<<30));
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerARM64::PopCurrentPosition() {
Pop(current_input_offset());
......
......@@ -73,9 +73,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM64
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -139,10 +138,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerARM64
// 16 registers.
static const int kNumCachedRegisters = 16;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -981,25 +981,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kIA32Implementation;
}
void RegExpMacroAssemblerIA32::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerIA32::PopCurrentPosition() {
Pop(edi);
......
......@@ -66,9 +66,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerIA32
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -127,10 +126,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerIA32
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -958,25 +958,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kMIPSImplementation;
}
void RegExpMacroAssemblerMIPS::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works).
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerMIPS::PopCurrentPosition() {
Pop(current_input_offset());
......
......@@ -67,9 +67,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -128,10 +127,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -994,25 +994,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kMIPSImplementation;
}
void RegExpMacroAssemblerMIPS::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works).
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerMIPS::PopCurrentPosition() {
Pop(current_input_offset());
......
......@@ -67,9 +67,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -133,10 +132,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerMIPS
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -992,25 +992,6 @@ RegExpMacroAssemblerPPC::Implementation() {
return kPPCImplementation;
}
void RegExpMacroAssemblerPPC::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1 << 30)); // Be sane! (And ensure negation works)
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerPPC::PopCurrentPosition() {
Pop(current_input_offset());
......
......@@ -59,9 +59,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerPPC
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -119,10 +118,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerPPC
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -111,6 +111,24 @@ NativeRegExpMacroAssembler::NativeRegExpMacroAssembler(Isolate* isolate,
NativeRegExpMacroAssembler::~NativeRegExpMacroAssembler() = default;
void NativeRegExpMacroAssembler::LoadCurrentCharacterImpl(
int cp_offset, Label* on_end_of_input, bool check_bounds, int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(base::IsInRange(cp_offset, kMinCPOffset, kMaxCPOffset));
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
bool NativeRegExpMacroAssembler::CanReadUnaligned() {
return FLAG_enable_regexp_unaligned_accesses && !slow_safe();
}
......
......@@ -272,6 +272,13 @@ class NativeRegExpMacroAssembler: public RegExpMacroAssembler {
const byte* input_end, int* output,
int output_size, Isolate* isolate,
JSRegExp regexp);
void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least) override;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
virtual void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count) = 0;
};
} // namespace internal
......
......@@ -983,26 +983,6 @@ RegExpMacroAssemblerS390::Implementation() {
return kS390Implementation;
}
void RegExpMacroAssemblerS390::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1 << 30)); // Be sane! (And ensure negation works)
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerS390::PopCurrentPosition() {
Pop(current_input_offset());
}
......
......@@ -59,9 +59,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerS390
virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
virtual void IfRegisterEqPos(int reg, Label* if_eq);
virtual IrregexpImplementation Implementation();
virtual void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least);
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
virtual void PopCurrentPosition();
virtual void PopRegister(int register_index);
virtual void PushBacktrack(Label* label);
......@@ -121,10 +119,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerS390
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
......@@ -1044,25 +1044,6 @@ RegExpMacroAssembler::IrregexpImplementation
return kX64Implementation;
}
void RegExpMacroAssemblerX64::LoadCurrentCharacterImpl(int cp_offset,
Label* on_end_of_input,
bool check_bounds,
int characters,
int eats_at_least) {
// It's possible to preload a small number of characters when each success
// path requires a large number of characters, but not the reverse.
DCHECK_GE(eats_at_least, characters);
DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
if (check_bounds) {
if (cp_offset >= 0) {
CheckPosition(cp_offset + eats_at_least - 1, on_end_of_input);
} else {
CheckPosition(cp_offset, on_end_of_input);
}
}
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
void RegExpMacroAssemblerX64::PopCurrentPosition() {
Pop(rdi);
......
......@@ -59,9 +59,8 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerX64
void IfRegisterLT(int reg, int comparand, Label* if_lt) override;
void IfRegisterEqPos(int reg, Label* if_eq) override;
IrregexpImplementation Implementation() override;
void LoadCurrentCharacterImpl(int cp_offset, Label* on_end_of_input,
bool check_bounds, int characters,
int eats_at_least) override;
void LoadCurrentCharacterUnchecked(int cp_offset,
int character_count) override;
void PopCurrentPosition() override;
void PopRegister(int register_index) override;
void PushBacktrack(Label* label) override;
......@@ -159,10 +158,6 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerX64
// Initial size of code buffer.
static const int kRegExpCodeSize = 1024;
// Load a number of characters at the given offset from the
// current position, into the current-character register.
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
// Check whether preemption has been requested.
void CheckPreemption();
......
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