|
LLVM 24.0.0git
|
#include "llvm/Transforms/Scalar/LoopDeletion.h"#include "ScalarOptions.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/CFG.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/LoopIterator.h"#include "llvm/Analysis/LoopPass.h"#include "llvm/Analysis/MemorySSA.h"#include "llvm/Analysis/OptimizationRemarkEmitter.h"#include "llvm/Analysis/ScalarEvolution.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/PatternMatch.h"#include "llvm/Transforms/Scalar/LoopPassManager.h"#include "llvm/Transforms/Utils/LoopUtils.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "loop-delete" |
Enumerations | |
| enum class | LoopDeletionResult { Unmodified , Modified , Deleted } |
Functions | |
| STATISTIC (NumDeleted, "Number of loops deleted") | |
| STATISTIC (NumBackedgesBroken, "Number of loops for which we managed to break the backedge") | |
| static LoopDeletionResult | merge (LoopDeletionResult A, LoopDeletionResult B) |
| static bool | isLoopDead (Loop *L, ScalarEvolution &SE, SmallVectorImpl< BasicBlock * > &ExitingBlocks, BasicBlock *ExitBlock, bool &Changed, BasicBlock *Preheader, LoopInfo &LI) |
| Determines if a loop is dead. | |
| static bool | isLoopNeverExecuted (Loop *L) |
This function returns true if there is no viable path from the entry block to the header of L. | |
| static Value * | getValueOnFirstIteration (Value *V, DenseMap< Value *, Value * > &FirstIterValue, const SimplifyQuery &SQ) |
| static bool | canProveExitOnFirstIteration (Loop *L, DominatorTree &DT, LoopInfo &LI) |
| static LoopDeletionResult | breakBackedgeIfNotTaken (Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA, OptimizationRemarkEmitter &ORE) |
| If we can prove the backedge is untaken, remove it. | |
| static LoopDeletionResult | deleteLoopIfDead (Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA, OptimizationRemarkEmitter &ORE) |
| Remove a loop if it is dead. | |
| #define DEBUG_TYPE "loop-delete" |
Definition at line 35 of file LoopDeletion.cpp.
|
strong |
| Enumerator | |
|---|---|
| Unmodified | |
| Modified | |
| Deleted | |
Definition at line 41 of file LoopDeletion.cpp.
|
static |
If we can prove the backedge is untaken, remove it.
This destroys the loop, but leaves the (now trivially loop invariant) control flow and side effects (if any) in place.
Definition at line 395 of file LoopDeletion.cpp.
References assert(), llvm::breakLoopBackedge(), canProveExitOnFirstIteration(), Deleted, llvm::ScalarEvolution::getBackedgeTakenCount(), llvm::ScalarEvolution::getConstantMaxBackedgeTakenCount(), llvm::isa(), llvm::ScalarEvolution::isKnownNonZero(), llvm::SCEV::isZero(), and Unmodified.
Referenced by llvm::LoopDeletionPass::run().
|
static |
Definition at line 212 of file LoopDeletion.cpp.
References assert(), Cond, llvm::containsIrreducibleCFG(), llvm::detail::DenseSetImpl< ValueT, MapTy >::count(), llvm::SmallPtrSetImpl< PtrType >::count(), DL, llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::PoisonValue::get(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::BasicBlock::getParent(), getValueOnFirstIteration(), llvm::detail::DenseSetImpl< ValueT, MapTy >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::LoopInfoBase< BlockT, LoopT >::isLoopHeader(), llvm::PatternMatch::m_BasicBlock(), llvm::PatternMatch::m_Br(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::LoopBlocksRPO::perform(), llvm::predecessors(), and llvm::successors().
Referenced by breakBackedgeIfNotTaken().
|
static |
Remove a loop if it is dead.
A loop is considered dead either if it does not impact the observable behavior of the program other than finite running time, or if it is required to make progress by an attribute such as 'mustprogress' or 'llvm.loop.mustprogress' and does not make any. This may remove infinite loops that have been required to make progress.
This entire process relies pretty heavily on LoopSimplify form and LCSSA in order to make various safety checks work.
Definition at line 432 of file LoopDeletion.cpp.
References assert(), Changed, llvm::dbgs(), DEBUG_TYPE, Deleted, llvm::deleteDeadLoop(), llvm::OptimizationRemarkEmitter::emit(), llvm::fill(), llvm::ScalarEvolution::forgetLoop(), llvm::PoisonValue::get(), llvm::LoopInfoBase< BlockT, LoopT >::hasNoExitBlocks(), llvm::BasicBlock::isEHPad(), isLoopDead(), isLoopNeverExecuted(), LLVM_DEBUG, Modified, P, llvm::BasicBlock::phis(), and Unmodified.
Referenced by llvm::LoopDeletionPass::run().
|
static |
Definition at line 173 of file LoopDeletion.cpp.
References C(), Cond, llvm::dyn_cast(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::find(), getValueOnFirstIteration(), llvm::isa(), LHS, RHS, Select, llvm::simplifyBinOp(), and llvm::simplifyICmpInst().
Referenced by canProveExitOnFirstIteration(), and getValueOnFirstIteration().
|
static |
Determines if a loop is dead.
This assumes that we've already checked for unique exit and exiting blocks, and that the code is in LCSSA form.
Definition at line 59 of file LoopDeletion.cpp.
References llvm::all_of(), llvm::any_of(), llvm::SmallVectorImpl< T >::append(), llvm::ArrayRef(), llvm::LoopBase< BlockT, LoopT >::begin(), Changed, llvm::containsIrreducibleCFG(), llvm::dbgs(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::LoopBase< BlockT, LoopT >::end(), llvm::ScalarEvolution::getConstantMaxBackedgeTakenCount(), llvm::BasicBlock::getTerminator(), llvm::hasMustProgress(), I, llvm::isa(), LLVM_DEBUG, P, llvm::LoopBlocksRPO::perform(), llvm::BasicBlock::phis(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by deleteLoopIfDead().
This function returns true if there is no viable path from the entry block to the header of L.
Right now, it only does a local search to save compile time.
Definition at line 143 of file LoopDeletion.cpp.
References assert(), Cond, llvm::PatternMatch::m_Br(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::match(), llvm::pred_empty(), llvm::predecessors(), and std::swap().
Referenced by deleteLoopIfDead().
|
static |
Definition at line 47 of file LoopDeletion.cpp.
References A(), B(), Deleted, Modified, and Unmodified.
Referenced by llvm::LoopDeletionPass::run(), and llvm::simple_ilist< T, Options >::sort().
| STATISTIC | ( | NumDeleted | , |
| "Number of loops deleted" | ) |