CallSite.h revision 95ab3d4bc492707bdb6a3e60cffabaa875c1f5e6
1//===-- llvm/Support/CallSite.h - Abstract Call & Invoke instrs -*- C++ -*-===//
2//
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.
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef LLVM_SUPPORT_CALLSITE_H
9#define LLVM_SUPPORT_CALLSITE_H
10
11#include "llvm/Instruction.h"
12
13class CallInst;
14class InvokeInst;
15
16class CallSite {
17  Instruction *I;
18public:
19  CallSite() : I(0) {}
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; }
24
25  /// getInstruction - Return the instruction this call site corresponds to
26  Instruction *getInstruction() const { return I; }
27
28  /// getCalledValue - Return the pointer to function that is being called...
29  ///
30  Value *getCalledValue() const { return I->getOperand(0); }
31
32  /// getCalledFunction - Return the function being called if this is a direct
33  /// call, otherwise return null (if it's an indirect call).
34  ///
35  Function *getCalledFunction() const {
36    return dyn_cast<Function>(getCalledValue());
37  }
38
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;
42
43  /// arg_begin/arg_end - Return iterators corresponding to the actual argument
44  /// list for a call site.
45  ///
46  arg_iterator arg_begin() const {
47    if (I->getOpcode() == Instruction::Call)
48      return I->op_begin()+1; // Skip Function
49    else
50      return I->op_begin()+3; // Skip Function, BB, BB
51  }
52  arg_iterator arg_end() const { return I->op_begin(); }
53};
54
55#endif
56