LLVM: lib/Transforms/Scalar/LoopInstSimplify.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
33#include
34#include
35
36using namespace llvm;
37
38#define DEBUG_TYPE "loop-instsimplify"
39
40STATISTIC(NumSimplified, "Number of redundant instructions simplified");
41
45 const DataLayout &DL = L.getHeader()->getDataLayout();
47
48
49
50
51
52
53
55
56
57
59
60
61
63
64
65
66
67
68
72
74 for (;;) {
80 VisitedPHIs.insert(PI);
81
82 if (I.use_empty()) {
85 continue;
86 }
87
88
89
90 bool IsFirstIteration = ToSimplify->empty();
91
92 if (!IsFirstIteration && !ToSimplify->count(&I))
93 continue;
94
97 continue;
98
101 U.set(V);
102
103
105 continue;
106
107
108
109
111 if (VisitedPHIs.count(UserPI)) {
112 Next->insert(UserPI);
113 continue;
114 }
115
116
117
118
119
120
121
122
123
125 "Uses outside the loop should be PHI nodes due to LCSSA!");
126 if (!IsFirstIteration && L.contains(UserI))
127 ToSimplify->insert(UserI);
128 }
129
130 if (MSSAU)
134 MA->replaceAllUsesWith(ReplacementMA);
135
136 assert(I.use_empty() && "Should always have replaced all uses!");
139 ++NumSimplified;
141 }
142 }
143
144
145
146 if (!DeadInsts.empty()) {
149 }
150
153
154
155
156 if (Next->empty())
157 break;
158
159
160
162 Next->clear();
163 VisitedPHIs.clear();
164 DeadInsts.clear();
165 }
166
168}
169
173 std::optional MSSAU;
174 if (AR.MSSA) {
178 }
180 MSSAU ? &*MSSAU : nullptr))
182
187 return PA;
188}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, const TargetLibraryInfo &TLI, MemorySSAUpdater *MSSAU)
Definition LoopInstSimplify.cpp:42
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Represents analyses that only rely on functions' control flow.
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
void perform(const LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Definition LoopInstSimplify.cpp:170
Represents a single loop in the control flow graph.
An analysis that produces MemorySSA for a function.
MemorySSA * getMemorySSA() const
Get handle on MemorySSA.
Encapsulates MemorySSA, including all data associated with memory accesses.
LLVM_ABI void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
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.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool VerifyMemorySSA
Enables verification of MemorySSA.
FunctionAddr VTableAddr Next
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
SimplifyQuery getWithInstruction(const Instruction *I) const