diff options
author | Chris Lattner <sabre@nondot.org> | 2004-06-19 08:56:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-06-19 08:56:43 +0000 |
commit | edb8433c917d97c237832954135e785b8c84f045 (patch) | |
tree | a9c4e0e192f738fd0583a2f57b01b611ca9a8eee /lib | |
parent | abc35bcad3011d582bad3717e14c7398c8c51282 (diff) | |
download | external_llvm-edb8433c917d97c237832954135e785b8c84f045.zip external_llvm-edb8433c917d97c237832954135e785b8c84f045.tar.gz external_llvm-edb8433c917d97c237832954135e785b8c84f045.tar.bz2 |
Fix one source of nondeterminism in the -licm pass: the hoist pass
was processing blocks in whatever order they happened to end up in the
dominator tree data structure. Force an ordering.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/LICM.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 8bdde10..31aff0d 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -40,6 +40,7 @@ #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Support/CFG.h" +#include "llvm/Support/StableBasicBlockNumbering.h" #include "llvm/Transforms/Utils/PromoteMemToReg.h" #include "llvm/Transforms/Utils/Local.h" #include "Support/CommandLine.h" @@ -81,6 +82,7 @@ namespace { LoopInfo *LI; // Current LoopInfo DominatorTree *DT; // Dominator Tree for the current Loop... DominanceFrontier *DF; // Current Dominance Frontier + StableBasicBlockNumbering *BBNum; // Stable IDs for basic blocks // State that is updated as we process loops bool Changed; // Set to true when we change anything. @@ -203,7 +205,7 @@ FunctionPass *llvm::createLICMPass() { return new LICM(); } /// runOnFunction - For LICM, this simply traverses the loop structure of the /// function, hoisting expressions out of loops if possible. /// -bool LICM::runOnFunction(Function &) { +bool LICM::runOnFunction(Function &F) { Changed = false; // Get our Loop and Alias Analysis information... @@ -212,6 +214,10 @@ bool LICM::runOnFunction(Function &) { DF = &getAnalysis<DominanceFrontier>(); DT = &getAnalysis<DominatorTree>(); + // Get a stable numbering of basic blocks. + StableBasicBlockNumbering CurBBNum(&F); + BBNum = &CurBBNum; + // Hoist expressions out of all of the top-level loops. for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) { AliasSetTracker AST(*AA); @@ -337,8 +343,16 @@ void LICM::HoistRegion(DominatorTree::Node *N) { } const std::vector<DominatorTree::Node*> &Children = N->getChildren(); + std::vector<std::pair<unsigned, DominatorTree::Node*> > ChildrenWithIDs; + ChildrenWithIDs.reserve(Children.size()); + for (unsigned i = 0, e = Children.size(); i != e; ++i) { + unsigned ID = BBNum->getNumber(Children[i]->getBlock()); + ChildrenWithIDs.push_back(std::make_pair(ID, Children[i])); + } + + std::sort(ChildrenWithIDs.begin(), ChildrenWithIDs.end()); for (unsigned i = 0, e = Children.size(); i != e; ++i) - HoistRegion(Children[i]); + HoistRegion(ChildrenWithIDs[i].second); } /// canSinkOrHoistInst - Return true if the hoister and sinker can handle this |