Bug 1015205 - Part 1: Let MToString work on all types (bails for MIRType_Object) r=bbouvier

This commit is contained in:
Wes Kocher committed 2014-05-27 15:18:51 -07:00
1 parent 40750ae522
commit 1567156ade
8 files changed
+70 -35

No files matched your search

+13 -4
View File
@@ -859,9 +859,9 @@ static const VMFunctionsModal PrimitiveToStringInfo = VMFunctionsModal(
FunctionInfo<PrimitiveToStringParFn>(PrimitiveToStringPar));
bool
CodeGenerator::visitPrimitiveToString(LPrimitiveToString *lir)
CodeGenerator::visitValueToString(LValueToString *lir)
{
ValueOperand input = ToValue(lir, LPrimitiveToString::Input);
ValueOperand input = ToValue(lir, LValueToString::Input);
Register output = ToRegister(lir->output());
OutOfLineCode *ool = oolCallVM(PrimitiveToStringInfo, lir, (ArgList(), input),
@@ -931,9 +931,18 @@ CodeGenerator::visitPrimitiveToString(LPrimitiveToString *lir)
masm.bind(&notBoolean);
}
// Object
if (lir->mir()->input()->mightBeType(MIRType_Object)) {
// Bail.
JS_ASSERT(lir->mir()->fallible());
Label bail;
masm.branchTestObject(Assembler::Equal, tag, &bail);
if (!bailoutFrom(&bail, lir->snapshot()))
return false;
}
#ifdef DEBUG
// Objects are not supported or we see a type that wasn't accounted for.
masm.assumeUnreachable("Unexpected type for MPrimitiveToString.");
masm.assumeUnreachable("Unexpected type for MValueToString.");
#endif
masm.bind(&done);
+1 -1
View File
@@ -93,7 +93,7 @@ class CodeGenerator : public CodeGeneratorSpecific
void emitIntToString(Register input, Register output, Label *ool);
bool visitIntToString(LIntToString *lir);
bool visitDoubleToString(LDoubleToString *lir);
bool visitPrimitiveToString(LPrimitiveToString *lir);
bool visitValueToString(LValueToString *lir);
bool visitInteger(LInteger *lir);
bool visitRegExp(LRegExp *lir);
bool visitRegExpExec(LRegExpExec *lir);
+3 -3
View File
@@ -3182,12 +3182,12 @@ class LDoubleToString : public LInstructionHelper<1, 1, 1>
};
// Convert a primitive to a string with a function call.
class LPrimitiveToString : public LInstructionHelper<1, BOX_PIECES, 1>
class LValueToString : public LInstructionHelper<1, BOX_PIECES, 1>
{
public:
LIR_HEADER(PrimitiveToString)
LIR_HEADER(ValueToString)
explicit LPrimitiveToString(const LDefinition &tempToUnbox)
LValueToString(const LDefinition &tempToUnbox))
{
setTemp(0, tempToUnbox);
}
+1 -1
View File
@@ -147,7 +147,7 @@
_(BooleanToString) \
_(IntToString) \
_(DoubleToString) \
_(PrimitiveToString) \
_(ValueToString) \
_(Start) \
_(OsrEntry) \
_(OsrValue) \
+8 -4
View File
@@ -1916,10 +1916,14 @@ LIRGenerator::visitToString(MToString *ins)
return assignSafepoint(lir, ins);
}
case MIRType_String:
return redefine(ins, ins->input());
case MIRType_Value: {
JS_ASSERT(!opd->mightBeType(MIRType_Object));
LPrimitiveToString *lir = new(alloc()) LPrimitiveToString(tempToUnbox());
if (!useBox(lir, LPrimitiveToString::Input, opd))
LValueToString *lir = new(alloc()) LValueToString(tempToUnbox());
if (!useBox(lir, LValueToString::Input, opd))
return false;
if (ins->fallible() && !assignSnapshot(lir))
return false;
if (!define(lir, ins))
return false;
@@ -1927,7 +1931,7 @@ LIRGenerator::visitToString(MToString *ins)
}
default:
// Objects might be effectful. (see ToPrimitive)
// Float32 and objects are not supported.
MOZ_ASSUME_UNREACHABLE("unexpected type");
}
}
+12 -8
View File
@@ -3362,17 +3362,13 @@ class MTruncateToInt32 : public MUnaryInstruction
};
// Converts any type to a string
class MToString : public MUnaryInstruction
class MToString :
public MUnaryInstruction,
public ToStringPolicy
{
explicit MToString(MDefinition *def)
: MUnaryInstruction(def)
{
// Converting an object to a string might be effectful.
JS_ASSERT(!def->mightBeType(MIRType_Object));
// NOP
JS_ASSERT(def->type() != MIRType_String);
setResultType(MIRType_String);
setMovable();
}
@@ -3386,13 +3382,21 @@ class MToString : public MUnaryInstruction
MDefinition *foldsTo(TempAllocator &alloc, bool useValueNumbers);
TypePolicy *typePolicy() {
return this;
}
bool congruentTo(const MDefinition *ins) const {
return congruentIfOperandsEqual(ins);
}
AliasSet getAliasSet() const {
JS_ASSERT(!input()->mightBeType(MIRType_Object));
return AliasSet::None();
}
bool fallible() const {
return input()->mightBeType(MIRType_Object);
}
};
class MBitNot
+21 -13
View File
@@ -416,21 +416,13 @@ ConvertToStringPolicy<Op>::staticAdjustInputs(TempAllocator &alloc, MInstruction
if (in->type() == MIRType_String)
return true;
MInstruction *replace;
if (in->mightBeType(MIRType_Object)) {
if (in->type() != MIRType_Value)
in = boxAt(alloc, ins, in);
replace = MUnbox::New(alloc, in, MIRType_String, MUnbox::Fallible);
} else {
// TODO remove these two lines once 966957 has landed
EnsureOperandNotFloat32(alloc, ins, Op);
in = ins->getOperand(Op);
replace = MToString::New(alloc, in);
}
MToString *replace = MToString::New(alloc, in);
ins->block()->insertBefore(ins, replace);
ins->replaceOperand(Op, replace);
if (!ToStringPolicy::staticAdjustInputs(alloc, replace))
return false;
return true;
}
@@ -618,6 +610,22 @@ ToInt32Policy::staticAdjustInputs(TempAllocator &alloc, MInstruction *ins)
return true;
}
bool
ToStringPolicy::staticAdjustInputs(TempAllocator &alloc, MInstruction *ins)
{
JS_ASSERT(ins->isToString());
if (ins->getOperand(0)->type() == MIRType_Object) {
ins->replaceOperand(0, boxAt(alloc, ins, ins->getOperand(0)));
return true;
}
// TODO remove the following line once 966957 has landed
EnsureOperandNotFloat32(alloc, ins, 0);
return true;
}
template <unsigned Op>
bool
ObjectPolicy<Op>::staticAdjustInputs(TempAllocator &alloc, MInstruction *ins)
+11 -1
View File
@@ -120,7 +120,7 @@ class StringPolicy : public BoxInputsPolicy
// Expect a string for operand Op. Else a ToString instruction is inserted.
template <unsigned Op>
class ConvertToStringPolicy : public BoxInputsPolicy
class ConvertToStringPolicy : public TypePolicy
{
public:
static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
@@ -221,6 +221,16 @@ class ToInt32Policy : public BoxInputsPolicy
}
};
// Box objects as input to a ToString instruction.
class ToStringPolicy : public BoxInputsPolicy
{
public:
static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
return staticAdjustInputs(alloc, def);
}
};
template <unsigned Op>
class ObjectPolicy : public BoxInputsPolicy
{