33 #define DEBUG_TYPE "loop-instsimplify"
35 STATISTIC(NumSimplified,
"Number of redundant instructions simplified");
62 while (!VisitStack.
empty()) {
65 bool IsSubloopHeader = Item.getInt();
75 if (!ToSimplify->empty() && !ToSimplify->count(I))
84 Next->insert(cast<Instruction>(U));
100 if (IsSubloopHeader && !isa<PHINode>(I))
113 if (!Visited.
insert(SuccBB).second)
117 if (SuccLoop && SuccLoop->
getHeader() == SuccBB &&
119 VisitStack.
push_back(WorklistItem(SuccBB,
true));
124 for (
unsigned i = 0;
i < SubLoopExitBlocks.
size(); ++
i) {
127 VisitStack.
push_back(WorklistItem(ExitBB,
false));
134 std::binary_search(ExitBlocks.
begin(), ExitBlocks.
end(), SuccBB);
138 VisitStack.
push_back(WorklistItem(SuccBB,
false));
147 Changed |= LocalChanged;
148 }
while (LocalChanged);
154 class LoopInstSimplifyLegacyPass :
public LoopPass {
165 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
167 LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
169 &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
172 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
197 "Simplify instructions in loops",
false,
false)
205 return new LoopInstSimplifyLegacyPass();
Pass interface - Implemented by all 'passes'.
INITIALIZE_PASS_BEGIN(LoopInstSimplifyLegacyPass,"loop-instsimplify","Simplify instructions in loops", false, false) INITIALIZE_PASS_END(LoopInstSimplifyLegacyPass
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
STATISTIC(NumFunctions,"Total number of functions")
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
static bool SimplifyLoopInst(Loop *L, DominatorTree *DT, LoopInfo *LI, AssumptionCache *AC, const TargetLibraryInfo *TLI)
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
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.
BlockT * getHeader() const
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
DominatorTree & getDomTree()
LLVM_NODISCARD bool empty() const
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
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...
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 initializeLoopInstSimplifyLegacyPassPass(PassRegistry &)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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
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
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
Return all unique successor blocks of this loop.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
loop Simplify instructions in loops
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.
LLVM_NODISCARD T pop_back_val()
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.
iterator_range< user_iterator > users()
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Represents a single loop in the control flow graph.
loop Simplify instructions in false
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
LLVM Value Representation.
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
See if we can compute a simplified version of this instruction.
Legacy analysis pass which computes a DominatorTree.
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form...