45 #define DEBUG_TYPE "loop-instsimplify" 47 STATISTIC(NumSimplified,
"Number of redundant instructions simplified");
83 if (
auto *PI = dyn_cast<PHINode>(&
I))
94 bool IsFirstIteration = ToSimplify->
empty();
96 if (!IsFirstIteration && !ToSimplify->
count(&
I))
106 auto *UserI = cast<Instruction>(U.
getUser());
112 if (
auto *UserPI = dyn_cast<PHINode>(UserI))
113 if (VisitedPHIs.
count(UserPI)) {
114 Next->insert(UserPI);
127 "Uses outside the loop should be PHI nodes due to LCSSA!");
128 if (!IsFirstIteration && L.
contains(UserI))
129 ToSimplify->
insert(UserI);
132 assert(
I.use_empty() &&
"Should always have replaced all uses!");
142 if (!DeadInsts.
empty()) {
165 class LoopInstSimplifyLegacyPass :
public LoopPass {
169 LoopInstSimplifyLegacyPass() :
LoopPass(ID) {
176 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
177 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
179 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
182 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
212 "Simplify instructions in loops",
false,
false)
220 return new LoopInstSimplifyLegacyPass();
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. ...
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.
Compute iterated dominance frontiers using a linear time algorithm.
SimplifyQuery getWithInstruction(Instruction *I) const
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
STATISTIC(NumFunctions, "Total number of functions")
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
#define INITIALIZE_PASS_DEPENDENCY(depName)
static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, const TargetLibraryInfo &TLI)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
A Use represents the edge between a Value definition and its users.
BlockT * getHeader() const
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
Pass * createLoopInstSimplifyPass()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
use_iterator_impl< Use > use_iterator
void initializeLoopInstSimplifyLegacyPassPass(PassRegistry &)
A set of analyses that are preserved following a run of a transformation pass.
INITIALIZE_PASS_BEGIN(LoopInstSimplifyLegacyPass, "loop-instsimplify", "Simplify instructions in loops", false, false) INITIALIZE_PASS_END(LoopInstSimplifyLegacyPass
LLVM Basic Block Representation.
LLVM_NODISCARD bool empty() const
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.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
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...
Module.h This file contains the declarations for the Module class.
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.
Represents analyses that only rely on functions' control flow.
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
const Function * getParent() const
Return the enclosing method, or null if none.
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
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...
This header defines various interfaces for pass management in LLVM.
void perform(LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.