15#ifndef LLVM_TRANSFORMS_SCALAR_GVN_H
16#define LLVM_TRANSFORMS_SCALAR_GVN_H
41class ExtractValueInst;
44class GetElementPtrInst;
45class ImplicitControlFlowTracking;
49class MemoryDependenceResults;
51class MemorySSAUpdater;
52class NonLocalDepResult;
53class OptimizationRemarkEmitter;
55class TargetLibraryInfo;
129 function_ref<StringRef(StringRef)> MapClassName2PassName);
161 std::vector<Expression> Expressions;
162 std::vector<uint32_t> ExprIdx;
188 std::pair<uint32_t, bool> assignExpNewValueNum(
Expression &exp);
243 struct LeaderListNode {
245 LeaderListNode *Next;
252 const LeaderListNode *Current;
263 assert(Current &&
"Dereferenced end of leader list!");
264 Current = Current->Next;
268 return Current ==
Other.Current;
271 return Current !=
Other.Current;
277 auto I = NumToLeaders.
find(
N);
278 if (
I == NumToLeaders.
end()) {
280 leader_iterator(
nullptr));
284 leader_iterator(
nullptr));
287 void insert(
uint32_t N, Value *V,
const BasicBlock *BB);
288 void erase(
uint32_t N, Instruction *
I,
const BasicBlock *BB);
289 void verifyRemoved(
const Value *Inst)
const;
291 NumToLeaders.
clear();
292 TableAllocator.
Reset();
295 LeaderMap LeaderTable;
300 SmallMapVector<Value *, Value *, 4> ReplaceOperandsWithMap;
301 SmallVector<Instruction *, 8> InstrsToErase;
305 DenseMap<AssertingVH<BasicBlock>,
uint32_t> BlockRPONumber;
310 bool InvalidBlockRPONumbers =
true;
312 using LoadDepVect = SmallVector<NonLocalDepResult, 64>;
313 using AvailValInBlkVect = SmallVector<gvn::AvailableValueInBlock, 64>;
314 using UnavailBlkVect = SmallVector<BasicBlock *, 64>;
316 bool runImpl(Function &
F, AssumptionCache &RunAC, DominatorTree &RunDT,
317 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
318 MemoryDependenceResults *RunMD, LoopInfo &LI,
319 OptimizationRemarkEmitter *ORE, MemorySSA *MSSA =
nullptr);
322 SmallVector<std::pair<Instruction *, unsigned>, 4> toSplit;
325 bool processLoad(LoadInst *L);
326 bool processNonLocalLoad(LoadInst *L);
327 bool processAssumeIntrinsic(AssumeInst *
II);
331 std::optional<gvn::AvailableValue>
332 AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo, Value *
Address);
337 void AnalyzeLoadAvailability(LoadInst *Load, LoadDepVect &Deps,
338 AvailValInBlkVect &ValuesPerBlock,
339 UnavailBlkVect &UnavailableBlocks);
343 LoadInst *findLoadToHoistIntoPred(BasicBlock *Pred, BasicBlock *LoadBB,
346 bool PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
347 UnavailBlkVect &UnavailableBlocks);
352 bool performLoopLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
353 UnavailBlkVect &UnavailableBlocks);
357 void eliminatePartiallyRedundantLoad(
358 LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
359 MapVector<BasicBlock *, Value *> &AvailableLoads,
360 MapVector<BasicBlock *, LoadInst *> *CriticalEdgePredAndLoad);
363 bool processInstruction(Instruction *
I);
364 bool processBlock(BasicBlock *BB);
365 void dump(DenseMap<uint32_t, Value *> &d)
const;
366 bool iterateOnFunction(Function &
F);
367 bool performPRE(Function &
F);
368 bool performScalarPRE(Instruction *
I);
369 bool performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
370 BasicBlock *Curr,
unsigned int ValNo);
372 void cleanupGlobalSets();
373 void removeInstruction(Instruction *
I);
374 void verifyRemoved(
const Instruction *
I)
const;
375 bool splitCriticalEdges();
376 BasicBlock *splitCriticalEdges(BasicBlock *Pred, BasicBlock *Succ);
377 bool replaceOperandsForInBlockEquality(Instruction *
I)
const;
378 bool propagateEquality(Value *
LHS, Value *
RHS,
const BasicBlockEdge &Root,
379 bool DominatesByEdge);
380 bool processFoldableCondBr(BranchInst *BI);
381 void addDeadBlock(BasicBlock *BB);
382 void assignValNumForDeadCode();
383 void assignBlockRPONumber(Function &
F);
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_LIBRARY_VISIBILITY
This file defines the DenseMap class.
early cse Early CSE w MemorySSA
This file implements a map that provides insertion order iteration.
uint64_t IntrinsicInst * II
ppc ctr loops PowerPC CTR Loops Verify
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Allocate memory in an ever growing pool, as if by bump-pointer.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
iterator find(const_arg_type_t< KeyT > Val)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
std::forward_iterator_tag iterator_category
bool operator==(const leader_iterator &Other) const
bool operator!=(const leader_iterator &Other) const
leader_iterator(const LeaderListNode *C)
leader_iterator & operator++()
std::ptrdiff_t difference_type
reference operator*() const
This class holds the mapping between values and value numbers.
ValueTable(ValueTable &&Arg)
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...
uint32_t getNextUnusedValueNumber()
uint32_t lookupOrAdd(Value *V)
lookup_or_add - Returns the value number for the specified value, assigning it a new number if it did...
uint32_t lookup(Value *V, bool Verify=true) const
Returns the value number of the specified value.
ValueTable & operator=(const ValueTable &Arg)
void setAliasAnalysis(AAResults *A)
void clear()
Remove all entries from the ValueTable.
bool exists(Value *V) const
Returns true if a value number exists for the specified value.
ValueTable(const ValueTable &Arg)
AAResults * getAliasAnalysis() const
uint32_t phiTranslate(const BasicBlock *BB, const BasicBlock *PhiBlock, uint32_t Num, GVNPass &Gvn)
Wrap phiTranslateImpl to provide caching functionality.
void setMemDep(MemoryDependenceResults *M)
void erase(Value *v)
Remove a value from the value numbering.
void add(Value *V, uint32_t num)
add - Insert a value into the table with a specified value number.
void setDomTree(DominatorTree *D)
void eraseTranslateCacheEntry(uint32_t Num, const BasicBlock &CurrBlock)
Erase stale entry from phiTranslate cache so phiTranslate can be computed again.
void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
The core GVN pass object.
bool isPREEnabled() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
AAResults * getAliasAnalysis() const
bool isLoadPREEnabled() const
GVNPass(GVNOptions Options={})
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
DominatorTree & getDominatorTree() const
bool isLoadInLoopPREEnabled() const
bool isLoadPRESplitBackedgeEnabled() const
void markInstructionForDeletion(Instruction *I)
This removes the specified instruction from our various maps and marks it for deletion.
bool isMemDepEnabled() const
MemoryDependenceResults & getMemDep() const
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.
Provides a lazy, caching interface for making common memory aliasing information queries,...
A set of analyses that are preserved following a run of a transformation pass.
A vector that has set insertion semantics.
void push_back(const T &Elt)
Provides information about what library functions are available for the current target.
LLVM Value Representation.
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createGVNPass(bool NoMemDepAnalysis=false)
Create a legacy GVN pass.
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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
A set of parameters to control various transforms performed by GVN pass.
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
std::optional< bool > AllowLoadPRESplitBackedge
GVNOptions & setPRE(bool PRE)
Enables or disables PRE in GVN.
GVNOptions & setLoadInLoopPRE(bool LoadInLoopPRE)
std::optional< bool > AllowPRE
std::optional< bool > AllowLoadInLoopPRE
std::optional< bool > AllowMemDep
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
std::optional< bool > AllowLoadPRE
GVNOptions & setLoadPRESplitBackedge(bool LoadPRESplitBackedge)
Enables or disables PRE of loads in GVN.
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
A CRTP mix-in to automatically provide informational APIs needed for passes.
Represents an AvailableValue which can be rematerialized at the end of the associated BasicBlock.
Represents a particular available value that we know how to materialize.