Commit 6246a1f9 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[csa] Add some types to some string/regexp-related functions.

E.g. SubString and StringAdd.

Bug: v8:7310
Change-Id: I352044f88fe79c5b576c5423d6feae3bcb7d725a
Reviewed-on: https://chromium-review.googlesource.com/934284Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51504}
parent 0b9b48b5
This diff is collapsed.
...@@ -50,7 +50,7 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -50,7 +50,7 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
Node* ConstructNewResultFromMatchInfo(Node* const context, Node* const regexp, Node* ConstructNewResultFromMatchInfo(Node* const context, Node* const regexp,
Node* const match_info, Node* const match_info,
Node* const string); TNode<String> const string);
Node* RegExpPrototypeExecBodyWithoutResult(Node* const context, Node* RegExpPrototypeExecBodyWithoutResult(Node* const context,
Node* const regexp, Node* const regexp,
...@@ -58,7 +58,7 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -58,7 +58,7 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
Label* if_didnotmatch, Label* if_didnotmatch,
const bool is_fastpath); const bool is_fastpath);
Node* RegExpPrototypeExecBody(Node* const context, Node* const regexp, Node* RegExpPrototypeExecBody(Node* const context, Node* const regexp,
Node* const string, const bool is_fastpath); TNode<String> string, const bool is_fastpath);
Node* ThrowIfNotJSReceiver(Node* context, Node* maybe_receiver, Node* ThrowIfNotJSReceiver(Node* context, Node* maybe_receiver,
MessageTemplate::Template msg_template, MessageTemplate::Template msg_template,
...@@ -100,7 +100,8 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -100,7 +100,8 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
Node* const is_unicode, bool is_fastpath); Node* const is_unicode, bool is_fastpath);
void RegExpPrototypeMatchBody(Node* const context, Node* const regexp, void RegExpPrototypeMatchBody(Node* const context, Node* const regexp,
Node* const string, const bool is_fastpath); TNode<String> const string,
const bool is_fastpath);
void RegExpPrototypeSearchBodyFast(Node* const context, Node* const regexp, void RegExpPrototypeSearchBodyFast(Node* const context, Node* const regexp,
Node* const string); Node* const string);
...@@ -108,12 +109,13 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -108,12 +109,13 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
Node* const string); Node* const string);
void RegExpPrototypeSplitBody(Node* const context, Node* const regexp, void RegExpPrototypeSplitBody(Node* const context, Node* const regexp,
Node* const string, Node* const limit); TNode<String> const string, Node* const limit);
Node* ReplaceGlobalCallableFastPath(Node* context, Node* regexp, Node* string, Node* ReplaceGlobalCallableFastPath(Node* context, Node* regexp, Node* string,
Node* replace_callable); Node* replace_callable);
Node* ReplaceSimpleStringFastPath(Node* context, Node* regexp, Node* string, Node* ReplaceSimpleStringFastPath(Node* context, Node* regexp,
Node* replace_string); TNode<String> string,
TNode<String> replace_string);
}; };
} // namespace internal } // namespace internal
......
...@@ -1666,8 +1666,8 @@ TF_BUILTIN(StringPrototypeSlice, StringBuiltinsAssembler) { ...@@ -1666,8 +1666,8 @@ TF_BUILTIN(StringPrototypeSlice, StringBuiltinsAssembler) {
RequireObjectCoercible(context, receiver, "String.prototype.slice"); RequireObjectCoercible(context, receiver, "String.prototype.slice");
// 2. Let S be ? ToString(O). // 2. Let S be ? ToString(O).
Node* const subject_string = TNode<String> const subject_string =
CallBuiltin(Builtins::kToString, context, receiver); CAST(CallBuiltin(Builtins::kToString, context, receiver));
// 3. Let len be the number of elements in S. // 3. Let len be the number of elements in S.
TNode<Smi> const length = LoadStringLengthAsSmi(subject_string); TNode<Smi> const length = LoadStringLengthAsSmi(subject_string);
...@@ -1688,7 +1688,7 @@ TF_BUILTIN(StringPrototypeSlice, StringBuiltinsAssembler) { ...@@ -1688,7 +1688,7 @@ TF_BUILTIN(StringPrototypeSlice, StringBuiltinsAssembler) {
{ {
GotoIf(SmiLessThanOrEqual(var_end.value(), var_start.value()), GotoIf(SmiLessThanOrEqual(var_end.value(), var_start.value()),
&return_emptystring); &return_emptystring);
Node* const result = TNode<String> const result =
SubString(subject_string, var_start.value(), var_end.value()); SubString(subject_string, var_start.value(), var_end.value());
args.PopAndReturn(result); args.PopAndReturn(result);
} }
...@@ -1819,7 +1819,7 @@ TF_BUILTIN(StringPrototypeSubstr, StringBuiltinsAssembler) { ...@@ -1819,7 +1819,7 @@ TF_BUILTIN(StringPrototypeSubstr, StringBuiltinsAssembler) {
TNode<Smi> const zero = SmiConstant(0); TNode<Smi> const zero = SmiConstant(0);
// Check that {receiver} is coercible to Object and convert it to a String. // Check that {receiver} is coercible to Object and convert it to a String.
Node* const string = TNode<String> const string =
ToThisString(context, receiver, "String.prototype.substr"); ToThisString(context, receiver, "String.prototype.substr");
TNode<Smi> const string_length = LoadStringLengthAsSmi(string); TNode<Smi> const string_length = LoadStringLengthAsSmi(string);
...@@ -1888,8 +1888,7 @@ TF_BUILTIN(StringPrototypeSubstr, StringBuiltinsAssembler) { ...@@ -1888,8 +1888,7 @@ TF_BUILTIN(StringPrototypeSubstr, StringBuiltinsAssembler) {
BIND(&out); BIND(&out);
{ {
TNode<Smi> const end = SmiAdd(var_start.value(), var_result_length.value()); TNode<Smi> const end = SmiAdd(var_start.value(), var_result_length.value());
Node* const result = SubString(string, var_start.value(), end); args.PopAndReturn(SubString(string, var_start.value(), end));
args.PopAndReturn(result);
} }
} }
...@@ -1943,7 +1942,7 @@ TNode<Smi> StringBuiltinsAssembler::ToSmiBetweenZeroAnd( ...@@ -1943,7 +1942,7 @@ TNode<Smi> StringBuiltinsAssembler::ToSmiBetweenZeroAnd(
} }
TF_BUILTIN(SubString, CodeStubAssembler) { TF_BUILTIN(SubString, CodeStubAssembler) {
Node* string = Parameter(Descriptor::kString); TNode<String> string = CAST(Parameter(Descriptor::kString));
Node* from = Parameter(Descriptor::kFrom); Node* from = Parameter(Descriptor::kFrom);
Node* to = Parameter(Descriptor::kTo); Node* to = Parameter(Descriptor::kTo);
...@@ -1970,7 +1969,7 @@ TF_BUILTIN(StringPrototypeSubstring, StringBuiltinsAssembler) { ...@@ -1970,7 +1969,7 @@ TF_BUILTIN(StringPrototypeSubstring, StringBuiltinsAssembler) {
VARIABLE(var_end, MachineRepresentation::kTagged); VARIABLE(var_end, MachineRepresentation::kTagged);
// Check that {receiver} is coercible to Object and convert it to a String. // Check that {receiver} is coercible to Object and convert it to a String.
Node* const string = TNode<String> const string =
ToThisString(context, receiver, "String.prototype.substring"); ToThisString(context, receiver, "String.prototype.substring");
Node* const length = LoadStringLengthAsSmi(string); Node* const length = LoadStringLengthAsSmi(string);
...@@ -1999,10 +1998,7 @@ TF_BUILTIN(StringPrototypeSubstring, StringBuiltinsAssembler) { ...@@ -1999,10 +1998,7 @@ TF_BUILTIN(StringPrototypeSubstring, StringBuiltinsAssembler) {
} }
BIND(&out); BIND(&out);
{ { args.PopAndReturn(SubString(string, var_start.value(), var_end.value())); }
Node* result = SubString(string, var_start.value(), var_end.value());
args.PopAndReturn(result);
}
} }
// ES6 #sec-string.prototype.trim // ES6 #sec-string.prototype.trim
...@@ -2030,7 +2026,7 @@ void StringTrimAssembler::Generate(String::TrimMode mode, ...@@ -2030,7 +2026,7 @@ void StringTrimAssembler::Generate(String::TrimMode mode,
Node* const receiver = arguments.GetReceiver(); Node* const receiver = arguments.GetReceiver();
// Check that {receiver} is coercible to Object and convert it to a String. // Check that {receiver} is coercible to Object and convert it to a String.
Node* const string = ToThisString(context, receiver, method_name); TNode<String> const string = ToThisString(context, receiver, method_name);
TNode<IntPtrT> const string_length = LoadStringLengthAsWord(string); TNode<IntPtrT> const string_length = LoadStringLengthAsWord(string);
ToDirectStringAssembler to_direct(state(), string); ToDirectStringAssembler to_direct(state(), string);
......
This diff is collapsed.
...@@ -765,38 +765,45 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -765,38 +765,45 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
TNode<WordT> LoadBigIntBitfield(TNode<BigInt> bigint); TNode<WordT> LoadBigIntBitfield(TNode<BigInt> bigint);
TNode<UintPtrT> LoadBigIntDigit(TNode<BigInt> bigint, int digit_index); TNode<UintPtrT> LoadBigIntDigit(TNode<BigInt> bigint, int digit_index);
// Allocate a SeqOneByteString with the given length. // Allocate a SeqOneByteString with the given length.
Node* AllocateSeqOneByteString(int length, AllocationFlags flags = kNone); TNode<String> AllocateSeqOneByteString(int length,
Node* AllocateSeqOneByteString(Node* context, TNode<Smi> length, AllocationFlags flags = kNone);
AllocationFlags flags = kNone); TNode<String> AllocateSeqOneByteString(Node* context, TNode<Smi> length,
AllocationFlags flags = kNone);
// Allocate a SeqTwoByteString with the given length. // Allocate a SeqTwoByteString with the given length.
Node* AllocateSeqTwoByteString(int length, AllocationFlags flags = kNone); TNode<String> AllocateSeqTwoByteString(int length,
Node* AllocateSeqTwoByteString(Node* context, TNode<Smi> length, AllocationFlags flags = kNone);
AllocationFlags flags = kNone); TNode<String> AllocateSeqTwoByteString(Node* context, TNode<Smi> length,
AllocationFlags flags = kNone);
// Allocate a SlicedOneByteString with the given length, parent and offset. // Allocate a SlicedOneByteString with the given length, parent and offset.
// |length| and |offset| are expected to be tagged. // |length| and |offset| are expected to be tagged.
Node* AllocateSlicedOneByteString(TNode<Smi> length, Node* parent, TNode<String> AllocateSlicedOneByteString(TNode<Smi> length, Node* parent,
Node* offset); Node* offset);
// Allocate a SlicedTwoByteString with the given length, parent and offset. // Allocate a SlicedTwoByteString with the given length, parent and offset.
// |length| and |offset| are expected to be tagged. // |length| and |offset| are expected to be tagged.
Node* AllocateSlicedTwoByteString(TNode<Smi> length, Node* parent, TNode<String> AllocateSlicedTwoByteString(TNode<Smi> length, Node* parent,
Node* offset); Node* offset);
// Allocate a one-byte ConsString with the given length, first and second // Allocate a one-byte ConsString with the given length, first and second
// parts. |length| is expected to be tagged, and |first| and |second| are // parts. |length| is expected to be tagged, and |first| and |second| are
// expected to be one-byte strings. // expected to be one-byte strings.
Node* AllocateOneByteConsString(TNode<Smi> length, Node* first, Node* second, TNode<String> AllocateOneByteConsString(TNode<Smi> length,
AllocationFlags flags = kNone); TNode<String> first,
TNode<String> second,
AllocationFlags flags = kNone);
// Allocate a two-byte ConsString with the given length, first and second // Allocate a two-byte ConsString with the given length, first and second
// parts. |length| is expected to be tagged, and |first| and |second| are // parts. |length| is expected to be tagged, and |first| and |second| are
// expected to be two-byte strings. // expected to be two-byte strings.
Node* AllocateTwoByteConsString(TNode<Smi> length, Node* first, Node* second, TNode<String> AllocateTwoByteConsString(TNode<Smi> length,
AllocationFlags flags = kNone); TNode<String> first,
TNode<String> second,
AllocationFlags flags = kNone);
// Allocate an appropriate one- or two-byte ConsString with the first and // Allocate an appropriate one- or two-byte ConsString with the first and
// second parts specified by |left| and |right|. // second parts specified by |left| and |right|.
Node* NewConsString(Node* context, TNode<Smi> length, Node* left, Node* right, TNode<String> NewConsString(Node* context, TNode<Smi> length,
AllocationFlags flags = kNone); TNode<String> left, TNode<String> right,
AllocationFlags flags = kNone);
Node* AllocateNameDictionary(int at_least_space_for); Node* AllocateNameDictionary(int at_least_space_for);
Node* AllocateNameDictionary(Node* at_least_space_for); Node* AllocateNameDictionary(Node* at_least_space_for);
...@@ -1216,11 +1223,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -1216,11 +1223,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
// Return a new string object which holds a substring containing the range // Return a new string object which holds a substring containing the range
// [from,to[ of string. |from| and |to| are expected to be tagged. // [from,to[ of string. |from| and |to| are expected to be tagged.
Node* SubString(Node* string, Node* from, Node* to); TNode<String> SubString(TNode<String> string, SloppyTNode<Smi> from,
SloppyTNode<Smi> to);
// Return a new string object produced by concatenating |first| with |second|. // Return a new string object produced by concatenating |first| with |second|.
Node* StringAdd(Node* context, Node* first, Node* second, TNode<String> StringAdd(Node* context, TNode<String> first,
AllocationFlags flags = kNone); TNode<String> second, AllocationFlags flags = kNone);
// Check if |string| is an indirect (thin or flat cons) string type that can // Check if |string| is an indirect (thin or flat cons) string type that can
// be dereferenced by DerefIndirectString. // be dereferenced by DerefIndirectString.
...@@ -2096,12 +2104,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -2096,12 +2104,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* EmitKeyedSloppyArguments(Node* receiver, Node* key, Node* value, Node* EmitKeyedSloppyArguments(Node* receiver, Node* key, Node* value,
Label* bailout); Label* bailout);
Node* AllocateSlicedString(Heap::RootListIndex map_root_index, TNode<String> AllocateSlicedString(Heap::RootListIndex map_root_index,
TNode<Smi> length, Node* parent, Node* offset); TNode<Smi> length, Node* parent,
Node* offset);
Node* AllocateConsString(Heap::RootListIndex map_root_index, TNode<String> AllocateConsString(Heap::RootListIndex map_root_index,
TNode<Smi> length, Node* first, Node* second, TNode<Smi> length, TNode<String> first,
AllocationFlags flags); TNode<String> second, AllocationFlags flags);
// Implements DescriptorArray::number_of_entries. // Implements DescriptorArray::number_of_entries.
// Returns an untagged int32. // Returns an untagged int32.
...@@ -2114,9 +2123,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -2114,9 +2123,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* CollectFeedbackForString(Node* instance_type); Node* CollectFeedbackForString(Node* instance_type);
void GenerateEqual_Same(Node* value, Label* if_equal, Label* if_notequal, void GenerateEqual_Same(Node* value, Label* if_equal, Label* if_notequal,
Variable* var_type_feedback = nullptr); Variable* var_type_feedback = nullptr);
Node* AllocAndCopyStringCharacters(Node* from, Node* from_instance_type, TNode<String> AllocAndCopyStringCharacters(Node* from,
TNode<IntPtrT> from_index, Node* from_instance_type,
TNode<Smi> character_count); TNode<IntPtrT> from_index,
TNode<Smi> character_count);
static const int kElementLoopUnrollThreshold = 8; static const int kElementLoopUnrollThreshold = 8;
......
...@@ -289,7 +289,7 @@ TF_STUB(StringAddStub, CodeStubAssembler) { ...@@ -289,7 +289,7 @@ TF_STUB(StringAddStub, CodeStubAssembler) {
CodeStubAssembler::AllocationFlag allocation_flags = CodeStubAssembler::AllocationFlag allocation_flags =
(pretenure_flag == TENURED) ? CodeStubAssembler::kPretenured (pretenure_flag == TENURED) ? CodeStubAssembler::kPretenured
: CodeStubAssembler::kNone; : CodeStubAssembler::kNone;
Return(StringAdd(context, left, right, allocation_flags)); Return(StringAdd(context, CAST(left), CAST(right), allocation_flags));
} else { } else {
Callable callable = CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, Callable callable = CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE,
pretenure_flag); pretenure_flag);
......
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