block_merge_pass.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2017 The Khronos Group Inc.
  2. // Copyright (c) 2017 Valve Corporation
  3. // Copyright (c) 2017 LunarG Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. #ifndef SOURCE_OPT_BLOCK_MERGE_PASS_H_
  17. #define SOURCE_OPT_BLOCK_MERGE_PASS_H_
  18. #include <algorithm>
  19. #include <map>
  20. #include <queue>
  21. #include <unordered_map>
  22. #include <unordered_set>
  23. #include <utility>
  24. #include "source/opt/basic_block.h"
  25. #include "source/opt/def_use_manager.h"
  26. #include "source/opt/ir_context.h"
  27. #include "source/opt/module.h"
  28. #include "source/opt/pass.h"
  29. namespace spvtools {
  30. namespace opt {
  31. // See optimizer.hpp for documentation.
  32. class BlockMergePass : public Pass {
  33. public:
  34. BlockMergePass();
  35. const char* name() const override { return "merge-blocks"; }
  36. Status Process() override;
  37. IRContext::Analysis GetPreservedAnalyses() override {
  38. return IRContext::kAnalysisDefUse |
  39. IRContext::kAnalysisInstrToBlockMapping |
  40. IRContext::kAnalysisDecorations | IRContext::kAnalysisCombinators |
  41. IRContext::kAnalysisNameMap | IRContext::kAnalysisConstants |
  42. IRContext::kAnalysisTypes;
  43. }
  44. private:
  45. // Search |func| for blocks which have a single Branch to a block
  46. // with no other predecessors. Merge these blocks into a single block.
  47. bool MergeBlocks(Function* func);
  48. };
  49. } // namespace opt
  50. } // namespace spvtools
  51. #endif // SOURCE_OPT_BLOCK_MERGE_PASS_H_