Move type dispatch of ConvCellToInt to simplifier
Currently, CastInt does this all in its HHBC -> HHIR translation, but this could be improved.
Esse commit está contido em:
@@ -2880,26 +2880,8 @@ void HhbcTranslator::emitCastDouble() {
|
||||
void HhbcTranslator::emitCastInt() {
|
||||
IRTrace* catchTrace = getCatchTrace();
|
||||
SSATmp* src = popC();
|
||||
Type fromType = src->type();
|
||||
if (fromType.isInt()) {
|
||||
push(src);
|
||||
} else if (fromType.isNull()) {
|
||||
push(cns(0));
|
||||
} else if (fromType.isArray()) {
|
||||
push(gen(ConvArrToInt, src));
|
||||
gen(DecRef, src);
|
||||
} else if (fromType.isBool()) {
|
||||
push(gen(ConvBoolToInt, src));
|
||||
} else if (fromType.isDbl()) {
|
||||
push(gen(ConvDblToInt, src));
|
||||
} else if (fromType.isString()) {
|
||||
push(gen(ConvStrToInt, src));
|
||||
gen(DecRef, src);
|
||||
} else if (fromType.isObj()) {
|
||||
push(gen(ConvObjToInt, catchTrace, src));
|
||||
} else {
|
||||
push(gen(ConvCellToInt, catchTrace, src));
|
||||
}
|
||||
push(gen(ConvCellToInt, catchTrace, src));
|
||||
gen(DecRef, src);
|
||||
}
|
||||
|
||||
void HhbcTranslator::emitCastObject() {
|
||||
|
||||
@@ -242,9 +242,9 @@ O(ConvCellToDbl, D(Dbl), S(Cell), N|Er|CRc|K) \
|
||||
O(ConvArrToInt, D(Int), S(Arr), C|N) \
|
||||
O(ConvBoolToInt, D(Int), S(Bool), C) \
|
||||
O(ConvDblToInt, D(Int), S(Dbl), C|N) \
|
||||
O(ConvObjToInt, D(Int), S(Obj), N|Er|CRc|K) \
|
||||
O(ConvObjToInt, D(Int), S(Obj), N|Er|K) \
|
||||
O(ConvStrToInt, D(Int), S(Str), N) \
|
||||
O(ConvCellToInt, D(Int), S(Cell), N|Er|CRc|K) \
|
||||
O(ConvCellToInt, D(Int), S(Cell), N|Er|K) \
|
||||
\
|
||||
O(ConvCellToObj, D(Obj), S(Cell), N|CRc|K) \
|
||||
\
|
||||
|
||||
@@ -305,6 +305,7 @@ SSATmp* Simplifier::simplify(IRInstruction* inst) {
|
||||
case ConvDblToStr: return simplifyConvDblToStr(inst);
|
||||
case ConvIntToStr: return simplifyConvIntToStr(inst);
|
||||
case ConvCellToBool:return simplifyConvCellToBool(inst);
|
||||
case ConvCellToInt: return simplifyConvCellToInt(inst);
|
||||
case Unbox: return simplifyUnbox(inst);
|
||||
case UnboxPtr: return simplifyUnboxPtr(inst);
|
||||
case IsType:
|
||||
@@ -1446,6 +1447,21 @@ SSATmp* Simplifier::simplifyConvCellToBool(IRInstruction* inst) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SSATmp* Simplifier::simplifyConvCellToInt(IRInstruction* inst) {
|
||||
auto const src = inst->src(0);
|
||||
auto const srcType = src->type();
|
||||
|
||||
if (srcType.isInt()) return src;
|
||||
if (srcType.isNull()) return cns(0);
|
||||
if (srcType.isArray()) return gen(ConvArrToInt, src);
|
||||
if (srcType.isBool()) return gen(ConvBoolToInt, src);
|
||||
if (srcType.isDbl()) return gen(ConvDblToInt, src);
|
||||
if (srcType.isString()) return gen(ConvStrToInt, src);
|
||||
if (srcType.isObj()) return gen(ConvObjToInt, inst->taken(), src);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SSATmp* Simplifier::simplifyLdClsPropAddr(IRInstruction* inst) {
|
||||
SSATmp* propName = inst->src(1);
|
||||
if (!propName->isConst()) return nullptr;
|
||||
|
||||
@@ -101,6 +101,7 @@ private:
|
||||
SSATmp* simplifyConvDblToStr(IRInstruction*);
|
||||
SSATmp* simplifyConvIntToStr(IRInstruction*);
|
||||
SSATmp* simplifyConvCellToBool(IRInstruction*);
|
||||
SSATmp* simplifyConvCellToInt(IRInstruction*);
|
||||
SSATmp* simplifyUnbox(IRInstruction*);
|
||||
SSATmp* simplifyUnboxPtr(IRInstruction*);
|
||||
SSATmp* simplifyCheckInit(IRInstruction* inst);
|
||||
|
||||
@@ -170,19 +170,7 @@ int64_t convStrToIntHelper(const StringData* s) {
|
||||
}
|
||||
|
||||
int64_t convCellToIntHelper(TypedValue tv) {
|
||||
try {
|
||||
tvCastToInt64InPlace(&tv); // consumes a ref on counted values
|
||||
// but not if an exception happens. (REVIEW)
|
||||
return tv.m_data.num;
|
||||
} catch (...) {
|
||||
// spill tv back to stack. unwinder
|
||||
// will take care of decreffing it.
|
||||
VMRegAnchor _;
|
||||
TypedValue* spillSlot = (TypedValue *)vmsp();
|
||||
spillSlot->m_data.num = tv.m_data.num;
|
||||
spillSlot->m_type = tv.m_type;
|
||||
throw;
|
||||
}
|
||||
return tvCastToInt64(&tv);
|
||||
}
|
||||
|
||||
ObjectData* convCellToObjHelper(TypedValue tv) {
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário