47 #define DEBUG_TYPE "loop-instsimplify" 49 STATISTIC(NumSimplified,
"Number of redundant instructions simplified");
88 if (
auto *PI = dyn_cast<PHINode>(&
I))
99 bool IsFirstIteration = ToSimplify->
empty();
101 if (!IsFirstIteration && !ToSimplify->
count(&
I))
111 auto *UserI = cast<Instruction>(U.
getUser());
117 if (
auto *UserPI = dyn_cast<PHINode>(UserI))
118 if (VisitedPHIs.
count(UserPI)) {
119 Next->insert(UserPI);
132 "Uses outside the loop should be PHI nodes due to LCSSA!");
133 if (!IsFirstIteration && L.
contains(UserI))
134 ToSimplify->
insert(UserI);
138 if (
Instruction *SimpleI = dyn_cast_or_null<Instruction>(V))
141 MA->replaceAllUsesWith(ReplacementMA);
143 assert(
I.use_empty() &&
"Should always have replaced all uses!");
153 if (!DeadInsts.
empty()) {
179 class LoopInstSimplifyLegacyPass :
public LoopPass {
183 LoopInstSimplifyLegacyPass() :
LoopPass(ID) {
190 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
191 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
193 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
196 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
200 MSSA = &getAnalysis<MemorySSAWrapperPass>().getMSSA();
243 "Simplify instructions in loops",
false,
false)
252 return new LoopInstSimplifyLegacyPass();
Pass interface - Implemented by all 'passes'.
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...
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
bool VerifyMemorySSA
Enables verification of MemorySSA.
This class represents lattice values for constants.
SimplifyQuery getWithInstruction(Instruction *I) const
void push_back(const T &Elt)
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)
Legacy analysis pass which computes MemorySSA.
MemorySSA * getMemorySSA() const
Get handle on MemorySSA.
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.
Encapsulates MemorySSA, including all data associated with memory accesses.
static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, const TargetLibraryInfo &TLI, MemorySSAUpdater *MSSAU)
BlockT * getHeader() const
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
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.
const T * getPointer() const
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, MemorySSAUpdater *MSSAU=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
void verifyMemorySSA() const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
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.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
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.
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
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.
cl::opt< bool > EnableMSSALoopDependency
Enables memory ssa as a dependency for loop passes.