while (instrs.hasNext()) { Instr instr = instrs.next(); Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr.isDead()) { instrs.remove();
@Override public Object execute(IRScope s, Object... data) { // This let us compute execute scope flags for a method based on what all nested closures do for (IRClosure c: s.getClosures()) { run(c, true); } for (BasicBlock b: ((CFG) data[0]).getBasicBlocks()) { runLocalOptsOnInstrList(s, b.getInstrs().listIterator(), false); } // Only after running local opts, compute various execution scope flags s.computeScopeFlags(); // Mark done locallyOptimized = true; return null; }
} else { if (!res.equals(val)) { recordSimplification(res, val, valueMap, simplificationMap);
@Override public Object execute(IRScope s, Object... data) { for (BasicBlock b: s.getCFG().getBasicBlocks()) { runLocalOptsOnBasicBlock(s, b); } // SSS FIXME: What is this about? // Why 'Only after running local opts'? Figure out and document. // // Only after running local opts, compute various execution scope flags. s.computeScopeFlags(); // LVA information is no longer valid after this pass // Currently, we don't run this after LVA, but just in case ... // // FIXME: Grrr ... this seems broken to have to create a new object to invalidate (new LiveVariableAnalysis()).invalidate(s); return null; }
} else { if (!res.equals(val)) { recordSimplification(res, val, valueMap, simplificationMap);
@Override public Object execute(IRScope s, Object... data) { for (BasicBlock b: s.getCFG().getBasicBlocks()) { runLocalOptsOnBasicBlock(s, b); } // SSS FIXME: What is this about? // Why 'Only after running local opts'? Figure out and document. // // Only after running local opts, compute various execution scope flags. s.computeScopeFlags(); // LVA information is no longer valid after this pass // Currently, we don't run this after LVA, but just in case ... // // FIXME: Grrr ... this seems broken to have to create a new object to invalidate (new LiveVariableAnalysis()).invalidate(s); return null; }
recordSimplification(res, val, valueMap, simplificationMap); } else if (!i.hasSideEffects()) { if (i instanceof CopyInstr) {
@Override public Object execute(IRScope s, Object... data) { // This let us compute execute scope flags for a method based on what all nested closures do for (IRClosure c: s.getClosures()) { run(c, true); } for (BasicBlock b: ((CFG) data[0]).getBasicBlocks()) { runLocalOptsOnInstrList(s, b.getInstrs().listIterator(), false); } // Only after running local opts, compute various execution scope flags s.computeScopeFlags(); // Mark done locallyOptimized = true; return null; }
while (instrs.hasNext()) { Instr instr = instrs.next(); Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr.isDead()) { instrs.remove();
recordSimplification(res, val, valueMap, simplificationMap); } else if (!i.hasSideEffects()) { if (i instanceof CopyInstr) {
public static void runLocalOptsOnInstrArray(IRScope s, Instr[] instrs) { // Reset value map if this instruction is the start/end of a basic block Map<Operand,Operand> valueMap = new HashMap<>(); Map<Variable,List<Variable>> simplificationMap = new HashMap<>(); for (int i = 0; i < instrs.length; i++) { Instr instr = instrs[i]; Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr != instr) { instrs[i] = newInstr; } // If the call has been optimized away in the previous step, it is no longer a hard boundary for opts! // // Right now, calls are considered hard boundaries for optimization and // information cannot be propagated across them! // // SSS FIXME: Rather than treat all calls with a broad brush, what we need // is to capture different attributes about a call : // - uses closures // - known call target // - can modify scope, // - etc. // // This information is present in instruction flags on CallBase. Use it! Operation iop = instr.getOperation(); if (iop.startsBasicBlock() || iop.endsBasicBlock() || (iop.isCall() && !instr.isDead())) { valueMap = new HashMap<>(); simplificationMap = new HashMap<>(); } } }
public static void runLocalOptsOnInstrArray(IRScope s, Instr[] instrs) { // Reset value map if this instruction is the start/end of a basic block Map<Operand,Operand> valueMap = new HashMap<>(); Map<Variable,List<Variable>> simplificationMap = new HashMap<>(); for (int i = 0; i < instrs.length; i++) { Instr instr = instrs[i]; Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr != instr) { instrs[i] = newInstr; } // If the call has been optimized away in the previous step, it is no longer a hard boundary for opts! // // Right now, calls are considered hard boundaries for optimization and // information cannot be propagated across them! // // SSS FIXME: Rather than treat all calls with a broad brush, what we need // is to capture different attributes about a call : // - uses closures // - known call target // - can modify scope, // - etc. // // This information is present in instruction flags on CallBase. Use it! Operation iop = instr.getOperation(); if (iop.startsBasicBlock() || iop.endsBasicBlock() || (iop.isCall() && !instr.isDead())) { valueMap = new HashMap<>(); simplificationMap = new HashMap<>(); } } }