Commit c65fac58 authored by jgruber's avatar jgruber Committed by Commit Bot

[regexp] Extract CSA::AllocateRegExpResult

This is a simple move of CSA::AllocateRegExpResult to
RegExpBuiltinsAssembler. There's no reason for this method to be in CSA,
and this way we save a bit of binary size since code in builtins-*-gen
is not shipped.

Bug: v8:6741
Change-Id: I89507a0bfa4e0e922d92b9fcd0604ce86efea293
Reviewed-on: https://chromium-review.googlesource.com/626078Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47532}
parent 093dcd9d
......@@ -20,6 +20,54 @@ using compiler::Node;
// -----------------------------------------------------------------------------
// ES6 section 21.2 RegExp Objects
Node* RegExpBuiltinsAssembler::AllocateRegExpResult(Node* context, Node* length,
Node* index, Node* input) {
CSA_ASSERT(this, IsFixedArray(context));
CSA_ASSERT(this, TaggedIsSmi(index));
CSA_ASSERT(this, TaggedIsSmi(length));
CSA_ASSERT(this, IsString(input));
#ifdef DEBUG
Node* const max_length = SmiConstant(JSArray::kInitialMaxFastElementArray);
CSA_ASSERT(this, SmiLessThanOrEqual(length, max_length));
#endif // DEBUG
// Allocate the JSRegExpResult.
// TODO(jgruber): Fold JSArray and FixedArray allocations, then remove
// unneeded store of elements.
Node* const result = Allocate(JSRegExpResult::kSize);
// TODO(jgruber): Store map as Heap constant?
Node* const native_context = LoadNativeContext(context);
Node* const map =
LoadContextElement(native_context, Context::REGEXP_RESULT_MAP_INDEX);
StoreMapNoWriteBarrier(result, map);
// Initialize the header before allocating the elements.
Node* const empty_array = EmptyFixedArrayConstant();
DCHECK(Heap::RootIsImmortalImmovable(Heap::kEmptyFixedArrayRootIndex));
StoreObjectFieldNoWriteBarrier(result, JSArray::kPropertiesOrHashOffset,
empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset, empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kLengthOffset, length);
StoreObjectFieldNoWriteBarrier(result, JSRegExpResult::kIndexOffset, index);
StoreObjectField(result, JSRegExpResult::kInputOffset, input);
Node* const zero = IntPtrConstant(0);
Node* const length_intptr = SmiUntag(length);
const ElementsKind elements_kind = PACKED_ELEMENTS;
Node* const elements = AllocateFixedArray(elements_kind, length_intptr);
StoreObjectField(result, JSArray::kElementsOffset, elements);
// Fill in the elements with undefined.
FillFixedArrayWithValue(elements_kind, elements, zero, length_intptr,
Heap::kUndefinedValueRootIndex);
return result;
}
Node* RegExpBuiltinsAssembler::FastLoadLastIndex(Node* regexp) {
// Load the in-object field.
static const int field_offset =
......@@ -156,6 +204,8 @@ Node* RegExpBuiltinsAssembler::ConstructNewResultFromMatchInfo(
// Allocate a new object to store the named capture properties.
// TODO(jgruber): Could be optimized by adding the object map to the heap
// root list.
// TODO(jgruber): Replace CreateDataProperty runtime calls once we have
// equivalent functionality in CSA.
Node* const native_context = LoadNativeContext(context);
Node* const map = LoadContextElement(
......
......@@ -20,6 +20,13 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
Label* const if_ismodified);
protected:
// Allocate a RegExpResult with the given length (the number of captures,
// including the match itself), index (the index where the match starts),
// and input string. |length| and |index| are expected to be tagged, and
// |input| must be a string.
Node* AllocateRegExpResult(Node* context, Node* length, Node* index,
Node* input);
Node* FastLoadLastIndex(Node* regexp);
Node* SlowLoadLastIndex(Node* context, Node* regexp);
Node* LoadLastIndex(Node* context, Node* regexp, bool is_fastpath);
......
......@@ -2208,54 +2208,6 @@ Node* CodeStubAssembler::NewConsString(Node* context, Node* length, Node* left,
return result.value();
}
Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length,
Node* index, Node* input) {
CSA_ASSERT(this, IsFixedArray(context));
CSA_ASSERT(this, TaggedIsSmi(index));
CSA_ASSERT(this, TaggedIsSmi(length));
CSA_ASSERT(this, IsString(input));
#ifdef DEBUG
Node* const max_length = SmiConstant(JSArray::kInitialMaxFastElementArray);
CSA_ASSERT(this, SmiLessThanOrEqual(length, max_length));
#endif // DEBUG
// Allocate the JSRegExpResult.
// TODO(jgruber): Fold JSArray and FixedArray allocations, then remove
// unneeded store of elements.
Node* const result = Allocate(JSRegExpResult::kSize);
// TODO(jgruber): Store map as Heap constant?
Node* const native_context = LoadNativeContext(context);
Node* const map =
LoadContextElement(native_context, Context::REGEXP_RESULT_MAP_INDEX);
StoreMapNoWriteBarrier(result, map);
// Initialize the header before allocating the elements.
Node* const empty_array = EmptyFixedArrayConstant();
DCHECK(Heap::RootIsImmortalImmovable(Heap::kEmptyFixedArrayRootIndex));
StoreObjectFieldNoWriteBarrier(result, JSArray::kPropertiesOrHashOffset,
empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset, empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kLengthOffset, length);
StoreObjectFieldNoWriteBarrier(result, JSRegExpResult::kIndexOffset, index);
StoreObjectField(result, JSRegExpResult::kInputOffset, input);
Node* const zero = IntPtrConstant(0);
Node* const length_intptr = SmiUntag(length);
const ElementsKind elements_kind = PACKED_ELEMENTS;
Node* const elements = AllocateFixedArray(elements_kind, length_intptr);
StoreObjectField(result, JSArray::kElementsOffset, elements);
// Fill in the elements with undefined.
FillFixedArrayWithValue(elements_kind, elements, zero, length_intptr,
Heap::kUndefinedValueRootIndex);
return result;
}
Node* CodeStubAssembler::AllocateNameDictionary(int at_least_space_for) {
return AllocateNameDictionary(IntPtrConstant(at_least_space_for));
}
......
......@@ -679,13 +679,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* NewConsString(Node* context, Node* length, Node* left, Node* right,
AllocationFlags flags = kNone);
// Allocate a RegExpResult with the given length (the number of captures,
// including the match itself), index (the index where the match starts),
// and input string. |length| and |index| are expected to be tagged, and
// |input| must be a string.
Node* AllocateRegExpResult(Node* context, Node* length, Node* index,
Node* input);
Node* AllocateNameDictionary(int at_least_space_for);
Node* AllocateNameDictionary(Node* at_least_space_for);
Node* AllocateNameDictionaryWithCapacity(Node* capacity);
......
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