1 // Copyright (c) 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SOURCE_FUZZ_REPEATED_PASS_INSTANCES_H_ 16 #define SOURCE_FUZZ_REPEATED_PASS_INSTANCES_H_ 17 18 #include "source/fuzz/fuzzer_pass_add_access_chains.h" 19 #include "source/fuzz/fuzzer_pass_add_bit_instruction_synonyms.h" 20 #include "source/fuzz/fuzzer_pass_add_composite_extract.h" 21 #include "source/fuzz/fuzzer_pass_add_composite_inserts.h" 22 #include "source/fuzz/fuzzer_pass_add_composite_types.h" 23 #include "source/fuzz/fuzzer_pass_add_copy_memory.h" 24 #include "source/fuzz/fuzzer_pass_add_dead_blocks.h" 25 #include "source/fuzz/fuzzer_pass_add_dead_breaks.h" 26 #include "source/fuzz/fuzzer_pass_add_dead_continues.h" 27 #include "source/fuzz/fuzzer_pass_add_equation_instructions.h" 28 #include "source/fuzz/fuzzer_pass_add_function_calls.h" 29 #include "source/fuzz/fuzzer_pass_add_global_variables.h" 30 #include "source/fuzz/fuzzer_pass_add_image_sample_unused_components.h" 31 #include "source/fuzz/fuzzer_pass_add_loads.h" 32 #include "source/fuzz/fuzzer_pass_add_local_variables.h" 33 #include "source/fuzz/fuzzer_pass_add_loop_preheaders.h" 34 #include "source/fuzz/fuzzer_pass_add_loops_to_create_int_constant_synonyms.h" 35 #include "source/fuzz/fuzzer_pass_add_opphi_synonyms.h" 36 #include "source/fuzz/fuzzer_pass_add_parameters.h" 37 #include "source/fuzz/fuzzer_pass_add_relaxed_decorations.h" 38 #include "source/fuzz/fuzzer_pass_add_stores.h" 39 #include "source/fuzz/fuzzer_pass_add_synonyms.h" 40 #include "source/fuzz/fuzzer_pass_add_vector_shuffle_instructions.h" 41 #include "source/fuzz/fuzzer_pass_apply_id_synonyms.h" 42 #include "source/fuzz/fuzzer_pass_construct_composites.h" 43 #include "source/fuzz/fuzzer_pass_copy_objects.h" 44 #include "source/fuzz/fuzzer_pass_donate_modules.h" 45 #include "source/fuzz/fuzzer_pass_duplicate_regions_with_selections.h" 46 #include "source/fuzz/fuzzer_pass_expand_vector_reductions.h" 47 #include "source/fuzz/fuzzer_pass_flatten_conditional_branches.h" 48 #include "source/fuzz/fuzzer_pass_inline_functions.h" 49 #include "source/fuzz/fuzzer_pass_invert_comparison_operators.h" 50 #include "source/fuzz/fuzzer_pass_make_vector_operations_dynamic.h" 51 #include "source/fuzz/fuzzer_pass_merge_blocks.h" 52 #include "source/fuzz/fuzzer_pass_merge_function_returns.h" 53 #include "source/fuzz/fuzzer_pass_mutate_pointers.h" 54 #include "source/fuzz/fuzzer_pass_obfuscate_constants.h" 55 #include "source/fuzz/fuzzer_pass_outline_functions.h" 56 #include "source/fuzz/fuzzer_pass_permute_blocks.h" 57 #include "source/fuzz/fuzzer_pass_permute_function_parameters.h" 58 #include "source/fuzz/fuzzer_pass_permute_instructions.h" 59 #include "source/fuzz/fuzzer_pass_propagate_instructions_down.h" 60 #include "source/fuzz/fuzzer_pass_propagate_instructions_up.h" 61 #include "source/fuzz/fuzzer_pass_push_ids_through_variables.h" 62 #include "source/fuzz/fuzzer_pass_replace_adds_subs_muls_with_carrying_extended.h" 63 #include "source/fuzz/fuzzer_pass_replace_branches_from_dead_blocks_with_exits.h" 64 #include "source/fuzz/fuzzer_pass_replace_copy_memories_with_loads_stores.h" 65 #include "source/fuzz/fuzzer_pass_replace_copy_objects_with_stores_loads.h" 66 #include "source/fuzz/fuzzer_pass_replace_irrelevant_ids.h" 67 #include "source/fuzz/fuzzer_pass_replace_linear_algebra_instructions.h" 68 #include "source/fuzz/fuzzer_pass_replace_loads_stores_with_copy_memories.h" 69 #include "source/fuzz/fuzzer_pass_replace_opphi_ids_from_dead_predecessors.h" 70 #include "source/fuzz/fuzzer_pass_replace_opselects_with_conditional_branches.h" 71 #include "source/fuzz/fuzzer_pass_replace_parameter_with_global.h" 72 #include "source/fuzz/fuzzer_pass_replace_params_with_struct.h" 73 #include "source/fuzz/fuzzer_pass_split_blocks.h" 74 #include "source/fuzz/fuzzer_pass_swap_conditional_branch_operands.h" 75 #include "source/fuzz/fuzzer_pass_wrap_regions_in_selections.h" 76 #include "source/fuzz/fuzzer_pass_wrap_vector_synonym.h" 77 78 namespace spvtools { 79 namespace fuzz { 80 81 // This class has a distinct member for each repeated fuzzer pass (i.e., a 82 // fuzzer pass that it makes sense to run multiple times). If a member is null 83 // then we do not have an instance of that fuzzer pass, i.e. it is disabled. 84 // The class also provides access to the set of passes that are enabled. 85 class RepeatedPassInstances { 86 // This macro should be invoked below for every repeated fuzzer pass. If a 87 // repeated fuzzer pass is called FuzzerPassFoo then the macro invocation: 88 // 89 // REPEATED_PASS_INSTANCE(Foo); 90 // 91 // should be used. This adds a private member of type FuzzerPassFoo*, and 92 // provides the following public methods: 93 // 94 // // Requires that SetPass has not been called previously with FuzzerPassFoo. 95 // // Adds |pass| to the set of known pass instances. 96 // void SetPass(std::unique_ptr<FuzzerPassFoo> pass); 97 // 98 // // Returns a pointer to a pass instance of type FuzzerPassFoo that was 99 // // previously registered via SetPass(), or nullptr if no such instance was 100 // // registered 101 // FuzzerPassFoo* GetFoo(); 102 #define REPEATED_PASS_INSTANCE(NAME) \ 103 public: \ 104 FuzzerPass##NAME* Get##NAME() const { return NAME##_; } \ 105 void SetPass(std::unique_ptr<FuzzerPass##NAME> pass) { \ 106 assert(NAME##_ == nullptr && "Attempt to set pass multiple times."); \ 107 NAME##_ = pass.get(); \ 108 passes_.push_back(std::move(pass)); \ 109 } \ 110 \ 111 private: \ 112 FuzzerPass##NAME* NAME##_ = nullptr 113 114 REPEATED_PASS_INSTANCE(AddAccessChains); 115 REPEATED_PASS_INSTANCE(AddBitInstructionSynonyms); 116 REPEATED_PASS_INSTANCE(AddCompositeExtract); 117 REPEATED_PASS_INSTANCE(AddCompositeInserts); 118 REPEATED_PASS_INSTANCE(AddCompositeTypes); 119 REPEATED_PASS_INSTANCE(AddCopyMemory); 120 REPEATED_PASS_INSTANCE(AddDeadBlocks); 121 REPEATED_PASS_INSTANCE(AddDeadBreaks); 122 REPEATED_PASS_INSTANCE(AddDeadContinues); 123 REPEATED_PASS_INSTANCE(AddEquationInstructions); 124 REPEATED_PASS_INSTANCE(AddFunctionCalls); 125 REPEATED_PASS_INSTANCE(AddGlobalVariables); 126 REPEATED_PASS_INSTANCE(AddImageSampleUnusedComponents); 127 REPEATED_PASS_INSTANCE(AddLoads); 128 REPEATED_PASS_INSTANCE(AddLocalVariables); 129 REPEATED_PASS_INSTANCE(AddLoopPreheaders); 130 REPEATED_PASS_INSTANCE(AddLoopsToCreateIntConstantSynonyms); 131 REPEATED_PASS_INSTANCE(AddOpPhiSynonyms); 132 REPEATED_PASS_INSTANCE(AddParameters); 133 REPEATED_PASS_INSTANCE(AddRelaxedDecorations); 134 REPEATED_PASS_INSTANCE(AddStores); 135 REPEATED_PASS_INSTANCE(AddSynonyms); 136 REPEATED_PASS_INSTANCE(AddVectorShuffleInstructions); 137 REPEATED_PASS_INSTANCE(ApplyIdSynonyms); 138 REPEATED_PASS_INSTANCE(ConstructComposites); 139 REPEATED_PASS_INSTANCE(CopyObjects); 140 REPEATED_PASS_INSTANCE(DonateModules); 141 REPEATED_PASS_INSTANCE(DuplicateRegionsWithSelections); 142 REPEATED_PASS_INSTANCE(ExpandVectorReductions); 143 REPEATED_PASS_INSTANCE(FlattenConditionalBranches); 144 REPEATED_PASS_INSTANCE(InlineFunctions); 145 REPEATED_PASS_INSTANCE(InvertComparisonOperators); 146 REPEATED_PASS_INSTANCE(MakeVectorOperationsDynamic); 147 REPEATED_PASS_INSTANCE(MergeBlocks); 148 REPEATED_PASS_INSTANCE(MergeFunctionReturns); 149 REPEATED_PASS_INSTANCE(MutatePointers); 150 REPEATED_PASS_INSTANCE(ObfuscateConstants); 151 REPEATED_PASS_INSTANCE(OutlineFunctions); 152 REPEATED_PASS_INSTANCE(PermuteBlocks); 153 REPEATED_PASS_INSTANCE(PermuteFunctionParameters); 154 REPEATED_PASS_INSTANCE(PermuteInstructions); 155 REPEATED_PASS_INSTANCE(PropagateInstructionsDown); 156 REPEATED_PASS_INSTANCE(PropagateInstructionsUp); 157 REPEATED_PASS_INSTANCE(PushIdsThroughVariables); 158 REPEATED_PASS_INSTANCE(ReplaceAddsSubsMulsWithCarryingExtended); 159 REPEATED_PASS_INSTANCE(ReplaceBranchesFromDeadBlocksWithExits); 160 REPEATED_PASS_INSTANCE(ReplaceCopyMemoriesWithLoadsStores); 161 REPEATED_PASS_INSTANCE(ReplaceCopyObjectsWithStoresLoads); 162 REPEATED_PASS_INSTANCE(ReplaceLoadsStoresWithCopyMemories); 163 REPEATED_PASS_INSTANCE(ReplaceIrrelevantIds); 164 REPEATED_PASS_INSTANCE(ReplaceOpPhiIdsFromDeadPredecessors); 165 REPEATED_PASS_INSTANCE(ReplaceOpSelectsWithConditionalBranches); 166 REPEATED_PASS_INSTANCE(ReplaceParameterWithGlobal); 167 REPEATED_PASS_INSTANCE(ReplaceLinearAlgebraInstructions); 168 REPEATED_PASS_INSTANCE(ReplaceParamsWithStruct); 169 REPEATED_PASS_INSTANCE(SplitBlocks); 170 REPEATED_PASS_INSTANCE(SwapBranchConditionalOperands); 171 REPEATED_PASS_INSTANCE(WrapRegionsInSelections); 172 REPEATED_PASS_INSTANCE(WrapVectorSynonym); 173 #undef REPEATED_PASS_INSTANCE 174 175 public: 176 // Yields the sequence of fuzzer pass instances that have been registered. GetPasses()177 const std::vector<std::unique_ptr<FuzzerPass>>& GetPasses() const { 178 return passes_; 179 } 180 181 private: 182 // The distinct fuzzer pass instances that have been registered via SetPass(). 183 std::vector<std::unique_ptr<FuzzerPass>> passes_; 184 }; 185 186 } // namespace fuzz 187 } // namespace spvtools 188 189 #endif // SOURCE_FUZZ_REPEATED_PASS_INSTANCES_H_ 190