15 #define DEBUG_TYPE "iv-users"
35 "Induction Variable Users",
false,
true)
55 if (AR->getLoop() == L)
56 return AR->isAffine() ||
67 if (
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
68 bool AnyInterestingYet =
false;
72 if (AnyInterestingYet)
74 AnyInterestingYet =
true;
76 return AnyInterestingYet;
88 Loop *NearestLoop = 0;
93 if (DomLoop && DomLoop->
getHeader() == DomBB) {
98 if (SimpleLoopNests.
count(DomLoop))
103 NearestLoop = DomLoop;
107 SimpleLoopNests.
insert(NearestLoop);
118 if (!Processed.insert(I))
149 if (!UniqueUsers.
insert(User))
153 if (isa<PHINode>(User) && Processed.count(User))
161 unsigned OperandNo = UI.getOperandNo();
163 UseBB =
PHI->getIncomingBlock(ValNo);
174 bool AddUserToIVUsers =
false;
176 if (isa<PHINode>(User) || Processed.count(User) ||
178 DEBUG(
dbgs() <<
"FOUND USER in other loop: " << *User <<
'\n'
179 <<
" OF SCEV: " << *ISE <<
'\n');
180 AddUserToIVUsers =
true;
182 }
else if (Processed.count(User) || !
AddUsersImpl(User, SimpleLoopNests)) {
183 DEBUG(
dbgs() <<
"FOUND USER: " << *User <<
'\n'
184 <<
" OF SCEV: " << *ISE <<
'\n');
185 AddUserToIVUsers =
true;
188 if (AddUserToIVUsers) {
200 dbgs() <<
" NORMALIZED TO: " << *ISE <<
'\n');
216 IVUses.push_back(
new IVStrideUse(
this, User, Operand));
217 return IVUses.back();
235 LI = &getAnalysis<LoopInfo>();
236 DT = &getAnalysis<DominatorTree>();
237 SE = &getAnalysis<ScalarEvolution>();
238 TD = getAnalysisIfAvailable<DataLayout>();
250 OS <<
"IV Users for loop ";
252 if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
253 OS <<
" with backedge-taken count "
254 << *SE->getBackedgeTakenCount(L);
259 E = IVUses.end(); UI != E; ++UI) {
264 I = UI->PostIncLoops.begin(),
265 E = UI->PostIncLoops.end();
I != E; ++
I) {
266 OS <<
" (post-inc with loop ";
271 UI->getUser()->print(OS);
276 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
282 void IVUsers::releaseMemory() {
304 if (AR->getLoop() == L)
309 if (
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
322 return AR->getStepRecurrence(*SE);
330 void IVStrideUse::deleted() {
332 Parent->Processed.erase(this->
getUser());
333 Parent->IVUses.erase(
this);
DomTreeNode * getNode(BasicBlock *BB) const
const SCEV * getExpr(const IVStrideUse &IU) const
getExpr - Return the expression for the use.
static PassRegistry * getPassRegistry()
const PostIncLoopSet & getPostIncLoops() const
const SCEV * TransformForPostIncUse(TransformKind Kind, const SCEV *S, Instruction *User, Value *OperandValToReplace, PostIncLoopSet &Loops, ScalarEvolution &SE, DominatorTree &DT)
The main container class for the LLVM Intermediate Representation.
Pass * createIVUsersPass()
bool AddUsersImpl(Instruction *I, SmallPtrSet< Loop *, 16 > &SimpleLoopNests)
iv Induction Variable Users
BlockT * getHeader() const
LoopInfoBase< BlockT, LoopT > * LI
bool AddUsersIfInteresting(Instruction *I)
DomTreeNodeBase< NodeT > * getIDom() const
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
void initializeIVUsersPass(PassRegistry &)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const SCEV * getStride(const IVStrideUse &IU, const Loop *L) const
const SCEV *const * op_iterator
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
static bool isSimplifiedLoopNest(BasicBlock *BB, const DominatorTree *DT, const LoopInfo *LI, SmallPtrSet< Loop *, 16 > &SimpleLoopNests)
uint64_t getTypeSizeInBits(Type *Ty) const
ID
LLVM Calling Convention Representation.
bool isLoopSimplifyForm() const
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
Instruction * getUser() const
getUser - Return the user instruction for this use.
Loop * getLoopFor(const BasicBlock *BB) const
bool isSCEVable(Type *Ty) const
LLVM Basic Block Representation.
Normalize - Normalize according to the given loops.
const SCEV * getReplacementExpr(const IVStrideUse &IU) const
const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
bool contains(const LoopT *L) const
static unsigned getIncomingValueNumForOperand(unsigned i)
static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L, ScalarEvolution *SE, LoopInfo *LI)
iv Induction Variable false
bool isSafeToSpeculativelyExecute(const Value *V, const DataLayout *TD=0)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
Value * getOperandValToReplace() const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void dump() const
dump - This method is used for debugging.
bool isLegalInteger(unsigned Width) const
void transformToPostInc(const Loop *L)
INITIALIZE_PASS_BEGIN(IVUsers,"iv-users","Induction Variable Users", false, true) INITIALIZE_PASS_END(IVUsers
static const SCEVAddRecExpr * findAddRecForLoop(const SCEV *S, const Loop *L)
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
void print(raw_ostream &OS, const Module *=0) const
IVStrideUse & AddUser(Instruction *User, Value *Operand)
const BasicBlock * getParent() const