use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class MLContextUtil method deleteRemoveVariableInstructions.
/**
* Recursively traverse program block to delete 'remove variable'
* instructions.
*
* @param pb
* Program block
*/
private static void deleteRemoveVariableInstructions(ProgramBlock pb) {
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
for (ProgramBlock pbc : wpb.getChildBlocks()) deleteRemoveVariableInstructions(pbc);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) deleteRemoveVariableInstructions(pbc);
for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) deleteRemoveVariableInstructions(pbc);
} else if (pb instanceof ForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
for (ProgramBlock pbc : fpb.getChildBlocks()) deleteRemoveVariableInstructions(pbc);
} else {
ArrayList<Instruction> instructions = pb.getInstructions();
deleteRemoveVariableInstructions(instructions);
}
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class Recompiler method recompileProgramBlockInstructions.
/**
* This method does NO full program block recompile (no stats update, no rewrites, no recursion) but
* only regenerates lops and instructions. The primary use case is recompilation after are hop configuration
* changes which allows to preserve statistics (e.g., propagated worst case stats from other program blocks)
* and better performance for recompiling individual program blocks.
*
* @param pb program block
* @throws IOException if IOException occurs
*/
public static void recompileProgramBlockInstructions(ProgramBlock pb) throws IOException {
if (pb instanceof WhileProgramBlock) {
// recompile while predicate instructions
WhileProgramBlock wpb = (WhileProgramBlock) pb;
WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
if (wsb != null && wsb.getPredicateHops() != null)
wpb.setPredicate(recompileHopsDagInstructions(wsb.getPredicateHops()));
} else if (pb instanceof IfProgramBlock) {
// recompile if predicate instructions
IfProgramBlock ipb = (IfProgramBlock) pb;
IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
if (isb != null && isb.getPredicateHops() != null)
ipb.setPredicate(recompileHopsDagInstructions(isb.getPredicateHops()));
} else if (pb instanceof ForProgramBlock) {
// recompile for/parfor predicate instructions
ForProgramBlock fpb = (ForProgramBlock) pb;
ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
if (fsb != null && fsb.getFromHops() != null)
fpb.setFromInstructions(recompileHopsDagInstructions(fsb.getFromHops()));
if (fsb != null && fsb.getToHops() != null)
fpb.setToInstructions(recompileHopsDagInstructions(fsb.getToHops()));
if (fsb != null && fsb.getIncrementHops() != null)
fpb.setIncrementInstructions(recompileHopsDagInstructions(fsb.getIncrementHops()));
} else {
// recompile last-level program block instructions
StatementBlock sb = pb.getStatementBlock();
if (sb != null && sb.getHops() != null) {
pb.setInstructions(recompileHopsDagInstructions(sb, sb.getHops()));
}
}
}
Aggregations