Both 1 and 2 are "true". It returns the call instruction, whose "value", when we execute the code, will be the return value of the function.
To illustrate, take this little Pascal program:
program p;
function f: integer;
begin
f := 42;
end; { f }
begin
writeln(f);
end.
Which translates to this LLVM-IR:
; ModuleID = 'TheModule'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%text = type { i32, i8*, i32, i32 }
@input = global %text zeroinitializer, align 8
@output = global %text zeroinitializer, align 8
@UnitIniList = constant [1 x i8*] zeroinitializer
define i32 @P.f() #0 {
entry:
%f = alloca i32, align 4
store i32 42, i32* %f
%0 = load i32, i32* %f
ret i32 %0
}
define void @__PascalMain() #0 {
entry:
%calltmp = call i32 @P.f()
call void @__write_int(%text* @output, i32 %calltmp, i32 0)
call void @__write_nl(%text* @output)
ret void
}
declare void @__write_int(%text*, i32, i32)
declare void @__write_nl(%text*)
attributes #0 = { "no-frame-pointer-elim"="true" }
The call i32 @P.f() is generated by:
inst = builder.CreateCall(calleF, argsV, "calltmp");
The contents of inst is %calltmp = call i32 @P.f() - and that is a CallInst 'value'.
and inst is returned to the evaluation of the expression for the argument to writeln.
LLVM
llvm.org › doxygen › classllvm_1_1CallInst.html
LLVM: llvm::CallInst Class Reference
Inheritance diagram for llvm::CallInst: [legend] This class represents a function call, abstracting a target machine's calling convention. This class uses low bit of the SubClassData field to indicate whether or not this is a tail call. The rest of the bits hold the calling convention of the call.
Vu
few.vu.nl › ~lsc300 › LLVM › doxygen › classllvm_1_1CallInst.html
LLVM: llvm::CallInst Class Reference
CallInst - This class represents a function call, abstracting a target machine's calling convention. This class uses low bit of the SubClassData field to indicate whether or not this is a tail call.
Google Groups
groups.google.com › g › llvm-dev › c › ugSGgReOB1Q
[LLVMdev] How to access the return value of a CallInst
I have something like the following: CallInst *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(), "log_load_addr_ret", LI); CastInst *InsertedCast = CastInst::CreateTruncOrBitCast(InitCall.getCalledValue(), LI->getType(), "return_load", LI); I assume that getCalledValue() will give me the return value of the InitCall CallInst. This compiles fine. But the CastInst cannot be created. The runtime error is : opt: /panfs/panasas-01.cs.wisc.edu/scratch/wang/LLVM/src/llvm/lib/VMCore/Instructions.cpp:2338: llvm::TruncInst::TruncInst(llvm::Value*, const llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal Trunc"' failed.
Hdoc
docs.hdoc.io › hdoc › llvm-project › r7343C8EC823E5DC1.html
class CallInst: LLVM/Clang 15.x documentation
public static llvm::CallInst * Create(llvm::FunctionCallee Func, ArrayRef<llvm::Value *> Args, ArrayRef<llvm::OperandBundleDef> Bundles = None, const llvm::Twine & NameStr = "", llvm::Instruction * InsertBefore = nullptr)
LLVM
llvm.org › doxygen › classllvm_1_1sandboxir_1_1CallInst.html
LLVM: llvm::sandboxir::CallInst Class Reference
llvm · sandboxir · CallInst · Static Public Member Functions | Friends | List of all members · llvm::sandboxir::CallInst Class Reference · #include "llvm/SandboxIR/Instruction.h" Inheritance diagram for llvm::sandboxir::CallInst: [legend] Definition at line 1494 of file Instruction.h.
LLVM Discussion Forums
discourse.llvm.org › project infrastructure › llvm dev list archives
Insert CallInst within a function passing same parameters of the calling function. - LLVM Dev List Archives - LLVM Discussion Forums
March 1, 2016 - Hi, supposing I have a function “foo” like the following: int foo(int a, int b) { ... ... } I want to insert int the LLVM IR a call instructions to a function “bar” that requires the same parameters of foo. So my function foo will become: int foo(int a, int b) { bar(a,b); … ... } I am using the following code: bool ThreadSanitizer::runOnFunction(Function &F) { ValueToValueMapTy VMap; Function *new_function = CloneFunction(&F, VMap, false); new_function->setName...
Database Systems
db.in.tum.de › teaching › ss16 › moderndbs › resources › 7 › fibonacci.cpp
LLVM example program
BasicBlock* RecurseBB = BasicBlock::Create(Context, "recurse", FibF); // Create the "if (arg <= 2) goto exitbb" Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond"); BranchInst::Create(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 ReturnInst::Create(Context, One, RetBB); // create fib(x-1) Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB); CallInst *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB); CallFibX1->setTailCall(); // create fib(x-2) Sub = BinaryOperator::CreateSub(ArgX, Two, "arg", RecurseBB); CallInst *CallFibX2 = CallInst::
GitHub
github.com › llvm › llvm-project › blob › main › llvm › lib › IR › IntrinsicInst.cpp
llvm-project/llvm/lib/IR/IntrinsicInst.cpp at main · llvm/llvm-project
M, llvm::Intrinsic::experimental_convergence_anchor); auto *Call = CallInst::Create(Fn, "", BB.getFirstInsertionPt()); return cast<ConvergenceControlInst>(Call); } ·
Author llvm
Stack Overflow
stackoverflow.com › questions › 32156640 › creating-a-callinst-to-an-external-function
llvm - creating a callinst to an external function - Stack Overflow
C++ method names also have name mangling so it's not using the symbol "foo". When using mcjit it lowers your IR to machine code, it doesn't actually execute the IR so when running you're not passing llvm::Function or llvm::BasicBlock so the instrumentation function won't work even if you called it like that.
Hdoc
docs.hdoc.io › hdoc › llvm-project › r4D5D8AFED2D433D2.html
class IntrinsicInst: LLVM/Clang 15.x documentation
Building LLVM · Coding Standards · API Documentation · Functions · Records · Enums · Namespaces · class IntrinsicInst : public CallInst { /* full declaration omitted */ }; A wrapper class for inspecting calls to intrinsic functions. This allows the standard isa/dyncast/cast functionality ...
Google Groups
groups.google.com › g › llvm-dev › c › Smr-KrHHLWQ
[LLVMdev] How to create arguments CallInst
For example, if the argument is long, accurate pass CallInst an integer argument, however, if a Char, Char must pass an argument.
LLVM Discussion Forums
discourse.llvm.org › project infrastructure › llvm dev list archives
creating a callinst to an external function - LLVM Dev List Archives - LLVM Discussion Forums
August 19, 2015 - Dear All I’m making an instrumentation pass. The pass is supposed to modify the given IR in a specefic way. One of the required modifications is to insert a call to a function at a specific location. This is the signature of the called function: void myclass::foo(Function f, BasicBlock b) ...
MIT CSAIL
groups.csail.mit.edu › graphics › face › xform › halide › clang+llvm-3.3-amd64-debian6 › include › llvm › IR › Instructions.h
https://groups.csail.mit.edu/graphics/face/xform/h...
Args, const Twine &NameStr, BasicBlock *InsertAtEnd); CallInst(Value *F, Value *Actual, const Twine &NameStr, Instruction *InsertBefore); CallInst(Value *F, Value *Actual, const Twine &NameStr, BasicBlock *InsertAtEnd); explicit CallInst(Value *F, const Twine &NameStr, Instruction *InsertBefore); CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); protected: virtual CallInst *clone_impl() const; public: static CallInst *Create(Value *Func, ArrayRef
LLVM Discussion Forums
discourse.llvm.org › ir & optimizations
RFC: Requiring callinst function type to match the type of the function being called? - IR & Optimizations - LLVM Discussion Forums
May 17, 2025 - I’ve just seen if (CB->getFunctionType() != F.getFunctionType()) return false; written in another place and thought I’d ask if we can make that a verifier error instead. Currently the type of the callee of a call instruction can be different from the type of the function being called.