• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 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_REDUCE_REDUCTION_OPPORTUNITY_FINDER_H_
16 #define SOURCE_REDUCE_REDUCTION_OPPORTUNITY_FINDER_H_
17 
18 #include <vector>
19 
20 #include "source/opt/ir_context.h"
21 #include "source/reduce/reduction_opportunity.h"
22 
23 namespace spvtools {
24 namespace reduce {
25 
26 // Abstract class for finding opportunities for reducing a SPIR-V module.
27 class ReductionOpportunityFinder {
28  public:
29   ReductionOpportunityFinder() = default;
30 
31   virtual ~ReductionOpportunityFinder() = default;
32 
33   // Finds and returns the reduction opportunities relevant to this pass that
34   // could be applied to SPIR-V module |context|.
35   //
36   // If |target_function| is non-zero then the available opportunities will be
37   // restricted to only those opportunities that modify the function with result
38   // id |target_function|.
39   virtual std::vector<std::unique_ptr<ReductionOpportunity>>
40   GetAvailableOpportunities(opt::IRContext* context,
41                             uint32_t target_function) const = 0;
42 
43   // Provides a name for the finder.
44   virtual std::string GetName() const = 0;
45 
46  protected:
47   // Requires that |target_function| is zero or the id of a function in
48   // |ir_context|.  If |target_function| is zero, returns all the functions in
49   // |ir_context|.  Otherwise, returns the function with id |target_function|.
50   // This allows fuzzer passes to restrict attention to a single function.
51   static std::vector<opt::Function*> GetTargetFunctions(
52       opt::IRContext* ir_context, uint32_t target_function);
53 };
54 
55 }  // namespace reduce
56 }  // namespace spvtools
57 
58 #endif  // SOURCE_REDUCE_REDUCTION_OPPORTUNITY_FINDER_H_
59