Search in sources :

Example 41 with IfStatement

use of org.apache.sysml.parser.IfStatement in project systemml by apache.

the class DmlSyntacticValidator method exitIfStatement.

@Override
public void exitIfStatement(IfStatementContext ctx) {
    IfStatement ifStmt = new IfStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    ifStmt.setConditionalPredicate(predicate);
    ifStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.ifBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.ifBody) {
            ifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
        }
        ifStmt.mergeStatementBlocksIfBody();
    }
    if (ctx.elseBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.elseBody) {
            ifStmt.addStatementBlockElseBody(getStatementBlock(stmtCtx.info.stmt));
        }
        ifStmt.mergeStatementBlocksElseBody();
    }
    ctx.info.stmt = ifStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : IfStatement(org.apache.sysml.parser.IfStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) ImportStatementContext(org.apache.sysml.parser.dml.DmlParser.ImportStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.IfdefAssignmentStatementContext) FunctionStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext) AccumulatorAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AccumulatorAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.dml.DmlParser.ForStatementContext) AssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.dml.DmlParser.IfStatementContext) PathStatementContext(org.apache.sysml.parser.dml.DmlParser.PathStatementContext) WhileStatementContext(org.apache.sysml.parser.dml.DmlParser.WhileStatementContext) ParForStatementContext(org.apache.sysml.parser.dml.DmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallAssignmentStatementContext) StatementContext(org.apache.sysml.parser.dml.DmlParser.StatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext)

Example 42 with IfStatement

use of org.apache.sysml.parser.IfStatement in project systemml by apache.

the class SpoofCompiler method generateCodeFromStatementBlock.

public static void generateCodeFromStatementBlock(StatementBlock current) {
    if (current instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) current;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock sb : fstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else if (current instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) current;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        wsb.setPredicateHops(optimize(wsb.getPredicateHops(), false));
        for (StatementBlock sb : wstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else if (current instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) current;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        isb.setPredicateHops(optimize(isb.getPredicateHops(), false));
        for (StatementBlock sb : istmt.getIfBody()) generateCodeFromStatementBlock(sb);
        for (StatementBlock sb : istmt.getElseBody()) generateCodeFromStatementBlock(sb);
    } else if (// incl parfor
    current instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) current;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        fsb.setFromHops(optimize(fsb.getFromHops(), false));
        fsb.setToHops(optimize(fsb.getToHops(), false));
        fsb.setIncrementHops(optimize(fsb.getIncrementHops(), false));
        for (StatementBlock sb : fstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else // generic (last-level)
    {
        current.setHops(generateCodeFromHopDAGs(current.getHops()));
        current.updateRecompilationFlag();
    }
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) FunctionStatement(org.apache.sysml.parser.FunctionStatement) IfStatement(org.apache.sysml.parser.IfStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) WhileStatement(org.apache.sysml.parser.WhileStatement) ForStatement(org.apache.sysml.parser.ForStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 43 with IfStatement

use of org.apache.sysml.parser.IfStatement in project systemml by apache.

the class IPAPassFlagFunctionsRecompileOnce method rFlagFunctionForRecompileOnce.

/**
 * Returns true if this statementblock requires recompilation inside a
 * loop statement block.
 *
 * @param sb statement block
 * @param inLoop true if in loop
 * @return true if statement block requires recompilation inside a loop statement block
 */
public boolean rFlagFunctionForRecompileOnce(StatementBlock sb, boolean inLoop) {
    boolean ret = false;
    if (sb instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock c : fstmt.getBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
    } else if (sb instanceof WhileStatementBlock) {
        // recompilation information not available at this point
        // hence, mark any loop statement block
        ret = true;
    } else if (sb instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        ret |= (inLoop && isb.requiresPredicateRecompilation());
        for (StatementBlock c : istmt.getIfBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
        for (StatementBlock c : istmt.getElseBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
    } else if (sb instanceof ForStatementBlock) {
        // recompilation information not available at this point
        // hence, mark any loop statement block
        ret = true;
    } else {
        ret |= (inLoop && sb.requiresRecompilation());
    }
    return ret;
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) FunctionStatement(org.apache.sysml.parser.FunctionStatement) IfStatement(org.apache.sysml.parser.IfStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 44 with IfStatement

use of org.apache.sysml.parser.IfStatement in project systemml by apache.

the class ProgramRewriter method rRewriteStatementBlockHopDAGs.

public void rRewriteStatementBlockHopDAGs(StatementBlock current, ProgramRewriteStatus state) {
    // ensure robustness for calls from outside
    if (state == null)
        state = new ProgramRewriteStatus();
    if (current instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) current;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock sb : fstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (current instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) current;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        wsb.setPredicateHops(rewriteHopDAG(wsb.getPredicateHops(), state));
        for (StatementBlock sb : wstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (current instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) current;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        isb.setPredicateHops(rewriteHopDAG(isb.getPredicateHops(), state));
        for (StatementBlock sb : istmt.getIfBody()) rRewriteStatementBlockHopDAGs(sb, state);
        for (StatementBlock sb : istmt.getElseBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (// incl parfor
    current instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) current;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        fsb.setFromHops(rewriteHopDAG(fsb.getFromHops(), state));
        fsb.setToHops(rewriteHopDAG(fsb.getToHops(), state));
        fsb.setIncrementHops(rewriteHopDAG(fsb.getIncrementHops(), state));
        for (StatementBlock sb : fstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else // generic (last-level)
    {
        current.setHops(rewriteHopDAG(current.getHops(), state));
    }
}
Also used : ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) FunctionStatement(org.apache.sysml.parser.FunctionStatement) IfStatement(org.apache.sysml.parser.IfStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) WhileStatement(org.apache.sysml.parser.WhileStatement) ForStatement(org.apache.sysml.parser.ForStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Aggregations

IfStatement (org.apache.sysml.parser.IfStatement)44 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)38 StatementBlock (org.apache.sysml.parser.StatementBlock)38 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)36 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)36 ForStatement (org.apache.sysml.parser.ForStatement)33 WhileStatement (org.apache.sysml.parser.WhileStatement)33 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)28 FunctionStatement (org.apache.sysml.parser.FunctionStatement)23 Hop (org.apache.sysml.hops.Hop)16 ArrayList (java.util.ArrayList)13 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)12 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)9 ConditionalPredicate (org.apache.sysml.parser.ConditionalPredicate)6 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)6 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)6 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)6 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)6 DMLProgram (org.apache.sysml.parser.DMLProgram)5 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5