Lines Matching +full:- +full:- +full:user
1 //===- IVUsers.cpp - Induction Variable Users -------------------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
22 #include "llvm/Config/llvm-config.h"
32 #define DEBUG_TYPE "iv-users"
42 INITIALIZE_PASS_BEGIN(IVUsersWrapperPass, "iv-users",
48 INITIALIZE_PASS_END(IVUsersWrapperPass, "iv-users", "Induction Variable Users",
53 /// isInteresting - Test whether the given expression is "interesting" when
60 // Keep things simple. Don't touch loop-variant strides unless they're
62 if (AR->getLoop() == L)
63 return AR->isAffine() ||
64 (!L->contains(I) &&
65 SE->getSCEVAtScope(AR, LI->getLoopFor(I->getParent())) != AR);
69 return isInteresting(AR->getStart(), I, L, SE, LI) &&
70 !isInteresting(AR->getStepRecurrence(*SE), I, L, SE, LI);
76 for (const SCEV *Op : Add->operands())
89 /// IVUseShouldUsePostIncValue - We have discovered a "User" of an IV expression
90 /// and now we need to decide whether the user should use the preinc or post-inc
91 /// value. If this user should use the post-inc version of the IV, return true.
94 /// post-inc value when we cannot) or it can end up adding extra live-ranges to
95 /// the loop, resulting in reg-reg copies (if we use the pre-inc value when we
96 /// should use the post-inc value).
97 static bool IVUseShouldUsePostIncValue(Instruction *User, Value *Operand,
99 // If the user is in the loop, use the preinc value.
100 if (L->contains(User))
103 BasicBlock *LatchBlock = L->getLoopLatch();
107 // Ok, the user is outside of the loop. If it is dominated by the latch
108 // block, use the post-inc value.
109 if (DT->dominates(LatchBlock, User->getParent()))
115 // should still use the post-inc value. Check for this case now.
116 PHINode *PN = dyn_cast<PHINode>(User);
123 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
124 if (PN->getIncomingValue(i) == Operand &&
125 !DT->dominates(LatchBlock, PN->getIncomingBlock(i)))
129 // dominated by the latch block. Use the post-incremented value.
137 const DataLayout &DL = I->getDataLayout();
139 // Add this IV user to the Processed set before returning false to ensure that
144 if (!SE->isSCEVable(I->getType()))
153 // LSR is not APInt clean, do not touch integers bigger than 64-bits.
154 // Also avoid creating IVs of non-native types. For example, we don't want a
155 // 64-bit IV in 32-bit code just because the loop has one 64-bit cast.
156 uint64_t Width = SE->getTypeSizeInBits(I->getType());
166 const SCEV *ISE = SE->getSCEV(I);
169 // call this a user.
174 for (Use &U : I->uses()) {
175 Instruction *User = cast<Instruction>(U.getUser());
176 if (!UniqueUsers.insert(User).second)
180 if (isa<PHINode>(User) && Processed.count(User))
187 // If User is already in Processed, we don't want to recurse into it again,
190 if (LI->getLoopFor(User->getParent()) != L) {
191 if (isa<PHINode>(User) || Processed.count(User) ||
192 !AddUsersIfInteresting(User)) {
193 LLVM_DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
197 } else if (Processed.count(User) || !AddUsersIfInteresting(User)) {
198 LLVM_DEBUG(dbgs() << "FOUND USER: " << *User << '\n'
204 // Okay, we found a user that we cannot reduce.
205 IVStrideUse &NewUse = AddUser(User, I);
206 // Autodetect the post-inc loop set, populating NewUse.PostIncLoops.
212 auto *L = AR->getLoop();
213 bool Result = IVUseShouldUsePostIncValue(User, I, L, DT);
222 // pre-increment assumptions. Those assumptions (no wrapping) might not
223 // hold for the post-inc value. Catch such cases by making sure the
230 // original one, discard this user.
239 LLVM_DEBUG(if (SE->getSCEV(I) != ISE) dbgs()
246 IVStrideUse &IVUsers::AddUser(Instruction *User, Value *Operand) {
247 IVUses.push_back(new IVStrideUse(this, User, Operand));
261 for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I)
267 L->getHeader()->printAsOperand(OS, false);
268 if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
269 OS << " with backedge-taken count " << *SE->getBackedgeTakenCount(L);
275 IVUse.getOperandValToReplace()->printAsOperand(OS, false);
278 OS << " (post-inc with loop ";
279 PostIncLoop->getHeader()->printAsOperand(OS, false);
284 IVUse.getUser()->print(OS);
286 OS << "Printing <null> User";
314 *L->getHeader()->getParent());
324 IU->print(OS, M);
327 void IVUsersWrapperPass::releaseMemory() { IU->releaseMemory(); }
329 /// getReplacementExpr - Return a SCEV expression which computes the
332 return SE->getSCEV(IU.getOperandValToReplace());
335 /// getExpr - Return the expression for the use.
343 if (AR->getLoop() == L)
345 return findAddRecForLoop(AR->getStart(), L);
349 for (const SCEV *Op : Add->operands())
363 return AR->getStepRecurrence(*SE);
372 // Remove this user from the list.
373 Parent->Processed.erase(this->getUser());
374 Parent->IVUses.erase(this);