SSAUpdaterBulk.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SSAUpdaterBulk.h - Unstructured SSA Update Tool ----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the SSAUpdaterBulk class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
  18. #define LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
  19. #include "llvm/ADT/DenseMap.h"
  20. #include "llvm/ADT/StringRef.h"
  21. #include "llvm/IR/PredIteratorCache.h"
  22. namespace llvm {
  23. class BasicBlock;
  24. class PHINode;
  25. template <typename T> class SmallVectorImpl;
  26. class Type;
  27. class Use;
  28. class Value;
  29. class DominatorTree;
  30. /// Helper class for SSA formation on a set of values defined in multiple
  31. /// blocks.
  32. ///
  33. /// This is used when code duplication or another unstructured transformation
  34. /// wants to rewrite a set of uses of one value with uses of a set of values.
  35. /// The update is done only when RewriteAllUses is called, all other methods are
  36. /// used for book-keeping. That helps to share some common computations between
  37. /// updates of different uses (which is not the case when traditional SSAUpdater
  38. /// is used).
  39. class SSAUpdaterBulk {
  40. struct RewriteInfo {
  41. DenseMap<BasicBlock *, Value *> Defines;
  42. SmallVector<Use *, 4> Uses;
  43. StringRef Name;
  44. Type *Ty;
  45. RewriteInfo() = default;
  46. RewriteInfo(StringRef &N, Type *T) : Name(N), Ty(T){};
  47. };
  48. SmallVector<RewriteInfo, 4> Rewrites;
  49. PredIteratorCache PredCache;
  50. Value *computeValueAt(BasicBlock *BB, RewriteInfo &R, DominatorTree *DT);
  51. public:
  52. explicit SSAUpdaterBulk() = default;
  53. SSAUpdaterBulk(const SSAUpdaterBulk &) = delete;
  54. SSAUpdaterBulk &operator=(const SSAUpdaterBulk &) = delete;
  55. ~SSAUpdaterBulk() = default;
  56. /// Add a new variable to the SSA rewriter. This needs to be called before
  57. /// AddAvailableValue or AddUse calls. The return value is the variable ID,
  58. /// which needs to be passed to AddAvailableValue and AddUse.
  59. unsigned AddVariable(StringRef Name, Type *Ty);
  60. /// Indicate that a rewritten value is available in the specified block with
  61. /// the specified value.
  62. void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V);
  63. /// Record a use of the symbolic value. This use will be updated with a
  64. /// rewritten value when RewriteAllUses is called.
  65. void AddUse(unsigned Var, Use *U);
  66. /// Perform all the necessary updates, including new PHI-nodes insertion and
  67. /// the requested uses update.
  68. ///
  69. /// The function requires dominator tree DT, which is used for computing
  70. /// locations for new phi-nodes insertions. If a nonnull pointer to a vector
  71. /// InsertedPHIs is passed, all the new phi-nodes will be added to this
  72. /// vector.
  73. void RewriteAllUses(DominatorTree *DT,
  74. SmallVectorImpl<PHINode *> *InsertedPHIs = nullptr);
  75. };
  76. } // end namespace llvm
  77. #endif // LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
  78. #ifdef __GNUC__
  79. #pragma GCC diagnostic pop
  80. #endif