Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 1 | //===- IVUsers.cpp - Induction Variable Users -------------------*- C++ -*-===// |
| 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 implements bookkeeping for "interesting" users of expressions |
| 11 | // computed from induction variables. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "iv-users" |
| 16 | #include "llvm/Analysis/IVUsers.h" |
| 17 | #include "llvm/Constants.h" |
| 18 | #include "llvm/Instructions.h" |
| 19 | #include "llvm/Type.h" |
| 20 | #include "llvm/DerivedTypes.h" |
| 21 | #include "llvm/Analysis/Dominators.h" |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/LoopPass.h" |
| 23 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
| 24 | #include "llvm/ADT/STLExtras.h" |
| 25 | #include "llvm/Support/Debug.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
| 27 | #include <algorithm> |
| 28 | using namespace llvm; |
| 29 | |
| 30 | char IVUsers::ID = 0; |
| 31 | static RegisterPass<IVUsers> |
| 32 | X("iv-users", "Induction Variable Users", false, true); |
| 33 | |
| 34 | Pass *llvm::createIVUsersPass() { |
| 35 | return new IVUsers(); |
| 36 | } |
| 37 | |
| 38 | /// containsAddRecFromDifferentLoop - Determine whether expression S involves a |
| 39 | /// subexpression that is an AddRec from a loop other than L. An outer loop |
| 40 | /// of L is OK, but not an inner loop nor a disjoint loop. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 41 | static bool containsAddRecFromDifferentLoop(const SCEV *S, Loop *L) { |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 42 | // This is very common, put it first. |
| 43 | if (isa<SCEVConstant>(S)) |
| 44 | return false; |
| 45 | if (const SCEVCommutativeExpr *AE = dyn_cast<SCEVCommutativeExpr>(S)) { |
| 46 | for (unsigned int i=0; i< AE->getNumOperands(); i++) |
| 47 | if (containsAddRecFromDifferentLoop(AE->getOperand(i), L)) |
| 48 | return true; |
| 49 | return false; |
| 50 | } |
| 51 | if (const SCEVAddRecExpr *AE = dyn_cast<SCEVAddRecExpr>(S)) { |
| 52 | if (const Loop *newLoop = AE->getLoop()) { |
| 53 | if (newLoop == L) |
| 54 | return false; |
| 55 | // if newLoop is an outer loop of L, this is OK. |
Dan Gohman | c8d76d5 | 2009-07-13 21:51:15 +0000 | [diff] [blame] | 56 | if (!LoopInfo::isNotAlreadyContainedIn(L, newLoop)) |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 57 | return false; |
| 58 | } |
| 59 | return true; |
| 60 | } |
| 61 | if (const SCEVUDivExpr *DE = dyn_cast<SCEVUDivExpr>(S)) |
| 62 | return containsAddRecFromDifferentLoop(DE->getLHS(), L) || |
| 63 | containsAddRecFromDifferentLoop(DE->getRHS(), L); |
| 64 | #if 0 |
| 65 | // SCEVSDivExpr has been backed out temporarily, but will be back; we'll |
| 66 | // need this when it is. |
| 67 | if (const SCEVSDivExpr *DE = dyn_cast<SCEVSDivExpr>(S)) |
| 68 | return containsAddRecFromDifferentLoop(DE->getLHS(), L) || |
| 69 | containsAddRecFromDifferentLoop(DE->getRHS(), L); |
| 70 | #endif |
| 71 | if (const SCEVCastExpr *CE = dyn_cast<SCEVCastExpr>(S)) |
| 72 | return containsAddRecFromDifferentLoop(CE->getOperand(), L); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /// getSCEVStartAndStride - Compute the start and stride of this expression, |
| 77 | /// returning false if the expression is not a start/stride pair, or true if it |
| 78 | /// is. The stride must be a loop invariant expression, but the start may be |
| 79 | /// a mix of loop invariant and loop variant expressions. The start cannot, |
| 80 | /// however, contain an AddRec from a different loop, unless that loop is an |
| 81 | /// outer loop of the current loop. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 82 | static bool getSCEVStartAndStride(const SCEV *&SH, Loop *L, Loop *UseLoop, |
| 83 | const SCEV *&Start, const SCEV *&Stride, |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 84 | ScalarEvolution *SE, DominatorTree *DT) { |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 85 | const SCEV *TheAddRec = Start; // Initialize to zero. |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 86 | |
| 87 | // If the outer level is an AddExpr, the operands are all start values except |
| 88 | // for a nested AddRecExpr. |
| 89 | if (const SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(SH)) { |
| 90 | for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i) |
| 91 | if (const SCEVAddRecExpr *AddRec = |
| 92 | dyn_cast<SCEVAddRecExpr>(AE->getOperand(i))) { |
| 93 | if (AddRec->getLoop() == L) |
| 94 | TheAddRec = SE->getAddExpr(AddRec, TheAddRec); |
| 95 | else |
| 96 | return false; // Nested IV of some sort? |
| 97 | } else { |
| 98 | Start = SE->getAddExpr(Start, AE->getOperand(i)); |
| 99 | } |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 100 | } else if (isa<SCEVAddRecExpr>(SH)) { |
| 101 | TheAddRec = SH; |
| 102 | } else { |
| 103 | return false; // not analyzable. |
| 104 | } |
| 105 | |
| 106 | const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(TheAddRec); |
| 107 | if (!AddRec || AddRec->getLoop() != L) return false; |
| 108 | |
| 109 | // Use getSCEVAtScope to attempt to simplify other loops out of |
| 110 | // the picture. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 111 | const SCEV *AddRecStart = AddRec->getStart(); |
Dan Gohman | 743e41e | 2009-06-15 18:38:59 +0000 | [diff] [blame] | 112 | AddRecStart = SE->getSCEVAtScope(AddRecStart, UseLoop); |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 113 | const SCEV *AddRecStride = AddRec->getStepRecurrence(*SE); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 114 | |
| 115 | // FIXME: If Start contains an SCEVAddRecExpr from a different loop, other |
| 116 | // than an outer loop of the current loop, reject it. LSR has no concept of |
| 117 | // operating on more than one loop at a time so don't confuse it with such |
| 118 | // expressions. |
| 119 | if (containsAddRecFromDifferentLoop(AddRecStart, L)) |
| 120 | return false; |
| 121 | |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 122 | Start = SE->getAddExpr(Start, AddRecStart); |
| 123 | |
Dan Gohman | 00cb673 | 2009-09-27 15:30:00 +0000 | [diff] [blame] | 124 | // If stride is an instruction, make sure it properly dominates the header. |
Dan Gohman | 743e41e | 2009-06-15 18:38:59 +0000 | [diff] [blame] | 125 | // Otherwise we could end up with a use before def situation. |
| 126 | if (!isa<SCEVConstant>(AddRecStride)) { |
Dan Gohman | 00cb673 | 2009-09-27 15:30:00 +0000 | [diff] [blame] | 127 | BasicBlock *Header = L->getHeader(); |
| 128 | if (!AddRecStride->properlyDominates(Header, DT)) |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 129 | return false; |
| 130 | |
Daniel Dunbar | ce63ffb | 2009-07-25 00:23:56 +0000 | [diff] [blame] | 131 | DEBUG(errs() << "[" << L->getHeader()->getName() |
| 132 | << "] Variable stride: " << *AddRec << "\n"); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Dan Gohman | 743e41e | 2009-06-15 18:38:59 +0000 | [diff] [blame] | 135 | Stride = AddRecStride; |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 136 | return true; |
| 137 | } |
| 138 | |
| 139 | /// IVUseShouldUsePostIncValue - We have discovered a "User" of an IV expression |
| 140 | /// and now we need to decide whether the user should use the preinc or post-inc |
| 141 | /// value. If this user should use the post-inc version of the IV, return true. |
| 142 | /// |
| 143 | /// Choosing wrong here can break dominance properties (if we choose to use the |
| 144 | /// post-inc value when we cannot) or it can end up adding extra live-ranges to |
| 145 | /// the loop, resulting in reg-reg copies (if we use the pre-inc value when we |
| 146 | /// should use the post-inc value). |
| 147 | static bool IVUseShouldUsePostIncValue(Instruction *User, Instruction *IV, |
| 148 | Loop *L, LoopInfo *LI, DominatorTree *DT, |
| 149 | Pass *P) { |
| 150 | // If the user is in the loop, use the preinc value. |
| 151 | if (L->contains(User->getParent())) return false; |
| 152 | |
| 153 | BasicBlock *LatchBlock = L->getLoopLatch(); |
Dan Gohman | a6a4aae | 2009-11-05 19:41:37 +0000 | [diff] [blame] | 154 | if (!LatchBlock) |
| 155 | return false; |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 156 | |
| 157 | // Ok, the user is outside of the loop. If it is dominated by the latch |
| 158 | // block, use the post-inc value. |
| 159 | if (DT->dominates(LatchBlock, User->getParent())) |
| 160 | return true; |
| 161 | |
| 162 | // There is one case we have to be careful of: PHI nodes. These little guys |
| 163 | // can live in blocks that are not dominated by the latch block, but (since |
| 164 | // their uses occur in the predecessor block, not the block the PHI lives in) |
| 165 | // should still use the post-inc value. Check for this case now. |
| 166 | PHINode *PN = dyn_cast<PHINode>(User); |
| 167 | if (!PN) return false; // not a phi, not dominated by latch block. |
| 168 | |
| 169 | // Look at all of the uses of IV by the PHI node. If any use corresponds to |
| 170 | // a block that is not dominated by the latch block, give up and use the |
| 171 | // preincremented value. |
| 172 | unsigned NumUses = 0; |
| 173 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 174 | if (PN->getIncomingValue(i) == IV) { |
| 175 | ++NumUses; |
| 176 | if (!DT->dominates(LatchBlock, PN->getIncomingBlock(i))) |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | // Okay, all uses of IV by PN are in predecessor blocks that really are |
| 181 | // dominated by the latch block. Use the post-incremented value. |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | /// AddUsersIfInteresting - Inspect the specified instruction. If it is a |
| 186 | /// reducible SCEV, recursively add its users to the IVUsesByStride set and |
| 187 | /// return true. Otherwise, return false. |
| 188 | bool IVUsers::AddUsersIfInteresting(Instruction *I) { |
| 189 | if (!SE->isSCEVable(I->getType())) |
| 190 | return false; // Void and FP expressions cannot be reduced. |
| 191 | |
| 192 | // LSR is not APInt clean, do not touch integers bigger than 64-bits. |
| 193 | if (SE->getTypeSizeInBits(I->getType()) > 64) |
| 194 | return false; |
| 195 | |
| 196 | if (!Processed.insert(I)) |
| 197 | return true; // Instruction already handled. |
| 198 | |
| 199 | // Get the symbolic expression for this instruction. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 200 | const SCEV *ISE = SE->getSCEV(I); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 201 | if (isa<SCEVCouldNotCompute>(ISE)) return false; |
| 202 | |
| 203 | // Get the start and stride for this expression. |
| 204 | Loop *UseLoop = LI->getLoopFor(I->getParent()); |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 205 | const SCEV *Start = SE->getIntegerSCEV(0, ISE->getType()); |
| 206 | const SCEV *Stride = Start; |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 207 | |
Dan Gohman | 4e8a985 | 2009-06-18 16:54:06 +0000 | [diff] [blame] | 208 | if (!getSCEVStartAndStride(ISE, L, UseLoop, Start, Stride, SE, DT)) |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 209 | return false; // Non-reducible symbolic expression, bail out. |
| 210 | |
Jim Grosbach | 97200e4 | 2009-11-19 02:05:44 +0000 | [diff] [blame] | 211 | // Keep things simple. Don't touch loop-variant strides. |
Jim Grosbach | dbc3577 | 2009-11-23 23:25:54 +0000 | [diff] [blame] | 212 | if (!Stride->isLoopInvariant(L) && L->contains(I->getParent())) |
Jim Grosbach | 97200e4 | 2009-11-19 02:05:44 +0000 | [diff] [blame] | 213 | return false; |
| 214 | |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 215 | SmallPtrSet<Instruction *, 4> UniqueUsers; |
| 216 | for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); |
| 217 | UI != E; ++UI) { |
| 218 | Instruction *User = cast<Instruction>(*UI); |
| 219 | if (!UniqueUsers.insert(User)) |
| 220 | continue; |
| 221 | |
| 222 | // Do not infinitely recurse on PHI nodes. |
| 223 | if (isa<PHINode>(User) && Processed.count(User)) |
| 224 | continue; |
| 225 | |
| 226 | // Descend recursively, but not into PHI nodes outside the current loop. |
| 227 | // It's important to see the entire expression outside the loop to get |
| 228 | // choices that depend on addressing mode use right, although we won't |
| 229 | // consider references ouside the loop in all cases. |
| 230 | // If User is already in Processed, we don't want to recurse into it again, |
| 231 | // but do want to record a second reference in the same instruction. |
| 232 | bool AddUserToIVUsers = false; |
| 233 | if (LI->getLoopFor(User->getParent()) != L) { |
| 234 | if (isa<PHINode>(User) || Processed.count(User) || |
| 235 | !AddUsersIfInteresting(User)) { |
Chris Lattner | bdff548 | 2009-08-23 04:37:46 +0000 | [diff] [blame] | 236 | DEBUG(errs() << "FOUND USER in other loop: " << *User << '\n' |
| 237 | << " OF SCEV: " << *ISE << '\n'); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 238 | AddUserToIVUsers = true; |
| 239 | } |
| 240 | } else if (Processed.count(User) || |
| 241 | !AddUsersIfInteresting(User)) { |
Chris Lattner | bdff548 | 2009-08-23 04:37:46 +0000 | [diff] [blame] | 242 | DEBUG(errs() << "FOUND USER: " << *User << '\n' |
| 243 | << " OF SCEV: " << *ISE << '\n'); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 244 | AddUserToIVUsers = true; |
| 245 | } |
| 246 | |
| 247 | if (AddUserToIVUsers) { |
| 248 | IVUsersOfOneStride *StrideUses = IVUsesByStride[Stride]; |
| 249 | if (!StrideUses) { // First occurrence of this stride? |
| 250 | StrideOrder.push_back(Stride); |
| 251 | StrideUses = new IVUsersOfOneStride(Stride); |
| 252 | IVUses.push_back(StrideUses); |
| 253 | IVUsesByStride[Stride] = StrideUses; |
| 254 | } |
| 255 | |
| 256 | // Okay, we found a user that we cannot reduce. Analyze the instruction |
| 257 | // and decide what to do with it. If we are a use inside of the loop, use |
| 258 | // the value before incrementation, otherwise use it after incrementation. |
| 259 | if (IVUseShouldUsePostIncValue(User, I, L, LI, DT, this)) { |
| 260 | // The value used will be incremented by the stride more than we are |
| 261 | // expecting, so subtract this off. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 262 | const SCEV *NewStart = SE->getMinusSCEV(Start, Stride); |
Dan Gohman | 4e8a985 | 2009-06-18 16:54:06 +0000 | [diff] [blame] | 263 | StrideUses->addUser(NewStart, User, I); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 264 | StrideUses->Users.back().setIsUseOfPostIncrementedValue(true); |
Chris Lattner | bbbfa99 | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 265 | DEBUG(errs() << " USING POSTINC SCEV, START=" << *NewStart<< "\n"); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 266 | } else { |
Dan Gohman | 4e8a985 | 2009-06-18 16:54:06 +0000 | [diff] [blame] | 267 | StrideUses->addUser(Start, User, I); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
| 271 | return true; |
| 272 | } |
| 273 | |
Evan Cheng | 586f69a | 2009-11-12 07:35:05 +0000 | [diff] [blame] | 274 | void IVUsers::AddUser(const SCEV *Stride, const SCEV *Offset, |
| 275 | Instruction *User, Value *Operand) { |
| 276 | IVUsersOfOneStride *StrideUses = IVUsesByStride[Stride]; |
| 277 | if (!StrideUses) { // First occurrence of this stride? |
| 278 | StrideOrder.push_back(Stride); |
| 279 | StrideUses = new IVUsersOfOneStride(Stride); |
| 280 | IVUses.push_back(StrideUses); |
| 281 | IVUsesByStride[Stride] = StrideUses; |
| 282 | } |
| 283 | IVUsesByStride[Stride]->addUser(Offset, User, Operand); |
| 284 | } |
| 285 | |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 286 | IVUsers::IVUsers() |
| 287 | : LoopPass(&ID) { |
| 288 | } |
| 289 | |
| 290 | void IVUsers::getAnalysisUsage(AnalysisUsage &AU) const { |
| 291 | AU.addRequired<LoopInfo>(); |
| 292 | AU.addRequired<DominatorTree>(); |
| 293 | AU.addRequired<ScalarEvolution>(); |
| 294 | AU.setPreservesAll(); |
| 295 | } |
| 296 | |
| 297 | bool IVUsers::runOnLoop(Loop *l, LPPassManager &LPM) { |
| 298 | |
| 299 | L = l; |
| 300 | LI = &getAnalysis<LoopInfo>(); |
| 301 | DT = &getAnalysis<DominatorTree>(); |
| 302 | SE = &getAnalysis<ScalarEvolution>(); |
| 303 | |
| 304 | // Find all uses of induction variables in this loop, and categorize |
| 305 | // them by stride. Start by finding all of the PHI nodes in the header for |
| 306 | // this loop. If they are induction variables, inspect their uses. |
| 307 | for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) |
| 308 | AddUsersIfInteresting(I); |
| 309 | |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | /// getReplacementExpr - Return a SCEV expression which computes the |
| 314 | /// value of the OperandValToReplace of the given IVStrideUse. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 315 | const SCEV *IVUsers::getReplacementExpr(const IVStrideUse &U) const { |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 316 | // Start with zero. |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 317 | const SCEV *RetVal = SE->getIntegerSCEV(0, U.getParent()->Stride->getType()); |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 318 | // Create the basic add recurrence. |
| 319 | RetVal = SE->getAddRecExpr(RetVal, U.getParent()->Stride, L); |
| 320 | // Add the offset in a separate step, because it may be loop-variant. |
| 321 | RetVal = SE->getAddExpr(RetVal, U.getOffset()); |
| 322 | // For uses of post-incremented values, add an extra stride to compute |
| 323 | // the actual replacement value. |
| 324 | if (U.isUseOfPostIncrementedValue()) |
| 325 | RetVal = SE->getAddExpr(RetVal, U.getParent()->Stride); |
| 326 | // Evaluate the expression out of the loop, if possible. |
| 327 | if (!L->contains(U.getUser()->getParent())) { |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 328 | const SCEV *ExitVal = SE->getSCEVAtScope(RetVal, L->getParentLoop()); |
Dan Gohman | 743e41e | 2009-06-15 18:38:59 +0000 | [diff] [blame] | 329 | if (ExitVal->isLoopInvariant(L)) |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 330 | RetVal = ExitVal; |
| 331 | } |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 332 | return RetVal; |
| 333 | } |
| 334 | |
| 335 | void IVUsers::print(raw_ostream &OS, const Module *M) const { |
| 336 | OS << "IV Users for loop "; |
| 337 | WriteAsOperand(OS, L->getHeader(), false); |
| 338 | if (SE->hasLoopInvariantBackedgeTakenCount(L)) { |
| 339 | OS << " with backedge-taken count " |
| 340 | << *SE->getBackedgeTakenCount(L); |
| 341 | } |
| 342 | OS << ":\n"; |
| 343 | |
| 344 | for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; ++Stride) { |
Dan Gohman | 0bba49c | 2009-07-07 17:06:11 +0000 | [diff] [blame] | 345 | std::map<const SCEV *, IVUsersOfOneStride*>::const_iterator SI = |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 346 | IVUsesByStride.find(StrideOrder[Stride]); |
| 347 | assert(SI != IVUsesByStride.end() && "Stride doesn't exist!"); |
| 348 | OS << " Stride " << *SI->first->getType() << " " << *SI->first << ":\n"; |
| 349 | |
| 350 | for (ilist<IVStrideUse>::const_iterator UI = SI->second->Users.begin(), |
| 351 | E = SI->second->Users.end(); UI != E; ++UI) { |
| 352 | OS << " "; |
| 353 | WriteAsOperand(OS, UI->getOperandValToReplace(), false); |
| 354 | OS << " = "; |
| 355 | OS << *getReplacementExpr(*UI); |
| 356 | if (UI->isUseOfPostIncrementedValue()) |
| 357 | OS << " (post-inc)"; |
| 358 | OS << " in "; |
| 359 | UI->getUser()->print(OS); |
Dan Gohman | d9ef1a8 | 2009-07-14 00:32:49 +0000 | [diff] [blame] | 360 | OS << '\n'; |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
Dan Gohman | 81db61a | 2009-05-12 02:17:14 +0000 | [diff] [blame] | 365 | void IVUsers::dump() const { |
| 366 | print(errs()); |
| 367 | } |
| 368 | |
| 369 | void IVUsers::releaseMemory() { |
| 370 | IVUsesByStride.clear(); |
| 371 | StrideOrder.clear(); |
| 372 | Processed.clear(); |
| 373 | } |
| 374 | |
| 375 | void IVStrideUse::deleted() { |
| 376 | // Remove this user from the list. |
| 377 | Parent->Users.erase(this); |
| 378 | // this now dangles! |
| 379 | } |