1 //===-- llvm/Support/CallSite.h - Abstract Call & Invoke instrs -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the CallSite class, which is a handy wrapper for code that
11 // wants to treat Call and Invoke instructions in a generic way.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_CALLSITE_H
16 #define LLVM_SUPPORT_CALLSITE_H
18 #include "llvm/Instruction.h"
27 CallSite(CallInst *CI) : I((Instruction*)CI) {}
28 CallSite(InvokeInst *II) : I((Instruction*)II) {}
29 CallSite(const CallSite &CS) : I(CS.I) {}
30 CallSite &operator=(const CallSite &CS) { I = CS.I; return *this; }
32 /// CallSite::get - This static method is sort of like a constructor. It will
33 /// create an appropriate call site for a Call or Invoke instruction, but it
34 /// can also create a null initialized CallSite object for something which is
37 static CallSite get(Value *V) {
38 if (Instruction *I = dyn_cast<Instruction>(V)) {
39 if (I->getOpcode() == Instruction::Call)
40 return CallSite((CallInst*)I);
41 else if (I->getOpcode() == Instruction::Invoke)
42 return CallSite((InvokeInst*)I);
47 /// getInstruction - Return the instruction this call site corresponds to
49 Instruction *getInstruction() const { return I; }
51 /// getCalledValue - Return the pointer to function that is being called...
53 Value *getCalledValue() const {
54 assert(I && "Not a call or invoke instruction!");
55 return I->getOperand(0);
58 /// getCalledFunction - Return the function being called if this is a direct
59 /// call, otherwise return null (if it's an indirect call).
61 /// FIXME: This should be inlined once ConstantPointerRefs are gone. :(
62 Function *getCalledFunction() const;
64 /// setCalledFunction - Set the callee to the specified value...
66 void setCalledFunction(Value *V) {
67 assert(I && "Not a call or invoke instruction!");
71 /// arg_iterator - The type of iterator to use when looping over actual
72 /// arguments at this call site...
73 typedef User::op_iterator arg_iterator;
75 /// arg_begin/arg_end - Return iterators corresponding to the actual argument
76 /// list for a call site.
78 arg_iterator arg_begin() const {
79 assert(I && "Not a call or invoke instruction!");
80 if (I->getOpcode() == Instruction::Call)
81 return I->op_begin()+1; // Skip Function
83 return I->op_begin()+3; // Skip Function, BB, BB
85 arg_iterator arg_end() const { return I->op_end(); }