LLVM  14.0.0git
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/StringRef.h"
19 
20 namespace llvm {
21 
22 class BasicBlock;
23 class PHINode;
24 template <typename T> class SmallVectorImpl;
25 class Type;
26 class Use;
27 class Value;
28 class DominatorTree;
29 
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).
40  struct RewriteInfo {
44  Type *Ty;
45  RewriteInfo(){};
46  RewriteInfo(StringRef &N, Type *T) : Name(N), Ty(T){};
47  };
49 
50  PredIteratorCache PredCache;
51 
52  Value *computeValueAt(BasicBlock *BB, RewriteInfo &R, DominatorTree *DT);
53 
54 public:
55  explicit SSAUpdaterBulk(){};
56  SSAUpdaterBulk(const SSAUpdaterBulk &) = delete;
57  SSAUpdaterBulk &operator=(const SSAUpdaterBulk &) = delete;
59 
60  /// Add a new variable to the SSA rewriter. This needs to be called before
61  /// AddAvailableValue or AddUse calls. The return value is the variable ID,
62  /// which needs to be passed to AddAvailableValue and AddUse.
63  unsigned AddVariable(StringRef Name, Type *Ty);
64 
65  /// Indicate that a rewritten value is available in the specified block with
66  /// the specified value.
67  void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V);
68 
69  /// Record a use of the symbolic value. This use will be updated with a
70  /// rewritten value when RewriteAllUses is called.
71  void AddUse(unsigned Var, Use *U);
72 
73  /// Perform all the necessary updates, including new PHI-nodes insertion and
74  /// the requested uses update.
75  ///
76  /// The function requires dominator tree DT, which is used for computing
77  /// locations for new phi-nodes insertions. If a nonnull pointer to a vector
78  /// InsertedPHIs is passed, all the new phi-nodes will be added to this
79  /// vector.
81  SmallVectorImpl<PHINode *> *InsertedPHIs = nullptr);
82 };
83 
84 } // end namespace llvm
85 
86 #endif // LLVM_TRANSFORMS_UTILS_SSAUPDATERBULK_H
llvm::SSAUpdaterBulk::SSAUpdaterBulk
SSAUpdaterBulk()
Definition: SSAUpdaterBulk.h:55
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
StringRef.h
llvm::SSAUpdaterBulk::AddUse
void AddUse(unsigned Var, Use *U)
Record a use of the symbolic value.
Definition: SSAUpdaterBulk.cpp:61
llvm::PredIteratorCache
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries.
Definition: PredIteratorCache.h:27
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
Uses
SmallPtrSet< MachineInstr *, 2 > Uses
Definition: ARMLowOverheadLoops.cpp:589
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::SSAUpdaterBulk
Helper class for SSA formation on a set of values defined in multiple blocks.
Definition: SSAUpdaterBulk.h:39
llvm::SSAUpdaterBulk::operator=
SSAUpdaterBulk & operator=(const SSAUpdaterBulk &)=delete
llvm::DenseMap
Definition: DenseMap.h:714
PredIteratorCache.h
TemplateParamKind::Type
@ Type
llvm::SSAUpdaterBulk::~SSAUpdaterBulk
~SSAUpdaterBulk()
Definition: SSAUpdaterBulk.h:58
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::SSAUpdaterBulk::AddVariable
unsigned AddVariable(StringRef Name, Type *Ty)
Add a new variable to the SSA rewriter.
Definition: SSAUpdaterBulk.cpp:40
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::SSAUpdaterBulk::AddAvailableValue
void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
Definition: SSAUpdaterBulk.cpp:51
N
#define N
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::SSAUpdaterBulk::RewriteAllUses
void RewriteAllUses(DominatorTree *DT, SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
Perform all the necessary updates, including new PHI-nodes insertion and the requested uses update.
Definition: SSAUpdaterBulk.cpp:122
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44