// Partially evaluate the programList with respect to the given static inputs, // producing a new ProgramLines object. public ProgramLines PEval(Value[] args, FullCellAddr[] residualInputs) { PEnv pEnv = new PEnv(); // Map static input cells to their constant values: for (int i = 0; i < args.Length; i++) { pEnv[inputCells[i]] = CGConst.Make(args[i]); } ProgramLines residual = new ProgramLines(outputCell, residualInputs); // PE-time environment PEnv maps each residual input cell address to the delegate argument: for (int i = 0; i < residualInputs.Length; i++) { FullCellAddr input = residualInputs[i]; pEnv[input] = new CGCellRef(input, residual.addressToVariable[input]); } // Process the given function's compute cells in dependency order, output last: foreach (ComputeCell ccell in programList) { ComputeCell rCcell = ccell.PEval(pEnv); if (rCcell != null) { residual.AddComputeCell(ccell.cellAddr, rCcell); } } residual = residual.PruneZeroUseCells(); return(residual); }
private ProgramLines PruneZeroUseCells() { // This is slightly more general than necessary, since we know that the // new order of FullCellAddrs could be embedded in the old one. So it would suffice // to simply count the number of uses of each FullCellAddr rather than do this sort. DependencyGraph dpGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList <FullCellAddr> prunedList = dpGraph.PrecedentOrder(); ProgramLines prunedProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in prunedList) { prunedProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } return(prunedProgram); }
/// CodeGenerate.Initialize(ilg) must be called first. public void EvalCondReorderCompile() { ComputeEvalConds(); // Re-sort the expressions to reflect new dependencies // introduced by evaluation conditions DependencyGraph augmentedGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList <FullCellAddr> augmentedList = augmentedGraph.PrecedentOrder(); ProgramLines finalProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in augmentedList) { finalProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } // This relies on all pathconds having been generated at this point: EmitCacheInitializations(); finalProgram.CreateUnwrappedNumberCells(); finalProgram.Compile(); }
/// CodeGenerate.Initialize(ilg) must be called first. public void EvalCondReorderCompile() { ComputeEvalConds(); // Re-sort the expressions to reflect new dependencies // introduced by evaluation conditions DependencyGraph augmentedGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList<FullCellAddr> augmentedList = augmentedGraph.PrecedentOrder(); ProgramLines finalProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in augmentedList) { finalProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } // This relies on all pathconds having been generated at this point: EmitCacheInitializations(); finalProgram.CreateUnwrappedNumberCells(); finalProgram.Compile(); }
private ProgramLines PruneZeroUseCells() { // This is slightly more general than necessary, since we know that the // new order of FullCellAddrs could be embedded in the old one. So it would suffice // to simply count the number of uses of each FullCellAddr rather than do this sort. DependencyGraph dpGraph = new DependencyGraph(outputCell, inputCells, GetComputeCell); IList<FullCellAddr> prunedList = dpGraph.PrecedentOrder(); ProgramLines prunedProgram = new ProgramLines(outputCell, inputCells); foreach (FullCellAddr cellAddr in prunedList) { prunedProgram.AddComputeCell(cellAddr, GetComputeCell(cellAddr)); } return prunedProgram; }
// Partially evaluate the programList with respect to the given static inputs, // producing a new ProgramLines object. public ProgramLines PEval(Value[] args, FullCellAddr[] residualInputs) { PEnv pEnv = new PEnv(); // Map static input cells to their constant values: for (int i = 0; i < args.Length; i++) { pEnv[inputCells[i]] = CGConst.Make(args[i]); } ProgramLines residual = new ProgramLines(outputCell, residualInputs); // PE-time environment PEnv maps each residual input cell address to the delegate argument: for (int i = 0; i < residualInputs.Length; i++) { FullCellAddr input = residualInputs[i]; pEnv[input] = new CGCellRef(input, residual.addressToVariable[input]); } // Process the given function's compute cells in dependency order, output last: foreach (ComputeCell ccell in programList) { ComputeCell rCcell = ccell.PEval(pEnv); if (rCcell != null) { residual.AddComputeCell(ccell.cellAddr, rCcell); } } residual = residual.PruneZeroUseCells(); return residual; }