LLVM  4.0.0
Instructions.h
Go to the documentation of this file.
1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- 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 exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
18 
19 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/None.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/IR/Attributes.h"
27 #include "llvm/IR/CallingConv.h"
28 #include "llvm/IR/Constant.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/InstrTypes.h"
32 #include "llvm/IR/OperandTraits.h"
33 #include "llvm/IR/Type.h"
34 #include "llvm/IR/Use.h"
35 #include "llvm/IR/User.h"
37 #include "llvm/Support/Casting.h"
39 #include <cassert>
40 #include <cstddef>
41 #include <cstdint>
42 
43 namespace llvm {
44 
45 class APInt;
46 class ConstantInt;
47 class DataLayout;
48 class LLVMContext;
49 
53 };
54 
55 //===----------------------------------------------------------------------===//
56 // AllocaInst Class
57 //===----------------------------------------------------------------------===//
58 
59 /// an instruction to allocate memory on the stack
60 class AllocaInst : public UnaryInstruction {
61  Type *AllocatedType;
62 
63 protected:
64  // Note: Instruction needs to be a friend here to call cloneImpl.
65  friend class Instruction;
66 
67  AllocaInst *cloneImpl() const;
68 
69 public:
70  explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
71  const Twine &Name = "",
72  Instruction *InsertBefore = nullptr);
73  AllocaInst(Type *Ty, Value *ArraySize,
74  const Twine &Name, BasicBlock *InsertAtEnd);
75 
76  AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
77  AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
78 
79  AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
80  const Twine &Name = "", Instruction *InsertBefore = nullptr);
81  AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
82  const Twine &Name, BasicBlock *InsertAtEnd);
83 
84  // Out of line virtual method, so the vtable, etc. has a home.
85  ~AllocaInst() override;
86 
87  /// Return true if there is an allocation size parameter to the allocation
88  /// instruction that is not 1.
89  bool isArrayAllocation() const;
90 
91  /// Get the number of elements allocated. For a simple allocation of a single
92  /// element, this will return a constant 1 value.
93  const Value *getArraySize() const { return getOperand(0); }
94  Value *getArraySize() { return getOperand(0); }
95 
96  /// Overload to return most specific pointer type.
97  PointerType *getType() const {
98  return cast<PointerType>(Instruction::getType());
99  }
100 
101  /// Return the type that is being allocated by the instruction.
102  Type *getAllocatedType() const { return AllocatedType; }
103  /// for use only in special circumstances that need to generically
104  /// transform a whole instruction (eg: IR linking and vectorization).
105  void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
106 
107  /// Return the alignment of the memory that is being allocated by the
108  /// instruction.
109  unsigned getAlignment() const {
110  return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
111  }
112  void setAlignment(unsigned Align);
113 
114  /// Return true if this alloca is in the entry block of the function and is a
115  /// constant size. If so, the code generator will fold it into the
116  /// prolog/epilog code, so it is basically free.
117  bool isStaticAlloca() const;
118 
119  /// Return true if this alloca is used as an inalloca argument to a call. Such
120  /// allocas are never considered static even if they are in the entry block.
121  bool isUsedWithInAlloca() const {
122  return getSubclassDataFromInstruction() & 32;
123  }
124 
125  /// Specify whether this alloca is used to represent the arguments to a call.
126  void setUsedWithInAlloca(bool V) {
127  setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
128  (V ? 32 : 0));
129  }
130 
131  /// Return true if this alloca is used as a swifterror argument to a call.
132  bool isSwiftError() const {
133  return getSubclassDataFromInstruction() & 64;
134  }
135 
136  /// Specify whether this alloca is used to represent a swifterror.
137  void setSwiftError(bool V) {
138  setInstructionSubclassData((getSubclassDataFromInstruction() & ~64) |
139  (V ? 64 : 0));
140  }
141 
142  // Methods for support type inquiry through isa, cast, and dyn_cast:
143  static inline bool classof(const Instruction *I) {
144  return (I->getOpcode() == Instruction::Alloca);
145  }
146  static inline bool classof(const Value *V) {
147  return isa<Instruction>(V) && classof(cast<Instruction>(V));
148  }
149 
150 private:
151  // Shadow Instruction::setInstructionSubclassData with a private forwarding
152  // method so that subclasses cannot accidentally use it.
153  void setInstructionSubclassData(unsigned short D) {
155  }
156 };
157 
158 //===----------------------------------------------------------------------===//
159 // LoadInst Class
160 //===----------------------------------------------------------------------===//
161 
162 /// An instruction for reading from memory. This uses the SubclassData field in
163 /// Value to store whether or not the load is volatile.
164 class LoadInst : public UnaryInstruction {
165  void AssertOK();
166 
167 protected:
168  // Note: Instruction needs to be a friend here to call cloneImpl.
169  friend class Instruction;
170 
171  LoadInst *cloneImpl() const;
172 
173 public:
174  LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
175  LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
176  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
177  Instruction *InsertBefore = nullptr);
178  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
179  Instruction *InsertBefore = nullptr)
180  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
181  NameStr, isVolatile, InsertBefore) {}
182  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
183  BasicBlock *InsertAtEnd);
184  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
185  Instruction *InsertBefore = nullptr)
186  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
187  NameStr, isVolatile, Align, InsertBefore) {}
188  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
189  unsigned Align, Instruction *InsertBefore = nullptr);
190  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
191  unsigned Align, BasicBlock *InsertAtEnd);
192  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
193  AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread,
194  Instruction *InsertBefore = nullptr)
195  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
196  NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {}
197  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
198  unsigned Align, AtomicOrdering Order,
199  SynchronizationScope SynchScope = CrossThread,
200  Instruction *InsertBefore = nullptr);
201  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
202  unsigned Align, AtomicOrdering Order,
203  SynchronizationScope SynchScope,
204  BasicBlock *InsertAtEnd);
205  LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
206  LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
207  LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
208  bool isVolatile = false, Instruction *InsertBefore = nullptr);
209  explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
210  bool isVolatile = false,
211  Instruction *InsertBefore = nullptr)
212  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
213  NameStr, isVolatile, InsertBefore) {}
214  LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
215  BasicBlock *InsertAtEnd);
216 
217  /// Return true if this is a load from a volatile memory location.
218  bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
219 
220  /// Specify whether this is a volatile load or not.
221  void setVolatile(bool V) {
222  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
223  (V ? 1 : 0));
224  }
225 
226  /// Return the alignment of the access that is being performed.
227  unsigned getAlignment() const {
228  return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
229  }
230 
231  void setAlignment(unsigned Align);
232 
233  /// Returns the ordering effect of this fence.
235  return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
236  }
237 
238  /// Set the ordering constraint on this load. May not be Release or
239  /// AcquireRelease.
240  void setOrdering(AtomicOrdering Ordering) {
241  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
242  ((unsigned)Ordering << 7));
243  }
244 
247  }
248 
249  /// Specify whether this load is ordered with respect to all
250  /// concurrently executing threads, or only with respect to signal handlers
251  /// executing in the same thread.
253  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
254  (xthread << 6));
255  }
256 
257  void setAtomic(AtomicOrdering Ordering,
258  SynchronizationScope SynchScope = CrossThread) {
259  setOrdering(Ordering);
260  setSynchScope(SynchScope);
261  }
262 
263  bool isSimple() const { return !isAtomic() && !isVolatile(); }
264  bool isUnordered() const {
265  return (getOrdering() == AtomicOrdering::NotAtomic ||
267  !isVolatile();
268  }
269 
271  const Value *getPointerOperand() const { return getOperand(0); }
272  static unsigned getPointerOperandIndex() { return 0U; }
273 
274  /// Returns the address space of the pointer operand.
275  unsigned getPointerAddressSpace() const {
277  }
278 
279  // Methods for support type inquiry through isa, cast, and dyn_cast:
280  static inline bool classof(const Instruction *I) {
281  return I->getOpcode() == Instruction::Load;
282  }
283  static inline bool classof(const Value *V) {
284  return isa<Instruction>(V) && classof(cast<Instruction>(V));
285  }
286 
287 private:
288  // Shadow Instruction::setInstructionSubclassData with a private forwarding
289  // method so that subclasses cannot accidentally use it.
290  void setInstructionSubclassData(unsigned short D) {
292  }
293 };
294 
295 //===----------------------------------------------------------------------===//
296 // StoreInst Class
297 //===----------------------------------------------------------------------===//
298 
299 /// An instruction for storing to memory.
300 class StoreInst : public Instruction {
301  void AssertOK();
302 
303 protected:
304  // Note: Instruction needs to be a friend here to call cloneImpl.
305  friend class Instruction;
306 
307  StoreInst *cloneImpl() const;
308 
309 public:
310  StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
311  StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
312  StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
313  Instruction *InsertBefore = nullptr);
314  StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
315  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
316  unsigned Align, Instruction *InsertBefore = nullptr);
317  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
318  unsigned Align, BasicBlock *InsertAtEnd);
319  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
320  unsigned Align, AtomicOrdering Order,
321  SynchronizationScope SynchScope = CrossThread,
322  Instruction *InsertBefore = nullptr);
323  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
324  unsigned Align, AtomicOrdering Order,
325  SynchronizationScope SynchScope,
326  BasicBlock *InsertAtEnd);
327 
328  // allocate space for exactly two operands
329  void *operator new(size_t s) {
330  return User::operator new(s, 2);
331  }
332 
333  void *operator new(size_t, unsigned) = delete;
334 
335  /// Return true if this is a store to a volatile memory location.
336  bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
337 
338  /// Specify whether this is a volatile store or not.
339  void setVolatile(bool V) {
340  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
341  (V ? 1 : 0));
342  }
343 
344  /// Transparently provide more efficient getOperand methods.
346 
347  /// Return the alignment of the access that is being performed
348  unsigned getAlignment() const {
349  return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
350  }
351 
352  void setAlignment(unsigned Align);
353 
354  /// Returns the ordering effect of this store.
356  return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
357  }
358 
359  /// Set the ordering constraint on this store. May not be Acquire or
360  /// AcquireRelease.
361  void setOrdering(AtomicOrdering Ordering) {
362  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
363  ((unsigned)Ordering << 7));
364  }
365 
368  }
369 
370  /// Specify whether this store instruction is ordered with respect to all
371  /// concurrently executing threads, or only with respect to signal handlers
372  /// executing in the same thread.
374  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
375  (xthread << 6));
376  }
377 
378  void setAtomic(AtomicOrdering Ordering,
379  SynchronizationScope SynchScope = CrossThread) {
380  setOrdering(Ordering);
381  setSynchScope(SynchScope);
382  }
383 
384  bool isSimple() const { return !isAtomic() && !isVolatile(); }
385  bool isUnordered() const {
386  return (getOrdering() == AtomicOrdering::NotAtomic ||
388  !isVolatile();
389  }
390 
391  Value *getValueOperand() { return getOperand(0); }
392  const Value *getValueOperand() const { return getOperand(0); }
393 
395  const Value *getPointerOperand() const { return getOperand(1); }
396  static unsigned getPointerOperandIndex() { return 1U; }
397 
398  /// Returns the address space of the pointer operand.
399  unsigned getPointerAddressSpace() const {
401  }
402 
403  // Methods for support type inquiry through isa, cast, and dyn_cast:
404  static inline bool classof(const Instruction *I) {
405  return I->getOpcode() == Instruction::Store;
406  }
407  static inline bool classof(const Value *V) {
408  return isa<Instruction>(V) && classof(cast<Instruction>(V));
409  }
410 
411 private:
412  // Shadow Instruction::setInstructionSubclassData with a private forwarding
413  // method so that subclasses cannot accidentally use it.
414  void setInstructionSubclassData(unsigned short D) {
416  }
417 };
418 
419 template <>
420 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
421 };
422 
424 
425 //===----------------------------------------------------------------------===//
426 // FenceInst Class
427 //===----------------------------------------------------------------------===//
428 
429 /// An instruction for ordering other memory operations.
430 class FenceInst : public Instruction {
431  void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
432 
433 protected:
434  // Note: Instruction needs to be a friend here to call cloneImpl.
435  friend class Instruction;
436 
437  FenceInst *cloneImpl() const;
438 
439 public:
440  // Ordering may only be Acquire, Release, AcquireRelease, or
441  // SequentiallyConsistent.
443  SynchronizationScope SynchScope = CrossThread,
444  Instruction *InsertBefore = nullptr);
446  SynchronizationScope SynchScope,
447  BasicBlock *InsertAtEnd);
448 
449  // allocate space for exactly zero operands
450  void *operator new(size_t s) {
451  return User::operator new(s, 0);
452  }
453 
454  void *operator new(size_t, unsigned) = delete;
455 
456  /// Returns the ordering effect of this fence.
458  return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
459  }
460 
461  /// Set the ordering constraint on this fence. May only be Acquire, Release,
462  /// AcquireRelease, or SequentiallyConsistent.
463  void setOrdering(AtomicOrdering Ordering) {
464  setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
465  ((unsigned)Ordering << 1));
466  }
467 
469  return SynchronizationScope(getSubclassDataFromInstruction() & 1);
470  }
471 
472  /// Specify whether this fence orders other operations with respect to all
473  /// concurrently executing threads, or only with respect to signal handlers
474  /// executing in the same thread.
476  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
477  xthread);
478  }
479 
480  // Methods for support type inquiry through isa, cast, and dyn_cast:
481  static inline bool classof(const Instruction *I) {
482  return I->getOpcode() == Instruction::Fence;
483  }
484  static inline bool classof(const Value *V) {
485  return isa<Instruction>(V) && classof(cast<Instruction>(V));
486  }
487 
488 private:
489  // Shadow Instruction::setInstructionSubclassData with a private forwarding
490  // method so that subclasses cannot accidentally use it.
491  void setInstructionSubclassData(unsigned short D) {
493  }
494 };
495 
496 //===----------------------------------------------------------------------===//
497 // AtomicCmpXchgInst Class
498 //===----------------------------------------------------------------------===//
499 
500 /// an instruction that atomically checks whether a
501 /// specified value is in a memory location, and, if it is, stores a new value
502 /// there. Returns the value that was loaded.
503 ///
505  void Init(Value *Ptr, Value *Cmp, Value *NewVal,
506  AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
507  SynchronizationScope SynchScope);
508 
509 protected:
510  // Note: Instruction needs to be a friend here to call cloneImpl.
511  friend class Instruction;
512 
513  AtomicCmpXchgInst *cloneImpl() const;
514 
515 public:
516  AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
517  AtomicOrdering SuccessOrdering,
518  AtomicOrdering FailureOrdering,
519  SynchronizationScope SynchScope,
520  Instruction *InsertBefore = nullptr);
521  AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
522  AtomicOrdering SuccessOrdering,
523  AtomicOrdering FailureOrdering,
524  SynchronizationScope SynchScope,
525  BasicBlock *InsertAtEnd);
526 
527  // allocate space for exactly three operands
528  void *operator new(size_t s) {
529  return User::operator new(s, 3);
530  }
531 
532  void *operator new(size_t, unsigned) = delete;
533 
534  /// Return true if this is a cmpxchg from a volatile memory
535  /// location.
536  ///
537  bool isVolatile() const {
538  return getSubclassDataFromInstruction() & 1;
539  }
540 
541  /// Specify whether this is a volatile cmpxchg.
542  ///
543  void setVolatile(bool V) {
544  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
545  (unsigned)V);
546  }
547 
548  /// Return true if this cmpxchg may spuriously fail.
549  bool isWeak() const {
550  return getSubclassDataFromInstruction() & 0x100;
551  }
552 
553  void setWeak(bool IsWeak) {
554  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
555  (IsWeak << 8));
556  }
557 
558  /// Transparently provide more efficient getOperand methods.
560 
561  /// Set the ordering constraint on this cmpxchg.
563  assert(Ordering != AtomicOrdering::NotAtomic &&
564  "CmpXchg instructions can only be atomic.");
565  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
566  ((unsigned)Ordering << 2));
567  }
568 
570  assert(Ordering != AtomicOrdering::NotAtomic &&
571  "CmpXchg instructions can only be atomic.");
572  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
573  ((unsigned)Ordering << 5));
574  }
575 
576  /// Specify whether this cmpxchg is atomic and orders other operations with
577  /// respect to all concurrently executing threads, or only with respect to
578  /// signal handlers executing in the same thread.
580  setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
581  (SynchScope << 1));
582  }
583 
584  /// Returns the ordering constraint on this cmpxchg.
586  return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
587  }
588 
589  /// Returns the ordering constraint on this cmpxchg.
591  return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
592  }
593 
594  /// Returns whether this cmpxchg is atomic between threads or only within a
595  /// single thread.
598  }
599 
601  const Value *getPointerOperand() const { return getOperand(0); }
602  static unsigned getPointerOperandIndex() { return 0U; }
603 
605  const Value *getCompareOperand() const { return getOperand(1); }
606 
608  const Value *getNewValOperand() const { return getOperand(2); }
609 
610  /// Returns the address space of the pointer operand.
611  unsigned getPointerAddressSpace() const {
613  }
614 
615  /// Returns the strongest permitted ordering on failure, given the
616  /// desired ordering on success.
617  ///
618  /// If the comparison in a cmpxchg operation fails, there is no atomic store
619  /// so release semantics cannot be provided. So this function drops explicit
620  /// Release requests from the AtomicOrdering. A SequentiallyConsistent
621  /// operation would remain SequentiallyConsistent.
622  static AtomicOrdering
624  switch (SuccessOrdering) {
625  default:
626  llvm_unreachable("invalid cmpxchg success ordering");
635  }
636  }
637 
638  // Methods for support type inquiry through isa, cast, and dyn_cast:
639  static inline bool classof(const Instruction *I) {
640  return I->getOpcode() == Instruction::AtomicCmpXchg;
641  }
642  static inline bool classof(const Value *V) {
643  return isa<Instruction>(V) && classof(cast<Instruction>(V));
644  }
645 
646 private:
647  // Shadow Instruction::setInstructionSubclassData with a private forwarding
648  // method so that subclasses cannot accidentally use it.
649  void setInstructionSubclassData(unsigned short D) {
651  }
652 };
653 
654 template <>
656  public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
657 };
658 
660 
661 //===----------------------------------------------------------------------===//
662 // AtomicRMWInst Class
663 //===----------------------------------------------------------------------===//
664 
665 /// an instruction that atomically reads a memory location,
666 /// combines it with another value, and then stores the result back. Returns
667 /// the old value.
668 ///
669 class AtomicRMWInst : public Instruction {
670 protected:
671  // Note: Instruction needs to be a friend here to call cloneImpl.
672  friend class Instruction;
673 
674  AtomicRMWInst *cloneImpl() const;
675 
676 public:
677  /// This enumeration lists the possible modifications atomicrmw can make. In
678  /// the descriptions, 'p' is the pointer to the instruction's memory location,
679  /// 'old' is the initial value of *p, and 'v' is the other value passed to the
680  /// instruction. These instructions always return 'old'.
681  enum BinOp {
682  /// *p = v
684  /// *p = old + v
686  /// *p = old - v
688  /// *p = old & v
690  /// *p = ~(old & v)
692  /// *p = old | v
693  Or,
694  /// *p = old ^ v
696  /// *p = old >signed v ? old : v
698  /// *p = old <signed v ? old : v
700  /// *p = old >unsigned v ? old : v
702  /// *p = old <unsigned v ? old : v
704 
705  FIRST_BINOP = Xchg,
706  LAST_BINOP = UMin,
707  BAD_BINOP
708  };
709 
710  AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
711  AtomicOrdering Ordering, SynchronizationScope SynchScope,
712  Instruction *InsertBefore = nullptr);
713  AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
714  AtomicOrdering Ordering, SynchronizationScope SynchScope,
715  BasicBlock *InsertAtEnd);
716 
717  // allocate space for exactly two operands
718  void *operator new(size_t s) {
719  return User::operator new(s, 2);
720  }
721 
722  void *operator new(size_t, unsigned) = delete;
723 
724  BinOp getOperation() const {
725  return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
726  }
727 
728  void setOperation(BinOp Operation) {
729  unsigned short SubclassData = getSubclassDataFromInstruction();
730  setInstructionSubclassData((SubclassData & 31) |
731  (Operation << 5));
732  }
733 
734  /// Return true if this is a RMW on a volatile memory location.
735  ///
736  bool isVolatile() const {
737  return getSubclassDataFromInstruction() & 1;
738  }
739 
740  /// Specify whether this is a volatile RMW or not.
741  ///
742  void setVolatile(bool V) {
743  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
744  (unsigned)V);
745  }
746 
747  /// Transparently provide more efficient getOperand methods.
749 
750  /// Set the ordering constraint on this RMW.
751  void setOrdering(AtomicOrdering Ordering) {
752  assert(Ordering != AtomicOrdering::NotAtomic &&
753  "atomicrmw instructions can only be atomic.");
754  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
755  ((unsigned)Ordering << 2));
756  }
757 
758  /// Specify whether this RMW orders other operations with respect to all
759  /// concurrently executing threads, or only with respect to signal handlers
760  /// executing in the same thread.
762  setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
763  (SynchScope << 1));
764  }
765 
766  /// Returns the ordering constraint on this RMW.
768  return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
769  }
770 
771  /// Returns whether this RMW is atomic between threads or only within a
772  /// single thread.
774  return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
775  }
776 
777  Value *getPointerOperand() { return getOperand(0); }
778  const Value *getPointerOperand() const { return getOperand(0); }
779  static unsigned getPointerOperandIndex() { return 0U; }
780 
781  Value *getValOperand() { return getOperand(1); }
782  const Value *getValOperand() const { return getOperand(1); }
783 
784  /// Returns the address space of the pointer operand.
785  unsigned getPointerAddressSpace() const {
787  }
788 
789  // Methods for support type inquiry through isa, cast, and dyn_cast:
790  static inline bool classof(const Instruction *I) {
791  return I->getOpcode() == Instruction::AtomicRMW;
792  }
793  static inline bool classof(const Value *V) {
794  return isa<Instruction>(V) && classof(cast<Instruction>(V));
795  }
796 
797 private:
798  void Init(BinOp Operation, Value *Ptr, Value *Val,
799  AtomicOrdering Ordering, SynchronizationScope SynchScope);
800 
801  // Shadow Instruction::setInstructionSubclassData with a private forwarding
802  // method so that subclasses cannot accidentally use it.
803  void setInstructionSubclassData(unsigned short D) {
805  }
806 };
807 
808 template <>
810  : public FixedNumOperandTraits<AtomicRMWInst,2> {
811 };
812 
814 
815 //===----------------------------------------------------------------------===//
816 // GetElementPtrInst Class
817 //===----------------------------------------------------------------------===//
818 
819 // checkGEPType - Simple wrapper function to give a better assertion failure
820 // message on bad indexes for a gep instruction.
821 //
823  assert(Ty && "Invalid GetElementPtrInst indices for type!");
824  return Ty;
825 }
826 
827 /// an instruction for type-safe pointer arithmetic to
828 /// access elements of arrays and structs
829 ///
831  Type *SourceElementType;
832  Type *ResultElementType;
833 
834  void anchor() override;
835 
837  void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
838 
839  /// Constructors - Create a getelementptr instruction with a base pointer an
840  /// list of indices. The first ctor can optionally insert before an existing
841  /// instruction, the second appends the new instruction to the specified
842  /// BasicBlock.
843  inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
844  ArrayRef<Value *> IdxList, unsigned Values,
845  const Twine &NameStr, Instruction *InsertBefore);
846  inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
847  ArrayRef<Value *> IdxList, unsigned Values,
848  const Twine &NameStr, BasicBlock *InsertAtEnd);
849 
850 protected:
851  // Note: Instruction needs to be a friend here to call cloneImpl.
852  friend class Instruction;
853 
854  GetElementPtrInst *cloneImpl() const;
855 
856 public:
857  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
858  ArrayRef<Value *> IdxList,
859  const Twine &NameStr = "",
860  Instruction *InsertBefore = nullptr) {
861  unsigned Values = 1 + unsigned(IdxList.size());
862  if (!PointeeType)
863  PointeeType =
864  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
865  else
866  assert(
867  PointeeType ==
868  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
869  return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
870  NameStr, InsertBefore);
871  }
872 
873  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
874  ArrayRef<Value *> IdxList,
875  const Twine &NameStr,
876  BasicBlock *InsertAtEnd) {
877  unsigned Values = 1 + unsigned(IdxList.size());
878  if (!PointeeType)
879  PointeeType =
880  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
881  else
882  assert(
883  PointeeType ==
884  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
885  return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
886  NameStr, InsertAtEnd);
887  }
888 
889  /// Create an "inbounds" getelementptr. See the documentation for the
890  /// "inbounds" flag in LangRef.html for details.
892  ArrayRef<Value *> IdxList,
893  const Twine &NameStr = "",
894  Instruction *InsertBefore = nullptr){
895  return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
896  }
897 
898  static GetElementPtrInst *
899  CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
900  const Twine &NameStr = "",
901  Instruction *InsertBefore = nullptr) {
903  Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
904  GEP->setIsInBounds(true);
905  return GEP;
906  }
907 
909  ArrayRef<Value *> IdxList,
910  const Twine &NameStr,
911  BasicBlock *InsertAtEnd) {
912  return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
913  }
914 
915  static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
916  ArrayRef<Value *> IdxList,
917  const Twine &NameStr,
918  BasicBlock *InsertAtEnd) {
920  Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
921  GEP->setIsInBounds(true);
922  return GEP;
923  }
924 
925  /// Transparently provide more efficient getOperand methods.
927 
928  Type *getSourceElementType() const { return SourceElementType; }
929 
930  void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
931  void setResultElementType(Type *Ty) { ResultElementType = Ty; }
932 
934  assert(ResultElementType ==
935  cast<PointerType>(getType()->getScalarType())->getElementType());
936  return ResultElementType;
937  }
938 
939  /// Returns the address space of this instruction's pointer type.
940  unsigned getAddressSpace() const {
941  // Note that this is always the same as the pointer operand's address space
942  // and that is cheaper to compute, so cheat here.
943  return getPointerAddressSpace();
944  }
945 
946  /// Returns the type of the element that would be loaded with
947  /// a load instruction with the specified parameters.
948  ///
949  /// Null is returned if the indices are invalid for the specified
950  /// pointer type.
951  ///
952  static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
953  static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
954  static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
955 
956  inline op_iterator idx_begin() { return op_begin()+1; }
957  inline const_op_iterator idx_begin() const { return op_begin()+1; }
958  inline op_iterator idx_end() { return op_end(); }
959  inline const_op_iterator idx_end() const { return op_end(); }
960 
962  return getOperand(0);
963  }
964  const Value *getPointerOperand() const {
965  return getOperand(0);
966  }
967  static unsigned getPointerOperandIndex() {
968  return 0U; // get index for modifying correct operand.
969  }
970 
971  /// Method to return the pointer operand as a
972  /// PointerType.
974  return getPointerOperand()->getType();
975  }
976 
977  /// Returns the address space of the pointer operand.
978  unsigned getPointerAddressSpace() const {
980  }
981 
982  /// Returns the pointer type returned by the GEP
983  /// instruction, which may be a vector of pointers.
984  static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
985  return getGEPReturnType(
986  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
987  Ptr, IdxList);
988  }
989  static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
990  ArrayRef<Value *> IdxList) {
991  Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
992  Ptr->getType()->getPointerAddressSpace());
993  // Vector GEP
994  if (Ptr->getType()->isVectorTy()) {
995  unsigned NumElem = Ptr->getType()->getVectorNumElements();
996  return VectorType::get(PtrTy, NumElem);
997  }
998  for (Value *Index : IdxList)
999  if (Index->getType()->isVectorTy()) {
1000  unsigned NumElem = Index->getType()->getVectorNumElements();
1001  return VectorType::get(PtrTy, NumElem);
1002  }
1003  // Scalar GEP
1004  return PtrTy;
1005  }
1006 
1007  unsigned getNumIndices() const { // Note: always non-negative
1008  return getNumOperands() - 1;
1009  }
1010 
1011  bool hasIndices() const {
1012  return getNumOperands() > 1;
1013  }
1014 
1015  /// Return true if all of the indices of this GEP are
1016  /// zeros. If so, the result pointer and the first operand have the same
1017  /// value, just potentially different types.
1018  bool hasAllZeroIndices() const;
1019 
1020  /// Return true if all of the indices of this GEP are
1021  /// constant integers. If so, the result pointer and the first operand have
1022  /// a constant offset between them.
1023  bool hasAllConstantIndices() const;
1024 
1025  /// Set or clear the inbounds flag on this GEP instruction.
1026  /// See LangRef.html for the meaning of inbounds on a getelementptr.
1027  void setIsInBounds(bool b = true);
1028 
1029  /// Determine whether the GEP has the inbounds flag.
1030  bool isInBounds() const;
1031 
1032  /// Accumulate the constant address offset of this GEP if possible.
1033  ///
1034  /// This routine accepts an APInt into which it will accumulate the constant
1035  /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1036  /// all-constant, it returns false and the value of the offset APInt is
1037  /// undefined (it is *not* preserved!). The APInt passed into this routine
1038  /// must be at least as wide as the IntPtr type for the address space of
1039  /// the base GEP pointer.
1040  bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1041 
1042  // Methods for support type inquiry through isa, cast, and dyn_cast:
1043  static inline bool classof(const Instruction *I) {
1044  return (I->getOpcode() == Instruction::GetElementPtr);
1045  }
1046  static inline bool classof(const Value *V) {
1047  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1048  }
1049 };
1050 
1051 template <>
1053  public VariadicOperandTraits<GetElementPtrInst, 1> {
1054 };
1055 
1056 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1057  ArrayRef<Value *> IdxList, unsigned Values,
1058  const Twine &NameStr,
1059  Instruction *InsertBefore)
1060  : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1061  OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1062  Values, InsertBefore),
1063  SourceElementType(PointeeType),
1064  ResultElementType(getIndexedType(PointeeType, IdxList)) {
1065  assert(ResultElementType ==
1066  cast<PointerType>(getType()->getScalarType())->getElementType());
1067  init(Ptr, IdxList, NameStr);
1068 }
1069 
1070 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1071  ArrayRef<Value *> IdxList, unsigned Values,
1072  const Twine &NameStr,
1073  BasicBlock *InsertAtEnd)
1074  : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1075  OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1076  Values, InsertAtEnd),
1077  SourceElementType(PointeeType),
1078  ResultElementType(getIndexedType(PointeeType, IdxList)) {
1079  assert(ResultElementType ==
1080  cast<PointerType>(getType()->getScalarType())->getElementType());
1081  init(Ptr, IdxList, NameStr);
1082 }
1083 
1084 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1085 
1086 //===----------------------------------------------------------------------===//
1087 // ICmpInst Class
1088 //===----------------------------------------------------------------------===//
1089 
1090 /// This instruction compares its operands according to the predicate given
1091 /// to the constructor. It only operates on integers or pointers. The operands
1092 /// must be identical types.
1093 /// Represent an integer comparison operator.
1094 class ICmpInst: public CmpInst {
1095  void anchor() override;
1096 
1097  void AssertOK() {
1098  assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
1099  getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
1100  "Invalid ICmp predicate value");
1101  assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1102  "Both operands to ICmp instruction are not of the same type!");
1103  // Check that the operands are the right type
1104  assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1105  getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1106  "Invalid operand types for ICmp instruction");
1107  }
1108 
1109 protected:
1110  // Note: Instruction needs to be a friend here to call cloneImpl.
1111  friend class Instruction;
1112 
1113  /// Clone an identical ICmpInst
1114  ICmpInst *cloneImpl() const;
1115 
1116 public:
1117  /// Constructor with insert-before-instruction semantics.
1119  Instruction *InsertBefore, ///< Where to insert
1120  Predicate pred, ///< The predicate to use for the comparison
1121  Value *LHS, ///< The left-hand-side of the expression
1122  Value *RHS, ///< The right-hand-side of the expression
1123  const Twine &NameStr = "" ///< Name of the instruction
1124  ) : CmpInst(makeCmpResultType(LHS->getType()),
1125  Instruction::ICmp, pred, LHS, RHS, NameStr,
1126  InsertBefore) {
1127 #ifndef NDEBUG
1128  AssertOK();
1129 #endif
1130  }
1131 
1132  /// Constructor with insert-at-end semantics.
1134  BasicBlock &InsertAtEnd, ///< Block to insert into.
1135  Predicate pred, ///< The predicate to use for the comparison
1136  Value *LHS, ///< The left-hand-side of the expression
1137  Value *RHS, ///< The right-hand-side of the expression
1138  const Twine &NameStr = "" ///< Name of the instruction
1139  ) : CmpInst(makeCmpResultType(LHS->getType()),
1140  Instruction::ICmp, pred, LHS, RHS, NameStr,
1141  &InsertAtEnd) {
1142 #ifndef NDEBUG
1143  AssertOK();
1144 #endif
1145  }
1146 
1147  /// Constructor with no-insertion semantics
1149  Predicate pred, ///< The predicate to use for the comparison
1150  Value *LHS, ///< The left-hand-side of the expression
1151  Value *RHS, ///< The right-hand-side of the expression
1152  const Twine &NameStr = "" ///< Name of the instruction
1153  ) : CmpInst(makeCmpResultType(LHS->getType()),
1154  Instruction::ICmp, pred, LHS, RHS, NameStr) {
1155 #ifndef NDEBUG
1156  AssertOK();
1157 #endif
1158  }
1159 
1160  /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1161  /// @returns the predicate that would be the result if the operand were
1162  /// regarded as signed.
1163  /// Return the signed version of the predicate
1165  return getSignedPredicate(getPredicate());
1166  }
1167 
1168  /// This is a static version that you can use without an instruction.
1169  /// Return the signed version of the predicate.
1170  static Predicate getSignedPredicate(Predicate pred);
1171 
1172  /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1173  /// @returns the predicate that would be the result if the operand were
1174  /// regarded as unsigned.
1175  /// Return the unsigned version of the predicate
1177  return getUnsignedPredicate(getPredicate());
1178  }
1179 
1180  /// This is a static version that you can use without an instruction.
1181  /// Return the unsigned version of the predicate.
1182  static Predicate getUnsignedPredicate(Predicate pred);
1183 
1184  /// Return true if this predicate is either EQ or NE. This also
1185  /// tests for commutativity.
1186  static bool isEquality(Predicate P) {
1187  return P == ICMP_EQ || P == ICMP_NE;
1188  }
1189 
1190  /// Return true if this predicate is either EQ or NE. This also
1191  /// tests for commutativity.
1192  bool isEquality() const {
1193  return isEquality(getPredicate());
1194  }
1195 
1196  /// @returns true if the predicate of this ICmpInst is commutative
1197  /// Determine if this relation is commutative.
1198  bool isCommutative() const { return isEquality(); }
1199 
1200  /// Return true if the predicate is relational (not EQ or NE).
1201  ///
1202  bool isRelational() const {
1203  return !isEquality();
1204  }
1205 
1206  /// Return true if the predicate is relational (not EQ or NE).
1207  ///
1208  static bool isRelational(Predicate P) {
1209  return !isEquality(P);
1210  }
1211 
1212  /// Exchange the two operands to this instruction in such a way that it does
1213  /// not modify the semantics of the instruction. The predicate value may be
1214  /// changed to retain the same result if the predicate is order dependent
1215  /// (e.g. ult).
1216  /// Swap operands and adjust predicate.
1217  void swapOperands() {
1218  setPredicate(getSwappedPredicate());
1219  Op<0>().swap(Op<1>());
1220  }
1221 
1222  // Methods for support type inquiry through isa, cast, and dyn_cast:
1223  static inline bool classof(const Instruction *I) {
1224  return I->getOpcode() == Instruction::ICmp;
1225  }
1226  static inline bool classof(const Value *V) {
1227  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1228  }
1229 };
1230 
1231 //===----------------------------------------------------------------------===//
1232 // FCmpInst Class
1233 //===----------------------------------------------------------------------===//
1234 
1235 /// This instruction compares its operands according to the predicate given
1236 /// to the constructor. It only operates on floating point values or packed
1237 /// vectors of floating point values. The operands must be identical types.
1238 /// Represents a floating point comparison operator.
1239 class FCmpInst: public CmpInst {
1240 protected:
1241  // Note: Instruction needs to be a friend here to call cloneImpl.
1242  friend class Instruction;
1243 
1244  /// Clone an identical FCmpInst
1245  FCmpInst *cloneImpl() const;
1246 
1247 public:
1248  /// Constructor with insert-before-instruction semantics.
1250  Instruction *InsertBefore, ///< Where to insert
1251  Predicate pred, ///< The predicate to use for the comparison
1252  Value *LHS, ///< The left-hand-side of the expression
1253  Value *RHS, ///< The right-hand-side of the expression
1254  const Twine &NameStr = "" ///< Name of the instruction
1255  ) : CmpInst(makeCmpResultType(LHS->getType()),
1256  Instruction::FCmp, pred, LHS, RHS, NameStr,
1257  InsertBefore) {
1259  "Invalid FCmp predicate value");
1260  assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1261  "Both operands to FCmp instruction are not of the same type!");
1262  // Check that the operands are the right type
1263  assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1264  "Invalid operand types for FCmp instruction");
1265  }
1266 
1267  /// Constructor with insert-at-end semantics.
1269  BasicBlock &InsertAtEnd, ///< Block to insert into.
1270  Predicate pred, ///< The predicate to use for the comparison
1271  Value *LHS, ///< The left-hand-side of the expression
1272  Value *RHS, ///< The right-hand-side of the expression
1273  const Twine &NameStr = "" ///< Name of the instruction
1274  ) : CmpInst(makeCmpResultType(LHS->getType()),
1275  Instruction::FCmp, pred, LHS, RHS, NameStr,
1276  &InsertAtEnd) {
1278  "Invalid FCmp predicate value");
1279  assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1280  "Both operands to FCmp instruction are not of the same type!");
1281  // Check that the operands are the right type
1282  assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1283  "Invalid operand types for FCmp instruction");
1284  }
1285 
1286  /// Constructor with no-insertion semantics
1288  Predicate pred, ///< The predicate to use for the comparison
1289  Value *LHS, ///< The left-hand-side of the expression
1290  Value *RHS, ///< The right-hand-side of the expression
1291  const Twine &NameStr = "" ///< Name of the instruction
1292  ) : CmpInst(makeCmpResultType(LHS->getType()),
1293  Instruction::FCmp, pred, LHS, RHS, NameStr) {
1295  "Invalid FCmp predicate value");
1296  assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1297  "Both operands to FCmp instruction are not of the same type!");
1298  // Check that the operands are the right type
1299  assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1300  "Invalid operand types for FCmp instruction");
1301  }
1302 
1303  /// @returns true if the predicate of this instruction is EQ or NE.
1304  /// Determine if this is an equality predicate.
1305  static bool isEquality(Predicate Pred) {
1306  return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1307  Pred == FCMP_UNE;
1308  }
1309 
1310  /// @returns true if the predicate of this instruction is EQ or NE.
1311  /// Determine if this is an equality predicate.
1312  bool isEquality() const { return isEquality(getPredicate()); }
1313 
1314  /// @returns true if the predicate of this instruction is commutative.
1315  /// Determine if this is a commutative predicate.
1316  bool isCommutative() const {
1317  return isEquality() ||
1318  getPredicate() == FCMP_FALSE ||
1319  getPredicate() == FCMP_TRUE ||
1320  getPredicate() == FCMP_ORD ||
1321  getPredicate() == FCMP_UNO;
1322  }
1323 
1324  /// @returns true if the predicate is relational (not EQ or NE).
1325  /// Determine if this a relational predicate.
1326  bool isRelational() const { return !isEquality(); }
1327 
1328  /// Exchange the two operands to this instruction in such a way that it does
1329  /// not modify the semantics of the instruction. The predicate value may be
1330  /// changed to retain the same result if the predicate is order dependent
1331  /// (e.g. ult).
1332  /// Swap operands and adjust predicate.
1333  void swapOperands() {
1335  Op<0>().swap(Op<1>());
1336  }
1337 
1338  /// Methods for support type inquiry through isa, cast, and dyn_cast:
1339  static inline bool classof(const Instruction *I) {
1340  return I->getOpcode() == Instruction::FCmp;
1341  }
1342  static inline bool classof(const Value *V) {
1343  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1344  }
1345 };
1346 
1347 //===----------------------------------------------------------------------===//
1348 /// This class represents a function call, abstracting a target
1349 /// machine's calling convention. This class uses low bit of the SubClassData
1350 /// field to indicate whether or not this is a tail call. The rest of the bits
1351 /// hold the calling convention of the call.
1352 ///
1353 class CallInst : public Instruction,
1354  public OperandBundleUser<CallInst, User::op_iterator> {
1356 
1357  AttributeSet AttributeList; ///< parameter attributes for call
1358  FunctionType *FTy;
1359 
1360  CallInst(const CallInst &CI);
1361 
1362  /// Construct a CallInst given a range of arguments.
1363  /// Construct a CallInst from a range of arguments
1364  inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1365  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1366  Instruction *InsertBefore);
1367 
1368  inline CallInst(Value *Func, ArrayRef<Value *> Args,
1369  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1370  Instruction *InsertBefore)
1371  : CallInst(cast<FunctionType>(
1372  cast<PointerType>(Func->getType())->getElementType()),
1373  Func, Args, Bundles, NameStr, InsertBefore) {}
1374 
1375  inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1376  Instruction *InsertBefore)
1377  : CallInst(Func, Args, None, NameStr, InsertBefore) {}
1378 
1379  /// Construct a CallInst given a range of arguments.
1380  /// Construct a CallInst from a range of arguments
1381  inline CallInst(Value *Func, ArrayRef<Value *> Args,
1382  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1383  BasicBlock *InsertAtEnd);
1384 
1385  explicit CallInst(Value *F, const Twine &NameStr,
1386  Instruction *InsertBefore);
1387 
1388  CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1389 
1390  void init(Value *Func, ArrayRef<Value *> Args,
1391  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
1392  init(cast<FunctionType>(
1393  cast<PointerType>(Func->getType())->getElementType()),
1394  Func, Args, Bundles, NameStr);
1395  }
1396  void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1397  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1398  void init(Value *Func, const Twine &NameStr);
1399 
1400  bool hasDescriptor() const { return HasDescriptor; }
1401 
1402 protected:
1403  // Note: Instruction needs to be a friend here to call cloneImpl.
1404  friend class Instruction;
1405 
1406  CallInst *cloneImpl() const;
1407 
1408 public:
1409  ~CallInst() override;
1410 
1412  ArrayRef<OperandBundleDef> Bundles = None,
1413  const Twine &NameStr = "",
1414  Instruction *InsertBefore = nullptr) {
1415  return Create(cast<FunctionType>(
1416  cast<PointerType>(Func->getType())->getElementType()),
1417  Func, Args, Bundles, NameStr, InsertBefore);
1418  }
1419 
1421  const Twine &NameStr,
1422  Instruction *InsertBefore = nullptr) {
1423  return Create(cast<FunctionType>(
1424  cast<PointerType>(Func->getType())->getElementType()),
1425  Func, Args, None, NameStr, InsertBefore);
1426  }
1427 
1429  const Twine &NameStr,
1430  Instruction *InsertBefore = nullptr) {
1431  return new (unsigned(Args.size() + 1))
1432  CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1433  }
1434 
1436  ArrayRef<OperandBundleDef> Bundles = None,
1437  const Twine &NameStr = "",
1438  Instruction *InsertBefore = nullptr) {
1439  const unsigned TotalOps =
1440  unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1441  const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1442 
1443  return new (TotalOps, DescriptorBytes)
1444  CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1445  }
1446 
1449  const Twine &NameStr, BasicBlock *InsertAtEnd) {
1450  const unsigned TotalOps =
1451  unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1452  const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1453 
1454  return new (TotalOps, DescriptorBytes)
1455  CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
1456  }
1457 
1459  const Twine &NameStr, BasicBlock *InsertAtEnd) {
1460  return new (unsigned(Args.size() + 1))
1461  CallInst(Func, Args, None, NameStr, InsertAtEnd);
1462  }
1463 
1464  static CallInst *Create(Value *F, const Twine &NameStr = "",
1465  Instruction *InsertBefore = nullptr) {
1466  return new(1) CallInst(F, NameStr, InsertBefore);
1467  }
1468 
1469  static CallInst *Create(Value *F, const Twine &NameStr,
1470  BasicBlock *InsertAtEnd) {
1471  return new(1) CallInst(F, NameStr, InsertAtEnd);
1472  }
1473 
1474  /// Create a clone of \p CI with a different set of operand bundles and
1475  /// insert it before \p InsertPt.
1476  ///
1477  /// The returned call instruction is identical \p CI in every way except that
1478  /// the operand bundles for the new instruction are set to the operand bundles
1479  /// in \p Bundles.
1480  static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
1481  Instruction *InsertPt = nullptr);
1482 
1483  /// Generate the IR for a call to malloc:
1484  /// 1. Compute the malloc call's argument as the specified type's size,
1485  /// possibly multiplied by the array size if the array size is not
1486  /// constant 1.
1487  /// 2. Call malloc with that argument.
1488  /// 3. Bitcast the result of the malloc call to the specified type.
1489  static Instruction *CreateMalloc(Instruction *InsertBefore,
1490  Type *IntPtrTy, Type *AllocTy,
1491  Value *AllocSize, Value *ArraySize = nullptr,
1492  Function* MallocF = nullptr,
1493  const Twine &Name = "");
1494  static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1495  Type *IntPtrTy, Type *AllocTy,
1496  Value *AllocSize, Value *ArraySize = nullptr,
1497  Function* MallocF = nullptr,
1498  const Twine &Name = "");
1499  static Instruction *CreateMalloc(Instruction *InsertBefore,
1500  Type *IntPtrTy, Type *AllocTy,
1501  Value *AllocSize, Value *ArraySize = nullptr,
1502  ArrayRef<OperandBundleDef> Bundles = None,
1503  Function* MallocF = nullptr,
1504  const Twine &Name = "");
1505  static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1506  Type *IntPtrTy, Type *AllocTy,
1507  Value *AllocSize, Value *ArraySize = nullptr,
1508  ArrayRef<OperandBundleDef> Bundles = None,
1509  Function* MallocF = nullptr,
1510  const Twine &Name = "");
1511  /// Generate the IR for a call to the builtin free function.
1513  Instruction *InsertBefore);
1515  BasicBlock *InsertAtEnd);
1518  Instruction *InsertBefore);
1521  BasicBlock *InsertAtEnd);
1522 
1523  FunctionType *getFunctionType() const { return FTy; }
1524 
1526  mutateType(FTy->getReturnType());
1527  this->FTy = FTy;
1528  }
1529 
1530  // Note that 'musttail' implies 'tail'.
1532  TCK_NoTail = 3 };
1535  }
1536 
1537  bool isTailCall() const {
1538  unsigned Kind = getSubclassDataFromInstruction() & 3;
1539  return Kind == TCK_Tail || Kind == TCK_MustTail;
1540  }
1541 
1542  bool isMustTailCall() const {
1543  return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1544  }
1545 
1546  bool isNoTailCall() const {
1547  return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
1548  }
1549 
1550  void setTailCall(bool isTC = true) {
1551  setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1552  unsigned(isTC ? TCK_Tail : TCK_None));
1553  }
1554 
1556  setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1557  unsigned(TCK));
1558  }
1559 
1560  /// Provide fast operand accessors
1562 
1563  /// Return the number of call arguments.
1564  ///
1565  unsigned getNumArgOperands() const {
1566  return getNumOperands() - getNumTotalBundleOperands() - 1;
1567  }
1568 
1569  /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1570  ///
1571  Value *getArgOperand(unsigned i) const {
1572  assert(i < getNumArgOperands() && "Out of bounds!");
1573  return getOperand(i);
1574  }
1575  void setArgOperand(unsigned i, Value *v) {
1576  assert(i < getNumArgOperands() && "Out of bounds!");
1577  setOperand(i, v);
1578  }
1579 
1580  /// Return the iterator pointing to the beginning of the argument list.
1582 
1583  /// Return the iterator pointing to the end of the argument list.
1585  // [ call args ], [ operand bundles ], callee
1586  return op_end() - getNumTotalBundleOperands() - 1;
1587  }
1588 
1589  /// Iteration adapter for range-for loops.
1591  return make_range(arg_begin(), arg_end());
1592  }
1593 
1594  /// Return the iterator pointing to the beginning of the argument list.
1595  const_op_iterator arg_begin() const { return op_begin(); }
1596 
1597  /// Return the iterator pointing to the end of the argument list.
1599  // [ call args ], [ operand bundles ], callee
1600  return op_end() - getNumTotalBundleOperands() - 1;
1601  }
1602 
1603  /// Iteration adapter for range-for loops.
1605  return make_range(arg_begin(), arg_end());
1606  }
1607 
1608  /// Wrappers for getting the \c Use of a call argument.
1609  const Use &getArgOperandUse(unsigned i) const {
1610  assert(i < getNumArgOperands() && "Out of bounds!");
1611  return getOperandUse(i);
1612  }
1613  Use &getArgOperandUse(unsigned i) {
1614  assert(i < getNumArgOperands() && "Out of bounds!");
1615  return getOperandUse(i);
1616  }
1617 
1618  /// If one of the arguments has the 'returned' attribute, return its
1619  /// operand value. Otherwise, return nullptr.
1620  Value *getReturnedArgOperand() const;
1621 
1622  /// getCallingConv/setCallingConv - Get or set the calling convention of this
1623  /// function call.
1625  return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1626  }
1628  auto ID = static_cast<unsigned>(CC);
1629  assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
1630  setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1631  (ID << 2));
1632  }
1633 
1634  /// Return the parameter attributes for this call.
1635  ///
1636  AttributeSet getAttributes() const { return AttributeList; }
1637 
1638  /// Set the parameter attributes for this call.
1639  ///
1640  void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; }
1641 
1642  /// adds the attribute to the list of attributes.
1643  void addAttribute(unsigned i, Attribute::AttrKind Kind);
1644 
1645  /// adds the attribute to the list of attributes.
1646  void addAttribute(unsigned i, Attribute Attr);
1647 
1648  /// removes the attribute from the list of attributes.
1649  void removeAttribute(unsigned i, Attribute::AttrKind Kind);
1650 
1651  /// removes the attribute from the list of attributes.
1652  void removeAttribute(unsigned i, StringRef Kind);
1653 
1654  /// adds the dereferenceable attribute to the list of attributes.
1655  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
1656 
1657  /// adds the dereferenceable_or_null attribute to the list of
1658  /// attributes.
1659  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
1660 
1661  /// Determine whether this call has the given attribute.
1663  assert(Kind != Attribute::NoBuiltin &&
1664  "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1665  return hasFnAttrImpl(Kind);
1666  }
1667 
1668  /// Determine whether this call has the given attribute.
1669  bool hasFnAttr(StringRef Kind) const {
1670  return hasFnAttrImpl(Kind);
1671  }
1672 
1673  /// Determine whether the call or the callee has the given attributes.
1674  bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const;
1675 
1676  /// Get the attribute of a given kind at a position.
1678  return getAttributes().getAttribute(i, Kind);
1679  }
1680 
1681  /// Get the attribute of a given kind at a position.
1683  return getAttributes().getAttribute(i, Kind);
1684  }
1685 
1686  /// Return true if the data operand at index \p i has the attribute \p
1687  /// A.
1688  ///
1689  /// Data operands include call arguments and values used in operand bundles,
1690  /// but does not include the callee operand. This routine dispatches to the
1691  /// underlying AttributeList or the OperandBundleUser as appropriate.
1692  ///
1693  /// The index \p i is interpreted as
1694  ///
1695  /// \p i == Attribute::ReturnIndex -> the return value
1696  /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
1697  /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
1698  /// (\p i - 1) in the operand list.
1699  bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const;
1700 
1701  /// Extract the alignment for a call or parameter (0=unknown).
1702  unsigned getParamAlignment(unsigned i) const {
1703  return AttributeList.getParamAlignment(i);
1704  }
1705 
1706  /// Extract the number of dereferenceable bytes for a call or
1707  /// parameter (0=unknown).
1708  uint64_t getDereferenceableBytes(unsigned i) const {
1709  return AttributeList.getDereferenceableBytes(i);
1710  }
1711 
1712  /// Extract the number of dereferenceable_or_null bytes for a call or
1713  /// parameter (0=unknown).
1714  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1715  return AttributeList.getDereferenceableOrNullBytes(i);
1716  }
1717 
1718  /// @brief Determine if the parameter or return value is marked with NoAlias
1719  /// attribute.
1720  /// @param n The parameter to check. 1 is the first parameter, 0 is the return
1721  bool doesNotAlias(unsigned n) const {
1722  return AttributeList.hasAttribute(n, Attribute::NoAlias);
1723  }
1724 
1725  /// Return true if the call should not be treated as a call to a
1726  /// builtin.
1727  bool isNoBuiltin() const {
1728  return hasFnAttrImpl(Attribute::NoBuiltin) &&
1729  !hasFnAttrImpl(Attribute::Builtin);
1730  }
1731 
1732  /// Return true if the call should not be inlined.
1733  bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1734  void setIsNoInline() {
1735  addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1736  }
1737 
1738  /// Return true if the call can return twice
1739  bool canReturnTwice() const {
1740  return hasFnAttr(Attribute::ReturnsTwice);
1741  }
1743  addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1744  }
1745 
1746  /// Determine if the call does not access memory.
1747  bool doesNotAccessMemory() const {
1748  return hasFnAttr(Attribute::ReadNone);
1749  }
1751  addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1752  }
1753 
1754  /// Determine if the call does not access or only reads memory.
1755  bool onlyReadsMemory() const {
1757  }
1760  }
1761 
1762  /// Determine if the call does not access or only writes memory.
1763  bool doesNotReadMemory() const {
1765  }
1768  }
1769 
1770  /// @brief Determine if the call can access memmory only using pointers based
1771  /// on its arguments.
1772  bool onlyAccessesArgMemory() const {
1773  return hasFnAttr(Attribute::ArgMemOnly);
1774  }
1776  addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
1777  }
1778 
1779  /// Determine if the call cannot return.
1780  bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1782  addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1783  }
1784 
1785  /// Determine if the call cannot unwind.
1786  bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1788  addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1789  }
1790 
1791  /// Determine if the call cannot be duplicated.
1792  bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1794  addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1795  }
1796 
1797  /// Determine if the call is convergent
1799  void setConvergent() {
1801  }
1804  }
1805 
1806  /// Determine if the call returns a structure through first
1807  /// pointer argument.
1808  bool hasStructRetAttr() const {
1809  if (getNumArgOperands() == 0)
1810  return false;
1811 
1812  // Be friendly and also check the callee.
1813  return paramHasAttr(1, Attribute::StructRet);
1814  }
1815 
1816  /// Determine if any call argument is an aggregate passed by value.
1817  bool hasByValArgument() const {
1818  return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1819  }
1820 
1821  /// Return the function called, or null if this is an
1822  /// indirect function invocation.
1823  ///
1825  return dyn_cast<Function>(Op<-1>());
1826  }
1827 
1828  /// Get a pointer to the function that is invoked by this
1829  /// instruction.
1830  const Value *getCalledValue() const { return Op<-1>(); }
1831  Value *getCalledValue() { return Op<-1>(); }
1832 
1833  /// Set the function called.
1836  cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1837  Fn);
1838  }
1840  this->FTy = FTy;
1841  assert(FTy == cast<FunctionType>(
1842  cast<PointerType>(Fn->getType())->getElementType()));
1843  Op<-1>() = Fn;
1844  }
1845 
1846  /// Check if this call is an inline asm statement.
1847  bool isInlineAsm() const {
1848  return isa<InlineAsm>(Op<-1>());
1849  }
1850 
1851  // Methods for support type inquiry through isa, cast, and dyn_cast:
1852  static inline bool classof(const Instruction *I) {
1853  return I->getOpcode() == Instruction::Call;
1854  }
1855  static inline bool classof(const Value *V) {
1856  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1857  }
1858 
1859 private:
1860  template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
1861  if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind))
1862  return true;
1863 
1864  // Operand bundles override attributes on the called function, but don't
1865  // override attributes directly present on the call instruction.
1866  if (isFnAttrDisallowedByOpBundle(Kind))
1867  return false;
1868 
1869  if (const Function *F = getCalledFunction())
1870  return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind);
1871  return false;
1872  }
1873 
1874  // Shadow Instruction::setInstructionSubclassData with a private forwarding
1875  // method so that subclasses cannot accidentally use it.
1876  void setInstructionSubclassData(unsigned short D) {
1878  }
1879 };
1880 
1881 template <>
1882 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1883 };
1884 
1885 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1886  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1887  BasicBlock *InsertAtEnd)
1888  : Instruction(
1890  ->getElementType())->getReturnType(),
1891  Instruction::Call, OperandTraits<CallInst>::op_end(this) -
1892  (Args.size() + CountBundleInputs(Bundles) + 1),
1893  unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) {
1894  init(Func, Args, Bundles, NameStr);
1895 }
1896 
1897 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1898  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1899  Instruction *InsertBefore)
1900  : Instruction(Ty->getReturnType(), Instruction::Call,
1901  OperandTraits<CallInst>::op_end(this) -
1902  (Args.size() + CountBundleInputs(Bundles) + 1),
1903  unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
1904  InsertBefore) {
1905  init(Ty, Func, Args, Bundles, NameStr);
1906 }
1907 
1908 // Note: if you get compile errors about private methods then
1909 // please update your code to use the high-level operand
1910 // interfaces. See line 943 above.
1911 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1912 
1913 //===----------------------------------------------------------------------===//
1914 // SelectInst Class
1915 //===----------------------------------------------------------------------===//
1916 
1917 /// This class represents the LLVM 'select' instruction.
1918 ///
1919 class SelectInst : public Instruction {
1920  SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1921  Instruction *InsertBefore)
1922  : Instruction(S1->getType(), Instruction::Select,
1923  &Op<0>(), 3, InsertBefore) {
1924  init(C, S1, S2);
1925  setName(NameStr);
1926  }
1927 
1928  SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1929  BasicBlock *InsertAtEnd)
1930  : Instruction(S1->getType(), Instruction::Select,
1931  &Op<0>(), 3, InsertAtEnd) {
1932  init(C, S1, S2);
1933  setName(NameStr);
1934  }
1935 
1936  void init(Value *C, Value *S1, Value *S2) {
1937  assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1938  Op<0>() = C;
1939  Op<1>() = S1;
1940  Op<2>() = S2;
1941  }
1942 
1943 protected:
1944  // Note: Instruction needs to be a friend here to call cloneImpl.
1945  friend class Instruction;
1946 
1947  SelectInst *cloneImpl() const;
1948 
1949 public:
1950  static SelectInst *Create(Value *C, Value *S1, Value *S2,
1951  const Twine &NameStr = "",
1952  Instruction *InsertBefore = nullptr,
1953  Instruction *MDFrom = nullptr) {
1954  SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1955  if (MDFrom)
1956  Sel->copyMetadata(*MDFrom);
1957  return Sel;
1958  }
1959 
1960  static SelectInst *Create(Value *C, Value *S1, Value *S2,
1961  const Twine &NameStr,
1962  BasicBlock *InsertAtEnd) {
1963  return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1964  }
1965 
1966  const Value *getCondition() const { return Op<0>(); }
1967  const Value *getTrueValue() const { return Op<1>(); }
1968  const Value *getFalseValue() const { return Op<2>(); }
1969  Value *getCondition() { return Op<0>(); }
1970  Value *getTrueValue() { return Op<1>(); }
1971  Value *getFalseValue() { return Op<2>(); }
1972 
1973  void setCondition(Value *V) { Op<0>() = V; }
1974  void setTrueValue(Value *V) { Op<1>() = V; }
1975  void setFalseValue(Value *V) { Op<2>() = V; }
1976 
1977  /// Return a string if the specified operands are invalid
1978  /// for a select operation, otherwise return null.
1979  static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1980 
1981  /// Transparently provide more efficient getOperand methods.
1983 
1985  return static_cast<OtherOps>(Instruction::getOpcode());
1986  }
1987 
1988  // Methods for support type inquiry through isa, cast, and dyn_cast:
1989  static inline bool classof(const Instruction *I) {
1990  return I->getOpcode() == Instruction::Select;
1991  }
1992  static inline bool classof(const Value *V) {
1993  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1994  }
1995 };
1996 
1997 template <>
1998 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1999 };
2000 
2002 
2003 //===----------------------------------------------------------------------===//
2004 // VAArgInst Class
2005 //===----------------------------------------------------------------------===//
2006 
2007 /// This class represents the va_arg llvm instruction, which returns
2008 /// an argument of the specified type given a va_list and increments that list
2009 ///
2010 class VAArgInst : public UnaryInstruction {
2011 protected:
2012  // Note: Instruction needs to be a friend here to call cloneImpl.
2013  friend class Instruction;
2014 
2015  VAArgInst *cloneImpl() const;
2016 
2017 public:
2018  VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
2019  Instruction *InsertBefore = nullptr)
2020  : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
2021  setName(NameStr);
2022  }
2023 
2024  VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
2025  BasicBlock *InsertAtEnd)
2026  : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
2027  setName(NameStr);
2028  }
2029 
2030  Value *getPointerOperand() { return getOperand(0); }
2031  const Value *getPointerOperand() const { return getOperand(0); }
2032  static unsigned getPointerOperandIndex() { return 0U; }
2033 
2034  // Methods for support type inquiry through isa, cast, and dyn_cast:
2035  static inline bool classof(const Instruction *I) {
2036  return I->getOpcode() == VAArg;
2037  }
2038  static inline bool classof(const Value *V) {
2039  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2040  }
2041 };
2042 
2043 //===----------------------------------------------------------------------===//
2044 // ExtractElementInst Class
2045 //===----------------------------------------------------------------------===//
2046 
2047 /// This instruction extracts a single (scalar)
2048 /// element from a VectorType value
2049 ///
2051  ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
2052  Instruction *InsertBefore = nullptr);
2053  ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
2054  BasicBlock *InsertAtEnd);
2055 
2056 protected:
2057  // Note: Instruction needs to be a friend here to call cloneImpl.
2058  friend class Instruction;
2059 
2060  ExtractElementInst *cloneImpl() const;
2061 
2062 public:
2063  static ExtractElementInst *Create(Value *Vec, Value *Idx,
2064  const Twine &NameStr = "",
2065  Instruction *InsertBefore = nullptr) {
2066  return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
2067  }
2068 
2069  static ExtractElementInst *Create(Value *Vec, Value *Idx,
2070  const Twine &NameStr,
2071  BasicBlock *InsertAtEnd) {
2072  return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
2073  }
2074 
2075  /// Return true if an extractelement instruction can be
2076  /// formed with the specified operands.
2077  static bool isValidOperands(const Value *Vec, const Value *Idx);
2078 
2079  Value *getVectorOperand() { return Op<0>(); }
2080  Value *getIndexOperand() { return Op<1>(); }
2081  const Value *getVectorOperand() const { return Op<0>(); }
2082  const Value *getIndexOperand() const { return Op<1>(); }
2083 
2085  return cast<VectorType>(getVectorOperand()->getType());
2086  }
2087 
2088  /// Transparently provide more efficient getOperand methods.
2090 
2091  // Methods for support type inquiry through isa, cast, and dyn_cast:
2092  static inline bool classof(const Instruction *I) {
2093  return I->getOpcode() == Instruction::ExtractElement;
2094  }
2095  static inline bool classof(const Value *V) {
2096  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2097  }
2098 };
2099 
2100 template <>
2102  public FixedNumOperandTraits<ExtractElementInst, 2> {
2103 };
2104 
2106 
2107 //===----------------------------------------------------------------------===//
2108 // InsertElementInst Class
2109 //===----------------------------------------------------------------------===//
2110 
2111 /// This instruction inserts a single (scalar)
2112 /// element into a VectorType value
2113 ///
2115  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
2116  const Twine &NameStr = "",
2117  Instruction *InsertBefore = nullptr);
2118  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
2119  BasicBlock *InsertAtEnd);
2120 
2121 protected:
2122  // Note: Instruction needs to be a friend here to call cloneImpl.
2123  friend class Instruction;
2124 
2125  InsertElementInst *cloneImpl() const;
2126 
2127 public:
2128  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2129  const Twine &NameStr = "",
2130  Instruction *InsertBefore = nullptr) {
2131  return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
2132  }
2133 
2134  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2135  const Twine &NameStr,
2136  BasicBlock *InsertAtEnd) {
2137  return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
2138  }
2139 
2140  /// Return true if an insertelement instruction can be
2141  /// formed with the specified operands.
2142  static bool isValidOperands(const Value *Vec, const Value *NewElt,
2143  const Value *Idx);
2144 
2145  /// Overload to return most specific vector type.
2146  ///
2147  VectorType *getType() const {
2148  return cast<VectorType>(Instruction::getType());
2149  }
2150 
2151  /// Transparently provide more efficient getOperand methods.
2153 
2154  // Methods for support type inquiry through isa, cast, and dyn_cast:
2155  static inline bool classof(const Instruction *I) {
2156  return I->getOpcode() == Instruction::InsertElement;
2157  }
2158  static inline bool classof(const Value *V) {
2159  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2160  }
2161 };
2162 
2163 template <>
2165  public FixedNumOperandTraits<InsertElementInst, 3> {
2166 };
2167 
2169 
2170 //===----------------------------------------------------------------------===//
2171 // ShuffleVectorInst Class
2172 //===----------------------------------------------------------------------===//
2173 
2174 /// This instruction constructs a fixed permutation of two
2175 /// input vectors.
2176 ///
2178 protected:
2179  // Note: Instruction needs to be a friend here to call cloneImpl.
2180  friend class Instruction;
2181 
2182  ShuffleVectorInst *cloneImpl() const;
2183 
2184 public:
2186  const Twine &NameStr = "",
2187  Instruction *InsertBefor = nullptr);
2189  const Twine &NameStr, BasicBlock *InsertAtEnd);
2190 
2191  // allocate space for exactly three operands
2192  void *operator new(size_t s) {
2193  return User::operator new(s, 3);
2194  }
2195 
2196  /// Return true if a shufflevector instruction can be
2197  /// formed with the specified operands.
2198  static bool isValidOperands(const Value *V1, const Value *V2,
2199  const Value *Mask);
2200 
2201  /// Overload to return most specific vector type.
2202  ///
2203  VectorType *getType() const {
2204  return cast<VectorType>(Instruction::getType());
2205  }
2206 
2207  /// Transparently provide more efficient getOperand methods.
2209 
2210  Constant *getMask() const {
2211  return cast<Constant>(getOperand(2));
2212  }
2213 
2214  /// Return the shuffle mask value for the specified element of the mask.
2215  /// Return -1 if the element is undef.
2216  static int getMaskValue(Constant *Mask, unsigned Elt);
2217 
2218  /// Return the shuffle mask value of this instruction for the given element
2219  /// index. Return -1 if the element is undef.
2220  int getMaskValue(unsigned Elt) const {
2221  return getMaskValue(getMask(), Elt);
2222  }
2223 
2224  /// Convert the input shuffle mask operand to a vector of integers. Undefined
2225  /// elements of the mask are returned as -1.
2226  static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
2227 
2228  /// Return the mask for this instruction as a vector of integers. Undefined
2229  /// elements of the mask are returned as -1.
2230  void getShuffleMask(SmallVectorImpl<int> &Result) const {
2231  return getShuffleMask(getMask(), Result);
2232  }
2233 
2236  getShuffleMask(Mask);
2237  return Mask;
2238  }
2239 
2240  // Methods for support type inquiry through isa, cast, and dyn_cast:
2241  static inline bool classof(const Instruction *I) {
2242  return I->getOpcode() == Instruction::ShuffleVector;
2243  }
2244  static inline bool classof(const Value *V) {
2245  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2246  }
2247 };
2248 
2249 template <>
2251  public FixedNumOperandTraits<ShuffleVectorInst, 3> {
2252 };
2253 
2255 
2256 //===----------------------------------------------------------------------===//
2257 // ExtractValueInst Class
2258 //===----------------------------------------------------------------------===//
2259 
2260 /// This instruction extracts a struct member or array
2261 /// element value from an aggregate value.
2262 ///
2264  SmallVector<unsigned, 4> Indices;
2265 
2266  ExtractValueInst(const ExtractValueInst &EVI);
2267  /// Constructors - Create a extractvalue instruction with a base aggregate
2268  /// value and a list of indices. The first ctor can optionally insert before
2269  /// an existing instruction, the second appends the new instruction to the
2270  /// specified BasicBlock.
2271  inline ExtractValueInst(Value *Agg,
2272  ArrayRef<unsigned> Idxs,
2273  const Twine &NameStr,
2274  Instruction *InsertBefore);
2275  inline ExtractValueInst(Value *Agg,
2276  ArrayRef<unsigned> Idxs,
2277  const Twine &NameStr, BasicBlock *InsertAtEnd);
2278 
2279  // allocate space for exactly one operand
2280  void *operator new(size_t s) { return User::operator new(s, 1); }
2281 
2282  void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2283 
2284 protected:
2285  // Note: Instruction needs to be a friend here to call cloneImpl.
2286  friend class Instruction;
2287 
2288  ExtractValueInst *cloneImpl() const;
2289 
2290 public:
2292  ArrayRef<unsigned> Idxs,
2293  const Twine &NameStr = "",
2294  Instruction *InsertBefore = nullptr) {
2295  return new
2296  ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2297  }
2298 
2300  ArrayRef<unsigned> Idxs,
2301  const Twine &NameStr,
2302  BasicBlock *InsertAtEnd) {
2303  return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2304  }
2305 
2306  /// Returns the type of the element that would be extracted
2307  /// with an extractvalue instruction with the specified parameters.
2308  ///
2309  /// Null is returned if the indices are invalid for the specified type.
2310  static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2311 
2312  typedef const unsigned* idx_iterator;
2313  inline idx_iterator idx_begin() const { return Indices.begin(); }
2314  inline idx_iterator idx_end() const { return Indices.end(); }
2316  return make_range(idx_begin(), idx_end());
2317  }
2318 
2320  return getOperand(0);
2321  }
2322  const Value *getAggregateOperand() const {
2323  return getOperand(0);
2324  }
2325  static unsigned getAggregateOperandIndex() {
2326  return 0U; // get index for modifying correct operand
2327  }
2328 
2330  return Indices;
2331  }
2332 
2333  unsigned getNumIndices() const {
2334  return (unsigned)Indices.size();
2335  }
2336 
2337  bool hasIndices() const {
2338  return true;
2339  }
2340 
2341  // Methods for support type inquiry through isa, cast, and dyn_cast:
2342  static inline bool classof(const Instruction *I) {
2343  return I->getOpcode() == Instruction::ExtractValue;
2344  }
2345  static inline bool classof(const Value *V) {
2346  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2347  }
2348 };
2349 
2350 ExtractValueInst::ExtractValueInst(Value *Agg,
2351  ArrayRef<unsigned> Idxs,
2352  const Twine &NameStr,
2353  Instruction *InsertBefore)
2354  : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2355  ExtractValue, Agg, InsertBefore) {
2356  init(Idxs, NameStr);
2357 }
2358 
2359 ExtractValueInst::ExtractValueInst(Value *Agg,
2360  ArrayRef<unsigned> Idxs,
2361  const Twine &NameStr,
2362  BasicBlock *InsertAtEnd)
2363  : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2364  ExtractValue, Agg, InsertAtEnd) {
2365  init(Idxs, NameStr);
2366 }
2367 
2368 //===----------------------------------------------------------------------===//
2369 // InsertValueInst Class
2370 //===----------------------------------------------------------------------===//
2371 
2372 /// This instruction inserts a struct field of array element
2373 /// value into an aggregate value.
2374 ///
2376  SmallVector<unsigned, 4> Indices;
2377 
2378  InsertValueInst(const InsertValueInst &IVI);
2379 
2380  /// Constructors - Create a insertvalue instruction with a base aggregate
2381  /// value, a value to insert, and a list of indices. The first ctor can
2382  /// optionally insert before an existing instruction, the second appends
2383  /// the new instruction to the specified BasicBlock.
2384  inline InsertValueInst(Value *Agg, Value *Val,
2385  ArrayRef<unsigned> Idxs,
2386  const Twine &NameStr,
2387  Instruction *InsertBefore);
2388  inline InsertValueInst(Value *Agg, Value *Val,
2389  ArrayRef<unsigned> Idxs,
2390  const Twine &NameStr, BasicBlock *InsertAtEnd);
2391 
2392  /// Constructors - These two constructors are convenience methods because one
2393  /// and two index insertvalue instructions are so common.
2394  InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2395  const Twine &NameStr = "",
2396  Instruction *InsertBefore = nullptr);
2397  InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
2398  BasicBlock *InsertAtEnd);
2399 
2400  void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2401  const Twine &NameStr);
2402 
2403 protected:
2404  // Note: Instruction needs to be a friend here to call cloneImpl.
2405  friend class Instruction;
2406 
2407  InsertValueInst *cloneImpl() const;
2408 
2409 public:
2410  // allocate space for exactly two operands
2411  void *operator new(size_t s) {
2412  return User::operator new(s, 2);
2413  }
2414 
2415  void *operator new(size_t, unsigned) = delete;
2416 
2417  static InsertValueInst *Create(Value *Agg, Value *Val,
2418  ArrayRef<unsigned> Idxs,
2419  const Twine &NameStr = "",
2420  Instruction *InsertBefore = nullptr) {
2421  return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2422  }
2423 
2424  static InsertValueInst *Create(Value *Agg, Value *Val,
2425  ArrayRef<unsigned> Idxs,
2426  const Twine &NameStr,
2427  BasicBlock *InsertAtEnd) {
2428  return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2429  }
2430 
2431  /// Transparently provide more efficient getOperand methods.
2433 
2434  typedef const unsigned* idx_iterator;
2435  inline idx_iterator idx_begin() const { return Indices.begin(); }
2436  inline idx_iterator idx_end() const { return Indices.end(); }
2438  return make_range(idx_begin(), idx_end());
2439  }
2440 
2442  return getOperand(0);
2443  }
2444  const Value *getAggregateOperand() const {
2445  return getOperand(0);
2446  }
2447  static unsigned getAggregateOperandIndex() {
2448  return 0U; // get index for modifying correct operand
2449  }
2450 
2452  return getOperand(1);
2453  }
2455  return getOperand(1);
2456  }
2457  static unsigned getInsertedValueOperandIndex() {
2458  return 1U; // get index for modifying correct operand
2459  }
2460 
2462  return Indices;
2463  }
2464 
2465  unsigned getNumIndices() const {
2466  return (unsigned)Indices.size();
2467  }
2468 
2469  bool hasIndices() const {
2470  return true;
2471  }
2472 
2473  // Methods for support type inquiry through isa, cast, and dyn_cast:
2474  static inline bool classof(const Instruction *I) {
2475  return I->getOpcode() == Instruction::InsertValue;
2476  }
2477  static inline bool classof(const Value *V) {
2478  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2479  }
2480 };
2481 
2482 template <>
2484  public FixedNumOperandTraits<InsertValueInst, 2> {
2485 };
2486 
2487 InsertValueInst::InsertValueInst(Value *Agg,
2488  Value *Val,
2489  ArrayRef<unsigned> Idxs,
2490  const Twine &NameStr,
2491  Instruction *InsertBefore)
2492  : Instruction(Agg->getType(), InsertValue,
2493  OperandTraits<InsertValueInst>::op_begin(this),
2494  2, InsertBefore) {
2495  init(Agg, Val, Idxs, NameStr);
2496 }
2497 
2498 InsertValueInst::InsertValueInst(Value *Agg,
2499  Value *Val,
2500  ArrayRef<unsigned> Idxs,
2501  const Twine &NameStr,
2502  BasicBlock *InsertAtEnd)
2503  : Instruction(Agg->getType(), InsertValue,
2504  OperandTraits<InsertValueInst>::op_begin(this),
2505  2, InsertAtEnd) {
2506  init(Agg, Val, Idxs, NameStr);
2507 }
2508 
2509 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2510 
2511 //===----------------------------------------------------------------------===//
2512 // PHINode Class
2513 //===----------------------------------------------------------------------===//
2514 
2515 // PHINode - The PHINode class is used to represent the magical mystical PHI
2516 // node, that can not exist in nature, but can be synthesized in a computer
2517 // scientist's overactive imagination.
2518 //
2519 class PHINode : public Instruction {
2520  /// The number of operands actually allocated. NumOperands is
2521  /// the number actually in use.
2522  unsigned ReservedSpace;
2523 
2524  PHINode(const PHINode &PN);
2525  // allocate space for exactly zero operands
2526 
2527  explicit PHINode(Type *Ty, unsigned NumReservedValues,
2528  const Twine &NameStr = "",
2529  Instruction *InsertBefore = nullptr)
2530  : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2531  ReservedSpace(NumReservedValues) {
2532  setName(NameStr);
2533  allocHungoffUses(ReservedSpace);
2534  }
2535 
2536  PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2537  BasicBlock *InsertAtEnd)
2538  : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2539  ReservedSpace(NumReservedValues) {
2540  setName(NameStr);
2541  allocHungoffUses(ReservedSpace);
2542  }
2543 
2544  void *operator new(size_t s) {
2545  return User::operator new(s);
2546  }
2547 
2548  void anchor() override;
2549 
2550 protected:
2551  // Note: Instruction needs to be a friend here to call cloneImpl.
2552  friend class Instruction;
2553 
2554  PHINode *cloneImpl() const;
2555 
2556  // allocHungoffUses - this is more complicated than the generic
2557  // User::allocHungoffUses, because we have to allocate Uses for the incoming
2558  // values and pointers to the incoming blocks, all in one allocation.
2559  void allocHungoffUses(unsigned N) {
2560  User::allocHungoffUses(N, /* IsPhi */ true);
2561  }
2562 
2563 public:
2564  void *operator new(size_t, unsigned) = delete;
2565 
2566  /// Constructors - NumReservedValues is a hint for the number of incoming
2567  /// edges that this phi node will have (use 0 if you really have no idea).
2568  static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2569  const Twine &NameStr = "",
2570  Instruction *InsertBefore = nullptr) {
2571  return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2572  }
2573 
2574  static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2575  const Twine &NameStr, BasicBlock *InsertAtEnd) {
2576  return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2577  }
2578 
2579  /// Provide fast operand accessors
2581 
2582  // Block iterator interface. This provides access to the list of incoming
2583  // basic blocks, which parallels the list of incoming values.
2584 
2587 
2588  block_iterator block_begin() {
2589  Use::UserRef *ref =
2590  reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2591  return reinterpret_cast<block_iterator>(ref + 1);
2592  }
2593 
2594  const_block_iterator block_begin() const {
2595  const Use::UserRef *ref =
2596  reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2597  return reinterpret_cast<const_block_iterator>(ref + 1);
2598  }
2599 
2600  block_iterator block_end() {
2601  return block_begin() + getNumOperands();
2602  }
2603 
2604  const_block_iterator block_end() const {
2605  return block_begin() + getNumOperands();
2606  }
2607 
2609  return make_range(block_begin(), block_end());
2610  }
2611 
2613  return make_range(block_begin(), block_end());
2614  }
2615 
2616  op_range incoming_values() { return operands(); }
2617 
2618  const_op_range incoming_values() const { return operands(); }
2619 
2620  /// Return the number of incoming edges
2621  ///
2622  unsigned getNumIncomingValues() const { return getNumOperands(); }
2623 
2624  /// Return incoming value number x
2625  ///
2626  Value *getIncomingValue(unsigned i) const {
2627  return getOperand(i);
2628  }
2629  void setIncomingValue(unsigned i, Value *V) {
2630  assert(V && "PHI node got a null value!");
2631  assert(getType() == V->getType() &&
2632  "All operands to PHI node must be the same type as the PHI node!");
2633  setOperand(i, V);
2634  }
2635  static unsigned getOperandNumForIncomingValue(unsigned i) {
2636  return i;
2637  }
2638  static unsigned getIncomingValueNumForOperand(unsigned i) {
2639  return i;
2640  }
2641 
2642  /// Return incoming basic block number @p i.
2643  ///
2644  BasicBlock *getIncomingBlock(unsigned i) const {
2645  return block_begin()[i];
2646  }
2647 
2648  /// Return incoming basic block corresponding
2649  /// to an operand of the PHI.
2650  ///
2651  BasicBlock *getIncomingBlock(const Use &U) const {
2652  assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2653  return getIncomingBlock(unsigned(&U - op_begin()));
2654  }
2655 
2656  /// Return incoming basic block corresponding
2657  /// to value use iterator.
2658  ///
2660  return getIncomingBlock(I.getUse());
2661  }
2662 
2663  void setIncomingBlock(unsigned i, BasicBlock *BB) {
2664  assert(BB && "PHI node got a null basic block!");
2665  block_begin()[i] = BB;
2666  }
2667 
2668  /// Add an incoming value to the end of the PHI list
2669  ///
2670  void addIncoming(Value *V, BasicBlock *BB) {
2671  if (getNumOperands() == ReservedSpace)
2672  growOperands(); // Get more space!
2673  // Initialize some new operands.
2674  setNumHungOffUseOperands(getNumOperands() + 1);
2675  setIncomingValue(getNumOperands() - 1, V);
2676  setIncomingBlock(getNumOperands() - 1, BB);
2677  }
2678 
2679  /// Remove an incoming value. This is useful if a
2680  /// predecessor basic block is deleted. The value removed is returned.
2681  ///
2682  /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2683  /// is true), the PHI node is destroyed and any uses of it are replaced with
2684  /// dummy values. The only time there should be zero incoming values to a PHI
2685  /// node is when the block is dead, so this strategy is sound.
2686  ///
2687  Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2688 
2689  Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2690  int Idx = getBasicBlockIndex(BB);
2691  assert(Idx >= 0 && "Invalid basic block argument to remove!");
2692  return removeIncomingValue(Idx, DeletePHIIfEmpty);
2693  }
2694 
2695  /// Return the first index of the specified basic
2696  /// block in the value list for this PHI. Returns -1 if no instance.
2697  ///
2698  int getBasicBlockIndex(const BasicBlock *BB) const {
2699  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2700  if (block_begin()[i] == BB)
2701  return i;
2702  return -1;
2703  }
2704 
2706  int Idx = getBasicBlockIndex(BB);
2707  assert(Idx >= 0 && "Invalid basic block argument!");
2708  return getIncomingValue(Idx);
2709  }
2710 
2711  /// If the specified PHI node always merges together the
2712  /// same value, return the value, otherwise return null.
2713  Value *hasConstantValue() const;
2714 
2715  /// Whether the specified PHI node always merges
2716  /// together the same value, assuming undefs are equal to a unique
2717  /// non-undef value.
2718  bool hasConstantOrUndefValue() const;
2719 
2720  /// Methods for support type inquiry through isa, cast, and dyn_cast:
2721  static inline bool classof(const Instruction *I) {
2722  return I->getOpcode() == Instruction::PHI;
2723  }
2724  static inline bool classof(const Value *V) {
2725  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2726  }
2727 
2728 private:
2729  void growOperands();
2730 };
2731 
2732 template <>
2734 };
2735 
2737 
2738 //===----------------------------------------------------------------------===//
2739 // LandingPadInst Class
2740 //===----------------------------------------------------------------------===//
2741 
2742 //===---------------------------------------------------------------------------
2743 /// The landingpad instruction holds all of the information
2744 /// necessary to generate correct exception handling. The landingpad instruction
2745 /// cannot be moved from the top of a landing pad block, which itself is
2746 /// accessible only from the 'unwind' edge of an invoke. This uses the
2747 /// SubclassData field in Value to store whether or not the landingpad is a
2748 /// cleanup.
2749 ///
2750 class LandingPadInst : public Instruction {
2751  /// The number of operands actually allocated. NumOperands is
2752  /// the number actually in use.
2753  unsigned ReservedSpace;
2754 
2755  LandingPadInst(const LandingPadInst &LP);
2756 
2757 public:
2759 
2760 private:
2761  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2762  const Twine &NameStr, Instruction *InsertBefore);
2763  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2764  const Twine &NameStr, BasicBlock *InsertAtEnd);
2765 
2766  // Allocate space for exactly zero operands.
2767  void *operator new(size_t s) {
2768  return User::operator new(s);
2769  }
2770 
2771  void growOperands(unsigned Size);
2772  void init(unsigned NumReservedValues, const Twine &NameStr);
2773 
2774 protected:
2775  // Note: Instruction needs to be a friend here to call cloneImpl.
2776  friend class Instruction;
2777 
2778  LandingPadInst *cloneImpl() const;
2779 
2780 public:
2781  void *operator new(size_t, unsigned) = delete;
2782 
2783  /// Constructors - NumReservedClauses is a hint for the number of incoming
2784  /// clauses that this landingpad will have (use 0 if you really have no idea).
2785  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2786  const Twine &NameStr = "",
2787  Instruction *InsertBefore = nullptr);
2788  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2789  const Twine &NameStr, BasicBlock *InsertAtEnd);
2790 
2791  /// Provide fast operand accessors
2793 
2794  /// Return 'true' if this landingpad instruction is a
2795  /// cleanup. I.e., it should be run when unwinding even if its landing pad
2796  /// doesn't catch the exception.
2797  bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2798 
2799  /// Indicate that this landingpad instruction is a cleanup.
2800  void setCleanup(bool V) {
2801  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2802  (V ? 1 : 0));
2803  }
2804 
2805  /// Add a catch or filter clause to the landing pad.
2806  void addClause(Constant *ClauseVal);
2807 
2808  /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2809  /// determine what type of clause this is.
2810  Constant *getClause(unsigned Idx) const {
2811  return cast<Constant>(getOperandList()[Idx]);
2812  }
2813 
2814  /// Return 'true' if the clause and index Idx is a catch clause.
2815  bool isCatch(unsigned Idx) const {
2816  return !isa<ArrayType>(getOperandList()[Idx]->getType());
2817  }
2818 
2819  /// Return 'true' if the clause and index Idx is a filter clause.
2820  bool isFilter(unsigned Idx) const {
2821  return isa<ArrayType>(getOperandList()[Idx]->getType());
2822  }
2823 
2824  /// Get the number of clauses for this landing pad.
2825  unsigned getNumClauses() const { return getNumOperands(); }
2826 
2827  /// Grow the size of the operand list to accommodate the new
2828  /// number of clauses.
2829  void reserveClauses(unsigned Size) { growOperands(Size); }
2830 
2831  // Methods for support type inquiry through isa, cast, and dyn_cast:
2832  static inline bool classof(const Instruction *I) {
2833  return I->getOpcode() == Instruction::LandingPad;
2834  }
2835  static inline bool classof(const Value *V) {
2836  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2837  }
2838 };
2839 
2840 template <>
2842 };
2843 
2845 
2846 //===----------------------------------------------------------------------===//
2847 // ReturnInst Class
2848 //===----------------------------------------------------------------------===//
2849 
2850 //===---------------------------------------------------------------------------
2851 /// Return a value (possibly void), from a function. Execution
2852 /// does not continue in this function any longer.
2853 ///
2854 class ReturnInst : public TerminatorInst {
2855  ReturnInst(const ReturnInst &RI);
2856 
2857 private:
2858  // ReturnInst constructors:
2859  // ReturnInst() - 'ret void' instruction
2860  // ReturnInst( null) - 'ret void' instruction
2861  // ReturnInst(Value* X) - 'ret X' instruction
2862  // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2863  // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2864  // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2865  // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2866  //
2867  // NOTE: If the Value* passed is of type void then the constructor behaves as
2868  // if it was passed NULL.
2869  explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2870  Instruction *InsertBefore = nullptr);
2871  ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2872  explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2873 
2874 protected:
2875  // Note: Instruction needs to be a friend here to call cloneImpl.
2876  friend class Instruction;
2877 
2878  ReturnInst *cloneImpl() const;
2879 
2880 public:
2881  ~ReturnInst() override;
2882 
2883  static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2884  Instruction *InsertBefore = nullptr) {
2885  return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2886  }
2887 
2888  static ReturnInst* Create(LLVMContext &C, Value *retVal,
2889  BasicBlock *InsertAtEnd) {
2890  return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2891  }
2892 
2893  static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2894  return new(0) ReturnInst(C, InsertAtEnd);
2895  }
2896 
2897  /// Provide fast operand accessors
2899 
2900  /// Convenience accessor. Returns null if there is no return value.
2902  return getNumOperands() != 0 ? getOperand(0) : nullptr;
2903  }
2904 
2905  unsigned getNumSuccessors() const { return 0; }
2906 
2907  // Methods for support type inquiry through isa, cast, and dyn_cast:
2908  static inline bool classof(const Instruction *I) {
2909  return (I->getOpcode() == Instruction::Ret);
2910  }
2911  static inline bool classof(const Value *V) {
2912  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2913  }
2914 
2915 private:
2916  BasicBlock *getSuccessorV(unsigned idx) const override;
2917  unsigned getNumSuccessorsV() const override;
2918  void setSuccessorV(unsigned idx, BasicBlock *B) override;
2919 };
2920 
2921 template <>
2922 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2923 };
2924 
2926 
2927 //===----------------------------------------------------------------------===//
2928 // BranchInst Class
2929 //===----------------------------------------------------------------------===//
2930 
2931 //===---------------------------------------------------------------------------
2932 /// Conditional or Unconditional Branch instruction.
2933 ///
2934 class BranchInst : public TerminatorInst {
2935  /// Ops list - Branches are strange. The operands are ordered:
2936  /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2937  /// they don't have to check for cond/uncond branchness. These are mostly
2938  /// accessed relative from op_end().
2939  BranchInst(const BranchInst &BI);
2940  // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2941  // BranchInst(BB *B) - 'br B'
2942  // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2943  // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2944  // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2945  // BranchInst(BB* B, BB *I) - 'br B' insert at end
2946  // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2947  explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2948  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2949  Instruction *InsertBefore = nullptr);
2950  BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2951  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2952  BasicBlock *InsertAtEnd);
2953 
2954  void AssertOK();
2955 
2956 protected:
2957  // Note: Instruction needs to be a friend here to call cloneImpl.
2958  friend class Instruction;
2959 
2960  BranchInst *cloneImpl() const;
2961 
2962 public:
2963  static BranchInst *Create(BasicBlock *IfTrue,
2964  Instruction *InsertBefore = nullptr) {
2965  return new(1) BranchInst(IfTrue, InsertBefore);
2966  }
2967 
2968  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2969  Value *Cond, Instruction *InsertBefore = nullptr) {
2970  return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2971  }
2972 
2973  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2974  return new(1) BranchInst(IfTrue, InsertAtEnd);
2975  }
2976 
2977  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2978  Value *Cond, BasicBlock *InsertAtEnd) {
2979  return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2980  }
2981 
2982  /// Transparently provide more efficient getOperand methods.
2984 
2985  bool isUnconditional() const { return getNumOperands() == 1; }
2986  bool isConditional() const { return getNumOperands() == 3; }
2987 
2988  Value *getCondition() const {
2989  assert(isConditional() && "Cannot get condition of an uncond branch!");
2990  return Op<-3>();
2991  }
2992 
2993  void setCondition(Value *V) {
2994  assert(isConditional() && "Cannot set condition of unconditional branch!");
2995  Op<-3>() = V;
2996  }
2997 
2998  unsigned getNumSuccessors() const { return 1+isConditional(); }
2999 
3000  BasicBlock *getSuccessor(unsigned i) const {
3001  assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
3002  return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
3003  }
3004 
3005  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3006  assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
3007  *(&Op<-1>() - idx) = NewSucc;
3008  }
3009 
3010  /// Swap the successors of this branch instruction.
3011  ///
3012  /// Swaps the successors of the branch instruction. This also swaps any
3013  /// branch weight metadata associated with the instruction so that it
3014  /// continues to map correctly to each operand.
3015  void swapSuccessors();
3016 
3017  // Methods for support type inquiry through isa, cast, and dyn_cast:
3018  static inline bool classof(const Instruction *I) {
3019  return (I->getOpcode() == Instruction::Br);
3020  }
3021  static inline bool classof(const Value *V) {
3022  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3023  }
3024 
3025 private:
3026  BasicBlock *getSuccessorV(unsigned idx) const override;
3027  unsigned getNumSuccessorsV() const override;
3028  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3029 };
3030 
3031 template <>
3032 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
3033 };
3034 
3036 
3037 //===----------------------------------------------------------------------===//
3038 // SwitchInst Class
3039 //===----------------------------------------------------------------------===//
3040 
3041 //===---------------------------------------------------------------------------
3042 /// Multiway switch
3043 ///
3044 class SwitchInst : public TerminatorInst {
3045  unsigned ReservedSpace;
3046 
3047  // Operand[0] = Value to switch on
3048  // Operand[1] = Default basic block destination
3049  // Operand[2n ] = Value to match
3050  // Operand[2n+1] = BasicBlock to go to on match
3051  SwitchInst(const SwitchInst &SI);
3052 
3053  /// Create a new switch instruction, specifying a value to switch on and a
3054  /// default destination. The number of additional cases can be specified here
3055  /// to make memory allocation more efficient. This constructor can also
3056  /// auto-insert before another instruction.
3057  SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3058  Instruction *InsertBefore);
3059 
3060  /// Create a new switch instruction, specifying a value to switch on and a
3061  /// default destination. The number of additional cases can be specified here
3062  /// to make memory allocation more efficient. This constructor also
3063  /// auto-inserts at the end of the specified BasicBlock.
3064  SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3065  BasicBlock *InsertAtEnd);
3066 
3067  // allocate space for exactly zero operands
3068  void *operator new(size_t s) {
3069  return User::operator new(s);
3070  }
3071 
3072  void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
3073  void growOperands();
3074 
3075 protected:
3076  // Note: Instruction needs to be a friend here to call cloneImpl.
3077  friend class Instruction;
3078 
3079  SwitchInst *cloneImpl() const;
3080 
3081 public:
3082  void *operator new(size_t, unsigned) = delete;
3083 
3084  // -2
3085  static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
3086 
3087  template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
3089  protected:
3090  SwitchInstTy *SI;
3091  unsigned Index;
3092 
3093  public:
3095 
3096  /// Initializes case iterator for given SwitchInst and for given
3097  /// case number.
3098  CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
3099  this->SI = SI;
3100  Index = CaseNum;
3101  }
3102 
3103  /// Initializes case iterator for given SwitchInst and for given
3104  /// TerminatorInst's successor index.
3105  static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
3106  assert(SuccessorIndex < SI->getNumSuccessors() &&
3107  "Successor index # out of range!");
3108  return SuccessorIndex != 0 ?
3109  Self(SI, SuccessorIndex - 1) :
3110  Self(SI, DefaultPseudoIndex);
3111  }
3112 
3113  /// Resolves case value for current case.
3114  ConstantIntTy *getCaseValue() {
3115  assert(Index < SI->getNumCases() && "Index out the number of cases.");
3116  return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
3117  }
3118 
3119  /// Resolves successor for current case.
3120  BasicBlockTy *getCaseSuccessor() {
3121  assert((Index < SI->getNumCases() ||
3122  Index == DefaultPseudoIndex) &&
3123  "Index out the number of cases.");
3124  return SI->getSuccessor(getSuccessorIndex());
3125  }
3126 
3127  /// Returns number of current case.
3128  unsigned getCaseIndex() const { return Index; }
3129 
3130  /// Returns TerminatorInst's successor index for current case successor.
3131  unsigned getSuccessorIndex() const {
3132  assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
3133  "Index out the number of cases.");
3134  return Index != DefaultPseudoIndex ? Index + 1 : 0;
3135  }
3136 
3138  // Check index correctness after increment.
3139  // Note: Index == getNumCases() means end().
3140  assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
3141  ++Index;
3142  return *this;
3143  }
3145  Self tmp = *this;
3146  ++(*this);
3147  return tmp;
3148  }
3150  // Check index correctness after decrement.
3151  // Note: Index == getNumCases() means end().
3152  // Also allow "-1" iterator here. That will became valid after ++.
3153  assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
3154  "Index out the number of cases.");
3155  --Index;
3156  return *this;
3157  }
3159  Self tmp = *this;
3160  --(*this);
3161  return tmp;
3162  }
3163  bool operator==(const Self& RHS) const {
3164  assert(RHS.SI == SI && "Incompatible operators.");
3165  return RHS.Index == Index;
3166  }
3167  bool operator!=(const Self& RHS) const {
3168  assert(RHS.SI == SI && "Incompatible operators.");
3169  return RHS.Index != Index;
3170  }
3172  return *this;
3173  }
3174  };
3175 
3176  typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
3178 
3179  class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
3181 
3182  public:
3183  CaseIt(const ParentTy &Src) : ParentTy(Src) {}
3184  CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
3185 
3186  /// Sets the new value for current case.
3188  assert(Index < SI->getNumCases() && "Index out the number of cases.");
3189  SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
3190  }
3191 
3192  /// Sets the new successor for current case.
3194  SI->setSuccessor(getSuccessorIndex(), S);
3195  }
3196  };
3197 
3198  static SwitchInst *Create(Value *Value, BasicBlock *Default,
3199  unsigned NumCases,
3200  Instruction *InsertBefore = nullptr) {
3201  return new SwitchInst(Value, Default, NumCases, InsertBefore);
3202  }
3203 
3204  static SwitchInst *Create(Value *Value, BasicBlock *Default,
3205  unsigned NumCases, BasicBlock *InsertAtEnd) {
3206  return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
3207  }
3208 
3209  /// Provide fast operand accessors
3211 
3212  // Accessor Methods for Switch stmt
3213  Value *getCondition() const { return getOperand(0); }
3214  void setCondition(Value *V) { setOperand(0, V); }
3215 
3217  return cast<BasicBlock>(getOperand(1));
3218  }
3219 
3220  void setDefaultDest(BasicBlock *DefaultCase) {
3221  setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3222  }
3223 
3224  /// Return the number of 'cases' in this switch instruction, excluding the
3225  /// default case.
3226  unsigned getNumCases() const {
3227  return getNumOperands()/2 - 1;
3228  }
3229 
3230  /// Returns a read/write iterator that points to the first case in the
3231  /// SwitchInst.
3233  return CaseIt(this, 0);
3234  }
3235 
3236  /// Returns a read-only iterator that points to the first case in the
3237  /// SwitchInst.
3239  return ConstCaseIt(this, 0);
3240  }
3241 
3242  /// Returns a read/write iterator that points one past the last in the
3243  /// SwitchInst.
3245  return CaseIt(this, getNumCases());
3246  }
3247 
3248  /// Returns a read-only iterator that points one past the last in the
3249  /// SwitchInst.
3251  return ConstCaseIt(this, getNumCases());
3252  }
3253 
3254  /// Iteration adapter for range-for loops.
3256  return make_range(case_begin(), case_end());
3257  }
3258 
3259  /// Constant iteration adapter for range-for loops.
3261  return make_range(case_begin(), case_end());
3262  }
3263 
3264  /// Returns an iterator that points to the default case.
3265  /// Note: this iterator allows to resolve successor only. Attempt
3266  /// to resolve case value causes an assertion.
3267  /// Also note, that increment and decrement also causes an assertion and
3268  /// makes iterator invalid.
3270  return CaseIt(this, DefaultPseudoIndex);
3271  }
3273  return ConstCaseIt(this, DefaultPseudoIndex);
3274  }
3275 
3276  /// Search all of the case values for the specified constant. If it is
3277  /// explicitly handled, return the case iterator of it, otherwise return
3278  /// default case iterator to indicate that it is handled by the default
3279  /// handler.
3281  for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
3282  if (i.getCaseValue() == C)
3283  return i;
3284  return case_default();
3285  }
3287  for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
3288  if (i.getCaseValue() == C)
3289  return i;
3290  return case_default();
3291  }
3292 
3293  /// Finds the unique case value for a given successor. Returns null if the
3294  /// successor is not found, not unique, or is the default case.
3296  if (BB == getDefaultDest()) return nullptr;
3297 
3298  ConstantInt *CI = nullptr;
3299  for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
3300  if (i.getCaseSuccessor() == BB) {
3301  if (CI) return nullptr; // Multiple cases lead to BB.
3302  else CI = i.getCaseValue();
3303  }
3304  }
3305  return CI;
3306  }
3307 
3308  /// Add an entry to the switch instruction.
3309  /// Note:
3310  /// This action invalidates case_end(). Old case_end() iterator will
3311  /// point to the added case.
3312  void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3313 
3314  /// This method removes the specified case and its successor from the switch
3315  /// instruction. Note that this operation may reorder the remaining cases at
3316  /// index idx and above.
3317  /// Note:
3318  /// This action invalidates iterators for all cases following the one removed,
3319  /// including the case_end() iterator.
3320  void removeCase(CaseIt i);
3321 
3322  unsigned getNumSuccessors() const { return getNumOperands()/2; }
3323  BasicBlock *getSuccessor(unsigned idx) const {
3324  assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3325  return cast<BasicBlock>(getOperand(idx*2+1));
3326  }
3327  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3328  assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3329  setOperand(idx * 2 + 1, NewSucc);
3330  }
3331 
3332  // Methods for support type inquiry through isa, cast, and dyn_cast:
3333  static inline bool classof(const Instruction *I) {
3334  return I->getOpcode() == Instruction::Switch;
3335  }
3336  static inline bool classof(const Value *V) {
3337  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3338  }
3339 
3340 private:
3341  BasicBlock *getSuccessorV(unsigned idx) const override;
3342  unsigned getNumSuccessorsV() const override;
3343  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3344 };
3345 
3346 template <>
3348 };
3349 
3351 
3352 //===----------------------------------------------------------------------===//
3353 // IndirectBrInst Class
3354 //===----------------------------------------------------------------------===//
3355 
3356 //===---------------------------------------------------------------------------
3357 /// Indirect Branch Instruction.
3358 ///
3360  unsigned ReservedSpace;
3361 
3362  // Operand[0] = Address to jump to
3363  // Operand[n+1] = n-th destination
3364  IndirectBrInst(const IndirectBrInst &IBI);
3365 
3366  /// Create a new indirectbr instruction, specifying an
3367  /// Address to jump to. The number of expected destinations can be specified
3368  /// here to make memory allocation more efficient. This constructor can also
3369  /// autoinsert before another instruction.
3370  IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
3371 
3372  /// Create a new indirectbr instruction, specifying an
3373  /// Address to jump to. The number of expected destinations can be specified
3374  /// here to make memory allocation more efficient. This constructor also
3375  /// autoinserts at the end of the specified BasicBlock.
3376  IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
3377 
3378  // allocate space for exactly zero operands
3379  void *operator new(size_t s) {
3380  return User::operator new(s);
3381  }
3382 
3383  void init(Value *Address, unsigned NumDests);
3384  void growOperands();
3385 
3386 protected:
3387  // Note: Instruction needs to be a friend here to call cloneImpl.
3388  friend class Instruction;
3389 
3390  IndirectBrInst *cloneImpl() const;
3391 
3392 public:
3393  void *operator new(size_t, unsigned) = delete;
3394 
3395  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3396  Instruction *InsertBefore = nullptr) {
3397  return new IndirectBrInst(Address, NumDests, InsertBefore);
3398  }
3399 
3400  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3401  BasicBlock *InsertAtEnd) {
3402  return new IndirectBrInst(Address, NumDests, InsertAtEnd);
3403  }
3404 
3405  /// Provide fast operand accessors.
3407 
3408  // Accessor Methods for IndirectBrInst instruction.
3409  Value *getAddress() { return getOperand(0); }
3410  const Value *getAddress() const { return getOperand(0); }
3411  void setAddress(Value *V) { setOperand(0, V); }
3412 
3413  /// return the number of possible destinations in this
3414  /// indirectbr instruction.
3415  unsigned getNumDestinations() const { return getNumOperands()-1; }
3416 
3417  /// Return the specified destination.
3418  BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3419  const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3420 
3421  /// Add a destination.
3422  ///
3423  void addDestination(BasicBlock *Dest);
3424 
3425  /// This method removes the specified successor from the
3426  /// indirectbr instruction.
3427  void removeDestination(unsigned i);
3428 
3429  unsigned getNumSuccessors() const { return getNumOperands()-1; }
3430  BasicBlock *getSuccessor(unsigned i) const {
3431  return cast<BasicBlock>(getOperand(i+1));
3432  }
3433  void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3434  setOperand(i + 1, NewSucc);
3435  }
3436 
3437  // Methods for support type inquiry through isa, cast, and dyn_cast:
3438  static inline bool classof(const Instruction *I) {
3439  return I->getOpcode() == Instruction::IndirectBr;
3440  }
3441  static inline bool classof(const Value *V) {
3442  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3443  }
3444 
3445 private:
3446  BasicBlock *getSuccessorV(unsigned idx) const override;
3447  unsigned getNumSuccessorsV() const override;
3448  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3449 };
3450 
3451 template <>
3453 };
3454 
3456 
3457 //===----------------------------------------------------------------------===//
3458 // InvokeInst Class
3459 //===----------------------------------------------------------------------===//
3460 
3461 /// Invoke instruction. The SubclassData field is used to hold the
3462 /// calling convention of the call.
3463 ///
3466  friend class OperandBundleUser<InvokeInst, User::op_iterator>;
3467 
3468  AttributeSet AttributeList;
3469  FunctionType *FTy;
3470 
3471  InvokeInst(const InvokeInst &BI);
3472 
3473  /// Construct an InvokeInst given a range of arguments.
3474  ///
3475  /// Construct an InvokeInst from a range of arguments
3476  inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3477  ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3478  unsigned Values, const Twine &NameStr,
3479  Instruction *InsertBefore)
3480  : InvokeInst(cast<FunctionType>(
3481  cast<PointerType>(Func->getType())->getElementType()),
3482  Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3483  InsertBefore) {}
3484 
3485  inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3486  BasicBlock *IfException, ArrayRef<Value *> Args,
3487  ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3488  const Twine &NameStr, Instruction *InsertBefore);
3489  /// Construct an InvokeInst given a range of arguments.
3490  ///
3491  /// Construct an InvokeInst from a range of arguments
3492  inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3494  unsigned Values, const Twine &NameStr,
3495  BasicBlock *InsertAtEnd);
3496 
3497  bool hasDescriptor() const { return HasDescriptor; }
3498 
3499  void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3500  ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3501  const Twine &NameStr) {
3502  init(cast<FunctionType>(
3503  cast<PointerType>(Func->getType())->getElementType()),
3504  Func, IfNormal, IfException, Args, Bundles, NameStr);
3505  }
3506 
3507  void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3508  BasicBlock *IfException, ArrayRef<Value *> Args,
3509  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3510 
3511 protected:
3512  // Note: Instruction needs to be a friend here to call cloneImpl.
3513  friend class Instruction;
3514 
3515  InvokeInst *cloneImpl() const;
3516 
3517 public:
3518  static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3519  BasicBlock *IfException, ArrayRef<Value *> Args,
3520  const Twine &NameStr,
3521  Instruction *InsertBefore = nullptr) {
3522  return Create(cast<FunctionType>(
3523  cast<PointerType>(Func->getType())->getElementType()),
3524  Func, IfNormal, IfException, Args, None, NameStr,
3525  InsertBefore);
3526  }
3527 
3528  static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3529  BasicBlock *IfException, ArrayRef<Value *> Args,
3530  ArrayRef<OperandBundleDef> Bundles = None,
3531  const Twine &NameStr = "",
3532  Instruction *InsertBefore = nullptr) {
3533  return Create(cast<FunctionType>(
3534  cast<PointerType>(Func->getType())->getElementType()),
3535  Func, IfNormal, IfException, Args, Bundles, NameStr,
3536  InsertBefore);
3537  }
3538 
3539  static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3540  BasicBlock *IfException, ArrayRef<Value *> Args,
3541  const Twine &NameStr,
3542  Instruction *InsertBefore = nullptr) {
3543  unsigned Values = unsigned(Args.size()) + 3;
3544  return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, None,
3545  Values, NameStr, InsertBefore);
3546  }
3547 
3548  static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3549  BasicBlock *IfException, ArrayRef<Value *> Args,
3550  ArrayRef<OperandBundleDef> Bundles = None,
3551  const Twine &NameStr = "",
3552  Instruction *InsertBefore = nullptr) {
3553  unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3554  unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3555 
3556  return new (Values, DescriptorBytes)
3557  InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, Values,
3558  NameStr, InsertBefore);
3559  }
3560 
3561  static InvokeInst *Create(Value *Func,
3562  BasicBlock *IfNormal, BasicBlock *IfException,
3563  ArrayRef<Value *> Args, const Twine &NameStr,
3564  BasicBlock *InsertAtEnd) {
3565  unsigned Values = unsigned(Args.size()) + 3;
3566  return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None,
3567  Values, NameStr, InsertAtEnd);
3568  }
3569  static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3570  BasicBlock *IfException, ArrayRef<Value *> Args,
3572  const Twine &NameStr, BasicBlock *InsertAtEnd) {
3573  unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3574  unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3575 
3576  return new (Values, DescriptorBytes)
3577  InvokeInst(Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3578  InsertAtEnd);
3579  }
3580 
3581  /// Create a clone of \p II with a different set of operand bundles and
3582  /// insert it before \p InsertPt.
3583  ///
3584  /// The returned invoke instruction is identical to \p II in every way except
3585  /// that the operand bundles for the new instruction are set to the operand
3586  /// bundles in \p Bundles.
3587  static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
3588  Instruction *InsertPt = nullptr);
3589 
3590  /// Provide fast operand accessors
3592 
3593  FunctionType *getFunctionType() const { return FTy; }
3594 
3596  mutateType(FTy->getReturnType());
3597  this->FTy = FTy;
3598  }
3599 
3600  /// Return the number of invoke arguments.
3601  ///
3602  unsigned getNumArgOperands() const {
3603  return getNumOperands() - getNumTotalBundleOperands() - 3;
3604  }
3605 
3606  /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
3607  ///
3608  Value *getArgOperand(unsigned i) const {
3609  assert(i < getNumArgOperands() && "Out of bounds!");
3610  return getOperand(i);
3611  }
3612  void setArgOperand(unsigned i, Value *v) {
3613  assert(i < getNumArgOperands() && "Out of bounds!");
3614  setOperand(i, v);
3615  }
3616 
3617  /// Return the iterator pointing to the beginning of the argument list.
3618  op_iterator arg_begin() { return op_begin(); }
3619 
3620  /// Return the iterator pointing to the end of the argument list.
3621  op_iterator arg_end() {
3622  // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee
3623  return op_end() - getNumTotalBundleOperands() - 3;
3624  }
3625 
3626  /// Iteration adapter for range-for loops.
3628  return make_range(arg_begin(), arg_end());
3629  }
3630 
3631  /// Return the iterator pointing to the beginning of the argument list.
3632  const_op_iterator arg_begin() const { return op_begin(); }
3633 
3634  /// Return the iterator pointing to the end of the argument list.
3636  // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee
3637  return op_end() - getNumTotalBundleOperands() - 3;
3638  }
3639 
3640  /// Iteration adapter for range-for loops.
3642  return make_range(arg_begin(), arg_end());
3643  }
3644 
3645  /// Wrappers for getting the \c Use of a invoke argument.
3646  const Use &getArgOperandUse(unsigned i) const {
3647  assert(i < getNumArgOperands() && "Out of bounds!");
3648  return getOperandUse(i);
3649  }
3650  Use &getArgOperandUse(unsigned i) {
3651  assert(i < getNumArgOperands() && "Out of bounds!");
3652  return getOperandUse(i);
3653  }
3654 
3655  /// If one of the arguments has the 'returned' attribute, return its
3656  /// operand value. Otherwise, return nullptr.
3657  Value *getReturnedArgOperand() const;
3658 
3659  /// getCallingConv/setCallingConv - Get or set the calling convention of this
3660  /// function call.
3662  return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3663  }
3665  auto ID = static_cast<unsigned>(CC);
3666  assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
3667  setInstructionSubclassData(ID);
3668  }
3669 
3670  /// Return the parameter attributes for this invoke.
3671  ///
3672  AttributeSet getAttributes() const { return AttributeList; }
3673 
3674  /// Set the parameter attributes for this invoke.
3675  ///
3676  void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; }
3677 
3678  /// adds the attribute to the list of attributes.
3679  void addAttribute(unsigned i, Attribute::AttrKind Kind);
3680 
3681  /// adds the attribute to the list of attributes.
3682  void addAttribute(unsigned i, Attribute Attr);
3683 
3684  /// removes the attribute from the list of attributes.
3685  void removeAttribute(unsigned i, Attribute::AttrKind Kind);
3686 
3687  /// removes the attribute from the list of attributes.
3688  void removeAttribute(unsigned i, StringRef Kind);
3689 
3690  /// adds the dereferenceable attribute to the list of attributes.
3691  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
3692 
3693  /// adds the dereferenceable_or_null attribute to the list of
3694  /// attributes.
3695  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
3696 
3697  /// Determine whether this call has the given attribute.
3698  bool hasFnAttr(Attribute::AttrKind Kind) const {
3699  assert(Kind != Attribute::NoBuiltin &&
3700  "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3701  return hasFnAttrImpl(Kind);
3702  }
3703 
3704  /// Determine whether this call has the given attribute.
3705  bool hasFnAttr(StringRef Kind) const {
3706  return hasFnAttrImpl(Kind);
3707  }
3708 
3709  /// Determine whether the call or the callee has the given attributes.
3710  bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const;
3711 
3712  /// Get the attribute of a given kind at a position.
3714  return getAttributes().getAttribute(i, Kind);
3715  }
3716 
3717  /// Get the attribute of a given kind at a position.
3718  Attribute getAttribute(unsigned i, StringRef Kind) const {
3719  return getAttributes().getAttribute(i, Kind);
3720  }
3721 
3722  /// Return true if the data operand at index \p i has the attribute \p
3723  /// A.
3724  ///
3725  /// Data operands include invoke arguments and values used in operand bundles,
3726  /// but does not include the invokee operand, or the two successor blocks.
3727  /// This routine dispatches to the underlying AttributeList or the
3728  /// OperandBundleUser as appropriate.
3729  ///
3730  /// The index \p i is interpreted as
3731  ///
3732  /// \p i == Attribute::ReturnIndex -> the return value
3733  /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
3734  /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
3735  /// (\p i - 1) in the operand list.
3736  bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const;
3737 
3738  /// Extract the alignment for a call or parameter (0=unknown).
3739  unsigned getParamAlignment(unsigned i) const {
3740  return AttributeList.getParamAlignment(i);
3741  }
3742 
3743  /// Extract the number of dereferenceable bytes for a call or
3744  /// parameter (0=unknown).
3745  uint64_t getDereferenceableBytes(unsigned i) const {
3746  return AttributeList.getDereferenceableBytes(i);
3747  }
3748 
3749  /// Extract the number of dereferenceable_or_null bytes for a call or
3750  /// parameter (0=unknown).
3751  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
3752  return AttributeList.getDereferenceableOrNullBytes(i);
3753  }
3754 
3755  /// @brief Determine if the parameter or return value is marked with NoAlias
3756  /// attribute.
3757  /// @param n The parameter to check. 1 is the first parameter, 0 is the return
3758  bool doesNotAlias(unsigned n) const {
3759  return AttributeList.hasAttribute(n, Attribute::NoAlias);
3760  }
3761 
3762  /// Return true if the call should not be treated as a call to a
3763  /// builtin.
3764  bool isNoBuiltin() const {
3765  // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3766  // to check it by hand.
3767  return hasFnAttrImpl(Attribute::NoBuiltin) &&
3768  !hasFnAttrImpl(Attribute::Builtin);
3769  }
3770 
3771  /// Return true if the call should not be inlined.
3772  bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3773  void setIsNoInline() {
3774  addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3775  }
3776 
3777  /// Determine if the call does not access memory.
3778  bool doesNotAccessMemory() const {
3779  return hasFnAttr(Attribute::ReadNone);
3780  }
3782  addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3783  }
3784 
3785  /// Determine if the call does not access or only reads memory.
3786  bool onlyReadsMemory() const {
3787  return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3788  }
3791  }
3792 
3793  /// Determine if the call does not access or only writes memory.
3794  bool doesNotReadMemory() const {
3795  return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
3796  }
3799  }
3800 
3801  /// @brief Determine if the call access memmory only using it's pointer
3802  /// arguments.
3803  bool onlyAccessesArgMemory() const {
3804  return hasFnAttr(Attribute::ArgMemOnly);
3805  }
3807  addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
3808  }
3809 
3810  /// Determine if the call cannot return.
3811  bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3813  addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3814  }
3815 
3816  /// Determine if the call cannot unwind.
3817  bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3819  addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3820  }
3821 
3822  /// Determine if the invoke cannot be duplicated.
3823  bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3825  addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3826  }
3827 
3828  /// Determine if the invoke is convergent
3829  bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
3830  void setConvergent() {
3832  }
3835  }
3836 
3837  /// Determine if the call returns a structure through first
3838  /// pointer argument.
3839  bool hasStructRetAttr() const {
3840  if (getNumArgOperands() == 0)
3841  return false;
3842 
3843  // Be friendly and also check the callee.
3844  return paramHasAttr(1, Attribute::StructRet);
3845  }
3846 
3847  /// Determine if any call argument is an aggregate passed by value.
3848  bool hasByValArgument() const {
3849  return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3850  }
3851 
3852  /// Return the function called, or null if this is an
3853  /// indirect function invocation.
3854  ///
3856  return dyn_cast<Function>(Op<-3>());
3857  }
3858 
3859  /// Get a pointer to the function that is invoked by this
3860  /// instruction
3861  const Value *getCalledValue() const { return Op<-3>(); }
3862  Value *getCalledValue() { return Op<-3>(); }
3863 
3864  /// Set the function called.
3866  setCalledFunction(
3867  cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
3868  Fn);
3869  }
3871  this->FTy = FTy;
3872  assert(FTy == cast<FunctionType>(
3873  cast<PointerType>(Fn->getType())->getElementType()));
3874  Op<-3>() = Fn;
3875  }
3876 
3877  // get*Dest - Return the destination basic blocks...
3879  return cast<BasicBlock>(Op<-2>());
3880  }
3882  return cast<BasicBlock>(Op<-1>());
3883  }
3885  Op<-2>() = reinterpret_cast<Value*>(B);
3886  }
3888  Op<-1>() = reinterpret_cast<Value*>(B);
3889  }
3890 
3891  /// Get the landingpad instruction from the landing pad
3892  /// block (the unwind destination).
3893  LandingPadInst *getLandingPadInst() const;
3894 
3895  BasicBlock *getSuccessor(unsigned i) const {
3896  assert(i < 2 && "Successor # out of range for invoke!");
3897  return i == 0 ? getNormalDest() : getUnwindDest();
3898  }
3899 
3900  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3901  assert(idx < 2 && "Successor # out of range for invoke!");
3902  *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3903  }
3904 
3905  unsigned getNumSuccessors() const { return 2; }
3906 
3907  // Methods for support type inquiry through isa, cast, and dyn_cast:
3908  static inline bool classof(const Instruction *I) {
3909  return (I->getOpcode() == Instruction::Invoke);
3910  }
3911  static inline bool classof(const Value *V) {
3912  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3913  }
3914 
3915 private:
3916  BasicBlock *getSuccessorV(unsigned idx) const override;
3917  unsigned getNumSuccessorsV() const override;
3918  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3919 
3920  template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
3921  if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind))
3922  return true;
3923 
3924  // Operand bundles override attributes on the called function, but don't
3925  // override attributes directly present on the invoke instruction.
3926  if (isFnAttrDisallowedByOpBundle(Kind))
3927  return false;
3928 
3929  if (const Function *F = getCalledFunction())
3930  return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind);
3931  return false;
3932  }
3933 
3934  // Shadow Instruction::setInstructionSubclassData with a private forwarding
3935  // method so that subclasses cannot accidentally use it.
3936  void setInstructionSubclassData(unsigned short D) {
3938  }
3939 };
3940 
3941 template <>
3942 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3943 };
3944 
3945 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3946  BasicBlock *IfException, ArrayRef<Value *> Args,
3947  ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3948  const Twine &NameStr, Instruction *InsertBefore)
3949  : TerminatorInst(Ty->getReturnType(), Instruction::Invoke,
3950  OperandTraits<InvokeInst>::op_end(this) - Values, Values,
3951  InsertBefore) {
3952  init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3953 }
3954 
3955 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
3956  BasicBlock *IfException, ArrayRef<Value *> Args,
3957  ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3958  const Twine &NameStr, BasicBlock *InsertAtEnd)
3959  : TerminatorInst(
3960  cast<FunctionType>(cast<PointerType>(Func->getType())
3961  ->getElementType())->getReturnType(),
3962  Instruction::Invoke, OperandTraits<InvokeInst>::op_end(this) - Values,
3963  Values, InsertAtEnd) {
3964  init(Func, IfNormal, IfException, Args, Bundles, NameStr);
3965 }
3966 
3967 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3968 
3969 //===----------------------------------------------------------------------===//
3970 // ResumeInst Class
3971 //===----------------------------------------------------------------------===//
3972 
3973 //===---------------------------------------------------------------------------
3974 /// Resume the propagation of an exception.
3975 ///
3976 class ResumeInst : public TerminatorInst {
3977  ResumeInst(const ResumeInst &RI);
3978 
3979  explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3980  ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3981 
3982 protected:
3983  // Note: Instruction needs to be a friend here to call cloneImpl.
3984  friend class Instruction;
3985 
3986  ResumeInst *cloneImpl() const;
3987 
3988 public:
3989  static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3990  return new(1) ResumeInst(Exn, InsertBefore);
3991  }
3992 
3993  static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3994  return new(1) ResumeInst(Exn, InsertAtEnd);
3995  }
3996 
3997  /// Provide fast operand accessors
3999 
4000  /// Convenience accessor.
4001  Value *getValue() const { return Op<0>(); }
4002 
4003  unsigned getNumSuccessors() const { return 0; }
4004 
4005  // Methods for support type inquiry through isa, cast, and dyn_cast:
4006  static inline bool classof(const Instruction *I) {
4007  return I->getOpcode() == Instruction::Resume;
4008  }
4009  static inline bool classof(const Value *V) {
4010  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4011  }
4012 
4013 private:
4014  BasicBlock *getSuccessorV(unsigned idx) const override;
4015  unsigned getNumSuccessorsV() const override;
4016  void setSuccessorV(unsigned idx, BasicBlock *B) override;
4017 };
4018 
4019 template <>
4021  public FixedNumOperandTraits<ResumeInst, 1> {
4022 };
4023 
4025 
4026 //===----------------------------------------------------------------------===//
4027 // CatchSwitchInst Class
4028 //===----------------------------------------------------------------------===//
4029 class CatchSwitchInst : public TerminatorInst {
4030  /// The number of operands actually allocated. NumOperands is
4031  /// the number actually in use.
4032  unsigned ReservedSpace;
4033 
4034  // Operand[0] = Outer scope
4035  // Operand[1] = Unwind block destination
4036  // Operand[n] = BasicBlock to go to on match
4037  CatchSwitchInst(const CatchSwitchInst &CSI);
4038 
4039  /// Create a new switch instruction, specifying a
4040  /// default destination. The number of additional handlers can be specified
4041  /// here to make memory allocation more efficient.
4042  /// This constructor can also autoinsert before another instruction.
4043  CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4044  unsigned NumHandlers, const Twine &NameStr,
4045  Instruction *InsertBefore);
4046 
4047  /// Create a new switch instruction, specifying a
4048  /// default destination. The number of additional handlers can be specified
4049  /// here to make memory allocation more efficient.
4050  /// This constructor also autoinserts at the end of the specified BasicBlock.
4051  CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4052  unsigned NumHandlers, const Twine &NameStr,
4053  BasicBlock *InsertAtEnd);
4054 
4055  // allocate space for exactly zero operands
4056  void *operator new(size_t s) { return User::operator new(s); }
4057 
4058  void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
4059  void growOperands(unsigned Size);
4060 
4061 protected:
4062  // Note: Instruction needs to be a friend here to call cloneImpl.
4063  friend class Instruction;
4064 
4065  CatchSwitchInst *cloneImpl() const;
4066 
4067 public:
4068  void *operator new(size_t, unsigned) = delete;
4069 
4070  static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4071  unsigned NumHandlers,
4072  const Twine &NameStr = "",
4073  Instruction *InsertBefore = nullptr) {
4074  return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4075  InsertBefore);
4076  }
4077 
4078  static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4079  unsigned NumHandlers, const Twine &NameStr,
4080  BasicBlock *InsertAtEnd) {
4081  return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4082  InsertAtEnd);
4083  }
4084 
4085  /// Provide fast operand accessors
4087 
4088  // Accessor Methods for CatchSwitch stmt
4089  Value *getParentPad() const { return getOperand(0); }
4090  void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
4091 
4092  // Accessor Methods for CatchSwitch stmt
4093  bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4094  bool unwindsToCaller() const { return !hasUnwindDest(); }
4096  if (hasUnwindDest())
4097  return cast<BasicBlock>(getOperand(1));
4098  return nullptr;
4099  }
4100  void setUnwindDest(BasicBlock *UnwindDest) {
4101  assert(UnwindDest);
4102  assert(hasUnwindDest());
4103  setOperand(1, UnwindDest);
4104  }
4105 
4106  /// return the number of 'handlers' in this catchswitch
4107  /// instruction, except the default handler
4108  unsigned getNumHandlers() const {
4109  if (hasUnwindDest())
4110  return getNumOperands() - 2;
4111  return getNumOperands() - 1;
4112  }
4113 
4114 private:
4115  static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
4116  static const BasicBlock *handler_helper(const Value *V) {
4117  return cast<BasicBlock>(V);
4118  }
4119 
4120 public:
4121  typedef std::pointer_to_unary_function<Value *, BasicBlock *> DerefFnTy;
4124  typedef std::pointer_to_unary_function<const Value *, const BasicBlock *>
4128 
4129  /// Returns an iterator that points to the first handler in CatchSwitchInst.
4130  handler_iterator handler_begin() {
4131  op_iterator It = op_begin() + 1;
4132  if (hasUnwindDest())
4133  ++It;
4134  return handler_iterator(It, DerefFnTy(handler_helper));
4135  }
4136 
4137  /// Returns an iterator that points to the first handler in the
4138  /// CatchSwitchInst.
4139  const_handler_iterator handler_begin() const {
4140  const_op_iterator It = op_begin() + 1;
4141  if (hasUnwindDest())
4142  ++It;
4143  return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
4144  }
4145 
4146  /// Returns a read-only iterator that points one past the last
4147  /// handler in the CatchSwitchInst.
4148  handler_iterator handler_end() {
4149  return handler_iterator(op_end(), DerefFnTy(handler_helper));
4150  }
4151 
4152  /// Returns an iterator that points one past the last handler in the
4153  /// CatchSwitchInst.
4154  const_handler_iterator handler_end() const {
4155  return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
4156  }
4157 
4158  /// iteration adapter for range-for loops.
4159  handler_range handlers() {
4160  return make_range(handler_begin(), handler_end());
4161  }
4162 
4163  /// iteration adapter for range-for loops.
4164  const_handler_range handlers() const {
4165  return make_range(handler_begin(), handler_end());
4166  }
4167 
4168  /// Add an entry to the switch instruction...
4169  /// Note:
4170  /// This action invalidates handler_end(). Old handler_end() iterator will
4171  /// point to the added handler.
4172  void addHandler(BasicBlock *Dest);
4173 
4174  void removeHandler(handler_iterator HI);
4175 
4176  unsigned getNumSuccessors() const { return getNumOperands() - 1; }
4177  BasicBlock *getSuccessor(unsigned Idx) const {
4178  assert(Idx < getNumSuccessors() &&
4179  "Successor # out of range for catchswitch!");
4180  return cast<BasicBlock>(getOperand(Idx + 1));
4181  }
4182  void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
4183  assert(Idx < getNumSuccessors() &&
4184  "Successor # out of range for catchswitch!");
4185  setOperand(Idx + 1, NewSucc);
4186  }
4187 
4188  // Methods for support type inquiry through isa, cast, and dyn_cast:
4189  static inline bool classof(const Instruction *I) {
4190  return I->getOpcode() == Instruction::CatchSwitch;
4191  }
4192  static inline bool classof(const Value *V) {
4193  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4194  }
4195 
4196 private:
4197  BasicBlock *getSuccessorV(unsigned Idx) const override;
4198  unsigned getNumSuccessorsV() const override;
4199  void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4200 };
4201 
4202 template <>
4204 
4206 
4207 //===----------------------------------------------------------------------===//
4208 // CleanupPadInst Class
4209 //===----------------------------------------------------------------------===//
4211 private:
4212  explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4213  unsigned Values, const Twine &NameStr,
4214  Instruction *InsertBefore)
4215  : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4216  NameStr, InsertBefore) {}
4217  explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4218  unsigned Values, const Twine &NameStr,
4219  BasicBlock *InsertAtEnd)
4220  : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4221  NameStr, InsertAtEnd) {}
4222 
4223 public:
4224  static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = None,
4225  const Twine &NameStr = "",
4226  Instruction *InsertBefore = nullptr) {
4227  unsigned Values = 1 + Args.size();
4228  return new (Values)
4229  CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
4230  }
4231 
4232  static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args,
4233  const Twine &NameStr, BasicBlock *InsertAtEnd) {
4234  unsigned Values = 1 + Args.size();
4235  return new (Values)
4236  CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd);
4237  }
4238 
4239  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4240  static inline bool classof(const Instruction *I) {
4241  return I->getOpcode() == Instruction::CleanupPad;
4242  }
4243  static inline bool classof(const Value *V) {
4244  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4245  }
4246 };
4247 
4248 //===----------------------------------------------------------------------===//
4249 // CatchPadInst Class
4250 //===----------------------------------------------------------------------===//
4252 private:
4253  explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4254  unsigned Values, const Twine &NameStr,
4255  Instruction *InsertBefore)
4256  : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4257  NameStr, InsertBefore) {}
4258  explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4259  unsigned Values, const Twine &NameStr,
4260  BasicBlock *InsertAtEnd)
4261  : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4262  NameStr, InsertAtEnd) {}
4263 
4264 public:
4265  static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4266  const Twine &NameStr = "",
4267  Instruction *InsertBefore = nullptr) {
4268  unsigned Values = 1 + Args.size();
4269  return new (Values)
4270  CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
4271  }
4272 
4273  static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4274  const Twine &NameStr, BasicBlock *InsertAtEnd) {
4275  unsigned Values = 1 + Args.size();
4276  return new (Values)
4277  CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd);
4278  }
4279 
4280  /// Convenience accessors
4282  return cast<CatchSwitchInst>(Op<-1>());
4283  }
4284  void setCatchSwitch(Value *CatchSwitch) {
4285  assert(CatchSwitch);
4286  Op<-1>() = CatchSwitch;
4287  }
4288 
4289  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4290  static inline bool classof(const Instruction *I) {
4291  return I->getOpcode() == Instruction::CatchPad;
4292  }
4293  static inline bool classof(const Value *V) {
4294  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4295  }
4296 };
4297 
4298 //===----------------------------------------------------------------------===//
4299 // CatchReturnInst Class
4300 //===----------------------------------------------------------------------===//
4301 
4302 class CatchReturnInst : public TerminatorInst {
4303  CatchReturnInst(const CatchReturnInst &RI);
4304  CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
4305  CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
4306 
4307  void init(Value *CatchPad, BasicBlock *BB);
4308 
4309 protected:
4310  // Note: Instruction needs to be a friend here to call cloneImpl.
4311  friend class Instruction;
4312 
4313  CatchReturnInst *cloneImpl() const;
4314 
4315 public:
4316  static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4317  Instruction *InsertBefore = nullptr) {
4318  assert(CatchPad);
4319  assert(BB);
4320  return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
4321  }
4322 
4323  static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4324  BasicBlock *InsertAtEnd) {
4325  assert(CatchPad);
4326  assert(BB);
4327  return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd);
4328  }
4329 
4330  /// Provide fast operand accessors
4332 
4333  /// Convenience accessors.
4334  CatchPadInst *getCatchPad() const { return cast<CatchPadInst>(Op<0>()); }
4335  void setCatchPad(CatchPadInst *CatchPad) {
4336  assert(CatchPad);
4337  Op<0>() = CatchPad;
4338  }
4339 
4340  BasicBlock *getSuccessor() const { return cast<BasicBlock>(Op<1>()); }
4341  void setSuccessor(BasicBlock *NewSucc) {
4342  assert(NewSucc);
4343  Op<1>() = NewSucc;
4344  }
4345  unsigned getNumSuccessors() const { return 1; }
4346 
4347  /// Get the parentPad of this catchret's catchpad's catchswitch.
4348  /// The successor block is implicitly a member of this funclet.
4350  return getCatchPad()->getCatchSwitch()->getParentPad();
4351  }
4352 
4353  // Methods for support type inquiry through isa, cast, and dyn_cast:
4354  static inline bool classof(const Instruction *I) {
4355  return (I->getOpcode() == Instruction::CatchRet);
4356  }
4357  static inline bool classof(const Value *V) {
4358  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4359  }
4360 
4361 private:
4362  BasicBlock *getSuccessorV(unsigned Idx) const override;
4363  unsigned getNumSuccessorsV() const override;
4364  void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4365 };
4366 
4367 template <>
4369  : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4370 
4372 
4373 //===----------------------------------------------------------------------===//
4374 // CleanupReturnInst Class
4375 //===----------------------------------------------------------------------===//
4376 
4377 class CleanupReturnInst : public TerminatorInst {
4378 private:
4380  CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4381  Instruction *InsertBefore = nullptr);
4382  CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4383  BasicBlock *InsertAtEnd);
4384 
4385  void init(Value *CleanupPad, BasicBlock *UnwindBB);
4386 
4387 protected:
4388  // Note: Instruction needs to be a friend here to call cloneImpl.
4389  friend class Instruction;
4390 
4391  CleanupReturnInst *cloneImpl() const;
4392 
4393 public:
4394  static CleanupReturnInst *Create(Value *CleanupPad,
4395  BasicBlock *UnwindBB = nullptr,
4396  Instruction *InsertBefore = nullptr) {
4397  assert(CleanupPad);
4398  unsigned Values = 1;
4399  if (UnwindBB)
4400  ++Values;
4401  return new (Values)
4402  CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
4403  }
4404 
4405  static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
4406  BasicBlock *InsertAtEnd) {
4407  assert(CleanupPad);
4408  unsigned Values = 1;
4409  if (UnwindBB)
4410  ++Values;
4411  return new (Values)
4412  CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
4413  }
4414 
4415  /// Provide fast operand accessors
4417 
4418  bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4419  bool unwindsToCaller() const { return !hasUnwindDest(); }
4420 
4421  /// Convenience accessor.
4423  return cast<CleanupPadInst>(Op<0>());
4424  }
4425  void setCleanupPad(CleanupPadInst *CleanupPad) {
4426  assert(CleanupPad);
4427  Op<0>() = CleanupPad;
4428  }
4429 
4430  unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4431 
4433  return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
4434  }
4435  void setUnwindDest(BasicBlock *NewDest) {
4436  assert(NewDest);
4437  assert(hasUnwindDest());
4438  Op<1>() = NewDest;
4439  }
4440 
4441  // Methods for support type inquiry through isa, cast, and dyn_cast:
4442  static inline bool classof(const Instruction *I) {
4443  return (I->getOpcode() == Instruction::CleanupRet);
4444  }
4445  static inline bool classof(const Value *V) {
4446  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4447  }
4448 
4449 private:
4450  BasicBlock *getSuccessorV(unsigned Idx) const override;
4451  unsigned getNumSuccessorsV() const override;
4452  void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4453 
4454  // Shadow Instruction::setInstructionSubclassData with a private forwarding
4455  // method so that subclasses cannot accidentally use it.
4456  void setInstructionSubclassData(unsigned short D) {
4458  }
4459 };
4460 
4461 template <>
4463  : public VariadicOperandTraits<CleanupReturnInst, /*MINARITY=*/1> {};
4464 
4466 
4467 //===----------------------------------------------------------------------===//
4468 // UnreachableInst Class
4469 //===----------------------------------------------------------------------===//
4470 
4471 //===---------------------------------------------------------------------------
4472 /// This function has undefined behavior. In particular, the
4473 /// presence of this instruction indicates some higher level knowledge that the
4474 /// end of the block cannot be reached.
4475 ///
4476 class UnreachableInst : public TerminatorInst {
4477 protected:
4478  // Note: Instruction needs to be a friend here to call cloneImpl.
4479  friend class Instruction;
4480 
4481  UnreachableInst *cloneImpl() const;
4482 
4483 public:
4484  explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
4485  explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
4486 
4487  // allocate space for exactly zero operands
4488  void *operator new(size_t s) {
4489  return User::operator new(s, 0);
4490  }
4491 
4492  void *operator new(size_t, unsigned) = delete;
4493 
4494  unsigned getNumSuccessors() const { return 0; }
4495 
4496  // Methods for support type inquiry through isa, cast, and dyn_cast:
4497  static inline bool classof(const Instruction *I) {
4498  return I->getOpcode() == Instruction::Unreachable;
4499  }
4500  static inline bool classof(const Value *V) {
4501  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4502  }
4503 
4504 private:
4505  BasicBlock *getSuccessorV(unsigned idx) const override;
4506  unsigned getNumSuccessorsV() const override;
4507  void setSuccessorV(unsigned idx, BasicBlock *B) override;
4508 };
4509 
4510 //===----------------------------------------------------------------------===//
4511 // TruncInst Class
4512 //===----------------------------------------------------------------------===//
4513 
4514 /// This class represents a truncation of integer types.
4515 class TruncInst : public CastInst {
4516 protected:
4517  // Note: Instruction needs to be a friend here to call cloneImpl.
4518  friend class Instruction;
4519 
4520  /// Clone an identical TruncInst
4521  TruncInst *cloneImpl() const;
4522 
4523 public:
4524  /// Constructor with insert-before-instruction semantics
4525  TruncInst(
4526  Value *S, ///< The value to be truncated
4527  Type *Ty, ///< The (smaller) type to truncate to
4528  const Twine &NameStr = "", ///< A name for the new instruction
4529  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4530  );
4531 
4532  /// Constructor with insert-at-end-of-block semantics
4533  TruncInst(
4534  Value *S, ///< The value to be truncated
4535  Type *Ty, ///< The (smaller) type to truncate to
4536  const Twine &NameStr, ///< A name for the new instruction
4537  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4538  );
4539 
4540  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4541  static inline bool classof(const Instruction *I) {
4542  return I->getOpcode() == Trunc;
4543  }
4544  static inline bool classof(const Value *V) {
4545  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4546  }
4547 };
4548 
4549 //===----------------------------------------------------------------------===//
4550 // ZExtInst Class
4551 //===----------------------------------------------------------------------===//
4552 
4553 /// This class represents zero extension of integer types.
4554 class ZExtInst : public CastInst {
4555 protected:
4556  // Note: Instruction needs to be a friend here to call cloneImpl.
4557  friend class Instruction;
4558 
4559  /// Clone an identical ZExtInst
4560  ZExtInst *cloneImpl() const;
4561 
4562 public:
4563  /// Constructor with insert-before-instruction semantics
4564  ZExtInst(
4565  Value *S, ///< The value to be zero extended
4566  Type *Ty, ///< The type to zero extend to
4567  const Twine &NameStr = "", ///< A name for the new instruction
4568  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4569  );
4570 
4571  /// Constructor with insert-at-end semantics.
4572  ZExtInst(
4573  Value *S, ///< The value to be zero extended
4574  Type *Ty, ///< The type to zero extend to
4575  const Twine &NameStr, ///< A name for the new instruction
4576  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4577  );
4578 
4579  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4580  static inline bool classof(const Instruction *I) {
4581  return I->getOpcode() == ZExt;
4582  }
4583  static inline bool classof(const Value *V) {
4584  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4585  }
4586 };
4587 
4588 //===----------------------------------------------------------------------===//
4589 // SExtInst Class
4590 //===----------------------------------------------------------------------===//
4591 
4592 /// This class represents a sign extension of integer types.
4593 class SExtInst : public CastInst {
4594 protected:
4595  // Note: Instruction needs to be a friend here to call cloneImpl.
4596  friend class Instruction;
4597 
4598  /// Clone an identical SExtInst
4599  SExtInst *cloneImpl() const;
4600 
4601 public:
4602  /// Constructor with insert-before-instruction semantics
4603  SExtInst(
4604  Value *S, ///< The value to be sign extended
4605  Type *Ty, ///< The type to sign extend to
4606  const Twine &NameStr = "", ///< A name for the new instruction
4607  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4608  );
4609 
4610  /// Constructor with insert-at-end-of-block semantics
4611  SExtInst(
4612  Value *S, ///< The value to be sign extended
4613  Type *Ty, ///< The type to sign extend to
4614  const Twine &NameStr, ///< A name for the new instruction
4615  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4616  );
4617 
4618  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4619  static inline bool classof(const Instruction *I) {
4620  return I->getOpcode() == SExt;
4621  }
4622  static inline bool classof(const Value *V) {
4623  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4624  }
4625 };
4626 
4627 //===----------------------------------------------------------------------===//
4628 // FPTruncInst Class
4629 //===----------------------------------------------------------------------===//
4630 
4631 /// This class represents a truncation of floating point types.
4632 class FPTruncInst : public CastInst {
4633 protected:
4634  // Note: Instruction needs to be a friend here to call cloneImpl.
4635  friend class Instruction;
4636 
4637  /// Clone an identical FPTruncInst
4638  FPTruncInst *cloneImpl() const;
4639 
4640 public:
4641  /// Constructor with insert-before-instruction semantics
4642  FPTruncInst(
4643  Value *S, ///< The value to be truncated
4644  Type *Ty, ///< The type to truncate to
4645  const Twine &NameStr = "", ///< A name for the new instruction
4646  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4647  );
4648 
4649  /// Constructor with insert-before-instruction semantics
4650  FPTruncInst(
4651  Value *S, ///< The value to be truncated
4652  Type *Ty, ///< The type to truncate to
4653  const Twine &NameStr, ///< A name for the new instruction
4654  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4655  );
4656 
4657  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4658  static inline bool classof(const Instruction *I) {
4659  return I->getOpcode() == FPTrunc;
4660  }
4661  static inline bool classof(const Value *V) {
4662  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4663  }
4664 };
4665 
4666 //===----------------------------------------------------------------------===//
4667 // FPExtInst Class
4668 //===----------------------------------------------------------------------===//
4669 
4670 /// This class represents an extension of floating point types.
4671 class FPExtInst : public CastInst {
4672 protected:
4673  // Note: Instruction needs to be a friend here to call cloneImpl.
4674  friend class Instruction;
4675 
4676  /// Clone an identical FPExtInst
4677  FPExtInst *cloneImpl() const;
4678 
4679 public:
4680  /// Constructor with insert-before-instruction semantics
4681  FPExtInst(
4682  Value *S, ///< The value to be extended
4683  Type *Ty, ///< The type to extend to
4684  const Twine &NameStr = "", ///< A name for the new instruction
4685  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4686  );
4687 
4688  /// Constructor with insert-at-end-of-block semantics
4689  FPExtInst(
4690  Value *S, ///< The value to be extended
4691  Type *Ty, ///< The type to extend to
4692  const Twine &NameStr, ///< A name for the new instruction
4693  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4694  );
4695 
4696  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4697  static inline bool classof(const Instruction *I) {
4698  return I->getOpcode() == FPExt;
4699  }
4700  static inline bool classof(const Value *V) {
4701  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4702  }
4703 };
4704 
4705 //===----------------------------------------------------------------------===//
4706 // UIToFPInst Class
4707 //===----------------------------------------------------------------------===//
4708 
4709 /// This class represents a cast unsigned integer to floating point.
4710 class UIToFPInst : public CastInst {
4711 protected:
4712  // Note: Instruction needs to be a friend here to call cloneImpl.
4713  friend class Instruction;
4714 
4715  /// Clone an identical UIToFPInst
4716  UIToFPInst *cloneImpl() const;
4717 
4718 public:
4719  /// Constructor with insert-before-instruction semantics
4720  UIToFPInst(
4721  Value *S, ///< The value to be converted
4722  Type *Ty, ///< The type to convert to
4723  const Twine &NameStr = "", ///< A name for the new instruction
4724  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4725  );
4726 
4727  /// Constructor with insert-at-end-of-block semantics
4728  UIToFPInst(
4729  Value *S, ///< The value to be converted
4730  Type *Ty, ///< The type to convert to
4731  const Twine &NameStr, ///< A name for the new instruction
4732  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4733  );
4734 
4735  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4736  static inline bool classof(const Instruction *I) {
4737  return I->getOpcode() == UIToFP;
4738  }
4739  static inline bool classof(const Value *V) {
4740  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4741  }
4742 };
4743 
4744 //===----------------------------------------------------------------------===//
4745 // SIToFPInst Class
4746 //===----------------------------------------------------------------------===//
4747 
4748 /// This class represents a cast from signed integer to floating point.
4749 class SIToFPInst : public CastInst {
4750 protected:
4751  // Note: Instruction needs to be a friend here to call cloneImpl.
4752  friend class Instruction;
4753 
4754  /// Clone an identical SIToFPInst
4755  SIToFPInst *cloneImpl() const;
4756 
4757 public:
4758  /// Constructor with insert-before-instruction semantics
4759  SIToFPInst(
4760  Value *S, ///< The value to be converted
4761  Type *Ty, ///< The type to convert to
4762  const Twine &NameStr = "", ///< A name for the new instruction
4763  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4764  );
4765 
4766  /// Constructor with insert-at-end-of-block semantics
4767  SIToFPInst(
4768  Value *S, ///< The value to be converted
4769  Type *Ty, ///< The type to convert to
4770  const Twine &NameStr, ///< A name for the new instruction
4771  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4772  );
4773 
4774  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4775  static inline bool classof(const Instruction *I) {
4776  return I->getOpcode() == SIToFP;
4777  }
4778  static inline bool classof(const Value *V) {
4779  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4780  }
4781 };
4782 
4783 //===----------------------------------------------------------------------===//
4784 // FPToUIInst Class
4785 //===----------------------------------------------------------------------===//
4786 
4787 /// This class represents a cast from floating point to unsigned integer
4788 class FPToUIInst : public CastInst {
4789 protected:
4790  // Note: Instruction needs to be a friend here to call cloneImpl.
4791  friend class Instruction;
4792 
4793  /// Clone an identical FPToUIInst
4794  FPToUIInst *cloneImpl() const;
4795 
4796 public:
4797  /// Constructor with insert-before-instruction semantics
4798  FPToUIInst(
4799  Value *S, ///< The value to be converted
4800  Type *Ty, ///< The type to convert to
4801  const Twine &NameStr = "", ///< A name for the new instruction
4802  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4803  );
4804 
4805  /// Constructor with insert-at-end-of-block semantics
4806  FPToUIInst(
4807  Value *S, ///< The value to be converted
4808  Type *Ty, ///< The type to convert to
4809  const Twine &NameStr, ///< A name for the new instruction
4810  BasicBlock *InsertAtEnd ///< Where to insert the new instruction
4811  );
4812 
4813  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4814  static inline bool classof(const Instruction *I) {
4815  return I->getOpcode() == FPToUI;
4816  }
4817  static inline bool classof(const Value *V) {
4818  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4819  }
4820 };
4821 
4822 //===----------------------------------------------------------------------===//
4823 // FPToSIInst Class
4824 //===----------------------------------------------------------------------===//
4825 
4826 /// This class represents a cast from floating point to signed integer.
4827 class FPToSIInst : public CastInst {
4828 protected:
4829  // Note: Instruction needs to be a friend here to call cloneImpl.
4830  friend class Instruction;
4831 
4832  /// Clone an identical FPToSIInst
4833  FPToSIInst *cloneImpl() const;
4834 
4835 public:
4836  /// Constructor with insert-before-instruction semantics
4837  FPToSIInst(
4838  Value *S, ///< The value to be converted
4839  Type *Ty, ///< The type to convert to
4840  const Twine &NameStr = "", ///< A name for the new instruction
4841  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4842  );
4843 
4844  /// Constructor with insert-at-end-of-block semantics
4845  FPToSIInst(
4846  Value *S, ///< The value to be converted
4847  Type *Ty, ///< The type to convert to
4848  const Twine &NameStr, ///< A name for the new instruction
4849  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4850  );
4851 
4852  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4853  static inline bool classof(const Instruction *I) {
4854  return I->getOpcode() == FPToSI;
4855  }
4856  static inline bool classof(const Value *V) {
4857  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4858  }
4859 };
4860 
4861 //===----------------------------------------------------------------------===//
4862 // IntToPtrInst Class
4863 //===----------------------------------------------------------------------===//
4864 
4865 /// This class represents a cast from an integer to a pointer.
4866 class IntToPtrInst : public CastInst {
4867 public:
4868  // Note: Instruction needs to be a friend here to call cloneImpl.
4869  friend class Instruction;
4870 
4871  /// Constructor with insert-before-instruction semantics
4872  IntToPtrInst(
4873  Value *S, ///< The value to be converted
4874  Type *Ty, ///< The type to convert to
4875  const Twine &NameStr = "", ///< A name for the new instruction
4876  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4877  );
4878 
4879  /// Constructor with insert-at-end-of-block semantics
4880  IntToPtrInst(
4881  Value *S, ///< The value to be converted
4882  Type *Ty, ///< The type to convert to
4883  const Twine &NameStr, ///< A name for the new instruction
4884  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4885  );
4886 
4887  /// Clone an identical IntToPtrInst.
4888  IntToPtrInst *cloneImpl() const;
4889 
4890  /// Returns the address space of this instruction's pointer type.
4891  unsigned getAddressSpace() const {
4892  return getType()->getPointerAddressSpace();
4893  }
4894 
4895  // Methods for support type inquiry through isa, cast, and dyn_cast:
4896  static inline bool classof(const Instruction *I) {
4897  return I->getOpcode() == IntToPtr;
4898  }
4899  static inline bool classof(const Value *V) {
4900  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4901  }
4902 };
4903 
4904 //===----------------------------------------------------------------------===//
4905 // PtrToIntInst Class
4906 //===----------------------------------------------------------------------===//
4907 
4908 /// This class represents a cast from a pointer to an integer.
4909 class PtrToIntInst : public CastInst {
4910 protected:
4911  // Note: Instruction needs to be a friend here to call cloneImpl.
4912  friend class Instruction;
4913 
4914  /// Clone an identical PtrToIntInst.
4915  PtrToIntInst *cloneImpl() const;
4916 
4917 public:
4918  /// Constructor with insert-before-instruction semantics
4919  PtrToIntInst(
4920  Value *S, ///< The value to be converted
4921  Type *Ty, ///< The type to convert to
4922  const Twine &NameStr = "", ///< A name for the new instruction
4923  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4924  );
4925 
4926  /// Constructor with insert-at-end-of-block semantics
4927  PtrToIntInst(
4928  Value *S, ///< The value to be converted
4929  Type *Ty, ///< The type to convert to
4930  const Twine &NameStr, ///< A name for the new instruction
4931  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4932  );
4933 
4934  /// Gets the pointer operand.
4936  /// Gets the pointer operand.
4937  const Value *getPointerOperand() const { return getOperand(0); }
4938  /// Gets the operand index of the pointer operand.
4939  static unsigned getPointerOperandIndex() { return 0U; }
4940 
4941  /// Returns the address space of the pointer operand.
4942  unsigned getPointerAddressSpace() const {
4944  }
4945 
4946  // Methods for support type inquiry through isa, cast, and dyn_cast:
4947  static inline bool classof(const Instruction *I) {
4948  return I->getOpcode() == PtrToInt;
4949  }
4950  static inline bool classof(const Value *V) {
4951  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4952  }
4953 };
4954 
4955 //===----------------------------------------------------------------------===//
4956 // BitCastInst Class
4957 //===----------------------------------------------------------------------===//
4958 
4959 /// This class represents a no-op cast from one type to another.
4960 class BitCastInst : public CastInst {
4961 protected:
4962  // Note: Instruction needs to be a friend here to call cloneImpl.
4963  friend class Instruction;
4964 
4965  /// Clone an identical BitCastInst.
4966  BitCastInst *cloneImpl() const;
4967 
4968 public:
4969  /// Constructor with insert-before-instruction semantics
4970  BitCastInst(
4971  Value *S, ///< The value to be casted
4972  Type *Ty, ///< The type to casted to
4973  const Twine &NameStr = "", ///< A name for the new instruction
4974  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4975  );
4976 
4977  /// Constructor with insert-at-end-of-block semantics
4978  BitCastInst(
4979  Value *S, ///< The value to be casted
4980  Type *Ty, ///< The type to casted to
4981  const Twine &NameStr, ///< A name for the new instruction
4982  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4983  );
4984 
4985  // Methods for support type inquiry through isa, cast, and dyn_cast:
4986  static inline bool classof(const Instruction *I) {
4987  return I->getOpcode() == BitCast;
4988  }
4989  static inline bool classof(const Value *V) {
4990  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4991  }
4992 };
4993 
4994 //===----------------------------------------------------------------------===//
4995 // AddrSpaceCastInst Class
4996 //===----------------------------------------------------------------------===//
4997 
4998 /// This class represents a conversion between pointers from one address space
4999 /// to another.
5000 class AddrSpaceCastInst : public CastInst {
5001 protected:
5002  // Note: Instruction needs to be a friend here to call cloneImpl.
5003  friend class Instruction;
5004 
5005  /// Clone an identical AddrSpaceCastInst.
5006  AddrSpaceCastInst *cloneImpl() const;
5007 
5008 public:
5009  /// Constructor with insert-before-instruction semantics
5011  Value *S, ///< The value to be casted
5012  Type *Ty, ///< The type to casted to
5013  const Twine &NameStr = "", ///< A name for the new instruction
5014  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
5015  );
5016 
5017  /// Constructor with insert-at-end-of-block semantics
5019  Value *S, ///< The value to be casted
5020  Type *Ty, ///< The type to casted to
5021  const Twine &NameStr, ///< A name for the new instruction
5022  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
5023  );
5024 
5025  // Methods for support type inquiry through isa, cast, and dyn_cast:
5026  static inline bool classof(const Instruction *I) {
5027  return I->getOpcode() == AddrSpaceCast;
5028  }
5029  static inline bool classof(const Value *V) {
5030  return isa<Instruction>(V) && classof(cast<Instruction>(V));
5031  }
5032 
5033  /// Gets the pointer operand.
5035  return getOperand(0);
5036  }
5037 
5038  /// Gets the pointer operand.
5039  const Value *getPointerOperand() const {
5040  return getOperand(0);
5041  }
5042 
5043  /// Gets the operand index of the pointer operand.
5044  static unsigned getPointerOperandIndex() {
5045  return 0U;
5046  }
5047 
5048  /// Returns the address space of the pointer operand.
5049  unsigned getSrcAddressSpace() const {
5051  }
5052 
5053  /// Returns the address space of the result.
5054  unsigned getDestAddressSpace() const {
5055  return getType()->getPointerAddressSpace();
5056  }
5057 };
5058 
5059 } // end namespace llvm
5060 
5061 #endif // LLVM_IR_INSTRUCTIONS_H
static unsigned getInsertedValueOperandIndex()
MachineLoop * L
AttributeSet getAttributes() const
Return the parameter attributes for this call.
const Value * getAddress() const
const NoneType None
Definition: None.h:23
iterator_range< const_handler_iterator > const_handler_range
const Use & getOperandUse(unsigned i) const
Definition: User.h:158
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
BasicBlock * getSuccessor(unsigned i) const
Return a value (possibly void), from a function.
The highest possible calling convention ID. Must be some 2^k - 1.
Definition: CallingConv.h:200
Value * getValueOperand()
Definition: Instructions.h:391
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
bool hasStructRetAttr() const
Determine if the call returns a structure through first pointer argument.
Value * getArraySize()
Definition: Instructions.h:94
AllocaInst(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="", Instruction *InsertBefore=nullptr)
static bool isEquality(Predicate Pred)
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
AtomicOrdering getFailureOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:590
void setDoesNotThrow()
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler ...
static bool classof(const Instruction *I)
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:870
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
ConstantIntTy * getCaseValue()
Resolves case value for current case.
unsigned HasDescriptor
Definition: Value.h:117
void getShuffleMask(SmallVectorImpl< int > &Result) const
Return the mask for this instruction as a vector of integers.
void setUnwindDest(BasicBlock *UnwindDest)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This instruction extracts a struct member or array element value from an aggregate value...
CatchPadInst * getCatchPad() const
Convenience accessors.
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
Get the attribute of a given kind at a position.
*p = old <signed v ? old : v
Definition: Instructions.h:699
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
static bool classof(const Value *V)
Value * getAggregateOperand()
static bool classof(const Instruction *I)
iterator_range< handler_iterator > handler_range
static bool classof(const Instruction *I)
Definition: Instructions.h:404
static bool classof(const Instruction *I)
Atomic ordering constants.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:1112
Type * getSourceElementType() const
Definition: Instructions.h:928
static bool classof(const Value *V)
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
size_t i
bool isVolatile() const
Return true if this is a store to a volatile memory location.
Definition: Instructions.h:336
SynchronizationScope getSynchScope() const
Definition: Instructions.h:366
ArrayRef< unsigned > getIndices() const
AttributeSet getAttributes() const
Return the parameter attributes for this invoke.
Various leaf nodes.
Definition: ISDOpcodes.h:60
void setCalledFunction(Value *Fn)
Set the function called.
void allocHungoffUses(unsigned N)
void setConvergent()
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, BasicBlock *InsertAtEnd)
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a invoke argument.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
void setOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this RMW.
Definition: Instructions.h:751
static bool classof(const Instruction *I)
void setAlignment(unsigned Align)
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
AtomicOrdering getSuccessOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:585
An instruction for ordering other memory operations.
Definition: Instructions.h:430
unsigned getSuccessorIndex() const
Returns TerminatorInst's successor index for current case successor.
ExtractElementInst * cloneImpl() const
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:504
PtrToIntInst * cloneImpl() const
Clone an identical PtrToIntInst.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
iterator_range< const_op_iterator > arg_operands() const
Iteration adapter for range-for loops.
void setSynchScope(SynchronizationScope xthread)
Specify whether this fence orders other operations with respect to all concurrently executing threads...
Definition: Instructions.h:475
This class represents zero extension of integer types.
unsigned getNumOperands() const
Definition: User.h:167
unsigned getNumSuccessors() const
bool hasFnAttr(StringRef Kind) const
Determine whether this call has the given attribute.
void setSuccessor(BasicBlock *S)
Sets the new successor for current case.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:978
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Value * getValue() const
Convenience accessor.
void setDoesNotReadMemory()
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
Definition: InstrTypes.h:1661
bool isSimple() const
Definition: Instructions.h:384
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:785
Value * getPointerOperand()
Gets the pointer operand.
This class represents a function call, abstracting a target machine's calling convention.
static bool classof(const Value *V)
void setOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this load.
Definition: Instructions.h:240
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
static bool classof(const Value *V)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:655
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static CallInst * Create(FunctionType *Ty, Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
*p = old <unsigned v ? old : v
Definition: Instructions.h:703
void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
Definition: Instructions.h:105
const_handler_range handlers() const
iteration adapter for range-for loops.
CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum)
Initializes case iterator for given SwitchInst and for given case number.
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
Definition: Instructions.h:543
*p = old >unsigned v ? old : v
Definition: Instructions.h:701
Attribute getAttribute(unsigned i, StringRef Kind) const
Get the attribute of a given kind at a position.
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
static bool classof(const Value *V)
static bool classof(const Value *V)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles, const Twine &NameStr, BasicBlock *InsertAtEnd)
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:896
bool doesNotThrow() const
Determine if the call cannot unwind.
static bool classof(const Instruction *I)
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
unsigned getNumIndices() const
void setSuccessor(unsigned i, BasicBlock *NewSucc)
void setSuccessor(BasicBlock *NewSucc)
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
This class represents a sign extension of integer types.
An instruction for reading from memory.
Definition: Instructions.h:164
static bool classof(const Value *V)
static bool classof(const Value *V)
CleanupPadInst * getCleanupPad() const
Convenience accessor.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:905
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:669
void setAddress(Value *V)
Hexagon Common GEP
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles, const Twine &NameStr, BasicBlock *InsertAtEnd)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB, BasicBlock *InsertAtEnd)
LoadInst(Value *Ptr, const char *NameStr=nullptr, bool isVolatile=false, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:209
CaseIt(SwitchInst *SI, unsigned CaseNum)
static Instruction * CreateFree(Value *Source, Instruction *InsertBefore)
Generate the IR for a call to the builtin free function.
static bool classof(const Value *V)
This defines the Use class.
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
handler_iterator handler_begin()
Returns an iterator that points to the first handler in CatchSwitchInst.
static bool classof(const Instruction *I)
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr, BasicBlock *InsertAtEnd)
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:994
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
SExtInst * cloneImpl() const
Clone an identical SExtInst.
static bool classof(const Instruction *I)
const Value * getPointerOperand() const
Definition: Instructions.h:778
bool isSimple() const
Definition: Instructions.h:263
*p = old >signed v ? old : v
Definition: Instructions.h:697
void setSynchScope(SynchronizationScope SynchScope)
Specify whether this cmpxchg is atomic and orders other operations with respect to all concurrently e...
Definition: Instructions.h:579
unsigned getSrcAddressSpace() const
Returns the address space of the pointer operand.
bool doesNotReturn() const
Determine if the call cannot return.
unsigned getNumIndices() const
static bool classof(const Instruction *I)
op_iterator op_begin()
Definition: User.h:205
Value * removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true)
ConstantInt * findCaseDest(BasicBlock *BB)
Finds the unique case value for a given successor.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, BasicBlock *InsertAtEnd)
void setCanReturnTwice()
Constant * getMask() const
void setAttributes(AttributeSet Attrs)
Set the parameter attributes for this invoke.
FPExtInst * cloneImpl() const
Clone an identical FPExtInst.
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BasicBlock *InsertAtEnd)
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
Definition: Instructions.h:742
bool hasIndices() const
block_iterator block_end()
static bool classof(const Instruction *I)
BasicBlock *const * const_block_iterator
void setCallingConv(CallingConv::ID CC)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd)
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
ArrayRef< unsigned > getIndices() const
bool isFnAttrDisallowedByOpBundle(StringRef S) const
Is the function attribute S disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1513
static bool classof(const Instruction *I)
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:891
void setSynchScope(SynchronizationScope xthread)
Specify whether this load is ordered with respect to all concurrently executing threads, or only with respect to signal handlers executing in the same thread.
Definition: Instructions.h:252
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
static unsigned getOperandNumForIncomingValue(unsigned i)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock *InsertAtEnd)
Definition: Instructions.h:873
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:890
bool isUnconditional() const
This class represents a conversion between pointers from one address space to another.
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
static Value * getPointerOperand(Instruction &Inst)
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:588
This class represents the LLVM 'select' instruction.
IntToPtrInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Value *V)
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void setCleanupPad(CleanupPadInst *CleanupPad)
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:578
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool isUnordered() const
Definition: Instructions.h:264
CallInst * cloneImpl() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Instruction *I)
bool doesNotReturn() const
Determine if the call cannot return.
static bool classof(const Value *V)
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
void setSynchScope(SynchronizationScope xthread)
Specify whether this store instruction is ordered with respect to all concurrently executing threads...
Definition: Instructions.h:373
static bool classof(const Value *V)
void setOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this fence.
Definition: Instructions.h:463
bool onlyAccessesArgMemory() const
Determine if the call access memmory only using it's pointer arguments.
void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
PtrToIntInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
unsigned getNumArgOperands() const
Return the number of call arguments.
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
VectorType * getVectorOperandType() const
unsigned getNumIndices() const
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
UIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: InstrTypes.h:1363
FCmpInst * cloneImpl() const
Clone an identical FCmpInst.
SynchronizationScope
Definition: Instructions.h:50
bool isCommutative() const
bool isMustTailCall() const
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setCalledFunction(FunctionType *FTy, Value *Fn)
Value * getTrueValue()
FPToUIInst * cloneImpl() const
Clone an identical FPToUIInst.
Value * getPointerOperand()
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition: Instructions.h:973
block_iterator block_begin()
unsigned getNumSuccessors() const
Value * getFalseValue()
BasicBlock * getDestination(unsigned i)
Return the specified destination.
iterator_range< ConstCaseIt > cases() const
Constant iteration adapter for range-for loops.
static bool classof(const Instruction *I)
SynchronizationScope getSynchScope() const
Definition: Instructions.h:245
This class represents a cast from a pointer to an integer.
AtomicOrdering
Atomic ordering for LLVM's memory model.
bool doesNotThrow() const
Determine if the call cannot unwind.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:399
void setUnwindDest(BasicBlock *B)
UIToFPInst * cloneImpl() const
Clone an identical UIToFPInst.
~AllocaInst() override
const_op_iterator idx_end() const
Definition: Instructions.h:959
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: Instructions.h:257
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Class to represent function types.
Definition: DerivedTypes.h:102
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
Definition: Instructions.h:537
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
Definition: Instructions.h:767
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:891
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr, BasicBlock *InsertAtEnd)
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
#define F(x, y, z)
Definition: MD5.cpp:51
static bool classof(const Instruction *I)
BitCastInst * cloneImpl() const
Clone an identical BitCastInst.
void setNotConvergent()
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Definition: Instructions.h:280
VectorType * getType() const
Overload to return most specific vector type.
bool isNoInline() const
Return true if the call should not be inlined.
void setValue(ConstantInt *V)
Sets the new value for current case.
op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:681
void setNormalDest(BasicBlock *B)
bool doesNotAccessMemory() const
Determine if the call does not access memory.
void mutateFunctionType(FunctionType *FTy)
const unsigned * idx_iterator
CaseIteratorT< const SwitchInst, const ConstantInt, const BasicBlock > ConstCaseIt
CaseIt(const ParentTy &Src)
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, Instruction *InsertBefore=nullptr)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
static bool classof(const Value *V)
This instruction compares its operands according to the predicate given to the constructor.
idx_iterator idx_end() const
BasicBlock * getSuccessor(unsigned i) const
static bool classof(const Value *V)
static bool classof(const Value *V)
This class represents a no-op cast from one type to another.
BasicBlock * getIncomingBlock(const Use &U) const
Return incoming basic block corresponding to an operand of the PHI.
op_iterator idx_begin()
Definition: Instructions.h:956
StoreInst * cloneImpl() const
bool hasFnAttr(StringRef Kind) const
Determine whether this call has the given attribute.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Value * getInsertedValueOperand()
Used to keep track of an operand bundle.
Definition: InstrTypes.h:1541
unsigned getNumSuccessors() const
const Value * getInsertedValueOperand() const
void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes.
SIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
static bool classof(const Value *V)
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
FPToSIInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void setInstructionSubclassData(unsigned short D)
Definition: Instruction.h:583
An instruction for storing to memory.
Definition: Instructions.h:300
friend class Instruction
This class represents a cast from floating point to signed integer.
const_handler_iterator handler_begin() const
Returns an iterator that points to the first handler in the CatchSwitchInst.
BasicBlock * getIncomingBlock(Value::const_user_iterator I) const
Return incoming basic block corresponding to value use iterator.
bool isNoTailCall() const
const Value * getPointerOperand() const
Gets the pointer operand.
static bool classof(const Value *V)
Definition: Instructions.h:146
BasicBlock * getSuccessor() const
handler_range handlers()
iteration adapter for range-for loops.
ICmpInst(BasicBlock &InsertAtEnd, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insert-at-end semantics.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.cpp:44
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
int Switch(int a)
Definition: Switch2Test.cpp:11
bool cannotDuplicate() const
Determine if the invoke cannot be duplicated.
This class represents a truncation of integer types.
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
bool hasByValArgument() const
Determine if any call argument is an aggregate passed by value.
Value * getCalledValue()
BasicBlock * getNormalDest() const
unsigned getNumSuccessors() const
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
Definition: Casting.h:221
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
Class to represent pointers.
Definition: DerivedTypes.h:443
void setAttributes(AttributeSet Attrs)
Set the parameter attributes for this call.
OtherOps getOpcode() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
FPTruncInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
void setUnwindDest(BasicBlock *NewDest)
SIToFPInst * cloneImpl() const
Clone an identical SIToFPInst.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:830
LoadInst * cloneImpl() const
static bool classof(const Instruction *I)
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
static bool classof(const Value *V)
static unsigned getPointerOperandIndex()
Definition: Instructions.h:602
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:395
This instruction inserts a single (scalar) element into a VectorType value.
void setParentPad(Value *ParentPad)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
void setDoesNotAccessMemory()
VAArgInst(Value *List, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:348
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:52
unsigned getCaseIndex() const
Returns number of current case.
SynchronizationScope getSynchScope() const
Returns whether this RMW is atomic between threads or only within a single thread.
Definition: Instructions.h:773
static unsigned getAggregateOperandIndex()
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
iterator_range< idx_iterator > indices() const
PointerIntPair - This class implements a pair of a pointer and small integer.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
static unsigned getPointerOperandIndex()
Definition: Instructions.h:396
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
const_handler_iterator handler_end() const
Returns an iterator that points one past the last handler in the CatchSwitchInst. ...
Conditional or Unconditional Branch instruction.
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:219
const Value * getAggregateOperand() const
bool isEquality() const
Return true if this predicate is either EQ or NE.
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
This function has undefined behavior.
This is an important base class in LLVM.
Definition: Constant.h:42
PointerType * getType() const
Overload to return most specific pointer type.
Definition: Instructions.h:97
const Value * getCondition() const
Resume the propagation of an exception.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
void setFailureOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:569
void setDoesNotReadMemory()
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
Definition: Instructions.h:126
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
void setCalledFunction(FunctionType *FTy, Value *Fn)
Indirect Branch Instruction.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:109
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock *InsertAtEnd)
static bool classof(const Value *V)
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr, BasicBlock *InsertAtEnd)
op_iterator op_end()
Definition: User.h:207
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const unsigned * idx_iterator
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock *InsertAtEnd)
Definition: Instructions.h:915
static unsigned getPointerOperandIndex()
uint32_t Offset
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
static bool classof(const Value *V)
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instructions.h:121
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:899
This instruction compares its operands according to the predicate given to the constructor.
const Value * getValueOperand() const
Definition: Instructions.h:392
bool unwindsToCaller() const
bool doesNotAccessMemory() const
Determine if the call does not access memory.
User * getUser() const
Returns the User that contains this Use.
Definition: Use.cpp:41
Value * getOperand(unsigned i) const
Definition: User.h:145
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:889
Value * getPointerOperand()
Definition: Instructions.h:270
void setIsNoInline()
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock *InsertAtEnd)
static bool classof(const Value *V)
CatchSwitchInst * getCatchSwitch() const
Convenience accessors.
op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
iterator_range< block_iterator > blocks()
iterator_range< const_op_iterator > arg_operands() const
Iteration adapter for range-for loops.
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:960
static bool classof(const Value *V)
static Type * getGEPReturnType(Type *ElTy, Value *Ptr, ArrayRef< Value * > IdxList)
Definition: Instructions.h:989
bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i has the attribute A.
bool isUnordered() const
Definition: Instructions.h:385
void setTailCallKind(TailCallKind TCK)
void setSourceElementType(Type *Ty)
Definition: Instructions.h:930
void setAlignment(unsigned Align)
This class represents a cast from an integer to a pointer.
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:897
Value * getCondition()
static CallInst * Create(FunctionType *Ty, Value *Func, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
CaseIteratorT< SwitchInstTy, ConstantIntTy, BasicBlockTy > Self
static bool classof(const Value *V)
Definition: Instructions.h:407
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
void setTailCall(bool isTC=true)
FunctionType * getFunctionType() const
std::pointer_to_unary_function< const Value *, const BasicBlock * > ConstDerefFnTy
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
FPToUIInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:48
static bool classof(const Instruction *I)
bool unwindsToCaller() const
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: Instructions.h:378
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd)
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
static unsigned getIncomingValueNumForOperand(unsigned i)
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
bool isNoInline() const
Return true if the call should not be inlined.
static bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
const Value * getTrueValue() const
static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex)
Initializes case iterator for given SwitchInst and for given TerminatorInst's successor index...
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock *InsertAtEnd)
ConstCaseIt case_end() const
Returns a read-only iterator that points one past the last in the SwitchInst.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:857
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned Idx) const
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
unsigned getNumSuccessors() const
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
FunctionType * getFunctionType() const
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
bool operator!=(const Self &RHS) const
static bool classof(const Instruction *I)
Definition: Instructions.h:639
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
~CallInst() override
BasicBlock * getSuccessor(unsigned i) const
Attribute getAttribute(unsigned i, StringRef Kind) const
Get the attribute of a given kind at a position.
static bool classof(const Value *V)
Definition: Instructions.h:484
hexagon gen pred
FCmpInst(Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with no-insertion semantics.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
Definition: Instructions.h:940
void setOnlyAccessesArgMemory()
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success...
Definition: Instructions.h:623
bool hasByValArgument() const
Determine if any call argument is an aggregate passed by value.
TruncInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
BasicBlock * getUnwindDest() const
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, BasicBlock *InsertAtEnd)
bool isConditional() const
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
BasicBlock * getUnwindDest() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
idx_iterator idx_begin() const
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile=false, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:178
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
Value * getValOperand()
Definition: Instructions.h:781
static bool classof(const Instruction *I)
static bool classof(const Value *V)
BasicBlock * getUnwindDest() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
Definition: Instructions.h:355
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Definition: Instructions.h:132
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
static bool classof(const Instruction *I)
void setIncomingBlock(unsigned i, BasicBlock *BB)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static bool classof(const Instruction *I)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
AtomicCmpXchgInst * cloneImpl() const
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers...
Definition: Instructions.h:984
static bool classof(const Instruction *I)
Definition: Instructions.h:790
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
AddrSpaceCastInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
Type * checkGEPType(Type *Ty)
Definition: Instructions.h:822
unsigned getDestAddressSpace() const
Returns the address space of the result.
bool doesNotAlias(unsigned n) const
Determine if the parameter or return value is marked with NoAlias attribute.
unsigned getNumSuccessors() const
const BasicBlock * getDestination(unsigned i) const
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
static bool classof(const Instruction *I)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Use & getArgOperandUse(unsigned i)
ConstCaseIt case_begin() const
Returns a read-only iterator that points to the first case in the SwitchInst.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
const Value * getCompareOperand() const
Definition: Instructions.h:605
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void mutateFunctionType(FunctionType *FTy)
const Value * getValOperand() const
Definition: Instructions.h:782
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore)
TailCallKind getTailCallKind() const
op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instructions.h:218
always inline
bool isEquality() const
This class represents a cast from floating point to unsigned integer.
Value * getCatchSwitchParentPad() const
Get the parentPad of this catchret's catchpad's catchswitch.
BasicBlockTy * getCaseSuccessor()
Resolves successor for current case.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setCannotDuplicate()
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition: InstrTypes.h:1000
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
Definition: Instructions.h:234
const Value * getAggregateOperand() const
static bool classof(const Instruction *I)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
SExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
bool isConvergent() const
Determine if the call is convergent.
ZExtInst * cloneImpl() const
Clone an identical ZExtInst.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:275
CaseIt findCaseValue(const ConstantInt *C)
Search all of the case values for the specified constant.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
BinOp getOperation() const
Definition: Instructions.h:724
static bool classof(const Instruction *I)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:965
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
FCmpInst(BasicBlock &InsertAtEnd, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insert-at-end semantics.
void setOperand(unsigned i, Value *Val)
Definition: User.h:150
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:586
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
SynchronizationScope getSynchScope() const
Definition: Instructions.h:468
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
A range adaptor for a pair of iterators.
Class to represent vector types.
Definition: DerivedTypes.h:369
BasicBlock ** block_iterator
void setVolatile(bool V)
Specify whether this is a volatile store or not.
Definition: Instructions.h:339
Class for arbitrary precision integers.
Definition: APInt.h:77
static bool classof(const Instruction *I)
static bool classof(const Value *V)
static bool classof(const Value *V)
ConstCaseIt findCaseValue(const ConstantInt *C) const
const Value * getPointerOperand() const
Value * getReturnedArgOperand() const
If one of the arguments has the 'returned' attribute, return its operand value.
VAArgInst(Value *List, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
void setWeak(bool IsWeak)
Definition: Instructions.h:553
void setResultElementType(Type *Ty)
Definition: Instructions.h:931
bool isCommutative() const
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:438
static bool classof(const Value *V)
ZExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static ReturnInst * Create(LLVMContext &C, BasicBlock *InsertAtEnd)
idx_iterator idx_end() const
bool hasStructRetAttr() const
Determine if the call returns a structure through first pointer argument.
FCmpInst(Instruction *InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insert-before-instruction semantics.
static ResumeInst * Create(Value *Exn, BasicBlock *InsertAtEnd)
Value * getCondition() const
BitCastInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
bool isInlineAsm() const
Check if this call is an inline asm statement.
void setCondition(Value *V)
static CallInst * Create(Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
Definition: Instructions.h:137
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
static Instruction * CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize=nullptr, Function *MallocF=nullptr, const Twine &Name="")
Generate the IR for a call to malloc:
unsigned getNumSuccessors() const
const Value * getNewValOperand() const
Definition: Instructions.h:608
Value * getParentPad() const
AllocaInst * cloneImpl() const
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, AtomicOrdering Order, SynchronizationScope SynchScope=CrossThread, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:192
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
static bool classof(const Value *V)
Definition: Instructions.h:283
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr, BasicBlock *InsertAtEnd)
void setOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this store.
Definition: Instructions.h:361
ConstCaseIt case_default() const
void setCalledFunction(Value *Fn)
Set the function called.
bool isConvergent() const
Determine if the invoke is convergent.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th invoke argument.
BasicBlock * getSuccessor(unsigned idx) const
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:341
Value * getCondition() const
Value * getPointerOperand()
Gets the pointer operand.
BasicBlock * getDefaultDest() const
void setTrueValue(Value *V)
void setArgOperand(unsigned i, Value *v)
void setDoesNotAccessMemory()
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
unsigned getNumSuccessors() const
void setCondition(Value *V)
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
Definition: Instructions.h:457
CatchReturnInst * cloneImpl() const
const_op_iterator arg_end() const
Return the iterator pointing to the end of the argument list.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:227
void setOperation(BinOp Operation)
Definition: Instructions.h:728
Value * getPointerOperand()
Definition: Instructions.h:777
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
void setOnlyAccessesArgMemory()
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
Get the attribute of a given kind at a position.
const NodeList & List
Definition: RDFGraph.cpp:205
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
const Value * getIndexOperand() const
static ReturnInst * Create(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
iterator_range< const_block_iterator > blocks() const
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
void setArgOperand(unsigned i, Value *v)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock *InsertAtEnd)
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
static bool classof(const Value *V)
This class represents a cast unsigned integer to floating point.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock *InsertAtEnd)
Definition: Instructions.h:908
static bool classof(const Value *V)
Definition: Instructions.h:793
static bool classof(const Value *V)
bool isTailCall() const
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:888
Compile-time customization of User operands.
Definition: User.h:43
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
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:287
This instruction extracts a single (scalar) element from a VectorType value.
static bool classof(const Value *V)
void setFalseValue(Value *V)
unsigned getNumSuccessors() const
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
VectorType * getType() const
Overload to return most specific vector type.
IntToPtrInst * cloneImpl() const
Clone an identical IntToPtrInst.
static bool classof(const Instruction *I)
static unsigned getPointerOperandIndex()
Definition: Instructions.h:779
void setOnlyReadsMemory()
const Value * getVectorOperand() const
CaseIt case_default()
Returns an iterator that points to the default case.
ICmpInst(Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with no-insertion semantics.
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
const_op_iterator arg_begin() const
Return the iterator pointing to the beginning of the argument list.
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
bool hasUnwindDest() const
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:558
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setCatchSwitch(Value *CatchSwitch)
bool doesNotAlias(unsigned n) const
Determine if the parameter or return value is marked with NoAlias attribute.
void setDoesNotReturn()
static CallInst * Create(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd)
static Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
void reserveClauses(unsigned Size)
Grow the size of the operand list to accommodate the new number of clauses.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
bool hasUnwindDest() const
static bool classof(const Value *V)
std::pointer_to_unary_function< Value *, BasicBlock * > DerefFnTy
static bool classof(const Value *V)
Definition: Instructions.h:642
void setCondition(Value *V)
const_block_iterator block_begin() const
Use & getArgOperandUse(unsigned i)
const unsigned Kind
Multiway switch.
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
static unsigned getPointerOperandIndex()
Definition: Instructions.h:272
const Value * getPointerOperand() const
Definition: Instructions.h:601
This class represents a cast from signed integer to floating point.
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
Definition: Instructions.h:549
GetElementPtrInst * cloneImpl() const
Type * getReturnType() const
Definition: DerivedTypes.h:123
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
handler_iterator handler_end()
Returns a read-only iterator that points one past the last handler in the CatchSwitchInst.
iterator_range< idx_iterator > indices() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:611
This class represents a truncation of floating point types.
const Value * getPointerOperand() const
Gets the pointer operand.
const_op_iterator arg_begin() const
Return the iterator pointing to the beginning of the argument list.
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
void setSuccessOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this cmpxchg.
Definition: Instructions.h:562
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:883
LLVM Value Representation.
Definition: Value.h:71
void setAlignment(unsigned Align)
FPExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static unsigned getAggregateOperandIndex()
FPToSIInst * cloneImpl() const
Clone an identical FPToSIInst.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:111
void setDefaultDest(BasicBlock *DefaultCase)
void setOnlyReadsMemory()
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
Definition: OperandTraits.h:93
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:631
void allocHungoffUses(unsigned N, bool IsPhi=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition: User.cpp:43
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
bool hasIndices() const
const Value * getArraySize() const
Get the number of elements allocated.
Definition: Instructions.h:93
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
bool hasIndices() const
void setCallingConv(CallingConv::ID CC)
bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const
Determine whether the call or the callee has the given attributes.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Invoke instruction.
void setSynchScope(SynchronizationScope SynchScope)
Specify whether this RMW orders other operations with respect to all concurrently executing threads...
Definition: Instructions.h:761
static bool classof(const Instruction *I)
Definition: Instructions.h:481
TruncInst * cloneImpl() const
Clone an identical TruncInst.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
const Value * getFalseValue() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
const_block_iterator block_end() const
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SynchronizationScope SynchScope, Instruction *InsertBefore=nullptr)
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:31
ICmpInst(Instruction *InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insert-before-instruction semantics.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
Use & Op()
Definition: User.h:117
mapped_iterator< const_op_iterator, ConstDerefFnTy > const_handler_iterator
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
idx_iterator idx_begin() const
static bool classof(const Value *V)
const_op_range incoming_values() const
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:66
int * Ptr
void setIncomingValue(unsigned i, Value *V)
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static bool classof(const Value *V)
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:102
op_range incoming_values()
This class represents an extension of floating point types.
bool isRelational() const
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Definition: Instructions.h:221
SynchronizationScope getSynchScope() const
Returns whether this cmpxchg is atomic between threads or only within a single thread.
Definition: Instructions.h:596
const Value * getPointerOperand() const
Definition: Instructions.h:395
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:479
void setCannotDuplicate()
FPTruncInst * cloneImpl() const
Clone an identical FPTruncInst.
unsigned getNumArgOperands() const
Return the number of invoke arguments.
InsertValueInst * cloneImpl() const
Value * getPointerOperand()
Definition: Instructions.h:394
unsigned getNumSuccessors() const
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
const Value * getPointerOperand() const
Definition: Instructions.h:964
Value * getCalledValue()
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Type * getResultElementType() const
Definition: Instructions.h:933
static unsigned getPointerOperandIndex()
Definition: Instructions.h:967
A mixin to add operand bundle functionality to llvm instruction classes.
Definition: InstrTypes.h:1333
const_op_iterator arg_end() const
Return the iterator pointing to the end of the argument list.
const_op_iterator idx_begin() const
Definition: Instructions.h:957
SmallVector< int, 16 > getShuffleMask() const
void addDereferenceableAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
0 0 0 0 Always false (always folded)
Definition: InstrTypes.h:882
bool canReturnTwice() const
Return true if the call can return twice.
static bool classof(const Value *V)
AddrSpaceCastInst * cloneImpl() const
Clone an identical AddrSpaceCastInst.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd)
an instruction to allocate memory on the stack
Definition: Instructions.h:60
static bool classof(const Instruction *I)
This instruction inserts a struct field of array element value into an aggregate value.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67
bool operator==(const Self &RHS) const
void setCatchPad(CatchPadInst *CatchPad)
bool isVolatile() const
Return true if this is a RMW on a volatile memory location.
Definition: Instructions.h:736
static bool classof(const Instruction *I)
Definition: Instructions.h:143
const Value * getPointerOperand() const
Definition: Instructions.h:271
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:184
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...