Search in sources :

Example 36 with WhileProgramBlock

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);
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ArrayList(java.util.ArrayList) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock)

Aggregations

WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)36 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)35 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)35 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)31 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)28 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)21 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)15 ArrayList (java.util.ArrayList)14 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)14 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)14 StatementBlock (org.apache.sysml.parser.StatementBlock)14 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)12 Instruction (org.apache.sysml.runtime.instructions.Instruction)12 Hop (org.apache.sysml.hops.Hop)7 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)7 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)6 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)5 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)4