SSAUpdaterBulk.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(){};
  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(){};
  53. SSAUpdaterBulk(const SSAUpdaterBulk &) = delete;
  54. SSAUpdaterBulk &operator=(const SSAUpdaterBulk &) = delete;
  55. ~SSAUpdaterBulk(){};
  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. /// Return true if the SSAUpdater already has a value for the specified
  67. /// variable in the specified block.
  68. bool HasValueForBlock(unsigned Var, BasicBlock *BB);
  69. /// Perform all the necessary updates, including new PHI-nodes insertion and
  70. /// the requested uses update.
  71. ///
  72. /// The function requires dominator tree DT, which is used for computing
  73. /// locations for new phi-nodes insertions. If a nonnull pointer to a vector
  74. /// InsertedPHIs is passed, all the new phi-nodes will be added to this
  75. /// vector.
  76. void RewriteAllUses(DominatorTree *DT,
  77. SmallVectorImpl<PHINode *> *InsertedPHIs = nullptr);
  78. };
  79. } // end namespace llvm
  80. #endif // LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif