DFGMovHintRemovalPhase.cpp [plain text]
#include "config.h"
#include "DFGMovHintRemovalPhase.h"
#if ENABLE(DFG_JIT)
#include "BytecodeLivenessAnalysisInlines.h"
#include "DFGEpoch.h"
#include "DFGForAllKills.h"
#include "DFGGraph.h"
#include "DFGInsertionSet.h"
#include "DFGMayExit.h"
#include "DFGPhase.h"
#include "JSCInlines.h"
#include "OperandsInlines.h"
namespace JSC { namespace DFG {
namespace {
bool verbose = false;
class MovHintRemovalPhase : public Phase {
public:
MovHintRemovalPhase(Graph& graph)
: Phase(graph, "MovHint removal")
, m_state(OperandsLike, graph.block(0)->variablesAtHead)
, m_changed(false)
{
}
bool run()
{
if (verbose) {
dataLog("Graph before MovHint removal:\n");
m_graph.dump();
}
for (BasicBlock* block : m_graph.blocksInNaturalOrder())
handleBlock(block);
return m_changed;
}
private:
void handleBlock(BasicBlock* block)
{
if (verbose)
dataLog("Handing block ", pointerDump(block), "\n");
Epoch currentEpoch = Epoch::first();
m_state.fill(Epoch());
m_graph.forAllLiveInBytecode(
block->terminal()->origin.forExit,
[&] (VirtualRegister reg) {
m_state.operand(reg) = currentEpoch;
});
if (verbose)
dataLog(" Locals: ", m_state, "\n");
currentEpoch.bump();
for (unsigned nodeIndex = block->size(); nodeIndex--;) {
Node* node = block->at(nodeIndex);
if (node->op() == MovHint) {
Epoch localEpoch = m_state.operand(node->unlinkedLocal());
if (verbose)
dataLog(" At ", node, ": current = ", currentEpoch, ", local = ", localEpoch, "\n");
if (!localEpoch || localEpoch == currentEpoch) {
node->setOpAndDefaultFlags(ZombieHint);
node->child1() = Edge();
m_changed = true;
}
m_state.operand(node->unlinkedLocal()) = Epoch();
}
if (mayExit(m_graph, node))
currentEpoch.bump();
if (nodeIndex) {
forAllKilledOperands(
m_graph, block->at(nodeIndex - 1), node,
[&] (VirtualRegister reg) {
if (!!m_state.operand(reg))
return;
if (verbose)
dataLog(" Killed operand at ", node, ": ", reg, "\n");
m_state.operand(reg) = currentEpoch;
});
}
}
}
Operands<Epoch> m_state;
bool m_changed;
};
}
bool performMovHintRemoval(Graph& graph)
{
SamplingRegion samplingRegion("DFG MovHint Removal Phase");
return runPhase<MovHintRemovalPhase>(graph);
}
} }
#endif // ENABLE(DFG_JIT)