35 #define DEBUG_TYPE "iv-users"
46 "Induction Variable Users",
false,
true)
65 if (AR->getLoop() ==
L)
66 return AR->isAffine() ||
78 bool AnyInterestingYet =
false;
79 for (
const auto *
Op :
Add->operands())
81 if (AnyInterestingYet)
83 AnyInterestingYet =
true;
85 return AnyInterestingYet;
97 Loop *NearestLoop =
nullptr;
99 Rung; Rung = Rung->getIDom()) {
102 if (DomLoop && DomLoop->
getHeader() == DomBB) {
107 if (SimpleLoopNests.
count(DomLoop))
112 NearestLoop = DomLoop;
116 SimpleLoopNests.
insert(NearestLoop);
173 if (!Processed.insert(I).second)
194 if (EphValues.count(I))
208 if (!UniqueUsers.
insert(User).second)
212 if (isa<PHINode>(User) && Processed.count(User))
219 if (
PHINode *PHI = dyn_cast<PHINode>(User)) {
220 unsigned OperandNo = U.getOperandNo();
222 UseBB = PHI->getIncomingBlock(ValNo);
233 bool AddUserToIVUsers =
false;
235 if (isa<PHINode>(User) || Processed.count(User) ||
237 DEBUG(
dbgs() <<
"FOUND USER in other loop: " << *User <<
'\n'
238 <<
" OF SCEV: " << *ISE <<
'\n');
239 AddUserToIVUsers =
true;
241 }
else if (Processed.count(User) || !
AddUsersImpl(User, SimpleLoopNests)) {
242 DEBUG(
dbgs() <<
"FOUND USER: " << *User <<
'\n'
243 <<
" OF SCEV: " << *ISE <<
'\n');
244 AddUserToIVUsers =
true;
247 if (AddUserToIVUsers) {
253 const SCEV *OriginalISE = ISE;
256 auto *L = AR->getLoop();
259 NewUse.PostIncLoops.
insert(L);
269 if (OriginalISE != ISE) {
270 const SCEV *DenormalizedISE =
275 if (OriginalISE != DenormalizedISE) {
276 DEBUG(
dbgs() <<
" DISCARDING (NORMALIZATION ISN'T INVERTIBLE): "
283 dbgs() <<
" NORMALIZED TO: " << *ISE <<
'\n');
299 IVUses.push_back(
new IVStrideUse(
this, User, Operand));
300 return IVUses.back();
305 : L(L), AC(AC), LI(LI), DT(DT), SE(SE), IVUses() {
318 OS <<
"IV Users for loop ";
319 L->
getHeader()->printAsOperand(OS,
false);
327 IVUse.getOperandValToReplace()->printAsOperand(OS,
false);
329 for (
auto PostIncLoop : IVUse.PostIncLoops) {
330 OS <<
" (post-inc with loop ";
331 PostIncLoop->getHeader()->printAsOperand(OS,
false);
336 IVUse.getUser()->print(OS);
338 OS <<
"Printing <null> User";
343 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
365 auto *AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
367 auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
368 auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
369 auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
371 IU.reset(
new IVUsers(L, AC, LI, DT, SE));
395 if (AR->getLoop() ==
L)
401 for (
const auto *
Op :
Add->operands())
412 return AR->getStepRecurrence(*SE);
420 void IVStrideUse::deleted() {
422 Parent->Processed.erase(this->
getUser());
423 Parent->IVUses.erase(
this);
Pass interface - Implemented by all 'passes'.
bool runOnLoop(Loop *L, LPPassManager &LPM) override
const SCEV * getExpr(const IVStrideUse &IU) const
getExpr - Return the expression for the use.
A parsed version of the target data layout string in and methods for querying it. ...
iterator_range< use_iterator > uses()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const PostIncLoopSet & getPostIncLoops() const
getPostIncLoops - Return the set of loops for which the expression has been adjusted to use post-inc ...
static bool IVUseShouldUsePostIncValue(Instruction *User, Value *Operand, const Loop *L, DominatorTree *DT)
IVUseShouldUsePostIncValue - We have discovered a "User" of an IV expression and now we need to decid...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
A Module instance is used to store all the information related to an LLVM module. ...
const SCEV * normalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops, ScalarEvolution &SE)
Normalize S to be post-increment for all loops present in Loops.
Pass * createIVUsersPass()
The main scalar evolution driver.
void initializeIVUsersWrapperPassPass(PassRegistry &)
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
void print(raw_ostream &OS, const Module *=nullptr) const
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
iv Induction Variable Users
BlockT * getHeader() const
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool AddUsersIfInteresting(Instruction *I)
AddUsersIfInteresting - Inspect the specified Instruction.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const SCEV * getStride(const IVStrideUse &IU, const Loop *L) const
A Use represents the edge between a Value definition and its users.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to...
This node represents a polynomial recurrence on the trip count of the specified loop.
static bool isSimplifiedLoopNest(BasicBlock *BB, const DominatorTree *DT, const LoopInfo *LI, SmallPtrSetImpl< Loop * > &SimpleLoopNests)
Return true if all loop headers that dominate this block are in simplified form.
Base class for the actual dominator tree node.
This header provides classes for managing per-loop analyses.
Instruction * getUser() const
getUser - Return the user instruction for this use.
void dump() const
dump - This method is used for debugging.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
const SCEV * normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred, ScalarEvolution &SE)
Normalize S for all add recurrence sub-expressions for which Pred returns true.
bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
bool AddUsersImpl(Instruction *I, SmallPtrSetImpl< Loop * > &SimpleLoopNests)
AddUsersImpl - Inspect the specified instruction.
LLVM Basic Block Representation.
IVUsers run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
const SCEV * getReplacementExpr(const IVStrideUse &IU) const
getReplacementExpr - Return a SCEV expression which computes the value of the OperandValToReplace of ...
const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static unsigned getIncomingValueNumForOperand(unsigned i)
static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L, ScalarEvolution *SE, LoopInfo *LI)
isInteresting - Test whether the given expression is "interesting" when used by the given expression...
iv Induction Variable false
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Iterator for intrusive lists based on ilist_node.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Value * getOperandValToReplace() const
getOperandValToReplace - Return the Value of the operand in the user instruction that this IVStrideUs...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This node represents an addition of some number of SCEVs.
void setPreservesAll()
Set by analyses that do not transform their input at all.
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE)
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void transformToPostInc(const Loop *L)
transformToPostInc - Transform the expression to post-inc form for the given loop.
const SCEV * getBackedgeTakenCount(const Loop *L)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
static const SCEVAddRecExpr * findAddRecForLoop(const SCEV *S, const Loop *L)
const SCEV * denormalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops, ScalarEvolution &SE)
Denormalize S to be post-increment for all loops present in Loops.
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
INITIALIZE_PASS_BEGIN(IVUsersWrapperPass,"iv-users","Induction Variable Users", false, true) INITIALIZE_PASS_END(IVUsersWrapperPass
IVStrideUse - Keep track of one use of a strided induction variable.
This class implements an extremely fast bulk output stream that can only output to a stream...
The legacy pass manager's analysis pass to compute loop information.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU...
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop)...
IVStrideUse & AddUser(Instruction *User, Value *Operand)
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count...
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
void print(raw_ostream &OS, const Module *=nullptr) const override
print - Print out the internal state of the pass.