#pragma once
#if ENABLE(DFG_JIT)
#include "DFGGraph.h"
#include "DFGNodeFlowProjection.h"
namespace JSC { namespace DFG {
class FlowIndexing {
public:
FlowIndexing(Graph&);
~FlowIndexing();
void recompute();
Graph& graph() const { return m_graph; }
unsigned numIndices() const { return m_numIndices; }
unsigned index(unsigned nodeIndex) const { return nodeIndex; }
unsigned index(Node* node) const { return index(node->index()); }
unsigned shadowIndex(unsigned nodeIndex) const
{
return m_nodeIndexToShadowIndex[nodeIndex];
}
unsigned shadowIndex(Node* node) const
{
DFG_ASSERT(m_graph, node, node->op() == Phi, node->op());
return shadowIndex(node->index());
}
unsigned index(unsigned nodeIndex, NodeFlowProjection::Kind kind) const
{
switch (kind) {
case NodeFlowProjection::Primary:
return index(nodeIndex);
case NodeFlowProjection::Shadow:
return shadowIndex(nodeIndex);
}
RELEASE_ASSERT_NOT_REACHED();
return 0;
}
unsigned index(Node *node, NodeFlowProjection::Kind kind) const
{
switch (kind) {
case NodeFlowProjection::Primary:
return index(node);
case NodeFlowProjection::Shadow:
return shadowIndex(node);
}
RELEASE_ASSERT_NOT_REACHED();
return 0;
}
unsigned index(NodeFlowProjection projection) const
{
return index(projection.node(), projection.kind());
}
NodeFlowProjection nodeProjection(unsigned index) const
{
if (index < m_nodeIndexToShadowIndex.size())
return NodeFlowProjection(m_graph.nodeAt(index));
return NodeFlowProjection(
m_graph.nodeAt(m_shadowIndexToNodeIndex[index - m_nodeIndexToShadowIndex.size()]),
NodeFlowProjection::Shadow);
}
private:
Graph& m_graph;
unsigned m_numIndices;
Vector<unsigned, 0, UnsafeVectorOverflow> m_nodeIndexToShadowIndex;
Vector<unsigned, 0, UnsafeVectorOverflow> m_shadowIndexToNodeIndex;
};
} }
#endif // ENABLE(DFG_JIT)