#include "config.h"
#include "DFGCFAPhase.h"
#if ENABLE(DFG_JIT)
#include "DFGAbstractState.h"
#include "DFGGraph.h"
#include "DFGPhase.h"
#include "Operations.h"
namespace JSC { namespace DFG {
class CFAPhase : public Phase {
public:
CFAPhase(Graph& graph)
: Phase(graph, "control flow analysis")
, m_state(graph)
{
}
bool run()
{
ASSERT(m_graph.m_form == ThreadedCPS);
ASSERT(m_graph.m_unificationState == GloballyUnified);
ASSERT(m_graph.m_refCountState == EverythingIsLive);
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
m_count = 0;
#endif
AbstractState::initialize(m_graph);
do {
m_changed = false;
performForwardCFA();
} while (m_changed);
return true;
}
private:
void performBlockCFA(BlockIndex blockIndex)
{
BasicBlock* block = m_graph.m_blocks[blockIndex].get();
if (!block)
return;
if (!block->cfaShouldRevisit)
return;
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF(" Block #%u (bc#%u):\n", blockIndex, block->bytecodeBegin);
#endif
m_state.beginBasicBlock(block);
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF(" head vars: ");
dumpOperands(block->valuesAtHead, WTF::dataFile());
dataLogF("\n");
#endif
for (unsigned i = 0; i < block->size(); ++i) {
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
Node* node = block->at(i);
dataLogF(" %s @%u: ", Graph::opName(node->op()), node->index());
m_state.dump(WTF::dataFile());
dataLogF("\n");
#endif
if (!m_state.execute(i)) {
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF(" Expect OSR exit.\n");
#endif
break;
}
}
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF(" tail regs: ");
m_state.dump(WTF::dataFile());
dataLogF("\n");
#endif
m_changed |= m_state.endBasicBlock(AbstractState::MergeToSuccessors);
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF(" tail vars: ");
dumpOperands(block->valuesAtTail, WTF::dataFile());
dataLogF("\n");
#endif
}
void performForwardCFA()
{
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
dataLogF("CFA [%u]\n", ++m_count);
#endif
for (BlockIndex block = 0; block < m_graph.m_blocks.size(); ++block)
performBlockCFA(block);
}
private:
AbstractState m_state;
bool m_changed;
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
unsigned m_count;
#endif
};
bool performCFA(Graph& graph)
{
SamplingRegion samplingRegion("DFG CFA Phase");
return runPhase<CFAPhase>(graph);
}
} }
#endif // ENABLE(DFG_JIT)