[llvm] r260332 - Add binding for counting argument and find called value of call and invoke instruction from the C API.
Amaury Sechet via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 9 16:09:37 PST 2016
Author: deadalnix
Date: Tue Feb 9 18:09:37 2016
New Revision: 260332
URL: http://llvm.org/viewvc/llvm-project?rev=260332&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/tools/llvm-c-test/echo.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=260332&r1=260331&r2=260332&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Tue Feb 9 18:09:37 2016
@@ -2386,6 +2386,17 @@ LLVMValueRef LLVMInstructionClone(LLVMVa
*/
/**
+ * Obtain the argument count for a call instruction.
+ *
+ * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
+ * llvm::InvokeInst.
+ *
+ * @see llvm::CallInst::getNumArgOperands()
+ * @see llvm::InvokeInst::getNumArgOperands()
+ */
+unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
+
+/**
* Set the calling convention for a call instruction.
*
* This expects an LLVMValueRef that corresponds to a llvm::CallInst or
@@ -2414,6 +2425,17 @@ void LLVMSetInstrParamAlignment(LLVMValu
unsigned align);
/**
+ * Obtain the pointer to the function invoked by this instruction.
+ *
+ * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
+ * llvm::InvokeInst.
+ *
+ * @see llvm::CallInst::getCalledValue()
+ * @see llvm::InvokeInst::getCalledValue()
+ */
+LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
+
+/**
* Obtain whether a call instruction is a tail call.
*
* This only works on llvm::CallInst instructions.
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=260332&r1=260331&r2=260332&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Tue Feb 9 18:09:37 2016
@@ -2041,22 +2041,17 @@ LLVMValueRef LLVMInstructionClone(LLVMVa
/*--.. Call and invoke instructions ........................................--*/
+unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {
+ return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands();
+}
+
unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
- Value *V = unwrap(Instr);
- if (CallInst *CI = dyn_cast<CallInst>(V))
- return CI->getCallingConv();
- if (InvokeInst *II = dyn_cast<InvokeInst>(V))
- return II->getCallingConv();
- llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
+ return CallSite(unwrap<Instruction>(Instr)).getCallingConv();
}
void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
- Value *V = unwrap(Instr);
- if (CallInst *CI = dyn_cast<CallInst>(V))
- return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
- else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
- return II->setCallingConv(static_cast<CallingConv::ID>(CC));
- llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
+ return CallSite(unwrap<Instruction>(Instr))
+ .setCallingConv(static_cast<CallingConv::ID>(CC));
}
void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
@@ -2090,6 +2085,10 @@ void LLVMSetInstrParamAlignment(LLVMValu
index, B)));
}
+LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {
+ return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
+}
+
/*--.. Operations on call instructions (only) ..............................--*/
LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
Modified: llvm/trunk/tools/llvm-c-test/echo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/echo.cpp?rev=260332&r1=260331&r2=260332&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/echo.cpp (original)
+++ llvm/trunk/tools/llvm-c-test/echo.cpp Tue Feb 9 18:09:37 2016
@@ -336,10 +336,10 @@ struct FunCloner {
}
case LLVMCall: {
SmallVector<LLVMValueRef, 8> Args;
- int ArgCount = LLVMGetNumOperands(Src) - 1;
+ int ArgCount = LLVMGetNumArgOperands(Src);
for (int i = 0; i < ArgCount; i++)
Args.push_back(CloneValue(LLVMGetOperand(Src, i)));
- LLVMValueRef Fn = CloneValue(LLVMGetOperand(Src, ArgCount));
+ LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name);
break;
}
More information about the llvm-commits
mailing list