bool run() { ASSERT(m_graph.m_form == ThreadedCPS || m_graph.m_form == SSA); ASSERT(m_graph.m_unificationState == GloballyUnified); ASSERT(m_graph.m_refCountState == EverythingIsLive); m_count = 0; if (m_verbose && !shouldDumpGraphAtEachPhase()) { dataLog("Graph before CFA:\n"); m_graph.dump(); } // This implements a pseudo-worklist-based forward CFA, except that the visit order // of blocks is the bytecode program order (which is nearly topological), and // instead of a worklist we just walk all basic blocks checking if cfaShouldRevisit // is set to true. This is likely to balance the efficiency properties of both // worklist-based and forward fixpoint-based approaches. Like a worklist-based // approach, it won't visit code if it's meaningless to do so (nothing changed at // the head of the block or the predecessors have not been visited). Like a forward // fixpoint-based approach, it has a high probability of only visiting a block // after all predecessors have been visited. Only loops will cause this analysis to // revisit blocks, and the amount of revisiting is proportional to loop depth. m_state.initialize(); do { m_changed = false; performForwardCFA(); } while (m_changed); return true; }
void Phase::beginPhase() { if (Options::verboseValidationFailure()) { StringPrintStream out; m_graph.dump(out); m_graphDumpBeforePhase = out.toCString(); } if (!shouldDumpGraphAtEachPhase(m_graph.m_plan.mode())) return; dataLog("Beginning DFG phase ", m_name, ".\n"); dataLog("Before ", m_name, ":\n"); m_graph.dump(); }
bool run() { ASSERT(m_graph.m_form == ThreadedCPS || m_graph.m_form == SSA); ASSERT(m_graph.m_unificationState == GloballyUnified); ASSERT(m_graph.m_refCountState == EverythingIsLive); m_count = 0; if (m_verbose && !shouldDumpGraphAtEachPhase(m_graph.m_plan.mode)) { dataLog("Graph before CFA:\n"); m_graph.dump(); } // This implements a pseudo-worklist-based forward CFA, except that the visit order // of blocks is the bytecode program order (which is nearly topological), and // instead of a worklist we just walk all basic blocks checking if cfaShouldRevisit // is set to true. This is likely to balance the efficiency properties of both // worklist-based and forward fixpoint-based approaches. Like a worklist-based // approach, it won't visit code if it's meaningless to do so (nothing changed at // the head of the block or the predecessors have not been visited). Like a forward // fixpoint-based approach, it has a high probability of only visiting a block // after all predecessors have been visited. Only loops will cause this analysis to // revisit blocks, and the amount of revisiting is proportional to loop depth. m_state.initialize(); do { m_changed = false; performForwardCFA(); } while (m_changed); if (m_graph.m_form != SSA) { if (m_verbose) dataLog(" Widening state at OSR entry block.\n"); ASSERT(!m_changed); // Widen the abstract values at the block that serves as the must-handle OSR entry. for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) { BasicBlock* block = m_graph.block(blockIndex); if (!block) continue; if (!block->isOSRTarget) continue; if (block->bytecodeBegin != m_graph.m_plan.osrEntryBytecodeIndex) continue; if (m_verbose) dataLog(" Found must-handle block: ", *block, "\n"); bool changed = false; for (size_t i = m_graph.m_plan.mustHandleValues.size(); i--;) { int operand = m_graph.m_plan.mustHandleValues.operandForIndex(i); JSValue value = m_graph.m_plan.mustHandleValues[i]; Node* node = block->variablesAtHead.operand(operand); if (!node) { if (m_verbose) dataLog(" Not live: ", VirtualRegister(operand), "\n"); continue; } if (m_verbose) dataLog(" Widening ", VirtualRegister(operand), " with ", value, "\n"); AbstractValue& target = block->valuesAtHead.operand(operand); changed |= target.mergeOSREntryValue(m_graph, value); target.fixTypeForRepresentation( m_graph, resultFor(node->variableAccessData()->flushFormat())); } if (changed || !block->cfaHasVisited) { m_changed = true; block->cfaShouldRevisit = true; } } // Propagate any of the changes we just introduced. while (m_changed) { m_changed = false; performForwardCFA(); } // Make sure we record the intersection of all proofs that we ever allowed the // compiler to rely upon. for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) { BasicBlock* block = m_graph.block(blockIndex); if (!block) continue; block->intersectionOfCFAHasVisited &= block->cfaHasVisited; for (unsigned i = block->intersectionOfPastValuesAtHead.size(); i--;) block->intersectionOfPastValuesAtHead[i].filter(block->valuesAtHead[i]); } } return true; }