| 1 | // Copyright (c) 2017 Pierre Moreau |
| 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 | #ifndef SOURCE_OPT_REMOVE_DUPLICATES_PASS_H_ |
| 16 | #define SOURCE_OPT_REMOVE_DUPLICATES_PASS_H_ |
| 17 | |
| 18 | #include <unordered_map> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "source/opt/decoration_manager.h" |
| 22 | #include "source/opt/def_use_manager.h" |
| 23 | #include "source/opt/ir_context.h" |
| 24 | #include "source/opt/module.h" |
| 25 | #include "source/opt/pass.h" |
| 26 | |
| 27 | namespace spvtools { |
| 28 | namespace opt { |
| 29 | |
| 30 | using IdDecorationsList = |
| 31 | std::unordered_map<uint32_t, std::vector<Instruction*>>; |
| 32 | |
| 33 | // See optimizer.hpp for documentation. |
| 34 | class RemoveDuplicatesPass : public Pass { |
| 35 | public: |
| 36 | const char* name() const override { return "remove-duplicates" ; } |
| 37 | Status Process() override; |
| 38 | |
| 39 | private: |
| 40 | // Remove duplicate capabilities from the module |
| 41 | // |
| 42 | // Returns true if the module was modified, false otherwise. |
| 43 | bool RemoveDuplicateCapabilities() const; |
| 44 | // Remove duplicate extended instruction imports from the module |
| 45 | // |
| 46 | // Returns true if the module was modified, false otherwise. |
| 47 | bool RemoveDuplicatesExtInstImports() const; |
| 48 | // Remove duplicate types from the module |
| 49 | // |
| 50 | // Returns true if the module was modified, false otherwise. |
| 51 | bool RemoveDuplicateTypes() const; |
| 52 | // Remove duplicate decorations from the module |
| 53 | // |
| 54 | // Returns true if the module was modified, false otherwise. |
| 55 | bool RemoveDuplicateDecorations() const; |
| 56 | }; |
| 57 | |
| 58 | } // namespace opt |
| 59 | } // namespace spvtools |
| 60 | |
| 61 | #endif // SOURCE_OPT_REMOVE_DUPLICATES_PASS_H_ |
| 62 | |