1 //===-- llvm/Support/CallSite.h - Abstract Call & Invoke instrs -*- C++ -*-===//
3 // This file defines the CallSite class, which is a handy wrapper for code that
4 // wants to treat Call and Invoke instructions in a generic way.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_SUPPORT_CALLSITE_H
9 #define LLVM_SUPPORT_CALLSITE_H
11 #include "llvm/Instruction.h"
20 CallSite(CallInst *CI) : I((Instruction*)CI) {}
21 CallSite(InvokeInst *II) : I((Instruction*)II) {}
22 CallSite(const CallSite &CS) : I(CS.I) {}
23 CallSite &operator=(const CallSite &CS) { I = CS.I; return *this; }
25 /// getInstruction - Return the instruction this call site corresponds to
26 Instruction *getInstruction() const { return I; }
28 /// getCalledValue - Return the pointer to function that is being called...
30 Value *getCalledValue() const { return I->getOperand(0); }
32 /// getCalledFunction - Return the function being called if this is a direct
33 /// call, otherwise return null (if it's an indirect call).
35 Function *getCalledFunction() const {
36 return dyn_cast<Function>(getCalledValue());
39 /// arg_iterator - The type of iterator to use when looping over actual
40 /// arguments at this call site...
41 typedef User::op_iterator arg_iterator;
43 /// arg_begin/arg_end - Return iterators corresponding to the actual argument
44 /// list for a call site.
46 arg_iterator arg_begin() const {
47 if (I->getOpcode() == Instruction::Call)
48 return I->op_begin()+1; // Skip Function
50 return I->op_begin()+3; // Skip Function, BB, BB
52 arg_iterator arg_end() const { return I->op_begin(); }