@Test public void exprSimplificationAndLoopSplitInteraction() throws Exception { String program = "void main() {" + " if(_GLF_DEAD(_GLF_FALSE(false, false))) {" + " for(\n" + " int _GLF_SPLIT_LOOP_COUNTER_1n = 0;\n" + " _GLF_SPLIT_LOOP_COUNTER_1n < 3;\n" + " _GLF_SPLIT_LOOP_COUNTER_1n ++\n" + " )\n" + " {\n" + " }\n" + " for(\n" + " int _GLF_SPLIT_LOOP_COUNTER_1n = 3;\n" + " _GLF_SPLIT_LOOP_COUNTER_1n < 3;\n" + " _GLF_SPLIT_LOOP_COUNTER_1n ++\n" + " )\n" + " {\n" + " }\n" + " }\n" + "}\n"; TranslationUnit tu = ParseHelper.parse(program); List<Integer> indicesOfExprToConstOps = new ArrayList<>(); { List<IReductionOpportunity> ops = ReductionOpportunities .getReductionOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator()), fileOps); for (int i = 0; i < ops.size(); i++) { if (ops.get(i) instanceof SimplifyExprReductionOpportunity) { indicesOfExprToConstOps.add(i); } } } for (Integer index : indicesOfExprToConstOps) { final TranslationUnit tuClone = tu.clone(); { final List<IReductionOpportunity> ops = ReductionOpportunities.getReductionOpportunities( MakeShaderJobFromFragmentShader.make(tuClone), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator()), fileOps); ((SimplifyExprReductionOpportunity) ops.get(index)).applyReduction(); } for (IReductionOpportunity op : ReductionOpportunities .getReductionOpportunities(MakeShaderJobFromFragmentShader.make(tuClone), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator()), fileOps)) { if (op instanceof LoopMergeReductionOpportunity) { op.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);  }