diff options
author | Owen Anderson <resistor@mac.com> | 2008-06-19 19:54:19 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2008-06-19 19:54:19 +0000 |
commit | fdf9f168b53406dff92a2cddea70ad2d1ca0967f (patch) | |
tree | 7d45d6b94bd66397e0883eb24d7d46c2a214cbb5 /llvm/lib | |
parent | 65643c6480e8564a3f1fa8b90f886ea36d3b1beb (diff) | |
download | bcm5719-llvm-fdf9f168b53406dff92a2cddea70ad2d1ca0967f.tar.gz bcm5719-llvm-fdf9f168b53406dff92a2cddea70ad2d1ca0967f.zip |
PRE requires that critical edges be split.
llvm-svn: 52505
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index f8522694286..cbc24eda56f 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" using namespace llvm; STATISTIC(NumGVNInstr, "Number of instructions deleted"); @@ -1128,6 +1129,7 @@ bool GVN::processBlock(DomTreeNode* DTN) { /// control flow patterns and attempts to perform simple PRE at the join point. bool GVN::performPRE(Function& F) { bool changed = false; + SmallVector<std::pair<TerminatorInst*, unsigned>, 4> toSplit; for (df_iterator<BasicBlock*> DI = df_begin(&F.getEntryBlock()), DE = df_end(&F.getEntryBlock()); DI != DE; ++DI) { BasicBlock* CurrentBlock = *DI; @@ -1179,6 +1181,24 @@ bool GVN::performPRE(Function& F) { continue; } + // We can't do PRE safely on a critical edge, so instead we schedule + // the edge to be split and perform the PRE the next time we iterate + // on the function. + unsigned succNum = 0; + for (unsigned i = 0, e = PREPred->getTerminator()->getNumSuccessors(); + i != e; ++i) + if (PREPred->getTerminator()->getSuccessor(i) == PREPred) { + succNum = i; + break; + } + + if (isCriticalEdge(PREPred->getTerminator(), succNum)) { + toSplit.push_back(std::make_pair(PREPred->getTerminator(), succNum)); + changed = true; + BI++; + continue; + } + // Instantiate the expression the in predecessor that lacked it. // Because we are going top-down through the block, all value numbers // will be available in the predecessor by the time we need them. Any @@ -1244,6 +1264,10 @@ bool GVN::performPRE(Function& F) { } } + for (SmallVector<std::pair<TerminatorInst*, unsigned>, 4>::iterator + I = toSplit.begin(), E = toSplit.end(); I != E; ++I) + SplitCriticalEdge(I->first, I->second, this); + return changed; } |