X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FPromoteMemoryToRegister.cpp;h=b84f1a378fa2970409e05a66e87ced6e050f01d7;hb=d76efa018660e806cd87c0a24512e3c532fc1d36;hp=378e9799a8c107d427d516ca6f3cc1f5275c9f7b;hpb=f629309f74cf1a64aa7fd1cd5784fd7db9a8f59e;p=oota-llvm.git diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 378e9799a8c..b84f1a378fa 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -55,7 +55,7 @@ namespace { // getAnalysisUsage - We need dominance frontiers // virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(DominanceFrontier::ID); + AU.addRequired(); AU.preservesCFG(); } @@ -66,7 +66,7 @@ namespace { void FindSafeAllocas(Function &F); }; - RegisterPass X("mem2reg", "Promote Memory to Register"); + RegisterOpt X("mem2reg", "Promote Memory to Register"); } // end of anonymous namespace @@ -76,25 +76,11 @@ namespace { static inline bool isSafeAlloca(const AllocaInst *AI) { if (AI->isArrayAllocation()) return false; + // Only allow direct loads and stores... for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end(); - UI != UE; ++UI) { // Loop over all of the uses of the alloca - - // Only allow nonindexed memory access instructions... - if (MemAccessInst *MAI = dyn_cast(*UI)) { - if (MAI->getPointerOperand() != (Value*)AI) - return false; // Reject stores of alloca pointer into some other loc. - - if (MAI->hasIndices()) { // indexed? - // Allow the access if there is only one index and the index is - // zero. - if (*MAI->idx_begin() != Constant::getNullValue(Type::UIntTy) || - MAI->idx_begin()+1 != MAI->idx_end()) - return false; - } - } else { + UI != UE; ++UI) // Loop over all of the uses of the alloca + if (!isa(*UI) && !isa(*UI)) return false; // Not a load or store? - } - } return true; } @@ -210,14 +196,12 @@ bool PromotePass::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) { // If the BB already has a phi node added for the i'th alloca then we're done! if (BBPNs[AllocaNo]) return false; - // Create a PhiNode using the dereferenced type... + // Create a PhiNode using the dereferenced type... and add the phi-node to the + // BasicBlock PHINode *PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(), - Allocas[AllocaNo]->getName()+".mem2reg"); + Allocas[AllocaNo]->getName()+".mem2reg", + BB->begin()); BBPNs[AllocaNo] = PN; - - // Add the phi-node to the basic-block - BB->getInstList().push_front(PN); - PhiNodes[AllocaNo].push_back(BB); return true; }