[llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Oct 4 21:38:01 PDT 2003
Changes in directory llvm/lib/Transforms/Utils:
PromoteMemoryToRegister.cpp updated: 1.43 -> 1.44
---
Log message:
Two small cleanups/speedups:
* Do not insert a new entry into NewPhiNodes during the rename pass if there are no PHIs in a block.
* Do not compute WriteSets in parallel
---
Diffs of the changes:
Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.43 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.44
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.43 Sat Oct 4 20:52:53 2003
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Sat Oct 4 21:37:36 2003
@@ -93,26 +93,24 @@
AllocaLookup[Allocas[i]] = i;
}
- // Calculate the set of write-locations for each alloca. This is analogous to
- // counting the number of 'redefinitions' of each variable.
- std::vector<std::vector<BasicBlock*> > WriteSets;// Idx corresponds to Allocas
- WriteSets.resize(Allocas.size());
+ PhiNodes.resize(Allocas.size());
for (unsigned i = 0; i != Allocas.size(); ++i) {
AllocaInst *AI = Allocas[i];
+
+ // Calculate the set of write-locations for each alloca. This is analogous
+ // to counting the number of 'redefinitions' of each variable.
+ std::vector<BasicBlock*> WriteSets;
for (Value::use_iterator U =AI->use_begin(), E = AI->use_end(); U != E; ++U)
if (StoreInst *SI = dyn_cast<StoreInst>(*U))
// jot down the basic-block it came from
- WriteSets[i].push_back(SI->getParent());
- }
-
- // Compute the locations where PhiNodes need to be inserted. Look at the
- // dominance frontier of EACH basic-block we have a write in
- //
- PhiNodes.resize(Allocas.size());
- for (unsigned i = 0; i != Allocas.size(); ++i) {
- for (unsigned j = 0; j != WriteSets[i].size(); j++) {
+ WriteSets.push_back(SI->getParent());
+
+ // Compute the locations where PhiNodes need to be inserted. Look at the
+ // dominance frontier of EACH basic-block we have a write in.
+ //
+ for (unsigned j = 0; j != WriteSets.size(); j++) {
// Look up the DF for this write, add it to PhiNodes
- DominanceFrontier::const_iterator it = DF.find(WriteSets[i][j]);
+ DominanceFrontier::const_iterator it = DF.find(WriteSets[j]);
if (it != DF.end()) {
const DominanceFrontier::DomSetType &S = it->second;
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
@@ -200,22 +198,26 @@
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
std::vector<Value*> &IncomingVals) {
- // If this is a BB needing a phi node, lookup/create the phinode for each
- // variable we need phinodes for.
- std::vector<PHINode *> &BBPNs = NewPhiNodes[BB];
- for (unsigned k = 0; k != BBPNs.size(); ++k)
- if (PHINode *PN = BBPNs[k]) {
- // The PHI node may have multiple entries for this predecessor. We must
- // make sure we update all of them.
- for (unsigned i = 0, e = PN->getNumOperands(); i != e; i += 2) {
- if (PN->getOperand(i+1) == Pred)
- // At this point we can assume that the array has phi nodes.. let's
- // update the incoming data.
- PN->setOperand(i, IncomingVals[k]);
+ // If this BB needs a PHI node, update the PHI node for each variable we need
+ // PHI nodes for.
+ std::map<BasicBlock*, std::vector<PHINode *> >::iterator
+ BBPNI = NewPhiNodes.find(BB);
+ if (BBPNI != NewPhiNodes.end()) {
+ std::vector<PHINode *> &BBPNs = BBPNI->second;
+ for (unsigned k = 0; k != BBPNs.size(); ++k)
+ if (PHINode *PN = BBPNs[k]) {
+ // The PHI node may have multiple entries for this predecessor. We must
+ // make sure we update all of them.
+ for (unsigned i = 0, e = PN->getNumOperands(); i != e; i += 2) {
+ if (PN->getOperand(i+1) == Pred)
+ // At this point we can assume that the array has phi nodes.. let's
+ // update the incoming data.
+ PN->setOperand(i, IncomingVals[k]);
+ }
+ // also note that the active variable IS designated by the phi node
+ IncomingVals[k] = PN;
}
- // also note that the active variable IS designated by the phi node
- IncomingVals[k] = PN;
- }
+ }
// don't revisit nodes
if (Visited.count(BB)) return;
More information about the llvm-commits
mailing list