Add a new BasicBlockPass::doInitialization/Finalization(Function &) pair of

methods that may be useful for BasicBlockPasses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3689 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-09-12 17:06:43 +00:00
parent e0a54f88a0
commit d0713f94af
2 changed files with 77 additions and 17 deletions

View File

@ -25,13 +25,19 @@
</ul> </ul>
<li><a href="#FunctionPass">The <tt>FunctionPass</tt> class</a> <li><a href="#FunctionPass">The <tt>FunctionPass</tt> class</a>
<ul> <ul>
<li><a href="#doInitialization">The <tt>doInitialization</tt> method</a> <li><a href="#doInitialization_mod">The <tt>doInitialization(Module
&amp;)</tt> method</a>
<li><a href="#runOnFunction">The <tt>runOnFunction</tt> method</a> <li><a href="#runOnFunction">The <tt>runOnFunction</tt> method</a>
<li><a href="#doFinalization">The <tt>doFinalization</tt> method</a> <li><a href="#doFinalization_mod">The <tt>doFinalization(Module
&amp;)</tt> method</a>
</ul> </ul>
<li><a href="#BasicBlockPass">The <tt>BasicBlockPass</tt> class</a> <li><a href="#BasicBlockPass">The <tt>BasicBlockPass</tt> class</a>
<ul> <ul>
<li><a href="#doInitialization_fn">The <tt>doInitialization(Function
&amp;)</tt> method</a>
<li><a href="#runOnBasicBlock">The <tt>runOnBasicBlock</tt> method</a> <li><a href="#runOnBasicBlock">The <tt>runOnBasicBlock</tt> method</a>
<li><a href="#doFinalization_fn">The <tt>doFinalization(Function
&amp;)</tt> method</a>
</ul> </ul>
</ul> </ul>
<li><a href="#registration">Pass Registration</a> <li><a href="#registration">Pass Registration</a>
@ -424,8 +430,8 @@ may overload three virtual methods to do their work. All of these methods
should return true if they modified the program, or false if they didn't.<p> should return true if they modified the program, or false if they didn't.<p>
<!-- _______________________________________________________________________ --> <!-- _______________________________________________________________________ -->
</ul><h4><a name="doInitialization"><hr size=0>The <tt>doInitialization</tt> </ul><h4><a name="doInitialization_mod"><hr size=0>The
method</h4><ul> <tt>doInitialization(Module &amp;)</tt> method</h4><ul>
<pre> <pre>
<b>virtual bool</b> doInitialization(Module &amp;M); <b>virtual bool</b> doInitialization(Module &amp;M);
@ -433,10 +439,11 @@ method</h4><ul>
The <tt>doIninitialize</tt> method is allowed to do most of the things that The <tt>doIninitialize</tt> method is allowed to do most of the things that
<tt>FunctionPass</tt>'s are not allowed to do. They can add and remove <tt>FunctionPass</tt>'s are not allowed to do. They can add and remove
functions, get pointers to functions, etc. The <tt>doInitialize</tt> method is functions, get pointers to functions, etc. The <tt>doInitialization</tt> method
designed to do simple initialization type of stuff that does not depend on the is designed to do simple initialization type of stuff that does not depend on
functions being processed. The <tt>doInitialization</tt> function call is not the functions being processed. The <tt>doInitialization</tt> method call is not
scheduled to overlap with any other pass executions.<p> scheduled to overlap with any other pass executions (thus it should be very
fast).<p>
A good example of how this method should be used is the <a A good example of how this method should be used is the <a
href="http://llvm.cs.uiuc.edu/doxygen/LowerAllocations_8cpp-source.html">LowerAllocations</a> href="http://llvm.cs.uiuc.edu/doxygen/LowerAllocations_8cpp-source.html">LowerAllocations</a>
@ -457,7 +464,7 @@ transformation or analysis work of your pass. As usual, a true value should be
returned if the function is modified.<p> returned if the function is modified.<p>
<!-- _______________________________________________________________________ --> <!-- _______________________________________________________________________ -->
</ul><h4><a name="doFinalization"><hr size=0>The <tt>doFinalization</tt> method</h4><ul> </ul><h4><a name="doFinalization_mod"><hr size=0>The <tt>doFinalization(Module &amp;)</tt> method</h4><ul>
<pre> <pre>
<b>virtual bool</b> doFinalization(Module &amp;M); <b>virtual bool</b> doFinalization(Module &amp;M);
@ -493,10 +500,26 @@ As such, they are <b>not</b> allowed to do any of the following:<p>
<tt>BasicBlockPass</tt>'s are useful for traditional local and "peephole" <tt>BasicBlockPass</tt>'s are useful for traditional local and "peephole"
optimizations. They may override the same <a optimizations. They may override the same <a
href="#doInitialization"><tt>doInitialization</tt></a> and <a href="#doInitialization_mod"><tt>doInitialization(Module &amp;)</tt></a> and <a
href="#doFinalization"><tt>doFinalization</tt></a> methods that <a href="#doFinalization_mod"><tt>doFinalization(Module &amp;)</tt></a> methods that <a
href="#FunctionPass"><tt>FunctionPass</tt></a>'s have, but also have a href="#FunctionPass"><tt>FunctionPass</tt></a>'s have, but also have the following virtual methods that may also be implemented:<p>
<tt>runOnBasicBlock</tt> method:<p>
<!-- _______________________________________________________________________ -->
</ul><h4><a name="doInitialization_fn"><hr size=0>The
<tt>doInitialization(Function &amp;)</tt> method</h4><ul>
<pre>
<b>virtual bool</b> doInitialization(Function &amp;F);
</pre><p>
The <tt>doIninitialize</tt> method is allowed to do most of the things that
<tt>BasicBlockPass</tt>'s are not allowed to do, but that
<tt>FunctionPass</tt>'s can. The <tt>doInitialization</tt> method is designed
to do simple initialization type of stuff that does not depend on the
BasicBlocks being processed. The <tt>doInitialization</tt> method call is not
scheduled to overlap with any other pass executions (thus it should be very
fast).<p>
<!-- _______________________________________________________________________ --> <!-- _______________________________________________________________________ -->
</ul><h4><a name="runOnBasicBlock"><hr size=0>The <tt>runOnBasicBlock</tt> method</h4><ul> </ul><h4><a name="runOnBasicBlock"><hr size=0>The <tt>runOnBasicBlock</tt> method</h4><ul>
@ -511,6 +534,22 @@ parameter, and are not allowed to modify the CFG. A true value must be returned
if the basic block is modified.<p> if the basic block is modified.<p>
<!-- _______________________________________________________________________ -->
</ul><h4><a name="doFinalization_fn"><hr size=0>The <tt>doFinalization(Function
&amp;)</tt> method</h4><ul>
<pre>
<b>virtual bool</b> doFinalization(Function &amp;F);
</pre</p>
The <tt>doFinalization</tt> method is an infrequently used method that is called
when the pass framework has finished calling <a
href="#runOnBasicBlock"><tt>runOnBasicBlock</tt></a> for every BasicBlock in the
program being compiled. This can be used to perform per-function
finalization.<p>
<!-- *********************************************************************** --> <!-- *********************************************************************** -->
</ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0> </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
<tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b> <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
@ -1164,6 +1203,6 @@ href="#Pass"><tt>Pass</tt></a>, only the other way around.<p>
<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address> <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
<!-- Created: Tue Aug 6 15:00:33 CDT 2002 --> <!-- Created: Tue Aug 6 15:00:33 CDT 2002 -->
<!-- hhmts start --> <!-- hhmts start -->
Last modified: Thu Sep 5 15:06:01 CDT 2002 Last modified: Thu Sep 12 11:46:40 CDT 2002
<!-- hhmts end --> <!-- hhmts end -->
</font></body></html> </font></body></html>

