| 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 |
#include "source/reduce/remove_function_reduction_opportunity_finder.h" |
| 16 |
|
| 17 |
#include "source/reduce/remove_function_reduction_opportunity.h" |
| 18 |
|
| 19 |
namespace spvtools { |
| 20 |
namespace reduce { |
| 21 |
|
| 22 |
std::vector<std::unique_ptr<ReductionOpportunity>> |
| 23 |
RemoveFunctionReductionOpportunityFinder::GetAvailableOpportunities( |
| 24 |
opt::IRContext* context, uint32_t target_function) const { |
| 25 |
if (target_function) { |
| 26 |
// If we are targeting a specific function then we are only interested in |
| 27 |
// opportunities that simplify the internals of that function; removing |
| 28 |
// whole functions does not fit the bill. |
| 29 |
return {}; |
| 30 |
} |
| 31 |
|
| 32 |
std::vector<std::unique_ptr<ReductionOpportunity>> result; |
| 33 |
// Consider each function. |
| 34 |
for (auto& function : *context->module()) { |
| 35 |
if (context->get_def_use_mgr()->NumUses(function.result_id()) > 0) { |
| 36 |
// If the function is referenced, ignore it. |
| 37 |
continue; |
| 38 |
} |
| 39 |
result.push_back( |
| 40 |
MakeUnique<RemoveFunctionReductionOpportunity>(context, &function)); |
| 41 |
} |
| 42 |
return result; |
| 43 |
} |
| 44 |
|
| 45 |
std::string RemoveFunctionReductionOpportunityFinder::GetName() const { |
| 46 |
return "RemoveFunctionReductionOpportunityFinder"; |
| 47 |
} |
| 48 |
|
| 49 |
} // namespace reduce |
| 50 |
} // namespace spvtools |