@Override public Stmt getNextStmt() { return chooseThen ? ifStmt.getThenStmt() : ifStmt.getElseStmt(); }
@Override public void inject(Stmt stmt) { if (chooseThen) { assert !(ifStmt.getThenStmt() instanceof BlockStmt); List<Stmt> stmts = new ArrayList<>(); stmts.add(stmt); stmts.add(ifStmt.getThenStmt()); ifStmt.setThenStmt(new BlockStmt(stmts, false)); } else { assert ifStmt.hasElseStmt(); assert !(ifStmt.getElseStmt() instanceof BlockStmt); List<Stmt> stmts = new ArrayList<>(); stmts.add(stmt); stmts.add(ifStmt.getElseStmt()); ifStmt.setElseStmt(new BlockStmt(stmts, false)); } }
@Override public void visitIfStmt(IfStmt ifStmt) { if (shouldRemove.test(ifStmt.getThenStmt())) { ifStmt.setThenStmt(getReplacementStmt(ifStmt.getThenStmt())); } if (ifStmt.hasElseStmt()) { if (shouldRemove.test(ifStmt.getElseStmt())) { ifStmt.setElseStmt(getReplacementStmt(ifStmt.getElseStmt())); } } super.visitIfStmt(ifStmt); }
@Override public void visitIfStmt(IfStmt ifStmt) { super.visitIfStmt(ifStmt); if (!isBlock(ifStmt.getThenStmt())) { ifStmt.setThenStmt(makeBlock(ifStmt.getThenStmt())); } if (ifStmt.hasElseStmt() && !isBlock(ifStmt.getElseStmt())) { ifStmt.setElseStmt(makeBlock(ifStmt.getElseStmt())); } }
@Override public void visitIfStmt(IfStmt ifStmt) { visitChildFromParent(ifStmt.getCondition(), ifStmt); visitChildFromParent(ifStmt.getThenStmt(), ifStmt); if (ifStmt.hasElseStmt()) { visitChildFromParent(ifStmt.getElseStmt(), ifStmt); } }
@Override public void visitIfStmt(IfStmt ifStmt) { super.visitIfStmt(ifStmt); if (MacroNames.isDeadByConstruction(ifStmt.getCondition())) { return; } addOpportunity(ifStmt, ifStmt.getThenStmt()); if (ifStmt.hasElseStmt()) { addOpportunity(ifStmt, ifStmt.getElseStmt()); } }
@Override public void visitIfStmt(IfStmt ifStmt) { out.append(indent() + "if("); visit(ifStmt.getCondition()); out.append(")" + newLine()); increaseIndent(); visit(ifStmt.getThenStmt()); decreaseIndent(); if (ifStmt.hasElseStmt()) { out.append(indent() + "else" + newLine()); increaseIndent(); visit(ifStmt.getElseStmt()); decreaseIndent(); } }
@Override public void visitIfStmt(IfStmt ifStmt) { if (!(ifStmt.getThenStmt() instanceof BlockStmt)) { maybeAddInjectionPoint(new IfInjectionPoint(ifStmt, true, currentFunction, inLoop(), currentScope)); } if (ifStmt.hasElseStmt()) { if (!(ifStmt.getElseStmt() instanceof BlockStmt)) { maybeAddInjectionPoint(new IfInjectionPoint(ifStmt, false, currentFunction, inLoop(), currentScope)); } } super.visitIfStmt(ifStmt); }
boolean elseBranchCanBeTransformed = ((IfStmt) stmt).hasElseStmt() && isBlockWithoutTopLevelBreaks(((IfStmt) stmt).getElseStmt()); switchify(((IfStmt) stmt).getElseStmt(), injectionPoint, generator, shadingLanguageVersion, generationParams); return; switchify(((IfStmt) stmt).getElseStmt(), injectionPoint, generator, shadingLanguageVersion, generationParams); transformedOne = true;
@Override public void visitIfStmt(IfStmt ifStmt) { super.visitIfStmt(ifStmt); if (MacroNames.isIfWrapperTrue(ifStmt.getCondition())) { addOpportunity(new UnwrapReductionOpportunity(ifStmt, ifStmt.getThenStmt(), parentMap, getVistitationDepth())); } else if (MacroNames.isIfWrapperFalse(ifStmt.getCondition())) { addOpportunity(new UnwrapReductionOpportunity(ifStmt, ifStmt.getElseStmt(), parentMap, getVistitationDepth())); } }
private static boolean suitableForSwitchInjection(IInjectionPoint injectionPoint) { if (!injectionPoint.hasNextStmt()) { return false; } final Stmt nextStmt = injectionPoint.getNextStmt(); // We are interested in blocks, and loops and conditionals with block bodies, // as long as there are no top-level breaks. if (isBlockWithoutTopLevelBreaks(nextStmt)) { return true; } if (nextStmt instanceof IfStmt) { final IfStmt nextIfStmt = (IfStmt) nextStmt; if (isBlockWithoutTopLevelBreaks(nextIfStmt.getThenStmt())) { return true; } if (nextIfStmt.hasElseStmt() && isBlockWithoutTopLevelBreaks(nextIfStmt.getElseStmt())) { return true; } } if (nextStmt instanceof LoopStmt && isBlockWithoutTopLevelBreaks(((LoopStmt) nextStmt).getBody())) { return true; } return false; }