diff options
author | Owen Anderson <resistor@mac.com> | 2006-06-01 06:05:47 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2006-06-01 06:05:47 +0000 |
commit | 2824da4738aba79a140ce77ccc918587ea9d534a (patch) | |
tree | 34482d883b749e63193afc112c2ce8130d1ea939 /lib/Transforms/Utils | |
parent | 2675534b7f3a7652e2a0040f415c60557a84e3a8 (diff) | |
download | external_llvm-2824da4738aba79a140ce77ccc918587ea9d534a.zip external_llvm-2824da4738aba79a140ce77ccc918587ea9d534a.tar.gz external_llvm-2824da4738aba79a140ce77ccc918587ea9d534a.tar.bz2 |
More cleanups. Also, add a special case for updating PHI nodes, and
reimplement getValueDominatingFunction to walk the DominanceTree rather than
just searching blindly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28618 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r-- | lib/Transforms/Utils/LCSSA.cpp | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index 2682906..aa52235 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -36,7 +36,7 @@ #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/CFG.h" #include <algorithm> -#include <iostream> +#include <cassert> #include <map> #include <vector> @@ -143,17 +143,12 @@ void LCSSA::processInstruction(Instruction* Instr, std::vector<PHINode*> workList; for (std::vector<BasicBlock*>::const_iterator BBI = exitBlocks.begin(), - BBE = exitBlocks.end(); BBI != BBE; ++BBI) { - PHINode *phi = new PHINode(Instr->getType(), "lcssa", (*BBI)->begin()); - workList.push_back(phi); - Phis[*BBI] = phi; - - // Since LoopSimplify has been run, we know that all of these predecessors - // are in the loop, so just hook them up in the obvious manner. - //for (pred_iterator PI = pred_begin(*BBI), PE = pred_end(*BBI); PI != PE; - // ++PI) - // phi->addIncoming(Instr, *PI); - } + BBE = exitBlocks.end(); BBI != BBE; ++BBI) + if (DT->getNode(Instr->getParent())->dominates(DT->getNode(*BBI))) { + PHINode *phi = new PHINode(Instr->getType(), "lcssa", (*BBI)->begin()); + workList.push_back(phi); + Phis[*BBI] = phi; + } // Calculate the IDF of these LCSSA Phi nodes, inserting new Phi's where // necessary. Keep track of these new Phi's in Phis. @@ -170,8 +165,7 @@ void LCSSA::processInstruction(Instruction* Instr, PE = S.end(); P != PE; ++P) { if (Phis[*P] == 0) { // Still doesn't have operands... - PHINode *phi = new PHINode(Instr->getType(), "lcssa"); - (*P)->getInstList().insert((*P)->front(), phi); + PHINode *phi = new PHINode(Instr->getType(), "lcssa", (*P)->begin()); Phis[*P] = phi; workList.push_back(phi); @@ -208,8 +202,21 @@ void LCSSA::processInstruction(Instruction* Instr, for (std::vector<Instruction*>::iterator II = Uses.begin(), IE = Uses.end(); II != IE; ++II) { - (*II)->replaceUsesOfWith(Instr, getValueDominatingBlock((*II)->getParent(), - Phis)); + if (PHINode* phi = dyn_cast<PHINode>(*II)) { + for (unsigned int i = 0; i < phi->getNumIncomingValues(); ++i) { + // FIXME: Replace a Phi entry if and only if the corresponding + // predecessor is dominated. + Instruction* dominator = + getValueDominatingBlock(phi->getIncomingBlock(i), Phis); + + if (phi->getIncomingValue(i) == Instr) + phi->setIncomingValue(i, dominator); + } + } else { + (*II)->replaceUsesOfWith(Instr, + getValueDominatingBlock((*II)->getParent(), + Phis)); + } } } @@ -241,12 +248,17 @@ std::set<Instruction*> LCSSA::getLoopValuesUsedOutsideLoop(Loop *L, Instruction *LCSSA::getValueDominatingBlock(BasicBlock *BB, std::map<BasicBlock*, Instruction*> PotDoms) { - for (std::map<BasicBlock*, Instruction*>::iterator MI = PotDoms.begin(), - ME = PotDoms.end(); MI != ME; ++MI) - if (DT->getNode((*MI).first)->dominates(DT->getNode(BB))) - return (*MI).second; + DominatorTree::Node* bbNode = DT->getNode(BB); + while (bbNode != 0) { + std::map<BasicBlock*, Instruction*>::iterator I = + PotDoms.find(bbNode->getBlock()); + if (I != PotDoms.end()) { + return (*I).second; + } + bbNode = bbNode->getIDom(); + } - // FIXME: Should assert false + assert(0 && "No dominating value found."); return 0; } |