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 /// CallSite::get - This static method is sort of like a constructor. It will
26 /// create an appropriate call site for a Call or Invoke instruction, but it
27 /// can also create a null initialized CallSite object for something which is
30 static CallSite get(Value *V) {
31 if (Instruction *I = dyn_cast<Instruction>(V)) {
32 if (I->getOpcode() == Instruction::Call)
33 return CallSite((CallInst*)I);
34 else if (I->getOpcode() == Instruction::Invoke)
35 return CallSite((InvokeInst*)I);
40 /// getInstruction - Return the instruction this call site corresponds to
42 Instruction *getInstruction() const { return I; }
44 /// getCalledValue - Return the pointer to function that is being called...
46 Value *getCalledValue() const { return I->getOperand(0); }
48 /// getCalledFunction - Return the function being called if this is a direct
49 /// call, otherwise return null (if it's an indirect call).
51 Function *getCalledFunction() const {
52 return dyn_cast<Function>(getCalledValue());
55 /// setCalledFunction - Set the callee to the specied value...
57 void setCalledFunction(Value *V) {
61 /// arg_iterator - The type of iterator to use when looping over actual
62 /// arguments at this call site...
63 typedef User::op_iterator arg_iterator;
65 /// arg_begin/arg_end - Return iterators corresponding to the actual argument
66 /// list for a call site.
68 arg_iterator arg_begin() const {
69 if (I->getOpcode() == Instruction::Call)
70 return I->op_begin()+1; // Skip Function
72 return I->op_begin()+3; // Skip Function, BB, BB
74 arg_iterator arg_end() const { return I->op_end(); }