Go to the documentation of this file.
25 #define DEBUG_TYPE "sink"
27 STATISTIC(NumSunk,
"Number of instructions sunk");
28 STATISTIC(NumSinkIter,
"Number of sinking iterations");
38 if (
LoadInst *L = dyn_cast<LoadInst>(Inst)) {
49 if (
auto *Call = dyn_cast<CallBase>(Inst)) {
52 if (Call->isConvergent())
67 assert(Inst &&
"Instruction to be sunk is null");
68 assert(SuccToSinkTo &&
"Candidate sink target is null");
93 if (succ !=
nullptr && succ != cur)
108 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
109 if (AI->isStaticAlloca())
131 Instruction *UseInst = cast<Instruction>(U.getUser());
136 if (
PHINode *PN = dyn_cast<PHINode>(UseInst)) {
140 UseBlock = PN->getIncomingBlock(Num);
145 SuccToSinkTo = UseBlock;
154 while (SuccToSinkTo !=
BB &&
157 if (SuccToSinkTo ==
BB)
158 SuccToSinkTo =
nullptr;
177 if (
BB.getTerminator()->getNumSuccessors() <= 1)
return false;
184 bool MadeChange =
false;
189 bool ProcessedBegin =
false;
196 ProcessedBegin =
I ==
BB.begin();
209 }
while (!ProcessedBegin);
216 bool MadeChange, EverMadeChange =
false;
220 LLVM_DEBUG(
dbgs() <<
"Sinking iteration " << NumSinkIter <<
"\n");
224 EverMadeChange |= MadeChange;
226 }
while (MadeChange);
228 return EverMadeChange;
253 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
254 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
255 auto &
AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
A set of analyses that are preserved following a run of a transformation pass.
bool isTerminator() const
A manager for alias analyses.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
This is an optimization pass for GlobalISel generic memory operations.
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
Find nearest common dominator basic block for basic block A and B.
InstListType::iterator iterator
Instruction iterators...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represents a single loop in the control flow graph.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
The legacy pass manager's analysis pass to compute loop information.
static bool SinkInstruction(Instruction *Inst, SmallPtrSetImpl< Instruction * > &Stores, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
SinkInstruction - Determine whether it is safe to sink the specified machine instruction out of its c...
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
bool mayThrow() const
Return true if this instruction may throw an exception.
DomTreeNodeBase * getIDom() const
bool isExceptionalTerminator() const
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
bool willReturn() const
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static bool IsAcceptableTarget(Instruction *Inst, BasicBlock *SuccToSinkTo, DominatorTree &DT, LoopInfo &LI)
IsAcceptableTarget - Return true if it is possible to sink the instruction in the specified basic blo...
Represent the analysis usage information of a pass.
iterator_range< use_iterator > uses()
static bool iterativelySinkInstructions(Function &F, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Legacy analysis pass which computes a DominatorTree.
STATISTIC(NumFunctions, "Total number of functions")
FunctionPass * createSinkingPass()
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
static unsigned getIncomingValueNumForOperand(unsigned i)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
gvn sink
When an instruction is found to only be used outside of the loop, this function moves it to the exit ...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
bool mayReadFromMemory() const
Return true if this instruction may read memory.
An instruction for reading from memory.
static bool runOnFunction(Function &F, bool PostInlining)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA, SmallPtrSetImpl< Instruction * > &Stores)
bool isDebugOrPseudoInst() const
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
Analysis pass which computes a DominatorTree.
void preserveSet()
Mark an analysis set as preserved.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
const BasicBlock * getParent() const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
AnalysisUsage & addRequired()
an instruction to allocate memory on the stack
static bool ProcessBlock(BasicBlock &BB, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
void initializeSinkingLegacyPassPass(PassRegistry &)
Representation for a specific memory location.
Analysis pass that exposes the LoopInfo for a function.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
A Use represents the edge between a Value definition and its users.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.