diff --git a/hphp/runtime/vm/translator/hopt/codegen.h b/hphp/runtime/vm/translator/hopt/codegen.h index 0521c043e..bade0ea5d 100644 --- a/hphp/runtime/vm/translator/hopt/codegen.h +++ b/hphp/runtime/vm/translator/hopt/codegen.h @@ -21,7 +21,8 @@ #include "runtime/vm/translator/hopt/ir.h" #include "runtime/vm/translator/hopt/irfactory.h" #include "runtime/vm/translator/targetcache.h" -#include +#include "runtime/vm/translator/translator-x64.h" +#include "runtime/vm/translator/hopt/state_vector.h" namespace HPHP { namespace VM { diff --git a/hphp/runtime/vm/translator/hopt/dce.cpp b/hphp/runtime/vm/translator/hopt/dce.cpp index c79e4fce4..325fa141c 100644 --- a/hphp/runtime/vm/translator/hopt/dce.cpp +++ b/hphp/runtime/vm/translator/hopt/dce.cpp @@ -14,12 +14,14 @@ +----------------------------------------------------------------------+ */ +#include + #include "util/trace.h" #include "runtime/vm/translator/hopt/ir.h" #include "runtime/vm/translator/hopt/opt.h" #include "runtime/vm/translator/hopt/irfactory.h" #include "runtime/vm/translator/hopt/simplifier.h" -#include +#include "runtime/vm/translator/hopt/state_vector.h" namespace HPHP { namespace VM { diff --git a/hphp/runtime/vm/translator/hopt/irfactory.h b/hphp/runtime/vm/translator/hopt/irfactory.h index 02d36d18a..f09d3cac6 100644 --- a/hphp/runtime/vm/translator/hopt/irfactory.h +++ b/hphp/runtime/vm/translator/hopt/irfactory.h @@ -264,72 +264,6 @@ private: Arena m_arena; }; -/* - * Utility to keep a vector of state about each key, indexed by - * factoryId(key), where key can be an IRInstruction, Block, or SSATmp. - */ -template -struct StateVector { - typedef std::vector InfoVector; - typedef typename InfoVector::iterator iterator; - typedef typename InfoVector::reference reference; - typedef typename InfoVector::const_reference const_reference; - - static unsigned factoryId(const IRInstruction* inst) { - return inst->getIId(); - } - static unsigned factoryId(const Block* block) { return block->getId(); } - static unsigned factoryId(const SSATmp* tmp) { return tmp->getId(); } - static unsigned count(const IRFactory* factory, IRInstruction*) { - return factory->numInsts(); - } - static unsigned count(const IRFactory* factory, SSATmp*) { - return factory->numTmps(); - } - static unsigned count(const IRFactory* factory, Block*) { - return factory->numBlocks(); - } - StateVector(const IRFactory* factory, Info init) - : m_factory(factory) - , m_info(count(factory, (Key*)nullptr), init) - , m_init(init) { - } - reference operator[](const Key& k) { return (*this)[&k]; } - reference operator[](const Key* k) { - auto id = factoryId(k); - if (id >= m_info.size()) grow(); - assert(id < m_info.size()); - return m_info[id]; - } - const_reference operator[](const Key& k) const { return (*this)[&k]; } - const_reference operator[](const Key* k) const { - assert(factoryId(k) < m_info.size()); - return m_info[factoryId(k)]; - } - void reset() { - for (size_t i = 0, n = m_info.size(); i < n; ++i) { - m_info[i] = m_init; - } - grow(); - } - - iterator begin() { return m_info.begin(); } - iterator end() { return m_info.end(); } - -private: - void grow() { - for (size_t i = m_info.size(), n = count(m_factory, (Key*)nullptr); - i < n; ++i) { - m_info.push_back(m_init); - } - } - -private: - const IRFactory* m_factory; - InfoVector m_info; - Info m_init; -}; - ////////////////////////////////////////////////////////////////////// }}} diff --git a/hphp/runtime/vm/translator/hopt/linearscan.cpp b/hphp/runtime/vm/translator/hopt/linearscan.cpp index d52a9a565..9d21ed8c3 100644 --- a/hphp/runtime/vm/translator/hopt/linearscan.cpp +++ b/hphp/runtime/vm/translator/hopt/linearscan.cpp @@ -608,6 +608,7 @@ void LinearScan::insertAllocFreeSpillAux(Trace* trace, void LinearScan::collectInfo(BlockList::iterator it, Trace* trace) { m_natives.clear(); m_jmps.reset(); + for (auto* block : m_blocks) { for (auto& inst : *block) { for (auto& dst : inst.getDsts()) { diff --git a/hphp/runtime/vm/translator/hopt/linearscan.h b/hphp/runtime/vm/translator/hopt/linearscan.h index a537aa46a..aa75321da 100644 --- a/hphp/runtime/vm/translator/hopt/linearscan.h +++ b/hphp/runtime/vm/translator/hopt/linearscan.h @@ -24,6 +24,7 @@ #include "runtime/vm/translator/hopt/ir.h" #include "runtime/vm/translator/hopt/tracebuilder.h" #include "runtime/vm/translator/hopt/codegen.h" +#include "runtime/vm/translator/hopt/state_vector.h" namespace HPHP { namespace VM { namespace JIT { diff --git a/hphp/runtime/vm/translator/hopt/state_vector.h b/hphp/runtime/vm/translator/hopt/state_vector.h new file mode 100644 index 000000000..8a653be1d --- /dev/null +++ b/hphp/runtime/vm/translator/hopt/state_vector.h @@ -0,0 +1,108 @@ +/* + +----------------------------------------------------------------------+ + | HipHop for PHP | + +----------------------------------------------------------------------+ + | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ +*/ + +#ifndef incl_HPHP_JIT_STATE_VECTOR_H_ +#define incl_HPHP_JIT_STATE_VECTOR_H_ + +#include "runtime/base/memory/memory_manager.h" + +#include "runtime/vm/translator/hopt/irfactory.h" + +namespace HPHP { namespace VM { namespace JIT { + +////////////////////////////////////////////////////////////////////// + +/* + * Utility to keep a vector of state about each key, indexed by + * factoryId(key), where key can be an IRInstruction, Block, or SSATmp. + * + * Takes an `init' element, which everything is defaulted to. Calls + * to reset() restore all entries to this state. + */ +template +struct StateVector { + typedef smart::vector InfoVector; + typedef typename InfoVector::iterator iterator; + typedef typename InfoVector::const_iterator const_iterator; + typedef typename InfoVector::reference reference; + typedef typename InfoVector::const_reference const_reference; + + StateVector(const IRFactory* factory, Info init) + : m_factory(factory) + , m_info(count(factory, (Key*)nullptr), init) + , m_init(init) { + } + + void reset() { + m_info.assign(m_info.size(), m_init); + grow(); + } + + reference operator[](const Key& k) { return (*this)[&k]; } + reference operator[](const Key* k) { + auto id = factoryId(k); + if (id >= m_info.size()) grow(); + assert(id < m_info.size()); + return m_info[id]; + } + + const_reference operator[](const Key& k) const { return (*this)[&k]; } + const_reference operator[](const Key* k) const { + assert(factoryId(k) < m_info.size()); + return m_info[factoryId(k)]; + } + + iterator begin() { return m_info.begin(); } + iterator end() { return m_info.end(); } + const_iterator begin() const { return m_info.begin(); } + const_iterator end() const { return m_info.end(); } + const_iterator cbegin() const { return m_info.cbegin(); } + const_iterator cend() const { return m_info.cend(); } + +private: + static unsigned factoryId(const IRInstruction* inst) { + return inst->getIId(); + } + static unsigned factoryId(const Block* block) { return block->getId(); } + static unsigned factoryId(const SSATmp* tmp) { return tmp->getId(); } + + static unsigned count(const IRFactory* factory, IRInstruction*) { + return factory->numInsts(); + } + static unsigned count(const IRFactory* factory, SSATmp*) { + return factory->numTmps(); + } + static unsigned count(const IRFactory* factory, Block*) { + return factory->numBlocks(); + } + +private: + void grow() { + m_info.resize(count(m_factory, static_cast(nullptr)), + m_init); + } + +private: + const IRFactory* m_factory; + InfoVector m_info; + Info m_init; +}; + +////////////////////////////////////////////////////////////////////// + +}}} + +#endif diff --git a/hphp/runtime/vm/translator/hopt/tracebuilder.h b/hphp/runtime/vm/translator/hopt/tracebuilder.h index be7fc9a71..2cf2f5a45 100644 --- a/hphp/runtime/vm/translator/hopt/tracebuilder.h +++ b/hphp/runtime/vm/translator/hopt/tracebuilder.h @@ -23,6 +23,7 @@ #include "runtime/vm/translator/hopt/irfactory.h" #include "runtime/vm/translator/hopt/cse.h" #include "runtime/vm/translator/hopt/simplifier.h" +#include "runtime/vm/translator/hopt/state_vector.h" #include "folly/ScopeGuard.h"