15#ifndef LLVM_TRANSFORMS_SCALAR_GVN_H
16#define LLVM_TRANSFORMS_SCALAR_GVN_H
41class ExtractValueInst;
44class GetElementPtrInst;
45class ImplicitControlFlowTracking;
50class MemoryDependenceResults;
53class MemorySSAUpdater;
54class NonLocalDepResult;
55class OptimizationRemarkEmitter;
57class TargetLibraryInfo;
139 function_ref<StringRef(StringRef)> MapClassName2PassName);
169 std::vector<Expression> Expressions;
170 std::vector<uint32_t> ExprIdx;
186 bool IsMDEnabled =
false;
188 bool IsMSSAEnabled =
false;
204 std::pair<uint32_t, bool> assignExpNewValueNum(
Expression &Exp);
233 IsMDEnabled = MDEnabled;
237 IsMSSAEnabled = MSSAEnabled;
270 struct LeaderListNode {
272 LeaderListNode *Next;
279 const LeaderListNode *Current;
290 assert(Current &&
"Dereferenced end of leader list!");
291 Current = Current->Next;
295 return Current ==
Other.Current;
298 return Current !=
Other.Current;
304 auto I = NumToLeaders.
find(
N);
305 if (
I == NumToLeaders.
end()) {
307 leader_iterator(
nullptr));
311 leader_iterator(
nullptr));
316 LLVM_ABI void verifyRemoved(
const Value *Inst)
const;
318 NumToLeaders.
clear();
319 TableAllocator.
Reset();
322 LeaderMap LeaderTable;
327 SmallMapVector<Value *, Value *, 4> ReplaceOperandsWithMap;
331 DenseMap<AssertingVH<BasicBlock>,
uint32_t> BlockRPONumber;
336 bool InvalidBlockRPONumbers =
true;
338 using LoadDepVect = SmallVector<NonLocalDepResult, 64>;
339 using AvailValInBlkVect = SmallVector<gvn::AvailableValueInBlock, 64>;
340 using UnavailBlkVect = SmallVector<BasicBlock *, 64>;
342 bool runImpl(Function &
F, AssumptionCache &RunAC, DominatorTree &RunDT,
343 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
344 MemoryDependenceResults *RunMD, LoopInfo &LI,
345 OptimizationRemarkEmitter *ORE, MemorySSA *MSSA =
nullptr);
348 SmallVector<std::pair<Instruction *, unsigned>, 4> ToSplit;
351 bool processLoad(LoadInst *L);
352 bool processNonLocalLoad(LoadInst *L);
353 bool processAssumeIntrinsic(AssumeInst *
II);
357 std::optional<gvn::AvailableValue>
358 AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo, Value *
Address);
363 void AnalyzeLoadAvailability(LoadInst *Load, LoadDepVect &Deps,
364 AvailValInBlkVect &ValuesPerBlock,
365 UnavailBlkVect &UnavailableBlocks);
369 LoadInst *findLoadToHoistIntoPred(BasicBlock *Pred, BasicBlock *LoadBB,
372 bool PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
373 UnavailBlkVect &UnavailableBlocks);
378 bool performLoopLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
379 UnavailBlkVect &UnavailableBlocks);
383 void eliminatePartiallyRedundantLoad(
384 LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
385 MapVector<BasicBlock *, Value *> &AvailableLoads,
386 MapVector<BasicBlock *, LoadInst *> *CriticalEdgePredAndLoad);
389 bool processInstruction(Instruction *
I);
390 bool processBlock(BasicBlock *BB);
391 void dump(DenseMap<uint32_t, Value *> &Map)
const;
392 bool iterateOnFunction(Function &
F);
393 bool performPRE(Function &
F);
394 bool performScalarPRE(Instruction *
I);
395 bool performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
396 BasicBlock *Curr,
unsigned int ValNo);
398 void cleanupGlobalSets();
399 void removeInstruction(Instruction *
I);
400 void verifyRemoved(
const Instruction *
I)
const;
401 bool splitCriticalEdges();
402 BasicBlock *splitCriticalEdges(BasicBlock *Pred, BasicBlock *Succ);
403 bool replaceOperandsForInBlockEquality(Instruction *
I)
const;
404 bool propagateEquality(Value *
LHS, Value *
RHS,
const BasicBlockEdge &Root,
405 bool DominatesByEdge);
406 bool processFoldableCondBr(BranchInst *BI);
407 void addDeadBlock(BasicBlock *BB);
408 void assignValNumForDeadCode();
409 void assignBlockRPONumber(Function &
F);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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_NAMESPACE
This file defines the DenseMap class.
early cse Early CSE w MemorySSA
This header defines various interfaces for pass management in LLVM.
This file implements a map that provides insertion order iteration.
uint64_t IntrinsicInst * II
ppc ctr loops PowerPC CTR Loops Verify
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
A private abstract base class describing the concept of an individual alias analysis implementation.
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.
void setMemDep(MemoryDependenceResults *M, bool MDEnabled=true)
LLVM_ABI ValueTable(ValueTable &&Arg)
void setMemorySSA(MemorySSA *M, bool MSSAEnabled=false)
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...
uint32_t getNextUnusedValueNumber()
LLVM_ABI uint32_t lookup(Value *V, bool Verify=true) const
Returns the value number of the specified value.
LLVM_ABI ValueTable & operator=(const ValueTable &Arg)
void setAliasAnalysis(AAResults *A)
LLVM_ABI void add(Value *V, uint32_t Num)
add - Insert a value into the table with a specified value number.
LLVM_ABI void clear()
Remove all entries from the ValueTable.
LLVM_ABI bool exists(Value *V) const
Returns true if a value number exists for the specified value.
LLVM_ABI ValueTable(const ValueTable &Arg)
LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA)
AAResults * getAliasAnalysis() const
LLVM_ABI uint32_t phiTranslate(const BasicBlock *BB, const BasicBlock *PhiBlock, uint32_t Num, GVNPass &GVN)
Wrap phiTranslateImpl to provide caching functionality.
void setDomTree(DominatorTree *D)
LLVM_ABI void eraseTranslateCacheEntry(uint32_t Num, const BasicBlock &CurrBlock)
Erase stale entry from phiTranslate cache so phiTranslate can be computed again.
LLVM_ABI void erase(Value *V)
Remove a value from the value numbering.
LLVM_ABI void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
The core GVN pass object.
LLVM_ABI bool isPREEnabled() const
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
LLVM_ABI void salvageAndRemoveInstruction(Instruction *I)
This removes the specified instruction from our various maps and marks it for deletion.
AAResults * getAliasAnalysis() const
LLVM_ABI bool isLoadPREEnabled() const
GVNPass(GVNOptions Options={})
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
LLVM_ABI bool isMemorySSAEnabled() const
DominatorTree & getDominatorTree() const
LLVM_ABI bool isLoadInLoopPREEnabled() const
LLVM_ABI bool isLoadPRESplitBackedgeEnabled() const
LLVM_ABI 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,...
Encapsulates MemorySSA, including all data associated with memory accesses.
A set of analyses that are preserved following a run of a transformation pass.
A vector that has set insertion semantics.
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.
LLVM_ABI FunctionPass * createGVNPass()
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.
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.
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.
std::optional< bool > AllowMemorySSA
GVNOptions & setMemorySSA(bool MemSSA)
Enables or disables use of MemorySSA.
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
LLVM_ABI 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.