FunctionType *funcType = FunctionType::get(IntegerType::get(context, 32), {IntegerType::get(context, 32), IntegerType::get(context, 32)}, false); Function *func = Function::Create(funcType, GlobalValue::ExternalLinkage, "add", module); BasicBlock *entry = BasicBlock::Create(context, "entry", func); LLVMContext &context = getGlobalContext(); ConstantInt *val1 = ConstantInt::get(IntegerType::get(context, 32), 10); ConstantInt *val2 = ConstantInt::get(IntegerType::get(context, 32), 20); CallInst *callInst = CallInst::Create(func, {val1, val2}, "", entry); Value *operand = callInst->getOperand(0); errs() << "Operand value: " << *operand << "\n";
Value *operand = llvm::dyn_castIn this example, we use the dyn_cast method to cast the instruction pointed to by the "inst" pointer to a CallInst pointer. We then call the CallInst getOperand method to retrieve the first operand of the call instruction. Package/library: LLVM(inst)->getOperand(0);