DFGVirtualRegisterAllocationPhase.cpp [plain text]
#include "config.h"
#include "DFGVirtualRegisterAllocationPhase.h"
#if ENABLE(DFG_JIT)
#include "DFGGraph.h"
#include "DFGScoreBoard.h"
#include "JSCInlines.h"
#include "StackAlignment.h"
#include <wtf/StdLibExtras.h>
namespace JSC { namespace DFG {
class VirtualRegisterAllocationPhase : public Phase {
public:
VirtualRegisterAllocationPhase(Graph& graph)
: Phase(graph, "virtual register allocation")
{
}
bool run()
{
ScoreBoard scoreBoard(m_graph.m_nextMachineLocal);
scoreBoard.assertClear();
for (size_t blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
BasicBlock* block = m_graph.block(blockIndex);
if (!block)
continue;
if (!block->isReachable)
continue;
for (size_t indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
Node* node = block->at(indexInBlock);
if (!node->shouldGenerate())
continue;
switch (node->op()) {
case Phi:
case Flush:
case PhantomLocal:
continue;
case GetLocal:
ASSERT(!node->child1()->hasResult());
break;
default:
break;
}
if (node->flags() & NodeHasVarArgs) {
for (unsigned childIdx = node->firstChild(); childIdx < node->firstChild() + node->numChildren(); childIdx++)
scoreBoard.useIfHasResult(m_graph.m_varArgChildren[childIdx]);
} else {
scoreBoard.useIfHasResult(node->child1());
scoreBoard.useIfHasResult(node->child2());
scoreBoard.useIfHasResult(node->child3());
}
if (!node->hasResult())
continue;
VirtualRegister virtualRegister = scoreBoard.allocate();
node->setVirtualRegister(virtualRegister);
if (node->mustGenerate())
scoreBoard.use(node);
}
scoreBoard.assertClear();
}
m_graph.m_nextMachineLocal = scoreBoard.highWatermark();
return true;
}
};
bool performVirtualRegisterAllocation(Graph& graph)
{
SamplingRegion samplingRegion("DFG Virtual Register Allocation Phase");
return runPhase<VirtualRegisterAllocationPhase>(graph);
}
} }
#endif // ENABLE(DFG_JIT)