1 // Copyright (c) 2017 The Khronos Group Inc.
2 // Copyright (c) 2017 Valve Corporation
3 // Copyright (c) 2017 LunarG Inc.
4 // Copyright (c) 2019 Google LLC
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 //     http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #ifndef SOURCE_OPT_BLOCK_MERGE_UTIL_H_
19 #define SOURCE_OPT_BLOCK_MERGE_UTIL_H_
20 
21 #include "source/opt/ir_context.h"
22 
23 namespace spvtools {
24 namespace opt {
25 
26 // Provides functions for determining when it is safe to merge blocks, and for
27 // actually merging blocks, for use by various analyses and passes.
28 namespace blockmergeutil {
29 
30 // Returns true if and only if |block| has exactly one successor and merging
31 // this successor into |block| has no impact on the semantics or validity of the
32 // SPIR-V module.
33 bool CanMergeWithSuccessor(IRContext* context, BasicBlock* block);
34 
35 // Requires that |bi| has a successor that can be safely merged into |bi|, and
36 // performs the merge.
37 void MergeWithSuccessor(IRContext* context, Function* func,
38                         Function::iterator bi);
39 
40 }  // namespace blockmergeutil
41 }  // namespace opt
42 }  // namespace spvtools
43 
44 #endif  //  SOURCE_OPT_BLOCK_MERGE_UTIL_H_
45