while (instrs.hasNext()) { Instr instr = instrs.next(); Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr.isDead()) { instrs.remove();
while (instrs.hasNext()) { Instr instr = instrs.next(); Instr newInstr = optInstr(s, instr, valueMap, simplificationMap); if (newInstr.isDead()) { instrs.remove();
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<>(); } } }