Commit 22881b41 authored by jgruber's avatar jgruber Committed by Commit bot

[regexp] Port RegExpConstructResultStub to TurboFan

The old hydrogen stub (and runtime fallback) are still needed while they are
used in regexp.js.  These will go away once affected code has been ported.

Drive-by-fix: Fixed typo in GetFixedA{a,}rrayAllocationSize.

BUG=v8:5339

Review-Url: https://codereview.chromium.org/2384473002
Cr-Commit-Position: refs/heads/master@{#39952}
parent 7d26871d
...@@ -92,9 +92,6 @@ compiler::Node* ConstructNewResultFromMatchInfo(Isolate* isolate, ...@@ -92,9 +92,6 @@ compiler::Node* ConstructNewResultFromMatchInfo(Isolate* isolate,
Label out(a); Label out(a);
Callable constructresult_callable =
CodeFactory::RegExpConstructResult(isolate);
CodeStubAssembler::ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS; CodeStubAssembler::ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS;
Node* const num_indices = a->SmiUntag(a->LoadFixedArrayElement( Node* const num_indices = a->SmiUntag(a->LoadFixedArrayElement(
match_elements, a->IntPtrConstant(RegExpImpl::kLastCaptureCount), 0, match_elements, a->IntPtrConstant(RegExpImpl::kLastCaptureCount), 0,
...@@ -110,8 +107,8 @@ compiler::Node* ConstructNewResultFromMatchInfo(Isolate* isolate, ...@@ -110,8 +107,8 @@ compiler::Node* ConstructNewResultFromMatchInfo(Isolate* isolate,
// to avoid an unnecessary write barrier storing the first result. // to avoid an unnecessary write barrier storing the first result.
Node* const first = a->SubString(context, string, start, end); Node* const first = a->SubString(context, string, start, end);
Node* const result = a->CallStub(constructresult_callable, context, Node* const result =
num_results, start, string); a->AllocateRegExpResult(context, num_results, start, string);
Node* const result_elements = a->LoadElements(result); Node* const result_elements = a->LoadElements(result);
a->StoreFixedArrayElement(result_elements, a->IntPtrConstant(0), first, a->StoreFixedArrayElement(result_elements, a->IntPtrConstant(0), first,
......
...@@ -1318,6 +1318,50 @@ Node* CodeStubAssembler::AllocateSlicedTwoByteString(Node* length, Node* parent, ...@@ -1318,6 +1318,50 @@ Node* CodeStubAssembler::AllocateSlicedTwoByteString(Node* length, Node* parent,
return result; return result;
} }
Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length,
Node* index, Node* input) {
Node* const max_length =
SmiConstant(Smi::FromInt(JSArray::kInitialMaxFastElementArray));
Assert(SmiLessThanOrEqual(length, max_length));
// 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::kPropertiesOffset,
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 = FAST_ELEMENTS;
const ParameterMode parameter_mode = INTPTR_PARAMETERS;
Node* const elements =
AllocateFixedArray(elements_kind, length_intptr, parameter_mode);
StoreObjectField(result, JSArray::kElementsOffset, elements);
// Fill in the elements with undefined.
FillFixedArrayWithValue(elements_kind, elements, zero, length_intptr,
Heap::kUndefinedValueRootIndex, parameter_mode);
return result;
}
Node* CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements( Node* CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements(
ElementsKind kind, Node* array_map, Node* length, Node* allocation_site) { ElementsKind kind, Node* array_map, Node* length, Node* allocation_site) {
Comment("begin allocation of JSArray without elements"); Comment("begin allocation of JSArray without elements");
...@@ -1408,7 +1452,7 @@ Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind, ...@@ -1408,7 +1452,7 @@ Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind,
Node* capacity_node, Node* capacity_node,
ParameterMode mode, ParameterMode mode,
AllocationFlags flags) { AllocationFlags flags) {
Node* total_size = GetFixedAarrayAllocationSize(capacity_node, kind, mode); Node* total_size = GetFixedArrayAllocationSize(capacity_node, kind, mode);
// Allocate both array and elements object, and initialize the JSArray. // Allocate both array and elements object, and initialize the JSArray.
Node* array = Allocate(total_size, flags); Node* array = Allocate(total_size, flags);
......
...@@ -28,6 +28,7 @@ enum class UnicodeEncoding { ...@@ -28,6 +28,7 @@ enum class UnicodeEncoding {
#define HEAP_CONSTANT_LIST(V) \ #define HEAP_CONSTANT_LIST(V) \
V(BooleanMap, BooleanMap) \ V(BooleanMap, BooleanMap) \
V(empty_string, EmptyString) \ V(empty_string, EmptyString) \
V(EmptyFixedArray, EmptyFixedArray) \
V(FixedArrayMap, FixedArrayMap) \ V(FixedArrayMap, FixedArrayMap) \
V(FixedCOWArrayMap, FixedCOWArrayMap) \ V(FixedCOWArrayMap, FixedCOWArrayMap) \
V(FixedDoubleArrayMap, FixedDoubleArrayMap) \ V(FixedDoubleArrayMap, FixedDoubleArrayMap) \
...@@ -355,6 +356,15 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -355,6 +356,15 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* parent, compiler::Node* parent,
compiler::Node* offset); compiler::Node* offset);
// 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.
compiler::Node* AllocateRegExpResult(compiler::Node* context,
compiler::Node* length,
compiler::Node* index,
compiler::Node* input);
// Allocate a JSArray without elements and initialize the header fields. // Allocate a JSArray without elements and initialize the header fields.
compiler::Node* AllocateUninitializedJSArrayWithoutElements( compiler::Node* AllocateUninitializedJSArrayWithoutElements(
ElementsKind kind, compiler::Node* array_map, compiler::Node* length, ElementsKind kind, compiler::Node* array_map, compiler::Node* length,
...@@ -814,7 +824,7 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -814,7 +824,7 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* CreateAllocationSiteInFeedbackVector( compiler::Node* CreateAllocationSiteInFeedbackVector(
compiler::Node* feedback_vector, compiler::Node* slot); compiler::Node* feedback_vector, compiler::Node* slot);
compiler::Node* GetFixedAarrayAllocationSize(compiler::Node* element_count, compiler::Node* GetFixedArrayAllocationSize(compiler::Node* element_count,
ElementsKind kind, ElementsKind kind,
ParameterMode mode) { ParameterMode mode) {
return ElementOffsetFromIndex(element_count, kind, mode, return ElementOffsetFromIndex(element_count, kind, mode,
......
...@@ -2067,7 +2067,7 @@ class RegExpExecStub: public PlatformCodeStub { ...@@ -2067,7 +2067,7 @@ class RegExpExecStub: public PlatformCodeStub {
DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
}; };
// TODO(jgruber): Remove this once all uses in regexp.js have been removed.
class RegExpConstructResultStub final : public HydrogenCodeStub { class RegExpConstructResultStub final : public HydrogenCodeStub {
public: public:
explicit RegExpConstructResultStub(Isolate* isolate) explicit RegExpConstructResultStub(Isolate* isolate)
......
...@@ -794,7 +794,7 @@ RUNTIME_FUNCTION(Runtime_RegExpSource) { ...@@ -794,7 +794,7 @@ RUNTIME_FUNCTION(Runtime_RegExpSource) {
return regexp->source(); return regexp->source();
} }
// TODO(jgruber): Remove this once all uses in regexp.js have been removed.
RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { RUNTIME_FUNCTION(Runtime_RegExpConstructResult) {
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
DCHECK(args.length() == 3); DCHECK(args.length() == 3);
......
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