use of org.apache.sysml.parser.IfStatement in project incubator-systemml by apache.
the class Explain method explainStatementBlock.
private static String explainStatementBlock(StatementBlock sb, int level) {
StringBuilder builder = new StringBuilder();
String offset = createOffset(level);
if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
builder.append(offset);
if (!wsb.getUpdateInPlaceVars().isEmpty())
builder.append("WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ") [in-place=" + wsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ")\n");
builder.append(explainHop(wsb.getPredicateHops(), level + 1));
WhileStatement ws = (WhileStatement) sb.getStatement(0);
for (StatementBlock current : ws.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof IfStatementBlock) {
IfStatementBlock ifsb = (IfStatementBlock) sb;
builder.append(offset);
builder.append("IF (lines " + ifsb.getBeginLine() + "-" + ifsb.getEndLine() + ")\n");
builder.append(explainHop(ifsb.getPredicateHops(), level + 1));
IfStatement ifs = (IfStatement) sb.getStatement(0);
for (StatementBlock current : ifs.getIfBody()) builder.append(explainStatementBlock(current, level + 1));
if (!ifs.getElseBody().isEmpty()) {
builder.append(offset);
builder.append("ELSE\n");
}
for (StatementBlock current : ifs.getElseBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
builder.append(offset);
if (sb instanceof ParForStatementBlock) {
if (!fsb.getUpdateInPlaceVars().isEmpty())
builder.append("PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")\n");
} else {
if (!fsb.getUpdateInPlaceVars().isEmpty())
builder.append("FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")\n");
}
if (fsb.getFromHops() != null)
builder.append(explainHop(fsb.getFromHops(), level + 1));
if (fsb.getToHops() != null)
builder.append(explainHop(fsb.getToHops(), level + 1));
if (fsb.getIncrementHops() != null)
builder.append(explainHop(fsb.getIncrementHops(), level + 1));
ForStatement fs = (ForStatement) sb.getStatement(0);
for (StatementBlock current : fs.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof FunctionStatementBlock) {
FunctionStatement fsb = (FunctionStatement) sb.getStatement(0);
for (StatementBlock current : fsb.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else {
// For generic StatementBlock
builder.append(offset);
builder.append("GENERIC (lines " + sb.getBeginLine() + "-" + sb.getEndLine() + ") [recompile=" + sb.requiresRecompilation() + "]\n");
ArrayList<Hop> hopsDAG = sb.getHops();
if (hopsDAG != null && !hopsDAG.isEmpty()) {
Hop.resetVisitStatus(hopsDAG);
for (Hop hop : hopsDAG) builder.append(explainHop(hop, level + 1));
Hop.resetVisitStatus(hopsDAG);
}
}
return builder.toString();
}
use of org.apache.sysml.parser.IfStatement in project systemml by apache.
the class PydmlSyntacticValidator method exitElifBranch.
@Override
public void exitElifBranch(ElifBranchContext ctx) {
IfStatement elifStmt = new IfStatement();
ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
elifStmt.setConditionalPredicate(predicate);
elifStmt.setCtxValuesAndFilename(ctx, currentFile);
if (ctx.elifBody.size() > 0) {
for (StatementContext stmtCtx : ctx.elifBody) {
elifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
}
elifStmt.mergeStatementBlocksIfBody();
}
ctx.info.stmt = elifStmt;
setFileLineColumn(ctx.info.stmt, ctx);
}
use of org.apache.sysml.parser.IfStatement in project systemml by apache.
the class Explain method explainStatementBlock.
private static String explainStatementBlock(StatementBlock sb, int level) {
StringBuilder builder = new StringBuilder();
String offset = createOffset(level);
if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
builder.append(offset);
if (!wsb.getUpdateInPlaceVars().isEmpty())
builder.append("WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ") [in-place=" + wsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ")\n");
builder.append(explainHop(wsb.getPredicateHops(), level + 1));
WhileStatement ws = (WhileStatement) sb.getStatement(0);
for (StatementBlock current : ws.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof IfStatementBlock) {
IfStatementBlock ifsb = (IfStatementBlock) sb;
builder.append(offset);
builder.append("IF (lines " + ifsb.getBeginLine() + "-" + ifsb.getEndLine() + ")\n");
builder.append(explainHop(ifsb.getPredicateHops(), level + 1));
IfStatement ifs = (IfStatement) sb.getStatement(0);
for (StatementBlock current : ifs.getIfBody()) builder.append(explainStatementBlock(current, level + 1));
if (!ifs.getElseBody().isEmpty()) {
builder.append(offset);
builder.append("ELSE\n");
}
for (StatementBlock current : ifs.getElseBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
builder.append(offset);
if (sb instanceof ParForStatementBlock) {
if (!fsb.getUpdateInPlaceVars().isEmpty())
builder.append("PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")\n");
} else {
if (!fsb.getUpdateInPlaceVars().isEmpty())
builder.append("FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
else
builder.append("FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")\n");
}
if (fsb.getFromHops() != null)
builder.append(explainHop(fsb.getFromHops(), level + 1));
if (fsb.getToHops() != null)
builder.append(explainHop(fsb.getToHops(), level + 1));
if (fsb.getIncrementHops() != null)
builder.append(explainHop(fsb.getIncrementHops(), level + 1));
ForStatement fs = (ForStatement) sb.getStatement(0);
for (StatementBlock current : fs.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else if (sb instanceof FunctionStatementBlock) {
FunctionStatement fsb = (FunctionStatement) sb.getStatement(0);
for (StatementBlock current : fsb.getBody()) builder.append(explainStatementBlock(current, level + 1));
} else {
// For generic StatementBlock
builder.append(offset);
builder.append("GENERIC (lines " + sb.getBeginLine() + "-" + sb.getEndLine() + ") [recompile=" + sb.requiresRecompilation() + "]\n");
ArrayList<Hop> hopsDAG = sb.getHops();
if (hopsDAG != null && !hopsDAG.isEmpty()) {
Hop.resetVisitStatus(hopsDAG);
for (Hop hop : hopsDAG) builder.append(explainHop(hop, level + 1));
Hop.resetVisitStatus(hopsDAG);
}
}
return builder.toString();
}
use of org.apache.sysml.parser.IfStatement in project systemml by apache.
the class RewriteCompressedReblock method rAnalyzeProgram.
private static void rAnalyzeProgram(StatementBlock sb, ProbeStatus status) {
if (sb instanceof FunctionStatementBlock) {
FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
for (StatementBlock csb : fstmt.getBody()) rAnalyzeProgram(csb, status);
} else if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
for (StatementBlock csb : wstmt.getBody()) rAnalyzeProgram(csb, status);
if (wsb.variablesRead().containsAnyName(status.compMtx))
status.usedInLoop = true;
} else if (sb instanceof IfStatementBlock) {
IfStatementBlock isb = (IfStatementBlock) sb;
IfStatement istmt = (IfStatement) isb.getStatement(0);
for (StatementBlock csb : istmt.getIfBody()) rAnalyzeProgram(csb, status);
for (StatementBlock csb : istmt.getElseBody()) rAnalyzeProgram(csb, status);
if (isb.variablesUpdated().containsAnyName(status.compMtx))
status.condUpdate = true;
} else if (sb instanceof ForStatementBlock) {
// incl parfor
ForStatementBlock fsb = (ForStatementBlock) sb;
ForStatement fstmt = (ForStatement) fsb.getStatement(0);
for (StatementBlock csb : fstmt.getBody()) rAnalyzeProgram(csb, status);
if (fsb.variablesRead().containsAnyName(status.compMtx))
status.usedInLoop = true;
} else if (sb.getHops() != null) {
// generic (last-level)
ArrayList<Hop> roots = sb.getHops();
Hop.resetVisitStatus(roots);
// process entire HOP DAG starting from the roots
for (Hop root : roots) rAnalyzeHopDag(root, status);
// remove temporary variables
status.compMtx.removeIf(n -> n.startsWith(TMP_PREFIX));
Hop.resetVisitStatus(roots);
}
}
use of org.apache.sysml.parser.IfStatement in project systemml by apache.
the class ProgramRewriter method rRewriteStatementBlock.
public ArrayList<StatementBlock> rRewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status, boolean splitDags) {
ArrayList<StatementBlock> ret = new ArrayList<>();
ret.add(sb);
// recursive invocation
if (sb instanceof FunctionStatementBlock) {
FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
fstmt.setBody(rRewriteStatementBlocks(fstmt.getBody(), status, splitDags));
} else if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
wstmt.setBody(rRewriteStatementBlocks(wstmt.getBody(), status, splitDags));
} else if (sb instanceof IfStatementBlock) {
IfStatementBlock isb = (IfStatementBlock) sb;
IfStatement istmt = (IfStatement) isb.getStatement(0);
istmt.setIfBody(rRewriteStatementBlocks(istmt.getIfBody(), status, splitDags));
istmt.setElseBody(rRewriteStatementBlocks(istmt.getElseBody(), status, splitDags));
} else if (sb instanceof ForStatementBlock) {
// incl parfor
// maintain parfor context information (e.g., for checkpointing)
boolean prestatus = status.isInParforContext();
if (sb instanceof ParForStatementBlock)
status.setInParforContext(true);
ForStatementBlock fsb = (ForStatementBlock) sb;
ForStatement fstmt = (ForStatement) fsb.getStatement(0);
fstmt.setBody(rRewriteStatementBlocks(fstmt.getBody(), status, splitDags));
status.setInParforContext(prestatus);
}
// apply rewrite rules to individual statement blocks
for (StatementBlockRewriteRule r : _sbRuleSet) {
if (!splitDags && r.createsSplitDag())
continue;
ArrayList<StatementBlock> tmp = new ArrayList<>();
for (StatementBlock sbc : ret) tmp.addAll(r.rewriteStatementBlock(sbc, status));
// take over set of rewritten sbs
ret.clear();
ret.addAll(tmp);
}
return ret;
}
Aggregations