]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/CallSite.h
Update our device tree files to a Linux 4.10
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / CallSite.h
1 //===- CallSite.h - Abstract Call & Invoke instrs ---------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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. When in non-
12 // mutation context (e.g. an analysis) ImmutableCallSite should be used.
13 // Finally, when some degree of customization is necessary between these two
14 // extremes, CallSiteBase<> can be supplied with fine-tuned parameters.
15 //
16 // NOTE: These classes are supposed to have "value semantics". So they should be
17 // passed by value, not by reference; they should not be "new"ed or "delete"d.
18 // They are efficiently copyable, assignable and constructable, with cost
19 // equivalent to copying a pointer (notice that they have only a single data
20 // member). The internal representation carries a flag which indicates which of
21 // the two variants is enclosed. This allows for cheaper checks when various
22 // accessors of CallSite are employed.
23 //
24 //===----------------------------------------------------------------------===//
25
26 #ifndef LLVM_IR_CALLSITE_H
27 #define LLVM_IR_CALLSITE_H
28
29 #include "llvm/ADT/iterator_range.h"
30 #include "llvm/ADT/Optional.h"
31 #include "llvm/ADT/PointerIntPair.h"
32 #include "llvm/IR/Attributes.h"
33 #include "llvm/IR/CallingConv.h"
34 #include "llvm/IR/Function.h"
35 #include "llvm/IR/InstrTypes.h"
36 #include "llvm/IR/Instruction.h"
37 #include "llvm/IR/Instructions.h"
38 #include "llvm/IR/Intrinsics.h"
39 #include "llvm/Support/Casting.h"
40 #include "llvm/IR/Use.h"
41 #include "llvm/IR/User.h"
42 #include "llvm/IR/Value.h"
43 #include <cassert>
44 #include <cstdint>
45 #include <iterator>
46
47 namespace llvm {
48
49 template <typename FunTy = const Function,
50           typename BBTy = const BasicBlock,
51           typename ValTy = const Value,
52           typename UserTy = const User,
53           typename UseTy = const Use,
54           typename InstrTy = const Instruction,
55           typename CallTy = const CallInst,
56           typename InvokeTy = const InvokeInst,
57           typename IterTy = User::const_op_iterator>
58 class CallSiteBase {
59 protected:
60   PointerIntPair<InstrTy*, 1, bool> I;
61
62   CallSiteBase() : I(nullptr, false) {}
63   CallSiteBase(CallTy *CI) : I(CI, true) { assert(CI); }
64   CallSiteBase(InvokeTy *II) : I(II, false) { assert(II); }
65   explicit CallSiteBase(ValTy *II) { *this = get(II); }
66
67 private:
68   /// CallSiteBase::get - This static method is sort of like a constructor.  It
69   /// will create an appropriate call site for a Call or Invoke instruction, but
70   /// it can also create a null initialized CallSiteBase object for something
71   /// which is NOT a call site.
72   ///
73   static CallSiteBase get(ValTy *V) {
74     if (InstrTy *II = dyn_cast<InstrTy>(V)) {
75       if (II->getOpcode() == Instruction::Call)
76         return CallSiteBase(static_cast<CallTy*>(II));
77       else if (II->getOpcode() == Instruction::Invoke)
78         return CallSiteBase(static_cast<InvokeTy*>(II));
79     }
80     return CallSiteBase();
81   }
82
83 public:
84   /// isCall - true if a CallInst is enclosed.
85   /// Note that !isCall() does not mean it is an InvokeInst enclosed,
86   /// it also could signify a NULL Instruction pointer.
87   bool isCall() const { return I.getInt(); }
88
89   /// isInvoke - true if a InvokeInst is enclosed.
90   ///
91   bool isInvoke() const { return getInstruction() && !I.getInt(); }
92
93   InstrTy *getInstruction() const { return I.getPointer(); }
94   InstrTy *operator->() const { return I.getPointer(); }
95   explicit operator bool() const { return I.getPointer(); }
96
97   /// Get the basic block containing the call site
98   BBTy* getParent() const { return getInstruction()->getParent(); }
99
100   /// getCalledValue - Return the pointer to function that is being called.
101   ///
102   ValTy *getCalledValue() const {
103     assert(getInstruction() && "Not a call or invoke instruction!");
104     return *getCallee();
105   }
106
107   /// getCalledFunction - Return the function being called if this is a direct
108   /// call, otherwise return null (if it's an indirect call).
109   ///
110   FunTy *getCalledFunction() const {
111     return dyn_cast<FunTy>(getCalledValue());
112   }
113
114   /// setCalledFunction - Set the callee to the specified value.
115   ///
116   void setCalledFunction(Value *V) {
117     assert(getInstruction() && "Not a call or invoke instruction!");
118     *getCallee() = V;
119   }
120
121   /// Return the intrinsic ID of the intrinsic called by this CallSite,
122   /// or Intrinsic::not_intrinsic if the called function is not an
123   /// intrinsic, or if this CallSite is an indirect call.
124   Intrinsic::ID getIntrinsicID() const {
125     if (auto *F = getCalledFunction())
126       return F->getIntrinsicID();
127     // Don't use Intrinsic::not_intrinsic, as it will require pulling
128     // Intrinsics.h into every header that uses CallSite.
129     return static_cast<Intrinsic::ID>(0);
130   }
131
132   /// isCallee - Determine whether the passed iterator points to the
133   /// callee operand's Use.
134   bool isCallee(Value::const_user_iterator UI) const {
135     return isCallee(&UI.getUse());
136   }
137
138   /// Determine whether this Use is the callee operand's Use.
139   bool isCallee(const Use *U) const { return getCallee() == U; }
140
141   /// \brief Determine whether the passed iterator points to an argument
142   /// operand.
143   bool isArgOperand(Value::const_user_iterator UI) const {
144     return isArgOperand(&UI.getUse());
145   }
146
147   /// \brief Determine whether the passed use points to an argument operand.
148   bool isArgOperand(const Use *U) const {
149     assert(getInstruction() == U->getUser());
150     return arg_begin() <= U && U < arg_end();
151   }
152
153   /// \brief Determine whether the passed iterator points to a bundle operand.
154   bool isBundleOperand(Value::const_user_iterator UI) const {
155     return isBundleOperand(&UI.getUse());
156   }
157
158   /// \brief Determine whether the passed use points to a bundle operand.
159   bool isBundleOperand(const Use *U) const {
160     assert(getInstruction() == U->getUser());
161     if (!hasOperandBundles())
162       return false;
163     unsigned OperandNo = U - (*this)->op_begin();
164     return getBundleOperandsStartIndex() <= OperandNo &&
165            OperandNo < getBundleOperandsEndIndex();
166   }
167
168   /// \brief Determine whether the passed iterator points to a data operand.
169   bool isDataOperand(Value::const_user_iterator UI) const {
170     return isDataOperand(&UI.getUse());
171   }
172
173   /// \brief Determine whether the passed use points to a data operand.
174   bool isDataOperand(const Use *U) const {
175     return data_operands_begin() <= U && U < data_operands_end();
176   }
177
178   ValTy *getArgument(unsigned ArgNo) const {
179     assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!");
180     return *(arg_begin() + ArgNo);
181   }
182
183   void setArgument(unsigned ArgNo, Value* newVal) {
184     assert(getInstruction() && "Not a call or invoke instruction!");
185     assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!");
186     getInstruction()->setOperand(ArgNo, newVal);
187   }
188
189   /// Given a value use iterator, returns the argument that corresponds to it.
190   /// Iterator must actually correspond to an argument.
191   unsigned getArgumentNo(Value::const_user_iterator I) const {
192     return getArgumentNo(&I.getUse());
193   }
194
195   /// Given a use for an argument, get the argument number that corresponds to
196   /// it.
197   unsigned getArgumentNo(const Use *U) const {
198     assert(getInstruction() && "Not a call or invoke instruction!");
199     assert(isArgOperand(U) && "Argument # out of range!");
200     return U - arg_begin();
201   }
202
203   /// arg_iterator - The type of iterator to use when looping over actual
204   /// arguments at this call site.
205   typedef IterTy arg_iterator;
206
207   iterator_range<IterTy> args() const {
208     return make_range(arg_begin(), arg_end());
209   }
210   bool arg_empty() const { return arg_end() == arg_begin(); }
211   unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); }
212
213   /// Given a value use iterator, returns the data operand that corresponds to
214   /// it.
215   /// Iterator must actually correspond to a data operand.
216   unsigned getDataOperandNo(Value::const_user_iterator UI) const {
217     return getDataOperandNo(&UI.getUse());
218   }
219
220   /// Given a use for a data operand, get the data operand number that
221   /// corresponds to it.
222   unsigned getDataOperandNo(const Use *U) const {
223     assert(getInstruction() && "Not a call or invoke instruction!");
224     assert(isDataOperand(U) && "Data operand # out of range!");
225     return U - data_operands_begin();
226   }
227
228   /// Type of iterator to use when looping over data operands at this call site
229   /// (see below).
230   typedef IterTy data_operand_iterator;
231
232   /// data_operands_begin/data_operands_end - Return iterators iterating over
233   /// the call / invoke argument list and bundle operands.  For invokes, this is
234   /// the set of instruction operands except the invoke target and the two
235   /// successor blocks; and for calls this is the set of instruction operands
236   /// except the call target.
237
238   IterTy data_operands_begin() const {
239     assert(getInstruction() && "Not a call or invoke instruction!");
240     return (*this)->op_begin();
241   }
242   IterTy data_operands_end() const {
243     assert(getInstruction() && "Not a call or invoke instruction!");
244     return (*this)->op_end() - (isCall() ? 1 : 3);
245   }
246   iterator_range<IterTy> data_ops() const {
247     return make_range(data_operands_begin(), data_operands_end());
248   }
249   bool data_operands_empty() const {
250     return data_operands_end() == data_operands_begin();
251   }
252   unsigned data_operands_size() const {
253     return std::distance(data_operands_begin(), data_operands_end());
254   }
255
256   /// getType - Return the type of the instruction that generated this call site
257   ///
258   Type *getType() const { return (*this)->getType(); }
259
260   /// getCaller - Return the caller function for this call site
261   ///
262   FunTy *getCaller() const { return (*this)->getParent()->getParent(); }
263
264   /// \brief Tests if this call site must be tail call optimized.  Only a
265   /// CallInst can be tail call optimized.
266   bool isMustTailCall() const {
267     return isCall() && cast<CallInst>(getInstruction())->isMustTailCall();
268   }
269
270   /// \brief Tests if this call site is marked as a tail call.
271   bool isTailCall() const {
272     return isCall() && cast<CallInst>(getInstruction())->isTailCall();
273   }
274
275 #define CALLSITE_DELEGATE_GETTER(METHOD) \
276   InstrTy *II = getInstruction();    \
277   return isCall()                        \
278     ? cast<CallInst>(II)->METHOD         \
279     : cast<InvokeInst>(II)->METHOD
280
281 #define CALLSITE_DELEGATE_SETTER(METHOD) \
282   InstrTy *II = getInstruction();    \
283   if (isCall())                          \
284     cast<CallInst>(II)->METHOD;          \
285   else                                   \
286     cast<InvokeInst>(II)->METHOD
287
288   unsigned getNumArgOperands() const {
289     CALLSITE_DELEGATE_GETTER(getNumArgOperands());
290   }
291
292   ValTy *getArgOperand(unsigned i) const {
293     CALLSITE_DELEGATE_GETTER(getArgOperand(i));
294   }
295
296   ValTy *getReturnedArgOperand() const {
297     CALLSITE_DELEGATE_GETTER(getReturnedArgOperand());
298   }
299
300   bool isInlineAsm() const {
301     if (isCall())
302       return cast<CallInst>(getInstruction())->isInlineAsm();
303     return false;
304   }
305
306   /// getCallingConv/setCallingConv - get or set the calling convention of the
307   /// call.
308   CallingConv::ID getCallingConv() const {
309     CALLSITE_DELEGATE_GETTER(getCallingConv());
310   }
311   void setCallingConv(CallingConv::ID CC) {
312     CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
313   }
314
315   FunctionType *getFunctionType() const {
316     CALLSITE_DELEGATE_GETTER(getFunctionType());
317   }
318
319   void mutateFunctionType(FunctionType *Ty) const {
320     CALLSITE_DELEGATE_SETTER(mutateFunctionType(Ty));
321   }
322
323   /// getAttributes/setAttributes - get or set the parameter attributes of
324   /// the call.
325   AttributeSet getAttributes() const {
326     CALLSITE_DELEGATE_GETTER(getAttributes());
327   }
328   void setAttributes(AttributeSet PAL) {
329     CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
330   }
331
332   void addAttribute(unsigned i, Attribute::AttrKind Kind) {
333     CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind));
334   }
335
336   void addAttribute(unsigned i, Attribute Attr) {
337     CALLSITE_DELEGATE_SETTER(addAttribute(i, Attr));
338   }
339
340   void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
341     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
342   }
343
344   void removeAttribute(unsigned i, StringRef Kind) {
345     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
346   }
347
348   /// \brief Return true if this function has the given attribute.
349   bool hasFnAttr(Attribute::AttrKind Kind) const {
350     CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
351   }
352
353   /// \brief Return true if this function has the given attribute.
354   bool hasFnAttr(StringRef Kind) const {
355     CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
356   }
357
358   /// \brief Return true if the call or the callee has the given attribute.
359   bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const {
360     CALLSITE_DELEGATE_GETTER(paramHasAttr(i, Kind));
361   }
362
363   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
364     CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
365   }
366
367   Attribute getAttribute(unsigned i, StringRef Kind) const {
368     CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
369   }
370
371   /// \brief Return true if the data operand at index \p i directly or
372   /// indirectly has the attribute \p A.
373   ///
374   /// Normal call or invoke arguments have per operand attributes, as specified
375   /// in the attribute set attached to this instruction, while operand bundle
376   /// operands may have some attributes implied by the type of its containing
377   /// operand bundle.
378   bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
379     CALLSITE_DELEGATE_GETTER(dataOperandHasImpliedAttr(i, Kind));
380   }
381
382   /// @brief Extract the alignment for a call or parameter (0=unknown).
383   uint16_t getParamAlignment(uint16_t i) const {
384     CALLSITE_DELEGATE_GETTER(getParamAlignment(i));
385   }
386
387   /// @brief Extract the number of dereferenceable bytes for a call or
388   /// parameter (0=unknown).
389   uint64_t getDereferenceableBytes(uint16_t i) const {
390     CALLSITE_DELEGATE_GETTER(getDereferenceableBytes(i));
391   }
392
393   /// @brief Extract the number of dereferenceable_or_null bytes for a call or
394   /// parameter (0=unknown).
395   uint64_t getDereferenceableOrNullBytes(uint16_t i) const {
396     CALLSITE_DELEGATE_GETTER(getDereferenceableOrNullBytes(i));
397   }
398
399   /// @brief Determine if the parameter or return value is marked with NoAlias
400   /// attribute.
401   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
402   bool doesNotAlias(unsigned n) const {
403     CALLSITE_DELEGATE_GETTER(doesNotAlias(n));
404   }
405
406   /// \brief Return true if the call should not be treated as a call to a
407   /// builtin.
408   bool isNoBuiltin() const {
409     CALLSITE_DELEGATE_GETTER(isNoBuiltin());
410   }
411
412   /// @brief Return true if the call should not be inlined.
413   bool isNoInline() const {
414     CALLSITE_DELEGATE_GETTER(isNoInline());
415   }
416   void setIsNoInline(bool Value = true) {
417     CALLSITE_DELEGATE_SETTER(setIsNoInline(Value));
418   }
419
420   /// @brief Determine if the call does not access memory.
421   bool doesNotAccessMemory() const {
422     CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
423   }
424   void setDoesNotAccessMemory() {
425     CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory());
426   }
427
428   /// @brief Determine if the call does not access or only reads memory.
429   bool onlyReadsMemory() const {
430     CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
431   }
432   void setOnlyReadsMemory() {
433     CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory());
434   }
435
436   /// @brief Determine if the call does not access or only writes memory.
437   bool doesNotReadMemory() const {
438     CALLSITE_DELEGATE_GETTER(doesNotReadMemory());
439   }
440   void setDoesNotReadMemory() {
441     CALLSITE_DELEGATE_SETTER(setDoesNotReadMemory());
442   }
443
444   /// @brief Determine if the call can access memmory only using pointers based
445   /// on its arguments.
446   bool onlyAccessesArgMemory() const {
447     CALLSITE_DELEGATE_GETTER(onlyAccessesArgMemory());
448   }
449   void setOnlyAccessesArgMemory() {
450     CALLSITE_DELEGATE_SETTER(setOnlyAccessesArgMemory());
451   }
452
453   /// @brief Determine if the call cannot return.
454   bool doesNotReturn() const {
455     CALLSITE_DELEGATE_GETTER(doesNotReturn());
456   }
457   void setDoesNotReturn() {
458     CALLSITE_DELEGATE_SETTER(setDoesNotReturn());
459   }
460
461   /// @brief Determine if the call cannot unwind.
462   bool doesNotThrow() const {
463     CALLSITE_DELEGATE_GETTER(doesNotThrow());
464   }
465   void setDoesNotThrow() {
466     CALLSITE_DELEGATE_SETTER(setDoesNotThrow());
467   }
468
469   /// @brief Determine if the call can be duplicated.
470   bool cannotDuplicate() const {
471     CALLSITE_DELEGATE_GETTER(cannotDuplicate());
472   }
473   void setCannotDuplicate() {
474     CALLSITE_DELEGATE_GETTER(setCannotDuplicate());
475   }
476
477   /// @brief Determine if the call is convergent.
478   bool isConvergent() const {
479     CALLSITE_DELEGATE_GETTER(isConvergent());
480   }
481   void setConvergent() {
482     CALLSITE_DELEGATE_SETTER(setConvergent());
483   }
484   void setNotConvergent() {
485     CALLSITE_DELEGATE_SETTER(setNotConvergent());
486   }
487
488   unsigned getNumOperandBundles() const {
489     CALLSITE_DELEGATE_GETTER(getNumOperandBundles());
490   }
491
492   bool hasOperandBundles() const {
493     CALLSITE_DELEGATE_GETTER(hasOperandBundles());
494   }
495
496   unsigned getBundleOperandsStartIndex() const {
497     CALLSITE_DELEGATE_GETTER(getBundleOperandsStartIndex());
498   }
499
500   unsigned getBundleOperandsEndIndex() const {
501     CALLSITE_DELEGATE_GETTER(getBundleOperandsEndIndex());
502   }
503
504   unsigned getNumTotalBundleOperands() const {
505     CALLSITE_DELEGATE_GETTER(getNumTotalBundleOperands());
506   }
507
508   OperandBundleUse getOperandBundleAt(unsigned Index) const {
509     CALLSITE_DELEGATE_GETTER(getOperandBundleAt(Index));
510   }
511
512   Optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
513     CALLSITE_DELEGATE_GETTER(getOperandBundle(Name));
514   }
515
516   Optional<OperandBundleUse> getOperandBundle(uint32_t ID) const {
517     CALLSITE_DELEGATE_GETTER(getOperandBundle(ID));
518   }
519
520   unsigned countOperandBundlesOfType(uint32_t ID) const {
521     CALLSITE_DELEGATE_GETTER(countOperandBundlesOfType(ID));
522   }
523
524   bool isBundleOperand(unsigned Idx) const {
525     CALLSITE_DELEGATE_GETTER(isBundleOperand(Idx));
526   }
527
528   IterTy arg_begin() const {
529     CALLSITE_DELEGATE_GETTER(arg_begin());
530   }
531
532   IterTy arg_end() const {
533     CALLSITE_DELEGATE_GETTER(arg_end());
534   }
535
536 #undef CALLSITE_DELEGATE_GETTER
537 #undef CALLSITE_DELEGATE_SETTER
538
539   void getOperandBundlesAsDefs(SmallVectorImpl<OperandBundleDef> &Defs) const {
540     const Instruction *II = getInstruction();
541     // Since this is actually a getter that "looks like" a setter, don't use the
542     // above macros to avoid confusion.
543     if (isCall())
544       cast<CallInst>(II)->getOperandBundlesAsDefs(Defs);
545     else
546       cast<InvokeInst>(II)->getOperandBundlesAsDefs(Defs);
547   }
548
549   /// @brief Determine whether this data operand is not captured.
550   bool doesNotCapture(unsigned OpNo) const {
551     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture);
552   }
553
554   /// @brief Determine whether this argument is passed by value.
555   bool isByValArgument(unsigned ArgNo) const {
556     return paramHasAttr(ArgNo + 1, Attribute::ByVal);
557   }
558
559   /// @brief Determine whether this argument is passed in an alloca.
560   bool isInAllocaArgument(unsigned ArgNo) const {
561     return paramHasAttr(ArgNo + 1, Attribute::InAlloca);
562   }
563
564   /// @brief Determine whether this argument is passed by value or in an alloca.
565   bool isByValOrInAllocaArgument(unsigned ArgNo) const {
566     return paramHasAttr(ArgNo + 1, Attribute::ByVal) ||
567            paramHasAttr(ArgNo + 1, Attribute::InAlloca);
568   }
569
570   /// @brief Determine if there are is an inalloca argument.  Only the last
571   /// argument can have the inalloca attribute.
572   bool hasInAllocaArgument() const {
573     return paramHasAttr(arg_size(), Attribute::InAlloca);
574   }
575
576   bool doesNotAccessMemory(unsigned OpNo) const {
577     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
578   }
579
580   bool onlyReadsMemory(unsigned OpNo) const {
581     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadOnly) ||
582            dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
583   }
584
585   /// @brief Return true if the return value is known to be not null.
586   /// This may be because it has the nonnull attribute, or because at least
587   /// one byte is dereferenceable and the pointer is in addrspace(0).
588   bool isReturnNonNull() const {
589     if (paramHasAttr(0, Attribute::NonNull))
590       return true;
591     else if (getDereferenceableBytes(0) > 0 &&
592              getType()->getPointerAddressSpace() == 0)
593       return true;
594
595     return false;
596   }
597
598   /// hasArgument - Returns true if this CallSite passes the given Value* as an
599   /// argument to the called function.
600   bool hasArgument(const Value *Arg) const {
601     for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E;
602          ++AI)
603       if (AI->get() == Arg)
604         return true;
605     return false;
606   }
607
608 private:
609   IterTy getCallee() const {
610     if (isCall()) // Skip Callee
611       return cast<CallInst>(getInstruction())->op_end() - 1;
612     else // Skip BB, BB, Callee
613       return cast<InvokeInst>(getInstruction())->op_end() - 3;
614   }
615 };
616
617 class CallSite : public CallSiteBase<Function, BasicBlock, Value, User, Use,
618                                      Instruction, CallInst, InvokeInst,
619                                      User::op_iterator> {
620 public:
621   CallSite() = default;
622   CallSite(CallSiteBase B) : CallSiteBase(B) {}
623   CallSite(CallInst *CI) : CallSiteBase(CI) {}
624   CallSite(InvokeInst *II) : CallSiteBase(II) {}
625   explicit CallSite(Instruction *II) : CallSiteBase(II) {}
626   explicit CallSite(Value *V) : CallSiteBase(V) {}
627
628   bool operator==(const CallSite &CS) const { return I == CS.I; }
629   bool operator!=(const CallSite &CS) const { return I != CS.I; }
630   bool operator<(const CallSite &CS) const {
631     return getInstruction() < CS.getInstruction();
632   }
633
634 private:
635   friend struct DenseMapInfo<CallSite>;
636
637   User::op_iterator getCallee() const;
638 };
639
640 template <> struct DenseMapInfo<CallSite> {
641   using BaseInfo = DenseMapInfo<decltype(CallSite::I)>;
642
643   static CallSite getEmptyKey() {
644     CallSite CS;
645     CS.I = BaseInfo::getEmptyKey();
646     return CS;
647   }
648
649   static CallSite getTombstoneKey() {
650     CallSite CS;
651     CS.I = BaseInfo::getTombstoneKey();
652     return CS;
653   }
654
655   static unsigned getHashValue(const CallSite &CS) {
656     return BaseInfo::getHashValue(CS.I);
657   }
658
659   static bool isEqual(const CallSite &LHS, const CallSite &RHS) {
660     return LHS == RHS;
661   }
662 };
663
664 /// ImmutableCallSite - establish a view to a call site for examination
665 class ImmutableCallSite : public CallSiteBase<> {
666 public:
667   ImmutableCallSite() = default;
668   ImmutableCallSite(const CallInst *CI) : CallSiteBase(CI) {}
669   ImmutableCallSite(const InvokeInst *II) : CallSiteBase(II) {}
670   explicit ImmutableCallSite(const Instruction *II) : CallSiteBase(II) {}
671   explicit ImmutableCallSite(const Value *V) : CallSiteBase(V) {}
672   ImmutableCallSite(CallSite CS) : CallSiteBase(CS.getInstruction()) {}
673 };
674
675 } // end namespace llvm
676
677 #endif // LLVM_IR_CALLSITE_H