/** * See "worklist algorithm" in http://www.cs.cornell.edu/courses/cs4120/2013fa/lectures/lec26-fa13.pdf * An alternative terminology for "kill/gen" is "def/use" */ private void compute(ControlFlowGraph cfg, SymbolTable symbols) { cfg.blocks().forEach(block -> liveVariablesPerBlock.put(block, LiveVariables.build(block, symbols))); Deque<CfgBlock> workList = new ArrayDeque<>(cfg.blocks()); while (!workList.isEmpty()) { CfgBlock currentBlock = workList.pop(); LiveVariables liveVariables = liveVariablesPerBlock.get(currentBlock); boolean liveInHasChanged = liveVariables.propagate(liveVariablesPerBlock); if (liveInHasChanged) { currentBlock.predecessors().forEach(workList::push); } } }
/** * See "worklist algorithm" in http://www.cs.cornell.edu/courses/cs4120/2013fa/lectures/lec26-fa13.pdf * An alternative terminology for "kill/gen" is "def/use" */ private void compute(ControlFlowGraph cfg, SymbolTable symbols) { cfg.blocks().forEach(block -> liveVariablesPerBlock.put(block, LiveVariables.build(block, symbols))); Deque<CfgBlock> workList = new ArrayDeque<>(cfg.blocks()); while (!workList.isEmpty()) { CfgBlock currentBlock = workList.pop(); LiveVariables liveVariables = liveVariablesPerBlock.get(currentBlock); boolean liveInHasChanged = liveVariables.propagate(liveVariablesPerBlock); if (liveInHasChanged) { currentBlock.predecessors().forEach(workList::push); } } }