DFGWatchpointCollectionPhase.cpp [plain text]
#include "config.h"
#include "DFGWatchpointCollectionPhase.h"
#if ENABLE(DFG_JIT)
#include "ArrayPrototype.h"
#include "DFGClobberize.h"
#include "DFGGraph.h"
#include "DFGPhase.h"
#include "JSCInlines.h"
namespace JSC { namespace DFG {
class WatchpointCollectionPhase : public Phase {
static const bool verbose = false;
public:
WatchpointCollectionPhase(Graph& graph)
: Phase(graph, "watchpoint collection")
{
}
bool run()
{
for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
BasicBlock* block = m_graph.block(blockIndex);
if (!block)
continue;
for (unsigned nodeIndex = block->size(); nodeIndex--;) {
m_node = block->at(nodeIndex);
handle();
}
}
return true;
}
private:
void handle()
{
switch (m_node->op()) {
case CompareEqConstant:
case IsUndefined:
handleMasqueradesAsUndefined();
break;
case CompareEq:
if (m_node->isBinaryUseKind(ObjectUse)
|| (m_node->child1().useKind() == ObjectUse && m_node->child2().useKind() == ObjectOrOtherUse)
|| (m_node->child1().useKind() == ObjectOrOtherUse && m_node->child2().useKind() == ObjectUse))
handleMasqueradesAsUndefined();
break;
case LogicalNot:
case Branch:
switch (m_node->child1().useKind()) {
case ObjectOrOtherUse:
case UntypedUse:
handleMasqueradesAsUndefined();
break;
default:
break;
}
break;
case NewArray:
case NewArrayWithSize:
case NewArrayBuffer:
if (!globalObject()->isHavingABadTime() && !hasAnyArrayStorage(m_node->indexingType()))
addLazily(globalObject()->havingABadTimeWatchpoint());
break;
case VarInjectionWatchpoint:
addLazily(globalObject()->varInjectionWatchpoint());
break;
default:
break;
}
}
void handleMasqueradesAsUndefined()
{
if (m_graph.masqueradesAsUndefinedWatchpointIsStillValid(m_node->origin.semantic))
addLazily(globalObject()->masqueradesAsUndefinedWatchpoint());
}
void addLazily(WatchpointSet* set)
{
m_graph.watchpoints().addLazily(set);
}
void addLazily(InlineWatchpointSet& set)
{
m_graph.watchpoints().addLazily(set);
}
JSGlobalObject* globalObject()
{
return m_graph.globalObjectFor(m_node->origin.semantic);
}
Node* m_node;
};
bool performWatchpointCollection(Graph& graph)
{
SamplingRegion samplingRegion("DFG Watchpoint Collection Phase");
return runPhase<WatchpointCollectionPhase>(graph);
}
} }
#endif // ENABLE(DFG_JIT)