LLVM 17.0.0git
|
#include "llvm/Transforms/Utils/SimplifyIndVar.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
Go to the source code of this file.
Namespaces | |
namespace | llvm |
This is an optimization pass for GlobalISel generic memory operations. | |
Macros | |
#define | DEBUG_TYPE "indvars" |
Functions | |
STATISTIC (NumElimIdentity, "Number of IV identities eliminated") | |
STATISTIC (NumElimOperand, "Number of IV operands folded into a use") | |
STATISTIC (NumFoldedUser, "Number of IV users folded into a constant") | |
STATISTIC (NumElimRem, "Number of IV remainder operations eliminated") | |
STATISTIC (NumSimplifiedSDiv, "Number of IV signed division operations converted to unsigned division") | |
STATISTIC (NumSimplifiedSRem, "Number of IV signed remainder operations converted to unsigned remainder") | |
STATISTIC (NumElimCmp, "Number of IV comparisons eliminated") | |
static Instruction * | findCommonDominator (ArrayRef< Instruction * > Instructions, DominatorTree &DT) |
Find a point in code which dominates all given instructions. | |
static Instruction * | GetLoopInvariantInsertPosition (Loop *L, Instruction *Hint) |
static void | pushIVUsers (Instruction *Def, Loop *L, SmallPtrSet< Instruction *, 16 > &Simplified, SmallVectorImpl< std::pair< Instruction *, Instruction * > > &SimpleIVUsers) |
Add all uses of Def to the current IV's worklist. | |
static bool | isSimpleIVUser (Instruction *I, const Loop *L, ScalarEvolution *SE) |
Return true if this instruction generates a simple SCEV expression in terms of that IV. | |
bool | llvm::simplifyUsersOfIV (PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead, SCEVExpander &Rewriter, IVVisitor *V=nullptr) |
simplifyUsersOfIV - Simplify instructions that use this induction variable by using ScalarEvolution to analyze the IV's recurrence. | |
bool | llvm::simplifyLoopIVs (Loop *L, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead) |
SimplifyLoopIVs - Simplify users of induction variables within this loop. | |
static Instruction * | getInsertPointForUses (Instruction *User, Value *Def, DominatorTree *DT, LoopInfo *LI) |
Determine the insertion point for this user. | |
static void | truncateIVUse (WidenIV::NarrowIVDefUse DU, DominatorTree *DT, LoopInfo *LI) |
This IV user cannot be widened. | |
#define DEBUG_TYPE "indvars" |
Definition at line 31 of file SimplifyIndVar.cpp.
|
static |
Find a point in code which dominates all given instructions.
We can safely assume that, whatever fact we can prove at the found point, this fact is also true for each of the given instructions.
Definition at line 106 of file SimplifyIndVar.cpp.
References assert(), llvm::DominatorTree::findNearestCommonDominator(), and Insn.
|
static |
Determine the insertion point for this user.
By default, insert immediately before the user. SCEVExpander or LICM will hoist loop invariants out of the loop. For PHI nodes, there may be multiple uses, so compute the nearest common dominator for the incoming blocks. A nullptr can be returned if no viable location is found: it may happen if User is a PHI and Def only comes to this PHI from unreachable blocks.
Definition at line 1127 of file SimplifyIndVar.cpp.
References assert(), llvm::DominatorTree::dominates(), llvm::DominatorTree::findNearestCommonDominator(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::DominatorTree::isReachableFromEntry(), llvm_unreachable, and PHI.
Referenced by truncateIVUse().
|
static |
Definition at line 610 of file SimplifyIndVar.cpp.
|
static |
Return true if this instruction generates a simple SCEV expression in terms of that IV.
This is similar to IVUsers' isInteresting() but processes each instruction non-recursively when the operand is already known to be a simpleIVUser.
Definition at line 845 of file SimplifyIndVar.cpp.
References llvm::SCEVAddRecExpr::getLoop(), llvm::ScalarEvolution::getSCEV(), I, and llvm::ScalarEvolution::isSCEVable().
|
static |
Add all uses of Def to the current IV's worklist.
Definition at line 811 of file SimplifyIndVar.cpp.
STATISTIC | ( | NumElimIdentity | , |
"Number of IV identities eliminated" | |||
) |
STATISTIC | ( | NumElimOperand | , |
"Number of IV operands folded into a use" | |||
) |
STATISTIC | ( | NumElimRem | , |
"Number of IV remainder operations eliminated" | |||
) |
STATISTIC | ( | NumSimplifiedSDiv | , |
"Number of IV signed division operations converted to unsigned division" | |||
) |
STATISTIC | ( | NumSimplifiedSRem | , |
"Number of IV signed remainder operations converted to unsigned remainder" | |||
) |
|
static |
This IV user cannot be widened.
Replace this use of the original narrow IV with a truncation of the new wide IV to isolate and eliminate the narrow IV.
Definition at line 1442 of file SimplifyIndVar.cpp.
References Builder, llvm::dbgs(), getInsertPointForUses(), and LLVM_DEBUG.