Bug 1531820 - Use ValueType for CacheIR guardType. r=mgaudet
authorTom Schuster <evilpies@gmail.com>
Fri, 01 Mar 2019 17:28:43 +0000
changeset 461972 a59b3f861c7d988f0de8384ded27558da16be3dc
parent 461971 666070099fbabe3160da0b468dde6b9130f71262
child 461973 f4ec35c8165ffde437c749537af1793c9f86abbf
push id35634
push userrmaries@mozilla.com
push dateSat, 02 Mar 2019 09:26:10 +0000
treeherdermozilla-central@4166cae81546 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1531820
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531820 - Use ValueType for CacheIR guardType. r=mgaudet Differential Revision: https://phabricator.services.mozilla.com/D21721
js/src/jit/BaselineCacheIRCompiler.cpp
js/src/jit/BaselineInspector.cpp
js/src/jit/CacheIR.cpp
js/src/jit/CacheIR.h
js/src/jit/CacheIRCompiler.cpp
js/src/jit/IonCacheIRCompiler.cpp
--- a/js/src/jit/BaselineCacheIRCompiler.cpp
+++ b/js/src/jit/BaselineCacheIRCompiler.cpp
@@ -716,17 +716,17 @@ bool BaselineCacheIRCompiler::emitCallNa
 }
 
 bool BaselineCacheIRCompiler::emitLoadUnboxedPropertyResult() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   AutoOutputRegister output(*this);
   Register obj = allocator.useRegister(masm, reader.objOperandId());
   AutoScratchRegisterMaybeOutput scratch(allocator, masm, output);
 
-  JSValueType fieldType = reader.valueType();
+  JSValueType fieldType = reader.jsValueType();
   Address fieldOffset(stubAddress(reader.stubOffset()));
   masm.load32(fieldOffset, scratch);
   masm.loadUnboxedProperty(BaseIndex(obj, scratch, TimesOne), fieldType,
                            output);
   return true;
 }
 
 bool BaselineCacheIRCompiler::emitGuardFrameHasNoArgumentsObject() {
@@ -1161,17 +1161,17 @@ bool BaselineCacheIRCompiler::emitAddAnd
 bool BaselineCacheIRCompiler::emitAllocateAndStoreDynamicSlot() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   return emitAddAndStoreSlotShared(CacheOp::AllocateAndStoreDynamicSlot);
 }
 
 bool BaselineCacheIRCompiler::emitStoreUnboxedProperty() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   ObjOperandId objId = reader.objOperandId();
-  JSValueType fieldType = reader.valueType();
+  JSValueType fieldType = reader.jsValueType();
   Address offsetAddr = stubAddress(reader.stubOffset());
 
   // Allocate the fixed registers first. These need to be fixed for
   // callTypeUpdateIC.
   AutoScratchRegister scratch(allocator, masm, R1.scratchReg());
   ValueOperand val =
       allocator.useFixedValueRegister(masm, reader.valOperandId(), R0);
 
