mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-29 14:20:29 +00:00
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 llvm-svn: 260332
This commit is contained in:
parent
c74a4e9807
commit
cd1fa43291
@ -2385,6 +2385,17 @@ LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@ -2413,6 +2424,17 @@ void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
|
||||
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
|
||||
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.
|
||||
*
|
||||
|
@ -2041,22 +2041,17 @@ LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) {
|
||||
|
||||
/*--.. 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(LLVMValueRef Instr, unsigned index,
|
||||
index, B)));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {
|
||||
return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
|
||||
}
|
||||
|
||||
/*--.. Operations on call instructions (only) ..............................--*/
|
||||
|
||||
LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user