[LLVMdev] One question about two passes interaction

Scott Moore sdmoore at fas.harvard.edu
Fri Feb 22 23:26:38 PST 2013


LLVM modules contain declarations of external functions, which are still
"functions".
You can filter these out by checking ff->isDeclaration().
Cheers,
Scott


On Sat, Feb 23, 2013 at 2:10 AM, Robert Sandra
<robert.sandra0712 at gmail.com>wrote:

> 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:
>
>  virtual bool runOnModule(Module &M) {
>
>
>     	for (Module::iterator b = M.begin(), be = M.end(); b != be; ++b) {
>
>
>     		Function *ff = dyn_cast<Function>(b);
>
>     		errs() <<"testff0: "<<funcname_index<<'\n';
>
>     		funcname[funcname_index++] = ff->getName();
>
>
>     	}
>
>     	return false;
>
>   }
>
>
> My test source file:
>
>
> void A(){}
>
> void B(){printf("dada");}
>
>
> void main(){A(); B();}
>
>
> The ModulePass output is:
>
>
> A
>
> B
>
> printf
>
> main
>
>
>
> Thanks.
>
> Robert
>
>
>
>
> ---------------------------------------------------------------------------
>
>
> 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 http://llvm.org/docs/WritingAnLLVMPass.html.
>
>
> Cheers,
> Scott
>
>
> On Sat, Feb 23, 2013 at 1:37 AM, Robert Sandra
> <robert.sandra0712 at gmail.com <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>>wrote:
>
> >* Hi all,*
> >**>* I am trying to run a case as follows:*>**>* FunctionPass1:  try to get all function's names and store them to a global*>* array*>* FunctionPass2:  get information from the global array*>* In FunctionPass2, I use getAnalysisUsage() to set that to run*>* FunctionPass2, FunctionPass1 should be executed first.*>**>* But according to the running result, I found that these two passes are*>* executing at the same time,*>* which means After FunctionPass1 iterate one function, then FunctionPass2*>* will be executed to iterate one function; then FunctionPass1 continues to*>* run, and then FunctionPass2....*>**>* While, what I expected is that the FunctionPass1 will complete first, then*>* FunctionPass2 will be executed. Am I understanding wrong?*>**>* Thanks.*>* Robert*>**>* _______________________________________________*>* LLVM Developers mailing list*
> >* LLVMdev at cs.uiuc.edu <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>         http://llvm.cs.uiuc.edu*>* http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev*>**>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130223/f5722c58/attachment.html>


More information about the llvm-dev mailing list