View File

@ -250,15 +250,36 @@ private:
/// 3. Optimizations conform to all of the contstraints of FunctionPass's. /// 3. Optimizations conform to all of the contstraints of FunctionPass's.
/// ///
struct BasicBlockPass : public FunctionPass { struct BasicBlockPass : public FunctionPass {
/// doInitialization - Virtual method overridden by subclasses to do
/// any neccesary per-module initialization.
///
virtual bool doInitialization(Module &M) { return false; }
/// doInitialization - Virtual method overridden by BasicBlockPass subclasses
/// to do any neccesary per-function initialization.
///
virtual bool doInitialization(Function &F) { return false; }
/// runOnBasicBlock - Virtual method overriden by subclasses to do the /// runOnBasicBlock - Virtual method overriden by subclasses to do the
/// per-basicblock processing of the pass. /// per-basicblock processing of the pass.
/// ///
virtual bool runOnBasicBlock(BasicBlock &BB) = 0; virtual bool runOnBasicBlock(BasicBlock &BB) = 0;
/// To run this pass on a function, we simply call runOnBasicBlock once for /// doFinalization - Virtual method overriden by BasicBlockPass subclasses to
/// each function. /// do any post processing needed after all passes have run.
/// ///
virtual bool runOnFunction(Function &F); virtual bool doFinalization(Function &F) { return false; }
/// doFinalization - Virtual method overriden by subclasses to do any post
/// processing needed after all passes have run.
///
virtual bool doFinalization(Module &M) { return false; }
// To run this pass on a function, we simply call runOnBasicBlock once for
// each function.
//
bool runOnFunction(Function &F);
/// To run directly on the basic block, we initialize, runOnBasicBlock, then /// To run directly on the basic block, we initialize, runOnBasicBlock, then
/// finalize. /// finalize.