llvm.org GIT mirror llvm / 6f6b354
Add binding for counting argument and find called value of call and invoke instruction from the C API. Summary: As per title. This remove the need to rely on internal knowledge of call and invoke instruction to find called value and argument count. Reviewers: bogner, chandlerc, echristo, dblaikie, joker.eph, Wallbraker Differential Revision: http://reviews.llvm.org/D17054 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260332 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 4 years ago
3 changed file(s) with 35 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
23852385 */
23862386
23872387 /**
2388 * Obtain the argument count for a call instruction.
2389 *
2390 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2391 * llvm::InvokeInst.
2392 *
2393 * @see llvm::CallInst::getNumArgOperands()
2394 * @see llvm::InvokeInst::getNumArgOperands()
2395 */
2396 unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2397
2398 /**
23882399 * Set the calling convention for a call instruction.
23892400 *
23902401 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
24112422 LLVMAttribute);
24122423 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
24132424 unsigned align);
2425
2426 /**
2427 * Obtain the pointer to the function invoked by this instruction.
2428 *
2429 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2430 * llvm::InvokeInst.
2431 *
2432 * @see llvm::CallInst::getCalledValue()
2433 * @see llvm::InvokeInst::getCalledValue()
2434 */
2435 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
24142436
24152437 /**
24162438 * Obtain whether a call instruction is a tail call.
20402040
20412041 /*--.. Call and invoke instructions ........................................--*/
20422042
2043 unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {
2044 return CallSite(unwrap(Instr)).getNumArgOperands();
2045 }
2046
20432047 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
2044 Value *V = unwrap(Instr);
2045 if (CallInst *CI = dyn_cast(V))
2046 return CI->getCallingConv();
2047 if (InvokeInst *II = dyn_cast(V))
2048 return II->getCallingConv();
2049 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
2048 return CallSite(unwrap(Instr)).getCallingConv();
20502049 }
20512050
20522051 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2053 Value *V = unwrap(Instr);
2054 if (CallInst *CI = dyn_cast(V))
2055 return CI->setCallingConv(static_cast(CC));
2056 else if (InvokeInst *II = dyn_cast(V))
2057 return II->setCallingConv(static_cast(CC));
2058 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
2052 return CallSite(unwrap(Instr))
2053 .setCallingConv(static_cast(CC));
20592054 }
20602055
20612056 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
20872082 .addAttributes(Call->getContext(), index,
20882083 AttributeSet::get(Call->getContext(),
20892084 index, B)));
2085 }
2086
2087 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {
2088 return wrap(CallSite(unwrap(Instr)).getCalledValue());
20902089 }
20912090
20922091 /*--.. Operations on call instructions (only) ..............................--*/
335335 }
336336 case LLVMCall: {
337337 SmallVector Args;
338 int ArgCount = LLVMGetNumOperands(Src) - 1;
338 int ArgCount = LLVMGetNumArgOperands(Src);
339339 for (int i = 0; i < ArgCount; i++)
340340 Args.push_back(CloneValue(LLVMGetOperand(Src, i)));
341 LLVMValueRef Fn = CloneValue(LLVMGetOperand(Src, ArgCount));
341 LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
342342 Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name);
343343 break;
344344 }