From 2a75bbce2534596986781e1ed583dd4d5704a0a8 Mon Sep 17 00:00:00 2001 From: hermanv Date: Sun, 31 Mar 2013 12:42:41 -0700 Subject: [PATCH] Introduce more helpers like Type::isArray. class Type had methods isArray and isNull, but not methods like isBoolean. This change introduces helpers for the other types that frequently need to be tested for in type specialization code. The change is kept small so that is is obviously correct and easy to push quickly. Making all type tests consistent will have to be achieved incrementally. --- .../vm/translator/hopt/hhbctranslator.cpp | 16 +++++++-------- hphp/runtime/vm/translator/hopt/ir.h | 20 +++++++++++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/hphp/runtime/vm/translator/hopt/hhbctranslator.cpp b/hphp/runtime/vm/translator/hopt/hhbctranslator.cpp index 9959f8576..74f7283ac 100644 --- a/hphp/runtime/vm/translator/hopt/hhbctranslator.cpp +++ b/hphp/runtime/vm/translator/hopt/hhbctranslator.cpp @@ -2020,15 +2020,15 @@ void HhbcTranslator::emitCastArray() { push(src); } else if (fromType.isNull()) { push(m_tb->genDefConst(HphpArray::GetStaticEmptyArray())); - } else if (fromType.equals(Type::Bool)) { + } else if (fromType.isBool()) { push(m_tb->gen(ConvBoolToArr, src)); - } else if (fromType.equals(Type::Dbl)) { + } else if (fromType.isDbl()) { push(m_tb->gen(ConvDblToArr, src)); - } else if (fromType.equals(Type::Int)) { + } else if (fromType.isInt()) { push(m_tb->gen(ConvIntToArr, src)); } else if (fromType.isString()) { push(m_tb->gen(ConvStrToArr, src)); - } else if (fromType.subtypeOf(Type::Obj)) { + } else if (fromType.isObj()) { push(m_tb->gen(ConvObjToArr, src)); } else { push(m_tb->gen(ConvGenToArr, src)); @@ -2044,19 +2044,19 @@ void HhbcTranslator::emitCastBool() { void HhbcTranslator::emitCastDouble() { SSATmp* src = popC(); Type fromType = src->getType(); - if (fromType.equals(Type::Dbl)) { + if (fromType.isDbl()) { push(src); } else if (fromType.isNull()) { push(m_tb->genDefConst(0.0)); } else if (fromType.isArray()) { push(m_tb->gen(ConvArrToDbl, src)); - } else if (fromType.equals(Type::Bool)) { + } else if (fromType.isBool()) { push(m_tb->gen(ConvBoolToDbl, src)); - } else if (fromType.equals(Type::Int)) { + } else if (fromType.isInt()) { push(m_tb->gen(ConvIntToDbl, src)); } else if (fromType.isString()) { push(m_tb->gen(ConvStrToDbl, src)); - } else if (fromType.subtypeOf(Type::Obj)) { + } else if (fromType.isObj()) { spillStack(); // may throw push(m_tb->gen(ConvObjToDbl, src)); } else { diff --git a/hphp/runtime/vm/translator/hopt/ir.h b/hphp/runtime/vm/translator/hopt/ir.h index a3180351c..c31e2650b 100644 --- a/hphp/runtime/vm/translator/hopt/ir.h +++ b/hphp/runtime/vm/translator/hopt/ir.h @@ -1161,14 +1161,30 @@ public: return subtypeOf(Arr); } - bool isString() const { - return subtypeOf(Str); + bool isBool() const { + return subtypeOf(Bool); + } + + bool isDbl() const { + return subtypeOf(Dbl); + } + + bool isInt() const { + return subtypeOf(Int); } bool isNull() const { return subtypeOf(Null); } + bool isObj() const { + return subtypeOf(Obj); + } + + bool isString() const { + return subtypeOf(Str); + } + Type innerType() const { assert(isBoxed()); return Type(m_bits >> kBoxShift);