From 28276a728852835d03fb3df76559c807cf8710a2 Mon Sep 17 00:00:00 2001 From: Oguz Ulgen Date: Mon, 25 Jul 2022 20:55:58 -0700 Subject: [PATCH] Use struct bit packing Summary: Instead of implementing two bits by hand, lets use proper packing Reviewed By: ricklavoie Differential Revision: D38119000 fbshipit-source-id: 406c6d97c16001eac0dd4ea2527a943b3f798794 --- hphp/runtime/vm/func-emitter.cpp | 7 +++---- hphp/runtime/vm/func-inl.h | 5 +---- hphp/runtime/vm/func.cpp | 3 +-- hphp/runtime/vm/func.h | 7 ++++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hphp/runtime/vm/func-emitter.cpp b/hphp/runtime/vm/func-emitter.cpp index d16ecad0d44..c5b15aedd38 100644 --- a/hphp/runtime/vm/func-emitter.cpp +++ b/hphp/runtime/vm/func-emitter.cpp @@ -300,8 +300,7 @@ Func* FuncEmitter::create(Unit& unit, PreClass* preClass /* = NULL */) const { ex->m_allFlags.m_returnByValue = false; ex->m_allFlags.m_isMemoizeWrapper = false; ex->m_allFlags.m_isMemoizeWrapperLSB = false; - ex->m_allFlags.m_memoizeICTypeBit0 = false; - ex->m_allFlags.m_memoizeICTypeBit1 = false; + ex->m_allFlags.m_memoizeICType = Func::MemoizeICType::NoIC; if (!coeffectRules.empty()) ex->m_coeffectRules = coeffectRules; ex->m_coeffectEscapes = coeffectsInfo.second; @@ -379,8 +378,8 @@ Func* FuncEmitter::create(Unit& unit, PreClass* preClass /* = NULL */) const { auto const it = userAttributes.find(attrName.get()); if (it != userAttributes.end()) { auto const ic_type = getICType(it->second); - f->shared()->m_allFlags.m_memoizeICTypeBit0 = ic_type & 1; - f->shared()->m_allFlags.m_memoizeICTypeBit1 = (ic_type >> 1) & 1; + assertx((ic_type & 0x3) == ic_type); + f->shared()->m_allFlags.m_memoizeICType = ic_type; } } diff --git a/hphp/runtime/vm/func-inl.h b/hphp/runtime/vm/func-inl.h index f4819d3dc98..5b0c43ce8ea 100644 --- a/hphp/runtime/vm/func-inl.h +++ b/hphp/runtime/vm/func-inl.h @@ -560,10 +560,7 @@ inline bool Func::isMemoizeWrapperLSB() const { inline Func::MemoizeICType Func::memoizeICType() const { assertx(isMemoizeWrapper()); - return static_cast( - shared()->m_allFlags.m_memoizeICTypeBit0 | - (shared()->m_allFlags.m_memoizeICTypeBit1 << 1) - ); + return shared()->m_allFlags.m_memoizeICType; } inline bool Func::isNoICMemoize() const { diff --git a/hphp/runtime/vm/func.cpp b/hphp/runtime/vm/func.cpp index d2a3b2b75cc..ecf1ff3f3db 100644 --- a/hphp/runtime/vm/func.cpp +++ b/hphp/runtime/vm/func.cpp @@ -721,8 +721,7 @@ Func::SharedData::SharedData(BCPtr bc, Offset bclen, m_allFlags.m_returnByValue = false; m_allFlags.m_isMemoizeWrapper = false; m_allFlags.m_isMemoizeWrapperLSB = false; - m_allFlags.m_memoizeICTypeBit0 = false; - m_allFlags.m_memoizeICTypeBit1 = false; + m_allFlags.m_memoizeICType = Func::MemoizeICType::NoIC; m_allFlags.m_isPhpLeafFn = isPhpLeafFn; m_allFlags.m_hasReifiedGenerics = false; m_allFlags.m_hasParamsWithMultiUBs = false; diff --git a/hphp/runtime/vm/func.h b/hphp/runtime/vm/func.h index 5828fb9a020..43f9bde42be 100644 --- a/hphp/runtime/vm/func.h +++ b/hphp/runtime/vm/func.h @@ -706,8 +706,10 @@ public: /* * What kind of memoized function is this? + * NB: MemoizeICType must be a unsigned char in order to enable + * struct bit packing. */ - enum MemoizeICType { + enum MemoizeICType : unsigned char { NoIC = 0, KeyedByIC = 1, MakeICInaccessible = 2, @@ -1341,8 +1343,7 @@ private: bool m_returnByValue : true; // only for builtins bool m_isMemoizeWrapper : true; bool m_isMemoizeWrapperLSB : true; - bool m_memoizeICTypeBit0 : true; - bool m_memoizeICTypeBit1 : true; + MemoizeICType m_memoizeICType : 2; bool m_isPhpLeafFn : true; bool m_hasReifiedGenerics : true; bool m_hasParamsWithMultiUBs : true; -- 2.11.4.GIT