Chris Lattner | 10f2d13 | 2009-11-11 00:22:30 +0000 | [diff] [blame] | 1 | //===- 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 Lattner | b8c124c | 2009-11-12 01:22:16 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "lazy-value-info" |
Chris Lattner | 10f2d13 | 2009-11-11 00:22:30 +0000 | [diff] [blame] | 16 | #include "llvm/Analysis/LazyValueInfo.h" |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 17 | #include "llvm/Constants.h" |
| 18 | #include "llvm/Instructions.h" |
| 19 | #include "llvm/Analysis/ConstantFolding.h" |
| 20 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CFG.h" |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ConstantRange.h" |
Chris Lattner | b8c124c | 2009-11-12 01:22:16 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/DenseMap.h" |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/DenseSet.h" |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 10f2d13 | 2009-11-11 00:22:30 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
| 31 | char LazyValueInfo::ID = 0; |
Owen Anderson | d13db2c | 2010-07-21 22:09:45 +0000 | [diff] [blame] | 32 | INITIALIZE_PASS(LazyValueInfo, "lazy-value-info", |
| 33 | "Lazy Value Information Analysis", false, true); |
Chris Lattner | 10f2d13 | 2009-11-11 00:22:30 +0000 | [diff] [blame] | 34 | |
| 35 | namespace llvm { |
| 36 | FunctionPass *createLazyValueInfoPass() { return new LazyValueInfo(); } |
| 37 | } |
| 38 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 39 | |
| 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 | /// |
| 50 | namespace { |
| 51 | class LVILatticeVal { |
| 52 | enum LatticeValueTy { |
| 53 | /// undefined - This LLVM Value has no known value yet. |
| 54 | undefined, |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 55 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 56 | /// constant - This LLVM Value has a specific constant value. |
| 57 | constant, |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 58 | /// notconstant - This LLVM value is known to not have the specified value. |
| 59 | notconstant, |
| 60 | |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 61 | /// constantrange |
| 62 | constantrange, |
| 63 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 64 | /// 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 Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 70 | /// the constant if this is a 'constant' or 'notconstant' value. |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 71 | LatticeValueTy Tag; |
| 72 | Constant *Val; |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 73 | ConstantRange Range; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 74 | |
| 75 | public: |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 76 | LVILatticeVal() : Tag(undefined), Val(0), Range(1, true) {} |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 78 | static LVILatticeVal get(Constant *C) { |
| 79 | LVILatticeVal Res; |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 80 | 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 Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 84 | return Res; |
| 85 | } |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 86 | static LVILatticeVal getNot(Constant *C) { |
| 87 | LVILatticeVal Res; |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 88 | if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) |
| 89 | Res.markConstantRange(ConstantRange(CI->getValue()+1, CI->getValue())); |
| 90 | else |
| 91 | Res.markNotConstant(C); |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 92 | return Res; |
| 93 | } |
Owen Anderson | 625051b | 2010-08-10 23:20:01 +0000 | [diff] [blame] | 94 | static LVILatticeVal getRange(ConstantRange CR) { |
| 95 | LVILatticeVal Res; |
| 96 | Res.markConstantRange(CR); |
| 97 | return Res; |
| 98 | } |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 99 | |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 100 | 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 Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 105 | |
| 106 | Constant *getConstant() const { |
| 107 | assert(isConstant() && "Cannot get the constant of a non-constant!"); |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 108 | return Val; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 111 | Constant *getNotConstant() const { |
| 112 | assert(isNotConstant() && "Cannot get the constant of a non-notconstant!"); |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 113 | return Val; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 116 | ConstantRange getConstantRange() const { |
| 117 | assert(isConstantRange() && |
| 118 | "Cannot get the constant-range of a non-constant-range!"); |
| 119 | return Range; |
| 120 | } |
| 121 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 122 | /// markOverdefined - Return true if this is a change in status. |
| 123 | bool markOverdefined() { |
| 124 | if (isOverdefined()) |
| 125 | return false; |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 126 | Tag = overdefined; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 127 | 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 Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 138 | Tag = constant; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 139 | assert(V && "Marking constant with NULL"); |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 140 | Val = V; |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 141 | return true; |
| 142 | } |
| 143 | |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 144 | /// 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 Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 156 | Tag = notconstant; |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 157 | assert(V && "Marking constant with NULL"); |
Owen Anderson | db78d73 | 2010-08-05 22:10:46 +0000 | [diff] [blame] | 158 | Val = V; |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 159 | return true; |
| 160 | } |
| 161 | |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 162 | /// 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 Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 168 | bool changed = Range == NewR; |
| 169 | Range = NewR; |
| 170 | return changed; |
| 171 | } |
| 172 | |
| 173 | assert(isUndefined()); |
| 174 | if (NewR.isEmptySet()) |
| 175 | return markOverdefined(); |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 176 | |
| 177 | Tag = constantrange; |
| 178 | Range = NewR; |
| 179 | return true; |
| 180 | } |
| 181 | |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 182 | /// mergeIn - Merge the specified lattice value into this one, updating this |
| 183 | /// one and returning true if anything changed. |
| 184 | bool mergeIn(const LVILatticeVal &RHS) { |
| 185 | if (RHS.isUndefined() || isOverdefined()) return false; |
| 186 | if (RHS.isOverdefined()) return markOverdefined(); |
| 187 | |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 188 | if (RHS.isNotConstant()) { |
| 189 | if (isNotConstant()) { |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 190 | if (getNotConstant() != RHS.getNotConstant() || |
| 191 | isa<ConstantExpr>(getNotConstant()) || |
| 192 | isa<ConstantExpr>(RHS.getNotConstant())) |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 193 | return markOverdefined(); |
| 194 | return false; |
Owen Anderson | 3929532 | 2010-08-30 17:03:45 +0000 | [diff] [blame] | 195 | } else if (isConstant()) { |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 196 | if (getConstant() == RHS.getNotConstant() || |
| 197 | isa<ConstantExpr>(RHS.getNotConstant()) || |
| 198 | isa<ConstantExpr>(getConstant())) |
| 199 | return markOverdefined(); |
| 200 | return markNotConstant(RHS.getNotConstant()); |
Owen Anderson | 3929532 | 2010-08-30 17:03:45 +0000 | [diff] [blame] | 201 | } else if (isConstantRange()) { |
| 202 | return markOverdefined(); |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | assert(isUndefined() && "Unexpected lattice"); |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 206 | return markNotConstant(RHS.getNotConstant()); |
| 207 | } |
| 208 | |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 209 | if (RHS.isConstantRange()) { |
| 210 | if (isConstantRange()) { |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 211 | ConstantRange NewR = Range.unionWith(RHS.getConstantRange()); |
| 212 | if (NewR.isFullSet()) |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 213 | return markOverdefined(); |
| 214 | else |
| 215 | return markConstantRange(NewR); |
Owen Anderson | 59b06dc | 2010-08-24 07:55:44 +0000 | [diff] [blame] | 216 | } else if (!isUndefined()) { |
| 217 | return markOverdefined(); |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | assert(isUndefined() && "Unexpected lattice"); |
| 221 | return markConstantRange(RHS.getConstantRange()); |
| 222 | } |
| 223 | |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 224 | // RHS must be a constant, we must be undef, constant, or notconstant. |
Owen Anderson | 5be2e78 | 2010-08-05 22:59:19 +0000 | [diff] [blame] | 225 | assert(!isConstantRange() && |
| 226 | "Constant and ConstantRange cannot be merged."); |
| 227 | |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 228 | if (isUndefined()) |
| 229 | return markConstant(RHS.getConstant()); |
| 230 | |
| 231 | if (isConstant()) { |
| 232 | if (getConstant() != RHS.getConstant()) |
| 233 | return markOverdefined(); |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | // If we are known "!=4" and RHS is "==5", stay at "!=4". |
| 238 | if (getNotConstant() == RHS.getConstant() || |
| 239 | isa<ConstantExpr>(getNotConstant()) || |
| 240 | isa<ConstantExpr>(RHS.getConstant())) |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 241 | return markOverdefined(); |
Chris Lattner | f496e79 | 2009-11-12 04:57:13 +0000 | [diff] [blame] | 242 | return false; |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | }; |
| 246 | |
| 247 | } // end anonymous namespace. |
| 248 | |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 249 | namespace llvm { |
| 250 | raw_ostream &operator<<(raw_ostream &OS, const LVILatticeVal &Val) { |
| 251 | if (Val.isUndefined()) |
| 252 | return OS << "undefined"; |
| 253 | if (Val.isOverdefined()) |
| 254 | return OS << "overdefined"; |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 255 | |
| 256 | if (Val.isNotConstant()) |
| 257 | return OS << "notconstant<" << *Val.getNotConstant() << '>'; |
Owen Anderson | 2f3ffb8 | 2010-08-09 20:50:46 +0000 | [diff] [blame] | 258 | else if (Val.isConstantRange()) |
| 259 | return OS << "constantrange<" << Val.getConstantRange().getLower() << ", " |
| 260 | << Val.getConstantRange().getUpper() << '>'; |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 261 | return OS << "constant<" << *Val.getConstant() << '>'; |
| 262 | } |
| 263 | } |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 264 | |
| 265 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 266 | // LazyValueInfoCache Decl |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 267 | //===----------------------------------------------------------------------===// |
| 268 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 269 | namespace { |
| 270 | /// LazyValueInfoCache - This is the cache kept by LazyValueInfo which |
| 271 | /// maintains information about queries across the clients' queries. |
| 272 | class LazyValueInfoCache { |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 273 | public: |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 274 | /// BlockCacheEntryTy - This is a computed lattice value at the end of the |
| 275 | /// specified basic block for a Value* that depends on context. |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 276 | typedef std::pair<AssertingVH<BasicBlock>, LVILatticeVal> BlockCacheEntryTy; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 277 | |
| 278 | /// ValueCacheEntryTy - This is all of the cached block information for |
| 279 | /// exactly one Value*. The entries are sorted by the BasicBlock* of the |
| 280 | /// entries, allowing us to do a lookup with a binary search. |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 281 | typedef std::map<AssertingVH<BasicBlock>, LVILatticeVal> ValueCacheEntryTy; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 282 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 283 | private: |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 284 | /// LVIValueHandle - A callback value handle update the cache when |
| 285 | /// values are erased. |
| 286 | struct LVIValueHandle : public CallbackVH { |
| 287 | LazyValueInfoCache *Parent; |
| 288 | |
| 289 | LVIValueHandle(Value *V, LazyValueInfoCache *P) |
| 290 | : CallbackVH(V), Parent(P) { } |
| 291 | |
| 292 | void deleted(); |
| 293 | void allUsesReplacedWith(Value* V) { |
| 294 | deleted(); |
| 295 | } |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 298 | /// ValueCache - This is all of the cached information for all values, |
| 299 | /// mapped from Value* to key information. |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 300 | std::map<LVIValueHandle, ValueCacheEntryTy> ValueCache; |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 301 | |
| 302 | /// OverDefinedCache - This tracks, on a per-block basis, the set of |
| 303 | /// values that are over-defined at the end of that block. This is required |
| 304 | /// for cache updating. |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 305 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> > OverDefinedCache; |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 306 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 307 | public: |
| 308 | |
| 309 | /// getValueInBlock - This is the query interface to determine the lattice |
| 310 | /// value for the specified Value* at the end of the specified block. |
| 311 | LVILatticeVal getValueInBlock(Value *V, BasicBlock *BB); |
| 312 | |
| 313 | /// getValueOnEdge - This is the query interface to determine the lattice |
| 314 | /// value for the specified Value* that is true on the specified edge. |
| 315 | LVILatticeVal getValueOnEdge(Value *V, BasicBlock *FromBB,BasicBlock *ToBB); |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 316 | |
| 317 | /// threadEdge - This is the update interface to inform the cache that an |
| 318 | /// edge from PredBB to OldSucc has been threaded to be from PredBB to |
| 319 | /// NewSucc. |
| 320 | void threadEdge(BasicBlock *PredBB,BasicBlock *OldSucc,BasicBlock *NewSucc); |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 321 | |
| 322 | /// eraseBlock - This is part of the update interface to inform the cache |
| 323 | /// that a block has been deleted. |
| 324 | void eraseBlock(BasicBlock *BB); |
| 325 | |
| 326 | /// clear - Empty the cache. |
| 327 | void clear() { |
| 328 | ValueCache.clear(); |
| 329 | OverDefinedCache.clear(); |
| 330 | } |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 331 | }; |
| 332 | } // end anonymous namespace |
| 333 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 334 | //===----------------------------------------------------------------------===// |
| 335 | // LVIQuery Impl |
| 336 | //===----------------------------------------------------------------------===// |
| 337 | |
| 338 | namespace { |
| 339 | /// LVIQuery - This is a transient object that exists while a query is |
| 340 | /// being performed. |
| 341 | /// |
| 342 | /// TODO: Reuse LVIQuery instead of recreating it for every query, this avoids |
| 343 | /// reallocation of the densemap on every query. |
| 344 | class LVIQuery { |
| 345 | typedef LazyValueInfoCache::BlockCacheEntryTy BlockCacheEntryTy; |
| 346 | typedef LazyValueInfoCache::ValueCacheEntryTy ValueCacheEntryTy; |
| 347 | |
| 348 | /// This is the current value being queried for. |
| 349 | Value *Val; |
| 350 | |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 351 | /// This is a pointer to the owning cache, for recursive queries. |
| 352 | LazyValueInfoCache &Parent; |
| 353 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 354 | /// This is all of the cached information about this value. |
| 355 | ValueCacheEntryTy &Cache; |
| 356 | |
| 357 | /// This tracks, for each block, what values are overdefined. |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 358 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &OverDefinedCache; |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 359 | |
| 360 | /// NewBlocks - This is a mapping of the new BasicBlocks which have been |
| 361 | /// added to cache but that are not in sorted order. |
| 362 | DenseSet<BasicBlock*> NewBlockInfo; |
Owen Anderson | c8ef750 | 2010-08-24 20:47:29 +0000 | [diff] [blame] | 363 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 364 | public: |
| 365 | |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 366 | LVIQuery(Value *V, LazyValueInfoCache &P, |
| 367 | ValueCacheEntryTy &VC, |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 368 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &ODC) |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 369 | : Val(V), Parent(P), Cache(VC), OverDefinedCache(ODC) { |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | ~LVIQuery() { |
| 373 | // When the query is done, insert the newly discovered facts into the |
| 374 | // cache in sorted order. |
| 375 | if (NewBlockInfo.empty()) return; |
| 376 | |
| 377 | for (DenseSet<BasicBlock*>::iterator I = NewBlockInfo.begin(), |
| 378 | E = NewBlockInfo.end(); I != E; ++I) { |
| 379 | if (Cache[*I].isOverdefined()) |
| 380 | OverDefinedCache.insert(std::make_pair(*I, Val)); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | LVILatticeVal getBlockValue(BasicBlock *BB); |
| 385 | LVILatticeVal getEdgeValue(BasicBlock *FromBB, BasicBlock *ToBB); |
| 386 | |
| 387 | private: |
Owen Anderson | 4bb3eaf | 2010-08-16 23:42:33 +0000 | [diff] [blame] | 388 | LVILatticeVal getCachedEntryForBlock(BasicBlock *BB); |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 389 | }; |
| 390 | } // end anonymous namespace |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 391 | |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 392 | void LazyValueInfoCache::LVIValueHandle::deleted() { |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 393 | for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 394 | I = Parent->OverDefinedCache.begin(), |
| 395 | E = Parent->OverDefinedCache.end(); |
| 396 | I != E; ) { |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 397 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I; |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 398 | ++I; |
| 399 | if (tmp->second == getValPtr()) |
| 400 | Parent->OverDefinedCache.erase(tmp); |
| 401 | } |
Owen Anderson | cf6abd2 | 2010-08-11 22:36:04 +0000 | [diff] [blame] | 402 | |
| 403 | // This erasure deallocates *this, so it MUST happen after we're done |
| 404 | // using any and all members of *this. |
| 405 | Parent->ValueCache.erase(*this); |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 408 | void LazyValueInfoCache::eraseBlock(BasicBlock *BB) { |
| 409 | for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator |
| 410 | I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ) { |
| 411 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I; |
| 412 | ++I; |
| 413 | if (tmp->first == BB) |
| 414 | OverDefinedCache.erase(tmp); |
| 415 | } |
| 416 | |
| 417 | for (std::map<LVIValueHandle, ValueCacheEntryTy>::iterator |
| 418 | I = ValueCache.begin(), E = ValueCache.end(); I != E; ++I) |
| 419 | I->second.erase(BB); |
| 420 | } |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 421 | |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 422 | /// getCachedEntryForBlock - See if we already have a value for this block. If |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 423 | /// so, return it, otherwise create a new entry in the Cache map to use. |
Owen Anderson | 4bb3eaf | 2010-08-16 23:42:33 +0000 | [diff] [blame] | 424 | LVILatticeVal LVIQuery::getCachedEntryForBlock(BasicBlock *BB) { |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 425 | NewBlockInfo.insert(BB); |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 426 | return Cache[BB]; |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 427 | } |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 428 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 429 | LVILatticeVal LVIQuery::getBlockValue(BasicBlock *BB) { |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 430 | // See if we already have a value for this block. |
Owen Anderson | 4bb3eaf | 2010-08-16 23:42:33 +0000 | [diff] [blame] | 431 | LVILatticeVal BBLV = getCachedEntryForBlock(BB); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 432 | |
| 433 | // If we've already computed this block's value, return it. |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 434 | if (!BBLV.isUndefined()) { |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 435 | DEBUG(dbgs() << " reuse BB '" << BB->getName() << "' val=" << BBLV <<'\n'); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 436 | return BBLV; |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 439 | // Otherwise, this is the first time we're seeing this block. Reset the |
| 440 | // lattice value to overdefined, so that cycles will terminate and be |
| 441 | // conservatively correct. |
| 442 | BBLV.markOverdefined(); |
Owen Anderson | 4bb3eaf | 2010-08-16 23:42:33 +0000 | [diff] [blame] | 443 | Cache[BB] = BBLV; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 444 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 445 | Instruction *BBI = dyn_cast<Instruction>(Val); |
| 446 | if (BBI == 0 || BBI->getParent() != BB) { |
| 447 | LVILatticeVal Result; // Start Undefined. |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 448 | |
Owen Anderson | c8ef750 | 2010-08-24 20:47:29 +0000 | [diff] [blame] | 449 | // If this is a pointer, and there's a load from that pointer in this BB, |
| 450 | // then we know that the pointer can't be NULL. |
Owen Anderson | 1593dd6 | 2010-09-03 19:08:37 +0000 | [diff] [blame] | 451 | bool NotNull = false; |
Owen Anderson | c8ef750 | 2010-08-24 20:47:29 +0000 | [diff] [blame] | 452 | if (Val->getType()->isPointerTy()) { |
Owen Anderson | 6cd2075 | 2010-08-25 01:16:47 +0000 | [diff] [blame] | 453 | for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE;++BI){ |
| 454 | LoadInst *L = dyn_cast<LoadInst>(BI); |
| 455 | if (L && L->getPointerAddressSpace() == 0 && |
| 456 | L->getPointerOperand()->getUnderlyingObject() == |
| 457 | Val->getUnderlyingObject()) { |
Owen Anderson | 1593dd6 | 2010-09-03 19:08:37 +0000 | [diff] [blame] | 458 | NotNull = true; |
| 459 | break; |
Owen Anderson | c8ef750 | 2010-08-24 20:47:29 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | unsigned NumPreds = 0; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 465 | // Loop over all of our predecessors, merging what we know from them into |
| 466 | // result. |
| 467 | for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 468 | Result.mergeIn(getEdgeValue(*PI, BB)); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 469 | |
| 470 | // If we hit overdefined, exit early. The BlockVals entry is already set |
| 471 | // to overdefined. |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 472 | if (Result.isOverdefined()) { |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 473 | DEBUG(dbgs() << " compute BB '" << BB->getName() |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 474 | << "' - overdefined because of pred.\n"); |
Owen Anderson | 1593dd6 | 2010-09-03 19:08:37 +0000 | [diff] [blame] | 475 | // If we previously determined that this is a pointer that can't be null |
| 476 | // then return that rather than giving up entirely. |
| 477 | if (NotNull) { |
| 478 | const PointerType *PTy = cast<PointerType>(Val->getType()); |
| 479 | Result = LVILatticeVal::getNot(ConstantPointerNull::get(PTy)); |
| 480 | } |
| 481 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 482 | return Result; |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 483 | } |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 484 | ++NumPreds; |
| 485 | } |
| 486 | |
Owen Anderson | 1593dd6 | 2010-09-03 19:08:37 +0000 | [diff] [blame] | 487 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 488 | // If this is the entry block, we must be asking about an argument. The |
| 489 | // value is overdefined. |
| 490 | if (NumPreds == 0 && BB == &BB->getParent()->front()) { |
| 491 | assert(isa<Argument>(Val) && "Unknown live-in to the entry block"); |
| 492 | Result.markOverdefined(); |
| 493 | return Result; |
| 494 | } |
| 495 | |
| 496 | // Return the merged value, which is more precise than 'overdefined'. |
| 497 | assert(!Result.isOverdefined()); |
Owen Anderson | 4bb3eaf | 2010-08-16 23:42:33 +0000 | [diff] [blame] | 498 | return Cache[BB] = Result; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | // If this value is defined by an instruction in this block, we have to |
| 502 | // process it here somehow or return overdefined. |
| 503 | if (PHINode *PN = dyn_cast<PHINode>(BBI)) { |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 504 | LVILatticeVal Result; // Start Undefined. |
| 505 | |
| 506 | // Loop over all of our predecessors, merging what we know from them into |
| 507 | // result. |
| 508 | for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { |
| 509 | Value* PhiVal = PN->getIncomingValueForBlock(*PI); |
| 510 | Result.mergeIn(Parent.getValueOnEdge(PhiVal, *PI, BB)); |
| 511 | |
| 512 | // If we hit overdefined, exit early. The BlockVals entry is already set |
| 513 | // to overdefined. |
| 514 | if (Result.isOverdefined()) { |
| 515 | DEBUG(dbgs() << " compute BB '" << BB->getName() |
| 516 | << "' - overdefined because of pred.\n"); |
| 517 | return Result; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | // Return the merged value, which is more precise than 'overdefined'. |
| 522 | assert(!Result.isOverdefined()); |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 523 | return Cache[BB] = Result; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 524 | } |
Chris Lattner | e564281 | 2009-11-15 20:00:52 +0000 | [diff] [blame] | 525 | |
Owen Anderson | b81fd62 | 2010-08-18 21:11:37 +0000 | [diff] [blame] | 526 | assert(Cache[BB].isOverdefined() && "Recursive query changed our cache?"); |
| 527 | |
| 528 | // We can only analyze the definitions of certain classes of instructions |
| 529 | // (integral binops and casts at the moment), so bail if this isn't one. |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 530 | LVILatticeVal Result; |
Owen Anderson | b81fd62 | 2010-08-18 21:11:37 +0000 | [diff] [blame] | 531 | if ((!isa<BinaryOperator>(BBI) && !isa<CastInst>(BBI)) || |
| 532 | !BBI->getType()->isIntegerTy()) { |
| 533 | DEBUG(dbgs() << " compute BB '" << BB->getName() |
| 534 | << "' - overdefined because inst def found.\n"); |
| 535 | Result.markOverdefined(); |
| 536 | return Result; |
| 537 | } |
| 538 | |
| 539 | // FIXME: We're currently limited to binops with a constant RHS. This should |
| 540 | // be improved. |
| 541 | BinaryOperator *BO = dyn_cast<BinaryOperator>(BBI); |
| 542 | if (BO && !isa<ConstantInt>(BO->getOperand(1))) { |
| 543 | DEBUG(dbgs() << " compute BB '" << BB->getName() |
| 544 | << "' - overdefined because inst def found.\n"); |
| 545 | |
| 546 | Result.markOverdefined(); |
| 547 | return Result; |
| 548 | } |
| 549 | |
| 550 | // Figure out the range of the LHS. If that fails, bail. |
| 551 | LVILatticeVal LHSVal = Parent.getValueInBlock(BBI->getOperand(0), BB); |
| 552 | if (!LHSVal.isConstantRange()) { |
| 553 | Result.markOverdefined(); |
| 554 | return Result; |
| 555 | } |
| 556 | |
| 557 | ConstantInt *RHS = 0; |
| 558 | ConstantRange LHSRange = LHSVal.getConstantRange(); |
| 559 | ConstantRange RHSRange(1); |
| 560 | const IntegerType *ResultTy = cast<IntegerType>(BBI->getType()); |
| 561 | if (isa<BinaryOperator>(BBI)) { |
Owen Anderson | 59b06dc | 2010-08-24 07:55:44 +0000 | [diff] [blame] | 562 | RHS = dyn_cast<ConstantInt>(BBI->getOperand(1)); |
| 563 | if (!RHS) { |
| 564 | Result.markOverdefined(); |
| 565 | return Result; |
| 566 | } |
| 567 | |
Owen Anderson | b81fd62 | 2010-08-18 21:11:37 +0000 | [diff] [blame] | 568 | RHSRange = ConstantRange(RHS->getValue(), RHS->getValue()+1); |
| 569 | } |
| 570 | |
| 571 | // NOTE: We're currently limited by the set of operations that ConstantRange |
| 572 | // can evaluate symbolically. Enhancing that set will allows us to analyze |
| 573 | // more definitions. |
| 574 | switch (BBI->getOpcode()) { |
| 575 | case Instruction::Add: |
| 576 | Result.markConstantRange(LHSRange.add(RHSRange)); |
| 577 | break; |
| 578 | case Instruction::Sub: |
| 579 | Result.markConstantRange(LHSRange.sub(RHSRange)); |
| 580 | break; |
| 581 | case Instruction::Mul: |
| 582 | Result.markConstantRange(LHSRange.multiply(RHSRange)); |
| 583 | break; |
| 584 | case Instruction::UDiv: |
| 585 | Result.markConstantRange(LHSRange.udiv(RHSRange)); |
| 586 | break; |
| 587 | case Instruction::Shl: |
| 588 | Result.markConstantRange(LHSRange.shl(RHSRange)); |
| 589 | break; |
| 590 | case Instruction::LShr: |
| 591 | Result.markConstantRange(LHSRange.lshr(RHSRange)); |
| 592 | break; |
| 593 | case Instruction::Trunc: |
| 594 | Result.markConstantRange(LHSRange.truncate(ResultTy->getBitWidth())); |
| 595 | break; |
| 596 | case Instruction::SExt: |
| 597 | Result.markConstantRange(LHSRange.signExtend(ResultTy->getBitWidth())); |
| 598 | break; |
| 599 | case Instruction::ZExt: |
| 600 | Result.markConstantRange(LHSRange.zeroExtend(ResultTy->getBitWidth())); |
| 601 | break; |
| 602 | case Instruction::BitCast: |
| 603 | Result.markConstantRange(LHSRange); |
| 604 | break; |
Nick Lewycky | 198381e | 2010-09-07 05:39:02 +0000 | [diff] [blame^] | 605 | case Instruction::And: |
| 606 | Result.markConstantRange(LHSRange.binaryAnd(RHSRange)); |
| 607 | break; |
| 608 | case Instruction::Or: |
| 609 | Result.markConstantRange(LHSRange.binaryOr(RHSRange)); |
| 610 | break; |
Owen Anderson | b81fd62 | 2010-08-18 21:11:37 +0000 | [diff] [blame] | 611 | |
| 612 | // Unhandled instructions are overdefined. |
| 613 | default: |
| 614 | DEBUG(dbgs() << " compute BB '" << BB->getName() |
| 615 | << "' - overdefined because inst def found.\n"); |
| 616 | Result.markOverdefined(); |
| 617 | break; |
| 618 | } |
| 619 | |
| 620 | return Cache[BB] = Result; |
Chris Lattner | 10f2d13 | 2009-11-11 00:22:30 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 623 | |
Chris Lattner | 800c47e | 2009-11-15 20:02:12 +0000 | [diff] [blame] | 624 | /// getEdgeValue - This method attempts to infer more complex |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 625 | LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) { |
Chris Lattner | 800c47e | 2009-11-15 20:02:12 +0000 | [diff] [blame] | 626 | // TODO: Handle more complex conditionals. If (v == 0 || v2 < 1) is false, we |
| 627 | // know that v != 0. |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 628 | if (BranchInst *BI = dyn_cast<BranchInst>(BBFrom->getTerminator())) { |
| 629 | // If this is a conditional branch and only one successor goes to BBTo, then |
| 630 | // we maybe able to infer something from the condition. |
| 631 | if (BI->isConditional() && |
| 632 | BI->getSuccessor(0) != BI->getSuccessor(1)) { |
| 633 | bool isTrueDest = BI->getSuccessor(0) == BBTo; |
| 634 | assert(BI->getSuccessor(!isTrueDest) == BBTo && |
| 635 | "BBTo isn't a successor of BBFrom"); |
| 636 | |
| 637 | // If V is the condition of the branch itself, then we know exactly what |
| 638 | // it is. |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 639 | if (BI->getCondition() == Val) |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 640 | return LVILatticeVal::get(ConstantInt::get( |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 641 | Type::getInt1Ty(Val->getContext()), isTrueDest)); |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 642 | |
| 643 | // If the condition of the branch is an equality comparison, we may be |
| 644 | // able to infer the value. |
Owen Anderson | 2d0f247 | 2010-08-11 04:24:25 +0000 | [diff] [blame] | 645 | ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition()); |
| 646 | if (ICI && ICI->getOperand(0) == Val && |
| 647 | isa<Constant>(ICI->getOperand(1))) { |
| 648 | if (ICI->isEquality()) { |
| 649 | // We know that V has the RHS constant if this is a true SETEQ or |
| 650 | // false SETNE. |
| 651 | if (isTrueDest == (ICI->getPredicate() == ICmpInst::ICMP_EQ)) |
| 652 | return LVILatticeVal::get(cast<Constant>(ICI->getOperand(1))); |
| 653 | return LVILatticeVal::getNot(cast<Constant>(ICI->getOperand(1))); |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 654 | } |
Owen Anderson | 2d0f247 | 2010-08-11 04:24:25 +0000 | [diff] [blame] | 655 | |
| 656 | if (ConstantInt *CI = dyn_cast<ConstantInt>(ICI->getOperand(1))) { |
| 657 | // Calculate the range of values that would satisfy the comparison. |
| 658 | ConstantRange CmpRange(CI->getValue(), CI->getValue()+1); |
| 659 | ConstantRange TrueValues = |
| 660 | ConstantRange::makeICmpRegion(ICI->getPredicate(), CmpRange); |
| 661 | |
| 662 | // If we're interested in the false dest, invert the condition. |
| 663 | if (!isTrueDest) TrueValues = TrueValues.inverse(); |
| 664 | |
| 665 | // Figure out the possible values of the query BEFORE this branch. |
| 666 | LVILatticeVal InBlock = getBlockValue(BBFrom); |
Owen Anderson | 660cab3 | 2010-08-27 17:12:29 +0000 | [diff] [blame] | 667 | if (!InBlock.isConstantRange()) |
| 668 | return LVILatticeVal::getRange(TrueValues); |
Owen Anderson | 2d0f247 | 2010-08-11 04:24:25 +0000 | [diff] [blame] | 669 | |
| 670 | // Find all potential values that satisfy both the input and output |
| 671 | // conditions. |
| 672 | ConstantRange PossibleValues = |
| 673 | TrueValues.intersectWith(InBlock.getConstantRange()); |
| 674 | |
| 675 | return LVILatticeVal::getRange(PossibleValues); |
| 676 | } |
| 677 | } |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 678 | } |
| 679 | } |
Chris Lattner | 800c47e | 2009-11-15 20:02:12 +0000 | [diff] [blame] | 680 | |
| 681 | // If the edge was formed by a switch on the value, then we may know exactly |
| 682 | // what it is. |
| 683 | if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) { |
Owen Anderson | dae90c6 | 2010-08-24 21:59:42 +0000 | [diff] [blame] | 684 | if (SI->getCondition() == Val) { |
Owen Anderson | 4caef60 | 2010-09-02 22:16:52 +0000 | [diff] [blame] | 685 | // We don't know anything in the default case. |
Owen Anderson | dae90c6 | 2010-08-24 21:59:42 +0000 | [diff] [blame] | 686 | if (SI->getDefaultDest() == BBTo) { |
Owen Anderson | dae90c6 | 2010-08-24 21:59:42 +0000 | [diff] [blame] | 687 | LVILatticeVal Result; |
Owen Anderson | 4caef60 | 2010-09-02 22:16:52 +0000 | [diff] [blame] | 688 | Result.markOverdefined(); |
Owen Anderson | dae90c6 | 2010-08-24 21:59:42 +0000 | [diff] [blame] | 689 | return Result; |
| 690 | } |
| 691 | |
Chris Lattner | 800c47e | 2009-11-15 20:02:12 +0000 | [diff] [blame] | 692 | // We only know something if there is exactly one value that goes from |
| 693 | // BBFrom to BBTo. |
| 694 | unsigned NumEdges = 0; |
| 695 | ConstantInt *EdgeVal = 0; |
| 696 | for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) { |
| 697 | if (SI->getSuccessor(i) != BBTo) continue; |
| 698 | if (NumEdges++) break; |
| 699 | EdgeVal = SI->getCaseValue(i); |
| 700 | } |
| 701 | assert(EdgeVal && "Missing successor?"); |
| 702 | if (NumEdges == 1) |
| 703 | return LVILatticeVal::get(EdgeVal); |
| 704 | } |
| 705 | } |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 706 | |
| 707 | // Otherwise see if the value is known in the block. |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 708 | return getBlockValue(BBFrom); |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 711 | |
| 712 | //===----------------------------------------------------------------------===// |
| 713 | // LazyValueInfoCache Impl |
| 714 | //===----------------------------------------------------------------------===// |
| 715 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 716 | LVILatticeVal LazyValueInfoCache::getValueInBlock(Value *V, BasicBlock *BB) { |
| 717 | // If already a constant, there is nothing to compute. |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 718 | if (Constant *VC = dyn_cast<Constant>(V)) |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 719 | return LVILatticeVal::get(VC); |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 720 | |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 721 | DEBUG(dbgs() << "LVI Getting block end value " << *V << " at '" |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 722 | << BB->getName() << "'\n"); |
| 723 | |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 724 | LVILatticeVal Result = LVIQuery(V, *this, |
Owen Anderson | c8ef750 | 2010-08-24 20:47:29 +0000 | [diff] [blame] | 725 | ValueCache[LVIValueHandle(V, this)], |
| 726 | OverDefinedCache).getBlockValue(BB); |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 727 | |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 728 | DEBUG(dbgs() << " Result = " << Result << "\n"); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 729 | return Result; |
| 730 | } |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 731 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 732 | LVILatticeVal LazyValueInfoCache:: |
| 733 | getValueOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB) { |
| 734 | // If already a constant, there is nothing to compute. |
| 735 | if (Constant *VC = dyn_cast<Constant>(V)) |
| 736 | return LVILatticeVal::get(VC); |
| 737 | |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 738 | DEBUG(dbgs() << "LVI Getting edge value " << *V << " from '" |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 739 | << FromBB->getName() << "' to '" << ToBB->getName() << "'\n"); |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 740 | |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 741 | LVILatticeVal Result = |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 742 | LVIQuery(V, *this, ValueCache[LVIValueHandle(V, this)], |
Owen Anderson | 81881bc | 2010-07-30 20:56:07 +0000 | [diff] [blame] | 743 | OverDefinedCache).getEdgeValue(FromBB, ToBB); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 744 | |
David Greene | 5d93a1f | 2009-12-23 20:43:58 +0000 | [diff] [blame] | 745 | DEBUG(dbgs() << " Result = " << Result << "\n"); |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 746 | |
| 747 | return Result; |
| 748 | } |
| 749 | |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 750 | void LazyValueInfoCache::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, |
| 751 | BasicBlock *NewSucc) { |
| 752 | // When an edge in the graph has been threaded, values that we could not |
| 753 | // determine a value for before (i.e. were marked overdefined) may be possible |
| 754 | // to solve now. We do NOT try to proactively update these values. Instead, |
| 755 | // we clear their entries from the cache, and allow lazy updating to recompute |
| 756 | // them when needed. |
| 757 | |
| 758 | // The updating process is fairly simple: we need to dropped cached info |
| 759 | // for all values that were marked overdefined in OldSucc, and for those same |
| 760 | // values in any successor of OldSucc (except NewSucc) in which they were |
| 761 | // also marked overdefined. |
| 762 | std::vector<BasicBlock*> worklist; |
| 763 | worklist.push_back(OldSucc); |
| 764 | |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 765 | DenseSet<Value*> ClearSet; |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 766 | for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 767 | I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ++I) { |
| 768 | if (I->first == OldSucc) |
| 769 | ClearSet.insert(I->second); |
| 770 | } |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 771 | |
| 772 | // Use a worklist to perform a depth-first search of OldSucc's successors. |
| 773 | // NOTE: We do not need a visited list since any blocks we have already |
| 774 | // visited will have had their overdefined markers cleared already, and we |
| 775 | // thus won't loop to their successors. |
| 776 | while (!worklist.empty()) { |
| 777 | BasicBlock *ToUpdate = worklist.back(); |
| 778 | worklist.pop_back(); |
| 779 | |
| 780 | // Skip blocks only accessible through NewSucc. |
| 781 | if (ToUpdate == NewSucc) continue; |
| 782 | |
| 783 | bool changed = false; |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 784 | for (DenseSet<Value*>::iterator I = ClearSet.begin(),E = ClearSet.end(); |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 785 | I != E; ++I) { |
| 786 | // If a value was marked overdefined in OldSucc, and is here too... |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 787 | std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator OI = |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 788 | OverDefinedCache.find(std::make_pair(ToUpdate, *I)); |
| 789 | if (OI == OverDefinedCache.end()) continue; |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 790 | |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 791 | // Remove it from the caches. |
Owen Anderson | 7f9cb74 | 2010-07-30 23:59:40 +0000 | [diff] [blame] | 792 | ValueCacheEntryTy &Entry = ValueCache[LVIValueHandle(*I, this)]; |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 793 | ValueCacheEntryTy::iterator CI = Entry.find(ToUpdate); |
| 794 | |
| 795 | assert(CI != Entry.end() && "Couldn't find entry to update?"); |
| 796 | Entry.erase(CI); |
| 797 | OverDefinedCache.erase(OI); |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 798 | |
Owen Anderson | 9a65dc9 | 2010-07-27 23:58:11 +0000 | [diff] [blame] | 799 | // If we removed anything, then we potentially need to update |
| 800 | // blocks successors too. |
| 801 | changed = true; |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | if (!changed) continue; |
| 805 | |
| 806 | worklist.insert(worklist.end(), succ_begin(ToUpdate), succ_end(ToUpdate)); |
| 807 | } |
| 808 | } |
| 809 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 810 | //===----------------------------------------------------------------------===// |
| 811 | // LazyValueInfo Impl |
| 812 | //===----------------------------------------------------------------------===// |
| 813 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 814 | /// getCache - This lazily constructs the LazyValueInfoCache. |
| 815 | static LazyValueInfoCache &getCache(void *&PImpl) { |
| 816 | if (!PImpl) |
| 817 | PImpl = new LazyValueInfoCache(); |
| 818 | return *static_cast<LazyValueInfoCache*>(PImpl); |
| 819 | } |
| 820 | |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 821 | bool LazyValueInfo::runOnFunction(Function &F) { |
| 822 | if (PImpl) |
| 823 | getCache(PImpl).clear(); |
| 824 | |
| 825 | TD = getAnalysisIfAvailable<TargetData>(); |
| 826 | // Fully lazy. |
| 827 | return false; |
| 828 | } |
| 829 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 830 | void LazyValueInfo::releaseMemory() { |
| 831 | // If the cache was allocated, free it. |
| 832 | if (PImpl) { |
| 833 | delete &getCache(PImpl); |
| 834 | PImpl = 0; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB) { |
| 839 | LVILatticeVal Result = getCache(PImpl).getValueInBlock(V, BB); |
| 840 | |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 841 | if (Result.isConstant()) |
| 842 | return Result.getConstant(); |
Owen Anderson | ee61fcf | 2010-08-27 23:29:38 +0000 | [diff] [blame] | 843 | else if (Result.isConstantRange()) { |
| 844 | ConstantRange CR = Result.getConstantRange(); |
| 845 | if (const APInt *SingleVal = CR.getSingleElement()) |
| 846 | return ConstantInt::get(V->getContext(), *SingleVal); |
| 847 | } |
Chris Lattner | 1697652 | 2009-11-11 22:48:44 +0000 | [diff] [blame] | 848 | return 0; |
| 849 | } |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 850 | |
Chris Lattner | 38392bb | 2009-11-12 01:29:10 +0000 | [diff] [blame] | 851 | /// getConstantOnEdge - Determine whether the specified value is known to be a |
| 852 | /// constant on the specified edge. Return null if not. |
| 853 | Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB, |
| 854 | BasicBlock *ToBB) { |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 855 | LVILatticeVal Result = getCache(PImpl).getValueOnEdge(V, FromBB, ToBB); |
Chris Lattner | 38392bb | 2009-11-12 01:29:10 +0000 | [diff] [blame] | 856 | |
| 857 | if (Result.isConstant()) |
| 858 | return Result.getConstant(); |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 859 | else if (Result.isConstantRange()) { |
| 860 | ConstantRange CR = Result.getConstantRange(); |
| 861 | if (const APInt *SingleVal = CR.getSingleElement()) |
| 862 | return ConstantInt::get(V->getContext(), *SingleVal); |
| 863 | } |
Chris Lattner | 38392bb | 2009-11-12 01:29:10 +0000 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 867 | /// getPredicateOnEdge - Determine whether the specified value comparison |
| 868 | /// with a constant is known to be true or false on the specified CFG edge. |
| 869 | /// Pred is a CmpInst predicate. |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 870 | LazyValueInfo::Tristate |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 871 | LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, |
| 872 | BasicBlock *FromBB, BasicBlock *ToBB) { |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 873 | LVILatticeVal Result = getCache(PImpl).getValueOnEdge(V, FromBB, ToBB); |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 874 | |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 875 | // If we know the value is a constant, evaluate the conditional. |
| 876 | Constant *Res = 0; |
| 877 | if (Result.isConstant()) { |
| 878 | Res = ConstantFoldCompareInstOperands(Pred, Result.getConstant(), C, TD); |
| 879 | if (ConstantInt *ResCI = dyn_cast_or_null<ConstantInt>(Res)) |
| 880 | return ResCI->isZero() ? False : True; |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 881 | return Unknown; |
| 882 | } |
| 883 | |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 884 | if (Result.isConstantRange()) { |
Owen Anderson | 59b06dc | 2010-08-24 07:55:44 +0000 | [diff] [blame] | 885 | ConstantInt *CI = dyn_cast<ConstantInt>(C); |
| 886 | if (!CI) return Unknown; |
| 887 | |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 888 | ConstantRange CR = Result.getConstantRange(); |
| 889 | if (Pred == ICmpInst::ICMP_EQ) { |
| 890 | if (!CR.contains(CI->getValue())) |
| 891 | return False; |
| 892 | |
| 893 | if (CR.isSingleElement() && CR.contains(CI->getValue())) |
| 894 | return True; |
| 895 | } else if (Pred == ICmpInst::ICMP_NE) { |
| 896 | if (!CR.contains(CI->getValue())) |
| 897 | return True; |
| 898 | |
| 899 | if (CR.isSingleElement() && CR.contains(CI->getValue())) |
| 900 | return False; |
| 901 | } |
| 902 | |
| 903 | // Handle more complex predicates. |
| 904 | ConstantRange RHS(CI->getValue(), CI->getValue()+1); |
| 905 | ConstantRange TrueValues = ConstantRange::makeICmpRegion(Pred, RHS); |
| 906 | if (CR.intersectWith(TrueValues).isEmptySet()) |
| 907 | return False; |
Owen Anderson | 625051b | 2010-08-10 23:20:01 +0000 | [diff] [blame] | 908 | else if (TrueValues.contains(CR)) |
Owen Anderson | 9f01406 | 2010-08-10 20:03:09 +0000 | [diff] [blame] | 909 | return True; |
| 910 | |
| 911 | return Unknown; |
| 912 | } |
| 913 | |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 914 | if (Result.isNotConstant()) { |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 915 | // If this is an equality comparison, we can try to fold it knowing that |
| 916 | // "V != C1". |
| 917 | if (Pred == ICmpInst::ICMP_EQ) { |
| 918 | // !C1 == C -> false iff C1 == C. |
| 919 | Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, |
| 920 | Result.getNotConstant(), C, TD); |
| 921 | if (Res->isNullValue()) |
| 922 | return False; |
| 923 | } else if (Pred == ICmpInst::ICMP_NE) { |
| 924 | // !C1 != C -> true iff C1 == C. |
Chris Lattner | 5553a3a | 2009-11-15 20:01:24 +0000 | [diff] [blame] | 925 | Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 926 | Result.getNotConstant(), C, TD); |
| 927 | if (Res->isNullValue()) |
| 928 | return True; |
| 929 | } |
Chris Lattner | 2c5adf8 | 2009-11-15 19:59:49 +0000 | [diff] [blame] | 930 | return Unknown; |
Chris Lattner | b52675b | 2009-11-12 04:36:58 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Chris Lattner | cc4d3b2 | 2009-11-11 02:08:33 +0000 | [diff] [blame] | 933 | return Unknown; |
| 934 | } |
| 935 | |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 936 | void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, |
| 937 | BasicBlock* NewSucc) { |
Owen Anderson | 00ac77e | 2010-08-18 18:39:01 +0000 | [diff] [blame] | 938 | if (PImpl) getCache(PImpl).threadEdge(PredBB, OldSucc, NewSucc); |
| 939 | } |
| 940 | |
| 941 | void LazyValueInfo::eraseBlock(BasicBlock *BB) { |
| 942 | if (PImpl) getCache(PImpl).eraseBlock(BB); |
Owen Anderson | cfa7fb6 | 2010-07-26 18:48:03 +0000 | [diff] [blame] | 943 | } |