LCOV - code coverage report
Current view: top level - include/llvm/IR - CallSite.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 199 207 96.1 %
Date: 2017-09-14 15:23:50 Functions: 87 90 96.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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/Optional.h"
      30             : #include "llvm/ADT/PointerIntPair.h"
      31             : #include "llvm/ADT/iterator_range.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/Use.h"
      39             : #include "llvm/IR/User.h"
      40             : #include "llvm/IR/Value.h"
      41             : #include "llvm/Support/Casting.h"
      42             : #include <cassert>
      43             : #include <cstdint>
      44             : #include <iterator>
      45             : 
      46             : namespace llvm {
      47             : 
      48             : namespace Intrinsic {
      49             : enum ID : unsigned;
      50             : }
      51             : 
      52             : template <typename FunTy = const Function,
      53             :           typename BBTy = const BasicBlock,
      54             :           typename ValTy = const Value,
      55             :           typename UserTy = const User,
      56             :           typename UseTy = const Use,
      57             :           typename InstrTy = const Instruction,
      58             :           typename CallTy = const CallInst,
      59             :           typename InvokeTy = const InvokeInst,
      60             :           typename IterTy = User::const_op_iterator>
      61             : class CallSiteBase {
      62             : protected:
      63             :   PointerIntPair<InstrTy*, 1, bool> I;
      64             : 
      65     1087926 :   CallSiteBase() : I(nullptr, false) {}
      66    89149838 :   CallSiteBase(CallTy *CI) : I(CI, true) { assert(CI); }
      67     7381292 :   CallSiteBase(InvokeTy *II) : I(II, false) { assert(II); }
      68   670931152 :   explicit CallSiteBase(ValTy *II) { *this = get(II); }
      69             : 
      70             : private:
      71             :   /// This static method is like a constructor. It will create an appropriate
      72             :   /// call site for a Call or Invoke instruction, but it can also create a null
      73             :   /// initialized CallSiteBase object for something which is NOT a call site.
      74             :   static CallSiteBase get(ValTy *V) {
      75   112814955 :     if (InstrTy *II = dyn_cast<InstrTy>(V)) {
      76   112814955 :       if (II->getOpcode() == Instruction::Call)
      77    33616799 :         return CallSiteBase(static_cast<CallTy*>(II));
      78    79198156 :       else if (II->getOpcode() == Instruction::Invoke)
      79     2959229 :         return CallSiteBase(static_cast<InvokeTy*>(II));
      80             :     }
      81             :     return CallSiteBase();
      82             :   }
      83             : 
      84             : public:
      85             :   /// Return true if a CallInst is enclosed. Note that !isCall() does not mean
      86             :   /// an InvokeInst is enclosed. It may also signify a NULL instruction pointer.
      87   418948078 :   bool isCall() const { return I.getInt(); }
      88             : 
      89             :   /// Return true if a InvokeInst is enclosed.
      90      511572 :   bool isInvoke() const { return getInstruction() && !I.getInt(); }
      91             : 
      92   639521966 :   InstrTy *getInstruction() const { return I.getPointer(); }
      93    25800638 :   InstrTy *operator->() const { return I.getPointer(); }
      94   369931649 :   explicit operator bool() const { return I.getPointer(); }
      95             : 
      96             :   /// Get the basic block containing the call site.
      97       93644 :   BBTy* getParent() const { return getInstruction()->getParent(); }
      98             : 
      99             :   /// Return the pointer to function that is being called.
     100             :   ValTy *getCalledValue() const {
     101             :     assert(getInstruction() && "Not a call or invoke instruction!");
     102    51709792 :     return *getCallee();
     103             :   }
     104             : 
     105             :   /// Return the function being called if this is a direct call, otherwise
     106             :   /// return null (if it's an indirect call).
     107             :   FunTy *getCalledFunction() const {
     108    88438869 :     return dyn_cast<FunTy>(getCalledValue());
     109             :   }
     110             : 
     111             :   /// Return true if the callsite is an indirect call.
     112         567 :   bool isIndirectCall() const {
     113         567 :     Value *V = getCalledValue();
     114         567 :     if (!V)
     115             :       return false;
     116        1134 :     if (isa<FunTy>(V) || isa<Constant>(V))
     117             :       return false;
     118         118 :     if (CallInst *CI = dyn_cast<CallInst>(getInstruction())) {
     119          53 :       if (CI->isInlineAsm())
     120             :         return false;
     121             :     }
     122             :     return true;
     123             :   }
     124             : 
     125             :   /// Set the callee to the specified value.
     126          48 :   void setCalledFunction(Value *V) {
     127             :     assert(getInstruction() && "Not a call or invoke instruction!");
     128          96 :     *getCallee() = V;
     129          48 :   }
     130             : 
     131             :   /// Return the intrinsic ID of the intrinsic called by this CallSite,
     132             :   /// or Intrinsic::not_intrinsic if the called function is not an
     133             :   /// intrinsic, or if this CallSite is an indirect call.
     134             :   Intrinsic::ID getIntrinsicID() const {
     135       66966 :     if (auto *F = getCalledFunction())
     136             :       return F->getIntrinsicID();
     137             :     // Don't use Intrinsic::not_intrinsic, as it will require pulling
     138             :     // Intrinsics.h into every header that uses CallSite.
     139             :     return static_cast<Intrinsic::ID>(0);
     140             :   }
     141             : 
     142             :   /// Determine whether the passed iterator points to the callee operand's Use.
     143             :   bool isCallee(Value::const_user_iterator UI) const {
     144             :     return isCallee(&UI.getUse());
     145             :   }
     146             : 
     147             :   /// Determine whether this Use is the callee operand's Use.
     148     1291304 :   bool isCallee(const Use *U) const { return getCallee() == U; }
     149             : 
     150             :   /// Determine whether the passed iterator points to an argument operand.
     151             :   bool isArgOperand(Value::const_user_iterator UI) const {
     152             :     return isArgOperand(&UI.getUse());
     153             :   }
     154             : 
     155             :   /// Determine whether the passed use points to an argument operand.
     156      369371 :   bool isArgOperand(const Use *U) const {
     157             :     assert(getInstruction() == U->getUser());
     158      369371 :     return arg_begin() <= U && U < arg_end();
     159             :   }
     160             : 
     161             :   /// Determine whether the passed iterator points to a bundle operand.
     162             :   bool isBundleOperand(Value::const_user_iterator UI) const {
     163             :     return isBundleOperand(&UI.getUse());
     164             :   }
     165             : 
     166             :   /// Determine whether the passed use points to a bundle operand.
     167        4020 :   bool isBundleOperand(const Use *U) const {
     168             :     assert(getInstruction() == U->getUser());
     169        4020 :     if (!hasOperandBundles())
     170             :       return false;
     171           3 :     unsigned OperandNo = U - (*this)->op_begin();
     172           2 :     return getBundleOperandsStartIndex() <= OperandNo &&
     173           1 :            OperandNo < getBundleOperandsEndIndex();
     174             :   }
     175             : 
     176             :   /// Determine whether the passed iterator points to a data operand.
     177             :   bool isDataOperand(Value::const_user_iterator UI) const {
     178             :     return isDataOperand(&UI.getUse());
     179             :   }
     180             : 
     181             :   /// Determine whether the passed use points to a data operand.
     182      305789 :   bool isDataOperand(const Use *U) const {
     183      305789 :     return data_operands_begin() <= U && U < data_operands_end();
     184             :   }
     185             : 
     186             :   ValTy *getArgument(unsigned ArgNo) const {
     187             :     assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!");
     188     5159345 :     return *(arg_begin() + ArgNo);
     189             :   }
     190             : 
     191             :   void setArgument(unsigned ArgNo, Value* newVal) {
     192             :     assert(getInstruction() && "Not a call or invoke instruction!");
     193             :     assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!");
     194          87 :     getInstruction()->setOperand(ArgNo, newVal);
     195             :   }
     196             : 
     197             :   /// Given a value use iterator, returns the argument that corresponds to it.
     198             :   /// Iterator must actually correspond to an argument.
     199             :   unsigned getArgumentNo(Value::const_user_iterator I) const {
     200             :     return getArgumentNo(&I.getUse());
     201             :   }
     202             : 
     203             :   /// Given a use for an argument, get the argument number that corresponds to
     204             :   /// it.
     205             :   unsigned getArgumentNo(const Use *U) const {
     206             :     assert(getInstruction() && "Not a call or invoke instruction!");
     207             :     assert(isArgOperand(U) && "Argument # out of range!");
     208        8150 :     return U - arg_begin();
     209             :   }
     210             : 
     211             :   /// The type of iterator to use when looping over actual arguments at this
     212             :   /// call site.
     213             :   using arg_iterator = IterTy;
     214             : 
     215     3628361 :   iterator_range<IterTy> args() const {
     216    10885083 :     return make_range(arg_begin(), arg_end());
     217             :   }
     218      840450 :   bool arg_empty() const { return arg_end() == arg_begin(); }
     219     5469102 :   unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); }
     220             : 
     221             :   /// Given a value use iterator, return the data operand corresponding to it.
     222             :   /// Iterator must actually correspond to a data operand.
     223             :   unsigned getDataOperandNo(Value::const_user_iterator UI) const {
     224             :     return getDataOperandNo(&UI.getUse());
     225             :   }
     226             : 
     227             :   /// Given a use for a data operand, get the data operand number that
     228             :   /// corresponds to it.
     229             :   unsigned getDataOperandNo(const Use *U) const {
     230             :     assert(getInstruction() && "Not a call or invoke instruction!");
     231             :     assert(isDataOperand(U) && "Data operand # out of range!");
     232      743452 :     return U - data_operands_begin();
     233             :   }
     234             : 
     235             :   /// Type of iterator to use when looping over data operands at this call site
     236             :   /// (see below).
     237             :   using data_operand_iterator = IterTy;
     238             : 
     239             :   /// data_operands_begin/data_operands_end - Return iterators iterating over
     240             :   /// the call / invoke argument list and bundle operands.  For invokes, this is
     241             :   /// the set of instruction operands except the invoke target and the two
     242             :   /// successor blocks; and for calls this is the set of instruction operands
     243             :   /// except the call target.
     244             : 
     245             :   IterTy data_operands_begin() const {
     246             :     assert(getInstruction() && "Not a call or invoke instruction!");
     247     6214718 :     return (*this)->op_begin();
     248             :   }
     249     2735633 :   IterTy data_operands_end() const {
     250             :     assert(getInstruction() && "Not a call or invoke instruction!");
     251     8206899 :     return (*this)->op_end() - (isCall() ? 1 : 3);
     252             :   }
     253         210 :   iterator_range<IterTy> data_ops() const {
     254         630 :     return make_range(data_operands_begin(), data_operands_end());
     255             :   }
     256             :   bool data_operands_empty() const {
     257             :     return data_operands_end() == data_operands_begin();
     258             :   }
     259             :   unsigned data_operands_size() const {
     260             :     return std::distance(data_operands_begin(), data_operands_end());
     261             :   }
     262             : 
     263             :   /// Return the type of the instruction that generated this call site.
     264      227322 :   Type *getType() const { return (*this)->getType(); }
     265             : 
     266             :   /// Return the caller function for this call site.
     267     2429110 :   FunTy *getCaller() const { return (*this)->getParent()->getParent(); }
     268             : 
     269             :   /// Tests if this call site must be tail call optimized. Only a CallInst can
     270             :   /// be tail call optimized.
     271             :   bool isMustTailCall() const {
     272      618938 :     return isCall() && cast<CallInst>(getInstruction())->isMustTailCall();
     273             :   }
     274             : 
     275             :   /// Tests if this call site is marked as a tail call.
     276             :   bool isTailCall() const {
     277           8 :     return isCall() && cast<CallInst>(getInstruction())->isTailCall();
     278             :   }
     279             : 
     280             : #define CALLSITE_DELEGATE_GETTER(METHOD) \
     281             :   InstrTy *II = getInstruction();    \
     282             :   return isCall()                        \
     283             :     ? cast<CallInst>(II)->METHOD         \
     284             :     : cast<InvokeInst>(II)->METHOD
     285             : 
     286             : #define CALLSITE_DELEGATE_SETTER(METHOD) \
     287             :   InstrTy *II = getInstruction();    \
     288             :   if (isCall())                          \
     289             :     cast<CallInst>(II)->METHOD;          \
     290             :   else                                   \
     291             :     cast<InvokeInst>(II)->METHOD
     292             : 
     293      237940 :   unsigned getNumArgOperands() const {
     294      951760 :     CALLSITE_DELEGATE_GETTER(getNumArgOperands());
     295             :   }
     296             : 
     297     2398606 :   ValTy *getArgOperand(unsigned i) const {
     298     9594424 :     CALLSITE_DELEGATE_GETTER(getArgOperand(i));
     299             :   }
     300             : 
     301      887994 :   ValTy *getReturnedArgOperand() const {
     302     2663982 :     CALLSITE_DELEGATE_GETTER(getReturnedArgOperand());
     303             :   }
     304             : 
     305             :   bool isInlineAsm() const {
     306        1709 :     if (isCall())
     307        4983 :       return cast<CallInst>(getInstruction())->isInlineAsm();
     308             :     return false;
     309             :   }
     310             : 
     311             :   /// Get the calling convention of the call.
     312             :   CallingConv::ID getCallingConv() const {
     313    11741528 :     CALLSITE_DELEGATE_GETTER(getCallingConv());
     314             :   }
     315             :   /// Set the calling convention of the call.
     316      163777 :   void setCallingConv(CallingConv::ID CC) {
     317      630705 :     CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
     318      163777 :   }
     319             : 
     320             :   FunctionType *getFunctionType() const {
     321     2649862 :     CALLSITE_DELEGATE_GETTER(getFunctionType());
     322             :   }
     323             : 
     324             :   void mutateFunctionType(FunctionType *Ty) const {
     325        1590 :     CALLSITE_DELEGATE_SETTER(mutateFunctionType(Ty));
     326             :   }
     327             : 
     328             :   /// Get the parameter attributes of the call.
     329             :   AttributeList getAttributes() const {
     330     2505582 :     CALLSITE_DELEGATE_GETTER(getAttributes());
     331             :   }
     332             :   /// Set the parameter attributes of the call.
     333             :   void setAttributes(AttributeList PAL) {
     334     1007466 :     CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
     335             :   }
     336             : 
     337             :   void addAttribute(unsigned i, Attribute::AttrKind Kind) {
     338             :     CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind));
     339             :   }
     340             : 
     341           5 :   void addAttribute(unsigned i, Attribute Attr) {
     342          15 :     CALLSITE_DELEGATE_SETTER(addAttribute(i, Attr));
     343           5 :   }
     344             : 
     345           7 :   void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
     346          21 :     CALLSITE_DELEGATE_SETTER(addParamAttr(ArgNo, Kind));
     347           7 :   }
     348             : 
     349           0 :   void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
     350           0 :     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
     351           0 :   }
     352             : 
     353           0 :   void removeAttribute(unsigned i, StringRef Kind) {
     354           0 :     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
     355           0 :   }
     356             : 
     357           7 :   void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
     358          21 :     CALLSITE_DELEGATE_SETTER(removeParamAttr(ArgNo, Kind));
     359           7 :   }
     360             : 
     361             :   /// Return true if this function has the given attribute.
     362     2086674 :   bool hasFnAttr(Attribute::AttrKind Kind) const {
     363     8346696 :     CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
     364             :   }
     365             : 
     366             :   /// Return true if this function has the given attribute.
     367         391 :   bool hasFnAttr(StringRef Kind) const {
     368        1564 :     CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
     369             :   }
     370             : 
     371             :   /// Return true if this return value has the given attribute.
     372     1279033 :   bool hasRetAttr(Attribute::AttrKind Kind) const {
     373     3837099 :     CALLSITE_DELEGATE_GETTER(hasRetAttr(Kind));
     374             :   }
     375             : 
     376             :   /// Return true if the call or the callee has the given attribute.
     377    13753480 :   bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
     378    41260440 :     CALLSITE_DELEGATE_GETTER(paramHasAttr(ArgNo, Kind));
     379             :   }
     380             : 
     381        1045 :   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
     382        4180 :     CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
     383             :   }
     384             : 
     385           0 :   Attribute getAttribute(unsigned i, StringRef Kind) const {
     386           0 :     CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
     387             :   }
     388             : 
     389             :   /// Return true if the data operand at index \p i directly or indirectly has
     390             :   /// the attribute \p A.
     391             :   ///
     392             :   /// Normal call or invoke arguments have per operand attributes, as specified
     393             :   /// in the attribute set attached to this instruction, while operand bundle
     394             :   /// operands may have some attributes implied by the type of its containing
     395             :   /// operand bundle.
     396     2607254 :   bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
     397     7821762 :     CALLSITE_DELEGATE_GETTER(dataOperandHasImpliedAttr(i, Kind));
     398             :   }
     399             : 
     400             :   /// Extract the alignment of the return value.
     401             :   unsigned getRetAlignment() const {
     402             :     CALLSITE_DELEGATE_GETTER(getRetAlignment());
     403             :   }
     404             : 
     405             :   /// Extract the alignment for a call or parameter (0=unknown).
     406      406256 :   unsigned getParamAlignment(unsigned ArgNo) const {
     407     1625024 :     CALLSITE_DELEGATE_GETTER(getParamAlignment(ArgNo));
     408             :   }
     409             : 
     410             :   /// Extract the number of dereferenceable bytes for a call or parameter
     411             :   /// (0=unknown).
     412       60092 :   uint64_t getDereferenceableBytes(unsigned i) const {
     413      240368 :     CALLSITE_DELEGATE_GETTER(getDereferenceableBytes(i));
     414             :   }
     415             : 
     416             :   /// Extract the number of dereferenceable_or_null bytes for a call or
     417             :   /// parameter (0=unknown).
     418        1253 :   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
     419        5012 :     CALLSITE_DELEGATE_GETTER(getDereferenceableOrNullBytes(i));
     420             :   }
     421             : 
     422             :   /// Determine if the return value is marked with NoAlias attribute.
     423             :   bool returnDoesNotAlias() const {
     424             :     CALLSITE_DELEGATE_GETTER(returnDoesNotAlias());
     425             :   }
     426             : 
     427             :   /// Return true if the call should not be treated as a call to a builtin.
     428    17713366 :   bool isNoBuiltin() const {
     429    53140098 :     CALLSITE_DELEGATE_GETTER(isNoBuiltin());
     430             :   }
     431             : 
     432             :   /// Return true if the call requires strict floating point semantics.
     433     8991801 :   bool isStrictFP() const {
     434    35967204 :     CALLSITE_DELEGATE_GETTER(isStrictFP());
     435             :   }
     436             : 
     437             :   /// Return true if the call should not be inlined.
     438      360400 :   bool isNoInline() const {
     439     1441600 :     CALLSITE_DELEGATE_GETTER(isNoInline());
     440             :   }
     441             :   void setIsNoInline(bool Value = true) {
     442             :     CALLSITE_DELEGATE_SETTER(setIsNoInline(Value));
     443             :   }
     444             : 
     445             :   /// Determine if the call does not access memory.
     446     8390350 :   bool doesNotAccessMemory() const {
     447    33561400 :     CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
     448             :   }
     449             :   void setDoesNotAccessMemory() {
     450             :     CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory());
     451             :   }
     452             : 
     453             :   /// Determine if the call does not access or only reads memory.
     454    11090670 :   bool onlyReadsMemory() const {
     455    33272010 :     CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
     456             :   }
     457           5 :   void setOnlyReadsMemory() {
     458          15 :     CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory());
     459           5 :   }
     460             : 
     461             :   /// Determine if the call does not access or only writes memory.
     462     8249166 :   bool doesNotReadMemory() const {
     463    24747498 :     CALLSITE_DELEGATE_GETTER(doesNotReadMemory());
     464             :   }
     465             :   void setDoesNotReadMemory() {
     466             :     CALLSITE_DELEGATE_SETTER(setDoesNotReadMemory());
     467             :   }
     468             : 
     469             :   /// Determine if the call can access memmory only using pointers based
     470             :   /// on its arguments.
     471     8293155 :   bool onlyAccessesArgMemory() const {
     472    33172620 :     CALLSITE_DELEGATE_GETTER(onlyAccessesArgMemory());
     473             :   }
     474             :   void setOnlyAccessesArgMemory() {
     475             :     CALLSITE_DELEGATE_SETTER(setOnlyAccessesArgMemory());
     476             :   }
     477             : 
     478             :   /// Determine if the call cannot return.
     479      344938 :   bool doesNotReturn() const {
     480     1379752 :     CALLSITE_DELEGATE_GETTER(doesNotReturn());
     481             :   }
     482          47 :   void setDoesNotReturn() {
     483         141 :     CALLSITE_DELEGATE_SETTER(setDoesNotReturn());
     484          47 :   }
     485             : 
     486             :   /// Determine if the call cannot unwind.
     487      191880 :   bool doesNotThrow() const {
     488      767520 :     CALLSITE_DELEGATE_GETTER(doesNotThrow());
     489             :   }
     490          22 :   void setDoesNotThrow() {
     491          66 :     CALLSITE_DELEGATE_SETTER(setDoesNotThrow());
     492          22 :   }
     493             : 
     494             :   /// Determine if the call can be duplicated.
     495       48871 :   bool cannotDuplicate() const {
     496      195484 :     CALLSITE_DELEGATE_GETTER(cannotDuplicate());
     497             :   }
     498          16 :   void setCannotDuplicate() {
     499          48 :     CALLSITE_DELEGATE_SETTER(setCannotDuplicate());
     500          16 :   }
     501             : 
     502             :   /// Determine if the call is convergent.
     503     2939142 :   bool isConvergent() const {
     504    11756568 :     CALLSITE_DELEGATE_GETTER(isConvergent());
     505             :   }
     506             :   void setConvergent() {
     507             :     CALLSITE_DELEGATE_SETTER(setConvergent());
     508             :   }
     509           1 :   void setNotConvergent() {
     510           3 :     CALLSITE_DELEGATE_SETTER(setNotConvergent());
     511           1 :   }
     512             : 
     513      424114 :   unsigned getNumOperandBundles() const {
     514     1272342 :     CALLSITE_DELEGATE_GETTER(getNumOperandBundles());
     515             :   }
     516             : 
     517    16831092 :   bool hasOperandBundles() const {
     518    67324368 :     CALLSITE_DELEGATE_GETTER(hasOperandBundles());
     519             :   }
     520             : 
     521           1 :   unsigned getBundleOperandsStartIndex() const {
     522           4 :     CALLSITE_DELEGATE_GETTER(getBundleOperandsStartIndex());
     523             :   }
     524             : 
     525           1 :   unsigned getBundleOperandsEndIndex() const {
     526           4 :     CALLSITE_DELEGATE_GETTER(getBundleOperandsEndIndex());
     527             :   }
     528             : 
     529             :   unsigned getNumTotalBundleOperands() const {
     530             :     CALLSITE_DELEGATE_GETTER(getNumTotalBundleOperands());
     531             :   }
     532             : 
     533        2735 :   OperandBundleUse getOperandBundleAt(unsigned Index) const {
     534        8205 :     CALLSITE_DELEGATE_GETTER(getOperandBundleAt(Index));
     535             :   }
     536             : 
     537             :   Optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
     538             :     CALLSITE_DELEGATE_GETTER(getOperandBundle(Name));
     539             :   }
     540             : 
     541       88815 :   Optional<OperandBundleUse> getOperandBundle(uint32_t ID) const {
     542      266445 :     CALLSITE_DELEGATE_GETTER(getOperandBundle(ID));
     543             :   }
     544             : 
     545         631 :   unsigned countOperandBundlesOfType(uint32_t ID) const {
     546        1893 :     CALLSITE_DELEGATE_GETTER(countOperandBundlesOfType(ID));
     547             :   }
     548             : 
     549      473973 :   bool isBundleOperand(unsigned Idx) const {
     550     1421919 :     CALLSITE_DELEGATE_GETTER(isBundleOperand(Idx));
     551             :   }
     552             : 
     553             :   IterTy arg_begin() const {
     554    96529848 :     CALLSITE_DELEGATE_GETTER(arg_begin());
     555             :   }
     556             : 
     557    13870948 :   IterTy arg_end() const {
     558    55483792 :     CALLSITE_DELEGATE_GETTER(arg_end());
     559             :   }
     560             : 
     561             : #undef CALLSITE_DELEGATE_GETTER
     562             : #undef CALLSITE_DELEGATE_SETTER
     563             : 
     564        2158 :   void getOperandBundlesAsDefs(SmallVectorImpl<OperandBundleDef> &Defs) const {
     565        2158 :     const Instruction *II = getInstruction();
     566             :     // Since this is actually a getter that "looks like" a setter, don't use the
     567             :     // above macros to avoid confusion.
     568        2158 :     if (isCall())
     569        2127 :       cast<CallInst>(II)->getOperandBundlesAsDefs(Defs);
     570             :     else
     571          31 :       cast<InvokeInst>(II)->getOperandBundlesAsDefs(Defs);
     572        2158 :   }
     573             : 
     574             :   /// Determine whether this data operand is not captured.
     575             :   bool doesNotCapture(unsigned OpNo) const {
     576     2562271 :     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture);
     577             :   }
     578             : 
     579             :   /// Determine whether this argument is passed by value.
     580             :   bool isByValArgument(unsigned ArgNo) const {
     581     1562867 :     return paramHasAttr(ArgNo, Attribute::ByVal);
     582             :   }
     583             : 
     584             :   /// Determine whether this argument is passed in an alloca.
     585             :   bool isInAllocaArgument(unsigned ArgNo) const {
     586      267651 :     return paramHasAttr(ArgNo, Attribute::InAlloca);
     587             :   }
     588             : 
     589             :   /// Determine whether this argument is passed by value or in an alloca.
     590          10 :   bool isByValOrInAllocaArgument(unsigned ArgNo) const {
     591          19 :     return paramHasAttr(ArgNo, Attribute::ByVal) ||
     592          19 :            paramHasAttr(ArgNo, Attribute::InAlloca);
     593             :   }
     594             : 
     595             :   /// Determine if there are is an inalloca argument. Only the last argument can
     596             :   /// have the inalloca attribute.
     597      420070 :   bool hasInAllocaArgument() const {
     598      420070 :     return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
     599             :   }
     600             : 
     601             :   bool doesNotAccessMemory(unsigned OpNo) const {
     602       32940 :     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
     603             :   }
     604             : 
     605        4390 :   bool onlyReadsMemory(unsigned OpNo) const {
     606        8099 :     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadOnly) ||
     607        8099 :            dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
     608             :   }
     609             : 
     610        2102 :   bool doesNotReadMemory(unsigned OpNo) const {
     611        3944 :     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::WriteOnly) ||
     612        3944 :            dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
     613             :   }
     614             : 
     615             :   /// Return true if the return value is known to be not null.
     616             :   /// This may be because it has the nonnull attribute, or because at least
     617             :   /// one byte is dereferenceable and the pointer is in addrspace(0).
     618       61607 :   bool isReturnNonNull() const {
     619       61607 :     if (hasRetAttr(Attribute::NonNull))
     620             :       return true;
     621       63628 :     else if (getDereferenceableBytes(AttributeList::ReturnIndex) > 0 &&
     622       10346 :              getType()->getPointerAddressSpace() == 0)
     623             :       return true;
     624             : 
     625             :     return false;
     626             :   }
     627             : 
     628             :   /// Returns true if this CallSite passes the given Value* as an argument to
     629             :   /// the called function.
     630             :   bool hasArgument(const Value *Arg) const {
     631             :     for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E;
     632             :          ++AI)
     633             :       if (AI->get() == Arg)
     634             :         return true;
     635             :     return false;
     636             :   }
     637             : 
     638             : private:
     639             :   IterTy getCallee() const {
     640    53001144 :     if (isCall()) // Skip Callee
     641   147560022 :       return cast<CallInst>(getInstruction())->op_end() - 1;
     642             :     else // Skip BB, BB, Callee
     643    11443410 :       return cast<InvokeInst>(getInstruction())->op_end() - 3;
     644             :   }
     645             : };
     646             : 
     647             : class CallSite : public CallSiteBase<Function, BasicBlock, Value, User, Use,
     648             :                                      Instruction, CallInst, InvokeInst,
     649             :                                      User::op_iterator> {
     650             : public:
     651      709998 :   CallSite() = default;
     652             :   CallSite(CallSiteBase B) : CallSiteBase(B) {}
     653    11587042 :   CallSite(CallInst *CI) : CallSiteBase(CI) {}
     654     1313786 :   CallSite(InvokeInst *II) : CallSiteBase(II) {}
     655    61348827 :   explicit CallSite(Instruction *II) : CallSiteBase(II) {}
     656   118397666 :   explicit CallSite(Value *V) : CallSiteBase(V) {}
     657             : 
     658        1636 :   bool operator==(const CallSite &CS) const { return I == CS.I; }
     659             :   bool operator!=(const CallSite &CS) const { return I != CS.I; }
     660             :   bool operator<(const CallSite &CS) const {
     661             :     return getInstruction() < CS.getInstruction();
     662             :   }
     663             : 
     664             : private:
     665             :   friend struct DenseMapInfo<CallSite>;
     666             : 
     667             :   User::op_iterator getCallee() const;
     668             : };
     669             : 
     670             : template <> struct DenseMapInfo<CallSite> {
     671             :   using BaseInfo = DenseMapInfo<decltype(CallSite::I)>;
     672             : 
     673             :   static CallSite getEmptyKey() {
     674        1170 :     CallSite CS;
     675        1170 :     CS.I = BaseInfo::getEmptyKey();
     676             :     return CS;
     677             :   }
     678             : 
     679             :   static CallSite getTombstoneKey() {
     680         592 :     CallSite CS;
     681         592 :     CS.I = BaseInfo::getTombstoneKey();
     682             :     return CS;
     683             :   }
     684             : 
     685             :   static unsigned getHashValue(const CallSite &CS) {
     686         241 :     return BaseInfo::getHashValue(CS.I);
     687             :   }
     688             : 
     689             :   static bool isEqual(const CallSite &LHS, const CallSite &RHS) {
     690         837 :     return LHS == RHS;
     691             :   }
     692             : };
     693             : 
     694             : /// Establish a view to a call site for examination.
     695             : class ImmutableCallSite : public CallSiteBase<> {
     696             : public:
     697      377928 :   ImmutableCallSite() = default;
     698    10329198 :   ImmutableCallSite(const CallInst *CI) : CallSiteBase(CI) {}
     699      149048 :   ImmutableCallSite(const InvokeInst *II) : CallSiteBase(II) {}
     700    31979572 :   explicit ImmutableCallSite(const Instruction *II) : CallSiteBase(II) {}
     701   224390160 :   explicit ImmutableCallSite(const Value *V) : CallSiteBase(V) {}
     702    18751818 :   ImmutableCallSite(CallSite CS) : CallSiteBase(CS.getInstruction()) {}
     703             : };
     704             : 
     705             : } // end namespace llvm
     706             : 
     707             : #endif // LLVM_IR_CALLSITE_H

Generated by: LCOV version 1.13