use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.
the class DMLProgram method addCleanupInstruction.
/**
* Adds the generated cleanup RMVAR instruction to the given program block.
* In case of generic (last-level) programblocks it is added to the end of
* the list of instructions, while for complex program blocks it is added to
* the end of the list of exit instructions.
*
* @param pb program block
* @param inst instruction
* @throws DMLRuntimeException if DMLRuntimeException occurs
*/
private void addCleanupInstruction(ProgramBlock pb, Instruction inst) throws DMLRuntimeException {
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
ArrayList<ProgramBlock> childs = wpb.getChildBlocks();
if (//generic last level pb
!childs.get(childs.size() - 1).getInstructions().isEmpty())
childs.get(childs.size() - 1).addInstruction(inst);
else {
ProgramBlock pbNew = new ProgramBlock(pb.getProgram());
pbNew.addInstruction(inst);
childs.add(pbNew);
}
} else if (//includes ParFORProgramBlock
pb instanceof ForProgramBlock) {
ForProgramBlock wpb = (ForProgramBlock) pb;
ArrayList<ProgramBlock> childs = wpb.getChildBlocks();
if (//generic last level pb
!childs.get(childs.size() - 1).getInstructions().isEmpty())
childs.get(childs.size() - 1).addInstruction(inst);
else {
ProgramBlock pbNew = new ProgramBlock(pb.getProgram());
pbNew.addInstruction(inst);
childs.add(pbNew);
}
} else if (pb instanceof IfProgramBlock)
((IfProgramBlock) pb).addExitInstruction(inst);
else if (//includes ExternalFunctionProgramBlock and ExternalFunctionProgramBlockCP)
pb instanceof FunctionProgramBlock)
//do nothing
;
else {
//add inst at end of pb
pb.addInstruction(inst);
}
}
Aggregations