Bug 1492995 - Adding CacheIR support for String + Boolean. r=mgaudet

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Adam Holm 2019-04-25 01:07:55 +00:00
Родитель 5f3821de3e
Коммит 322aae31af
6 изменённых файлов: 74 добавлений и 0 удалений

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

@ -50,6 +50,11 @@ var funAdd6 = (a, b) => { return a + b; }
warmup(funAdd6, [["x", 10, "x10"], [10, "bba", "10bba"], ["x", 1.2, "x1.2"],
[1.2, "bba", "1.2bba"]]);
// Add: String Boolean
var funAddStrBool = (a, b) => { return a + b; }
warmup(funAddStrBool, [[true, "true", "truetrue"], [false, "true", "falsetrue"],
["a string", true, "a stringtrue"]]);
// Sub Int32
var funSub1 = (a, b) => { return a - b; }
warmup(funSub1, [[7, 0, 7], [7, 8, -1], [4294967295, 2, 4294967293], [0,0,0]]);

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

@ -284,6 +284,7 @@ static MIRType ParseCacheIRStub(ICStub* stub) {
case CacheOp::CallStringConcatResult:
case CacheOp::CallStringObjectConcatResult:
case CacheOp::CallInt32ToString:
case CacheOp::BooleanToString:
case CacheOp::CallNumberToString:
return MIRType::String;
case CacheOp::DoubleAddResult:

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

@ -6403,6 +6403,11 @@ bool BinaryArithIRGenerator::tryAttachStub() {
return true;
}
// String + Boolean
if (tryAttachStringBooleanConcat()) {
return true;
}
trackAttached(IRGenerator::NotAttached);
return false;
}
@ -6621,6 +6626,39 @@ bool BinaryArithIRGenerator::tryAttachStringNumberConcat() {
return true;
}
bool BinaryArithIRGenerator::tryAttachStringBooleanConcat() {
// Only Addition
if (op_ != JSOP_ADD) {
return false;
}
if ((!lhs_.isString() || !rhs_.isBoolean()) &&
(!lhs_.isBoolean() || !rhs_.isString())) {
return false;
}
ValOperandId lhsId(writer.setInputOperandId(0));
ValOperandId rhsId(writer.setInputOperandId(1));
auto guardToString = [&](ValOperandId id, HandleValue v) {
if (v.isString()) {
return writer.guardIsString(id);
}
MOZ_ASSERT(v.isBoolean());
Int32OperandId intId = writer.guardIsBoolean(id);
return writer.booleanToString(intId);
};
StringOperandId lhsStrId = guardToString(lhsId, lhs_);
StringOperandId rhsStrId = guardToString(rhsId, rhs_);
writer.callStringConcatResult(lhsStrId, rhsStrId);
writer.returnFromIC();
trackAttached("BinaryArith.StringBooleanConcat");
return true;
}
bool BinaryArithIRGenerator::tryAttachStringConcat() {
// Only Addition
if (op_ != JSOP_ADD) {

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

@ -294,6 +294,7 @@ extern const uint32_t ArgLengths[];
_(CallAddOrUpdateSparseElementHelper, Id, Id, Id, Byte) \
_(CallInt32ToString, Id, Id) \
_(CallNumberToString, Id, Id) \
_(BooleanToString, Id, Id) \
_(CallScriptedFunction, Id, Id, Byte) \
_(CallNativeFunction, Id, Id, Byte, IF_SIMULATOR(Field, Byte)) \
_(CallClassHook, Id, Id, Byte, Field) \
@ -1297,6 +1298,12 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter {
writeOperandId(res);
return res;
}
StringOperandId booleanToString(Int32OperandId id) {
StringOperandId res(nextOperandId_++);
writeOpWithOperandId(CacheOp::BooleanToString, id);
writeOperandId(res);
return res;
}
void callScriptedFunction(ObjOperandId calleeId, Int32OperandId argc,
CallFlags flags) {
writeOpWithOperandId(CacheOp::CallScriptedFunction, calleeId);
@ -2440,6 +2447,7 @@ class MOZ_RAII BinaryArithIRGenerator : public IRGenerator {
bool tryAttachStringConcat();
bool tryAttachStringObjectConcat();
bool tryAttachStringNumberConcat();
bool tryAttachStringBooleanConcat();
public:
BinaryArithIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,

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

@ -4284,6 +4284,27 @@ bool CacheIRCompiler::emitCallNumberToString() {
return true;
}
bool CacheIRCompiler::emitBooleanToString() {
JitSpew(JitSpew_Codegen, __FUNCTION__);
Register boolean = allocator.useRegister(masm, reader.int32OperandId());
Register result = allocator.defineRegister(masm, reader.stringOperandId());
const JSAtomState& names = cx_->names();
Label true_, done;
masm.branchTest32(Assembler::NonZero, boolean, boolean, &true_);
// False case
masm.movePtr(ImmGCPtr(names.false_), result);
masm.jump(&done);
// True case
masm.bind(&true_);
masm.movePtr(ImmGCPtr(names.true_), result);
masm.bind(&done);
return true;
}
void js::jit::LoadTypedThingData(MacroAssembler& masm, TypedThingLayout layout,
Register obj, Register result) {
switch (layout) {

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

@ -126,6 +126,7 @@ namespace jit {
_(CallObjectHasSparseElementResult) \
_(CallInt32ToString) \
_(CallNumberToString) \
_(BooleanToString) \
_(CallIsSuspendedGeneratorResult) \
_(MetaTwoByte) \
_(WrapResult)