1 //===-- SSAUpdater.h - Unstructured SSA Update Tool -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SSAUpdater class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_UTILS_SSAUPDATER_H
15 #define LLVM_TRANSFORMS_UTILS_SSAUPDATER_H
22 template<typename T> class SmallVectorImpl;
23 template<typename T> class SSAUpdaterTraits;
24 class BumpPtrAllocator;
26 /// SSAUpdater - This class updates SSA form for a set of values defined in
27 /// multiple blocks. This is used when code duplication or another unstructured
28 /// transformation wants to rewrite a set of uses of one value with uses of a
31 friend class SSAUpdaterTraits<SSAUpdater>;
34 /// AvailableVals - This keeps track of which value to use on a per-block
35 /// basis. When we insert PHI nodes, we keep track of them here.
36 //typedef DenseMap<BasicBlock*, Value*> AvailableValsTy;
39 /// PrototypeValue is an arbitrary representative value, which we derive names
40 /// and a type for PHI nodes.
41 Value *PrototypeValue;
43 /// InsertedPHIs - If this is non-null, the SSAUpdater adds all PHI nodes that
44 /// it creates to the vector.
45 SmallVectorImpl<PHINode*> *InsertedPHIs;
48 /// SSAUpdater constructor. If InsertedPHIs is specified, it will be filled
49 /// in with all PHI Nodes created by rewriting.
50 explicit SSAUpdater(SmallVectorImpl<PHINode*> *InsertedPHIs = 0);
53 /// Initialize - Reset this object to get ready for a new set of SSA
54 /// updates. ProtoValue is the value used to name PHI nodes.
55 void Initialize(Value *ProtoValue);
57 /// AddAvailableValue - Indicate that a rewritten value is available at the
58 /// end of the specified block with the specified value.
59 void AddAvailableValue(BasicBlock *BB, Value *V);
61 /// HasValueForBlock - Return true if the SSAUpdater already has a value for
62 /// the specified block.
63 bool HasValueForBlock(BasicBlock *BB) const;
65 /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
66 /// live at the end of the specified block.
67 Value *GetValueAtEndOfBlock(BasicBlock *BB);
69 /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
70 /// is live in the middle of the specified block.
72 /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
73 /// important case: if there is a definition of the rewritten value after the
74 /// 'use' in BB. Consider code like this:
80 /// br Cond, SomeBB, OutBB
82 /// In this case, there are two values (X1 and X2) added to the AvailableVals
83 /// set by the client of the rewriter, and those values are both live out of
84 /// their respective blocks. However, the use of X happens in the *middle* of
85 /// a block. Because of this, we need to insert a new PHI node in SomeBB to
86 /// merge the appropriate values, and this value isn't live out of the block.
88 Value *GetValueInMiddleOfBlock(BasicBlock *BB);
90 /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
91 /// which use their value in the corresponding predecessor. Note that this
92 /// will not work if the use is supposed to be rewritten to a value defined in
93 /// the same block as the use, but above it. Any 'AddAvailableValue's added
94 /// for the use's block will be considered to be below it.
95 void RewriteUse(Use &U);
97 /// RewriteUseAfterInsertions - Rewrite a use, just like RewriteUse. However,
98 /// this version of the method can rewrite uses in the same block as a
99 /// definition, because it assumes that all uses of a value are below any
101 void RewriteUseAfterInsertions(Use &U);
104 Value *GetValueAtEndOfBlockInternal(BasicBlock *BB);
106 void operator=(const SSAUpdater&); // DO NOT IMPLEMENT
107 SSAUpdater(const SSAUpdater&); // DO NOT IMPLEMENT
110 } // End llvm namespace