[llvm-dev] Add Call instruction in IR for a non-existing function

serge guelton via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 5 13:38:08 PDT 2016


On Tue, Apr 05, 2016 at 04:28:18PM -0400, fateme Hoseini via llvm-dev wrote:
> Hello everyone,
> I am trying to add checkpoints to my IR code. In order to do that I need to
> add this instruction:
> call void @m5_checkpoint(i64 0, i64 0)
> to some of the basic blocks in my benchmark.
> m5_checkpoint is a function defined for checkpointing in another simulator
> and is not included in my benchmark source code. So I need to create this
> instruction and I couldn't figure out how to do this by reading the manual.
> I will appreciate if anyone can help me .
> Regards,
> Fami

Hi Fami,

you need to declare your function as an external global Symbol in order
to use it (you will still need to provide the symbol at linktime
though).

One way to do this is to call the module method getOrInsertFunction
after creating the correct Functiontype:

    auto *FT = llvm::FunctionType::get(...);
    M.getOrInsertFunction("m5_checkpoint", FT)

hope it helps,

Serge


More information about the llvm-dev mailing list