DFGAbstractValue.cpp [plain text]
#include "config.h"
#include "DFGAbstractValue.h"
#if ENABLE(DFG_JIT)
#include "DFGGraph.h"
#include "JSCInlines.h"
namespace JSC { namespace DFG {
void AbstractValue::setMostSpecific(Graph& graph, JSValue value)
{
if (!!value && value.isCell()) {
Structure* structure = value.asCell()->structure();
m_currentKnownStructure = structure;
setFuturePossibleStructure(graph, structure);
m_arrayModes = asArrayModes(structure->indexingType());
} else {
m_currentKnownStructure.clear();
m_futurePossibleStructure.clear();
m_arrayModes = 0;
}
m_type = speculationFromValue(value);
m_value = value;
checkConsistency();
}
void AbstractValue::set(Graph& graph, JSValue value)
{
if (!!value && value.isCell()) {
m_currentKnownStructure.makeTop();
Structure* structure = value.asCell()->structure();
setFuturePossibleStructure(graph, structure);
m_arrayModes = asArrayModes(structure->indexingType());
clobberArrayModes();
} else {
m_currentKnownStructure.clear();
m_futurePossibleStructure.clear();
m_arrayModes = 0;
}
m_type = speculationFromValue(value);
m_value = value;
checkConsistency();
}
void AbstractValue::set(Graph& graph, Structure* structure)
{
m_currentKnownStructure = structure;
setFuturePossibleStructure(graph, structure);
m_arrayModes = asArrayModes(structure->indexingType());
m_type = speculationFromStructure(structure);
m_value = JSValue();
checkConsistency();
}
void AbstractValue::fixTypeForRepresentation(NodeFlags representation)
{
if (representation == NodeResultDouble) {
if (m_value) {
ASSERT(m_value.isNumber());
if (m_value.isInt32())
m_value = jsDoubleNumber(m_value.asNumber());
}
if (m_type & SpecMachineInt) {
m_type &= ~SpecMachineInt;
m_type |= SpecInt52AsDouble;
}
if (m_type & ~SpecFullDouble) {
startCrashing();
dataLog("Abstract value ", *this, " for double node has type outside SpecFullDouble.\n");
CRASH();
}
} else if (representation == NodeResultInt52) {
if (m_type & SpecInt52AsDouble) {
m_type &= ~SpecInt52AsDouble;
m_type |= SpecInt52;
}
if (m_type & ~SpecMachineInt) {
startCrashing();
dataLog("Abstract value ", *this, " for int52 node has type outside SpecMachineInt.\n");
CRASH();
}
} else {
if (m_type & SpecInt52) {
m_type &= ~SpecInt52;
m_type |= SpecInt52AsDouble;
}
if (m_type & ~SpecBytecodeTop) {
startCrashing();
dataLog("Abstract value ", *this, " for value node has type outside SpecBytecodeTop.\n");
CRASH();
}
}
checkConsistency();
}
void AbstractValue::fixTypeForRepresentation(Node* node)
{
fixTypeForRepresentation(node->result());
}
FiltrationResult AbstractValue::filter(Graph& graph, const StructureSet& other)
{
if (isClear())
return FiltrationOK;
m_type &= other.speculationFromStructures();
m_arrayModes &= other.arrayModesFromStructures();
m_currentKnownStructure.filter(other);
m_currentKnownStructure.filter(m_type);
if (m_currentKnownStructure.hasSingleton())
setFuturePossibleStructure(graph, m_currentKnownStructure.singleton());
filterArrayModesByType();
filterValueByType();
return normalizeClarity();
}
FiltrationResult AbstractValue::filterArrayModes(ArrayModes arrayModes)
{
ASSERT(arrayModes);
if (isClear())
return FiltrationOK;
m_type &= SpecCell;
m_arrayModes &= arrayModes;
return normalizeClarity();
}
FiltrationResult AbstractValue::filter(SpeculatedType type)
{
if ((m_type & type) == m_type)
return FiltrationOK;
m_type &= type;
m_currentKnownStructure.filter(m_type);
m_futurePossibleStructure.filter(m_type);
filterArrayModesByType();
filterValueByType();
return normalizeClarity();
}
FiltrationResult AbstractValue::filterByValue(JSValue value)
{
FiltrationResult result = filter(speculationFromValue(value));
if (m_type)
m_value = value;
return result;
}
void AbstractValue::setFuturePossibleStructure(Graph& graph, Structure* structure)
{
ASSERT(structure);
if (graph.watchpoints().isStillValid(structure->transitionWatchpointSet()))
m_futurePossibleStructure = structure;
else
m_futurePossibleStructure.makeTop();
}
void AbstractValue::filterValueByType()
{
if (!!m_type) {
if (m_value && !validateType(m_value))
clear();
return;
}
ASSERT(!m_value || !validateType(m_value));
m_value = JSValue();
}
void AbstractValue::filterArrayModesByType()
{
if (!(m_type & SpecCell))
m_arrayModes = 0;
else if (!(m_type & ~SpecArray))
m_arrayModes &= ALL_ARRAY_ARRAY_MODES;
}
bool AbstractValue::shouldBeClear() const
{
if (m_type == SpecNone)
return true;
if (!(m_type & ~SpecCell)
&& (!m_arrayModes
|| m_currentKnownStructure.isClear()))
return true;
return false;
}
FiltrationResult AbstractValue::normalizeClarity()
{
FiltrationResult result;
if (shouldBeClear()) {
clear();
result = Contradiction;
} else
result = FiltrationOK;
checkConsistency();
return result;
}
#if !ASSERT_DISABLED
void AbstractValue::checkConsistency() const
{
if (!(m_type & SpecCell)) {
ASSERT(m_currentKnownStructure.isClear());
ASSERT(m_futurePossibleStructure.isClear());
ASSERT(!m_arrayModes);
}
if (isClear())
ASSERT(!m_value);
if (!!m_value) {
SpeculatedType type = m_type;
if (type & SpecInt52)
type |= SpecInt52AsDouble;
ASSERT(mergeSpeculations(type, speculationFromValue(m_value)) == type);
}
}
#endif
void AbstractValue::dump(PrintStream& out) const
{
dumpInContext(out, 0);
}
void AbstractValue::dumpInContext(PrintStream& out, DumpContext* context) const
{
out.print("(", SpeculationDump(m_type));
if (m_type & SpecCell) {
out.print(
", ", ArrayModesDump(m_arrayModes), ", ",
inContext(m_currentKnownStructure, context), ", ",
inContext(m_futurePossibleStructure, context));
}
if (!!m_value)
out.print(", ", inContext(m_value, context));
out.print(")");
}
} }
#endif // ENABLE(DFG_JIT)