#include "config.h"
#include "DFGGraph.h"
#include "CodeBlock.h"
#if ENABLE(DFG_JIT)
namespace JSC { namespace DFG {
#ifndef NDEBUG
static const char* dfgOpNames[] = {
#define STRINGIZE_DFG_OP_ENUM(opcode, flags) #opcode ,
FOR_EACH_DFG_OP(STRINGIZE_DFG_OP_ENUM)
#undef STRINGIZE_DFG_OP_ENUM
};
const char *Graph::opName(NodeType op)
{
return dfgOpNames[op & NodeIdMask];
}
void Graph::dump(NodeIndex nodeIndex, CodeBlock* codeBlock)
{
Node& node = at(nodeIndex);
NodeType op = node.op;
unsigned refCount = node.refCount();
if (!refCount)
return;
bool mustGenerate = node.mustGenerate();
if (mustGenerate)
--refCount;
printf("% 4d:\t<%c%u:", (int)nodeIndex, mustGenerate ? '!' : ' ', refCount);
if (node.hasResult())
printf("%u", node.virtualRegister());
else
printf("-");
printf(">\t%s(", opName(op));
bool hasPrinted;
if (op & NodeHasVarArgs) {
for (unsigned childIdx = node.firstChild(); childIdx < node.firstChild() + node.numChildren(); childIdx++) {
if (hasPrinted)
printf(", ");
else
hasPrinted = true;
printf("@%u", m_varArgChildren[childIdx]);
}
} else {
if (node.child1() != NoNode)
printf("@%u", node.child1());
if (node.child2() != NoNode)
printf(", @%u", node.child2());
if (node.child3() != NoNode)
printf(", @%u", node.child3());
hasPrinted = node.child1() != NoNode;
}
if (node.hasVarNumber()) {
printf("%svar%u", hasPrinted ? ", " : "", node.varNumber());
hasPrinted = true;
}
if (node.hasIdentifier()) {
if (codeBlock)
printf("%sid%u{%s}", hasPrinted ? ", " : "", node.identifierNumber(), codeBlock->identifier(node.identifierNumber()).ustring().utf8().data());
else
printf("%sid%u", hasPrinted ? ", " : "", node.identifierNumber());
hasPrinted = true;
}
if (node.hasLocal()) {
int local = node.local();
if (operandIsArgument(local))
printf("%sarg%u", hasPrinted ? ", " : "", local - codeBlock->thisRegister());
else
printf("%sr%u", hasPrinted ? ", " : "", local);
hasPrinted = true;
}
if (op == JSConstant) {
printf("%s$%u", hasPrinted ? ", " : "", node.constantNumber());
hasPrinted = true;
}
if (node.isBranch() || node.isJump()) {
printf("%sT:#%u", hasPrinted ? ", " : "", blockIndexForBytecodeOffset(node.takenBytecodeOffset()));
hasPrinted = true;
}
if (node.isBranch()) {
printf("%sF:#%u", hasPrinted ? ", " : "", blockIndexForBytecodeOffset(node.notTakenBytecodeOffset()));
hasPrinted = true;
}
printf(")");
if (node.hasLocal())
printf(" predicting %s", predictionToString(getPrediction(node.local())));
if (node.hasVarNumber())
printf(" predicting %s", predictionToString(getGlobalVarPrediction(node.varNumber())));
if (node.hasPrediction())
printf(" predicting %s", predictionToString(node.getPrediction()));
printf("\n");
}
void Graph::dump(CodeBlock* codeBlock)
{
for (size_t b = 0; b < m_blocks.size(); ++b) {
printf("Block #%u:\n", (int)b);
for (size_t i = m_blocks[b]->begin; i < m_blocks[b]->end; ++i)
dump(i, codeBlock);
}
printf("Phi Nodes:\n");
for (size_t i = m_blocks.last()->end; i < size(); ++i)
dump(i, codeBlock);
}
#endif
void Graph::refChildren(NodeIndex op)
{
Node& node = at(op);
if (node.op & NodeHasVarArgs) {
for (unsigned childIdx = node.firstChild(); childIdx < node.firstChild() + node.numChildren(); childIdx++)
ref(m_varArgChildren[childIdx]);
} else {
if (node.child1() == NoNode) {
ASSERT(node.child2() == NoNode && node.child3() == NoNode);
return;
}
ref(node.child1());
if (node.child2() == NoNode) {
ASSERT(node.child3() == NoNode);
return;
}
ref(node.child2());
if (node.child3() == NoNode)
return;
ref(node.child3());
}
}
void Graph::predictArgumentTypes(ExecState* exec)
{
size_t numberOfArguments = std::min(exec->argumentCountIncludingThis(), m_argumentPredictions.size());
for (size_t arg = 1; arg < numberOfArguments; ++arg) {
JSValue argumentValue = exec->argument(arg - 1);
if (argumentValue.isInt32())
m_argumentPredictions[arg].m_value |= PredictInt32;
else if (argumentValue.isDouble())
m_argumentPredictions[arg].m_value |= PredictDouble;
}
}
} }
#endif