[llvm-dev] Inserting an external call in FunctionPass

John Criswell via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 27 09:37:33 PDT 2017


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



More information about the llvm-dev mailing list