<pre style="white-space:pre-wrap">Actually I tried ModulePass. It works exactly as what I expect.But I found another problem. In ModulePass, it not only collects the functions I create, it also treat some system function such as 'printf' as a function. I do not if I does something wrong. The codes I use is as follows:</pre>
<pre style="white-space:pre-wrap"><p style="margin:0px;font-size:13px;font-family:Monaco"> <span style="color:#931a68">virtual</span> <span style="color:#931a68">bool</span> runOnModule(Module &M) {</p><p style="margin:0px;font-size:13px;font-family:Monaco">
<span class="Apple-tab-span" style="white-space:pre"> </span><span style="color:#931a68">for</span> (Module::iterator b = M.begin(), be = M.end(); b != be; ++b) {</p><p style="margin:0px;font-size:13px;font-family:Monaco">
<span class="Apple-tab-span" style="white-space:pre"> </span>Function *ff = dyn_cast<Function>(b);</p><p style="margin:0px;font-size:13px;font-family:Monaco"> <span class="Apple-tab-span" style="white-space:pre"> </span>errs() <<<span style="color:#3933ff">"testff0: "</span><<funcname_index<<<span style="color:#3933ff">'\n'</span>;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco"> <span class="Apple-tab-span" style="white-space:pre"> </span>funcname[funcname_index++] = ff->getName();</p><p style="margin:0px;font-size:13px;font-family:Monaco">
<span class="Apple-tab-span" style="white-space:pre"> </span>}</p><p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(147,26,104)"><span style="color:#000000"> <span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></p>
<p style="margin:0px;font-size:13px;font-family:Monaco"> }</p><p style="margin:0px;font-size:13px;font-family:Monaco"><br></p><p style="margin:0px;font-size:13px;font-family:Monaco">My test source file:</p><p style="margin:0px;font-size:13px;font-family:Monaco">
<br></p><p style="margin:0px;font-size:13px;font-family:Monaco">void A(){}</p><p style="margin:0px;font-size:13px;font-family:Monaco">void B(){printf("dada");}</p><p style="margin:0px;font-size:13px;font-family:Monaco">
void main(){A(); B();}</p><p style="margin:0px;font-size:13px;font-family:Monaco"><br></p><p style="margin:0px;font-size:13px;font-family:Monaco">The ModulePass output is:</p><p style="margin:0px;font-size:13px;font-family:Monaco">
A</p><p style="margin:0px;font-size:13px;font-family:Monaco">B</p><p style="margin:0px;font-size:13px;font-family:Monaco">printf</p><p style="margin:0px;font-size:13px;font-family:Monaco">main</p><p style="margin:0px;font-size:13px;font-family:Monaco">
<br></p><p style="margin:0px;font-size:13px;font-family:Monaco"><br></p><p style="margin:0px;font-size:13px;font-family:Monaco">Thanks.</p><p style="margin:0px;font-size:13px;font-family:Monaco">Robert</p></pre><pre style="white-space:pre-wrap">
<br></pre><pre style="white-space:pre-wrap"><br></pre><pre style="white-space:pre-wrap"><br></pre><pre style="white-space:pre-wrap">---------------------------------------------------------------------------</pre><pre style="white-space:pre-wrap">
Hi Robert,
Function passes are expected to have local behavior that can be scheduled
on a per-function basis in no particular order. To get the behavior you
want, you probably want to make "FunctionPass1" a Module pass and have it
iterate through all of the functions in the module.
You can find more information about passes and how to choose a type of pass
in the llvm documentation at <a href="http://llvm.org/docs/WritingAnLLVMPass.html.">http://llvm.org/docs/WritingAnLLVMPass.html.</a>
Cheers,
Scott
On Sat, Feb 23, 2013 at 1:37 AM, Robert Sandra
<<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">robert.sandra0712 at gmail.com</a>>wrote:
><i> Hi all,
</i>><i>
</i>><i> I am trying to run a case as follows:
</i>><i>
</i>><i> FunctionPass1: try to get all function's names and store them to a global
</i>><i> array
</i>><i> FunctionPass2: get information from the global array
</i>><i> In FunctionPass2, I use getAnalysisUsage() to set that to run
</i>><i> FunctionPass2, FunctionPass1 should be executed first.
</i>><i>
</i>><i> But according to the running result, I found that these two passes are
</i>><i> executing at the same time,
</i>><i> which means After FunctionPass1 iterate one function, then FunctionPass2
</i>><i> will be executed to iterate one function; then FunctionPass1 continues to
</i>><i> run, and then FunctionPass2....
</i>><i>
</i>><i> While, what I expected is that the FunctionPass1 will complete first, then
</i>><i> FunctionPass2 will be executed. Am I understanding wrong?
</i>><i>
</i>><i> Thanks.
</i>><i> Robert
</i>><i>
</i>><i> _______________________________________________
</i>><i> LLVM Developers mailing list
</i>><i> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVMdev at cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu</a>
</i>><i> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</i>><i>
</i>></pre>