30 #define DEBUG_TYPE "loop-instsimplify"
32 STATISTIC(NumSimplified,
"Number of redundant instructions simplified");
35 class LoopInstSimplify :
public LoopPass {
59 "Simplify instructions in loops",
false,
false)
69 return new LoopInstSimplify();
73 if (skipOptnoneFunction(L))
77 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
79 LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
81 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
82 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
100 LocalChanged =
false;
107 while (!VisitStack.
empty()) {
110 bool IsSubloopHeader = Item.getInt();
120 if (!ToSimplify->empty() && !ToSimplify->count(I))
129 Next->insert(cast<Instruction>(U));
146 if (IsSubloopHeader && !isa<PHINode>(I))
157 if (!Visited.
insert(SuccBB).second)
161 if (SuccLoop && SuccLoop->
getHeader() == SuccBB
163 VisitStack.
push_back(WorklistItem(SuccBB,
true));
168 for (
unsigned i = 0; i < SubLoopExitBlocks.
size(); ++i) {
171 VisitStack.
push_back(WorklistItem(ExitBB,
false));
177 bool IsExitBlock = std::binary_search(ExitBlocks.begin(),
178 ExitBlocks.end(), SuccBB);
182 VisitStack.
push_back(WorklistItem(SuccBB,
false));
191 Changed |= LocalChanged;
192 }
while (LocalChanged);
Pass interface - Implemented by all 'passes'.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
ScalarEvolution - This class is the main scalar evolution driver.
An immutable pass that tracks lazily created AssumptionCache objects.
LoopT * getLoopFor(const BlockT *BB) const
getLoopFor - Return the inner most loop that BB lives in.
BlockT * getHeader() const
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
DominatorTree & getDomTree()
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
getExitBlocks - Return all of the successor blocks of this loop.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
AnalysisUsage & addPreservedID(const void *ID)
Pass * createLoopInstSimplifyPass()
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Interval::succ_iterator succ_end(Interval *I)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
bool contains(const LoopT *L) const
contains - Return true if the specified loop is contained within in this loop.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a trivially dead instruction...
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
getUniqueExitBlocks - Return all unique successor blocks of this loop.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
loop Simplify instructions in loops
AnalysisUsage & addRequiredID(const void *ID)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
INITIALIZE_PASS_BEGIN(LoopInstSimplify,"loop-instsimplify","Simplify instructions in loops", false, false) INITIALIZE_PASS_END(LoopInstSimplify
iterator_range< user_iterator > users()
loop Simplify instructions in false
LLVM Value Representation.
The legacy pass manager's analysis pass to compute loop information.
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
SimplifyInstruction - See if we can compute a simplified version of this instruction.
Legacy analysis pass which computes a DominatorTree.
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
replacementPreservesLCSSAForm - Returns true if replacing From with To everywhere is guaranteed to pr...
void initializeLoopInstSimplifyPass(PassRegistry &)