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 17 #ifndef SOURCE_OPT_LOCAL_SSA_ELIM_PASS_H_ 18 #define SOURCE_OPT_LOCAL_SSA_ELIM_PASS_H_ 19 20 #include <algorithm> 21 #include <map> 22 #include <queue> 23 #include <string> 24 #include <unordered_map> 25 #include <unordered_set> 26 #include <utility> 27 #include <vector> 28 29 #include "source/opt/basic_block.h" 30 #include "source/opt/def_use_manager.h" 31 #include "source/opt/mem_pass.h" 32 #include "source/opt/module.h" 33 34 namespace spvtools { 35 namespace opt { 36 37 // See optimizer.hpp for documentation. 38 class LocalMultiStoreElimPass : public MemPass { 39 using cbb_ptr = const BasicBlock*; 40 41 public: 42 using GetBlocksFunction = 43 std::function<std::vector<BasicBlock*>*(const BasicBlock*)>; 44 45 LocalMultiStoreElimPass(); 46 name()47 const char* name() const override { return "eliminate-local-multi-store"; } 48 Status Process() override; 49 GetPreservedAnalyses()50 IRContext::Analysis GetPreservedAnalyses() override { 51 return IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping; 52 } 53 54 private: 55 // Initialize extensions whitelist 56 void InitExtensions(); 57 58 // Return true if all extensions in this module are allowed by this pass. 59 bool AllExtensionsSupported() const; 60 61 Pass::Status ProcessImpl(); 62 63 // Extensions supported by this pass. 64 std::unordered_set<std::string> extensions_whitelist_; 65 }; 66 67 } // namespace opt 68 } // namespace spvtools 69 70 #endif // SOURCE_OPT_LOCAL_SSA_ELIM_PASS_H_ 71