redundancy_elimination.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2017 Google Inc.
  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. #ifndef SOURCE_OPT_REDUNDANCY_ELIMINATION_H_
  15. #define SOURCE_OPT_REDUNDANCY_ELIMINATION_H_
  16. #include <map>
  17. #include "source/opt/ir_context.h"
  18. #include "source/opt/local_redundancy_elimination.h"
  19. #include "source/opt/pass.h"
  20. #include "source/opt/value_number_table.h"
  21. namespace spvtools {
  22. namespace opt {
  23. // This pass implements total redundancy elimination. This is the same as
  24. // local redundancy elimination except it looks across basic block boundaries.
  25. // An instruction, inst, is totally redundant if there is another instruction
  26. // that dominates inst, and also computes the same value.
  27. class RedundancyEliminationPass : public LocalRedundancyEliminationPass {
  28. public:
  29. const char* name() const override { return "redundancy-elimination"; }
  30. Status Process() override;
  31. protected:
  32. // Removes for all total redundancies in the function starting at |bb|.
  33. //
  34. // |vnTable| must have computed a value number for every result id defined
  35. // in the function containing |bb|.
  36. //
  37. // |value_to_ids| is a map from value number to ids. If {vn, id} is in
  38. // |value_to_ids| then vn is the value number of id, and the definition of id
  39. // dominates |bb|.
  40. //
  41. // Returns true if at least one instruction is deleted.
  42. bool EliminateRedundanciesFrom(DominatorTreeNode* bb,
  43. const ValueNumberTable& vnTable,
  44. std::map<uint32_t, uint32_t> value_to_ids);
  45. };
  46. } // namespace opt
  47. } // namespace spvtools
  48. #endif // SOURCE_OPT_REDUNDANCY_ELIMINATION_H_