Instantiating the new Instructions from CallInst Class

Hello All,

I'm developing timing analysis tool using LLVM.
After several analysis phases, I want to instantiate several instructions in the basic block.
Instructions that I try to instantiate are like below;

call void (int)* %waitABC(int 10)
%tmp = call int (int, int*)* %doABC(int %i, int* %total)

I think I should use 'CallInst' class in 'Instructions.h' file.
How I could make those instructions from 'CallInst' class?
Thank you.

- Yonghyun

Hi,

prior to call a function it should be declared in your
Hi

After several analysis phases, I want to instantiate several
instructions in the basic block.
Instructions that I try to instantiate are like below;

call void (int)* %waitABC(int 10)
%tmp = call int (int, int*)* %doABC(int %i, int* %total)

I think I should use 'CallInst' class in 'Instructions.h' file.
How I could make those instructions from 'CallInst' class?

To be able to call a function let's say "waitABC" that you have
defined in somewhere else you have to declare it in your module. To
declare a Function you have to create a Function object with empty
basic block (see
LLVM Programmer’s Manual — LLVM 16.0.0git documentation)

The code should be something like this:

Function *f = new Function(TheTypeOfYourFunction,
GlobalValue::ExternalLinkage, "FunctionName",
ModuleToPutYourFunction);
CallInst callInst = new CallInst(f, args, "valueName",
InstructionToInsertBefore);