Bug 1205707 part 1 - Clean up some is-TypedArrayObject code in Ion. r=Waldo, a=sylvestre
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 28 Sep 2015 13:30:42 +0200
changeset 296190 e8c15469d5936cd61a606f3f0ad464e97202e6b5
parent 296189 b6390a198cbb6d64a0aafb5305e3bc70bda2df08
child 296191 78d0438bcb818227de4b5fd263b631c786d10124
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo, sylvestre
bugs1205707
milestone43.0a2
Bug 1205707 part 1 - Clean up some is-TypedArrayObject code in Ion. r=Waldo, a=sylvestre
js/src/jit/MCallOptimize.cpp
--- a/js/src/jit/MCallOptimize.cpp
+++ b/js/src/jit/MCallOptimize.cpp
@@ -2159,28 +2159,43 @@ IonBuilder::inlineIsTypedArray(CallInfo&
 }
 
 IonBuilder::InliningStatus
 IonBuilder::inlineIsPossiblyWrappedTypedArray(CallInfo& callInfo)
 {
     return inlineIsTypedArrayHelper(callInfo, AllowWrappedTypedArrays);
 }
 
+static bool
+IsTypedArrayObject(CompilerConstraintList* constraints, MDefinition* def)
+{
+    MOZ_ASSERT(def->type() == MIRType_Object);
+
+    TemporaryTypeSet* types = def->resultTypeSet();
+    if (!types)
+        return false;
+
+    return types->forAllClasses(constraints, IsTypedArrayClass) ==
+           TemporaryTypeSet::ForAllResult::ALL_TRUE;
+}
+
 IonBuilder::InliningStatus
 IonBuilder::inlineTypedArrayLength(CallInfo& callInfo)
 {
     MOZ_ASSERT(!callInfo.constructing());
     MOZ_ASSERT(callInfo.argc() == 1);
     if (callInfo.getArg(0)->type() != MIRType_Object)
         return InliningStatus_NotInlined;
     if (getInlineReturnType() != MIRType_Int32)
         return InliningStatus_NotInlined;
 
-    // We assume that when calling this function we always
-    // have a TypedArray. The native asserts that as well.
+    // Note that the argument we see here is not necessarily a typed array.
+    // If it's not, this call should be unreachable though.
+    if (!IsTypedArrayObject(constraints(), callInfo.getArg(0)))
+        return InliningStatus_NotInlined;
 
     MInstruction* length = addTypedArrayLength(callInfo.getArg(0));
     current->push(length);
 
     callInfo.setImplicitlyUsedUnchecked();
     return InliningStatus_Inlined;
 }
 
@@ -2204,29 +2219,20 @@ IonBuilder::inlineSetDisjointTypedElemen
 
     MDefinition* sourceTypedArray = callInfo.getArg(2);
     if (sourceTypedArray->type() != MIRType_Object)
         return InliningStatus_NotInlined;
 
     // Only attempt to optimize if |target| and |sourceTypedArray| are both
     // definitely typed arrays.  (The former always is.  The latter is not,
     // necessarily, because of wrappers.)
-
-    MDefinition* arrays[] = { target, sourceTypedArray };
-
-    for (MDefinition* def : arrays) {
-        TemporaryTypeSet* types = def->resultTypeSet();
-        if (!types)
-            return InliningStatus_NotInlined;
-
-        if (types->forAllClasses(constraints(), IsTypedArrayClass) !=
-            TemporaryTypeSet::ForAllResult::ALL_TRUE)
-        {
-            return InliningStatus_NotInlined;
-        }
+    if (!IsTypedArrayObject(constraints(), target) ||
+        !IsTypedArrayObject(constraints(), sourceTypedArray))
+    {
+        return InliningStatus_NotInlined;
     }
 
     auto sets = MSetDisjointTypedElements::New(alloc(), target, targetOffset, sourceTypedArray);
     current->add(sets);
 
     pushConstant(UndefinedValue());
 
     if (!resumeAfter(sets))