LLVM  10.0.0svn
SSAUpdaterBulk.h
Go to the documentation of this file.
1 //===- SSAUpdaterBulk.h - Unstructured SSA Update Tool ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the SSAUpdaterBulk class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
14 #define LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/StringRef.h"
20 
21 namespace llvm {
22 
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 
31 /// Helper class for SSA formation on a set of values defined in multiple
32 /// blocks.
33 ///
34 /// This is used when code duplication or another unstructured transformation
35 /// wants to rewrite a set of uses of one value with uses of a set of values.
36 /// The update is done only when RewriteAllUses is called, all other methods are
37 /// used for book-keeping. That helps to share some common computations between
38 /// updates of different uses (which is not the case when traditional SSAUpdater
39 /// is used).
41  struct RewriteInfo {
45  Type *Ty;
46  RewriteInfo(){};
47  RewriteInfo(StringRef &N, Type *T) : Name(N), Ty(T){};
48  };
50 
51  PredIteratorCache PredCache;
52 
53  Value *computeValueAt(BasicBlock *BB, RewriteInfo &R, DominatorTree *DT);
54 
55 public:
56  explicit SSAUpdaterBulk(){};
57  SSAUpdaterBulk(const SSAUpdaterBulk &) = delete;
58  SSAUpdaterBulk &operator=(const SSAUpdaterBulk &) = delete;
60 
61  /// Add a new variable to the SSA rewriter. This needs to be called before
62  /// AddAvailableValue or AddUse calls. The return value is the variable ID,
63  /// which needs to be passed to AddAvailableValue and AddUse.
64  unsigned AddVariable(StringRef Name, Type *Ty);
65 
66  /// Indicate that a rewritten value is available in the specified block with
67  /// the specified value.
68  void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V);
69 
70  /// Record a use of the symbolic value. This use will be updated with a
71  /// rewritten value when RewriteAllUses is called.
72  void AddUse(unsigned Var, Use *U);
73 
74  /// Return true if the SSAUpdater already has a value for the specified
75  /// variable in the specified block.
76  bool HasValueForBlock(unsigned Var, BasicBlock *BB);
77 
78  /// Perform all the necessary updates, including new PHI-nodes insertion and
79  /// the requested uses update.
80  ///
81  /// The function requires dominator tree DT, which is used for computing
82  /// locations for new phi-nodes insertions. If a nonnull pointer to a vector
83  /// InsertedPHIs is passed, all the new phi-nodes will be added to this
84  /// vector.
86  SmallVectorImpl<PHINode *> *InsertedPHIs = nullptr);
87 };
88 
89 } // end namespace llvm
90 
91 #endif // LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
unsigned AddVariable(StringRef Name, Type *Ty)
Add a new variable to the SSA rewriter.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries...
Helper class for SSA formation on a set of values defined in multiple blocks.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void AddUse(unsigned Var, Use *U)
Record a use of the symbolic value.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
void RewriteAllUses(DominatorTree *DT, SmallVectorImpl< PHINode *> *InsertedPHIs=nullptr)
Perform all the necessary updates, including new PHI-nodes insertion and the requested uses update...
#define N
LLVM Value Representation.
Definition: Value.h:74
SSAUpdaterBulk & operator=(const SSAUpdaterBulk &)=delete
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool HasValueForBlock(unsigned Var, BasicBlock *BB)
Return true if the SSAUpdater already has a value for the specified variable in the specified block...