DFGStructureAbstractValue.cpp [plain text]
#include "config.h"
#include "DFGStructureAbstractValue.h"
#if ENABLE(DFG_JIT)
#include "DFGGraph.h"
namespace JSC { namespace DFG {
#if !ASSERT_DISABLED
void StructureAbstractValue::assertIsRegistered(Graph& graph) const
{
if (isTop())
return;
for (unsigned i = size(); i--;)
graph.assertIsRegistered(at(i).get());
}
#endif // !ASSERT_DISABLED
void StructureAbstractValue::clobber()
{
if (isTop())
return;
setClobbered(true);
if (m_set.isThin()) {
if (!m_set.singleEntry())
return;
if (!m_set.singleEntry()->dfgShouldWatch())
makeTopWhenThin();
return;
}
RegisteredStructureSet::OutOfLineList* list = m_set.list();
for (unsigned i = list->m_length; i--;) {
if (!list->list()[i]->dfgShouldWatch()) {
makeTop();
return;
}
}
}
void StructureAbstractValue::observeTransition(RegisteredStructure from, RegisteredStructure to)
{
ASSERT(!from->dfgShouldWatch());
if (isTop())
return;
if (!m_set.contains(from))
return;
if (!m_set.add(to))
return;
if (m_set.size() > polymorphismLimit)
makeTop();
}
void StructureAbstractValue::observeTransitions(const TransitionVector& vector)
{
if (isTop())
return;
RegisteredStructureSet newStructures;
for (unsigned i = vector.size(); i--;) {
ASSERT(!vector[i].previous->dfgShouldWatch());
if (!m_set.contains(vector[i].previous))
continue;
newStructures.add(vector[i].next);
}
if (!m_set.merge(newStructures))
return;
if (m_set.size() > polymorphismLimit)
makeTop();
}
bool StructureAbstractValue::add(RegisteredStructure structure)
{
if (isTop())
return false;
if (!m_set.add(structure))
return false;
if (m_set.size() > polymorphismLimit)
makeTop();
return true;
}
bool StructureAbstractValue::merge(const RegisteredStructureSet& other)
{
if (isTop())
return false;
return mergeNotTop(other);
}
bool StructureAbstractValue::mergeSlow(const StructureAbstractValue& other)
{
bool changed = false;
if (!isClobbered() && other.isClobbered()) {
setClobbered(true);
changed = true;
}
changed |= mergeNotTop(other.m_set);
return changed;
}
bool StructureAbstractValue::mergeNotTop(const RegisteredStructureSet& other)
{
if (!m_set.merge(other))
return false;
if (m_set.size() > polymorphismLimit)
makeTop();
return true;
}
void StructureAbstractValue::filter(const RegisteredStructureSet& other)
{
if (isTop()) {
m_set = other;
return;
}
if (isClobbered()) {
if (other.size() > m_set.size() + clobberedSupremacyThreshold)
return;
m_set = other;
setClobbered(false);
return;
}
m_set.filter(other);
}
void StructureAbstractValue::filter(const StructureAbstractValue& other)
{
if (other.isTop())
return;
if (other.isClobbered()) {
if (isTop())
return;
if (!isClobbered()) {
if (m_set.size() > other.m_set.size() + clobberedSupremacyThreshold)
*this = other; return;
}
m_set.filter(other.m_set);
return;
}
filter(other.m_set);
}
void StructureAbstractValue::filterSlow(SpeculatedType type)
{
if (!(type & SpecCell)) {
clear();
return;
}
ASSERT(!isTop());
m_set.genericFilter(
[&] (RegisteredStructure structure) {
return !!(speculationFromStructure(structure.get()) & type);
});
}
void StructureAbstractValue::filterClassInfoSlow(const ClassInfo* classInfo)
{
ASSERT(!isTop());
m_set.genericFilter(
[&] (RegisteredStructure structure) {
return structure->classInfo()->isSubClassOf(classInfo);
});
}
bool StructureAbstractValue::contains(RegisteredStructure structure) const
{
if (isInfinite())
return true;
return m_set.contains(structure);
}
bool StructureAbstractValue::contains(Structure* structure) const
{
if (isInfinite())
return true;
return m_set.toStructureSet().contains(structure);
}
bool StructureAbstractValue::isSubsetOf(const RegisteredStructureSet& other) const
{
if (isInfinite())
return false;
return m_set.isSubsetOf(other);
}
bool StructureAbstractValue::isSubsetOf(const StructureAbstractValue& other) const
{
if (isTop())
return false;
if (other.isTop())
return true;
if (isClobbered() == other.isClobbered())
return m_set.isSubsetOf(other.m_set);
if (isClobbered())
return false;
return m_set.isSubsetOf(other.m_set);
}
bool StructureAbstractValue::isSupersetOf(const RegisteredStructureSet& other) const
{
if (isInfinite())
return true;
return m_set.isSupersetOf(other);
}
bool StructureAbstractValue::overlaps(const RegisteredStructureSet& other) const
{
if (isInfinite())
return true;
return m_set.overlaps(other);
}
bool StructureAbstractValue::overlaps(const StructureAbstractValue& other) const
{
if (other.isInfinite())
return true;
return overlaps(other.m_set);
}
bool StructureAbstractValue::isSubClassOf(const ClassInfo* classInfo) const
{
if (isInfinite())
return false;
for (const RegisteredStructure structure : m_set) {
if (!structure->classInfo()->isSubClassOf(classInfo))
return false;
}
return true;
}
bool StructureAbstractValue::equalsSlow(const StructureAbstractValue& other) const
{
ASSERT(m_set.m_pointer != other.m_set.m_pointer);
ASSERT(!isTop());
ASSERT(!other.isTop());
return m_set == other.m_set
&& isClobbered() == other.isClobbered();
}
void StructureAbstractValue::dumpInContext(PrintStream& out, DumpContext* context) const
{
if (isClobbered())
out.print("Clobbered:");
if (isTop())
out.print("TOP");
else
out.print(inContext(m_set.toStructureSet(), context));
}
void StructureAbstractValue::dump(PrintStream& out) const
{
dumpInContext(out, 0);
}
void StructureAbstractValue::validateReferences(const TrackedReferences& trackedReferences) const
{
if (isTop())
return;
m_set.validateReferences(trackedReferences);
}
} }
#endif // ENABLE(DFG_JIT)