DFGStaticExecutionCountEstimationPhase.cpp [plain text]
#include "config.h"
#include "DFGStaticExecutionCountEstimationPhase.h"
#if ENABLE(DFG_JIT)
#include "DFGBasicBlockInlines.h"
#include "DFGGraph.h"
#include "DFGNaturalLoops.h"
#include "DFGPhase.h"
#include "JSCInlines.h"
namespace JSC { namespace DFG {
class StaticExecutionCountEstimationPhase : public Phase {
public:
StaticExecutionCountEstimationPhase(Graph& graph)
: Phase(graph, "static execution count estimation")
{
}
bool run()
{
m_graph.ensureNaturalLoops();
for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
BasicBlock* block = m_graph.block(blockIndex);
if (!block)
continue;
block->executionCount = pow(10, m_graph.m_naturalLoops->loopDepth(block));
}
for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
BasicBlock* block = m_graph.block(blockIndex);
if (!block)
continue;
Node* terminal = block->terminal();
switch (terminal->op()) {
case Branch: {
BranchData* data = terminal->branchData();
applyCounts(data->taken);
applyCounts(data->notTaken);
break;
}
case Switch: {
SwitchData* data = terminal->switchData();
for (unsigned i = data->cases.size(); i--;)
applyCounts(data->cases[i].target);
applyCounts(data->fallThrough);
break;
}
default:
break;
}
}
return true;
}
private:
void applyCounts(BranchTarget& target)
{
target.count = target.block->executionCount;
}
};
bool performStaticExecutionCountEstimation(Graph& graph)
{
return runPhase<StaticExecutionCountEstimationPhase>(graph);
}
} }
#endif // ENABLE(DFG_JIT)