30 #define DEBUG_TYPE "sink" 32 STATISTIC(NumSunk,
"Number of instructions sunk");
33 STATISTIC(NumSinkIter,
"Number of sinking iterations");
45 Instruction *UseInst = cast<Instruction>(U.getUser());
47 if (
PHINode *PN = dyn_cast<PHINode>(UseInst)) {
51 UseBlock = PN->getIncomingBlock(Num);
68 if (
LoadInst *L = dyn_cast<LoadInst>(Inst)) {
79 if (
auto *Call = dyn_cast<CallBase>(Inst)) {
97 assert(Inst &&
"Instruction to be sunk is null");
98 assert(SuccToSinkTo &&
"Candidate sink target is null");
128 if (succ !=
nullptr && succ != cur)
145 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
146 if (AI->isStaticAlloca())
170 I !=
E && SuccToSinkTo ==
nullptr; ++
I) {
175 SuccToSinkTo = Candidate;
192 SuccToSinkTo->printAsOperand(
dbgs(),
false);
dbgs() <<
")\n");
195 Inst->
moveBefore(&*SuccToSinkTo->getFirstInsertionPt());
209 bool MadeChange =
false;
214 bool ProcessedBegin =
false;
221 ProcessedBegin = I == BB.
begin();
225 if (isa<DbgInfoIntrinsic>(Inst))
234 }
while (!ProcessedBegin);
241 bool MadeChange, EverMadeChange =
false;
245 LLVM_DEBUG(
dbgs() <<
"Sinking iteration " << NumSinkIter <<
"\n");
249 EverMadeChange |= MadeChange;
251 }
while (MadeChange);
253 return EverMadeChange;
278 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
279 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
280 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
iterator_range< use_iterator > uses()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static bool AllUsesDominatedByBlock(Instruction *Inst, BasicBlock *BB, DominatorTree &DT)
AllUsesDominatedByBlock - Return true if all uses of the specified value occur in blocks dominated by...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isTerminator() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
STATISTIC(NumFunctions, "Total number of functions")
Analysis pass which computes a DominatorTree.
An instruction for reading from memory.
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...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
A Use represents the edge between a Value definition and its users.
FunctionPass * createSinkingPass()
Analysis pass that exposes the LoopInfo for a function.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
static bool ProcessBlock(BasicBlock &BB, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Interval::succ_iterator succ_end(Interval *I)
static bool runOnFunction(Function &F, bool PostInlining)
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A manager for alias analyses.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool mayThrow() const
Return true if this instruction may throw an exception.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
void initializeSinkingLegacyPassPass(PassRegistry &)
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...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool isExceptionalTerminator() const
static unsigned getIncomingValueNumForOperand(unsigned i)
static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA, SmallPtrSetImpl< Instruction *> &Stores)
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
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.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Representation for a specific memory location.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Represents analyses that only rely on functions' control flow.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
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...
Represents a single loop in the control flow graph.
void preserveSet()
Mark an analysis set as preserved.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
static bool iterativelySinkInstructions(Function &F, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
typename std::vector< DomTreeNodeBase *>::iterator iterator
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
The legacy pass manager's analysis pass to compute loop information.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
const BasicBlock * getParent() const
an instruction to allocate memory on the stack