mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-13 14:46:53 +00:00
rangify, fix function names; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262940 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
05a0bf3589
commit
94c032fe90
@ -46,7 +46,7 @@ STATISTIC(NumUnrolled, "Number of loops unrolled (completely or otherwise)");
|
||||
|
||||
/// Convert the instruction operands from referencing the current values into
|
||||
/// those specified by VMap.
|
||||
static inline void RemapInstruction(Instruction *I,
|
||||
static inline void remapInstruction(Instruction *I,
|
||||
ValueToValueMapTy &VMap) {
|
||||
for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
|
||||
Value *Op = I->getOperand(op);
|
||||
@ -73,7 +73,7 @@ static inline void RemapInstruction(Instruction *I,
|
||||
/// of loops that have already been forgotten to prevent redundant, expensive
|
||||
/// calls to ScalarEvolution::forgetLoop. Returns the new combined block.
|
||||
static BasicBlock *
|
||||
FoldBlockIntoPredecessor(BasicBlock *BB, LoopInfo *LI, ScalarEvolution *SE,
|
||||
foldBlockIntoPredecessor(BasicBlock *BB, LoopInfo *LI, ScalarEvolution *SE,
|
||||
SmallPtrSetImpl<Loop *> &ForgottenLoops,
|
||||
DominatorTree *DT) {
|
||||
// Merge basic blocks into their predecessor if there is only one distinct
|
||||
@ -395,13 +395,13 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
if (*BB == Header)
|
||||
// Loop over all of the PHI nodes in the block, changing them to use
|
||||
// the incoming values from the previous block.
|
||||
for (unsigned i = 0, e = OrigPHINode.size(); i != e; ++i) {
|
||||
PHINode *NewPHI = cast<PHINode>(VMap[OrigPHINode[i]]);
|
||||
for (PHINode *OrigPHI : OrigPHINode) {
|
||||
PHINode *NewPHI = cast<PHINode>(VMap[OrigPHI]);
|
||||
Value *InVal = NewPHI->getIncomingValueForBlock(LatchBlock);
|
||||
if (Instruction *InValI = dyn_cast<Instruction>(InVal))
|
||||
if (It > 1 && L->contains(InValI))
|
||||
InVal = LastValueMap[InValI];
|
||||
VMap[OrigPHINode[i]] = InVal;
|
||||
VMap[OrigPHI] = InVal;
|
||||
New->getInstList().erase(NewPHI);
|
||||
}
|
||||
|
||||
@ -412,11 +412,10 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
LastValueMap[VI->first] = VI->second;
|
||||
|
||||
// Add phi entries for newly created values to all exit blocks.
|
||||
for (succ_iterator SI = succ_begin(*BB), SE = succ_end(*BB);
|
||||
SI != SE; ++SI) {
|
||||
if (L->contains(*SI))
|
||||
for (BasicBlock *Succ : successors(*BB)) {
|
||||
if (L->contains(Succ))
|
||||
continue;
|
||||
for (BasicBlock::iterator BBI = (*SI)->begin();
|
||||
for (BasicBlock::iterator BBI = Succ->begin();
|
||||
PHINode *phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
||||
Value *Incoming = phi->getIncomingValueForBlock(*BB);
|
||||
ValueToValueMapTy::iterator It = LastValueMap.find(Incoming);
|
||||
@ -453,15 +452,13 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
}
|
||||
|
||||
// Remap all instructions in the most recent iteration
|
||||
for (unsigned i = 0; i < NewBlocks.size(); ++i)
|
||||
for (BasicBlock::iterator I = NewBlocks[i]->begin(),
|
||||
E = NewBlocks[i]->end(); I != E; ++I)
|
||||
::RemapInstruction(&*I, LastValueMap);
|
||||
for (BasicBlock *NewBlock : NewBlocks)
|
||||
for (Instruction &I : *NewBlock)
|
||||
::remapInstruction(&I, LastValueMap);
|
||||
}
|
||||
|
||||
// Loop over the PHI nodes in the original block, setting incoming values.
|
||||
for (unsigned i = 0, e = OrigPHINode.size(); i != e; ++i) {
|
||||
PHINode *PN = OrigPHINode[i];
|
||||
for (PHINode *PN : OrigPHINode) {
|
||||
if (CompletelyUnroll) {
|
||||
PN->replaceAllUsesWith(PN->getIncomingValueForBlock(Preheader));
|
||||
Header->getInstList().erase(PN);
|
||||
@ -516,11 +513,10 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
// Remove phi operands at this loop exit
|
||||
if (Dest != LoopExit) {
|
||||
BasicBlock *BB = Latches[i];
|
||||
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
||||
SI != SE; ++SI) {
|
||||
if (*SI == Headers[i])
|
||||
for (BasicBlock *Succ: successors(BB)) {
|
||||
if (Succ == Headers[i])
|
||||
continue;
|
||||
for (BasicBlock::iterator BBI = (*SI)->begin();
|
||||
for (BasicBlock::iterator BBI = Succ->begin();
|
||||
PHINode *Phi = dyn_cast<PHINode>(BBI); ++BBI) {
|
||||
Phi->removeIncomingValue(BB, false);
|
||||
}
|
||||
@ -550,12 +546,12 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
|
||||
// Merge adjacent basic blocks, if possible.
|
||||
SmallPtrSet<Loop *, 4> ForgottenLoops;
|
||||
for (unsigned i = 0, e = Latches.size(); i != e; ++i) {
|
||||
BranchInst *Term = cast<BranchInst>(Latches[i]->getTerminator());
|
||||
for (BasicBlock *Latch : Latches) {
|
||||
BranchInst *Term = cast<BranchInst>(Latch->getTerminator());
|
||||
if (Term->isUnconditional()) {
|
||||
BasicBlock *Dest = Term->getSuccessor(0);
|
||||
if (BasicBlock *Fold =
|
||||
FoldBlockIntoPredecessor(Dest, LI, SE, ForgottenLoops, DT)) {
|
||||
foldBlockIntoPredecessor(Dest, LI, SE, ForgottenLoops, DT)) {
|
||||
// Dest has been folded into Fold. Update our worklists accordingly.
|
||||
std::replace(Latches.begin(), Latches.end(), Dest, Fold);
|
||||
UnrolledLoopBlocks.erase(std::remove(UnrolledLoopBlocks.begin(),
|
||||
@ -594,17 +590,16 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
// go.
|
||||
const DataLayout &DL = Header->getModule()->getDataLayout();
|
||||
const std::vector<BasicBlock*> &NewLoopBlocks = L->getBlocks();
|
||||
for (std::vector<BasicBlock*>::const_iterator BB = NewLoopBlocks.begin(),
|
||||
BBE = NewLoopBlocks.end(); BB != BBE; ++BB)
|
||||
for (BasicBlock::iterator I = (*BB)->begin(), E = (*BB)->end(); I != E; ) {
|
||||
for (BasicBlock *BB : NewLoopBlocks)
|
||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
|
||||
Instruction *Inst = &*I++;
|
||||
|
||||
if (isInstructionTriviallyDead(Inst))
|
||||
(*BB)->getInstList().erase(Inst);
|
||||
BB->getInstList().erase(Inst);
|
||||
else if (Value *V = SimplifyInstruction(Inst, DL))
|
||||
if (LI->replacementPreservesLCSSAForm(Inst, V)) {
|
||||
Inst->replaceAllUsesWith(V);
|
||||
(*BB)->getInstList().erase(Inst);
|
||||
BB->getInstList().erase(Inst);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user