aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-05 03:16:07 +0000
committerChris Lattner <sabre@nondot.org>2003-10-05 03:16:07 +0000
commit9e38fbf57feef1e6680c0aed64b1d919b4e01626 (patch)
tree91d32c66e1d227321e2fe25988e41e6a38aa78a5 /lib/Transforms/Utils
parent9157f041abcd0d3bf55dd09bfe85238b6626cf19 (diff)
downloadexternal_llvm-9e38fbf57feef1e6680c0aed64b1d919b4e01626.zip
external_llvm-9e38fbf57feef1e6680c0aed64b1d919b4e01626.tar.gz
external_llvm-9e38fbf57feef1e6680c0aed64b1d919b4e01626.tar.bz2
* Document instance vars better
* Fuse two parallel loops * Use a more specific type for AllocaLookup git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8859 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index a56420f..7dd2dcd 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -51,14 +51,20 @@ bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD) {
namespace {
struct PromoteMem2Reg {
- const std::vector<AllocaInst*> &Allocas; // the alloca instructions..
- std::vector<unsigned> VersionNumbers; // Current version counters
+ // Allocas - The alloca instructions being promoted
+ const std::vector<AllocaInst*> &Allocas;
DominanceFrontier &DF;
const TargetData &TD;
- std::map<Instruction*, unsigned> AllocaLookup; // reverse mapping of above
+ // AllocaLookup - Reverse mapping of Allocas
+ std::map<AllocaInst*, unsigned> AllocaLookup;
+
+ // VersionNumbers - Current version counters for each alloca
+ std::vector<unsigned> VersionNumbers;
- std::vector<std::vector<BasicBlock*> > PhiNodes;// Idx corresponds 2 Allocas
+ // PhiNodes - Each alloca contains a list of basic blocks which contain PHI
+ // nodes for the alloca.
+ std::vector<std::vector<BasicBlock*> > PhiNodes;
// NewPhiNodes - The PhiNodes we're adding.
std::map<BasicBlock*, std::vector<PHINode*> > NewPhiNodes;
@@ -84,26 +90,25 @@ void PromoteMem2Reg::run() {
Function &F = *DF.getRoot()->getParent();
VersionNumbers.resize(Allocas.size());
+ PhiNodes.resize(Allocas.size());
- for (unsigned i = 0, e = Allocas.size(); i != e; ++i) {
- assert(isAllocaPromotable(Allocas[i], TD) &&
+ for (unsigned i = 0; i != Allocas.size(); ++i) {
+ AllocaInst *AI = Allocas[i];
+
+ assert(isAllocaPromotable(AI, TD) &&
"Cannot promote non-promotable alloca!");
assert(Allocas[i]->getParent()->getParent() == &F &&
"All allocas should be in the same function, which is same as DF!");
- AllocaLookup[Allocas[i]] = i;
- }
-
- 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))
+ if (StoreInst *SI = dyn_cast<StoreInst>(cast<Instruction>(*U)))
// jot down the basic-block it came from
WriteSets.push_back(SI->getParent());
+
+ AllocaLookup[Allocas[i]] = i;
// Compute the locations where PhiNodes need to be inserted. Look at the
// dominance frontier of EACH basic-block we have a write in.
@@ -120,12 +125,13 @@ void PromoteMem2Reg::run() {
}
// Perform iterative step
- for (unsigned k = 0; k != PhiNodes[i].size(); k++) {
- DominanceFrontier::const_iterator it = DF.find(PhiNodes[i][k]);
+ std::vector<BasicBlock*> &AllocaPhiNodes = PhiNodes[i];
+ for (unsigned k = 0; k != AllocaPhiNodes.size(); k++) {
+ DominanceFrontier::const_iterator it = DF.find(AllocaPhiNodes[k]);
if (it != DF.end()) {
- const DominanceFrontier::DomSetType &S = it->second;
- for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
- P != PE; ++P)
+ const DominanceFrontier::DomSetType &S = it->second;
+ for (DominanceFrontier::DomSetType::iterator
+ P = S.begin(), PE = S.end(); P != PE; ++P)
QueuePhiNode(*P, i);
}
}
@@ -231,7 +237,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
if (AllocaInst *Src = dyn_cast<AllocaInst>(LI->getPointerOperand())) {
- std::map<Instruction*, unsigned>::iterator AI = AllocaLookup.find(Src);
+ std::map<AllocaInst*, unsigned>::iterator AI = AllocaLookup.find(Src);
if (AI != AllocaLookup.end()) {
Value *V = IncomingVals[AI->second];
@@ -244,7 +250,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
// Delete this instruction and mark the name as the current holder of the
// value
if (AllocaInst *Dest = dyn_cast<AllocaInst>(SI->getPointerOperand())) {
- std::map<Instruction *, unsigned>::iterator ai =AllocaLookup.find(Dest);
+ std::map<AllocaInst *, unsigned>::iterator ai = AllocaLookup.find(Dest);
if (ai != AllocaLookup.end()) {
// what value were we writing?
IncomingVals[ai->second] = SI->getOperand(0);