--- a/js/src/jit/BaselineInspector.cpp
+++ b/js/src/jit/BaselineInspector.cpp
@@ -1657,18 +1657,18 @@ static MIRType GetCacheIRExpectedInputTy
   }
   if (reader.matchOp(CacheOp::GuardIsString, ValOperandId(0))) {
     return MIRType::String;
   }
   if (reader.matchOp(CacheOp::GuardIsNumber, ValOperandId(0))) {
     return MIRType::Double;
   }
   if (reader.matchOp(CacheOp::GuardType, ValOperandId(0))) {
-    JSValueType type = reader.valueType();
-    return MIRTypeFromValueType(type);
+    ValueType type = reader.valueType();
+    return MIRTypeFromValueType(JSValueType(type));
   }
 
   MOZ_ASSERT_UNREACHABLE("Unexpected instruction");
   return MIRType::Value;
 }
 
 MIRType BaselineInspector::expectedPropertyAccessInputType(jsbytecode* pc) {
   if (!hasICScript()) {
--- a/js/src/jit/CacheIR.cpp
+++ b/js/src/jit/CacheIR.cpp
@@ -1608,17 +1608,17 @@ static void CheckDOMProxyExpandoDoesNotS
         writer.loadDOMExpandoValueGuardGeneration(objId, expandoAndGeneration);
     expandoVal = expandoAndGeneration->expando;
   } else {
     expandoId = writer.loadDOMExpandoValue(objId);
   }
 
   if (expandoVal.isUndefined()) {
     // Guard there's no expando object.
-    writer.guardType(expandoId, JSVAL_TYPE_UNDEFINED);
+    writer.guardType(expandoId, ValueType::Undefined);
   } else if (expandoVal.isObject()) {
     // Guard the proxy either has no expando object or, if it has one, that
     // the shape matches the current expando object.
     NativeObject& expandoObj = expandoVal.toObject().as<NativeObject>();
     MOZ_ASSERT(!expandoObj.containsPure(id));
     writer.guardDOMExpandoMissingOrGuardShape(expandoId,
                                               expandoObj.lastProperty());
   } else {
@@ -2028,17 +2028,17 @@ bool GetPropIRGenerator::tryAttachPrimit
     if (IsIonEnabled(cx_)) {
       EnsureTrackPropertyTypes(cx_, holder, id);
     }
   }
 
   if (val_.isNumber()) {
     writer.guardIsNumber(valId);
   } else {
-    writer.guardType(valId, val_.extractNonDoubleType());
+    writer.guardType(valId, val_.type());
   }
   maybeEmitIdGuard(id);
 
   ObjOperandId protoId = writer.loadObject(proto);
   EmitReadSlotResult(writer, proto, holder, shape, protoId);
   EmitReadSlotReturn(writer, proto, holder, shape);
 
   trackAttached("Primitive");
@@ -3649,17 +3649,18 @@ bool SetPropIRGenerator::tryAttachUnboxe
 
 static void EmitGuardUnboxedPropertyType(CacheIRWriter& writer,
                                          JSValueType propType,
                                          ValOperandId valId) {
   if (propType == JSVAL_TYPE_OBJECT) {
     // Unboxed objects store NullValue as nullptr object.
     writer.guardIsObjectOrNull(valId);
   } else {
-    writer.guardType(valId, propType);
+    MOZ_ASSERT(propType <= JSVAL_TYPE_OBJECT);
+    writer.guardType(valId, ValueType(propType));
   }
 }
 
 bool SetPropIRGenerator::tryAttachUnboxedProperty(HandleObject obj,
                                                   ObjOperandId objId,
                                                   HandleId id,
                                                   ValOperandId rhsId) {
   if (!obj->is<UnboxedPlainObject>()) {
@@ -3749,17 +3750,17 @@ bool SetPropIRGenerator::tryAttachTypedO
   ReferenceType type = fieldDescr->as<ReferenceTypeDescr>().type();
   switch (type) {
     case ReferenceType::TYPE_ANY:
       break;
     case ReferenceType::TYPE_OBJECT:
       writer.guardIsObjectOrNull(rhsId);
       break;
     case ReferenceType::TYPE_STRING:
-      writer.guardType(rhsId, JSVAL_TYPE_STRING);
+      writer.guardType(rhsId, ValueType::String);
       break;
     case ReferenceType::TYPE_WASM_ANYREF:
       MOZ_CRASH();
   }
 
   writer.storeTypedObjectReferenceProperty(objId, fieldOffset, layout, type,
                                            rhsId);
   writer.returnFromIC();
@@ -4868,17 +4869,17 @@ bool TypeOfIRGenerator::tryAttachStub() 
 bool TypeOfIRGenerator::tryAttachPrimitive(ValOperandId valId) {
   if (!val_.isPrimitive()) {
     return false;
   }
 
   if (val_.isNumber()) {
     writer.guardIsNumber(valId);
   } else {
-    writer.guardType(valId, val_.extractNonDoubleType());
+    writer.guardType(valId, val_.type());
   }
 
   writer.loadStringResult(TypeName(js::TypeOfValue(val_), cx_->names()));
   writer.returnFromIC();
   trackAttached("Primitive");
   return true;
 }
 
@@ -5750,43 +5751,43 @@ bool ToBoolIRGenerator::tryAttachStub() 
 }
 
 bool ToBoolIRGenerator::tryAttachInt32() {
   if (!val_.isInt32()) {
     return false;
   }
 
   ValOperandId valId(writer.setInputOperandId(0));
-  writer.guardType(valId, JSVAL_TYPE_INT32);
+  writer.guardType(valId, ValueType::Int32);
   writer.loadInt32TruthyResult(valId);
   writer.returnFromIC();
   trackAttached("ToBoolInt32");
   return true;
 }
 
 bool ToBoolIRGenerator::tryAttachDouble() {
   if (!val_.isDouble()) {
     return false;
   }
 
   ValOperandId valId(writer.setInputOperandId(0));
-  writer.guardType(valId, JSVAL_TYPE_DOUBLE);
+  writer.guardType(valId, ValueType::Double);
   writer.loadDoubleTruthyResult(valId);
   writer.returnFromIC();
   trackAttached("ToBoolDouble");
   return true;
 }
 
 bool ToBoolIRGenerator::tryAttachSymbol() {
   if (!val_.isSymbol()) {
     return false;
   }
 
   ValOperandId valId(writer.setInputOperandId(0));
-  writer.guardType(valId, JSVAL_TYPE_SYMBOL);
+  writer.guardType(valId, ValueType::Symbol);
   writer.loadBooleanResult(true);
   writer.returnFromIC();
   trackAttached("ToBoolSymbol");
   return true;
 }
 
 bool ToBoolIRGenerator::tryAttachString() {
   if (!val_.isString()) {
@@ -6026,17 +6027,17 @@ bool BinaryArithIRGenerator::tryAttachBi
   auto guardToInt32 = [&](ValOperandId id, HandleValue val) {
     if (val.isInt32()) {
       return writer.guardIsInt32(id);
     }
     if (val.isBoolean()) {
       return writer.guardIsBoolean(id);
     }
     MOZ_ASSERT(val.isDouble());
-    writer.guardType(id, JSVAL_TYPE_DOUBLE);
+    writer.guardType(id, ValueType::Double);
     return writer.truncateDoubleToUInt32(id);
   };
 
   Int32OperandId lhsIntId = guardToInt32(lhsId, lhs_);
   Int32OperandId rhsIntId = guardToInt32(rhsId, rhs_);
 
   switch (op_) {
     case JSOP_BITOR:
--- a/js/src/jit/CacheIR.h
+++ b/js/src/jit/CacheIR.h
@@ -642,20 +642,20 @@ class MOZ_RAII CacheIRWriter : public JS
     Int32OperandId res(nextOperandId_++);
     writeOpWithOperandId(CacheOp::GuardIsInt32Index, val);
     writeOperandId(res);
     return res;
   }
   void guardIsNumber(ValOperandId val) {
     writeOpWithOperandId(CacheOp::GuardIsNumber, val);
   }
-  void guardType(ValOperandId val, JSValueType type) {
+  void guardType(ValOperandId val, ValueType type) {
     writeOpWithOperandId(CacheOp::GuardType, val);
     static_assert(sizeof(type) == sizeof(uint8_t),
-                  "JSValueType should fit in a byte");
+                  "JS::ValueType should fit in a byte");
     buffer_.writeByte(uint32_t(type));
   }
   void guardIsObjectOrNull(ValOperandId val) {
     writeOpWithOperandId(CacheOp::GuardIsObjectOrNull, val);
   }
   void guardIsNullOrUndefined(ValOperandId val) {
     writeOpWithOperandId(CacheOp::GuardIsNullOrUndefined, val);
   }
@@ -1488,17 +1488,18 @@ class MOZ_RAII CacheIRReader {
   }
   SymbolOperandId symbolOperandId() {
     return SymbolOperandId(buffer_.readByte());
   }
   Int32OperandId int32OperandId() { return Int32OperandId(buffer_.readByte()); }
 
   uint32_t stubOffset() { return buffer_.readByte() * sizeof(uintptr_t); }
   GuardClassKind guardClassKind() { return GuardClassKind(buffer_.readByte()); }
-  JSValueType valueType() { return JSValueType(buffer_.readByte()); }
+  JSValueType jsValueType() { return JSValueType(buffer_.readByte()); }
+  ValueType valueType() { return ValueType(buffer_.readByte()); }
   TypedThingLayout typedThingLayout() {
     return TypedThingLayout(buffer_.readByte());
   }
   Scalar::Type scalarType() { return Scalar::Type(buffer_.readByte()); }
   uint32_t typeDescrKey() { return buffer_.readByte(); }
   JSWhyMagic whyMagic() { return JSWhyMagic(buffer_.readByte()); }
   JSOp jsop() { return JSOp(buffer_.readByte()); }
   int32_t int32Immediate() { return int32_t(buffer_.readFixedUint32_t()); }
--- a/js/src/jit/CacheIRCompiler.cpp
+++ b/js/src/jit/CacheIRCompiler.cpp
@@ -1564,56 +1564,58 @@ bool CacheIRCompiler::emitGuardIsInt32In
 
   masm.bind(&done);
   return true;
 }
 
 bool CacheIRCompiler::emitGuardType() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   ValOperandId inputId = reader.valOperandId();
-  JSValueType type = reader.valueType();
-
-  if (allocator.knownType(inputId) == type) {
+  ValueType type = reader.valueType();
+
+  if (allocator.knownType(inputId) == JSValueType(type)) {
     return true;
   }
 
   ValueOperand input = allocator.useValueRegister(masm, inputId);
 
   FailurePath* failure;
   if (!addFailurePath(&failure)) {
     return false;
   }
 
   switch (type) {
-    case JSVAL_TYPE_STRING:
+    case ValueType::String:
       masm.branchTestString(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_SYMBOL:
+    case ValueType::Symbol:
       masm.branchTestSymbol(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_BIGINT:
+    case ValueType::BigInt:
       masm.branchTestBigInt(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_INT32:
+    case ValueType::Int32:
       masm.branchTestInt32(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_DOUBLE:
+    case ValueType::Double:
       masm.branchTestDouble(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_BOOLEAN:
+    case ValueType::Boolean:
       masm.branchTestBoolean(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_UNDEFINED:
+    case ValueType::Undefined:
       masm.branchTestUndefined(Assembler::NotEqual, input, failure->label());
       break;
-    case JSVAL_TYPE_NULL:
+    case ValueType::Null:
       masm.branchTestNull(Assembler::NotEqual, input, failure->label());
       break;
-    default:
-      MOZ_CRASH("Unexpected type");
+    case ValueType::Magic:
+    case ValueType::PrivateGCThing:
+    case ValueType::Object:
+      MOZ_CRASH("unexpected type");
   }
 
   return true;
 }
 
 bool CacheIRCompiler::emitGuardClass() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   ObjOperandId objId = reader.objOperandId();
--- a/js/src/jit/IonCacheIRCompiler.cpp
+++ b/js/src/jit/IonCacheIRCompiler.cpp
@@ -1208,17 +1208,17 @@ bool IonCacheIRCompiler::emitCallNativeG
   return true;
 }
 
 bool IonCacheIRCompiler::emitLoadUnboxedPropertyResult() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   AutoOutputRegister output(*this);
   Register obj = allocator.useRegister(masm, reader.objOperandId());
 
-  JSValueType fieldType = reader.valueType();
+  JSValueType fieldType = reader.jsValueType();
   int32_t fieldOffset = int32StubField(reader.stubOffset());
   masm.loadUnboxedProperty(Address(obj, fieldOffset), fieldType, output);
   return true;
 }
 
 bool IonCacheIRCompiler::emitGuardFrameHasNoArgumentsObject() {
   MOZ_CRASH("Baseline-specific op");
 }
@@ -1666,17 +1666,17 @@ bool IonCacheIRCompiler::emitAddAndStore
 bool IonCacheIRCompiler::emitAllocateAndStoreDynamicSlot() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   return emitAddAndStoreSlotShared(CacheOp::AllocateAndStoreDynamicSlot);
 }
 
 bool IonCacheIRCompiler::emitStoreUnboxedProperty() {
   JitSpew(JitSpew_Codegen, __FUNCTION__);
   Register obj = allocator.useRegister(masm, reader.objOperandId());
-  JSValueType fieldType = reader.valueType();
+  JSValueType fieldType = reader.jsValueType();
   int32_t offset = int32StubField(reader.stubOffset());
   ConstantOrRegister val =
       allocator.useConstantOrRegister(masm, reader.valOperandId());
 
   Maybe<AutoScratchRegister> scratch;
   if (needsPostBarrier() && UnboxedTypeNeedsPostBarrier(fieldType)) {
     scratch.emplace(allocator, masm);
   }