Evgenii Stepanov via llvm-dev
2017-Mar-24 00:19 UTC
[llvm-dev] Inserting an external call in FunctionPass
Hi, how do I insert a call to an external function in a FunctionPass? My problem is with creation of the declaration for the external function. According to http://llvm.org/docs/WritingAnLLVMPass.html#the-functionpass-class, a FunctionPass is not supposed to add or remove functions. I assume it's also true for function declarations. A declaration inserted in doInitialization is cleaned up in GlobalOptLegacyPass::runOnModule, which happens to run before my pass' runOnFunction(). Do I need a ModulePass for this?
John Criswell via llvm-dev
2017-Mar-27 16:37 UTC
[llvm-dev] Inserting an external call in FunctionPass
On 3/23/17 8:19 PM, Evgenii Stepanov via llvm-dev wrote:> Hi, > > how do I insert a call to an external function in a FunctionPass? > My problem is with creation of the declaration for the external function. > > According to http://llvm.org/docs/WritingAnLLVMPass.html#the-functionpass-class, > a FunctionPass is not supposed to add or remove functions. I assume > it's also true for function declarations. > > A declaration inserted in doInitialization is cleaned up in > GlobalOptLegacyPass::runOnModule, which happens to run before my pass' > runOnFunction(). > > Do I need a ModulePass for this?I see two possible solutions: 1. Inform the GlobalOptLegacyPass that it should not remove the function when you add it in doInitialization(). I believe adding the function to the llvm.used or llvm.compiler.used array will prevent the function from being removed. Skim the LLVM Language Reference Manual to see how to do this (http://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable) 2. Make your pass a ModulePass. Regards, John Criswell> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell
Reid Kleckner via llvm-dev
2017-Mar-29 18:54 UTC
[llvm-dev] Inserting an external call in FunctionPass
I think the documentation is wrong. Existing function passes frequently insert new intrinsic function declarations, and we expect that to work. The loop vectorizer also inserts calls to non-intrinsic library functions. The intention is that function passes don't introduce new function definitions, because then an outer pass manager would need to discover them and add them to its worklist. On Thu, Mar 23, 2017 at 5:19 PM, Evgenii Stepanov via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi, > > how do I insert a call to an external function in a FunctionPass? > My problem is with creation of the declaration for the external function. > > According to http://llvm.org/docs/WritingAnLLVMPass.html#the- > functionpass-class, > a FunctionPass is not supposed to add or remove functions. I assume > it's also true for function declarations. > > A declaration inserted in doInitialization is cleaned up in > GlobalOptLegacyPass::runOnModule, which happens to run before my pass' > runOnFunction(). > > Do I need a ModulePass for this? > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170329/1d517881/attachment.html>