diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-10 15:56:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-10 15:56:24 +0000 |
commit | 0ed2da9ac733c51ba004c067d3b552c1fa54613d (patch) | |
tree | a1aa14bba44241711766a5c305809c3367108ffb /lib/Transforms | |
parent | 5be28c59c6dca1fd069439c98312b6e80d44a631 (diff) | |
download | external_llvm-0ed2da9ac733c51ba004c067d3b552c1fa54613d.zip external_llvm-0ed2da9ac733c51ba004c067d3b552c1fa54613d.tar.gz external_llvm-0ed2da9ac733c51ba004c067d3b552c1fa54613d.tar.bz2 |
Make LICM itself a bit more efficient, and make the generated code more efficient too: don't insert a store in every exit block, because a particular block may be exited to more than once by a loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10369 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/LICM.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 4100aed..2293c17 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -571,9 +571,7 @@ void LICM::PromoteValuesInLoop() { } // Scan the basic blocks in the loop, replacing uses of our pointers with - // uses of the allocas in question. If we find a branch that exits the - // loop, make sure to put reload code into all of the successors of the - // loop. + // uses of the allocas in question. // const std::vector<BasicBlock*> &LoopBBs = CurLoop->getBlocks(); for (std::vector<BasicBlock*>::const_iterator I = LoopBBs.begin(), @@ -593,26 +591,33 @@ void LICM::PromoteValuesInLoop() { S->setOperand(1, I->second); // Rewrite store instruction... } } + } - // Check to see if any successors of this block are outside of the loop. - // If so, we need to copy the value from the alloca back into the memory - // location... - // - for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) - if (!CurLoop->contains(*SI)) { - // Copy all of the allocas into their memory locations... - BasicBlock::iterator BI = (*SI)->begin(); - while (isa<PHINode>(*BI)) - ++BI; // Skip over all of the phi nodes in the block... - Instruction *InsertPos = BI; - for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i) { - // Load from the alloca... - LoadInst *LI = new LoadInst(PromotedValues[i].first, "", InsertPos); - // Store into the memory we promoted... - new StoreInst(LI, PromotedValues[i].second, InsertPos); - } + // Now that the body of the loop uses the allocas instead of the original + // memory locations, insert code to copy the alloca value back into the + // original memory location on all exits from the loop. Note that we only + // want to insert one copy of the code in each exit block, though the loop may + // exit to the same block more than once. + // + std::set<BasicBlock*> ProcessedBlocks; + + const std::vector<BasicBlock*> &ExitBlocks = CurLoop->getExitBlocks(); + for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) + if (!ProcessedBlocks.count(ExitBlocks[i])) { + ProcessedBlocks.insert(ExitBlocks[i]); + + // Copy all of the allocas into their memory locations... + BasicBlock::iterator BI = ExitBlocks[i]->begin(); + while (isa<PHINode>(*BI)) + ++BI; // Skip over all of the phi nodes in the block... + Instruction *InsertPos = BI; + for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i) { + // Load from the alloca... + LoadInst *LI = new LoadInst(PromotedValues[i].first, "", InsertPos); + // Store into the memory we promoted... + new StoreInst(LI, PromotedValues[i].second, InsertPos); } - } + } // Now that we have done the deed, use the mem2reg functionality to promote // all of the new allocas we just created into real SSA registers... |