blob: 57b4dcb8d7c765ce34a9702b7620f29b5426f620 [file] [log] [blame]
Chris Lattner10f2d132009-11-11 00:22:30 +00001//===- LazyValueInfo.cpp - Value constraint analysis ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interface for lazy computation of value constraint
11// information.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattnerb8c124c2009-11-12 01:22:16 +000015#define DEBUG_TYPE "lazy-value-info"
Chris Lattner10f2d132009-11-11 00:22:30 +000016#include "llvm/Analysis/LazyValueInfo.h"
Chris Lattnercc4d3b22009-11-11 02:08:33 +000017#include "llvm/Constants.h"
18#include "llvm/Instructions.h"
19#include "llvm/Analysis/ConstantFolding.h"
20#include "llvm/Target/TargetData.h"
Chris Lattner16976522009-11-11 22:48:44 +000021#include "llvm/Support/CFG.h"
Owen Anderson5be2e782010-08-05 22:59:19 +000022#include "llvm/Support/ConstantRange.h"
Chris Lattnerb8c124c2009-11-12 01:22:16 +000023#include "llvm/Support/Debug.h"
Chris Lattner16976522009-11-11 22:48:44 +000024#include "llvm/Support/raw_ostream.h"
Owen Anderson7f9cb742010-07-30 23:59:40 +000025#include "llvm/Support/ValueHandle.h"
Chris Lattner16976522009-11-11 22:48:44 +000026#include "llvm/ADT/DenseMap.h"
Owen Anderson9a65dc92010-07-27 23:58:11 +000027#include "llvm/ADT/DenseSet.h"
Chris Lattnere5642812009-11-15 20:00:52 +000028#include "llvm/ADT/STLExtras.h"
Chris Lattner10f2d132009-11-11 00:22:30 +000029using namespace llvm;
30
31char LazyValueInfo::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +000032INITIALIZE_PASS(LazyValueInfo, "lazy-value-info",
33 "Lazy Value Information Analysis", false, true);
Chris Lattner10f2d132009-11-11 00:22:30 +000034
35namespace llvm {
36 FunctionPass *createLazyValueInfoPass() { return new LazyValueInfo(); }
37}
38
Chris Lattnercc4d3b22009-11-11 02:08:33 +000039
40//===----------------------------------------------------------------------===//
41// LVILatticeVal
42//===----------------------------------------------------------------------===//
43
44/// LVILatticeVal - This is the information tracked by LazyValueInfo for each
45/// value.
46///
47/// FIXME: This is basically just for bringup, this can be made a lot more rich
48/// in the future.
49///
50namespace {
51class LVILatticeVal {
52 enum LatticeValueTy {
53 /// undefined - This LLVM Value has no known value yet.
54 undefined,
Owen Anderson5be2e782010-08-05 22:59:19 +000055
Chris Lattnercc4d3b22009-11-11 02:08:33 +000056 /// constant - This LLVM Value has a specific constant value.
57 constant,
Chris Lattnerb52675b2009-11-12 04:36:58 +000058 /// notconstant - This LLVM value is known to not have the specified value.
59 notconstant,
60
Owen Anderson5be2e782010-08-05 22:59:19 +000061 /// constantrange
62 constantrange,
63
Chris Lattnercc4d3b22009-11-11 02:08:33 +000064 /// overdefined - This instruction is not known to be constant, and we know
65 /// it has a value.
66 overdefined
67 };
68
69 /// Val: This stores the current lattice value along with the Constant* for
Chris Lattnerb52675b2009-11-12 04:36:58 +000070 /// the constant if this is a 'constant' or 'notconstant' value.
Owen Andersondb78d732010-08-05 22:10:46 +000071 LatticeValueTy Tag;
72 Constant *Val;
Owen Anderson5be2e782010-08-05 22:59:19 +000073 ConstantRange Range;
Chris Lattnercc4d3b22009-11-11 02:08:33 +000074
75public:
Owen Anderson5be2e782010-08-05 22:59:19 +000076 LVILatticeVal() : Tag(undefined), Val(0), Range(1, true) {}
Chris Lattnercc4d3b22009-11-11 02:08:33 +000077
Chris Lattner16976522009-11-11 22:48:44 +000078 static LVILatticeVal get(Constant *C) {
79 LVILatticeVal Res;
Owen Anderson9f014062010-08-10 20:03:09 +000080 if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
81 Res.markConstantRange(ConstantRange(CI->getValue(), CI->getValue()+1));
82 else if (!isa<UndefValue>(C))
83 Res.markConstant(C);
Chris Lattner16976522009-11-11 22:48:44 +000084 return Res;
85 }
Chris Lattnerb52675b2009-11-12 04:36:58 +000086 static LVILatticeVal getNot(Constant *C) {
87 LVILatticeVal Res;
Owen Anderson9f014062010-08-10 20:03:09 +000088 if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
89 Res.markConstantRange(ConstantRange(CI->getValue()+1, CI->getValue()));
90 else
91 Res.markNotConstant(C);
Chris Lattnerb52675b2009-11-12 04:36:58 +000092 return Res;
93 }
Owen Anderson625051b2010-08-10 23:20:01 +000094 static LVILatticeVal getRange(ConstantRange CR) {
95 LVILatticeVal Res;
96 Res.markConstantRange(CR);
97 return Res;
98 }
Chris Lattner16976522009-11-11 22:48:44 +000099
Owen Anderson5be2e782010-08-05 22:59:19 +0000100 bool isUndefined() const { return Tag == undefined; }
101 bool isConstant() const { return Tag == constant; }
102 bool isNotConstant() const { return Tag == notconstant; }
103 bool isConstantRange() const { return Tag == constantrange; }
104 bool isOverdefined() const { return Tag == overdefined; }
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000105
106 Constant *getConstant() const {
107 assert(isConstant() && "Cannot get the constant of a non-constant!");
Owen Andersondb78d732010-08-05 22:10:46 +0000108 return Val;
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000109 }
110
Chris Lattnerb52675b2009-11-12 04:36:58 +0000111 Constant *getNotConstant() const {
112 assert(isNotConstant() && "Cannot get the constant of a non-notconstant!");
Owen Andersondb78d732010-08-05 22:10:46 +0000113 return Val;
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000114 }
115
Owen Anderson5be2e782010-08-05 22:59:19 +0000116 ConstantRange getConstantRange() const {
117 assert(isConstantRange() &&
118 "Cannot get the constant-range of a non-constant-range!");
119 return Range;
120 }
121
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000122 /// markOverdefined - Return true if this is a change in status.
123 bool markOverdefined() {
124 if (isOverdefined())
125 return false;
Owen Andersondb78d732010-08-05 22:10:46 +0000126 Tag = overdefined;
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000127 return true;
128 }
129
130 /// markConstant - Return true if this is a change in status.
131 bool markConstant(Constant *V) {
132 if (isConstant()) {
133 assert(getConstant() == V && "Marking constant with different value");
134 return false;
135 }
136
137 assert(isUndefined());
Owen Andersondb78d732010-08-05 22:10:46 +0000138 Tag = constant;
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000139 assert(V && "Marking constant with NULL");
Owen Andersondb78d732010-08-05 22:10:46 +0000140 Val = V;
Chris Lattner16976522009-11-11 22:48:44 +0000141 return true;
142 }
143
Chris Lattnerb52675b2009-11-12 04:36:58 +0000144 /// markNotConstant - Return true if this is a change in status.
145 bool markNotConstant(Constant *V) {
146 if (isNotConstant()) {
147 assert(getNotConstant() == V && "Marking !constant with different value");
148 return false;
149 }
150
151 if (isConstant())
152 assert(getConstant() != V && "Marking not constant with different value");
153 else
154 assert(isUndefined());
155
Owen Andersondb78d732010-08-05 22:10:46 +0000156 Tag = notconstant;
Chris Lattnerb52675b2009-11-12 04:36:58 +0000157 assert(V && "Marking constant with NULL");
Owen Andersondb78d732010-08-05 22:10:46 +0000158 Val = V;
Chris Lattnerb52675b2009-11-12 04:36:58 +0000159 return true;
160 }
161
Owen Anderson5be2e782010-08-05 22:59:19 +0000162 /// markConstantRange - Return true if this is a change in status.
163 bool markConstantRange(const ConstantRange NewR) {
164 if (isConstantRange()) {
165 if (NewR.isEmptySet())
166 return markOverdefined();
167
Owen Anderson5be2e782010-08-05 22:59:19 +0000168 bool changed = Range == NewR;
169 Range = NewR;
170 return changed;
171 }
172
173 assert(isUndefined());
174 if (NewR.isEmptySet())
175 return markOverdefined();
176 else if (NewR.isFullSet()) {
177 Tag = undefined;
178 return true;
179 }
180
181 Tag = constantrange;
182 Range = NewR;
183 return true;
184 }
185
Chris Lattner16976522009-11-11 22:48:44 +0000186 /// mergeIn - Merge the specified lattice value into this one, updating this
187 /// one and returning true if anything changed.
188 bool mergeIn(const LVILatticeVal &RHS) {
189 if (RHS.isUndefined() || isOverdefined()) return false;
190 if (RHS.isOverdefined()) return markOverdefined();
191
Chris Lattnerb52675b2009-11-12 04:36:58 +0000192 if (RHS.isNotConstant()) {
193 if (isNotConstant()) {
Chris Lattnerf496e792009-11-12 04:57:13 +0000194 if (getNotConstant() != RHS.getNotConstant() ||
195 isa<ConstantExpr>(getNotConstant()) ||
196 isa<ConstantExpr>(RHS.getNotConstant()))
Chris Lattnerb52675b2009-11-12 04:36:58 +0000197 return markOverdefined();
198 return false;
199 }
Chris Lattnerf496e792009-11-12 04:57:13 +0000200 if (isConstant()) {
201 if (getConstant() == RHS.getNotConstant() ||
202 isa<ConstantExpr>(RHS.getNotConstant()) ||
203 isa<ConstantExpr>(getConstant()))
204 return markOverdefined();
205 return markNotConstant(RHS.getNotConstant());
206 }
207
208 assert(isUndefined() && "Unexpected lattice");
Chris Lattnerb52675b2009-11-12 04:36:58 +0000209 return markNotConstant(RHS.getNotConstant());
210 }
211
Owen Anderson5be2e782010-08-05 22:59:19 +0000212 if (RHS.isConstantRange()) {
213 if (isConstantRange()) {
Owen Anderson9f014062010-08-10 20:03:09 +0000214 ConstantRange NewR = Range.unionWith(RHS.getConstantRange());
215 if (NewR.isFullSet())
Owen Anderson5be2e782010-08-05 22:59:19 +0000216 return markOverdefined();
217 else
218 return markConstantRange(NewR);
219 }
220
221 assert(isUndefined() && "Unexpected lattice");
222 return markConstantRange(RHS.getConstantRange());
223 }
224
Chris Lattnerf496e792009-11-12 04:57:13 +0000225 // RHS must be a constant, we must be undef, constant, or notconstant.
Owen Anderson5be2e782010-08-05 22:59:19 +0000226 assert(!isConstantRange() &&
227 "Constant and ConstantRange cannot be merged.");
228
Chris Lattnerf496e792009-11-12 04:57:13 +0000229 if (isUndefined())
230 return markConstant(RHS.getConstant());
231
232 if (isConstant()) {
233 if (getConstant() != RHS.getConstant())
234 return markOverdefined();
235 return false;
236 }
237
238 // If we are known "!=4" and RHS is "==5", stay at "!=4".
239 if (getNotConstant() == RHS.getConstant() ||
240 isa<ConstantExpr>(getNotConstant()) ||
241 isa<ConstantExpr>(RHS.getConstant()))
Chris Lattner16976522009-11-11 22:48:44 +0000242 return markOverdefined();
Chris Lattnerf496e792009-11-12 04:57:13 +0000243 return false;
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000244 }
245
246};
247
248} // end anonymous namespace.
249
Chris Lattner16976522009-11-11 22:48:44 +0000250namespace llvm {
251raw_ostream &operator<<(raw_ostream &OS, const LVILatticeVal &Val) {
252 if (Val.isUndefined())
253 return OS << "undefined";
254 if (Val.isOverdefined())
255 return OS << "overdefined";
Chris Lattnerb52675b2009-11-12 04:36:58 +0000256
257 if (Val.isNotConstant())
258 return OS << "notconstant<" << *Val.getNotConstant() << '>';
Owen Anderson2f3ffb82010-08-09 20:50:46 +0000259 else if (Val.isConstantRange())
260 return OS << "constantrange<" << Val.getConstantRange().getLower() << ", "
261 << Val.getConstantRange().getUpper() << '>';
Chris Lattner16976522009-11-11 22:48:44 +0000262 return OS << "constant<" << *Val.getConstant() << '>';
263}
264}
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000265
266//===----------------------------------------------------------------------===//
Chris Lattner2c5adf82009-11-15 19:59:49 +0000267// LazyValueInfoCache Decl
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000268//===----------------------------------------------------------------------===//
269
Chris Lattner2c5adf82009-11-15 19:59:49 +0000270namespace {
271 /// LazyValueInfoCache - This is the cache kept by LazyValueInfo which
272 /// maintains information about queries across the clients' queries.
273 class LazyValueInfoCache {
Owen Anderson81881bc2010-07-30 20:56:07 +0000274 public:
Chris Lattner2c5adf82009-11-15 19:59:49 +0000275 /// BlockCacheEntryTy - This is a computed lattice value at the end of the
276 /// specified basic block for a Value* that depends on context.
Owen Anderson00ac77e2010-08-18 18:39:01 +0000277 typedef std::pair<AssertingVH<BasicBlock>, LVILatticeVal> BlockCacheEntryTy;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000278
279 /// ValueCacheEntryTy - This is all of the cached block information for
280 /// exactly one Value*. The entries are sorted by the BasicBlock* of the
281 /// entries, allowing us to do a lookup with a binary search.
Owen Anderson00ac77e2010-08-18 18:39:01 +0000282 typedef std::map<AssertingVH<BasicBlock>, LVILatticeVal> ValueCacheEntryTy;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000283
Owen Anderson81881bc2010-07-30 20:56:07 +0000284 private:
Owen Anderson7f9cb742010-07-30 23:59:40 +0000285 /// LVIValueHandle - A callback value handle update the cache when
286 /// values are erased.
287 struct LVIValueHandle : public CallbackVH {
288 LazyValueInfoCache *Parent;
289
290 LVIValueHandle(Value *V, LazyValueInfoCache *P)
291 : CallbackVH(V), Parent(P) { }
292
293 void deleted();
294 void allUsesReplacedWith(Value* V) {
295 deleted();
296 }
297
298 LVIValueHandle &operator=(Value *V) {
299 return *this = LVIValueHandle(V, Parent);
300 }
301 };
302
Chris Lattner2c5adf82009-11-15 19:59:49 +0000303 /// ValueCache - This is all of the cached information for all values,
304 /// mapped from Value* to key information.
Owen Anderson7f9cb742010-07-30 23:59:40 +0000305 std::map<LVIValueHandle, ValueCacheEntryTy> ValueCache;
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000306
307 /// OverDefinedCache - This tracks, on a per-block basis, the set of
308 /// values that are over-defined at the end of that block. This is required
309 /// for cache updating.
Owen Anderson00ac77e2010-08-18 18:39:01 +0000310 std::set<std::pair<AssertingVH<BasicBlock>, Value*> > OverDefinedCache;
Owen Anderson7f9cb742010-07-30 23:59:40 +0000311
Chris Lattner2c5adf82009-11-15 19:59:49 +0000312 public:
313
314 /// getValueInBlock - This is the query interface to determine the lattice
315 /// value for the specified Value* at the end of the specified block.
316 LVILatticeVal getValueInBlock(Value *V, BasicBlock *BB);
317
318 /// getValueOnEdge - This is the query interface to determine the lattice
319 /// value for the specified Value* that is true on the specified edge.
320 LVILatticeVal getValueOnEdge(Value *V, BasicBlock *FromBB,BasicBlock *ToBB);
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000321
322 /// threadEdge - This is the update interface to inform the cache that an
323 /// edge from PredBB to OldSucc has been threaded to be from PredBB to
324 /// NewSucc.
325 void threadEdge(BasicBlock *PredBB,BasicBlock *OldSucc,BasicBlock *NewSucc);
Owen Anderson00ac77e2010-08-18 18:39:01 +0000326
327 /// eraseBlock - This is part of the update interface to inform the cache
328 /// that a block has been deleted.
329 void eraseBlock(BasicBlock *BB);
330
331 /// clear - Empty the cache.
332 void clear() {
333 ValueCache.clear();
334 OverDefinedCache.clear();
335 }
Chris Lattner2c5adf82009-11-15 19:59:49 +0000336 };
337} // end anonymous namespace
338
Owen Anderson81881bc2010-07-30 20:56:07 +0000339//===----------------------------------------------------------------------===//
340// LVIQuery Impl
341//===----------------------------------------------------------------------===//
342
343namespace {
344 /// LVIQuery - This is a transient object that exists while a query is
345 /// being performed.
346 ///
347 /// TODO: Reuse LVIQuery instead of recreating it for every query, this avoids
348 /// reallocation of the densemap on every query.
349 class LVIQuery {
350 typedef LazyValueInfoCache::BlockCacheEntryTy BlockCacheEntryTy;
351 typedef LazyValueInfoCache::ValueCacheEntryTy ValueCacheEntryTy;
352
353 /// This is the current value being queried for.
354 Value *Val;
355
Owen Anderson7f9cb742010-07-30 23:59:40 +0000356 /// This is a pointer to the owning cache, for recursive queries.
357 LazyValueInfoCache &Parent;
358
Owen Anderson81881bc2010-07-30 20:56:07 +0000359 /// This is all of the cached information about this value.
360 ValueCacheEntryTy &Cache;
361
362 /// This tracks, for each block, what values are overdefined.
Owen Anderson00ac77e2010-08-18 18:39:01 +0000363 std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &OverDefinedCache;
Owen Anderson81881bc2010-07-30 20:56:07 +0000364
365 /// NewBlocks - This is a mapping of the new BasicBlocks which have been
366 /// added to cache but that are not in sorted order.
367 DenseSet<BasicBlock*> NewBlockInfo;
368 public:
369
Owen Anderson7f9cb742010-07-30 23:59:40 +0000370 LVIQuery(Value *V, LazyValueInfoCache &P,
371 ValueCacheEntryTy &VC,
Owen Anderson00ac77e2010-08-18 18:39:01 +0000372 std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &ODC)
Owen Anderson7f9cb742010-07-30 23:59:40 +0000373 : Val(V), Parent(P), Cache(VC), OverDefinedCache(ODC) {
Owen Anderson81881bc2010-07-30 20:56:07 +0000374 }
375
376 ~LVIQuery() {
377 // When the query is done, insert the newly discovered facts into the
378 // cache in sorted order.
379 if (NewBlockInfo.empty()) return;
380
381 for (DenseSet<BasicBlock*>::iterator I = NewBlockInfo.begin(),
382 E = NewBlockInfo.end(); I != E; ++I) {
383 if (Cache[*I].isOverdefined())
384 OverDefinedCache.insert(std::make_pair(*I, Val));
385 }
386 }
387
388 LVILatticeVal getBlockValue(BasicBlock *BB);
389 LVILatticeVal getEdgeValue(BasicBlock *FromBB, BasicBlock *ToBB);
390
391 private:
Owen Anderson4bb3eaf2010-08-16 23:42:33 +0000392 LVILatticeVal getCachedEntryForBlock(BasicBlock *BB);
Owen Anderson81881bc2010-07-30 20:56:07 +0000393 };
394} // end anonymous namespace
Chris Lattner2c5adf82009-11-15 19:59:49 +0000395
Owen Anderson7f9cb742010-07-30 23:59:40 +0000396void LazyValueInfoCache::LVIValueHandle::deleted() {
Owen Anderson00ac77e2010-08-18 18:39:01 +0000397 for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
Owen Anderson7f9cb742010-07-30 23:59:40 +0000398 I = Parent->OverDefinedCache.begin(),
399 E = Parent->OverDefinedCache.end();
400 I != E; ) {
Owen Anderson00ac77e2010-08-18 18:39:01 +0000401 std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I;
Owen Anderson7f9cb742010-07-30 23:59:40 +0000402 ++I;
403 if (tmp->second == getValPtr())
404 Parent->OverDefinedCache.erase(tmp);
405 }
Owen Andersoncf6abd22010-08-11 22:36:04 +0000406
407 // This erasure deallocates *this, so it MUST happen after we're done
408 // using any and all members of *this.
409 Parent->ValueCache.erase(*this);
Owen Anderson7f9cb742010-07-30 23:59:40 +0000410}
411
Owen Anderson00ac77e2010-08-18 18:39:01 +0000412void LazyValueInfoCache::eraseBlock(BasicBlock *BB) {
413 for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
414 I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ) {
415 std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I;
416 ++I;
417 if (tmp->first == BB)
418 OverDefinedCache.erase(tmp);
419 }
420
421 for (std::map<LVIValueHandle, ValueCacheEntryTy>::iterator
422 I = ValueCache.begin(), E = ValueCache.end(); I != E; ++I)
423 I->second.erase(BB);
424}
Owen Anderson7f9cb742010-07-30 23:59:40 +0000425
Chris Lattnere5642812009-11-15 20:00:52 +0000426/// getCachedEntryForBlock - See if we already have a value for this block. If
Owen Anderson9a65dc92010-07-27 23:58:11 +0000427/// so, return it, otherwise create a new entry in the Cache map to use.
Owen Anderson4bb3eaf2010-08-16 23:42:33 +0000428LVILatticeVal LVIQuery::getCachedEntryForBlock(BasicBlock *BB) {
Owen Anderson81881bc2010-07-30 20:56:07 +0000429 NewBlockInfo.insert(BB);
Owen Anderson9a65dc92010-07-27 23:58:11 +0000430 return Cache[BB];
Chris Lattnere5642812009-11-15 20:00:52 +0000431}
Chris Lattner2c5adf82009-11-15 19:59:49 +0000432
Owen Anderson81881bc2010-07-30 20:56:07 +0000433LVILatticeVal LVIQuery::getBlockValue(BasicBlock *BB) {
Chris Lattner2c5adf82009-11-15 19:59:49 +0000434 // See if we already have a value for this block.
Owen Anderson4bb3eaf2010-08-16 23:42:33 +0000435 LVILatticeVal BBLV = getCachedEntryForBlock(BB);
Chris Lattner2c5adf82009-11-15 19:59:49 +0000436
437 // If we've already computed this block's value, return it.
Chris Lattnere5642812009-11-15 20:00:52 +0000438 if (!BBLV.isUndefined()) {
David Greene5d93a1f2009-12-23 20:43:58 +0000439 DEBUG(dbgs() << " reuse BB '" << BB->getName() << "' val=" << BBLV <<'\n');
Chris Lattner2c5adf82009-11-15 19:59:49 +0000440 return BBLV;
Chris Lattnere5642812009-11-15 20:00:52 +0000441 }
442
Chris Lattner2c5adf82009-11-15 19:59:49 +0000443 // Otherwise, this is the first time we're seeing this block. Reset the
444 // lattice value to overdefined, so that cycles will terminate and be
445 // conservatively correct.
446 BBLV.markOverdefined();
Owen Anderson4bb3eaf2010-08-16 23:42:33 +0000447 Cache[BB] = BBLV;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000448
449 // If V is live into BB, see if our predecessors know anything about it.
450 Instruction *BBI = dyn_cast<Instruction>(Val);
451 if (BBI == 0 || BBI->getParent() != BB) {
452 LVILatticeVal Result; // Start Undefined.
453 unsigned NumPreds = 0;
454
455 // Loop over all of our predecessors, merging what we know from them into
456 // result.
457 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
Owen Anderson81881bc2010-07-30 20:56:07 +0000458 Result.mergeIn(getEdgeValue(*PI, BB));
Chris Lattner2c5adf82009-11-15 19:59:49 +0000459
460 // If we hit overdefined, exit early. The BlockVals entry is already set
461 // to overdefined.
Chris Lattnere5642812009-11-15 20:00:52 +0000462 if (Result.isOverdefined()) {
David Greene5d93a1f2009-12-23 20:43:58 +0000463 DEBUG(dbgs() << " compute BB '" << BB->getName()
Chris Lattnere5642812009-11-15 20:00:52 +0000464 << "' - overdefined because of pred.\n");
Chris Lattner2c5adf82009-11-15 19:59:49 +0000465 return Result;
Chris Lattnere5642812009-11-15 20:00:52 +0000466 }
Chris Lattner2c5adf82009-11-15 19:59:49 +0000467 ++NumPreds;
468 }
469
470 // If this is the entry block, we must be asking about an argument. The
471 // value is overdefined.
472 if (NumPreds == 0 && BB == &BB->getParent()->front()) {
473 assert(isa<Argument>(Val) && "Unknown live-in to the entry block");
474 Result.markOverdefined();
475 return Result;
476 }
477
478 // Return the merged value, which is more precise than 'overdefined'.
479 assert(!Result.isOverdefined());
Owen Anderson4bb3eaf2010-08-16 23:42:33 +0000480 return Cache[BB] = Result;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000481 }
482
483 // If this value is defined by an instruction in this block, we have to
484 // process it here somehow or return overdefined.
485 if (PHINode *PN = dyn_cast<PHINode>(BBI)) {
Owen Anderson7f9cb742010-07-30 23:59:40 +0000486 LVILatticeVal Result; // Start Undefined.
487
488 // Loop over all of our predecessors, merging what we know from them into
489 // result.
490 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
491 Value* PhiVal = PN->getIncomingValueForBlock(*PI);
492 Result.mergeIn(Parent.getValueOnEdge(PhiVal, *PI, BB));
493
494 // If we hit overdefined, exit early. The BlockVals entry is already set
495 // to overdefined.
496 if (Result.isOverdefined()) {
497 DEBUG(dbgs() << " compute BB '" << BB->getName()
498 << "' - overdefined because of pred.\n");
499 return Result;
500 }
501 }
502
503 // Return the merged value, which is more precise than 'overdefined'.
504 assert(!Result.isOverdefined());
Owen Anderson00ac77e2010-08-18 18:39:01 +0000505 return Cache[BB] = Result;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000506 }
Chris Lattnere5642812009-11-15 20:00:52 +0000507
Owen Andersonb81fd622010-08-18 21:11:37 +0000508 assert(Cache[BB].isOverdefined() && "Recursive query changed our cache?");
509
510 // We can only analyze the definitions of certain classes of instructions
511 // (integral binops and casts at the moment), so bail if this isn't one.
Chris Lattner2c5adf82009-11-15 19:59:49 +0000512 LVILatticeVal Result;
Owen Andersonb81fd622010-08-18 21:11:37 +0000513 if ((!isa<BinaryOperator>(BBI) && !isa<CastInst>(BBI)) ||
514 !BBI->getType()->isIntegerTy()) {
515 DEBUG(dbgs() << " compute BB '" << BB->getName()
516 << "' - overdefined because inst def found.\n");
517 Result.markOverdefined();
518 return Result;
519 }
520
521 // FIXME: We're currently limited to binops with a constant RHS. This should
522 // be improved.
523 BinaryOperator *BO = dyn_cast<BinaryOperator>(BBI);
524 if (BO && !isa<ConstantInt>(BO->getOperand(1))) {
525 DEBUG(dbgs() << " compute BB '" << BB->getName()
526 << "' - overdefined because inst def found.\n");
527
528 Result.markOverdefined();
529 return Result;
530 }
531
532 // Figure out the range of the LHS. If that fails, bail.
533 LVILatticeVal LHSVal = Parent.getValueInBlock(BBI->getOperand(0), BB);
534 if (!LHSVal.isConstantRange()) {
535 Result.markOverdefined();
536 return Result;
537 }
538
539 ConstantInt *RHS = 0;
540 ConstantRange LHSRange = LHSVal.getConstantRange();
541 ConstantRange RHSRange(1);
542 const IntegerType *ResultTy = cast<IntegerType>(BBI->getType());
543 if (isa<BinaryOperator>(BBI)) {
544 RHS = cast<ConstantInt>(BBI->getOperand(1));
545 RHSRange = ConstantRange(RHS->getValue(), RHS->getValue()+1);
546 }
547
548 // NOTE: We're currently limited by the set of operations that ConstantRange
549 // can evaluate symbolically. Enhancing that set will allows us to analyze
550 // more definitions.
551 switch (BBI->getOpcode()) {
552 case Instruction::Add:
553 Result.markConstantRange(LHSRange.add(RHSRange));
554 break;
555 case Instruction::Sub:
556 Result.markConstantRange(LHSRange.sub(RHSRange));
557 break;
558 case Instruction::Mul:
559 Result.markConstantRange(LHSRange.multiply(RHSRange));
560 break;
561 case Instruction::UDiv:
562 Result.markConstantRange(LHSRange.udiv(RHSRange));
563 break;
564 case Instruction::Shl:
565 Result.markConstantRange(LHSRange.shl(RHSRange));
566 break;
567 case Instruction::LShr:
568 Result.markConstantRange(LHSRange.lshr(RHSRange));
569 break;
570 case Instruction::Trunc:
571 Result.markConstantRange(LHSRange.truncate(ResultTy->getBitWidth()));
572 break;
573 case Instruction::SExt:
574 Result.markConstantRange(LHSRange.signExtend(ResultTy->getBitWidth()));
575 break;
576 case Instruction::ZExt:
577 Result.markConstantRange(LHSRange.zeroExtend(ResultTy->getBitWidth()));
578 break;
579 case Instruction::BitCast:
580 Result.markConstantRange(LHSRange);
581 break;
582
583 // Unhandled instructions are overdefined.
584 default:
585 DEBUG(dbgs() << " compute BB '" << BB->getName()
586 << "' - overdefined because inst def found.\n");
587 Result.markOverdefined();
588 break;
589 }
590
591 return Cache[BB] = Result;
Chris Lattner10f2d132009-11-11 00:22:30 +0000592}
593
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000594
Chris Lattner800c47e2009-11-15 20:02:12 +0000595/// getEdgeValue - This method attempts to infer more complex
Owen Anderson81881bc2010-07-30 20:56:07 +0000596LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) {
Chris Lattner800c47e2009-11-15 20:02:12 +0000597 // TODO: Handle more complex conditionals. If (v == 0 || v2 < 1) is false, we
598 // know that v != 0.
Chris Lattner16976522009-11-11 22:48:44 +0000599 if (BranchInst *BI = dyn_cast<BranchInst>(BBFrom->getTerminator())) {
600 // If this is a conditional branch and only one successor goes to BBTo, then
601 // we maybe able to infer something from the condition.
602 if (BI->isConditional() &&
603 BI->getSuccessor(0) != BI->getSuccessor(1)) {
604 bool isTrueDest = BI->getSuccessor(0) == BBTo;
605 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
606 "BBTo isn't a successor of BBFrom");
607
608 // If V is the condition of the branch itself, then we know exactly what
609 // it is.
Chris Lattner2c5adf82009-11-15 19:59:49 +0000610 if (BI->getCondition() == Val)
Chris Lattner16976522009-11-11 22:48:44 +0000611 return LVILatticeVal::get(ConstantInt::get(
Owen Anderson9f014062010-08-10 20:03:09 +0000612 Type::getInt1Ty(Val->getContext()), isTrueDest));
Chris Lattner16976522009-11-11 22:48:44 +0000613
614 // If the condition of the branch is an equality comparison, we may be
615 // able to infer the value.
Owen Anderson2d0f2472010-08-11 04:24:25 +0000616 ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition());
617 if (ICI && ICI->getOperand(0) == Val &&
618 isa<Constant>(ICI->getOperand(1))) {
619 if (ICI->isEquality()) {
620 // We know that V has the RHS constant if this is a true SETEQ or
621 // false SETNE.
622 if (isTrueDest == (ICI->getPredicate() == ICmpInst::ICMP_EQ))
623 return LVILatticeVal::get(cast<Constant>(ICI->getOperand(1)));
624 return LVILatticeVal::getNot(cast<Constant>(ICI->getOperand(1)));
Chris Lattner16976522009-11-11 22:48:44 +0000625 }
Owen Anderson2d0f2472010-08-11 04:24:25 +0000626
627 if (ConstantInt *CI = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
628 // Calculate the range of values that would satisfy the comparison.
629 ConstantRange CmpRange(CI->getValue(), CI->getValue()+1);
630 ConstantRange TrueValues =
631 ConstantRange::makeICmpRegion(ICI->getPredicate(), CmpRange);
632
633 // If we're interested in the false dest, invert the condition.
634 if (!isTrueDest) TrueValues = TrueValues.inverse();
635
636 // Figure out the possible values of the query BEFORE this branch.
637 LVILatticeVal InBlock = getBlockValue(BBFrom);
638 if (!InBlock.isConstantRange()) return InBlock;
639
640 // Find all potential values that satisfy both the input and output
641 // conditions.
642 ConstantRange PossibleValues =
643 TrueValues.intersectWith(InBlock.getConstantRange());
644
645 return LVILatticeVal::getRange(PossibleValues);
646 }
647 }
Chris Lattner16976522009-11-11 22:48:44 +0000648 }
649 }
Chris Lattner800c47e2009-11-15 20:02:12 +0000650
651 // If the edge was formed by a switch on the value, then we may know exactly
652 // what it is.
653 if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) {
654 // If BBTo is the default destination of the switch, we don't know anything.
655 // Given a more powerful range analysis we could know stuff.
656 if (SI->getCondition() == Val && SI->getDefaultDest() != BBTo) {
657 // We only know something if there is exactly one value that goes from
658 // BBFrom to BBTo.
659 unsigned NumEdges = 0;
660 ConstantInt *EdgeVal = 0;
661 for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
662 if (SI->getSuccessor(i) != BBTo) continue;
663 if (NumEdges++) break;
664 EdgeVal = SI->getCaseValue(i);
665 }
666 assert(EdgeVal && "Missing successor?");
667 if (NumEdges == 1)
668 return LVILatticeVal::get(EdgeVal);
669 }
670 }
Chris Lattner16976522009-11-11 22:48:44 +0000671
672 // Otherwise see if the value is known in the block.
Owen Anderson81881bc2010-07-30 20:56:07 +0000673 return getBlockValue(BBFrom);
Chris Lattner16976522009-11-11 22:48:44 +0000674}
675
Owen Anderson81881bc2010-07-30 20:56:07 +0000676
677//===----------------------------------------------------------------------===//
678// LazyValueInfoCache Impl
679//===----------------------------------------------------------------------===//
680
Chris Lattner2c5adf82009-11-15 19:59:49 +0000681LVILatticeVal LazyValueInfoCache::getValueInBlock(Value *V, BasicBlock *BB) {
682 // If already a constant, there is nothing to compute.
Chris Lattner16976522009-11-11 22:48:44 +0000683 if (Constant *VC = dyn_cast<Constant>(V))
Chris Lattner2c5adf82009-11-15 19:59:49 +0000684 return LVILatticeVal::get(VC);
Chris Lattner16976522009-11-11 22:48:44 +0000685
David Greene5d93a1f2009-12-23 20:43:58 +0000686 DEBUG(dbgs() << "LVI Getting block end value " << *V << " at '"
Chris Lattner2c5adf82009-11-15 19:59:49 +0000687 << BB->getName() << "'\n");
688
Owen Anderson7f9cb742010-07-30 23:59:40 +0000689 LVILatticeVal Result = LVIQuery(V, *this,
690 ValueCache[LVIValueHandle(V, this)],
Owen Anderson81881bc2010-07-30 20:56:07 +0000691 OverDefinedCache).getBlockValue(BB);
Chris Lattner16976522009-11-11 22:48:44 +0000692
David Greene5d93a1f2009-12-23 20:43:58 +0000693 DEBUG(dbgs() << " Result = " << Result << "\n");
Chris Lattner2c5adf82009-11-15 19:59:49 +0000694 return Result;
695}
Chris Lattner16976522009-11-11 22:48:44 +0000696
Chris Lattner2c5adf82009-11-15 19:59:49 +0000697LVILatticeVal LazyValueInfoCache::
698getValueOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB) {
699 // If already a constant, there is nothing to compute.
700 if (Constant *VC = dyn_cast<Constant>(V))
701 return LVILatticeVal::get(VC);
702
David Greene5d93a1f2009-12-23 20:43:58 +0000703 DEBUG(dbgs() << "LVI Getting edge value " << *V << " from '"
Chris Lattner2c5adf82009-11-15 19:59:49 +0000704 << FromBB->getName() << "' to '" << ToBB->getName() << "'\n");
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000705
Owen Anderson81881bc2010-07-30 20:56:07 +0000706 LVILatticeVal Result =
Owen Anderson7f9cb742010-07-30 23:59:40 +0000707 LVIQuery(V, *this, ValueCache[LVIValueHandle(V, this)],
Owen Anderson81881bc2010-07-30 20:56:07 +0000708 OverDefinedCache).getEdgeValue(FromBB, ToBB);
Chris Lattner2c5adf82009-11-15 19:59:49 +0000709
David Greene5d93a1f2009-12-23 20:43:58 +0000710 DEBUG(dbgs() << " Result = " << Result << "\n");
Chris Lattner2c5adf82009-11-15 19:59:49 +0000711
712 return Result;
713}
714
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000715void LazyValueInfoCache::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
716 BasicBlock *NewSucc) {
717 // When an edge in the graph has been threaded, values that we could not
718 // determine a value for before (i.e. were marked overdefined) may be possible
719 // to solve now. We do NOT try to proactively update these values. Instead,
720 // we clear their entries from the cache, and allow lazy updating to recompute
721 // them when needed.
722
723 // The updating process is fairly simple: we need to dropped cached info
724 // for all values that were marked overdefined in OldSucc, and for those same
725 // values in any successor of OldSucc (except NewSucc) in which they were
726 // also marked overdefined.
727 std::vector<BasicBlock*> worklist;
728 worklist.push_back(OldSucc);
729
Owen Anderson9a65dc92010-07-27 23:58:11 +0000730 DenseSet<Value*> ClearSet;
Owen Anderson00ac77e2010-08-18 18:39:01 +0000731 for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
Owen Anderson9a65dc92010-07-27 23:58:11 +0000732 I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ++I) {
733 if (I->first == OldSucc)
734 ClearSet.insert(I->second);
735 }
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000736
737 // Use a worklist to perform a depth-first search of OldSucc's successors.
738 // NOTE: We do not need a visited list since any blocks we have already
739 // visited will have had their overdefined markers cleared already, and we
740 // thus won't loop to their successors.
741 while (!worklist.empty()) {
742 BasicBlock *ToUpdate = worklist.back();
743 worklist.pop_back();
744
745 // Skip blocks only accessible through NewSucc.
746 if (ToUpdate == NewSucc) continue;
747
748 bool changed = false;
Owen Anderson9a65dc92010-07-27 23:58:11 +0000749 for (DenseSet<Value*>::iterator I = ClearSet.begin(),E = ClearSet.end();
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000750 I != E; ++I) {
751 // If a value was marked overdefined in OldSucc, and is here too...
Owen Anderson00ac77e2010-08-18 18:39:01 +0000752 std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator OI =
Owen Anderson9a65dc92010-07-27 23:58:11 +0000753 OverDefinedCache.find(std::make_pair(ToUpdate, *I));
754 if (OI == OverDefinedCache.end()) continue;
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000755
Owen Anderson9a65dc92010-07-27 23:58:11 +0000756 // Remove it from the caches.
Owen Anderson7f9cb742010-07-30 23:59:40 +0000757 ValueCacheEntryTy &Entry = ValueCache[LVIValueHandle(*I, this)];
Owen Anderson9a65dc92010-07-27 23:58:11 +0000758 ValueCacheEntryTy::iterator CI = Entry.find(ToUpdate);
759
760 assert(CI != Entry.end() && "Couldn't find entry to update?");
761 Entry.erase(CI);
762 OverDefinedCache.erase(OI);
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000763
Owen Anderson9a65dc92010-07-27 23:58:11 +0000764 // If we removed anything, then we potentially need to update
765 // blocks successors too.
766 changed = true;
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000767 }
768
769 if (!changed) continue;
770
771 worklist.insert(worklist.end(), succ_begin(ToUpdate), succ_end(ToUpdate));
772 }
773}
774
Chris Lattner2c5adf82009-11-15 19:59:49 +0000775//===----------------------------------------------------------------------===//
776// LazyValueInfo Impl
777//===----------------------------------------------------------------------===//
778
Chris Lattner2c5adf82009-11-15 19:59:49 +0000779/// getCache - This lazily constructs the LazyValueInfoCache.
780static LazyValueInfoCache &getCache(void *&PImpl) {
781 if (!PImpl)
782 PImpl = new LazyValueInfoCache();
783 return *static_cast<LazyValueInfoCache*>(PImpl);
784}
785
Owen Anderson00ac77e2010-08-18 18:39:01 +0000786bool LazyValueInfo::runOnFunction(Function &F) {
787 if (PImpl)
788 getCache(PImpl).clear();
789
790 TD = getAnalysisIfAvailable<TargetData>();
791 // Fully lazy.
792 return false;
793}
794
Chris Lattner2c5adf82009-11-15 19:59:49 +0000795void LazyValueInfo::releaseMemory() {
796 // If the cache was allocated, free it.
797 if (PImpl) {
798 delete &getCache(PImpl);
799 PImpl = 0;
800 }
801}
802
803Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB) {
804 LVILatticeVal Result = getCache(PImpl).getValueInBlock(V, BB);
805
Chris Lattner16976522009-11-11 22:48:44 +0000806 if (Result.isConstant())
807 return Result.getConstant();
808 return 0;
809}
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000810
Chris Lattner38392bb2009-11-12 01:29:10 +0000811/// getConstantOnEdge - Determine whether the specified value is known to be a
812/// constant on the specified edge. Return null if not.
813Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB,
814 BasicBlock *ToBB) {
Chris Lattner2c5adf82009-11-15 19:59:49 +0000815 LVILatticeVal Result = getCache(PImpl).getValueOnEdge(V, FromBB, ToBB);
Chris Lattner38392bb2009-11-12 01:29:10 +0000816
817 if (Result.isConstant())
818 return Result.getConstant();
Owen Anderson9f014062010-08-10 20:03:09 +0000819 else if (Result.isConstantRange()) {
820 ConstantRange CR = Result.getConstantRange();
821 if (const APInt *SingleVal = CR.getSingleElement())
822 return ConstantInt::get(V->getContext(), *SingleVal);
823 }
Chris Lattner38392bb2009-11-12 01:29:10 +0000824 return 0;
825}
826
Chris Lattnerb52675b2009-11-12 04:36:58 +0000827/// getPredicateOnEdge - Determine whether the specified value comparison
828/// with a constant is known to be true or false on the specified CFG edge.
829/// Pred is a CmpInst predicate.
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000830LazyValueInfo::Tristate
Chris Lattnerb52675b2009-11-12 04:36:58 +0000831LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
832 BasicBlock *FromBB, BasicBlock *ToBB) {
Chris Lattner2c5adf82009-11-15 19:59:49 +0000833 LVILatticeVal Result = getCache(PImpl).getValueOnEdge(V, FromBB, ToBB);
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000834
Chris Lattnerb52675b2009-11-12 04:36:58 +0000835 // If we know the value is a constant, evaluate the conditional.
836 Constant *Res = 0;
837 if (Result.isConstant()) {
838 Res = ConstantFoldCompareInstOperands(Pred, Result.getConstant(), C, TD);
839 if (ConstantInt *ResCI = dyn_cast_or_null<ConstantInt>(Res))
840 return ResCI->isZero() ? False : True;
Chris Lattner2c5adf82009-11-15 19:59:49 +0000841 return Unknown;
842 }
843
Owen Anderson9f014062010-08-10 20:03:09 +0000844 if (Result.isConstantRange()) {
845 ConstantInt *CI = cast<ConstantInt>(C);
846 ConstantRange CR = Result.getConstantRange();
847 if (Pred == ICmpInst::ICMP_EQ) {
848 if (!CR.contains(CI->getValue()))
849 return False;
850
851 if (CR.isSingleElement() && CR.contains(CI->getValue()))
852 return True;
853 } else if (Pred == ICmpInst::ICMP_NE) {
854 if (!CR.contains(CI->getValue()))
855 return True;
856
857 if (CR.isSingleElement() && CR.contains(CI->getValue()))
858 return False;
859 }
860
861 // Handle more complex predicates.
862 ConstantRange RHS(CI->getValue(), CI->getValue()+1);
863 ConstantRange TrueValues = ConstantRange::makeICmpRegion(Pred, RHS);
864 if (CR.intersectWith(TrueValues).isEmptySet())
865 return False;
Owen Anderson625051b2010-08-10 23:20:01 +0000866 else if (TrueValues.contains(CR))
Owen Anderson9f014062010-08-10 20:03:09 +0000867 return True;
868
869 return Unknown;
870 }
871
Chris Lattner2c5adf82009-11-15 19:59:49 +0000872 if (Result.isNotConstant()) {
Chris Lattnerb52675b2009-11-12 04:36:58 +0000873 // If this is an equality comparison, we can try to fold it knowing that
874 // "V != C1".
875 if (Pred == ICmpInst::ICMP_EQ) {
876 // !C1 == C -> false iff C1 == C.
877 Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
878 Result.getNotConstant(), C, TD);
879 if (Res->isNullValue())
880 return False;
881 } else if (Pred == ICmpInst::ICMP_NE) {
882 // !C1 != C -> true iff C1 == C.
Chris Lattner5553a3a2009-11-15 20:01:24 +0000883 Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
Chris Lattnerb52675b2009-11-12 04:36:58 +0000884 Result.getNotConstant(), C, TD);
885 if (Res->isNullValue())
886 return True;
887 }
Chris Lattner2c5adf82009-11-15 19:59:49 +0000888 return Unknown;
Chris Lattnerb52675b2009-11-12 04:36:58 +0000889 }
890
Chris Lattnercc4d3b22009-11-11 02:08:33 +0000891 return Unknown;
892}
893
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000894void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
895 BasicBlock* NewSucc) {
Owen Anderson00ac77e2010-08-18 18:39:01 +0000896 if (PImpl) getCache(PImpl).threadEdge(PredBB, OldSucc, NewSucc);
897}
898
899void LazyValueInfo::eraseBlock(BasicBlock *BB) {
900 if (PImpl) getCache(PImpl).eraseBlock(BB);
Owen Andersoncfa7fb62010-07-26 18:48:03 +0000901}