LLVM 24.0.0git
GVN.h
Go to the documentation of this file.
1//===- GVN.h - Eliminate redundant values and loads -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file provides the interface for LLVM's Global Value Numbering pass
10/// which eliminates fully redundant instructions. It also does somewhat Ad-Hoc
11/// PRE and dead load elimination.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_SCALAR_GVN_H
16#define LLVM_TRANSFORMS_SCALAR_GVN_H
17
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/MapVector.h"
20#include "llvm/ADT/SetVector.h"
23#include "llvm/IR/Dominators.h"
24#include "llvm/IR/InstrTypes.h"
25#include "llvm/IR/PassManager.h"
26#include "llvm/IR/ValueHandle.h"
29#include <cstdint>
30#include <optional>
31#include <utility>
32#include <variant>
33#include <vector>
34
35namespace llvm {
36
37class AAResults;
38class AssumeInst;
39class AssumptionCache;
40class BasicBlock;
41class BatchAAResults;
42class CallInst;
43class CondBrInst;
46class Function;
47class FunctionPass;
48class GVNLegacyPass;
51class LoadInst;
52class LoopInfo;
53class MemDepResult;
54class MemoryAccess;
56class MemoryLocation;
57class MemorySSA;
61class PHINode;
63class Value;
64class IntrinsicInst;
65
66/// A set of parameters to control various transforms performed by GVN pass.
67// Each of the optional boolean parameters can be set to:
68/// true - enabling the transformation.
69/// false - disabling the transformation.
70/// None - relying on a global default.
71/// Intended use is to create a default object, modify parameters with
72/// additional setters and then pass it to GVN.
73struct GVNOptions {
74 std::optional<bool> AllowScalarPRE;
75 std::optional<bool> AllowLoadPRE;
76 std::optional<bool> AllowLoadInLoopPRE;
77 std::optional<bool> AllowLoadPRESplitBackedge;
78 std::optional<bool> AllowMemDep;
79 std::optional<bool> AllowMemorySSA;
80
81 GVNOptions() = default;
82
83 /// Enables or disables PRE of scalars in GVN.
84 GVNOptions &setScalarPRE(bool ScalarPRE) {
85 AllowScalarPRE = ScalarPRE;
86 return *this;
87 }
88
89 /// Enables or disables PRE of loads in GVN.
90 GVNOptions &setLoadPRE(bool LoadPRE) {
91 AllowLoadPRE = LoadPRE;
92 return *this;
93 }
94
95 GVNOptions &setLoadInLoopPRE(bool LoadInLoopPRE) {
96 AllowLoadInLoopPRE = LoadInLoopPRE;
97 return *this;
98 }
99
100 /// Enables or disables PRE of loads in GVN.
101 GVNOptions &setLoadPRESplitBackedge(bool LoadPRESplitBackedge) {
102 AllowLoadPRESplitBackedge = LoadPRESplitBackedge;
103 return *this;
104 }
105
106 /// Enables or disables use of MemDepAnalysis.
107 GVNOptions &setMemDep(bool MemDep) {
108 AllowMemDep = MemDep;
109 return *this;
110 }
111
112 /// Enables or disables use of MemorySSA.
113 GVNOptions &setMemorySSA(bool MemSSA) {
114 AllowMemorySSA = MemSSA;
115 return *this;
116 }
117};
118
119/// The core GVN pass object.
120///
121/// FIXME: We should have a good summary of the GVN algorithm implemented by
122/// this particular pass here.
123class GVNPass : public OptionalPassInfoMixin<GVNPass> {
124 GVNOptions Options;
125
126public:
127 struct Expression;
128 struct AvailableValue;
130
131 GVNPass(GVNOptions Options = {}) : Options(Options) {}
132
133 /// Run the pass over the function.
134 LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
135
136 LLVM_ABI void
137 printPipeline(raw_ostream &OS,
138 function_ref<StringRef(StringRef)> MapClassName2PassName);
139
140 /// This removes the specified instruction from
141 /// our various maps and marks it for deletion.
142 LLVM_ABI void salvageAndRemoveInstruction(Instruction *I);
143
144 DominatorTree &getDominatorTree() const { return *DT; }
145 AAResults *getAliasAnalysis() const { return VN.getAliasAnalysis(); }
146 MemoryDependenceResults &getMemDep() const { return *MD; }
147
148 LLVM_ABI bool isScalarPREEnabled() const;
149 LLVM_ABI bool isLoadPREEnabled() const;
150 LLVM_ABI bool isLoadInLoopPREEnabled() const;
152 LLVM_ABI bool isMemDepEnabled() const;
153 LLVM_ABI bool isMemorySSAEnabled() const;
154
155 /// This class holds the mapping between values and value numbers. It is used
156 /// as an efficient mechanism to determine the expression-wise equivalence of
157 /// two values.
159 DenseMap<Value *, uint32_t> ValueNumbering;
160 DenseMap<Expression, uint32_t> ExpressionNumbering;
161
162 // Expressions is the vector of Expression. ExprIdx is the mapping from
163 // value number to the index of Expression in Expressions. We use it
164 // instead of a DenseMap because filling such mapping is faster than
165 // filling a DenseMap and the compile time is a little better.
166 uint32_t NextExprNumber = 0;
167
168 std::vector<Expression> Expressions;
169 std::vector<uint32_t> ExprIdx;
170
171 // Value number to PHINode mapping. Used for phi-translate in scalarpre.
173
174 // Value number to BasicBlock mapping. Used for phi-translate across
175 // MemoryPhis.
177
178 // Cache for phi-translate in scalarpre.
179 using PhiTranslateMap =
181 PhiTranslateMap PhiTranslateTable;
182
183 AAResults *AA = nullptr;
184 MemoryDependenceResults *MD = nullptr;
185 bool IsMDEnabled = false;
186 MemorySSA *MSSA = nullptr;
187 bool IsMSSAEnabled = false;
188 DominatorTree *DT = nullptr;
189
190 uint32_t NextValueNumber = 1;
191
192 Expression createExpr(Instruction *I);
193 Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
194 Value *LHS, Value *RHS);
195 Expression createExtractvalueExpr(ExtractValueInst *EI);
196 Expression createGEPExpr(GetElementPtrInst *GEP);
197 uint32_t lookupOrAddCall(CallInst *C);
198 uint32_t computeLoadStoreVN(Instruction *I);
199 uint32_t phiTranslateImpl(const BasicBlock *BB, const BasicBlock *PhiBlock,
200 uint32_t Num, GVNPass &GVN);
201 bool areCallValsEqual(uint32_t Num, uint32_t NewNum, const BasicBlock *Pred,
202 const BasicBlock *PhiBlock, GVNPass &GVN);
203 std::pair<uint32_t, bool> assignExpNewValueNum(Expression &Exp);
204 bool areAllValsInBB(uint32_t Num, const BasicBlock *BB, GVNPass &GVN);
205 void addMemoryStateToExp(Instruction *I, Expression &Exp);
206
207 public:
213
216 LLVM_ABI uint32_t lookup(Value *V, bool Verify = true) const;
218 Value *LHS, Value *RHS);
221 const BasicBlock *PhiBlock, uint32_t Num,
222 GVNPass &GVN);
224 const BasicBlock &CurrBlock);
225 LLVM_ABI bool exists(Value *V) const;
226 LLVM_ABI void add(Value *V, uint32_t Num);
227 LLVM_ABI void clear();
228 LLVM_ABI void erase(Value *V);
229 void setAliasAnalysis(AAResults *A) { AA = A; }
230 AAResults *getAliasAnalysis() const { return AA; }
231 void setMemDep(MemoryDependenceResults *M, bool MDEnabled = true) {
232 MD = M;
233 IsMDEnabled = MDEnabled;
234 }
235 void setMemorySSA(MemorySSA *M, bool MSSAEnabled = false) {
236 MSSA = M;
237 IsMSSAEnabled = MSSAEnabled;
238 }
239 void setDomTree(DominatorTree *D) { DT = D; }
240 uint32_t getNextUnusedValueNumber() { return NextValueNumber; }
241 LLVM_ABI void verifyRemoved(const Value *) const;
242 };
243
244private:
245 friend class GVNLegacyPass;
246 friend struct DenseMapInfo<Expression>;
247
248 MemoryDependenceResults *MD = nullptr;
249 DominatorTree *DT = nullptr;
250 const TargetLibraryInfo *TLI = nullptr;
251 AssumptionCache *AC = nullptr;
252 SetVector<BasicBlock *> DeadBlocks;
253 OptimizationRemarkEmitter *ORE = nullptr;
254 ImplicitControlFlowTracking *ICF = nullptr;
255 LoopInfo *LI = nullptr;
256 AAResults *AA = nullptr;
257 MemorySSAUpdater *MSSAU = nullptr;
258
259 ValueTable VN;
260
261 /// A mapping from value numbers to lists of Value*'s that
262 /// have that value number. Use findLeader to query it.
263 class LeaderMap {
264 public:
266 // Use AssertingVH here to catch dangling Value*'s in the leader table.
267 // Will crash if the value gets deleted before the AssertingVH is
268 // destroyed.
272 };
273
274 private:
275 struct LeaderListNode {
276 LeaderTableEntry Entry;
277 LeaderListNode *Next;
278 LeaderListNode(Value *V, const BasicBlock *BB, LeaderListNode *Next)
279 : Entry(V, BB), Next(Next) {}
280 };
281 DenseMap<uint32_t, LeaderListNode> NumToLeaders;
282 BumpPtrAllocator TableAllocator;
283
284 public:
286 const LeaderListNode *Current;
287
288 public:
289 using iterator_category = std::forward_iterator_tag;
291 using difference_type = std::ptrdiff_t;
294
295 leader_iterator(const LeaderListNode *C) : Current(C) {}
297 assert(Current && "Dereferenced end of leader list!");
298 Current = Current->Next;
299 return *this;
300 }
301 bool operator==(const leader_iterator &Other) const {
302 return Current == Other.Current;
303 }
304 bool operator!=(const leader_iterator &Other) const {
305 return Current != Other.Current;
306 }
307 reference operator*() const { return Current->Entry; }
308 };
309
311 auto I = NumToLeaders.find(N);
312 if (I == NumToLeaders.end()) {
313 return iterator_range(leader_iterator(nullptr),
314 leader_iterator(nullptr));
315 }
316
317 return iterator_range(leader_iterator(&I->second),
318 leader_iterator(nullptr));
319 }
320
321 LLVM_ABI void insert(uint32_t N, Value *V, const BasicBlock *BB);
322 LLVM_ABI void erase(uint32_t N, Instruction *I, const BasicBlock *BB);
323 void clear() {
324 // Manually destroy non-head nodes (in BumpPtrAllocator) to properly
325 // clean up AssertingVH handles before Reset(). Head nodes are destroyed
326 // by NumToLeaders.clear() below.
327 for (auto &[_, HeadNode] : NumToLeaders) {
328 LeaderListNode *N = HeadNode.Next;
329 while (N) {
330 auto *Next = N->Next;
331 N->~LeaderListNode();
332 N = Next;
333 }
334 }
335 NumToLeaders.clear();
336 TableAllocator.Reset();
337 }
338 };
339 LeaderMap LeaderTable;
340
341 // Map the block to reversed postorder traversal number. It is used to
342 // find back edge easily.
343 DenseMap<AssertingVH<BasicBlock>, uint32_t> BlockRPONumber;
344
345 // This is set 'true' initially and also when new blocks have been added to
346 // the function being analyzed. This boolean is used to control the updating
347 // of BlockRPONumber prior to accessing the contents of BlockRPONumber.
348 bool InvalidBlockRPONumbers = true;
349
350 using LoadDepVect = SmallVector<NonLocalDepResult, 64>;
351 using AvailValInBlkVect = SmallVector<AvailableValueInBlock, 64>;
352 using UnavailBlkVect = SmallVector<BasicBlock *, 64>;
353
354 bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
355 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
356 MemoryDependenceResults *RunMD, LoopInfo &LI,
357 OptimizationRemarkEmitter *ORE, MemorySSA *MSSA = nullptr);
358
359 // List of critical edges to be split between iterations.
361
362 enum class DepKind {
363 Other = 0, // Unknown value.
364 Def, // Exactly overlapping locations.
365 Clobber, // Reaching value superset of needed bits.
366 Select, // Reaching value is a select of two reaching addresses.
367 };
368
369 // Describe a memory location value, such that there exists a path to a point
370 // in the program, along which that memory location is not modified.
371 struct ReachingMemVal {
372 DepKind Kind;
373 BasicBlock *Block;
374 const Value *Addr;
375 Instruction *Inst;
376 int32_t Offset;
377 // For DepKind::Select only: the condition and the two addresses referenced
378 // by the "true" and "false" side of the select-dependent load.
379 const Value *SelCond = nullptr;
380 const Value *SelTrueAddr = nullptr;
381 const Value *SelFalseAddr = nullptr;
382
383 static ReachingMemVal getUnknown(BasicBlock *BB, const Value *Addr,
384 Instruction *Inst = nullptr) {
385 return {DepKind::Other, BB, Addr, Inst, -1};
386 }
387
388 static ReachingMemVal getDef(const Value *Addr, Instruction *Inst) {
389 return {DepKind::Def, Inst->getParent(), Addr, Inst, -1};
390 }
391
392 static ReachingMemVal getClobber(const Value *Addr, Instruction *Inst,
393 int32_t Offset = -1) {
394 return {DepKind::Clobber, Inst->getParent(), Addr, Inst, Offset};
395 }
396
397 static ReachingMemVal getSelect(BasicBlock *BB, const Value *Cond,
398 const Value *TrueAddr,
399 const Value *FalseAddr) {
400 return {DepKind::Select, BB, nullptr, nullptr, -1, Cond,
401 TrueAddr, FalseAddr};
402 }
403 };
404
405 struct DependencyBlockInfo {
406 DependencyBlockInfo() = delete;
407 DependencyBlockInfo(const PHITransAddr &Addr, MemoryAccess *ClobberMA)
408 : Addr(Addr), InitialClobberMA(ClobberMA), ClobberMA(ClobberMA),
409 ForceUnknown(false), Visited(false) {}
410 PHITransAddr Addr;
411 MemoryAccess *InitialClobberMA;
412 MemoryAccess *ClobberMA;
413 std::optional<ReachingMemVal> MemVal;
414 bool ForceUnknown : 1;
415 bool Visited : 1;
416 };
417
418 using DependencyBlockSet = DenseMap<BasicBlock *, DependencyBlockInfo>;
419
420 std::optional<GVNPass::ReachingMemVal> scanMemoryAccessesUsers(
421 const MemoryLocation &Loc, bool IsInvariantLoad, BasicBlock *BB,
422 const SmallVectorImpl<MemoryAccess *> &ClobbersList, MemorySSA &MSSA,
423 BatchAAResults &AA, LoadInst *L = nullptr);
424
425 std::optional<GVNPass::ReachingMemVal>
426 accessMayModifyLocation(MemoryAccess *ClobberMA, const MemoryLocation &Loc,
427 bool IsInvariantLoad, BasicBlock *BB, MemorySSA &MSSA,
428 BatchAAResults &AA);
429
430 bool collectPredecessors(BasicBlock *BB, const PHITransAddr &Addr,
431 MemoryAccess *ClobberMA, DependencyBlockSet &Blocks,
432 SmallVectorImpl<BasicBlock *> &Worklist);
433
434 void collectClobberList(SmallVectorImpl<MemoryAccess *> &Clobbers,
435 BasicBlock *BB, const DependencyBlockInfo &StartInfo,
436 const DependencyBlockSet &Blocks, MemorySSA &MSSA);
437
438 bool findReachingValuesForLoad(LoadInst *Inst,
439 SmallVectorImpl<ReachingMemVal> &Values,
440 MemorySSA &MSSA, AAResults &AA);
441
442 // Helper functions of redundant load elimination.
443 bool processLoad(LoadInst *L);
444 bool processMaskedLoad(IntrinsicInst *I);
445 bool processNonLocalLoad(LoadInst *L);
446 bool processNonLocalLoad(LoadInst *L, SmallVectorImpl<ReachingMemVal> &Deps);
447 bool processAssumeIntrinsic(AssumeInst *II);
448
449 /// Given a local dependency (Def or Clobber) determine if a value is
450 /// available for the load.
451 std::optional<AvailableValue>
452 analyzeLoadAvailability(LoadInst *Load, const ReachingMemVal &Dep,
453 Value *Address);
454
455 /// Given a select-dependency for the load (the load address is a select of
456 /// \p TrueAddr and \p FalseAddr guarded by \p Cond), determine whether a
457 /// value is available by finding dominating values for both addresses. If
458 /// so, the load can be rematerialized as a select of those two values.
459 std::optional<AvailableValue>
460 analyzeSelectAvailability(LoadInst *Load, Value *Cond, Value *TrueAddr,
461 Value *FalseAddr, Instruction *From);
462
463 /// Given a list of non-local dependencies, determine if a value is
464 /// available for the load in each specified block. If it is, add it to
465 /// ValuesPerBlock. If not, add it to UnavailableBlocks.
466 void analyzeLoadAvailability(LoadInst *Load,
467 SmallVectorImpl<ReachingMemVal> &Deps,
468 AvailValInBlkVect &ValuesPerBlock,
469 UnavailBlkVect &UnavailableBlocks);
470
471 /// Given a critical edge from Pred to LoadBB, find a load instruction
472 /// which is identical to Load from another successor of Pred.
473 LoadInst *findLoadToHoistIntoPred(BasicBlock *Pred, BasicBlock *LoadBB,
474 LoadInst *Load);
475
476 bool performLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
477 UnavailBlkVect &UnavailableBlocks);
478
479 /// Try to replace a load which executes on each loop iteraiton with Phi
480 /// translation of load in preheader and load(s) in conditionally executed
481 /// paths.
482 bool performLoopLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
483 UnavailBlkVect &UnavailableBlocks);
484
485 /// Eliminates partially redundant \p Load, replacing it with \p
486 /// AvailableLoads (connected by Phis if needed).
487 void eliminatePartiallyRedundantLoad(
488 LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
489 MapVector<BasicBlock *, Value *> &AvailableLoads,
490 MapVector<BasicBlock *, LoadInst *> *CriticalEdgePredAndLoad);
491
492 // Other helper routines.
493 bool processInstruction(Instruction *I);
494 bool processBlock(BasicBlock *BB);
495 bool iterateOnFunction(Function &F);
496 bool performPRE(Function &F);
497 bool performScalarPRE(Instruction *I);
498 bool performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
499 BasicBlock *Curr, unsigned int ValNo);
500 Value *findLeader(const BasicBlock *BB, uint32_t Num);
501 void cleanupGlobalSets();
502 void removeInstruction(Instruction *I);
503 void verifyRemoved(const Instruction *I) const;
504 bool splitCriticalEdges();
505 BasicBlock *splitCriticalEdges(BasicBlock *Pred, BasicBlock *Succ);
506 bool
507 propagateEquality(Value *LHS, Value *RHS,
508 const std::variant<BasicBlockEdge, Instruction *> &Root);
509 bool processFoldableCondBr(CondBrInst *BI);
510 void addDeadBlock(BasicBlock *BB);
511 void assignValNumForDeadCode();
512 void assignBlockRPONumber(Function &F);
513};
514
515/// Create a legacy GVN pass.
516LLVM_ABI FunctionPass *createGVNPass(bool ScalarPRE);
518
519/// A simple and fast domtree-based GVN pass to hoist common expressions
520/// from sibling branches.
521struct GVNHoistPass : OptionalPassInfoMixin<GVNHoistPass> {
522 /// Run the pass over the function.
524};
525
526/// Uses an "inverted" value numbering to decide the similarity of
527/// expressions and sinks similar expressions into successors.
528struct GVNSinkPass : OptionalPassInfoMixin<GVNSinkPass> {
529 /// Run the pass over the function.
531};
532
533} // end namespace llvm
534
535#endif // LLVM_TRANSFORMS_SCALAR_GVN_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis false
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
early cse Early CSE w MemorySSA
Hexagon Common GEP
#define _
This header defines various interfaces for pass management in LLVM.
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file implements a map that provides insertion order iteration.
uint64_t IntrinsicInst * II
ppc ctr loops PowerPC CTR Loops Verify
const SmallVectorImpl< MachineOperand > & Cond
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
Value * RHS
Value * LHS
Value handle that asserts if the Value is deleted.
This represents the llvm.assume intrinsic.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
Conditional Branch instruction.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
Context-sensitive CaptureAnalysis provider, which computes and caches the earliest common dominator c...
This instruction extracts a struct member or array element value from an aggregate value.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
const LeaderTableEntry value_type
Definition GVN.h:290
std::forward_iterator_tag iterator_category
Definition GVN.h:289
bool operator==(const leader_iterator &Other) const
Definition GVN.h:301
bool operator!=(const leader_iterator &Other) const
Definition GVN.h:304
leader_iterator(const LeaderListNode *C)
Definition GVN.h:295
This class holds the mapping between values and value numbers.
Definition GVN.h:158
void setMemDep(MemoryDependenceResults *M, bool MDEnabled=true)
Definition GVN.h:231
LLVM_ABI ValueTable(ValueTable &&Arg)
void setMemorySSA(MemorySSA *M, bool MSSAEnabled=false)
Definition GVN.h:235
LLVM_ABI uint32_t lookupPtrToInt(Value *Ptr, Type *Ty)
Returns the value number of ptrtoint Ptr to \Ty.
Definition GVN.cpp:756
LLVM_ABI uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
Returns the value number of the given comparison, assigning it a new number if it did not have one be...
Definition GVN.cpp:748
uint32_t getNextUnusedValueNumber()
Definition GVN.h:240
LLVM_ABI uint32_t lookup(Value *V, bool Verify=true) const
Returns the value number of the specified value.
Definition GVN.cpp:735
LLVM_ABI ValueTable & operator=(const ValueTable &Arg)
void setAliasAnalysis(AAResults *A)
Definition GVN.h:229
LLVM_ABI void add(Value *V, uint32_t Num)
add - Insert a value into the table with a specified value number.
Definition GVN.cpp:467
LLVM_ABI void clear()
Remove all entries from the ValueTable.
Definition GVN.cpp:764
LLVM_ABI bool exists(Value *V) const
Returns true if a value number exists for the specified value.
Definition GVN.cpp:638
LLVM_ABI ValueTable(const ValueTable &Arg)
LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA)
Definition GVN.cpp:642
AAResults * getAliasAnalysis() const
Definition GVN.h:230
LLVM_ABI uint32_t phiTranslate(const BasicBlock *BB, const BasicBlock *PhiBlock, uint32_t Num, GVNPass &GVN)
Wrap phiTranslateImpl to provide caching functionality.
Definition GVN.cpp:2903
void setDomTree(DominatorTree *D)
Definition GVN.h:239
LLVM_ABI void eraseTranslateCacheEntry(uint32_t Num, const BasicBlock &CurrBlock)
Erase stale entry from phiTranslate cache so phiTranslate can be computed again.
Definition GVN.cpp:3033
LLVM_ABI void erase(Value *V)
Remove a value from the value numbering.
Definition GVN.cpp:777
LLVM_ABI void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
Definition GVN.cpp:789
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition GVN.cpp:879
LLVM_ABI void salvageAndRemoveInstruction(Instruction *I)
This removes the specified instruction from our various maps and marks it for deletion.
Definition GVN.cpp:931
AAResults * getAliasAnalysis() const
Definition GVN.h:145
LLVM_ABI bool isLoadPREEnabled() const
Definition GVN.cpp:858
GVNPass(GVNOptions Options={})
Definition GVN.h:131
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition GVN.cpp:911
LLVM_ABI bool isMemorySSAEnabled() const
Definition GVN.cpp:875
DominatorTree & getDominatorTree() const
Definition GVN.h:144
LLVM_ABI bool isLoadInLoopPREEnabled() const
Definition GVN.cpp:862
LLVM_ABI bool isScalarPREEnabled() const
Definition GVN.cpp:854
LLVM_ABI bool isLoadPRESplitBackedgeEnabled() const
Definition GVN.cpp:866
friend class GVNLegacyPass
Definition GVN.h:245
LLVM_ABI bool isMemDepEnabled() const
Definition GVN.cpp:871
MemoryDependenceResults & getMemDep() const
Definition GVN.h:146
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This class allows to keep track on instructions with implicit control flow.
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
A memory dependence query can return one of three different answers.
Provides a lazy, caching interface for making common memory aliasing information queries,...
Representation for a specific memory location.
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:702
This is a result from a NonLocal dependence query.
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
A vector that has set insertion semantics.
Definition SetVector.h:57
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
@ Load
The value being inserted comes from a load (InsertElement only).
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
LLVM_ABI FunctionPass * createGVNPass()
Definition GVN.cpp:4061
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
#define N
An information struct used to provide DenseMap with the various necessary components for a given valu...
A simple and fast domtree-based GVN pass to hoist common expressions from sibling branches.
Definition GVN.h:521
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
A set of parameters to control various transforms performed by GVN pass.
Definition GVN.h:73
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
Definition GVN.h:90
std::optional< bool > AllowLoadPRESplitBackedge
Definition GVN.h:77
std::optional< bool > AllowScalarPRE
Definition GVN.h:74
GVNOptions & setLoadInLoopPRE(bool LoadInLoopPRE)
Definition GVN.h:95
std::optional< bool > AllowLoadInLoopPRE
Definition GVN.h:76
std::optional< bool > AllowMemDep
Definition GVN.h:78
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
Definition GVN.h:107
GVNOptions & setScalarPRE(bool ScalarPRE)
Enables or disables PRE of scalars in GVN.
Definition GVN.h:84
std::optional< bool > AllowLoadPRE
Definition GVN.h:75
GVNOptions & setLoadPRESplitBackedge(bool LoadPRESplitBackedge)
Enables or disables PRE of loads in GVN.
Definition GVN.h:101
std::optional< bool > AllowMemorySSA
Definition GVN.h:79
GVNOptions()=default
GVNOptions & setMemorySSA(bool MemSSA)
Enables or disables use of MemorySSA.
Definition GVN.h:113
Represents an AvailableValue which can be rematerialized at the end of the associated BasicBlock.
Definition GVN.cpp:294
Represents a particular available value that we know how to materialize.
Definition GVN.cpp:198
LeaderTableEntry(Value *V, const BasicBlock *BB)
Definition GVN.h:271
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition GVN.h:528
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition GVNSink.cpp:844
A CRTP mix-in for passes that can be skipped.