From 71b9411b8c90cfb479ab7d641ba81fbe379f33df Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 12 Feb 2002 18:27:41 +0000 Subject: [PATCH] I forgot to provide dominance frontier information. Now it's available. Also add more comments. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1741 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Utils/PromoteMemoryToRegister.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index e53150d643d..f8cdb08520a 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -18,12 +18,15 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar/PromoteMemoryToRegister.h" +#include "llvm/Analysis/Dominators.h" #include "llvm/iMemory.h" #include "llvm/Pass.h" #include "llvm/Method.h" - #include "llvm/Assembly/Writer.h" // For debugging +using cfg::DominanceFrontier; +// PromotePass - This class is implements the PromoteMemoryToRegister pass +// class PromotePass : public MethodPass { public: // runOnMethod - To run this pass, first we calculate the alloca instructions @@ -33,14 +36,27 @@ public: std::vector Allocas; findSafeAllocas(M, Allocas); // Calculate safe allocas + // Get dominance frontier information... + DominanceFrontier &DF = getAnalysis(); + // Transform each alloca in turn... for (std::vector::iterator I = Allocas.begin(), E = Allocas.end(); I != E; ++I) - promoteAlloca(*I); + promoteAlloca(*I, DF); return !Allocas.empty(); } + + // getAnalysisUsageInfo - We need dominance frontiers + // + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Requires.push_back(DominanceFrontier::ID); + } + +private: // findSafeAllocas - Find allocas that are safe to promote // void findSafeAllocas(Method *M, std::vector &Allocas) const; @@ -48,7 +64,7 @@ public: // promoteAlloca - Convert the use chain of an alloca instruction into // register references. // - void promoteAlloca(AllocaInst *AI); + void promoteAlloca(AllocaInst *AI, DominanceFrontier &DF); }; @@ -79,15 +95,18 @@ void PromotePass::findSafeAllocas(Method *M, } + + // promoteAlloca - Convert the use chain of an alloca instruction into // register references. // -void PromotePass::promoteAlloca(AllocaInst *AI) { +void PromotePass::promoteAlloca(AllocaInst *AI, DominanceFrontier &DFInfo) { cerr << "TODO: Should process: " << AI; } - +// newPromoteMemoryToRegister - Provide an entry point to create this pass. +// Pass *newPromoteMemoryToRegister() { return new PromotePass(); }