LLVM  8.0.1
CallSite.h
Go to the documentation of this file.
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"
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:
64 
65  CallSiteBase() = default;
66  CallSiteBase(CallTy *CI) : I(CI, true) { assert(CI); }
67  CallSiteBase(InvokeTy *II) : I(II, false) { assert(II); }
68  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  if (InstrTy *II = dyn_cast<InstrTy>(V)) {
76  if (II->getOpcode() == Instruction::Call)
77  return CallSiteBase(static_cast<CallTy*>(II));
78  else if (II->getOpcode() == Instruction::Invoke)
79  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  bool isCall() const { return I.getInt(); }
88 
89  /// Return true if a InvokeInst is enclosed.
90  bool isInvoke() const { return getInstruction() && !I.getInt(); }
91 
92  InstrTy *getInstruction() const { return I.getPointer(); }
93  InstrTy *operator->() const { return I.getPointer(); }
94  explicit operator bool() const { return I.getPointer(); }
95 
96  /// Get the basic block containing the call site.
97  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  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  return dyn_cast<FunTy>(getCalledValue());
109  }
110 
111  /// Return true if the callsite is an indirect call.
112  bool isIndirectCall() const {
113  const Value *V = getCalledValue();
114  if (!V)
115  return false;
116  if (isa<FunTy>(V) || isa<Constant>(V))
117  return false;
118  if (const CallInst *CI = dyn_cast<CallInst>(getInstruction())) {
119  if (CI->isInlineAsm())
120  return false;
121  }
122  return true;
123  }
124 
125  /// Set the callee to the specified value.
127  assert(getInstruction() && "Not a call or invoke instruction!");
128  *getCallee() = V;
129  }
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.
135  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.
144  return isCallee(&UI.getUse());
145  }
146 
147  /// Determine whether this Use is the callee operand's Use.
148  bool isCallee(const Use *U) const { return getCallee() == U; }
149 
150  /// Determine whether the passed iterator points to an argument operand.
152  return isArgOperand(&UI.getUse());
153  }
154 
155  /// Determine whether the passed use points to an argument operand.
156  bool isArgOperand(const Use *U) const {
157  assert(getInstruction() == U->getUser());
158  return arg_begin() <= U && U < arg_end();
159  }
160 
161  /// Determine whether the passed iterator points to a bundle operand.
163  return isBundleOperand(&UI.getUse());
164  }
165 
166  /// Determine whether the passed use points to a bundle operand.
167  bool isBundleOperand(const Use *U) const {
168  assert(getInstruction() == U->getUser());
169  if (!hasOperandBundles())
170  return false;
171  unsigned OperandNo = U - (*this)->op_begin();
172  return getBundleOperandsStartIndex() <= OperandNo &&
173  OperandNo < getBundleOperandsEndIndex();
174  }
175 
176  /// Determine whether the passed iterator points to a data operand.
178  return isDataOperand(&UI.getUse());
179  }
180 
181  /// Determine whether the passed use points to a data operand.
182  bool isDataOperand(const Use *U) const {
183  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  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  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.
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  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 
216  return make_range(arg_begin(), arg_end());
217  }
218  bool arg_empty() const { return arg_end() == arg_begin(); }
219  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.
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  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  return (*this)->op_begin();
248  }
249  IterTy data_operands_end() const {
250  assert(getInstruction() && "Not a call or invoke instruction!");
251  return (*this)->op_end() - (isCall() ? 1 : 3);
252  }
254  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  Type *getType() const { return (*this)->getType(); }
265 
266  /// Return the caller function for this call site.
267  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  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  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  unsigned getNumArgOperands() const {
294  CALLSITE_DELEGATE_GETTER(getNumArgOperands());
295  }
296 
297  ValTy *getArgOperand(unsigned i) const {
298  CALLSITE_DELEGATE_GETTER(getArgOperand(i));
299  }
300 
301  ValTy *getReturnedArgOperand() const {
302  CALLSITE_DELEGATE_GETTER(getReturnedArgOperand());
303  }
304 
305  bool isInlineAsm() const {
306  if (isCall())
307  return cast<CallInst>(getInstruction())->isInlineAsm();
308  return false;
309  }
310 
311  /// Get the calling convention of the call.
313  CALLSITE_DELEGATE_GETTER(getCallingConv());
314  }
315  /// Set the calling convention of the call.
317  CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
318  }
319 
321  CALLSITE_DELEGATE_GETTER(getFunctionType());
322  }
323 
325  CALLSITE_DELEGATE_SETTER(mutateFunctionType(Ty));
326  }
327 
328  /// Get the parameter attributes of the call.
331  }
332  /// Set the parameter attributes of the call.
334  CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
335  }
336 
338  CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind));
339  }
340 
341  void addAttribute(unsigned i, Attribute Attr) {
342  CALLSITE_DELEGATE_SETTER(addAttribute(i, Attr));
343  }
344 
345  void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
346  CALLSITE_DELEGATE_SETTER(addParamAttr(ArgNo, Kind));
347  }
348 
350  CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
351  }
352 
353  void removeAttribute(unsigned i, StringRef Kind) {
354  CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
355  }
356 
357  void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
358  CALLSITE_DELEGATE_SETTER(removeParamAttr(ArgNo, Kind));
359  }
360 
361  /// Return true if this function has the given attribute.
363  CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
364  }
365 
366  /// Return true if this function has the given attribute.
367  bool hasFnAttr(StringRef Kind) const {
368  CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind));
369  }
370 
371  /// Return true if this return value has the given attribute.
373  CALLSITE_DELEGATE_GETTER(hasRetAttr(Kind));
374  }
375 
376  /// Return true if the call or the callee has the given attribute.
377  bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
378  CALLSITE_DELEGATE_GETTER(paramHasAttr(ArgNo, Kind));
379  }
380 
382  CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
383  }
384 
385  Attribute getAttribute(unsigned i, StringRef Kind) const {
386  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.
397  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  unsigned getParamAlignment(unsigned ArgNo) const {
407  CALLSITE_DELEGATE_GETTER(getParamAlignment(ArgNo));
408  }
409 
410  /// Extract the number of dereferenceable bytes for a call or parameter
411  /// (0=unknown).
412  uint64_t getDereferenceableBytes(unsigned i) const {
413  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  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
419  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  bool isNoBuiltin() const {
429  CALLSITE_DELEGATE_GETTER(isNoBuiltin());
430  }
431 
432  /// Return true if the call requires strict floating point semantics.
433  bool isStrictFP() const {
434  CALLSITE_DELEGATE_GETTER(isStrictFP());
435  }
436 
437  /// Return true if the call should not be inlined.
438  bool isNoInline() const {
439  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  bool doesNotAccessMemory() const {
447  CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
448  }
451  }
452 
453  /// Determine if the call does not access or only reads memory.
454  bool onlyReadsMemory() const {
455  CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
456  }
459  }
460 
461  /// Determine if the call does not access or only writes memory.
462  bool doesNotReadMemory() const {
463  CALLSITE_DELEGATE_GETTER(doesNotReadMemory());
464  }
466  CALLSITE_DELEGATE_SETTER(setDoesNotReadMemory());
467  }
468 
469  /// Determine if the call can access memmory only using pointers based
470  /// on its arguments.
471  bool onlyAccessesArgMemory() const {
472  CALLSITE_DELEGATE_GETTER(onlyAccessesArgMemory());
473  }
476  }
477 
478  /// Determine if the function may only access memory that is
479  /// inaccessible from the IR.
481  CALLSITE_DELEGATE_GETTER(onlyAccessesInaccessibleMemory());
482  }
484  CALLSITE_DELEGATE_SETTER(setOnlyAccessesInaccessibleMemory());
485  }
486 
487  /// Determine if the function may only access memory that is
488  /// either inaccessible from the IR or pointed to by its arguments.
490  CALLSITE_DELEGATE_GETTER(onlyAccessesInaccessibleMemOrArgMem());
491  }
493  CALLSITE_DELEGATE_SETTER(setOnlyAccessesInaccessibleMemOrArgMem());
494  }
495 
496  /// Determine if the call cannot return.
497  bool doesNotReturn() const {
498  CALLSITE_DELEGATE_GETTER(doesNotReturn());
499  }
501  CALLSITE_DELEGATE_SETTER(setDoesNotReturn());
502  }
503 
504  /// Determine if the call cannot unwind.
505  bool doesNotThrow() const {
506  CALLSITE_DELEGATE_GETTER(doesNotThrow());
507  }
510  }
511 
512  /// Determine if the call can be duplicated.
513  bool cannotDuplicate() const {
514  CALLSITE_DELEGATE_GETTER(cannotDuplicate());
515  }
518  }
519 
520  /// Determine if the call is convergent.
521  bool isConvergent() const {
522  CALLSITE_DELEGATE_GETTER(isConvergent());
523  }
524  void setConvergent() {
525  CALLSITE_DELEGATE_SETTER(setConvergent());
526  }
528  CALLSITE_DELEGATE_SETTER(setNotConvergent());
529  }
530 
531  unsigned getNumOperandBundles() const {
532  CALLSITE_DELEGATE_GETTER(getNumOperandBundles());
533  }
534 
535  bool hasOperandBundles() const {
536  CALLSITE_DELEGATE_GETTER(hasOperandBundles());
537  }
538 
539  unsigned getBundleOperandsStartIndex() const {
540  CALLSITE_DELEGATE_GETTER(getBundleOperandsStartIndex());
541  }
542 
543  unsigned getBundleOperandsEndIndex() const {
544  CALLSITE_DELEGATE_GETTER(getBundleOperandsEndIndex());
545  }
546 
547  unsigned getNumTotalBundleOperands() const {
548  CALLSITE_DELEGATE_GETTER(getNumTotalBundleOperands());
549  }
550 
552  CALLSITE_DELEGATE_GETTER(getOperandBundleAt(Index));
553  }
554 
556  CALLSITE_DELEGATE_GETTER(getOperandBundle(Name));
557  }
558 
560  CALLSITE_DELEGATE_GETTER(getOperandBundle(ID));
561  }
562 
564  CALLSITE_DELEGATE_GETTER(countOperandBundlesOfType(ID));
565  }
566 
567  bool isBundleOperand(unsigned Idx) const {
568  CALLSITE_DELEGATE_GETTER(isBundleOperand(Idx));
569  }
570 
571  IterTy arg_begin() const {
572  CALLSITE_DELEGATE_GETTER(arg_begin());
573  }
574 
575  IterTy arg_end() const {
576  CALLSITE_DELEGATE_GETTER(arg_end());
577  }
578 
579 #undef CALLSITE_DELEGATE_GETTER
580 #undef CALLSITE_DELEGATE_SETTER
581 
583  const Instruction *II = getInstruction();
584  // Since this is actually a getter that "looks like" a setter, don't use the
585  // above macros to avoid confusion.
586  if (isCall())
587  cast<CallInst>(II)->getOperandBundlesAsDefs(Defs);
588  else
589  cast<InvokeInst>(II)->getOperandBundlesAsDefs(Defs);
590  }
591 
592  /// Determine whether this data operand is not captured.
593  bool doesNotCapture(unsigned OpNo) const {
594  return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture);
595  }
596 
597  /// Determine whether this argument is passed by value.
598  bool isByValArgument(unsigned ArgNo) const {
599  return paramHasAttr(ArgNo, Attribute::ByVal);
600  }
601 
602  /// Determine whether this argument is passed in an alloca.
603  bool isInAllocaArgument(unsigned ArgNo) const {
604  return paramHasAttr(ArgNo, Attribute::InAlloca);
605  }
606 
607  /// Determine whether this argument is passed by value or in an alloca.
608  bool isByValOrInAllocaArgument(unsigned ArgNo) const {
609  return paramHasAttr(ArgNo, Attribute::ByVal) ||
610  paramHasAttr(ArgNo, Attribute::InAlloca);
611  }
612 
613  /// Determine if there are is an inalloca argument. Only the last argument can
614  /// have the inalloca attribute.
615  bool hasInAllocaArgument() const {
616  return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
617  }
618 
619  bool doesNotAccessMemory(unsigned OpNo) const {
620  return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
621  }
622 
623  bool onlyReadsMemory(unsigned OpNo) const {
624  return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadOnly) ||
625  dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
626  }
627 
628  bool doesNotReadMemory(unsigned OpNo) const {
629  return dataOperandHasImpliedAttr(OpNo + 1, Attribute::WriteOnly) ||
630  dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
631  }
632 
633  /// Return true if the return value is known to be not null.
634  /// This may be because it has the nonnull attribute, or because at least
635  /// one byte is dereferenceable and the pointer is in addrspace(0).
636  bool isReturnNonNull() const {
637  if (hasRetAttr(Attribute::NonNull))
638  return true;
639  else if (getDereferenceableBytes(AttributeList::ReturnIndex) > 0 &&
640  !NullPointerIsDefined(getCaller(),
641  getType()->getPointerAddressSpace()))
642  return true;
643 
644  return false;
645  }
646 
647  /// Returns true if this CallSite passes the given Value* as an argument to
648  /// the called function.
649  bool hasArgument(const Value *Arg) const {
650  for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E;
651  ++AI)
652  if (AI->get() == Arg)
653  return true;
654  return false;
655  }
656 
657 private:
658  IterTy getCallee() const {
659  return cast<CallBase>(getInstruction())->op_end() - 1;
660  }
661 };
662 
663 class CallSite : public CallSiteBase<Function, BasicBlock, Value, User, Use,
664  Instruction, CallInst, InvokeInst,
665  User::op_iterator> {
666 public:
667  CallSite() = default;
671  explicit CallSite(Instruction *II) : CallSiteBase(II) {}
672  explicit CallSite(Value *V) : CallSiteBase(V) {}
673 
674  bool operator==(const CallSite &CS) const { return I == CS.I; }
675  bool operator!=(const CallSite &CS) const { return I != CS.I; }
676  bool operator<(const CallSite &CS) const {
677  return getInstruction() < CS.getInstruction();
678  }
679 
680 private:
681  friend struct DenseMapInfo<CallSite>;
682 
683  User::op_iterator getCallee() const;
684 };
685 
686 template <> struct DenseMapInfo<CallSite> {
688 
690  CallSite CS;
691  CS.I = BaseInfo::getEmptyKey();
692  return CS;
693  }
694 
696  CallSite CS;
697  CS.I = BaseInfo::getTombstoneKey();
698  return CS;
699  }
700 
701  static unsigned getHashValue(const CallSite &CS) {
702  return BaseInfo::getHashValue(CS.I);
703  }
704 
705  static bool isEqual(const CallSite &LHS, const CallSite &RHS) {
706  return LHS == RHS;
707  }
708 };
709 
710 /// Establish a view to a call site for examination.
711 class ImmutableCallSite : public CallSiteBase<> {
712 public:
713  ImmutableCallSite() = default;
716  explicit ImmutableCallSite(const Instruction *II) : CallSiteBase(II) {}
717  explicit ImmutableCallSite(const Value *V) : CallSiteBase(V) {}
718  ImmutableCallSite(CallSite CS) : CallSiteBase(CS.getInstruction()) {}
719 };
720 
721 } // end namespace llvm
722 
723 #endif // LLVM_IR_CALLSITE_H
void setConvergent()
Definition: CallSite.h:524
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: CallSite.h:412
unsigned getArgumentNo(const Use *U) const
Given a use for an argument, get the argument number that corresponds to it.
Definition: CallSite.h:205
ImmutableCallSite(const Value *V)
Definition: CallSite.h:717
ImmutableCallSite(const Instruction *II)
Definition: CallSite.h:716
bool isInlineAsm() const
Definition: CallSite.h:305
static CallSite getEmptyKey()
Definition: CallSite.h:689
unsigned arg_size() const
Definition: CallSite.h:219
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
Definition: CallSite.h:312
This class represents lattice values for constants.
Definition: AllocatorList.h:24
CallSite(Instruction *II)
Definition: CallSite.h:671
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: CallSite.h:406
PointerTy getPointer() const
bool operator!=(const CallSite &CS) const
Definition: CallSite.h:675
Various leaf nodes.
Definition: ISDOpcodes.h:60
bool onlyReadsMemory(unsigned OpNo) const
Definition: CallSite.h:623
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
Definition: CallSite.h:603
bool isBundleOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a bundle operand.
Definition: CallSite.h:162
unsigned getDataOperandNo(const Use *U) const
Given a use for a data operand, get the data operand number that corresponds to it.
Definition: CallSite.h:229
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: CallSite.h:471
Attribute getAttribute(unsigned i, StringRef Kind) const
Definition: CallSite.h:385
void setDoesNotAccessMemory()
Definition: CallSite.h:449
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
Definition: CallSite.h:423
#define CALLSITE_DELEGATE_GETTER(METHOD)
Definition: CallSite.h:280
CallSiteBase(ValTy *II)
Definition: CallSite.h:68
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
This class represents a function call, abstracting a target machine&#39;s calling convention.
iterator_range< IterTy > args() const
Definition: CallSite.h:215
Optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
Definition: CallSite.h:559
static unsigned getHashValue(const CallSite &CS)
Definition: CallSite.h:701
bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i directly or indirectly has the attribute A...
Definition: CallSite.h:396
unsigned getBundleOperandsEndIndex() const
Definition: CallSite.h:543
F(f)
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
Definition: CallSite.h:418
block Block Frequency true
bool isCallee(const Use *U) const
Determine whether this Use is the callee operand&#39;s Use.
Definition: CallSite.h:148
CallSiteBase(CallTy *CI)
Definition: CallSite.h:66
bool isIndirectCall() const
Return true if the callsite is an indirect call.
Definition: CallSite.h:112
This defines the Use class.
CallSite(InvokeInst *II)
Definition: CallSite.h:670
bool isNoInline() const
Return true if the call should not be inlined.
Definition: CallSite.h:438
unsigned getBundleOperandsStartIndex() const
Definition: CallSite.h:539
PointerIntPair< InstrTy *, 1, bool > I
Definition: CallSite.h:63
void setOnlyAccessesInaccessibleMemory()
Definition: CallSite.h:483
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Definition: CallSite.h:454
bool arg_empty() const
Definition: CallSite.h:218
bool doesNotReturn() const
Determine if the call cannot return.
Definition: CallSite.h:497
amdgpu Simplify well known AMD library false Value Value const Twine & Name
InstrTy * operator->() const
Definition: CallSite.h:93
unsigned data_operands_size() const
Definition: CallSite.h:259
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
CallSite(Value *V)
Definition: CallSite.h:672
bool isArgOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to an argument operand.
Definition: CallSite.h:151
IterTy arg_end() const
Definition: CallSite.h:575
bool isArgOperand(const Use *U) const
Determine whether the passed use points to an argument operand.
Definition: CallSite.h:156
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
This file contains the simple types necessary to represent the attributes associated with functions a...
InstrTy * getInstruction() const
Definition: CallSite.h:92
bool isReturnNonNull() const
Return true if the return value is known to be not null.
Definition: CallSite.h:636
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
Definition: CallSite.h:615
void setArgument(unsigned ArgNo, Value *newVal)
Definition: CallSite.h:191
void setOnlyAccessesArgMemory()
Definition: CallSite.h:474
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:100
IterTy data_operands_end() const
Definition: CallSite.h:249
Class to represent function types.
Definition: DerivedTypes.h:103
static bool setDoesNotThrow(Function &F)
IntType getInt() const
ValTy * getArgOperand(unsigned i) const
Definition: CallSite.h:297
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: CallSite.h:428
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
Definition: CallSite.h:134
unsigned getDataOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the data operand corresponding to it.
Definition: CallSite.h:223
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
Definition: CallSite.h:377
void setDoesNotReadMemory()
Definition: CallSite.h:465
bool isCall() const
Return true if a CallInst is enclosed.
Definition: CallSite.h:87
CallSite(CallSiteBase B)
Definition: CallSite.h:668
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Definition: CallSite.h:555
bool isBundleOperand(const Use *U) const
Determine whether the passed use points to a bundle operand.
Definition: CallSite.h:167
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
Definition: CallSite.h:333
bool isStrictFP() const
Return true if the call requires strict floating point semantics.
Definition: CallSite.h:433
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setIsNoInline(bool Value=true)
Definition: CallSite.h:441
void addAttribute(unsigned i, Attribute Attr)
Definition: CallSite.h:341
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Definition: CallSite.h:362
bool doesNotReadMemory(unsigned OpNo) const
Definition: CallSite.h:628
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Definition: CallSite.h:357
static bool setOnlyReadsMemory(Function &F)
bool hasOperandBundles() const
Definition: CallSite.h:535
unsigned getNumTotalBundleOperands() const
Definition: CallSite.h:547
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
Definition: CallSite.h:316
bool isDataOperand(const Use *U) const
Determine whether the passed use points to a data operand.
Definition: CallSite.h:182
CallSite(CallInst *CI)
Definition: CallSite.h:669
bool isDataOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a data operand.
Definition: CallSite.h:177
bool hasFnAttr(StringRef Kind) const
Return true if this function has the given attribute.
Definition: CallSite.h:367
bool operator<(const CallSite &CS) const
Definition: CallSite.h:676
static bool setDoesNotAccessMemory(Function &F)
void setNotConvergent()
Definition: CallSite.h:527
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Definition: CallSite.h:593
bool hasArgument(const Value *Arg) const
Returns true if this CallSite passes the given Value* as an argument to the called function...
Definition: CallSite.h:649
unsigned getNumArgOperands() const
Definition: CallSite.h:293
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
Definition: CallSite.h:381
ImmutableCallSite(CallSite CS)
Definition: CallSite.h:718
static bool isEqual(const CallSite &LHS, const CallSite &RHS)
Definition: CallSite.h:705
bool doesNotAccessMemory(unsigned OpNo) const
Definition: CallSite.h:619
bool isInvoke() const
Return true if a InvokeInst is enclosed.
Definition: CallSite.h:90
void setCannotDuplicate()
Definition: CallSite.h:516
static CallSite getTombstoneKey()
Definition: CallSite.h:695
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool data_operands_empty() const
Definition: CallSite.h:256
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
Definition: CallSite.h:462
ValTy * getArgument(unsigned ArgNo) const
Definition: CallSite.h:186
OperandBundleUse getOperandBundleAt(unsigned Index) const
Definition: CallSite.h:551
void removeAttribute(unsigned i, StringRef Kind)
Definition: CallSite.h:353
IterTy arg_begin() const
Definition: CallSite.h:571
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:976
void setOnlyAccessesInaccessibleMemOrArgMem()
Definition: CallSite.h:492
ImmutableCallSite(const InvokeInst *II)
Definition: CallSite.h:715
void setDoesNotThrow()
Definition: CallSite.h:508
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
Definition: CallSite.h:480
IterTy data_operands_begin() const
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
Definition: CallSite.h:245
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:1437
BBTy * getParent() const
Get the basic block containing the call site.
Definition: CallSite.h:97
A range adaptor for a pair of iterators.
ImmutableCallSite(const CallInst *CI)
Definition: CallSite.h:714
bool isBundleOperand(unsigned Idx) const
Definition: CallSite.h:567
void setDoesNotReturn()
Definition: CallSite.h:500
A lightweight accessor for an operand bundle meant to be passed around by value.
Definition: InstrTypes.h:914
void addAttribute(unsigned i, Attribute::AttrKind Kind)
Definition: CallSite.h:337
bool operator==(const CallSite &CS) const
Definition: CallSite.h:674
bool doesNotAccessMemory() const
Determine if the call does not access memory.
Definition: CallSite.h:446
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:370
amdgpu Simplify well known AMD library false Value Value * Arg
could "use" a pointer
unsigned countOperandBundlesOfType(uint32_t ID) const
Definition: CallSite.h:563
FunTy * getCaller() const
Return the caller function for this call site.
Definition: CallSite.h:267
unsigned getNumOperandBundles() const
Definition: CallSite.h:531
bool cannotDuplicate() const
Determine if the call can be duplicated.
Definition: CallSite.h:513
#define CALLSITE_DELEGATE_SETTER(METHOD)
Definition: CallSite.h:286
CallSiteBase(InvokeTy *II)
Definition: CallSite.h:67
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Definition: CallSite.h:582
iterator_range< IterTy > data_ops() const
Definition: CallSite.h:253
const Use * const_op_iterator
Definition: User.h:226
Establish a view to a call site for examination.
Definition: CallSite.h:711
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
static bool setOnlyAccessesArgMemory(Function &F)
#define I(x, y, z)
Definition: MD5.cpp:58
bool doesNotThrow() const
Determine if the call cannot unwind.
Definition: CallSite.h:505
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
Definition: CallSite.h:349
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
bool isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
Definition: CallSite.h:608
Type * getType() const
Return the type of the instruction that generated this call site.
Definition: CallSite.h:264
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
Definition: CallSite.h:598
static void setCannotDuplicate(CoroIdInst *CoroId)
Definition: CoroEarly.cpp:147
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:107
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getRetAlignment() const
Extract the alignment of the return value.
Definition: CallSite.h:401
bool isTailCall() const
Tests if this call site is marked as a tail call.
Definition: CallSite.h:276
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
Definition: CallSite.h:372
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:566
LLVM Value Representation.
Definition: Value.h:73
FunctionType * getFunctionType() const
Definition: CallSite.h:320
void setOnlyReadsMemory()
Definition: CallSite.h:457
unsigned getArgumentNo(Value::const_user_iterator I) const
Given a value use iterator, returns the argument that corresponds to it.
Definition: CallSite.h:199
Invoke instruction.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
AttributeList getAttributes() const
Get the parameter attributes of the call.
Definition: CallSite.h:329
bool isConvergent() const
Determine if the call is convergent.
Definition: CallSite.h:521
ValTy * getReturnedArgOperand() const
Definition: CallSite.h:301
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Definition: CallSite.h:271
void setCalledFunction(Value *V)
Set the callee to the specified value.
Definition: CallSite.h:126
void mutateFunctionType(FunctionType *Ty) const
Definition: CallSite.h:324
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Definition: CallSite.h:345
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
Definition: CallSite.h:489
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand&#39;s Use.
Definition: CallSite.h:143