[llvm-commits] [PATCH 2/2] Allow RegionPass to do post processing after all passes have run.

ether zhhb etherzhhb at gmail.com
Thu May 5 01:07:41 PDT 2011


hi,

This patch add a module level finalization function to regionpass.

best regards
ether

---
 include/llvm/Analysis/RegionPass.h |   16 ++++++++++++++--
 lib/Analysis/RegionPass.cpp        |    9 +++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/llvm/Analysis/RegionPass.h
b/include/llvm/Analysis/RegionPass.h
index 6c4e226..82f4f76 100644
--- a/include/llvm/Analysis/RegionPass.h
+++ b/include/llvm/Analysis/RegionPass.h
@@ -61,6 +61,12 @@ public:

   virtual bool doInitialization(Region *R, RGPassManager &RGM) {
return false; }
   virtual bool doFinalization() { return false; }
+
+  /// @brief Virtual method overridden by subclasses to do any post processing
+  /// needed after all passes have run.
+  ///
+  /// @return True if the pass modifies the module.
+  virtual bool doFinalization(Module &M) { return false; }
   //@}

   //===--------------------------------------------------------------------===//
@@ -95,6 +101,12 @@ public:
   /// @return True if any of the passes modifies the function.
   bool runOnFunction(Function &F);

+  /// @brief Execute all of the passes to do any post processing needed after
+  ///        all passes have run.
+  ///
+  /// @return True if any of the passes modifies the module.
+  bool doFinalization(Module &M);
+
   /// Pass Manager itself does not invalidate any analysis info.
   /// RGPassManager needs RegionInfo.
   void getAnalysisUsage(AnalysisUsage &Info) const;
@@ -110,9 +122,9 @@ public:
   void dumpPassStructure(unsigned Offset);

   /// @brief Get passes contained by this manager.
-  Pass *getContainedPass(unsigned N) {
+  RegionPass *getContainedPass(unsigned N) {
     assert(N < PassVector.size() && "Pass number out of range!");
-    Pass *FP = static_cast<Pass *>(PassVector[N]);
+    RegionPass *FP = static_cast<RegionPass *>(PassVector[N]);
     return FP;
   }

diff --git a/lib/Analysis/RegionPass.cpp b/lib/Analysis/RegionPass.cpp
index 80eda79..9b1c3ab 100644
--- a/lib/Analysis/RegionPass.cpp
+++ b/lib/Analysis/RegionPass.cpp
@@ -165,6 +165,15 @@ bool RGPassManager::runOnFunction(Function &F) {
   return Changed;
 }

+bool RGPassManager::doFinalization(Module &M) {
+  bool Changed = false;
+
+  for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
+    Changed |= getContainedPass(Index)->doFinalization(M);
+
+  return Changed;
+}
+
 /// Print passes managed by this manager
 void RGPassManager::dumpPassStructure(unsigned Offset) {
   errs().indent(Offset*2) << "Region Pass Manager\n";
-- 
1.7.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Allow-RegionPass-to-do-post-processing-after-all-pas.patch
Type: application/octet-stream
Size: 2692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110505/254921d5/attachment.obj>


More information about the llvm-commits mailing list