#ifndef DFGGraph_h
#define DFGGraph_h
#if ENABLE(DFG_JIT)
#include <RegisterFile.h>
#include <dfg/DFGNode.h>
#include <wtf/Vector.h>
#include <wtf/StdLibExtras.h>
namespace JSC {
class CodeBlock;
namespace DFG {
inline bool operandIsArgument(int operand) { return operand < 0; }
typedef uint8_t PredictedType;
static const PredictedType PredictNone = 0;
static const PredictedType PredictCell = 0x01;
static const PredictedType PredictArray = 0x03;
static const PredictedType PredictInt32 = 0x04;
struct PredictionSlot {
public:
PredictionSlot()
: m_value(PredictNone)
{
}
PredictedType m_value;
};
typedef uint32_t BlockIndex;
struct VariableRecord {
VariableRecord()
: value(NoNode)
{
}
NodeIndex value;
};
typedef Vector <BlockIndex, 2> PredecessorList;
struct BasicBlock {
BasicBlock(unsigned bytecodeBegin, NodeIndex begin, unsigned numArguments, unsigned numLocals)
: bytecodeBegin(bytecodeBegin)
, begin(begin)
, end(NoNode)
, m_arguments(numArguments)
, m_locals(numLocals)
{
}
static inline BlockIndex getBytecodeBegin(OwnPtr<BasicBlock>* block)
{
return (*block)->bytecodeBegin;
}
unsigned bytecodeBegin;
NodeIndex begin;
NodeIndex end;
PredecessorList m_predecessors;
Vector <VariableRecord, 8> m_arguments;
Vector <VariableRecord, 16> m_locals;
};
class Graph : public Vector<Node, 64> {
public:
Graph(unsigned numArguments, unsigned numVariables)
: m_argumentPredictions(numArguments)
, m_variablePredictions(numVariables)
{
}
void ref(NodeIndex nodeIndex)
{
Node& node = at(nodeIndex);
if (node.ref())
refChildren(nodeIndex);
}
#ifndef NDEBUG
void dump(CodeBlock* = 0);
void dump(NodeIndex, CodeBlock* = 0);
#endif
BlockIndex blockIndexForBytecodeOffset(unsigned bytecodeBegin)
{
OwnPtr<BasicBlock>* begin = m_blocks.begin();
OwnPtr<BasicBlock>* block = binarySearch<OwnPtr<BasicBlock>, unsigned, BasicBlock::getBytecodeBegin>(begin, m_blocks.size(), bytecodeBegin);
ASSERT(block >= m_blocks.begin() && block < m_blocks.end());
return static_cast<BlockIndex>(block - begin);
}
BasicBlock& blockForBytecodeOffset(unsigned bytecodeBegin)
{
return *m_blocks[blockIndexForBytecodeOffset(bytecodeBegin)];
}
void predict(int operand, PredictedType prediction)
{
if (operandIsArgument(operand)) {
unsigned argument = operand + m_argumentPredictions.size() + RegisterFile::CallFrameHeaderSize;
m_argumentPredictions[argument].m_value |= prediction;
} else if ((unsigned)operand < m_variablePredictions.size())
m_variablePredictions[operand].m_value |= prediction;
}
PredictedType getPrediction(int operand)
{
if (operandIsArgument(operand)) {
unsigned argument = operand + m_argumentPredictions.size() + RegisterFile::CallFrameHeaderSize;
return m_argumentPredictions[argument].m_value;
}
if ((unsigned)operand < m_variablePredictions.size())
return m_variablePredictions[operand].m_value;
return PredictNone;
}
Vector< OwnPtr<BasicBlock> , 8> m_blocks;
private:
void refChildren(NodeIndex);
Vector<PredictionSlot, 16> m_argumentPredictions;
Vector<PredictionSlot, 16> m_variablePredictions;
};
} }
#endif
#endif