15 #define DEBUG_TYPE "sink"
29 STATISTIC(NumSunk,
"Number of instructions sunk");
30 STATISTIC(NumSinkIter,
"Number of sinking iterations");
74 bool Sinking::AllUsesDominatedByBlock(
Instruction *Inst,
85 if (
PHINode *PN = dyn_cast<PHINode>(UseInst)) {
89 UseBlock = PN->getIncomingBlock(Num);
92 if (!DT->dominates(BB, UseBlock))
98 bool Sinking::runOnFunction(
Function &
F) {
99 DT = &getAnalysis<DominatorTree>();
100 LI = &getAnalysis<LoopInfo>();
101 AA = &getAnalysis<AliasAnalysis>();
103 bool MadeChange, EverMadeChange =
false;
107 DEBUG(
dbgs() <<
"Sinking iteration " << NumSinkIter <<
"\n");
111 MadeChange |= ProcessBlock(*I);
112 EverMadeChange |= MadeChange;
114 }
while (MadeChange);
116 return EverMadeChange;
126 if (!DT->isReachableFromEntry(&BB))
return false;
128 bool MadeChange =
false;
133 bool ProcessedBegin =
false;
140 ProcessedBegin = I == BB.
begin();
144 if (isa<DbgInfoIntrinsic>(Inst))
147 if (SinkInstruction(Inst, Stores))
148 ++NumSunk, MadeChange =
true;
151 }
while (!ProcessedBegin);
164 if (
LoadInst *L = dyn_cast<LoadInst>(Inst)) {
167 E = Stores.
end(); I != E; ++
I)
172 if (isa<TerminatorInst>(Inst) || isa<PHINode>(Inst))
180 bool Sinking::IsAcceptableTarget(
Instruction *Inst,
182 assert(Inst &&
"Instruction to be sunk is null");
183 assert(SuccToSinkTo &&
"Candidate sink target is null");
202 if (!DT->dominates(Inst->
getParent(), SuccToSinkTo))
206 Loop *succ = LI->getLoopFor(SuccToSinkTo);
208 if (succ != 0 && succ != cur)
214 return AllUsesDominatedByBlock(Inst, SuccToSinkTo);
242 I != E && SuccToSinkTo == 0; ++
I) {
244 if ((*I)->getIDom()->getBlock() == Inst->
getParent() &&
245 IsAcceptableTarget(Inst, Candidate))
246 SuccToSinkTo = Candidate;
253 if (IsAcceptableTarget(Inst, *I))
258 if (SuccToSinkTo == 0)
268 Inst->
moveBefore(SuccToSinkTo->getFirstInsertionPt());
AnalysisUsage & addPreserved()
BasicBlock * getUniquePredecessor()
Return this block if it has a unique predecessor block. Otherwise return a null pointer.
static PassRegistry * getPassRegistry()
ModRefResult getModRefInfo(const Instruction *I, const Location &Loc)
virtual void getAnalysisUsage(AnalysisUsage &) const
machine Machine code sinking
LoopInfoBase< BlockT, LoopT > * LI
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
FunctionPass * createSinkingPass()
ID
LLVM Calling Convention Representation.
Interval::succ_iterator succ_begin(Interval *I)
Interval::succ_iterator succ_end(Interval *I)
unsigned getNumSuccessors() const
LLVM Basic Block Representation.
Location - A description of a memory location.
#define INITIALIZE_AG_DEPENDENCY(depName)
STATISTIC(NumSunk,"Number of instructions sunk")
static unsigned getIncomingValueNumForOperand(unsigned i)
bool mayWriteToMemory() const
bool isSafeToSpeculativelyExecute(const Value *V, const DataLayout *TD=0)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void initializeSinkingPass(PassRegistry &)
static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA, SmallPtrSet< Instruction *, 8 > &Stores)
Location getLocation(const LoadInst *LI)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
std::vector< DomTreeNodeBase< NodeT > * >::iterator iterator
void moveBefore(Instruction *MovePos)
const BasicBlock * getParent() const