• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
77 namespace spvtools {
78 namespace fuzz {
79 
80 // This class has a distinct member for each repeated fuzzer pass (i.e., a
81 // fuzzer pass that it makes sense to run multiple times).  If a member is null
82 // then we do not have an instance of that fuzzer pass, i.e. it is disabled.
83 // The class also provides access to the set of passes that are enabled.
84 class RepeatedPassInstances {
85 // This macro should be invoked below for every repeated fuzzer pass.  If a
86 // repeated fuzzer pass is called FuzzerPassFoo then the macro invocation:
87 //
88 //    REPEATED_PASS_INSTANCE(Foo);
89 //
90 // should be used.  This adds a private member of type FuzzerPassFoo*, and
91 // provides the following public methods:
92 //
93 // // Requires that SetPass has not been called previously with FuzzerPassFoo.
94 // // Adds |pass| to the set of known pass instances.
95 // void SetPass(std::unique_ptr<FuzzerPassFoo> pass);
96 //
97 // // Returns a pointer to a pass instance of type FuzzerPassFoo that was
98 // // previously registered via SetPass(), or nullptr if no such instance was
99 // // registered
100 // FuzzerPassFoo* GetFoo();
101 #define REPEATED_PASS_INSTANCE(NAME)                                     \
102  public:                                                                 \
103   FuzzerPass##NAME* Get##NAME() const { return NAME##_; }                \
104   void SetPass(std::unique_ptr<FuzzerPass##NAME> pass) {                 \
105     assert(NAME##_ == nullptr && "Attempt to set pass multiple times."); \
106     NAME##_ = pass.get();                                                \
107     passes_.push_back(std::move(pass));                                  \
108   }                                                                      \
109                                                                          \
110  private:                                                                \
111   FuzzerPass##NAME* NAME##_ = nullptr
112 
113   REPEATED_PASS_INSTANCE(AddAccessChains);
114   REPEATED_PASS_INSTANCE(AddBitInstructionSynonyms);
115   REPEATED_PASS_INSTANCE(AddCompositeExtract);
116   REPEATED_PASS_INSTANCE(AddCompositeInserts);
117   REPEATED_PASS_INSTANCE(AddCompositeTypes);
118   REPEATED_PASS_INSTANCE(AddCopyMemory);
119   REPEATED_PASS_INSTANCE(AddDeadBlocks);
120   REPEATED_PASS_INSTANCE(AddDeadBreaks);
121   REPEATED_PASS_INSTANCE(AddDeadContinues);
122   REPEATED_PASS_INSTANCE(AddEquationInstructions);
123   REPEATED_PASS_INSTANCE(AddFunctionCalls);
124   REPEATED_PASS_INSTANCE(AddGlobalVariables);
125   REPEATED_PASS_INSTANCE(AddImageSampleUnusedComponents);
126   REPEATED_PASS_INSTANCE(AddLoads);
127   REPEATED_PASS_INSTANCE(AddLocalVariables);
128   REPEATED_PASS_INSTANCE(AddLoopPreheaders);
129   REPEATED_PASS_INSTANCE(AddLoopsToCreateIntConstantSynonyms);
130   REPEATED_PASS_INSTANCE(AddOpPhiSynonyms);
131   REPEATED_PASS_INSTANCE(AddParameters);
132   REPEATED_PASS_INSTANCE(AddRelaxedDecorations);
133   REPEATED_PASS_INSTANCE(AddStores);
134   REPEATED_PASS_INSTANCE(AddSynonyms);
135   REPEATED_PASS_INSTANCE(AddVectorShuffleInstructions);
136   REPEATED_PASS_INSTANCE(ApplyIdSynonyms);
137   REPEATED_PASS_INSTANCE(ConstructComposites);
138   REPEATED_PASS_INSTANCE(CopyObjects);
139   REPEATED_PASS_INSTANCE(DonateModules);
140   REPEATED_PASS_INSTANCE(DuplicateRegionsWithSelections);
141   REPEATED_PASS_INSTANCE(ExpandVectorReductions);
142   REPEATED_PASS_INSTANCE(FlattenConditionalBranches);
143   REPEATED_PASS_INSTANCE(InlineFunctions);
144   REPEATED_PASS_INSTANCE(InvertComparisonOperators);
145   REPEATED_PASS_INSTANCE(MakeVectorOperationsDynamic);
146   REPEATED_PASS_INSTANCE(MergeBlocks);
147   REPEATED_PASS_INSTANCE(MergeFunctionReturns);
148   REPEATED_PASS_INSTANCE(MutatePointers);
149   REPEATED_PASS_INSTANCE(ObfuscateConstants);
150   REPEATED_PASS_INSTANCE(OutlineFunctions);
151   REPEATED_PASS_INSTANCE(PermuteBlocks);
152   REPEATED_PASS_INSTANCE(PermuteFunctionParameters);
153   REPEATED_PASS_INSTANCE(PermuteInstructions);
154   REPEATED_PASS_INSTANCE(PropagateInstructionsDown);
155   REPEATED_PASS_INSTANCE(PropagateInstructionsUp);
156   REPEATED_PASS_INSTANCE(PushIdsThroughVariables);
157   REPEATED_PASS_INSTANCE(ReplaceAddsSubsMulsWithCarryingExtended);
158   REPEATED_PASS_INSTANCE(ReplaceBranchesFromDeadBlocksWithExits);
159   REPEATED_PASS_INSTANCE(ReplaceCopyMemoriesWithLoadsStores);
160   REPEATED_PASS_INSTANCE(ReplaceCopyObjectsWithStoresLoads);
161   REPEATED_PASS_INSTANCE(ReplaceLoadsStoresWithCopyMemories);
162   REPEATED_PASS_INSTANCE(ReplaceIrrelevantIds);
163   REPEATED_PASS_INSTANCE(ReplaceOpPhiIdsFromDeadPredecessors);
164   REPEATED_PASS_INSTANCE(ReplaceOpSelectsWithConditionalBranches);
165   REPEATED_PASS_INSTANCE(ReplaceParameterWithGlobal);
166   REPEATED_PASS_INSTANCE(ReplaceLinearAlgebraInstructions);
167   REPEATED_PASS_INSTANCE(ReplaceParamsWithStruct);
168   REPEATED_PASS_INSTANCE(SplitBlocks);
169   REPEATED_PASS_INSTANCE(SwapBranchConditionalOperands);
170   REPEATED_PASS_INSTANCE(WrapRegionsInSelections);
171 #undef REPEATED_PASS_INSTANCE
172 
173  public:
174   // Yields the sequence of fuzzer pass instances that have been registered.
GetPasses()175   const std::vector<std::unique_ptr<FuzzerPass>>& GetPasses() const {
176     return passes_;
177   }
178 
179  private:
180   // The distinct fuzzer pass instances that have been registered via SetPass().
181   std::vector<std::unique_ptr<FuzzerPass>> passes_;
182 };
183 
184 }  // namespace fuzz
185 }  // namespace spvtools
186 
187 #endif  // SOURCE_FUZZ_REPEATED_PASS_INSTANCES_H_
188