use of org.apache.sysml.parser.WhileStatementBlock 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));
}
}
use of org.apache.sysml.parser.WhileStatementBlock in project systemml by apache.
the class RewriteMarkLoopVariablesUpdateInPlace method rewriteStatementBlock.
@Override
public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status) {
if (DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP || DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK) {
// nothing to do here, return original statement block
return Arrays.asList(sb);
}
if (// incl parfor
sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock) {
ArrayList<String> candidates = new ArrayList<>();
VariableSet updated = sb.variablesUpdated();
VariableSet liveout = sb.liveOut();
for (String varname : updated.getVariableNames()) {
if (updated.getVariable(varname).getDataType() == DataType.MATRIX && // exclude local vars
liveout.containsVariable(varname)) {
if (sb instanceof WhileStatementBlock) {
WhileStatement wstmt = (WhileStatement) sb.getStatement(0);
if (rIsApplicableForUpdateInPlace(wstmt.getBody(), varname))
candidates.add(varname);
} else if (sb instanceof ForStatementBlock) {
ForStatement wstmt = (ForStatement) sb.getStatement(0);
if (rIsApplicableForUpdateInPlace(wstmt.getBody(), varname))
candidates.add(varname);
}
}
}
sb.setUpdateInPlaceVars(candidates);
}
// return modified statement block
return Arrays.asList(sb);
}
Aggregations