1 // Copyright (c) 2017 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef LIBSPIRV_OPT_MERGE_RETURN_PASS_H_
16 #define LIBSPIRV_OPT_MERGE_RETURN_PASS_H_
18 #include "basic_block.h"
27 // Documented in optimizer.hpp
28 class MergeReturnPass : public Pass {
30 MergeReturnPass() = default;
31 const char* name() const override { return "merge-return-pass"; }
32 Status Process(ir::IRContext*) override;
34 ir::IRContext::Analysis GetPreservedAnalyses() override {
35 return ir::IRContext::kAnalysisDefUse;
39 // Returns all BasicBlocks terminated by OpReturn or OpReturnValue in
41 std::vector<ir::BasicBlock*> CollectReturnBlocks(ir::Function* function);
43 // Returns |true| if returns were merged, |false| otherwise.
45 // Creates a new basic block with a single return. If |function| returns a
46 // value, a phi node is created to select the correct value to return.
47 // Replaces old returns with an unconditional branch to the new block.
48 bool MergeReturnBlocks(ir::Function* function,
49 const std::vector<ir::BasicBlock*>& returnBlocks);
53 } // namespace spvtools
55 #endif // LIBSPIRV_OPT_MERGE_RETURN_PASS_H_