From cc139de15a24d576fd98ef4599558016c86b64d6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 22 Feb 2003 22:25:17 +0000 Subject: [PATCH] Clean up std namespace references git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5608 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Utils/PromoteMemoryToRegister.cpp | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index d8f53fb8808..3c4b16c3c36 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -13,7 +13,9 @@ // Currently this just loops over all alloca instructions, looking for // instructions that are only used in simple load and stores. // -// After this, the code is transformed by...something magical :) +// After this, the code is transformed by looping over all of the alloca +// instruction, calculating dominator frontiers, then inserting phi-nodes +// following the usual SSA construction algorithm. // //===----------------------------------------------------------------------===// @@ -27,23 +29,20 @@ #include "llvm/Type.h" #include "Support/Statistic.h" -using std::vector; -using std::map; -using std::set; - namespace { Statistic<> NumPromoted("mem2reg", "Number of alloca's promoted"); struct PromotePass : public FunctionPass { - vector Allocas; // the alloca instruction.. - map AllocaLookup; // reverse mapping of above + std::vector Allocas; // the alloca instruction.. + std::map AllocaLookup; // reverse mapping of above - vector > PhiNodes; // index corresponds to Allocas + std::vector > PhiNodes;// Idx corresponds 2 Allocas // List of instructions to remove at end of pass - vector KillList; + std::vector KillList; - map > NewPhiNodes; // the PhiNodes we're adding + std::map > NewPhiNodes; // the PhiNodes we're adding public: // runOnFunction - To run this pass, first we calculate the alloca @@ -59,8 +58,9 @@ namespace { } private: - void Traverse(BasicBlock *BB, BasicBlock *Pred, vector &IncVals, - set &Visited); + void RenamePass(BasicBlock *BB, BasicBlock *Pred, + std::vector &IncVals, + std::set &Visited); bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx); void FindSafeAllocas(Function &F); }; @@ -95,7 +95,7 @@ void PromotePass::FindSafeAllocas(Function &F) { BasicBlock &BB = F.getEntryNode(); // Get the entry node for the function // Look at all instructions in the entry node - for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) + for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) if (AllocaInst *AI = dyn_cast(&*I)) // Is it an alloca? if (isSafeAlloca(AI)) { // If safe alloca, add alloca to safe list AllocaLookup[AI] = Allocas.size(); // Keep reverse mapping @@ -118,7 +118,7 @@ bool PromotePass::runOnFunction(Function &F) { // Calculate the set of write-locations for each alloca. This is analogous to // counting the number of 'redefinitions' of each variable. - vector > WriteSets; // index corresponds to Allocas + std::vector > WriteSets;// Idx corresponds to Allocas WriteSets.resize(Allocas.size()); for (unsigned i = 0; i != Allocas.size(); ++i) { AllocaInst *AI = Allocas[i]; @@ -159,15 +159,15 @@ bool PromotePass::runOnFunction(Function &F) { // the alloca's. We do this in case there is a load of a value that has not // been stored yet. In this case, it will get this null value. // - vector Values(Allocas.size()); + std::vector Values(Allocas.size()); for (unsigned i = 0, e = Allocas.size(); i != e; ++i) Values[i] = Constant::getNullValue(Allocas[i]->getAllocatedType()); // Walks all basic blocks in the function performing the SSA rename algorithm // and inserting the phi nodes we marked as necessary // - set Visited; // The basic blocks we've already visited - Traverse(F.begin(), 0, Values, Visited); + std::set Visited; // The basic blocks we've already visited + RenamePass(F.begin(), 0, Values, Visited); // Remove all instructions marked by being placed in the KillList... // @@ -194,7 +194,7 @@ bool PromotePass::runOnFunction(Function &F) { // bool PromotePass::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) { // Look up the basic-block in question - vector &BBPNs = NewPhiNodes[BB]; + std::vector &BBPNs = NewPhiNodes[BB]; if (BBPNs.empty()) BBPNs.resize(Allocas.size()); // If the BB already has a phi node added for the i'th alloca then we're done! @@ -210,12 +210,12 @@ bool PromotePass::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) { return true; } -void PromotePass::Traverse(BasicBlock *BB, BasicBlock *Pred, - vector &IncomingVals, - set &Visited) { +void PromotePass::RenamePass(BasicBlock *BB, BasicBlock *Pred, + std::vector &IncomingVals, + std::set &Visited) { // If this is a BB needing a phi node, lookup/create the phinode for each // variable we need phinodes for. - vector &BBPNs = NewPhiNodes[BB]; + std::vector &BBPNs = NewPhiNodes[BB]; for (unsigned k = 0; k != BBPNs.size(); ++k) if (PHINode *PN = BBPNs[k]) { // at this point we can assume that the array has phi nodes.. let's add @@ -237,10 +237,8 @@ void PromotePass::Traverse(BasicBlock *BB, BasicBlock *Pred, Instruction *I = II; // get the instruction if (LoadInst *LI = dyn_cast(I)) { - Value *Ptr = LI->getPointerOperand(); - - if (AllocaInst *Src = dyn_cast(Ptr)) { - map::iterator AI = AllocaLookup.find(Src); + if (AllocaInst *Src = dyn_cast(LI->getPointerOperand())) { + std::map::iterator AI = AllocaLookup.find(Src); if (AI != AllocaLookup.end()) { Value *V = IncomingVals[AI->second]; @@ -250,11 +248,10 @@ void PromotePass::Traverse(BasicBlock *BB, BasicBlock *Pred, } } } else if (StoreInst *SI = dyn_cast(I)) { - // delete this instruction and mark the name as the current holder of the + // Delete this instruction and mark the name as the current holder of the // value - Value *Ptr = SI->getPointerOperand(); - if (AllocaInst *Dest = dyn_cast(Ptr)) { - map::iterator ai = AllocaLookup.find(Dest); + if (AllocaInst *Dest = dyn_cast(SI->getPointerOperand())) { + std::map::iterator ai =AllocaLookup.find(Dest); if (ai != AllocaLookup.end()) { // what value were we writing? IncomingVals[ai->second] = SI->getOperand(0); @@ -265,8 +262,8 @@ void PromotePass::Traverse(BasicBlock *BB, BasicBlock *Pred, } else if (TerminatorInst *TI = dyn_cast(I)) { // Recurse across our successors for (unsigned i = 0; i != TI->getNumSuccessors(); i++) { - vector OutgoingVals(IncomingVals); - Traverse(TI->getSuccessor(i), BB, OutgoingVals, Visited); + std::vector OutgoingVals(IncomingVals); + RenamePass(TI->getSuccessor(i), BB, OutgoingVals, Visited); } } }