| 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_REMOVE_BLOCK_REDUCTION_OPPORTUNITY_FINDER_H_ |
| 16 |
#define SOURCE_REDUCE_REMOVE_BLOCK_REDUCTION_OPPORTUNITY_FINDER_H_ |
| 17 |
|
| 18 |
#include "source/opt/function.h" |
| 19 |
#include "source/reduce/reduction_opportunity_finder.h" |
| 20 |
|
| 21 |
namespace spvtools { |
| 22 |
namespace reduce { |
| 23 |
|
| 24 |
// A finder of opportunities to remove a block. The optimizer can remove dead |
| 25 |
// code. However, the reducer needs to be able to remove at a fine-grained |
| 26 |
// level. |
| 27 |
class RemoveBlockReductionOpportunityFinder |
| 28 |
: public ReductionOpportunityFinder { |
| 29 |
public: |
| 30 |
RemoveBlockReductionOpportunityFinder() = default; |
| 31 |
|
| 32 |
~RemoveBlockReductionOpportunityFinder() override = default; |
| 33 |
|
| 34 |
std::string GetName() const final; |
| 35 |
|
| 36 |
std::vector<std::unique_ptr<ReductionOpportunity>> GetAvailableOpportunities( |
| 37 |
opt::IRContext* context, uint32_t target_function) const final; |
| 38 |
|
| 39 |
private: |
| 40 |
// Returns true if the block |bi| in function |function| is a valid |
| 41 |
// opportunity according to various restrictions. |
| 42 |
static bool IsBlockValidOpportunity(opt::IRContext* context, |
| 43 |
opt::Function* function, |
| 44 |
opt::Function::iterator* bi); |
| 45 |
|
| 46 |
// Returns true if the instructions (definitions) in block |bi| have no |
| 47 |
// references, except for references from inside the block itself. |
| 48 |
static bool BlockInstructionsHaveNoOutsideReferences( |
| 49 |
opt::IRContext* context, const opt::Function::iterator& bi); |
| 50 |
}; |
| 51 |
|
| 52 |
} // namespace reduce |
| 53 |
} // namespace spvtools |
| 54 |
|
| 55 |
#endif // SOURCE_REDUCE_REMOVE_BLOCK_REDUCTION_OPPORTUNITY_FINDER_H_ |