Commit 84ff6db7 authored by Jan de Mooij's avatar Jan de Mooij
Browse files

Bug 1322093 part 3 - Optimize type guards if we know they always succeed. r=nbp

parent c502c460
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -203,7 +203,11 @@ BaselineCacheIRCompiler::compile()
bool
BaselineCacheIRCompiler::emitGuardIsInt32()
{
    ValueOperand input = allocator.useValueRegister(masm, reader.valOperandId());
    ValOperandId inputId = reader.valOperandId();
    if (allocator.knownType(inputId) == JSVAL_TYPE_INT32)
        return true;

    ValueOperand input = allocator.useValueRegister(masm, inputId);
    AutoScratchRegister scratch(allocator, masm);

    FailurePath* failure;
@@ -233,9 +237,14 @@ BaselineCacheIRCompiler::emitGuardIsInt32()
bool
BaselineCacheIRCompiler::emitGuardType()
{
    ValueOperand input = allocator.useValueRegister(masm, reader.valOperandId());
    ValOperandId inputId = reader.valOperandId();
    JSValueType type = reader.valueType();

    if (allocator.knownType(inputId) == type)
        return true;

    ValueOperand input = allocator.useValueRegister(masm, inputId);

    FailurePath* failure;
    if (!addFailurePath(&failure))
        return false;
+36 −3
Original line number Diff line number Diff line
@@ -292,6 +292,27 @@ CacheRegisterAllocator::init(const AllocatableGeneralRegisterSet& available)
    return true;
}

JSValueType
CacheRegisterAllocator::knownType(ValOperandId val) const
{
    const OperandLocation& loc = operandLocations_[val.id()];

    switch (loc.kind()) {
      case OperandLocation::ValueReg:
      case OperandLocation::ValueStack:
        return JSVAL_TYPE_UNKNOWN;

      case OperandLocation::PayloadStack:
      case OperandLocation::PayloadReg:
        return loc.payloadType();

      case OperandLocation::Uninitialized:
        break;
    }

    MOZ_CRASH("Invalid kind");
}

size_t
CacheIRStubInfo::stubDataSize() const
{
@@ -654,7 +675,11 @@ CacheIRCompiler::emitFailurePath(size_t i)
bool
CacheIRCompiler::emitGuardIsObject()
{
    ValueOperand input = allocator.useValueRegister(masm, reader.valOperandId());
    ValOperandId inputId = reader.valOperandId();
    if (allocator.knownType(inputId) == JSVAL_TYPE_OBJECT)
        return true;

    ValueOperand input = allocator.useValueRegister(masm, inputId);
    FailurePath* failure;
    if (!addFailurePath(&failure))
        return false;
@@ -665,7 +690,11 @@ CacheIRCompiler::emitGuardIsObject()
bool
CacheIRCompiler::emitGuardIsString()
{
    ValueOperand input = allocator.useValueRegister(masm, reader.valOperandId());
    ValOperandId inputId = reader.valOperandId();
    if (allocator.knownType(inputId) == JSVAL_TYPE_STRING)
        return true;

    ValueOperand input = allocator.useValueRegister(masm, inputId);
    FailurePath* failure;
    if (!addFailurePath(&failure))
        return false;
@@ -676,7 +705,11 @@ CacheIRCompiler::emitGuardIsString()
bool
CacheIRCompiler::emitGuardIsSymbol()
{
    ValueOperand input = allocator.useValueRegister(masm, reader.valOperandId());
    ValOperandId inputId = reader.valOperandId();
    if (allocator.knownType(inputId) == JSVAL_TYPE_SYMBOL)
        return true;

    ValueOperand input = allocator.useValueRegister(masm, inputId);
    FailurePath* failure;
    if (!addFailurePath(&failure))
        return false;
+3 −0
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ class MOZ_RAII CacheRegisterAllocator
    // Allocates an output register for the given operand.
    Register defineRegister(MacroAssembler& masm, TypedOperandId typedId);
    ValueOperand defineValueRegister(MacroAssembler& masm, ValOperandId val);

    // Returns |val|'s JSValueType or JSVAL_TYPE_UNKNOWN.
    JSValueType knownType(ValOperandId val) const;
};

// RAII class to allocate a scratch register and release it when we're done