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//===----------------------------------------------------------------------===//
--- 10 unchanged lines hidden (view full) ---
19#include "llvm/Type.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Analysis/Dominators.h"
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 "llvm/Support/CommandLine.h"
28#include <algorithm>
29using namespace llvm;
30
31char IVUsers::ID = 0;
32static RegisterPass<IVUsers>
33X("iv-users", "Induction Variable Users", false, true);
34
35static cl::opt<bool>
36SimplifyIVUsers("simplify-iv-users", cl::Hidden, cl::init(false),
37 cl::desc("Restrict IV Users to loop-invariant strides"));
38
39Pass *llvm::createIVUsersPass() {
40 return new IVUsers();
41}
42
43/// containsAddRecFromDifferentLoop - Determine whether expression S involves a
44/// subexpression that is an AddRec from a loop other than L. An outer loop
45/// of L is OK, but not an inner loop nor a disjoint loop.
46static bool containsAddRecFromDifferentLoop(const SCEV *S, Loop *L) {
--- 161 unchanged lines hidden (view full) ---
208 // Get the start and stride for this expression.
209 Loop *UseLoop = LI->getLoopFor(I->getParent());
210 const SCEV *Start = SE->getIntegerSCEV(0, ISE->getType());
211 const SCEV *Stride = Start;
212
213 if (!getSCEVStartAndStride(ISE, L, UseLoop, Start, Stride, SE, DT))
214 return false; // Non-reducible symbolic expression, bail out.
215
216 // Keep things simple. Don't touch loop-variant strides.
217 if (SimplifyIVUsers && !Stride->isLoopInvariant(L)
218 && L->contains(I->getParent()))
219 return false;
220
221 SmallPtrSet<Instruction *, 4> UniqueUsers;
222 for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
223 UI != E; ++UI) {
224 Instruction *User = cast<Instruction>(*UI);
225 if (!UniqueUsers.insert(User))
226 continue;
227
228 // Do not infinitely recurse on PHI nodes.
--- 157 unchanged lines hidden ---
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//===----------------------------------------------------------------------===//
--- 10 unchanged lines hidden (view full) ---
19#include "llvm/Type.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Analysis/Dominators.h"
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 "llvm/Support/CommandLine.h"
28#include <algorithm>
29using namespace llvm;
30
31char IVUsers::ID = 0;
32static RegisterPass<IVUsers>
33X("iv-users", "Induction Variable Users", false, true);
34
35static cl::opt<bool>
36SimplifyIVUsers("simplify-iv-users", cl::Hidden, cl::init(false),
37 cl::desc("Restrict IV Users to loop-invariant strides"));
38
39Pass *llvm::createIVUsersPass() {
40 return new IVUsers();
41}
42
43/// containsAddRecFromDifferentLoop - Determine whether expression S involves a
44/// subexpression that is an AddRec from a loop other than L. An outer loop
45/// of L is OK, but not an inner loop nor a disjoint loop.
46static bool containsAddRecFromDifferentLoop(const SCEV *S, Loop *L) {
--- 161 unchanged lines hidden (view full) ---
208 // Get the start and stride for this expression.
209 Loop *UseLoop = LI->getLoopFor(I->getParent());
210 const SCEV *Start = SE->getIntegerSCEV(0, ISE->getType());
211 const SCEV *Stride = Start;
212
213 if (!getSCEVStartAndStride(ISE, L, UseLoop, Start, Stride, SE, DT))
214 return false; // Non-reducible symbolic expression, bail out.
215
216 // Keep things simple. Don't touch loop-variant strides.
217 if (SimplifyIVUsers && !Stride->isLoopInvariant(L)
218 && L->contains(I->getParent()))
219 return false;
220
221 SmallPtrSet<Instruction *, 4> UniqueUsers;
222 for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
223 UI != E; ++UI) {
224 Instruction *User = cast<Instruction>(*UI);
225 if (!UniqueUsers.insert(User))
226 continue;
227
228 // Do not infinitely recurse on PHI nodes.
--- 157 unchanged lines hidden ---