@Test public void testReductionOpportunitiesOnEmptyForLoops() throws Exception { final TranslationUnit tu = ParseHelper.parse("#version 310 es\n" + "precision highp float;\n" + "int x = 0;\n" + "void main() {\n" + " for(int i1 = 0;;) {\n" + " for(int i2 = 0;;) {\n" + " for(;;) {\n" + " for(int i3 = 0;;) {\n" + " x++;\n" + " if (x > 10) break;\n" + " }\n" + " for(int i3 = 0;;) {\n" + " x++;\n" + " if (x > 10) break;\n" + " }\n" + " x++;\n" + " if(x > 20) break;\n" + " }\n" + " x++;\n" + " if(x > 30) break;\n" + " }\n" + " x++;\n" + " if(x > 40) break;\n" + " };\n" + "}\n"); List<IReductionOpportunity> ops = ReductionOpportunities.getReductionOpportunities( MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(true, ShadingLanguageVersion.GLSL_440, new RandomWrapper(0), new IdGenerator()), fileOps); ops.forEach(IReductionOpportunity::applyReduction); }
public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); static List<IReductionOpportunity> getReductionOpportunities(
      ShaderJob shaderJob,
      ReducerContext context,
      ShaderJobFileOperations fileOps); }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); static List<IReductionOpportunity> getReductionOpportunities(
      ShaderJob shaderJob,
      ReducerContext context,
      ShaderJobFileOperations fileOps);  }