LLVM 23.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;
50class LoadInst;
51class LoopInfo;
52class MemDepResult;
53class MemoryAccess;
55class MemoryLocation;
56class MemorySSA;
60class PHINode;
62class Value;
63class IntrinsicInst;
64/// A private "module" namespace for types and utilities used by GVN. These
65/// are implementation details and should not be used by clients.
67
68struct AvailableValue;
70class GVNLegacyPass;
71
72} // end namespace gvn
73
74/// A set of parameters to control various transforms performed by GVN pass.
75// Each of the optional boolean parameters can be set to:
76/// true - enabling the transformation.
77/// false - disabling the transformation.
78/// None - relying on a global default.
79/// Intended use is to create a default object, modify parameters with
80/// additional setters and then pass it to GVN.
81struct GVNOptions {
82 std::optional<bool> AllowScalarPRE;
83 std::optional<bool> AllowLoadPRE;
84 std::optional<bool> AllowLoadInLoopPRE;
85 std::optional<bool> AllowLoadPRESplitBackedge;
86 std::optional<bool> AllowMemDep;
87 std::optional<bool> AllowMemorySSA;
88
89 GVNOptions() = default;
90
91 /// Enables or disables PRE of scalars in GVN.
92 GVNOptions &setScalarPRE(bool ScalarPRE) {
93 AllowScalarPRE = ScalarPRE;
94 return *this;
95 }
96
97 /// Enables or disables PRE of loads in GVN.
98 GVNOptions &setLoadPRE(bool LoadPRE) {
99 AllowLoadPRE = LoadPRE;
100 return *this;
101 }
102
103 GVNOptions &setLoadInLoopPRE(bool LoadInLoopPRE) {
104 AllowLoadInLoopPRE = LoadInLoopPRE;
105 return *this;
106 }
107
108 /// Enables or disables PRE of loads in GVN.
109 GVNOptions &setLoadPRESplitBackedge(bool LoadPRESplitBackedge) {
110 AllowLoadPRESplitBackedge = LoadPRESplitBackedge;
111 return *this;
112 }
113
114 /// Enables or disables use of MemDepAnalysis.
115 GVNOptions &setMemDep(bool MemDep) {
116 AllowMemDep = MemDep;
117 return *this;
118 }
119
120 /// Enables or disables use of MemorySSA.
121 GVNOptions &setMemorySSA(bool MemSSA) {
122 AllowMemorySSA = MemSSA;
123 return *this;
124 }
125};
126
127/// The core GVN pass object.
128///
129/// FIXME: We should have a good summary of the GVN algorithm implemented by
130/// this particular pass here.
131class GVNPass : public OptionalPassInfoMixin<GVNPass> {
132 GVNOptions Options;
133
134public:
135 struct Expression;
136
137 GVNPass(GVNOptions Options = {}) : Options(Options) {}
138
139 /// Run the pass over the function.
140 LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
141
142 LLVM_ABI void
143 printPipeline(raw_ostream &OS,
144 function_ref<StringRef(StringRef)> MapClassName2PassName);
145
146 /// This removes the specified instruction from
147 /// our various maps and marks it for deletion.
148 LLVM_ABI void salvageAndRemoveInstruction(Instruction *I);
149
150 DominatorTree &getDominatorTree() const { return *DT; }
151 AAResults *getAliasAnalysis() const { return VN.getAliasAnalysis(); }
152 MemoryDependenceResults &getMemDep() const { return *MD; }
153
154 LLVM_ABI bool isScalarPREEnabled() const;
155 LLVM_ABI bool isLoadPREEnabled() const;
156 LLVM_ABI bool isLoadInLoopPREEnabled() const;
158 LLVM_ABI bool isMemDepEnabled() const;
159 LLVM_ABI bool isMemorySSAEnabled() const;
160
161 /// This class holds the mapping between values and value numbers. It is used
162 /// as an efficient mechanism to determine the expression-wise equivalence of
163 /// two values.
165 DenseMap<Value *, uint32_t> ValueNumbering;
166 DenseMap<Expression, uint32_t> ExpressionNumbering;
167
168 // Expressions is the vector of Expression. ExprIdx is the mapping from
169 // value number to the index of Expression in Expressions. We use it
170 // instead of a DenseMap because filling such mapping is faster than
171 // filling a DenseMap and the compile time is a little better.
172 uint32_t NextExprNumber = 0;
173
174 std::vector<Expression> Expressions;
175 std::vector<uint32_t> ExprIdx;
176
177 // Value number to PHINode mapping. Used for phi-translate in scalarpre.
179
180 // Value number to BasicBlock mapping. Used for phi-translate across
181 // MemoryPhis.
183
184 // Cache for phi-translate in scalarpre.
185 using PhiTranslateMap =
187 PhiTranslateMap PhiTranslateTable;
188
189 AAResults *AA = nullptr;
190 MemoryDependenceResults *MD = nullptr;
191 bool IsMDEnabled = false;
192 MemorySSA *MSSA = nullptr;
193 bool IsMSSAEnabled = false;
194 DominatorTree *DT = nullptr;
195
196 uint32_t NextValueNumber = 1;
197
198 Expression createExpr(Instruction *I);
199 Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
200 Value *LHS, Value *RHS);
201 Expression createExtractvalueExpr(ExtractValueInst *EI);
202 Expression createGEPExpr(GetElementPtrInst *GEP);
203 uint32_t lookupOrAddCall(CallInst *C);
204 uint32_t computeLoadStoreVN(Instruction *I);
205 uint32_t phiTranslateImpl(const BasicBlock *BB, const BasicBlock *PhiBlock,
206 uint32_t Num, GVNPass &GVN);
207 bool areCallValsEqual(uint32_t Num, uint32_t NewNum, const BasicBlock *Pred,
208 const BasicBlock *PhiBlock, GVNPass &GVN);
209 std::pair<uint32_t, bool> assignExpNewValueNum(Expression &Exp);
210 bool areAllValsInBB(uint32_t Num, const BasicBlock *BB, GVNPass &GVN);
211 void addMemoryStateToExp(Instruction *I, Expression &Exp);
212
213 public:
219
222 LLVM_ABI uint32_t lookup(Value *V, bool Verify = true) const;
224 Value *LHS, Value *RHS);
227 const BasicBlock *PhiBlock, uint32_t Num,
228 GVNPass &GVN);
230 const BasicBlock &CurrBlock);
231 LLVM_ABI bool exists(Value *V) const;
232 LLVM_ABI void add(Value *V, uint32_t Num);
233 LLVM_ABI void clear();
234 LLVM_ABI void erase(Value *V);
235 void setAliasAnalysis(AAResults *A) { AA = A; }
236 AAResults *getAliasAnalysis() const { return AA; }
237 void setMemDep(MemoryDependenceResults *M, bool MDEnabled = true) {
238 MD = M;
239 IsMDEnabled = MDEnabled;
240 }
241 void setMemorySSA(MemorySSA *M, bool MSSAEnabled = false) {
242 MSSA = M;
243 IsMSSAEnabled = MSSAEnabled;
244 }
245 void setDomTree(DominatorTree *D) { DT = D; }
246 uint32_t getNextUnusedValueNumber() { return NextValueNumber; }
247 LLVM_ABI void verifyRemoved(const Value *) const;
248 };
249
250private:
251 friend class gvn::GVNLegacyPass;
252 friend struct DenseMapInfo<Expression>;
253
254 MemoryDependenceResults *MD = nullptr;
255 DominatorTree *DT = nullptr;
256 const TargetLibraryInfo *TLI = nullptr;
257 AssumptionCache *AC = nullptr;
258 SetVector<BasicBlock *> DeadBlocks;
259 OptimizationRemarkEmitter *ORE = nullptr;
260 ImplicitControlFlowTracking *ICF = nullptr;
261 LoopInfo *LI = nullptr;
262 AAResults *AA = nullptr;
263 MemorySSAUpdater *MSSAU = nullptr;
264
265 ValueTable VN;
266
267 /// A mapping from value numbers to lists of Value*'s that
268 /// have that value number. Use findLeader to query it.
269 class LeaderMap {
270 public:
272 // Use AssertingVH here to catch dangling Value*'s in the leader table.
273 // Will crash if the value gets deleted before the AssertingVH is
274 // destroyed.
278 };
279
280 private:
281 struct LeaderListNode {
282 LeaderTableEntry Entry;
283 LeaderListNode *Next;
284 LeaderListNode(Value *V, const BasicBlock *BB, LeaderListNode *Next)
285 : Entry(V, BB), Next(Next) {}
286 };
287 DenseMap<uint32_t, LeaderListNode> NumToLeaders;
288 BumpPtrAllocator TableAllocator;
289
290 public:
292 const LeaderListNode *Current;
293
294 public:
295 using iterator_category = std::forward_iterator_tag;
297 using difference_type = std::ptrdiff_t;
300
301 leader_iterator(const LeaderListNode *C) : Current(C) {}
303 assert(Current && "Dereferenced end of leader list!");
304 Current = Current->Next;
305 return *this;
306 }
307 bool operator==(const leader_iterator &Other) const {
308 return Current == Other.Current;
309 }
310 bool operator!=(const leader_iterator &Other) const {
311 return Current != Other.Current;
312 }
313 reference operator*() const { return Current->Entry; }
314 };
315
317 auto I = NumToLeaders.find(N);
318 if (I == NumToLeaders.end()) {
319 return iterator_range(leader_iterator(nullptr),
320 leader_iterator(nullptr));
321 }
322
323 return iterator_range(leader_iterator(&I->second),
324 leader_iterator(nullptr));
325 }
326
327 LLVM_ABI void insert(uint32_t N, Value *V, const BasicBlock *BB);
328 LLVM_ABI void erase(uint32_t N, Instruction *I, const BasicBlock *BB);
329 void clear() {
330 // Manually destroy non-head nodes (in BumpPtrAllocator) to properly
331 // clean up AssertingVH handles before Reset(). Head nodes are destroyed
332 // by NumToLeaders.clear() below.
333 for (auto &[_, HeadNode] : NumToLeaders) {
334 LeaderListNode *N = HeadNode.Next;
335 while (N) {
336 auto *Next = N->Next;
337 N->~LeaderListNode();
338 N = Next;
339 }
340 }
341 NumToLeaders.clear();
342 TableAllocator.Reset();
343 }
344 };
345 LeaderMap LeaderTable;
346
347 // Map the block to reversed postorder traversal number. It is used to
348 // find back edge easily.
349 DenseMap<AssertingVH<BasicBlock>, uint32_t> BlockRPONumber;
350
351 // This is set 'true' initially and also when new blocks have been added to
352 // the function being analyzed. This boolean is used to control the updating
353 // of BlockRPONumber prior to accessing the contents of BlockRPONumber.
354 bool InvalidBlockRPONumbers = true;
355
356 using LoadDepVect = SmallVector<NonLocalDepResult, 64>;
357 using AvailValInBlkVect = SmallVector<gvn::AvailableValueInBlock, 64>;
358 using UnavailBlkVect = SmallVector<BasicBlock *, 64>;
359
360 bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
361 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
362 MemoryDependenceResults *RunMD, LoopInfo &LI,
363 OptimizationRemarkEmitter *ORE, MemorySSA *MSSA = nullptr);
364
365 // List of critical edges to be split between iterations.
367
368 enum class DepKind {
369 Other = 0, // Unknown value.
370 Def, // Exactly overlapping locations.
371 Clobber, // Reaching value superset of needed bits.
372 Select, // Reaching value is a select of two reaching addresses.
373 };
374
375 // Describe a memory location value, such that there exists a path to a point
376 // in the program, along which that memory location is not modified.
377 struct ReachingMemVal {
378 DepKind Kind;
379 BasicBlock *Block;
380 const Value *Addr;
381 Instruction *Inst;
382 int32_t Offset;
383 // For DepKind::Select only: the condition and the two addresses referenced
384 // by the "true" and "false" side of the select-dependent load.
385 const Value *SelCond = nullptr;
386 const Value *SelTrueAddr = nullptr;
387 const Value *SelFalseAddr = nullptr;
388
389 static ReachingMemVal getUnknown(BasicBlock *BB, const Value *Addr,
390 Instruction *Inst = nullptr) {
391 return {DepKind::Other, BB, Addr, Inst, -1};
392 }
393
394 static ReachingMemVal getDef(const Value *Addr, Instruction *Inst) {
395 return {DepKind::Def, Inst->getParent(), Addr, Inst, -1};
396 }
397
398 static ReachingMemVal getClobber(const Value *Addr, Instruction *Inst,
399 int32_t Offset = -1) {
400 return {DepKind::Clobber, Inst->getParent(), Addr, Inst, Offset};
401 }
402
403 static ReachingMemVal getSelect(BasicBlock *BB, const Value *Cond,
404 const Value *TrueAddr,
405 const Value *FalseAddr) {
406 return {DepKind::Select, BB, nullptr, nullptr, -1, Cond,
407 TrueAddr, FalseAddr};
408 }
409 };
410
411 struct DependencyBlockInfo {
412 DependencyBlockInfo() = delete;
413 DependencyBlockInfo(const PHITransAddr &Addr, MemoryAccess *ClobberMA)
414 : Addr(Addr), InitialClobberMA(ClobberMA), ClobberMA(ClobberMA),
415 ForceUnknown(false), Visited(false) {}
416 PHITransAddr Addr;
417 MemoryAccess *InitialClobberMA;
418 MemoryAccess *ClobberMA;
419 std::optional<ReachingMemVal> MemVal;
420 bool ForceUnknown : 1;
421 bool Visited : 1;
422 };
423
424 using DependencyBlockSet = DenseMap<BasicBlock *, DependencyBlockInfo>;
425
426 std::optional<GVNPass::ReachingMemVal> scanMemoryAccessesUsers(
427 const MemoryLocation &Loc, bool IsInvariantLoad, BasicBlock *BB,
428 const SmallVectorImpl<MemoryAccess *> &ClobbersList, MemorySSA &MSSA,
429 BatchAAResults &AA, LoadInst *L = nullptr);
430
431 std::optional<GVNPass::ReachingMemVal>
432 accessMayModifyLocation(MemoryAccess *ClobberMA, const MemoryLocation &Loc,
433 bool IsInvariantLoad, BasicBlock *BB, MemorySSA &MSSA,
434 BatchAAResults &AA);
435
436 bool collectPredecessors(BasicBlock *BB, const PHITransAddr &Addr,
437 MemoryAccess *ClobberMA, DependencyBlockSet &Blocks,
438 SmallVectorImpl<BasicBlock *> &Worklist);
439
440 void collectClobberList(SmallVectorImpl<MemoryAccess *> &Clobbers,
441 BasicBlock *BB, const DependencyBlockInfo &StartInfo,
442 const DependencyBlockSet &Blocks, MemorySSA &MSSA);
443
444 bool findReachingValuesForLoad(LoadInst *Inst,
445 SmallVectorImpl<ReachingMemVal> &Values,
446 MemorySSA &MSSA, AAResults &AA);
447
448 // Helper functions of redundant load elimination.
449 bool processLoad(LoadInst *L);
450 bool processMaskedLoad(IntrinsicInst *I);
451 bool processNonLocalLoad(LoadInst *L);
452 bool processNonLocalLoad(LoadInst *L, SmallVectorImpl<ReachingMemVal> &Deps);
453 bool processAssumeIntrinsic(AssumeInst *II);
454
455 /// Given a local dependency (Def or Clobber) determine if a value is
456 /// available for the load.
457 std::optional<gvn::AvailableValue>
458 AnalyzeLoadAvailability(LoadInst *Load, const ReachingMemVal &Dep,
459 Value *Address);
460
461 /// Given a select-dependency for the load (the load address is a select of
462 /// \p TrueAddr and \p FalseAddr guarded by \p Cond), determine whether a
463 /// value is available by finding dominating values for both addresses. If
464 /// so, the load can be rematerialized as a select of those two values.
465 std::optional<gvn::AvailableValue>
466 AnalyzeSelectAvailability(LoadInst *Load, Value *Cond, Value *TrueAddr,
467 Value *FalseAddr, Instruction *From);
468
469 /// Given a list of non-local dependencies, determine if a value is
470 /// available for the load in each specified block. If it is, add it to
471 /// ValuesPerBlock. If not, add it to UnavailableBlocks.
472 void AnalyzeLoadAvailability(LoadInst *Load,
473 SmallVectorImpl<ReachingMemVal> &Deps,
474 AvailValInBlkVect &ValuesPerBlock,
475 UnavailBlkVect &UnavailableBlocks);
476
477 /// Given a critical edge from Pred to LoadBB, find a load instruction
478 /// which is identical to Load from another successor of Pred.
479 LoadInst *findLoadToHoistIntoPred(BasicBlock *Pred, BasicBlock *LoadBB,
480 LoadInst *Load);
481
482 bool PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
483 UnavailBlkVect &UnavailableBlocks);
484
485 /// Try to replace a load which executes on each loop iteraiton with Phi
486 /// translation of load in preheader and load(s) in conditionally executed
487 /// paths.
488 bool performLoopLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
489 UnavailBlkVect &UnavailableBlocks);
490
491 /// Eliminates partially redundant \p Load, replacing it with \p
492 /// AvailableLoads (connected by Phis if needed).
493 void eliminatePartiallyRedundantLoad(
494 LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
495 MapVector<BasicBlock *, Value *> &AvailableLoads,
496 MapVector<BasicBlock *, LoadInst *> *CriticalEdgePredAndLoad);
497
498 // Other helper routines.
499 bool processInstruction(Instruction *I);
500 bool processBlock(BasicBlock *BB);
501 void dump(DenseMap<uint32_t, Value *> &Map) const;
502 bool iterateOnFunction(Function &F);
503 bool performPRE(Function &F);
504 bool performScalarPRE(Instruction *I);
505 bool performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
506 BasicBlock *Curr, unsigned int ValNo);
507 Value *findLeader(const BasicBlock *BB, uint32_t Num);
508 void cleanupGlobalSets();
509 void removeInstruction(Instruction *I);
510 void verifyRemoved(const Instruction *I) const;
511 bool splitCriticalEdges();
512 BasicBlock *splitCriticalEdges(BasicBlock *Pred, BasicBlock *Succ);
513 bool
514 propagateEquality(Value *LHS, Value *RHS,
515 const std::variant<BasicBlockEdge, Instruction *> &Root);
516 bool processFoldableCondBr(CondBrInst *BI);
517 void addDeadBlock(BasicBlock *BB);
518 void assignValNumForDeadCode();
519 void assignBlockRPONumber(Function &F);
520};
521
522/// Create a legacy GVN pass.
523LLVM_ABI FunctionPass *createGVNPass(bool ScalarPRE);
525
526/// A simple and fast domtree-based GVN pass to hoist common expressions
527/// from sibling branches.
528struct GVNHoistPass : OptionalPassInfoMixin<GVNHoistPass> {
529 /// Run the pass over the function.
531};
532
533/// Uses an "inverted" value numbering to decide the similarity of
534/// expressions and sinks similar expressions into successors.
535struct GVNSinkPass : OptionalPassInfoMixin<GVNSinkPass> {
536 /// Run the pass over the function.
538};
539
540} // end namespace llvm
541
542#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
#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
Definition Compiler.h:143
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:296
std::forward_iterator_tag iterator_category
Definition GVN.h:295
bool operator==(const leader_iterator &Other) const
Definition GVN.h:307
bool operator!=(const leader_iterator &Other) const
Definition GVN.h:310
leader_iterator(const LeaderListNode *C)
Definition GVN.h:301
This class holds the mapping between values and value numbers.
Definition GVN.h:164
void setMemDep(MemoryDependenceResults *M, bool MDEnabled=true)
Definition GVN.h:237
LLVM_ABI ValueTable(ValueTable &&Arg)
void setMemorySSA(MemorySSA *M, bool MSSAEnabled=false)
Definition GVN.h:241
LLVM_ABI uint32_t lookupPtrToInt(Value *Ptr, Type *Ty)
Returns the value number of ptrtoint Ptr to \Ty.
Definition GVN.cpp:754
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:746
uint32_t getNextUnusedValueNumber()
Definition GVN.h:246
LLVM_ABI uint32_t lookup(Value *V, bool Verify=true) const
Returns the value number of the specified value.
Definition GVN.cpp:733
LLVM_ABI ValueTable & operator=(const ValueTable &Arg)
void setAliasAnalysis(AAResults *A)
Definition GVN.h:235
LLVM_ABI void add(Value *V, uint32_t Num)
add - Insert a value into the table with a specified value number.
Definition GVN.cpp:465
LLVM_ABI void clear()
Remove all entries from the ValueTable.
Definition GVN.cpp:762
LLVM_ABI bool exists(Value *V) const
Returns true if a value number exists for the specified value.
Definition GVN.cpp:636
LLVM_ABI ValueTable(const ValueTable &Arg)
LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA)
Definition GVN.cpp:640
AAResults * getAliasAnalysis() const
Definition GVN.h:236
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:2912
void setDomTree(DominatorTree *D)
Definition GVN.h:245
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:3042
LLVM_ABI void erase(Value *V)
Remove a value from the value numbering.
Definition GVN.cpp:775
LLVM_ABI void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
Definition GVN.cpp:787
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition GVN.cpp:877
LLVM_ABI void salvageAndRemoveInstruction(Instruction *I)
This removes the specified instruction from our various maps and marks it for deletion.
Definition GVN.cpp:929
AAResults * getAliasAnalysis() const
Definition GVN.h:151
LLVM_ABI bool isLoadPREEnabled() const
Definition GVN.cpp:856
GVNPass(GVNOptions Options={})
Definition GVN.h:137
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition GVN.cpp:909
LLVM_ABI bool isMemorySSAEnabled() const
Definition GVN.cpp:873
DominatorTree & getDominatorTree() const
Definition GVN.h:150
LLVM_ABI bool isLoadInLoopPREEnabled() const
Definition GVN.cpp:860
LLVM_ABI bool isScalarPREEnabled() const
Definition GVN.cpp:852
LLVM_ABI bool isLoadPRESplitBackedgeEnabled() const
Definition GVN.cpp:864
LLVM_ABI bool isMemDepEnabled() const
Definition GVN.cpp:869
MemoryDependenceResults & getMemDep() const
Definition GVN.h:152
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
A private "module" namespace for types and utilities used by GVN.
Definition GVN.h:66
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
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:4070
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:528
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:81
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
Definition GVN.h:98
std::optional< bool > AllowLoadPRESplitBackedge
Definition GVN.h:85
std::optional< bool > AllowScalarPRE
Definition GVN.h:82
GVNOptions & setLoadInLoopPRE(bool LoadInLoopPRE)
Definition GVN.h:103
std::optional< bool > AllowLoadInLoopPRE
Definition GVN.h:84
std::optional< bool > AllowMemDep
Definition GVN.h:86
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
Definition GVN.h:115
GVNOptions & setScalarPRE(bool ScalarPRE)
Enables or disables PRE of scalars in GVN.
Definition GVN.h:92
std::optional< bool > AllowLoadPRE
Definition GVN.h:83
GVNOptions & setLoadPRESplitBackedge(bool LoadPRESplitBackedge)
Enables or disables PRE of loads in GVN.
Definition GVN.h:109
std::optional< bool > AllowMemorySSA
Definition GVN.h:87
GVNOptions()=default
GVNOptions & setMemorySSA(bool MemSSA)
Enables or disables use of MemorySSA.
Definition GVN.h:121
LeaderTableEntry(Value *V, const BasicBlock *BB)
Definition GVN.h:277
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition GVN.h:535
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.
Represents an AvailableValue which can be rematerialized at the end of the associated BasicBlock.
Definition GVN.cpp:292
Represents a particular available value that we know how to materialize.
Definition GVN.cpp:196