Bug 1602720 part 4 - Factor out jsop_initelem_array fast path code into initArrayElemTryFastPath. r=tcampbell

No change in behavior.

Differential Revision: https://phabricator.services.mozilla.com/D56533

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2019-12-11 08:29:04 +00:00
Родитель 15b7c0b5b7
Коммит d37d695d06
2 изменённых файлов: 61 добавлений и 35 удалений

Просмотреть файл

@ -7368,53 +7368,75 @@ AbortReasonOr<Ok> IonBuilder::jsop_initelem_inc() {
return resumeAfter(initElem);
}
AbortReasonOr<Ok> IonBuilder::jsop_initelem_array() {
MDefinition* value = current->pop();
MDefinition* obj = current->peek(-1);
AbortReasonOr<Ok> IonBuilder::initArrayElemTryFastPath(bool* emitted,
MDefinition* obj,
MDefinition* id,
MDefinition* value) {
MOZ_ASSERT(*emitted == false);
MOZ_ASSERT(*pc == JSOP_INITELEM_ARRAY);
// Make sure that arrays have the type being written to them by the
// intializer, and that arrays are marked as non-packed when writing holes
// to them during initialization.
bool needStub = false;
if (!obj->isNewArray() || shouldAbortOnPreliminaryGroups(obj)) {
needStub = true;
} else if (!obj->resultTypeSet() || obj->resultTypeSet()->unknownObject() ||
obj->resultTypeSet()->getObjectCount() != 1) {
needStub = true;
} else {
MOZ_ASSERT(obj->resultTypeSet()->getObjectCount() == 1);
TypeSet::ObjectKey* initializer = obj->resultTypeSet()->getObject(0);
if (value->type() == MIRType::MagicHole) {
if (!initializer->hasFlags(constraints(), OBJECT_FLAG_NON_PACKED)) {
needStub = true;
}
} else if (!initializer->unknownProperties()) {
HeapTypeSetKey elemTypes = initializer->property(JSID_VOID);
if (!TypeSetIncludes(elemTypes.maybeTypes(), value->type(),
value->resultTypeSet())) {
elemTypes.freeze(constraints());
needStub = true;
}
if (!obj->isNewArray()) {
return Ok();
}
if (shouldAbortOnPreliminaryGroups(obj)) {
return Ok();
}
if (!obj->resultTypeSet() || obj->resultTypeSet()->unknownObject() ||
obj->resultTypeSet()->getObjectCount() != 1) {
return Ok();
}
TypeSet::ObjectKey* initializer = obj->resultTypeSet()->getObject(0);
if (value->type() == MIRType::MagicHole) {
if (!initializer->hasFlags(constraints(), OBJECT_FLAG_NON_PACKED)) {
return Ok();
}
} else if (!initializer->unknownProperties()) {
HeapTypeSetKey elemTypes = initializer->property(JSID_VOID);
if (!TypeSetIncludes(elemTypes.maybeTypes(), value->type(),
value->resultTypeSet())) {
elemTypes.freeze(constraints());
return Ok();
}
}
MOZ_TRY(initArrayElementFastPath(obj->toNewArray(), id, value,
/* addResumePoint = */ true));
*emitted = true;
return Ok();
}
AbortReasonOr<Ok> IonBuilder::jsop_initelem_array() {
MDefinition* value = current->pop();
MDefinition* obj = current->peek(-1);
uint32_t index = GET_UINT32(pc);
if (needStub) {
MOZ_ASSERT(index <= INT32_MAX,
"the bytecode emitter must fail to compile code that would "
"produce JSOP_INITELEM_ARRAY with an index exceeding "
"int32_t range");
MCallInitElementArray* store =
MCallInitElementArray::New(alloc(), obj, constantInt(index), value);
current->add(store);
return resumeAfter(store);
}
MOZ_ASSERT(index <= INT32_MAX,
"the bytecode emitter must fail to compile code that would "
"produce JSOP_INITELEM_ARRAY with an index exceeding "
"int32_t range");
bool emitted = false;
MConstant* id = MConstant::New(alloc(), Int32Value(index));
current->add(id);
return initArrayElementFastPath(obj->toNewArray(), id, value,
/* addResumePoint = */ true);
MOZ_TRY(initArrayElemTryFastPath(&emitted, obj, id, value));
if (emitted) {
return Ok();
}
MCallInitElementArray* store =
MCallInitElementArray::New(alloc(), obj, id, value);
current->add(store);
return resumeAfter(store);
}
AbortReasonOr<Ok> IonBuilder::initArrayElementFastPath(

Просмотреть файл

@ -611,6 +611,10 @@ class IonBuilder : public MIRGenerator,
TypedObjectPrediction objTypeReprs, MDefinition* value,
TypedObjectPrediction elemTypeReprs, uint32_t elemSize);
AbortReasonOr<Ok> initArrayElemTryFastPath(bool* emitted, MDefinition* obj,
MDefinition* id,
MDefinition* value);
AbortReasonOr<Ok> initArrayElementFastPath(
MNewArray* obj, MDefinition* id, MDefinition* value,
bool addResumePointAndIncrementInitializedLength);