llvm.org GIT mirror llvm / c92383f
Delete the LiveValues pass. I won't get get back to the project it was started for in the foreseeable future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126668 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
6 changed file(s) with 0 addition(s) and 308 deletion(s). Raw diff Collapse all Expand all
+0
-99
include/llvm/Analysis/LiveValues.h less more
None //===- LiveValues.h - Liveness information for LLVM IR Values. ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for the LLVM IR Value liveness
10 // analysis pass.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_LIVEVALUES_H
15 #define LLVM_ANALYSIS_LIVEVALUES_H
16
17 #include "llvm/Pass.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20
21 namespace llvm {
22
23 class DominatorTree;
24 class LoopInfo;
25 class Value;
26
27 /// LiveValues - Analysis that provides liveness information for
28 /// LLVM IR Values.
29 ///
30 class LiveValues : public FunctionPass {
31 DominatorTree *DT;
32 LoopInfo *LI;
33
34 /// Memo - A bunch of state to be associated with a value.
35 ///
36 struct Memo {
37 /// Used - The set of blocks which contain a use of the value.
38 ///
39 SmallPtrSet Used;
40
41 /// LiveThrough - A conservative approximation of the set of blocks in
42 /// which the value is live-through, meaning blocks properly dominated
43 /// by the definition, and from which blocks containing uses of the
44 /// value are reachable.
45 ///
46 SmallPtrSet LiveThrough;
47
48 /// Killed - A conservative approximation of the set of blocks in which
49 /// the value is used and not live-out.
50 ///
51 SmallPtrSet Killed;
52 };
53
54 /// Memos - Remembers the Memo for each Value. This is populated on
55 /// demand.
56 ///
57 DenseMap Memos;
58
59 /// getMemo - Retrieve an existing Memo for the given value if one
60 /// is available, otherwise compute a new one.
61 ///
62 Memo &getMemo(const Value *V);
63
64 /// compute - Compute a new Memo for the given value.
65 ///
66 Memo &compute(const Value *V);
67
68 public:
69 static char ID;
70 LiveValues();
71
72 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
73 virtual bool runOnFunction(Function &F);
74 virtual void releaseMemory();
75
76 /// isUsedInBlock - Test if the given value is used in the given block.
77 ///
78 bool isUsedInBlock(const Value *V, const BasicBlock *BB);
79
80 /// isLiveThroughBlock - Test if the given value is known to be
81 /// live-through the given block, meaning that the block is properly
82 /// dominated by the value's definition, and there exists a block
83 /// reachable from it that contains a use. This uses a conservative
84 /// approximation that errs on the side of returning false.
85 ///
86 bool isLiveThroughBlock(const Value *V, const BasicBlock *BB);
87
88 /// isKilledInBlock - Test if the given value is known to be killed in
89 /// the given block, meaning that the block contains a use of the value,
90 /// and no blocks reachable from the block contain a use. This uses a
91 /// conservative approximation that errs on the side of returning false.
92 ///
93 bool isKilledInBlock(const Value *V, const BasicBlock *BB);
94 };
95
96 } // end namespace llvm
97
98 #endif
158158
159159 //===--------------------------------------------------------------------===//
160160 //
161 // createLiveValuesPass - This creates an instance of the LiveValues pass.
162 //
163 FunctionPass *createLiveValuesPass();
164
165 //===--------------------------------------------------------------------===//
166 //
167161 /// createLazyValueInfoPass - This creates an instance of the LazyValueInfo
168162 /// pass.
169163 FunctionPass *createLazyValueInfoPass();
122122 void initializeLiveDebugVariablesPass(PassRegistry&);
123123 void initializeLiveIntervalsPass(PassRegistry&);
124124 void initializeLiveStacksPass(PassRegistry&);
125 void initializeLiveValuesPass(PassRegistry&);
126125 void initializeLiveVariablesPass(PassRegistry&);
127126 void initializeLoaderPassPass(PassRegistry&);
128127 void initializePathProfileLoaderPassPass(PassRegistry&);
8383 (void) llvm::createLCSSAPass();
8484 (void) llvm::createLICMPass();
8585 (void) llvm::createLazyValueInfoPass();
86 (void) llvm::createLiveValuesPass();
8786 (void) llvm::createLoopDependenceAnalysisPass();
8887 (void) llvm::createLoopExtractorPass();
8988 (void) llvm::createLoopSimplifyPass();
4242 initializeLazyValueInfoPass(Registry);
4343 initializeLibCallAliasAnalysisPass(Registry);
4444 initializeLintPass(Registry);
45 initializeLiveValuesPass(Registry);
4645 initializeLoopDependenceAnalysisPass(Registry);
4746 initializeLoopInfoPass(Registry);
4847 initializeMemDepPrinterPass(Registry);
+0
-200
lib/Analysis/LiveValues.cpp less more
None //===- LiveValues.cpp - Liveness information for LLVM IR Values. ----------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the implementation for the LLVM IR Value liveness
10 // analysis pass.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/LiveValues.h"
15 #include "llvm/Instructions.h"
16 #include "llvm/Analysis/Dominators.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 using namespace llvm;
19
20 namespace llvm {
21 FunctionPass *createLiveValuesPass() { return new LiveValues(); }
22 }
23
24 char LiveValues::ID = 0;
25 INITIALIZE_PASS_BEGIN(LiveValues, "live-values",
26 "Value Liveness Analysis", false, true)
27 INITIALIZE_PASS_DEPENDENCY(DominatorTree)
28 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
29 INITIALIZE_PASS_END(LiveValues, "live-values",
30 "Value Liveness Analysis", false, true)
31
32 LiveValues::LiveValues() : FunctionPass(ID) {
33 initializeLiveValuesPass(*PassRegistry::getPassRegistry());
34 }
35
36 void LiveValues::getAnalysisUsage(AnalysisUsage &AU) const {
37 AU.addRequired();
38 AU.addRequired();
39 AU.setPreservesAll();
40 }
41
42 bool LiveValues::runOnFunction(Function &F) {
43 DT = &getAnalysis();
44 LI = &getAnalysis();
45
46 // This pass' values are computed lazily, so there's nothing to do here.
47
48 return false;
49 }
50
51 void LiveValues::releaseMemory() {
52 Memos.clear();
53 }
54
55 /// isUsedInBlock - Test if the given value is used in the given block.
56 ///
57 bool LiveValues::isUsedInBlock(const Value *V, const BasicBlock *BB) {
58 Memo &M = getMemo(V);
59 return M.Used.count(BB);
60 }
61
62 /// isLiveThroughBlock - Test if the given value is known to be
63 /// live-through the given block, meaning that the block is properly
64 /// dominated by the value's definition, and there exists a block
65 /// reachable from it that contains a use. This uses a conservative
66 /// approximation that errs on the side of returning false.
67 ///
68 bool LiveValues::isLiveThroughBlock(const Value *V,
69 const BasicBlock *BB) {
70 Memo &M = getMemo(V);
71 return M.LiveThrough.count(BB);
72 }
73
74 /// isKilledInBlock - Test if the given value is known to be killed in
75 /// the given block, meaning that the block contains a use of the value,
76 /// and no blocks reachable from the block contain a use. This uses a
77 /// conservative approximation that errs on the side of returning false.
78 ///
79 bool LiveValues::isKilledInBlock(const Value *V, const BasicBlock *BB) {
80 Memo &M = getMemo(V);
81 return M.Killed.count(BB);
82 }
83
84 /// getMemo - Retrieve an existing Memo for the given value if one
85 /// is available, otherwise compute a new one.
86 ///
87 LiveValues::Memo &LiveValues::getMemo(const Value *V) {
88 DenseMap::iterator I = Memos.find(V);
89 if (I != Memos.end())
90 return I->second;
91 return compute(V);
92 }
93
94 /// getImmediateDominator - A handy utility for the specific DominatorTree
95 /// query that we need here.
96 ///
97 static const BasicBlock *getImmediateDominator(const BasicBlock *BB,
98 const DominatorTree *DT) {
99 DomTreeNode *Node = DT->getNode(const_cast(BB))->getIDom();
100 return Node ? Node->getBlock() : 0;
101 }
102
103 /// compute - Compute a new Memo for the given value.
104 ///
105 LiveValues::Memo &LiveValues::compute(const Value *V) {
106 Memo &M = Memos[V];
107
108 // Determine the block containing the definition.
109 const BasicBlock *DefBB;
110 // Instructions define values with meaningful live ranges.
111 if (const Instruction *I = dyn_cast(V))
112 DefBB = I->getParent();
113 // Arguments can be analyzed as values defined in the entry block.
114 else if (const Argument *A = dyn_cast(V))
115 DefBB = &A->getParent()->getEntryBlock();
116 // Constants and other things aren't meaningful here, so just
117 // return having computed an empty Memo so that we don't come
118 // here again. The assumption here is that client code won't
119 // be asking about such values very often.
120 else
121 return M;
122
123 // Determine if the value is defined inside a loop. This is used
124 // to track whether the value is ever used outside the loop, so
125 // it'll be set to null if the value is either not defined in a
126 // loop or used outside the loop in which it is defined.
127 const Loop *L = LI->getLoopFor(DefBB);
128
129 // Track whether the value is used anywhere outside of the block
130 // in which it is defined.
131 bool LiveOutOfDefBB = false;
132
133 // Examine each use of the value.
134 for (Value::const_use_iterator I = V->use_begin(), E = V->use_end();
135 I != E; ++I) {
136 const User *U = *I;
137 const BasicBlock *UseBB = cast(U)->getParent();
138
139 // Note the block in which this use occurs.
140 M.Used.insert(UseBB);
141
142 // If the use block doesn't have successors, the value can be
143 // considered killed.
144 if (succ_begin(UseBB) == succ_end(UseBB))
145 M.Killed.insert(UseBB);
146
147 // Observe whether the value is used outside of the loop in which
148 // it is defined. Switch to an enclosing loop if necessary.
149 for (; L; L = L->getParentLoop())
150 if (L->contains(UseBB))
151 break;
152
153 // Search for live-through blocks.
154 const BasicBlock *BB;
155 if (const PHINode *PHI = dyn_cast(U)) {
156 // For PHI nodes, start the search at the incoming block paired with the
157 // incoming value, which must be dominated by the definition.
158 unsigned Num = PHI->getIncomingValueNumForOperand(I.getOperandNo());
159 BB = PHI->getIncomingBlock(Num);
160
161 // A PHI-node use means the value is live-out of it's defining block
162 // even if that block also contains the only use.
163 LiveOutOfDefBB = true;
164 } else {
165 // Otherwise just start the search at the use.
166 BB = UseBB;
167
168 // Note if the use is outside the defining block.
169 LiveOutOfDefBB |= UseBB != DefBB;
170 }
171
172 // Climb the immediate dominator tree from the use to the definition
173 // and mark all intermediate blocks as live-through.
174 for (; BB != DefBB; BB = getImmediateDominator(BB, DT)) {
175 if (BB != UseBB && !M.LiveThrough.insert(BB))
176 break;
177 }
178 }
179
180 // If the value is defined inside a loop and is not live outside
181 // the loop, then each exit block of the loop in which the value
182 // is used is a kill block.
183 if (L) {
184 SmallVector ExitingBlocks;
185 L->getExitingBlocks(ExitingBlocks);
186 for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
187 const BasicBlock *ExitingBlock = ExitingBlocks[i];
188 if (M.Used.count(ExitingBlock))
189 M.Killed.insert(ExitingBlock);
190 }
191 }
192
193 // If the value was never used outside the block in which it was
194 // defined, it's killed in that block.
195 if (!LiveOutOfDefBB)
196 M.Killed.insert(DefBB);
197
198 return M;
199 }