LLVM  3.7.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"
20 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/InstrTypes.h"
28 #include <iterator>
29 
30 namespace llvm {
31 
32 class APInt;
33 class ConstantInt;
34 class ConstantRange;
35 class DataLayout;
36 class LLVMContext;
37 
39  NotAtomic = 0,
40  Unordered = 1,
41  Monotonic = 2,
42  // Consume = 3, // Not specified yet.
43  Acquire = 4,
44  Release = 5,
47 };
48 
52 };
53 
54 /// Returns true if the ordering is at least as strong as acquire
55 /// (i.e. acquire, acq_rel or seq_cst)
56 inline bool isAtLeastAcquire(AtomicOrdering Ord) {
57  return (Ord == Acquire ||
58  Ord == AcquireRelease ||
59  Ord == SequentiallyConsistent);
60 }
61 
62 /// Returns true if the ordering is at least as strong as release
63 /// (i.e. release, acq_rel or seq_cst)
64 inline bool isAtLeastRelease(AtomicOrdering Ord) {
65 return (Ord == Release ||
66  Ord == AcquireRelease ||
67  Ord == SequentiallyConsistent);
68 }
69 
70 //===----------------------------------------------------------------------===//
71 // AllocaInst Class
72 //===----------------------------------------------------------------------===//
73 
74 /// AllocaInst - an instruction to allocate memory on the stack
75 ///
76 class AllocaInst : public UnaryInstruction {
77  Type *AllocatedType;
78 
79 protected:
80  // Note: Instruction needs to be a friend here to call cloneImpl.
81  friend class Instruction;
82  AllocaInst *cloneImpl() const;
83 
84 public:
85  explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
86  const Twine &Name = "",
87  Instruction *InsertBefore = nullptr);
88  AllocaInst(Type *Ty, Value *ArraySize,
89  const Twine &Name, BasicBlock *InsertAtEnd);
90 
91  AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
92  AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
93 
94  AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
95  const Twine &Name = "", Instruction *InsertBefore = nullptr);
96  AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
97  const Twine &Name, BasicBlock *InsertAtEnd);
98 
99  // Out of line virtual method, so the vtable, etc. has a home.
100  ~AllocaInst() override;
101 
102  /// isArrayAllocation - Return true if there is an allocation size parameter
103  /// to the allocation instruction that is not 1.
104  ///
105  bool isArrayAllocation() const;
106 
107  /// getArraySize - Get the number of elements allocated. For a simple
108  /// allocation of a single element, this will return a constant 1 value.
109  ///
110  const Value *getArraySize() const { return getOperand(0); }
111  Value *getArraySize() { return getOperand(0); }
112 
113  /// getType - Overload to return most specific pointer type
114  ///
115  PointerType *getType() const {
116  return cast<PointerType>(Instruction::getType());
117  }
118 
119  /// getAllocatedType - Return the type that is being allocated by the
120  /// instruction.
121  ///
122  Type *getAllocatedType() const { return AllocatedType; }
123  /// \brief for use only in special circumstances that need to generically
124  /// transform a whole instruction (eg: IR linking and vectorization).
125  void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
126 
127  /// getAlignment - Return the alignment of the memory that is being allocated
128  /// by the instruction.
129  ///
130  unsigned getAlignment() const {
131  return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
132  }
133  void setAlignment(unsigned Align);
134 
135  /// isStaticAlloca - Return true if this alloca is in the entry block of the
136  /// function and is a constant size. If so, the code generator will fold it
137  /// into the prolog/epilog code, so it is basically free.
138  bool isStaticAlloca() const;
139 
140  /// \brief Return true if this alloca is used as an inalloca argument to a
141  /// call. Such allocas are never considered static even if they are in the
142  /// entry block.
143  bool isUsedWithInAlloca() const {
144  return getSubclassDataFromInstruction() & 32;
145  }
146 
147  /// \brief Specify whether this alloca is used to represent the arguments to
148  /// a call.
149  void setUsedWithInAlloca(bool V) {
150  setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
151  (V ? 32 : 0));
152  }
153 
154  // Methods for support type inquiry through isa, cast, and dyn_cast:
155  static inline bool classof(const Instruction *I) {
156  return (I->getOpcode() == Instruction::Alloca);
157  }
158  static inline bool classof(const Value *V) {
159  return isa<Instruction>(V) && classof(cast<Instruction>(V));
160  }
161 private:
162  // Shadow Instruction::setInstructionSubclassData with a private forwarding
163  // method so that subclasses cannot accidentally use it.
164  void setInstructionSubclassData(unsigned short D) {
166  }
167 };
168 
169 
170 //===----------------------------------------------------------------------===//
171 // LoadInst Class
172 //===----------------------------------------------------------------------===//
173 
174 /// LoadInst - an instruction for reading from memory. This uses the
175 /// SubclassData field in Value to store whether or not the load is volatile.
176 ///
177 class LoadInst : public UnaryInstruction {
178  void AssertOK();
179 protected:
180  // Note: Instruction needs to be a friend here to call cloneImpl.
181  friend class Instruction;
182  LoadInst *cloneImpl() const;
183 
184 public:
185  LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
186  LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
187  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
188  Instruction *InsertBefore = nullptr);
189  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
190  Instruction *InsertBefore = nullptr)
191  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
192  NameStr, isVolatile, InsertBefore) {}
193  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
194  BasicBlock *InsertAtEnd);
195  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
196  Instruction *InsertBefore = nullptr)
197  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
198  NameStr, isVolatile, Align, InsertBefore) {}
199  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
200  unsigned Align, Instruction *InsertBefore = nullptr);
201  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
202  unsigned Align, BasicBlock *InsertAtEnd);
203  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
204  AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread,
205  Instruction *InsertBefore = nullptr)
206  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
207  NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {}
208  LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
209  unsigned Align, AtomicOrdering Order,
210  SynchronizationScope SynchScope = CrossThread,
211  Instruction *InsertBefore = nullptr);
212  LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
213  unsigned Align, AtomicOrdering Order,
214  SynchronizationScope SynchScope,
215  BasicBlock *InsertAtEnd);
216 
217  LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
218  LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
219  LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
220  bool isVolatile = false, Instruction *InsertBefore = nullptr);
221  explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
222  bool isVolatile = false,
223  Instruction *InsertBefore = nullptr)
224  : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
225  NameStr, isVolatile, InsertBefore) {}
226  LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
227  BasicBlock *InsertAtEnd);
228 
229  /// isVolatile - Return true if this is a load from a volatile memory
230  /// location.
231  ///
232  bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
233 
234  /// setVolatile - Specify whether this is a volatile load or not.
235  ///
236  void setVolatile(bool V) {
237  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
238  (V ? 1 : 0));
239  }
240 
241  /// getAlignment - Return the alignment of the access that is being performed
242  ///
243  unsigned getAlignment() const {
244  return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
245  }
246 
247  void setAlignment(unsigned Align);
248 
249  /// Returns the ordering effect of this fence.
251  return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
252  }
253 
254  /// Set the ordering constraint on this load. May not be Release or
255  /// AcquireRelease.
256  void setOrdering(AtomicOrdering Ordering) {
257  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
258  (Ordering << 7));
259  }
260 
263  }
264 
265  /// Specify whether this load is ordered with respect to all
266  /// concurrently executing threads, or only with respect to signal handlers
267  /// executing in the same thread.
269  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
270  (xthread << 6));
271  }
272 
273  void setAtomic(AtomicOrdering Ordering,
274  SynchronizationScope SynchScope = CrossThread) {
275  setOrdering(Ordering);
276  setSynchScope(SynchScope);
277  }
278 
279  bool isSimple() const { return !isAtomic() && !isVolatile(); }
280  bool isUnordered() const {
281  return getOrdering() <= Unordered && !isVolatile();
282  }
283 
285  const Value *getPointerOperand() const { return getOperand(0); }
286  static unsigned getPointerOperandIndex() { return 0U; }
287 
288  /// \brief Returns the address space of the pointer operand.
289  unsigned getPointerAddressSpace() const {
291  }
292 
293 
294  // Methods for support type inquiry through isa, cast, and dyn_cast:
295  static inline bool classof(const Instruction *I) {
296  return I->getOpcode() == Instruction::Load;
297  }
298  static inline bool classof(const Value *V) {
299  return isa<Instruction>(V) && classof(cast<Instruction>(V));
300  }
301 private:
302  // Shadow Instruction::setInstructionSubclassData with a private forwarding
303  // method so that subclasses cannot accidentally use it.
304  void setInstructionSubclassData(unsigned short D) {
306  }
307 };
308 
309 
310 //===----------------------------------------------------------------------===//
311 // StoreInst Class
312 //===----------------------------------------------------------------------===//
313 
314 /// StoreInst - an instruction for storing to memory
315 ///
316 class StoreInst : public Instruction {
317  void *operator new(size_t, unsigned) = delete;
318  void AssertOK();
319 protected:
320  // Note: Instruction needs to be a friend here to call cloneImpl.
321  friend class Instruction;
322  StoreInst *cloneImpl() const;
323 
324 public:
325  // allocate space for exactly two operands
326  void *operator new(size_t s) {
327  return User::operator new(s, 2);
328  }
329  StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
330  StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
331  StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
332  Instruction *InsertBefore = nullptr);
333  StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
334  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
335  unsigned Align, Instruction *InsertBefore = nullptr);
336  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
337  unsigned Align, BasicBlock *InsertAtEnd);
338  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
339  unsigned Align, AtomicOrdering Order,
340  SynchronizationScope SynchScope = CrossThread,
341  Instruction *InsertBefore = nullptr);
342  StoreInst(Value *Val, Value *Ptr, bool isVolatile,
343  unsigned Align, AtomicOrdering Order,
344  SynchronizationScope SynchScope,
345  BasicBlock *InsertAtEnd);
346 
347 
348  /// isVolatile - Return true if this is a store to a volatile memory
349  /// location.
350  ///
351  bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
352 
353  /// setVolatile - Specify whether this is a volatile store or not.
354  ///
355  void setVolatile(bool V) {
356  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
357  (V ? 1 : 0));
358  }
359 
360  /// Transparently provide more efficient getOperand methods.
362 
363  /// getAlignment - Return the alignment of the access that is being performed
364  ///
365  unsigned getAlignment() const {
366  return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
367  }
368 
369  void setAlignment(unsigned Align);
370 
371  /// Returns the ordering effect of this store.
373  return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
374  }
375 
376  /// Set the ordering constraint on this store. May not be Acquire or
377  /// AcquireRelease.
378  void setOrdering(AtomicOrdering Ordering) {
379  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
380  (Ordering << 7));
381  }
382 
385  }
386 
387  /// Specify whether this store instruction is ordered with respect to all
388  /// concurrently executing threads, or only with respect to signal handlers
389  /// executing in the same thread.
391  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
392  (xthread << 6));
393  }
394 
395  void setAtomic(AtomicOrdering Ordering,
396  SynchronizationScope SynchScope = CrossThread) {
397  setOrdering(Ordering);
398  setSynchScope(SynchScope);
399  }
400 
401  bool isSimple() const { return !isAtomic() && !isVolatile(); }
402  bool isUnordered() const {
403  return getOrdering() <= Unordered && !isVolatile();
404  }
405 
406  Value *getValueOperand() { return getOperand(0); }
407  const Value *getValueOperand() const { return getOperand(0); }
408 
410  const Value *getPointerOperand() const { return getOperand(1); }
411  static unsigned getPointerOperandIndex() { return 1U; }
412 
413  /// \brief Returns the address space of the pointer operand.
414  unsigned getPointerAddressSpace() const {
416  }
417 
418  // Methods for support type inquiry through isa, cast, and dyn_cast:
419  static inline bool classof(const Instruction *I) {
420  return I->getOpcode() == Instruction::Store;
421  }
422  static inline bool classof(const Value *V) {
423  return isa<Instruction>(V) && classof(cast<Instruction>(V));
424  }
425 private:
426  // Shadow Instruction::setInstructionSubclassData with a private forwarding
427  // method so that subclasses cannot accidentally use it.
428  void setInstructionSubclassData(unsigned short D) {
430  }
431 };
432 
433 template <>
434 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
435 };
436 
438 
439 //===----------------------------------------------------------------------===//
440 // FenceInst Class
441 //===----------------------------------------------------------------------===//
442 
443 /// FenceInst - an instruction for ordering other memory operations
444 ///
445 class FenceInst : public Instruction {
446  void *operator new(size_t, unsigned) = delete;
447  void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
448 protected:
449  // Note: Instruction needs to be a friend here to call cloneImpl.
450  friend class Instruction;
451  FenceInst *cloneImpl() const;
452 
453 public:
454  // allocate space for exactly zero operands
455  void *operator new(size_t s) {
456  return User::operator new(s, 0);
457  }
458 
459  // Ordering may only be Acquire, Release, AcquireRelease, or
460  // SequentiallyConsistent.
462  SynchronizationScope SynchScope = CrossThread,
463  Instruction *InsertBefore = nullptr);
465  SynchronizationScope SynchScope,
466  BasicBlock *InsertAtEnd);
467 
468  /// Returns the ordering effect of this fence.
470  return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
471  }
472 
473  /// Set the ordering constraint on this fence. May only be Acquire, Release,
474  /// AcquireRelease, or SequentiallyConsistent.
475  void setOrdering(AtomicOrdering Ordering) {
476  setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
477  (Ordering << 1));
478  }
479 
481  return SynchronizationScope(getSubclassDataFromInstruction() & 1);
482  }
483 
484  /// Specify whether this fence orders other operations with respect to all
485  /// concurrently executing threads, or only with respect to signal handlers
486  /// executing in the same thread.
488  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
489  xthread);
490  }
491 
492  // Methods for support type inquiry through isa, cast, and dyn_cast:
493  static inline bool classof(const Instruction *I) {
494  return I->getOpcode() == Instruction::Fence;
495  }
496  static inline bool classof(const Value *V) {
497  return isa<Instruction>(V) && classof(cast<Instruction>(V));
498  }
499 private:
500  // Shadow Instruction::setInstructionSubclassData with a private forwarding
501  // method so that subclasses cannot accidentally use it.
502  void setInstructionSubclassData(unsigned short D) {
504  }
505 };
506 
507 //===----------------------------------------------------------------------===//
508 // AtomicCmpXchgInst Class
509 //===----------------------------------------------------------------------===//
510 
511 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
512 /// specified value is in a memory location, and, if it is, stores a new value
513 /// there. Returns the value that was loaded.
514 ///
516  void *operator new(size_t, unsigned) = delete;
517  void Init(Value *Ptr, Value *Cmp, Value *NewVal,
518  AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
519  SynchronizationScope SynchScope);
520 protected:
521  // Note: Instruction needs to be a friend here to call cloneImpl.
522  friend class Instruction;
523  AtomicCmpXchgInst *cloneImpl() const;
524 
525 public:
526  // allocate space for exactly three operands
527  void *operator new(size_t s) {
528  return User::operator new(s, 3);
529  }
530  AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
531  AtomicOrdering SuccessOrdering,
532  AtomicOrdering FailureOrdering,
533  SynchronizationScope SynchScope,
534  Instruction *InsertBefore = nullptr);
535  AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
536  AtomicOrdering SuccessOrdering,
537  AtomicOrdering FailureOrdering,
538  SynchronizationScope SynchScope,
539  BasicBlock *InsertAtEnd);
540 
541  /// isVolatile - Return true if this is a cmpxchg from a volatile memory
542  /// location.
543  ///
544  bool isVolatile() const {
545  return getSubclassDataFromInstruction() & 1;
546  }
547 
548  /// setVolatile - Specify whether this is a volatile cmpxchg.
549  ///
550  void setVolatile(bool V) {
551  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
552  (unsigned)V);
553  }
554 
555  /// Return true if this cmpxchg may spuriously fail.
556  bool isWeak() const {
557  return getSubclassDataFromInstruction() & 0x100;
558  }
559 
560  void setWeak(bool IsWeak) {
561  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
562  (IsWeak << 8));
563  }
564 
565  /// Transparently provide more efficient getOperand methods.
567 
568  /// Set the ordering constraint on this cmpxchg.
570  assert(Ordering != NotAtomic &&
571  "CmpXchg instructions can only be atomic.");
572  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
573  (Ordering << 2));
574  }
575 
577  assert(Ordering != NotAtomic &&
578  "CmpXchg instructions can only be atomic.");
579  setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
580  (Ordering << 5));
581  }
582 
583  /// Specify whether this cmpxchg is atomic and orders other operations with
584  /// respect to all concurrently executing threads, or only with respect to
585  /// signal handlers executing in the same thread.
587  setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
588  (SynchScope << 1));
589  }
590 
591  /// Returns the ordering constraint on this cmpxchg.
593  return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
594  }
595 
596  /// Returns the ordering constraint on this cmpxchg.
598  return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
599  }
600 
601  /// Returns whether this cmpxchg is atomic between threads or only within a
602  /// single thread.
605  }
606 
608  const Value *getPointerOperand() const { return getOperand(0); }
609  static unsigned getPointerOperandIndex() { return 0U; }
610 
612  const Value *getCompareOperand() const { return getOperand(1); }
613 
615  const Value *getNewValOperand() const { return getOperand(2); }
616 
617  /// \brief Returns the address space of the pointer operand.
618  unsigned getPointerAddressSpace() const {
620  }
621 
622  /// \brief Returns the strongest permitted ordering on failure, given the
623  /// desired ordering on success.
624  ///
625  /// If the comparison in a cmpxchg operation fails, there is no atomic store
626  /// so release semantics cannot be provided. So this function drops explicit
627  /// Release requests from the AtomicOrdering. A SequentiallyConsistent
628  /// operation would remain SequentiallyConsistent.
629  static AtomicOrdering
631  switch (SuccessOrdering) {
632  default: llvm_unreachable("invalid cmpxchg success ordering");
633  case Release:
634  case Monotonic:
635  return Monotonic;
636  case AcquireRelease:
637  case Acquire:
638  return Acquire;
640  return SequentiallyConsistent;
641  }
642  }
643 
644  // Methods for support type inquiry through isa, cast, and dyn_cast:
645  static inline bool classof(const Instruction *I) {
646  return I->getOpcode() == Instruction::AtomicCmpXchg;
647  }
648  static inline bool classof(const Value *V) {
649  return isa<Instruction>(V) && classof(cast<Instruction>(V));
650  }
651 private:
652  // Shadow Instruction::setInstructionSubclassData with a private forwarding
653  // method so that subclasses cannot accidentally use it.
654  void setInstructionSubclassData(unsigned short D) {
656  }
657 };
658 
659 template <>
661  public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
662 };
663 
665 
666 //===----------------------------------------------------------------------===//
667 // AtomicRMWInst Class
668 //===----------------------------------------------------------------------===//
669 
670 /// AtomicRMWInst - an instruction that atomically reads a memory location,
671 /// combines it with another value, and then stores the result back. Returns
672 /// the old value.
673 ///
674 class AtomicRMWInst : public Instruction {
675  void *operator new(size_t, unsigned) = delete;
676 protected:
677  // Note: Instruction needs to be a friend here to call cloneImpl.
678  friend class Instruction;
679  AtomicRMWInst *cloneImpl() const;
680 
681 public:
682  /// This enumeration lists the possible modifications atomicrmw can make. In
683  /// the descriptions, 'p' is the pointer to the instruction's memory location,
684  /// 'old' is the initial value of *p, and 'v' is the other value passed to the
685  /// instruction. These instructions always return 'old'.
686  enum BinOp {
687  /// *p = v
689  /// *p = old + v
691  /// *p = old - v
693  /// *p = old & v
695  /// *p = ~(old & v)
697  /// *p = old | v
698  Or,
699  /// *p = old ^ v
701  /// *p = old >signed v ? old : v
703  /// *p = old <signed v ? old : v
705  /// *p = old >unsigned v ? old : v
707  /// *p = old <unsigned v ? old : v
709 
710  FIRST_BINOP = Xchg,
711  LAST_BINOP = UMin,
712  BAD_BINOP
713  };
714 
715  // allocate space for exactly two operands
716  void *operator new(size_t s) {
717  return User::operator new(s, 2);
718  }
719  AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
720  AtomicOrdering Ordering, SynchronizationScope SynchScope,
721  Instruction *InsertBefore = nullptr);
722  AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
723  AtomicOrdering Ordering, SynchronizationScope SynchScope,
724  BasicBlock *InsertAtEnd);
725 
726  BinOp getOperation() const {
727  return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
728  }
729 
730  void setOperation(BinOp Operation) {
731  unsigned short SubclassData = getSubclassDataFromInstruction();
732  setInstructionSubclassData((SubclassData & 31) |
733  (Operation << 5));
734  }
735 
736  /// isVolatile - Return true if this is a RMW on a volatile memory location.
737  ///
738  bool isVolatile() const {
739  return getSubclassDataFromInstruction() & 1;
740  }
741 
742  /// setVolatile - Specify whether this is a volatile RMW or not.
743  ///
744  void setVolatile(bool V) {
745  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
746  (unsigned)V);
747  }
748 
749  /// Transparently provide more efficient getOperand methods.
751 
752  /// Set the ordering constraint on this RMW.
753  void setOrdering(AtomicOrdering Ordering) {
754  assert(Ordering != NotAtomic &&
755  "atomicrmw instructions can only be atomic.");
756  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
757  (Ordering << 2));
758  }
759 
760  /// Specify whether this RMW orders other operations with respect to all
761  /// concurrently executing threads, or only with respect to signal handlers
762  /// executing in the same thread.
764  setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
765  (SynchScope << 1));
766  }
767 
768  /// Returns the ordering constraint on this RMW.
770  return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
771  }
772 
773  /// Returns whether this RMW is atomic between threads or only within a
774  /// single thread.
776  return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
777  }
778 
779  Value *getPointerOperand() { return getOperand(0); }
780  const Value *getPointerOperand() const { return getOperand(0); }
781  static unsigned getPointerOperandIndex() { return 0U; }
782 
783  Value *getValOperand() { return getOperand(1); }
784  const Value *getValOperand() const { return getOperand(1); }
785 
786  /// \brief Returns the address space of the pointer operand.
787  unsigned getPointerAddressSpace() const {
789  }
790 
791  // Methods for support type inquiry through isa, cast, and dyn_cast:
792  static inline bool classof(const Instruction *I) {
793  return I->getOpcode() == Instruction::AtomicRMW;
794  }
795  static inline bool classof(const Value *V) {
796  return isa<Instruction>(V) && classof(cast<Instruction>(V));
797  }
798 private:
799  void Init(BinOp Operation, Value *Ptr, Value *Val,
800  AtomicOrdering Ordering, SynchronizationScope SynchScope);
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 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
828 /// access elements of arrays and structs
829 ///
831  Type *SourceElementType;
832  Type *ResultElementType;
833 
835  void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
836 
837  /// Constructors - Create a getelementptr instruction with a base pointer an
838  /// list of indices. The first ctor can optionally insert before an existing
839  /// instruction, the second appends the new instruction to the specified
840  /// BasicBlock.
841  inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
842  ArrayRef<Value *> IdxList, unsigned Values,
843  const Twine &NameStr, Instruction *InsertBefore);
844  inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
845  ArrayRef<Value *> IdxList, unsigned Values,
846  const Twine &NameStr, BasicBlock *InsertAtEnd);
847 
848 protected:
849  // Note: Instruction needs to be a friend here to call cloneImpl.
850  friend class Instruction;
851  GetElementPtrInst *cloneImpl() const;
852 
853 public:
854  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
855  ArrayRef<Value *> IdxList,
856  const Twine &NameStr = "",
857  Instruction *InsertBefore = nullptr) {
858  unsigned Values = 1 + unsigned(IdxList.size());
859  if (!PointeeType)
860  PointeeType =
861  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
862  else
863  assert(
864  PointeeType ==
865  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
866  return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
867  NameStr, InsertBefore);
868  }
869  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
870  ArrayRef<Value *> IdxList,
871  const Twine &NameStr,
872  BasicBlock *InsertAtEnd) {
873  unsigned Values = 1 + unsigned(IdxList.size());
874  if (!PointeeType)
875  PointeeType =
876  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
877  else
878  assert(
879  PointeeType ==
880  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
881  return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
882  NameStr, InsertAtEnd);
883  }
884 
885  /// Create an "inbounds" getelementptr. See the documentation for the
886  /// "inbounds" flag in LangRef.html for details.
888  ArrayRef<Value *> IdxList,
889  const Twine &NameStr = "",
890  Instruction *InsertBefore = nullptr){
891  return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
892  }
893  static GetElementPtrInst *
894  CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
895  const Twine &NameStr = "",
896  Instruction *InsertBefore = nullptr) {
898  Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
899  GEP->setIsInBounds(true);
900  return GEP;
901  }
903  ArrayRef<Value *> IdxList,
904  const Twine &NameStr,
905  BasicBlock *InsertAtEnd) {
906  return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
907  }
908  static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
909  ArrayRef<Value *> IdxList,
910  const Twine &NameStr,
911  BasicBlock *InsertAtEnd) {
913  Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
914  GEP->setIsInBounds(true);
915  return GEP;
916  }
917 
918  /// Transparently provide more efficient getOperand methods.
920 
921  // getType - Overload to return most specific sequential type.
923  return cast<SequentialType>(Instruction::getType());
924  }
925 
926  Type *getSourceElementType() const { return SourceElementType; }
927 
928  void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
929  void setResultElementType(Type *Ty) { ResultElementType = Ty; }
930 
932  assert(ResultElementType ==
933  cast<PointerType>(getType()->getScalarType())->getElementType());
934  return ResultElementType;
935  }
936 
937  /// \brief Returns the address space of this instruction's pointer type.
938  unsigned getAddressSpace() const {
939  // Note that this is always the same as the pointer operand's address space
940  // and that is cheaper to compute, so cheat here.
941  return getPointerAddressSpace();
942  }
943 
944  /// getIndexedType - Returns the type of the element that would be loaded with
945  /// a load instruction with the specified parameters.
946  ///
947  /// Null is returned if the indices are invalid for the specified
948  /// pointer type.
949  ///
950  static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
951  static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
952  static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
953 
954  inline op_iterator idx_begin() { return op_begin()+1; }
955  inline const_op_iterator idx_begin() const { return op_begin()+1; }
956  inline op_iterator idx_end() { return op_end(); }
957  inline const_op_iterator idx_end() const { return op_end(); }
958 
960  return getOperand(0);
961  }
962  const Value *getPointerOperand() const {
963  return getOperand(0);
964  }
965  static unsigned getPointerOperandIndex() {
966  return 0U; // get index for modifying correct operand.
967  }
968 
969  /// getPointerOperandType - Method to return the pointer operand as a
970  /// PointerType.
972  return getPointerOperand()->getType();
973  }
974 
975  /// \brief Returns the address space of the pointer operand.
976  unsigned getPointerAddressSpace() const {
978  }
979 
980  /// GetGEPReturnType - Returns the pointer type returned by the GEP
981  /// instruction, which may be a vector of pointers.
982  static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
983  return getGEPReturnType(
984  cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
985  Ptr, IdxList);
986  }
987  static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
988  ArrayRef<Value *> IdxList) {
989  Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
990  Ptr->getType()->getPointerAddressSpace());
991  // Vector GEP
992  if (Ptr->getType()->isVectorTy()) {
993  unsigned NumElem = Ptr->getType()->getVectorNumElements();
994  return VectorType::get(PtrTy, NumElem);
995  }
996  for (Value *Index : IdxList)
997  if (Index->getType()->isVectorTy()) {
998  unsigned NumElem = Index->getType()->getVectorNumElements();
999  return VectorType::get(PtrTy, NumElem);
1000  }
1001  // Scalar GEP
1002  return PtrTy;
1003  }
1004 
1005  unsigned getNumIndices() const { // Note: always non-negative
1006  return getNumOperands() - 1;
1007  }
1008 
1009  bool hasIndices() const {
1010  return getNumOperands() > 1;
1011  }
1012 
1013  /// hasAllZeroIndices - Return true if all of the indices of this GEP are
1014  /// zeros. If so, the result pointer and the first operand have the same
1015  /// value, just potentially different types.
1016  bool hasAllZeroIndices() const;
1017 
1018  /// hasAllConstantIndices - Return true if all of the indices of this GEP are
1019  /// constant integers. If so, the result pointer and the first operand have
1020  /// a constant offset between them.
1021  bool hasAllConstantIndices() const;
1022 
1023  /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
1024  /// See LangRef.html for the meaning of inbounds on a getelementptr.
1025  void setIsInBounds(bool b = true);
1026 
1027  /// isInBounds - Determine whether the GEP has the inbounds flag.
1028  bool isInBounds() const;
1029 
1030  /// \brief Accumulate the constant address offset of this GEP if possible.
1031  ///
1032  /// This routine accepts an APInt into which it will accumulate the constant
1033  /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1034  /// all-constant, it returns false and the value of the offset APInt is
1035  /// undefined (it is *not* preserved!). The APInt passed into this routine
1036  /// must be at least as wide as the IntPtr type for the address space of
1037  /// the base GEP pointer.
1038  bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1039 
1040  // Methods for support type inquiry through isa, cast, and dyn_cast:
1041  static inline bool classof(const Instruction *I) {
1042  return (I->getOpcode() == Instruction::GetElementPtr);
1043  }
1044  static inline bool classof(const Value *V) {
1045  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1046  }
1047 };
1048 
1049 template <>
1051  public VariadicOperandTraits<GetElementPtrInst, 1> {
1052 };
1053 
1054 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1055  ArrayRef<Value *> IdxList, unsigned Values,
1056  const Twine &NameStr,
1057  Instruction *InsertBefore)
1058  : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1059  OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1060  Values, InsertBefore),
1061  SourceElementType(PointeeType),
1062  ResultElementType(getIndexedType(PointeeType, IdxList)) {
1063  assert(ResultElementType ==
1064  cast<PointerType>(getType()->getScalarType())->getElementType());
1065  init(Ptr, IdxList, NameStr);
1066 }
1067 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1068  ArrayRef<Value *> IdxList, unsigned Values,
1069  const Twine &NameStr,
1070  BasicBlock *InsertAtEnd)
1071  : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1072  OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1073  Values, InsertAtEnd),
1074  SourceElementType(PointeeType),
1075  ResultElementType(getIndexedType(PointeeType, IdxList)) {
1076  assert(ResultElementType ==
1077  cast<PointerType>(getType()->getScalarType())->getElementType());
1078  init(Ptr, IdxList, NameStr);
1079 }
1080 
1081 
1082 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1083 
1084 
1085 //===----------------------------------------------------------------------===//
1086 // ICmpInst Class
1087 //===----------------------------------------------------------------------===//
1088 
1089 /// This instruction compares its operands according to the predicate given
1090 /// to the constructor. It only operates on integers or pointers. The operands
1091 /// must be identical types.
1092 /// \brief Represent an integer comparison operator.
1093 class ICmpInst: public CmpInst {
1094  void AssertOK() {
1095  assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
1096  getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
1097  "Invalid ICmp predicate value");
1098  assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1099  "Both operands to ICmp instruction are not of the same type!");
1100  // Check that the operands are the right type
1101  assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1102  getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1103  "Invalid operand types for ICmp instruction");
1104  }
1105 
1106 protected:
1107  // Note: Instruction needs to be a friend here to call cloneImpl.
1108  friend class Instruction;
1109  /// \brief Clone an identical ICmpInst
1110  ICmpInst *cloneImpl() const;
1111 
1112 public:
1113  /// \brief Constructor with insert-before-instruction semantics.
1115  Instruction *InsertBefore, ///< Where to insert
1116  Predicate pred, ///< The predicate to use for the comparison
1117  Value *LHS, ///< The left-hand-side of the expression
1118  Value *RHS, ///< The right-hand-side of the expression
1119  const Twine &NameStr = "" ///< Name of the instruction
1120  ) : CmpInst(makeCmpResultType(LHS->getType()),
1121  Instruction::ICmp, pred, LHS, RHS, NameStr,
1122  InsertBefore) {
1123 #ifndef NDEBUG
1124  AssertOK();
1125 #endif
1126  }
1127 
1128  /// \brief Constructor with insert-at-end semantics.
1130  BasicBlock &InsertAtEnd, ///< Block to insert into.
1131  Predicate pred, ///< The predicate to use for the comparison
1132  Value *LHS, ///< The left-hand-side of the expression
1133  Value *RHS, ///< The right-hand-side of the expression
1134  const Twine &NameStr = "" ///< Name of the instruction
1135  ) : CmpInst(makeCmpResultType(LHS->getType()),
1136  Instruction::ICmp, pred, LHS, RHS, NameStr,
1137  &InsertAtEnd) {
1138 #ifndef NDEBUG
1139  AssertOK();
1140 #endif
1141  }
1142 
1143  /// \brief Constructor with no-insertion semantics
1145  Predicate pred, ///< The predicate to use for the comparison
1146  Value *LHS, ///< The left-hand-side of the expression
1147  Value *RHS, ///< The right-hand-side of the expression
1148  const Twine &NameStr = "" ///< Name of the instruction
1149  ) : CmpInst(makeCmpResultType(LHS->getType()),
1150  Instruction::ICmp, pred, LHS, RHS, NameStr) {
1151 #ifndef NDEBUG
1152  AssertOK();
1153 #endif
1154  }
1155 
1156  /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1157  /// @returns the predicate that would be the result if the operand were
1158  /// regarded as signed.
1159  /// \brief Return the signed version of the predicate
1161  return getSignedPredicate(getPredicate());
1162  }
1163 
1164  /// This is a static version that you can use without an instruction.
1165  /// \brief Return the signed version of the predicate.
1166  static Predicate getSignedPredicate(Predicate pred);
1167 
1168  /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1169  /// @returns the predicate that would be the result if the operand were
1170  /// regarded as unsigned.
1171  /// \brief Return the unsigned version of the predicate
1173  return getUnsignedPredicate(getPredicate());
1174  }
1175 
1176  /// This is a static version that you can use without an instruction.
1177  /// \brief Return the unsigned version of the predicate.
1178  static Predicate getUnsignedPredicate(Predicate pred);
1179 
1180  /// isEquality - Return true if this predicate is either EQ or NE. This also
1181  /// tests for commutativity.
1182  static bool isEquality(Predicate P) {
1183  return P == ICMP_EQ || P == ICMP_NE;
1184  }
1185 
1186  /// isEquality - Return true if this predicate is either EQ or NE. This also
1187  /// tests for commutativity.
1188  bool isEquality() const {
1189  return isEquality(getPredicate());
1190  }
1191 
1192  /// @returns true if the predicate of this ICmpInst is commutative
1193  /// \brief Determine if this relation is commutative.
1194  bool isCommutative() const { return isEquality(); }
1195 
1196  /// isRelational - Return true if the predicate is relational (not EQ or NE).
1197  ///
1198  bool isRelational() const {
1199  return !isEquality();
1200  }
1201 
1202  /// isRelational - Return true if the predicate is relational (not EQ or NE).
1203  ///
1204  static bool isRelational(Predicate P) {
1205  return !isEquality(P);
1206  }
1207 
1208  /// Initialize a set of values that all satisfy the predicate with C.
1209  /// \brief Make a ConstantRange for a relation with a constant value.
1210  static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
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  /// \brief 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 //===----------------------------------------------------------------------===//
1233 // FCmpInst Class
1234 //===----------------------------------------------------------------------===//
1235 
1236 /// This instruction compares its operands according to the predicate given
1237 /// to the constructor. It only operates on floating point values or packed
1238 /// vectors of floating point values. The operands must be identical types.
1239 /// \brief Represents a floating point comparison operator.
1240 class FCmpInst: public CmpInst {
1241 protected:
1242  // Note: Instruction needs to be a friend here to call cloneImpl.
1243  friend class Instruction;
1244  /// \brief Clone an identical FCmpInst
1245  FCmpInst *cloneImpl() const;
1246 
1247 public:
1248  /// \brief 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) {
1258  assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
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  /// \brief 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) {
1277  assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
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  /// \brief 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) {
1294  assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief Swap operands and adjust predicate.
1333  void swapOperands() {
1335  Op<0>().swap(Op<1>());
1336  }
1337 
1338  /// \brief 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 /// CallInst - 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  AttributeSet AttributeList; ///< parameter attributes for call
1355  FunctionType *FTy;
1356  CallInst(const CallInst &CI);
1357  void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr) {
1358  init(cast<FunctionType>(
1359  cast<PointerType>(Func->getType())->getElementType()),
1360  Func, Args, NameStr);
1361  }
1362  void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1363  const Twine &NameStr);
1364  void init(Value *Func, const Twine &NameStr);
1365 
1366  /// Construct a CallInst given a range of arguments.
1367  /// \brief Construct a CallInst from a range of arguments
1368  inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1369  const Twine &NameStr, Instruction *InsertBefore);
1370  inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1371  Instruction *InsertBefore)
1372  : CallInst(cast<FunctionType>(
1373  cast<PointerType>(Func->getType())->getElementType()),
1374  Func, Args, NameStr, InsertBefore) {}
1375 
1376  /// Construct a CallInst given a range of arguments.
1377  /// \brief Construct a CallInst from a range of arguments
1378  inline CallInst(Value *Func, ArrayRef<Value *> Args,
1379  const Twine &NameStr, BasicBlock *InsertAtEnd);
1380 
1381  explicit CallInst(Value *F, const Twine &NameStr,
1382  Instruction *InsertBefore);
1383  CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1384 protected:
1385  // Note: Instruction needs to be a friend here to call cloneImpl.
1386  friend class Instruction;
1387  CallInst *cloneImpl() const;
1388 
1389 public:
1390  static CallInst *Create(Value *Func,
1391  ArrayRef<Value *> Args,
1392  const Twine &NameStr = "",
1393  Instruction *InsertBefore = nullptr) {
1394  return Create(cast<FunctionType>(
1395  cast<PointerType>(Func->getType())->getElementType()),
1396  Func, Args, NameStr, InsertBefore);
1397  }
1399  const Twine &NameStr = "",
1400  Instruction *InsertBefore = nullptr) {
1401  return new (unsigned(Args.size() + 1))
1402  CallInst(Ty, Func, Args, NameStr, InsertBefore);
1403  }
1404  static CallInst *Create(Value *Func,
1405  ArrayRef<Value *> Args,
1406  const Twine &NameStr, BasicBlock *InsertAtEnd) {
1407  return new(unsigned(Args.size() + 1))
1408  CallInst(Func, Args, NameStr, InsertAtEnd);
1409  }
1410  static CallInst *Create(Value *F, const Twine &NameStr = "",
1411  Instruction *InsertBefore = nullptr) {
1412  return new(1) CallInst(F, NameStr, InsertBefore);
1413  }
1414  static CallInst *Create(Value *F, const Twine &NameStr,
1415  BasicBlock *InsertAtEnd) {
1416  return new(1) CallInst(F, NameStr, InsertAtEnd);
1417  }
1418  /// CreateMalloc - Generate the IR for a call to malloc:
1419  /// 1. Compute the malloc call's argument as the specified type's size,
1420  /// possibly multiplied by the array size if the array size is not
1421  /// constant 1.
1422  /// 2. Call malloc with that argument.
1423  /// 3. Bitcast the result of the malloc call to the specified type.
1424  static Instruction *CreateMalloc(Instruction *InsertBefore,
1425  Type *IntPtrTy, Type *AllocTy,
1426  Value *AllocSize, Value *ArraySize = nullptr,
1427  Function* MallocF = nullptr,
1428  const Twine &Name = "");
1429  static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1430  Type *IntPtrTy, Type *AllocTy,
1431  Value *AllocSize, Value *ArraySize = nullptr,
1432  Function* MallocF = nullptr,
1433  const Twine &Name = "");
1434  /// CreateFree - Generate the IR for a call to the builtin free function.
1435  static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1436  static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1437 
1438  ~CallInst() override;
1439 
1440  FunctionType *getFunctionType() const { return FTy; }
1441 
1443  mutateType(FTy->getReturnType());
1444  this->FTy = FTy;
1445  }
1446 
1447  // Note that 'musttail' implies 'tail'.
1448  enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
1451  }
1452  bool isTailCall() const {
1453  return (getSubclassDataFromInstruction() & 3) != TCK_None;
1454  }
1455  bool isMustTailCall() const {
1456  return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1457  }
1458  void setTailCall(bool isTC = true) {
1459  setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1460  unsigned(isTC ? TCK_Tail : TCK_None));
1461  }
1463  setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1464  unsigned(TCK));
1465  }
1466 
1467  /// Provide fast operand accessors
1469 
1470  /// getNumArgOperands - Return the number of call arguments.
1471  ///
1472  unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1473 
1474  /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1475  ///
1476  Value *getArgOperand(unsigned i) const { return getOperand(i); }
1477  void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1478 
1479  /// arg_operands - iteration adapter for range-for loops.
1481  // The last operand in the op list is the callee - it's not one of the args
1482  // so we don't want to iterate over it.
1483  return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1484  }
1485 
1486  /// arg_operands - iteration adapter for range-for loops.
1489  }
1490 
1491  /// \brief Wrappers for getting the \c Use of a call argument.
1492  const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1493  Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1494 
1495  /// getCallingConv/setCallingConv - Get or set the calling convention of this
1496  /// function call.
1498  return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1499  }
1501  setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1502  (static_cast<unsigned>(CC) << 2));
1503  }
1504 
1505  /// getAttributes - Return the parameter attributes for this call.
1506  ///
1507  const AttributeSet &getAttributes() const { return AttributeList; }
1508 
1509  /// setAttributes - Set the parameter attributes for this call.
1510  ///
1511  void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1512 
1513  /// addAttribute - adds the attribute to the list of attributes.
1514  void addAttribute(unsigned i, Attribute::AttrKind attr);
1515 
1516  /// addAttribute - adds the attribute to the list of attributes.
1517  void addAttribute(unsigned i, StringRef Kind, StringRef Value);
1518 
1519  /// removeAttribute - removes the attribute from the list of attributes.
1520  void removeAttribute(unsigned i, Attribute attr);
1521 
1522  /// \brief adds the dereferenceable attribute to the list of attributes.
1523  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
1524 
1525  /// \brief adds the dereferenceable_or_null attribute to the list of
1526  /// attributes.
1527  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
1528 
1529  /// \brief Determine whether this call has the given attribute.
1531  assert(A != Attribute::NoBuiltin &&
1532  "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1533  return hasFnAttrImpl(A);
1534  }
1535 
1536  /// \brief Determine whether this call has the given attribute.
1537  bool hasFnAttr(StringRef A) const {
1538  return hasFnAttrImpl(A);
1539  }
1540 
1541  /// \brief Determine whether the call or the callee has the given attributes.
1542  bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1543 
1544  /// \brief Extract the alignment for a call or parameter (0=unknown).
1545  unsigned getParamAlignment(unsigned i) const {
1546  return AttributeList.getParamAlignment(i);
1547  }
1548 
1549  /// \brief Extract the number of dereferenceable bytes for a call or
1550  /// parameter (0=unknown).
1551  uint64_t getDereferenceableBytes(unsigned i) const {
1552  return AttributeList.getDereferenceableBytes(i);
1553  }
1554 
1555  /// \brief Extract the number of dereferenceable_or_null bytes for a call or
1556  /// parameter (0=unknown).
1557  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1558  return AttributeList.getDereferenceableOrNullBytes(i);
1559  }
1560 
1561  /// \brief Return true if the call should not be treated as a call to a
1562  /// builtin.
1563  bool isNoBuiltin() const {
1564  return hasFnAttrImpl(Attribute::NoBuiltin) &&
1565  !hasFnAttrImpl(Attribute::Builtin);
1566  }
1567 
1568  /// \brief Return true if the call should not be inlined.
1569  bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1570  void setIsNoInline() {
1572  }
1573 
1574  /// \brief Return true if the call can return twice
1575  bool canReturnTwice() const {
1577  }
1580  }
1581 
1582  /// \brief Determine if the call does not access memory.
1583  bool doesNotAccessMemory() const {
1585  }
1588  }
1589 
1590  /// \brief Determine if the call does not access or only reads memory.
1591  bool onlyReadsMemory() const {
1593  }
1596  }
1597 
1598  /// @brief Determine if the call can access memmory only using pointers based
1599  /// on its arguments.
1600  bool onlyAccessesArgMemory() const {
1602  }
1605  }
1606 
1607  /// \brief Determine if the call cannot return.
1608  bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1611  }
1612 
1613  /// \brief Determine if the call cannot unwind.
1614  bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1617  }
1618 
1619  /// \brief Determine if the call cannot be duplicated.
1623  }
1624 
1625  /// \brief Determine if the call returns a structure through first
1626  /// pointer argument.
1627  bool hasStructRetAttr() const {
1628  // Be friendly and also check the callee.
1630  }
1631 
1632  /// \brief Determine if any call argument is an aggregate passed by value.
1633  bool hasByValArgument() const {
1634  return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1635  }
1636 
1637  /// getCalledFunction - Return the function called, or null if this is an
1638  /// indirect function invocation.
1639  ///
1641  return dyn_cast<Function>(Op<-1>());
1642  }
1643 
1644  /// getCalledValue - Get a pointer to the function that is invoked by this
1645  /// instruction.
1646  const Value *getCalledValue() const { return Op<-1>(); }
1647  Value *getCalledValue() { return Op<-1>(); }
1648 
1649  /// setCalledFunction - Set the function called.
1652  cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1653  Fn);
1654  }
1656  this->FTy = FTy;
1657  assert(FTy == cast<FunctionType>(
1658  cast<PointerType>(Fn->getType())->getElementType()));
1659  Op<-1>() = Fn;
1660  }
1661 
1662  /// isInlineAsm - Check if this call is an inline asm statement.
1663  bool isInlineAsm() const {
1664  return isa<InlineAsm>(Op<-1>());
1665  }
1666 
1667  // Methods for support type inquiry through isa, cast, and dyn_cast:
1668  static inline bool classof(const Instruction *I) {
1669  return I->getOpcode() == Instruction::Call;
1670  }
1671  static inline bool classof(const Value *V) {
1672  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1673  }
1674 private:
1675 
1676  template<typename AttrKind>
1677  bool hasFnAttrImpl(AttrKind A) const {
1678  if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
1679  return true;
1680  if (const Function *F = getCalledFunction())
1681  return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
1682  return false;
1683  }
1684 
1685  // Shadow Instruction::setInstructionSubclassData with a private forwarding
1686  // method so that subclasses cannot accidentally use it.
1687  void setInstructionSubclassData(unsigned short D) {
1689  }
1690 };
1691 
1692 template <>
1693 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1694 };
1695 
1696 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1697  const Twine &NameStr, BasicBlock *InsertAtEnd)
1699  ->getElementType())->getReturnType(),
1700  Instruction::Call,
1701  OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1702  unsigned(Args.size() + 1), InsertAtEnd) {
1703  init(Func, Args, NameStr);
1704 }
1705 
1706 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1707  const Twine &NameStr, Instruction *InsertBefore)
1708  : Instruction(Ty->getReturnType(), Instruction::Call,
1709  OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1710  unsigned(Args.size() + 1), InsertBefore) {
1711  init(Ty, Func, Args, NameStr);
1712 }
1713 
1714 
1715 // Note: if you get compile errors about private methods then
1716 // please update your code to use the high-level operand
1717 // interfaces. See line 943 above.
1718 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1719 
1720 //===----------------------------------------------------------------------===//
1721 // SelectInst Class
1722 //===----------------------------------------------------------------------===//
1723 
1724 /// SelectInst - This class represents the LLVM 'select' instruction.
1725 ///
1726 class SelectInst : public Instruction {
1727  void init(Value *C, Value *S1, Value *S2) {
1728  assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1729  Op<0>() = C;
1730  Op<1>() = S1;
1731  Op<2>() = S2;
1732  }
1733 
1734  SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1735  Instruction *InsertBefore)
1736  : Instruction(S1->getType(), Instruction::Select,
1737  &Op<0>(), 3, InsertBefore) {
1738  init(C, S1, S2);
1739  setName(NameStr);
1740  }
1741  SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1742  BasicBlock *InsertAtEnd)
1743  : Instruction(S1->getType(), Instruction::Select,
1744  &Op<0>(), 3, InsertAtEnd) {
1745  init(C, S1, S2);
1746  setName(NameStr);
1747  }
1748 protected:
1749  // Note: Instruction needs to be a friend here to call cloneImpl.
1750  friend class Instruction;
1751  SelectInst *cloneImpl() const;
1752 
1753 public:
1754  static SelectInst *Create(Value *C, Value *S1, Value *S2,
1755  const Twine &NameStr = "",
1756  Instruction *InsertBefore = nullptr) {
1757  return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1758  }
1759  static SelectInst *Create(Value *C, Value *S1, Value *S2,
1760  const Twine &NameStr,
1761  BasicBlock *InsertAtEnd) {
1762  return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1763  }
1764 
1765  const Value *getCondition() const { return Op<0>(); }
1766  const Value *getTrueValue() const { return Op<1>(); }
1767  const Value *getFalseValue() const { return Op<2>(); }
1768  Value *getCondition() { return Op<0>(); }
1769  Value *getTrueValue() { return Op<1>(); }
1770  Value *getFalseValue() { return Op<2>(); }
1771 
1772  /// areInvalidOperands - Return a string if the specified operands are invalid
1773  /// for a select operation, otherwise return null.
1774  static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1775 
1776  /// Transparently provide more efficient getOperand methods.
1778 
1780  return static_cast<OtherOps>(Instruction::getOpcode());
1781  }
1782 
1783  // Methods for support type inquiry through isa, cast, and dyn_cast:
1784  static inline bool classof(const Instruction *I) {
1785  return I->getOpcode() == Instruction::Select;
1786  }
1787  static inline bool classof(const Value *V) {
1788  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1789  }
1790 };
1791 
1792 template <>
1793 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1794 };
1795 
1797 
1798 //===----------------------------------------------------------------------===//
1799 // VAArgInst Class
1800 //===----------------------------------------------------------------------===//
1801 
1802 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1803 /// an argument of the specified type given a va_list and increments that list
1804 ///
1805 class VAArgInst : public UnaryInstruction {
1806 protected:
1807  // Note: Instruction needs to be a friend here to call cloneImpl.
1808  friend class Instruction;
1809  VAArgInst *cloneImpl() const;
1810 
1811 public:
1812  VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1813  Instruction *InsertBefore = nullptr)
1814  : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1815  setName(NameStr);
1816  }
1817  VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1818  BasicBlock *InsertAtEnd)
1819  : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1820  setName(NameStr);
1821  }
1822 
1823  Value *getPointerOperand() { return getOperand(0); }
1824  const Value *getPointerOperand() const { return getOperand(0); }
1825  static unsigned getPointerOperandIndex() { return 0U; }
1826 
1827  // Methods for support type inquiry through isa, cast, and dyn_cast:
1828  static inline bool classof(const Instruction *I) {
1829  return I->getOpcode() == VAArg;
1830  }
1831  static inline bool classof(const Value *V) {
1832  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1833  }
1834 };
1835 
1836 //===----------------------------------------------------------------------===//
1837 // ExtractElementInst Class
1838 //===----------------------------------------------------------------------===//
1839 
1840 /// ExtractElementInst - This instruction extracts a single (scalar)
1841 /// element from a VectorType value
1842 ///
1844  ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1845  Instruction *InsertBefore = nullptr);
1846  ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1847  BasicBlock *InsertAtEnd);
1848 protected:
1849  // Note: Instruction needs to be a friend here to call cloneImpl.
1850  friend class Instruction;
1851  ExtractElementInst *cloneImpl() const;
1852 
1853 public:
1854  static ExtractElementInst *Create(Value *Vec, Value *Idx,
1855  const Twine &NameStr = "",
1856  Instruction *InsertBefore = nullptr) {
1857  return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1858  }
1859  static ExtractElementInst *Create(Value *Vec, Value *Idx,
1860  const Twine &NameStr,
1861  BasicBlock *InsertAtEnd) {
1862  return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1863  }
1864 
1865  /// isValidOperands - Return true if an extractelement instruction can be
1866  /// formed with the specified operands.
1867  static bool isValidOperands(const Value *Vec, const Value *Idx);
1868 
1869  Value *getVectorOperand() { return Op<0>(); }
1870  Value *getIndexOperand() { return Op<1>(); }
1871  const Value *getVectorOperand() const { return Op<0>(); }
1872  const Value *getIndexOperand() const { return Op<1>(); }
1873 
1875  return cast<VectorType>(getVectorOperand()->getType());
1876  }
1877 
1878 
1879  /// Transparently provide more efficient getOperand methods.
1881 
1882  // Methods for support type inquiry through isa, cast, and dyn_cast:
1883  static inline bool classof(const Instruction *I) {
1884  return I->getOpcode() == Instruction::ExtractElement;
1885  }
1886  static inline bool classof(const Value *V) {
1887  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1888  }
1889 };
1890 
1891 template <>
1893  public FixedNumOperandTraits<ExtractElementInst, 2> {
1894 };
1895 
1897 
1898 //===----------------------------------------------------------------------===//
1899 // InsertElementInst Class
1900 //===----------------------------------------------------------------------===//
1901 
1902 /// InsertElementInst - This instruction inserts a single (scalar)
1903 /// element into a VectorType value
1904 ///
1906  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1907  const Twine &NameStr = "",
1908  Instruction *InsertBefore = nullptr);
1909  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1910  const Twine &NameStr, BasicBlock *InsertAtEnd);
1911 protected:
1912  // Note: Instruction needs to be a friend here to call cloneImpl.
1913  friend class Instruction;
1914  InsertElementInst *cloneImpl() const;
1915 
1916 public:
1917  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1918  const Twine &NameStr = "",
1919  Instruction *InsertBefore = nullptr) {
1920  return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1921  }
1922  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1923  const Twine &NameStr,
1924  BasicBlock *InsertAtEnd) {
1925  return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1926  }
1927 
1928  /// isValidOperands - Return true if an insertelement instruction can be
1929  /// formed with the specified operands.
1930  static bool isValidOperands(const Value *Vec, const Value *NewElt,
1931  const Value *Idx);
1932 
1933  /// getType - Overload to return most specific vector type.
1934  ///
1935  VectorType *getType() const {
1936  return cast<VectorType>(Instruction::getType());
1937  }
1938 
1939  /// Transparently provide more efficient getOperand methods.
1941 
1942  // Methods for support type inquiry through isa, cast, and dyn_cast:
1943  static inline bool classof(const Instruction *I) {
1944  return I->getOpcode() == Instruction::InsertElement;
1945  }
1946  static inline bool classof(const Value *V) {
1947  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1948  }
1949 };
1950 
1951 template <>
1953  public FixedNumOperandTraits<InsertElementInst, 3> {
1954 };
1955 
1957 
1958 //===----------------------------------------------------------------------===//
1959 // ShuffleVectorInst Class
1960 //===----------------------------------------------------------------------===//
1961 
1962 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1963 /// input vectors.
1964 ///
1966 protected:
1967  // Note: Instruction needs to be a friend here to call cloneImpl.
1968  friend class Instruction;
1969  ShuffleVectorInst *cloneImpl() const;
1970 
1971 public:
1972  // allocate space for exactly three operands
1973  void *operator new(size_t s) {
1974  return User::operator new(s, 3);
1975  }
1976  ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1977  const Twine &NameStr = "",
1978  Instruction *InsertBefor = nullptr);
1979  ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1980  const Twine &NameStr, BasicBlock *InsertAtEnd);
1981 
1982  /// isValidOperands - Return true if a shufflevector instruction can be
1983  /// formed with the specified operands.
1984  static bool isValidOperands(const Value *V1, const Value *V2,
1985  const Value *Mask);
1986 
1987  /// getType - Overload to return most specific vector type.
1988  ///
1989  VectorType *getType() const {
1990  return cast<VectorType>(Instruction::getType());
1991  }
1992 
1993  /// Transparently provide more efficient getOperand methods.
1995 
1996  Constant *getMask() const {
1997  return cast<Constant>(getOperand(2));
1998  }
1999 
2000  /// getMaskValue - Return the index from the shuffle mask for the specified
2001  /// output result. This is either -1 if the element is undef or a number less
2002  /// than 2*numelements.
2003  static int getMaskValue(Constant *Mask, unsigned i);
2004 
2005  int getMaskValue(unsigned i) const {
2006  return getMaskValue(getMask(), i);
2007  }
2008 
2009  /// getShuffleMask - Return the full mask for this instruction, where each
2010  /// element is the element number and undef's are returned as -1.
2011  static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
2012 
2013  void getShuffleMask(SmallVectorImpl<int> &Result) const {
2014  return getShuffleMask(getMask(), Result);
2015  }
2016 
2018  SmallVector<int, 16> Mask;
2019  getShuffleMask(Mask);
2020  return Mask;
2021  }
2022 
2023 
2024  // Methods for support type inquiry through isa, cast, and dyn_cast:
2025  static inline bool classof(const Instruction *I) {
2026  return I->getOpcode() == Instruction::ShuffleVector;
2027  }
2028  static inline bool classof(const Value *V) {
2029  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2030  }
2031 };
2032 
2033 template <>
2035  public FixedNumOperandTraits<ShuffleVectorInst, 3> {
2036 };
2037 
2039 
2040 //===----------------------------------------------------------------------===//
2041 // ExtractValueInst Class
2042 //===----------------------------------------------------------------------===//
2043 
2044 /// ExtractValueInst - This instruction extracts a struct member or array
2045 /// element value from an aggregate value.
2046 ///
2048  SmallVector<unsigned, 4> Indices;
2049 
2050  ExtractValueInst(const ExtractValueInst &EVI);
2051  void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2052 
2053  /// Constructors - Create a extractvalue instruction with a base aggregate
2054  /// value and a list of indices. The first ctor can optionally insert before
2055  /// an existing instruction, the second appends the new instruction to the
2056  /// specified BasicBlock.
2057  inline ExtractValueInst(Value *Agg,
2058  ArrayRef<unsigned> Idxs,
2059  const Twine &NameStr,
2060  Instruction *InsertBefore);
2061  inline ExtractValueInst(Value *Agg,
2062  ArrayRef<unsigned> Idxs,
2063  const Twine &NameStr, BasicBlock *InsertAtEnd);
2064 
2065  // allocate space for exactly one operand
2066  void *operator new(size_t s) {
2067  return User::operator new(s, 1);
2068  }
2069 protected:
2070  // Note: Instruction needs to be a friend here to call cloneImpl.
2071  friend class Instruction;
2072  ExtractValueInst *cloneImpl() const;
2073 
2074 public:
2076  ArrayRef<unsigned> Idxs,
2077  const Twine &NameStr = "",
2078  Instruction *InsertBefore = nullptr) {
2079  return new
2080  ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2081  }
2083  ArrayRef<unsigned> Idxs,
2084  const Twine &NameStr,
2085  BasicBlock *InsertAtEnd) {
2086  return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2087  }
2088 
2089  /// getIndexedType - Returns the type of the element that would be extracted
2090  /// with an extractvalue instruction with the specified parameters.
2091  ///
2092  /// Null is returned if the indices are invalid for the specified type.
2093  static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2094 
2095  typedef const unsigned* idx_iterator;
2096  inline idx_iterator idx_begin() const { return Indices.begin(); }
2097  inline idx_iterator idx_end() const { return Indices.end(); }
2099  return iterator_range<idx_iterator>(idx_begin(), idx_end());
2100  }
2101 
2103  return getOperand(0);
2104  }
2105  const Value *getAggregateOperand() const {
2106  return getOperand(0);
2107  }
2108  static unsigned getAggregateOperandIndex() {
2109  return 0U; // get index for modifying correct operand
2110  }
2111 
2113  return Indices;
2114  }
2115 
2116  unsigned getNumIndices() const {
2117  return (unsigned)Indices.size();
2118  }
2119 
2120  bool hasIndices() const {
2121  return true;
2122  }
2123 
2124  // Methods for support type inquiry through isa, cast, and dyn_cast:
2125  static inline bool classof(const Instruction *I) {
2126  return I->getOpcode() == Instruction::ExtractValue;
2127  }
2128  static inline bool classof(const Value *V) {
2129  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2130  }
2131 };
2132 
2133 ExtractValueInst::ExtractValueInst(Value *Agg,
2134  ArrayRef<unsigned> Idxs,
2135  const Twine &NameStr,
2136  Instruction *InsertBefore)
2137  : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2138  ExtractValue, Agg, InsertBefore) {
2139  init(Idxs, NameStr);
2140 }
2141 ExtractValueInst::ExtractValueInst(Value *Agg,
2142  ArrayRef<unsigned> Idxs,
2143  const Twine &NameStr,
2144  BasicBlock *InsertAtEnd)
2145  : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2146  ExtractValue, Agg, InsertAtEnd) {
2147  init(Idxs, NameStr);
2148 }
2149 
2150 
2151 //===----------------------------------------------------------------------===//
2152 // InsertValueInst Class
2153 //===----------------------------------------------------------------------===//
2154 
2155 /// InsertValueInst - This instruction inserts a struct field of array element
2156 /// value into an aggregate value.
2157 ///
2159  SmallVector<unsigned, 4> Indices;
2160 
2161  void *operator new(size_t, unsigned) = delete;
2162  InsertValueInst(const InsertValueInst &IVI);
2163  void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2164  const Twine &NameStr);
2165 
2166  /// Constructors - Create a insertvalue instruction with a base aggregate
2167  /// value, a value to insert, and a list of indices. The first ctor can
2168  /// optionally insert before an existing instruction, the second appends
2169  /// the new instruction to the specified BasicBlock.
2170  inline InsertValueInst(Value *Agg, Value *Val,
2171  ArrayRef<unsigned> Idxs,
2172  const Twine &NameStr,
2173  Instruction *InsertBefore);
2174  inline InsertValueInst(Value *Agg, Value *Val,
2175  ArrayRef<unsigned> Idxs,
2176  const Twine &NameStr, BasicBlock *InsertAtEnd);
2177 
2178  /// Constructors - These two constructors are convenience methods because one
2179  /// and two index insertvalue instructions are so common.
2180  InsertValueInst(Value *Agg, Value *Val,
2181  unsigned Idx, const Twine &NameStr = "",
2182  Instruction *InsertBefore = nullptr);
2183  InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2184  const Twine &NameStr, BasicBlock *InsertAtEnd);
2185 protected:
2186  // Note: Instruction needs to be a friend here to call cloneImpl.
2187  friend class Instruction;
2188  InsertValueInst *cloneImpl() const;
2189 
2190 public:
2191  // allocate space for exactly two operands
2192  void *operator new(size_t s) {
2193  return User::operator new(s, 2);
2194  }
2195 
2196  static InsertValueInst *Create(Value *Agg, Value *Val,
2197  ArrayRef<unsigned> Idxs,
2198  const Twine &NameStr = "",
2199  Instruction *InsertBefore = nullptr) {
2200  return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2201  }
2202  static InsertValueInst *Create(Value *Agg, Value *Val,
2203  ArrayRef<unsigned> Idxs,
2204  const Twine &NameStr,
2205  BasicBlock *InsertAtEnd) {
2206  return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2207  }
2208 
2209  /// Transparently provide more efficient getOperand methods.
2211 
2212  typedef const unsigned* idx_iterator;
2213  inline idx_iterator idx_begin() const { return Indices.begin(); }
2214  inline idx_iterator idx_end() const { return Indices.end(); }
2217  }
2218 
2220  return getOperand(0);
2221  }
2222  const Value *getAggregateOperand() const {
2223  return getOperand(0);
2224  }
2225  static unsigned getAggregateOperandIndex() {
2226  return 0U; // get index for modifying correct operand
2227  }
2228 
2230  return getOperand(1);
2231  }
2233  return getOperand(1);
2234  }
2235  static unsigned getInsertedValueOperandIndex() {
2236  return 1U; // get index for modifying correct operand
2237  }
2238 
2240  return Indices;
2241  }
2242 
2243  unsigned getNumIndices() const {
2244  return (unsigned)Indices.size();
2245  }
2246 
2247  bool hasIndices() const {
2248  return true;
2249  }
2250 
2251  // Methods for support type inquiry through isa, cast, and dyn_cast:
2252  static inline bool classof(const Instruction *I) {
2253  return I->getOpcode() == Instruction::InsertValue;
2254  }
2255  static inline bool classof(const Value *V) {
2256  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2257  }
2258 };
2259 
2260 template <>
2262  public FixedNumOperandTraits<InsertValueInst, 2> {
2263 };
2264 
2265 InsertValueInst::InsertValueInst(Value *Agg,
2266  Value *Val,
2267  ArrayRef<unsigned> Idxs,
2268  const Twine &NameStr,
2269  Instruction *InsertBefore)
2270  : Instruction(Agg->getType(), InsertValue,
2271  OperandTraits<InsertValueInst>::op_begin(this),
2272  2, InsertBefore) {
2273  init(Agg, Val, Idxs, NameStr);
2274 }
2275 InsertValueInst::InsertValueInst(Value *Agg,
2276  Value *Val,
2277  ArrayRef<unsigned> Idxs,
2278  const Twine &NameStr,
2279  BasicBlock *InsertAtEnd)
2280  : Instruction(Agg->getType(), InsertValue,
2281  OperandTraits<InsertValueInst>::op_begin(this),
2282  2, InsertAtEnd) {
2283  init(Agg, Val, Idxs, NameStr);
2284 }
2285 
2286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2287 
2288 //===----------------------------------------------------------------------===//
2289 // PHINode Class
2290 //===----------------------------------------------------------------------===//
2291 
2292 // PHINode - The PHINode class is used to represent the magical mystical PHI
2293 // node, that can not exist in nature, but can be synthesized in a computer
2294 // scientist's overactive imagination.
2295 //
2296 class PHINode : public Instruction {
2297  void *operator new(size_t, unsigned) = delete;
2298  /// ReservedSpace - The number of operands actually allocated. NumOperands is
2299  /// the number actually in use.
2300  unsigned ReservedSpace;
2301  PHINode(const PHINode &PN);
2302  // allocate space for exactly zero operands
2303  void *operator new(size_t s) {
2304  return User::operator new(s);
2305  }
2306  explicit PHINode(Type *Ty, unsigned NumReservedValues,
2307  const Twine &NameStr = "",
2308  Instruction *InsertBefore = nullptr)
2309  : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2310  ReservedSpace(NumReservedValues) {
2311  setName(NameStr);
2312  allocHungoffUses(ReservedSpace);
2313  }
2314 
2315  PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2316  BasicBlock *InsertAtEnd)
2317  : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2318  ReservedSpace(NumReservedValues) {
2319  setName(NameStr);
2320  allocHungoffUses(ReservedSpace);
2321  }
2322 protected:
2323  // allocHungoffUses - this is more complicated than the generic
2324  // User::allocHungoffUses, because we have to allocate Uses for the incoming
2325  // values and pointers to the incoming blocks, all in one allocation.
2326  void allocHungoffUses(unsigned N) {
2327  User::allocHungoffUses(N, /* IsPhi */ true);
2328  }
2329 
2330  // Note: Instruction needs to be a friend here to call cloneImpl.
2331  friend class Instruction;
2332  PHINode *cloneImpl() const;
2333 
2334 public:
2335  /// Constructors - NumReservedValues is a hint for the number of incoming
2336  /// edges that this phi node will have (use 0 if you really have no idea).
2337  static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2338  const Twine &NameStr = "",
2339  Instruction *InsertBefore = nullptr) {
2340  return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2341  }
2342  static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2343  const Twine &NameStr, BasicBlock *InsertAtEnd) {
2344  return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2345  }
2346 
2347  /// Provide fast operand accessors
2349 
2350  // Block iterator interface. This provides access to the list of incoming
2351  // basic blocks, which parallels the list of incoming values.
2352 
2355 
2356  block_iterator block_begin() {
2357  Use::UserRef *ref =
2358  reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2359  return reinterpret_cast<block_iterator>(ref + 1);
2360  }
2361 
2362  const_block_iterator block_begin() const {
2363  const Use::UserRef *ref =
2364  reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2365  return reinterpret_cast<const_block_iterator>(ref + 1);
2366  }
2367 
2368  block_iterator block_end() {
2369  return block_begin() + getNumOperands();
2370  }
2371 
2372  const_block_iterator block_end() const {
2373  return block_begin() + getNumOperands();
2374  }
2375 
2376  op_range incoming_values() { return operands(); }
2377 
2378  const_op_range incoming_values() const { return operands(); }
2379 
2380  /// getNumIncomingValues - Return the number of incoming edges
2381  ///
2382  unsigned getNumIncomingValues() const { return getNumOperands(); }
2383 
2384  /// getIncomingValue - Return incoming value number x
2385  ///
2386  Value *getIncomingValue(unsigned i) const {
2387  return getOperand(i);
2388  }
2389  void setIncomingValue(unsigned i, Value *V) {
2390  setOperand(i, V);
2391  }
2392  static unsigned getOperandNumForIncomingValue(unsigned i) {
2393  return i;
2394  }
2395  static unsigned getIncomingValueNumForOperand(unsigned i) {
2396  return i;
2397  }
2398 
2399  /// getIncomingBlock - Return incoming basic block number @p i.
2400  ///
2401  BasicBlock *getIncomingBlock(unsigned i) const {
2402  return block_begin()[i];
2403  }
2404 
2405  /// getIncomingBlock - Return incoming basic block corresponding
2406  /// to an operand of the PHI.
2407  ///
2408  BasicBlock *getIncomingBlock(const Use &U) const {
2409  assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2410  return getIncomingBlock(unsigned(&U - op_begin()));
2411  }
2412 
2413  /// getIncomingBlock - Return incoming basic block corresponding
2414  /// to value use iterator.
2415  ///
2417  return getIncomingBlock(I.getUse());
2418  }
2419 
2420  void setIncomingBlock(unsigned i, BasicBlock *BB) {
2421  block_begin()[i] = BB;
2422  }
2423 
2424  /// addIncoming - Add an incoming value to the end of the PHI list
2425  ///
2426  void addIncoming(Value *V, BasicBlock *BB) {
2427  assert(V && "PHI node got a null value!");
2428  assert(BB && "PHI node got a null basic block!");
2429  assert(getType() == V->getType() &&
2430  "All operands to PHI node must be the same type as the PHI node!");
2431  if (getNumOperands() == ReservedSpace)
2432  growOperands(); // Get more space!
2433  // Initialize some new operands.
2434  setNumHungOffUseOperands(getNumOperands() + 1);
2435  setIncomingValue(getNumOperands() - 1, V);
2436  setIncomingBlock(getNumOperands() - 1, BB);
2437  }
2438 
2439  /// removeIncomingValue - Remove an incoming value. This is useful if a
2440  /// predecessor basic block is deleted. The value removed is returned.
2441  ///
2442  /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2443  /// is true), the PHI node is destroyed and any uses of it are replaced with
2444  /// dummy values. The only time there should be zero incoming values to a PHI
2445  /// node is when the block is dead, so this strategy is sound.
2446  ///
2447  Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2448 
2449  Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2450  int Idx = getBasicBlockIndex(BB);
2451  assert(Idx >= 0 && "Invalid basic block argument to remove!");
2452  return removeIncomingValue(Idx, DeletePHIIfEmpty);
2453  }
2454 
2455  /// getBasicBlockIndex - Return the first index of the specified basic
2456  /// block in the value list for this PHI. Returns -1 if no instance.
2457  ///
2458  int getBasicBlockIndex(const BasicBlock *BB) const {
2459  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2460  if (block_begin()[i] == BB)
2461  return i;
2462  return -1;
2463  }
2464 
2466  int Idx = getBasicBlockIndex(BB);
2467  assert(Idx >= 0 && "Invalid basic block argument!");
2468  return getIncomingValue(Idx);
2469  }
2470 
2471  /// hasConstantValue - If the specified PHI node always merges together the
2472  /// same value, return the value, otherwise return null.
2473  Value *hasConstantValue() const;
2474 
2475  /// Methods for support type inquiry through isa, cast, and dyn_cast:
2476  static inline bool classof(const Instruction *I) {
2477  return I->getOpcode() == Instruction::PHI;
2478  }
2479  static inline bool classof(const Value *V) {
2480  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2481  }
2482  private:
2483  void growOperands();
2484 };
2485 
2486 template <>
2488 };
2489 
2491 
2492 //===----------------------------------------------------------------------===//
2493 // LandingPadInst Class
2494 //===----------------------------------------------------------------------===//
2495 
2496 //===---------------------------------------------------------------------------
2497 /// LandingPadInst - The landingpad instruction holds all of the information
2498 /// necessary to generate correct exception handling. The landingpad instruction
2499 /// cannot be moved from the top of a landing pad block, which itself is
2500 /// accessible only from the 'unwind' edge of an invoke. This uses the
2501 /// SubclassData field in Value to store whether or not the landingpad is a
2502 /// cleanup.
2503 ///
2504 class LandingPadInst : public Instruction {
2505  /// ReservedSpace - The number of operands actually allocated. NumOperands is
2506  /// the number actually in use.
2507  unsigned ReservedSpace;
2508  LandingPadInst(const LandingPadInst &LP);
2509 public:
2510  enum ClauseType { Catch, Filter };
2511 private:
2512  void *operator new(size_t, unsigned) = delete;
2513  // Allocate space for exactly zero operands.
2514  void *operator new(size_t s) {
2515  return User::operator new(s);
2516  }
2517  void growOperands(unsigned Size);
2518  void init(unsigned NumReservedValues, const Twine &NameStr);
2519 
2520  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2521  const Twine &NameStr, Instruction *InsertBefore);
2522  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2523  const Twine &NameStr, BasicBlock *InsertAtEnd);
2524 
2525 protected:
2526  // Note: Instruction needs to be a friend here to call cloneImpl.
2527  friend class Instruction;
2528  LandingPadInst *cloneImpl() const;
2529 
2530 public:
2531  /// Constructors - NumReservedClauses is a hint for the number of incoming
2532  /// clauses that this landingpad will have (use 0 if you really have no idea).
2533  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2534  const Twine &NameStr = "",
2535  Instruction *InsertBefore = nullptr);
2536  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2537  const Twine &NameStr, BasicBlock *InsertAtEnd);
2538 
2539  /// Provide fast operand accessors
2541 
2542  /// isCleanup - Return 'true' if this landingpad instruction is a
2543  /// cleanup. I.e., it should be run when unwinding even if its landing pad
2544  /// doesn't catch the exception.
2545  bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2546 
2547  /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2548  void setCleanup(bool V) {
2549  setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2550  (V ? 1 : 0));
2551  }
2552 
2553  /// Add a catch or filter clause to the landing pad.
2554  void addClause(Constant *ClauseVal);
2555 
2556  /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2557  /// determine what type of clause this is.
2558  Constant *getClause(unsigned Idx) const {
2559  return cast<Constant>(getOperandList()[Idx]);
2560  }
2561 
2562  /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2563  bool isCatch(unsigned Idx) const {
2564  return !isa<ArrayType>(getOperandList()[Idx]->getType());
2565  }
2566 
2567  /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2568  bool isFilter(unsigned Idx) const {
2569  return isa<ArrayType>(getOperandList()[Idx]->getType());
2570  }
2571 
2572  /// getNumClauses - Get the number of clauses for this landing pad.
2573  unsigned getNumClauses() const { return getNumOperands(); }
2574 
2575  /// reserveClauses - Grow the size of the operand list to accommodate the new
2576  /// number of clauses.
2577  void reserveClauses(unsigned Size) { growOperands(Size); }
2578 
2579  // Methods for support type inquiry through isa, cast, and dyn_cast:
2580  static inline bool classof(const Instruction *I) {
2581  return I->getOpcode() == Instruction::LandingPad;
2582  }
2583  static inline bool classof(const Value *V) {
2584  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2585  }
2586 };
2587 
2588 template <>
2590 };
2591 
2593 
2594 //===----------------------------------------------------------------------===//
2595 // ReturnInst Class
2596 //===----------------------------------------------------------------------===//
2597 
2598 //===---------------------------------------------------------------------------
2599 /// ReturnInst - Return a value (possibly void), from a function. Execution
2600 /// does not continue in this function any longer.
2601 ///
2602 class ReturnInst : public TerminatorInst {
2603  ReturnInst(const ReturnInst &RI);
2604 
2605 private:
2606  // ReturnInst constructors:
2607  // ReturnInst() - 'ret void' instruction
2608  // ReturnInst( null) - 'ret void' instruction
2609  // ReturnInst(Value* X) - 'ret X' instruction
2610  // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2611  // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2612  // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2613  // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2614  //
2615  // NOTE: If the Value* passed is of type void then the constructor behaves as
2616  // if it was passed NULL.
2617  explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2618  Instruction *InsertBefore = nullptr);
2619  ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2620  explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2621 protected:
2622  // Note: Instruction needs to be a friend here to call cloneImpl.
2623  friend class Instruction;
2624  ReturnInst *cloneImpl() const;
2625 
2626 public:
2627  static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2628  Instruction *InsertBefore = nullptr) {
2629  return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2630  }
2631  static ReturnInst* Create(LLVMContext &C, Value *retVal,
2632  BasicBlock *InsertAtEnd) {
2633  return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2634  }
2635  static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2636  return new(0) ReturnInst(C, InsertAtEnd);
2637  }
2638  ~ReturnInst() override;
2639 
2640  /// Provide fast operand accessors
2642 
2643  /// Convenience accessor. Returns null if there is no return value.
2645  return getNumOperands() != 0 ? getOperand(0) : nullptr;
2646  }
2647 
2648  unsigned getNumSuccessors() const { return 0; }
2649 
2650  // Methods for support type inquiry through isa, cast, and dyn_cast:
2651  static inline bool classof(const Instruction *I) {
2652  return (I->getOpcode() == Instruction::Ret);
2653  }
2654  static inline bool classof(const Value *V) {
2655  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2656  }
2657  private:
2658  BasicBlock *getSuccessorV(unsigned idx) const override;
2659  unsigned getNumSuccessorsV() const override;
2660  void setSuccessorV(unsigned idx, BasicBlock *B) override;
2661 };
2662 
2663 template <>
2664 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2665 };
2666 
2668 
2669 //===----------------------------------------------------------------------===//
2670 // BranchInst Class
2671 //===----------------------------------------------------------------------===//
2672 
2673 //===---------------------------------------------------------------------------
2674 /// BranchInst - Conditional or Unconditional Branch instruction.
2675 ///
2676 class BranchInst : public TerminatorInst {
2677  /// Ops list - Branches are strange. The operands are ordered:
2678  /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2679  /// they don't have to check for cond/uncond branchness. These are mostly
2680  /// accessed relative from op_end().
2681  BranchInst(const BranchInst &BI);
2682  void AssertOK();
2683  // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2684  // BranchInst(BB *B) - 'br B'
2685  // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2686  // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2687  // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2688  // BranchInst(BB* B, BB *I) - 'br B' insert at end
2689  // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2690  explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2691  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2692  Instruction *InsertBefore = nullptr);
2693  BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2694  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2695  BasicBlock *InsertAtEnd);
2696 protected:
2697  // Note: Instruction needs to be a friend here to call cloneImpl.
2698  friend class Instruction;
2699  BranchInst *cloneImpl() const;
2700 
2701 public:
2702  static BranchInst *Create(BasicBlock *IfTrue,
2703  Instruction *InsertBefore = nullptr) {
2704  return new(1) BranchInst(IfTrue, InsertBefore);
2705  }
2706  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2707  Value *Cond, Instruction *InsertBefore = nullptr) {
2708  return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2709  }
2710  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2711  return new(1) BranchInst(IfTrue, InsertAtEnd);
2712  }
2713  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2714  Value *Cond, BasicBlock *InsertAtEnd) {
2715  return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2716  }
2717 
2718  /// Transparently provide more efficient getOperand methods.
2720 
2721  bool isUnconditional() const { return getNumOperands() == 1; }
2722  bool isConditional() const { return getNumOperands() == 3; }
2723 
2724  Value *getCondition() const {
2725  assert(isConditional() && "Cannot get condition of an uncond branch!");
2726  return Op<-3>();
2727  }
2728 
2729  void setCondition(Value *V) {
2730  assert(isConditional() && "Cannot set condition of unconditional branch!");
2731  Op<-3>() = V;
2732  }
2733 
2734  unsigned getNumSuccessors() const { return 1+isConditional(); }
2735 
2736  BasicBlock *getSuccessor(unsigned i) const {
2737  assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2738  return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2739  }
2740 
2741  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2742  assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2743  *(&Op<-1>() - idx) = (Value*)NewSucc;
2744  }
2745 
2746  /// \brief Swap the successors of this branch instruction.
2747  ///
2748  /// Swaps the successors of the branch instruction. This also swaps any
2749  /// branch weight metadata associated with the instruction so that it
2750  /// continues to map correctly to each operand.
2751  void swapSuccessors();
2752 
2753  // Methods for support type inquiry through isa, cast, and dyn_cast:
2754  static inline bool classof(const Instruction *I) {
2755  return (I->getOpcode() == Instruction::Br);
2756  }
2757  static inline bool classof(const Value *V) {
2758  return isa<Instruction>(V) && classof(cast<Instruction>(V));
2759  }
2760 private:
2761  BasicBlock *getSuccessorV(unsigned idx) const override;
2762  unsigned getNumSuccessorsV() const override;
2763  void setSuccessorV(unsigned idx, BasicBlock *B) override;
2764 };
2765 
2766 template <>
2767 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2768 };
2769 
2771 
2772 //===----------------------------------------------------------------------===//
2773 // SwitchInst Class
2774 //===----------------------------------------------------------------------===//
2775 
2776 //===---------------------------------------------------------------------------
2777 /// SwitchInst - Multiway switch
2778 ///
2779 class SwitchInst : public TerminatorInst {
2780  void *operator new(size_t, unsigned) = delete;
2781  unsigned ReservedSpace;
2782  // Operand[0] = Value to switch on
2783  // Operand[1] = Default basic block destination
2784  // Operand[2n ] = Value to match
2785  // Operand[2n+1] = BasicBlock to go to on match
2786  SwitchInst(const SwitchInst &SI);
2787  void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2788  void growOperands();
2789  // allocate space for exactly zero operands
2790  void *operator new(size_t s) {
2791  return User::operator new(s);
2792  }
2793  /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2794  /// switch on and a default destination. The number of additional cases can
2795  /// be specified here to make memory allocation more efficient. This
2796  /// constructor can also autoinsert before another instruction.
2797  SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2798  Instruction *InsertBefore);
2799 
2800  /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2801  /// switch on and a default destination. The number of additional cases can
2802  /// be specified here to make memory allocation more efficient. This
2803  /// constructor also autoinserts at the end of the specified BasicBlock.
2804  SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2805  BasicBlock *InsertAtEnd);
2806 protected:
2807  // Note: Instruction needs to be a friend here to call cloneImpl.
2808  friend class Instruction;
2809  SwitchInst *cloneImpl() const;
2810 
2811 public:
2812 
2813  // -2
2814  static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2815 
2816  template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2818  protected:
2819 
2820  SwitchInstTy *SI;
2821  unsigned Index;
2822 
2823  public:
2824 
2826 
2827  /// Initializes case iterator for given SwitchInst and for given
2828  /// case number.
2829  CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2830  this->SI = SI;
2831  Index = CaseNum;
2832  }
2833 
2834  /// Initializes case iterator for given SwitchInst and for given
2835  /// TerminatorInst's successor index.
2836  static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2837  assert(SuccessorIndex < SI->getNumSuccessors() &&
2838  "Successor index # out of range!");
2839  return SuccessorIndex != 0 ?
2840  Self(SI, SuccessorIndex - 1) :
2841  Self(SI, DefaultPseudoIndex);
2842  }
2843 
2844  /// Resolves case value for current case.
2845  ConstantIntTy *getCaseValue() {
2846  assert(Index < SI->getNumCases() && "Index out the number of cases.");
2847  return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2848  }
2849 
2850  /// Resolves successor for current case.
2851  BasicBlockTy *getCaseSuccessor() {
2852  assert((Index < SI->getNumCases() ||
2853  Index == DefaultPseudoIndex) &&
2854  "Index out the number of cases.");
2855  return SI->getSuccessor(getSuccessorIndex());
2856  }
2857 
2858  /// Returns number of current case.
2859  unsigned getCaseIndex() const { return Index; }
2860 
2861  /// Returns TerminatorInst's successor index for current case successor.
2862  unsigned getSuccessorIndex() const {
2863  assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2864  "Index out the number of cases.");
2865  return Index != DefaultPseudoIndex ? Index + 1 : 0;
2866  }
2867 
2869  // Check index correctness after increment.
2870  // Note: Index == getNumCases() means end().
2871  assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2872  ++Index;
2873  return *this;
2874  }
2876  Self tmp = *this;
2877  ++(*this);
2878  return tmp;
2879  }
2881  // Check index correctness after decrement.
2882  // Note: Index == getNumCases() means end().
2883  // Also allow "-1" iterator here. That will became valid after ++.
2884  assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2885  "Index out the number of cases.");
2886  --Index;
2887  return *this;
2888  }
2890  Self tmp = *this;
2891  --(*this);
2892  return tmp;
2893  }
2894  bool operator==(const Self& RHS) const {
2895  assert(RHS.SI == SI && "Incompatible operators.");
2896  return RHS.Index == Index;
2897  }
2898  bool operator!=(const Self& RHS) const {
2899  assert(RHS.SI == SI && "Incompatible operators.");
2900  return RHS.Index != Index;
2901  }
2903  return *this;
2904  }
2905  };
2906 
2907  typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2909 
2910  class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2911 
2913 
2914  public:
2915 
2916  CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2917  CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2918 
2919  /// Sets the new value for current case.
2921  assert(Index < SI->getNumCases() && "Index out the number of cases.");
2922  SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2923  }
2924 
2925  /// Sets the new successor for current case.
2927  SI->setSuccessor(getSuccessorIndex(), S);
2928  }
2929  };
2930 
2931  static SwitchInst *Create(Value *Value, BasicBlock *Default,
2932  unsigned NumCases,
2933  Instruction *InsertBefore = nullptr) {
2934  return new SwitchInst(Value, Default, NumCases, InsertBefore);
2935  }
2936  static SwitchInst *Create(Value *Value, BasicBlock *Default,
2937  unsigned NumCases, BasicBlock *InsertAtEnd) {
2938  return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2939  }
2940 
2941  /// Provide fast operand accessors
2943 
2944  // Accessor Methods for Switch stmt
2945  Value *getCondition() const { return getOperand(0); }
2946  void setCondition(Value *V) { setOperand(0, V); }
2947 
2949  return cast<BasicBlock>(getOperand(1));
2950  }
2951 
2952  void setDefaultDest(BasicBlock *DefaultCase) {
2953  setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2954  }
2955 
2956  /// getNumCases - return the number of 'cases' in this switch instruction,
2957  /// except the default case
2958  unsigned getNumCases() const {
2959  return getNumOperands()/2 - 1;
2960  }
2961 
2962  /// Returns a read/write iterator that points to the first
2963  /// case in SwitchInst.
2965  return CaseIt(this, 0);
2966  }
2967  /// Returns a read-only iterator that points to the first
2968  /// case in the SwitchInst.
2970  return ConstCaseIt(this, 0);
2971  }
2972 
2973  /// Returns a read/write iterator that points one past the last
2974  /// in the SwitchInst.
2976  return CaseIt(this, getNumCases());
2977  }
2978  /// Returns a read-only iterator that points one past the last
2979  /// in the SwitchInst.
2981  return ConstCaseIt(this, getNumCases());
2982  }
2983 
2984  /// cases - iteration adapter for range-for loops.
2986  return iterator_range<CaseIt>(case_begin(), case_end());
2987  }
2988 
2989  /// cases - iteration adapter for range-for loops.
2991  return iterator_range<ConstCaseIt>(case_begin(), case_end());
2992  }
2993 
2994  /// Returns an iterator that points to the default case.
2995  /// Note: this iterator allows to resolve successor only. Attempt
2996  /// to resolve case value causes an assertion.
2997  /// Also note, that increment and decrement also causes an assertion and
2998  /// makes iterator invalid.
3000  return CaseIt(this, DefaultPseudoIndex);
3001  }
3003  return ConstCaseIt(this, DefaultPseudoIndex);
3004  }
3005 
3006  /// findCaseValue - Search all of the case values for the specified constant.
3007  /// If it is explicitly handled, return the case iterator of it, otherwise
3008  /// return default case iterator to indicate
3009  /// that it is handled by the default handler.
3011  for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
3012  if (i.getCaseValue() == C)
3013  return i;
3014  return case_default();
3015  }
3017  for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
3018  if (i.getCaseValue() == C)
3019  return i;
3020  return case_default();
3021  }
3022 
3023  /// findCaseDest - Finds the unique case value for a given successor. Returns
3024  /// null if the successor is not found, not unique, or is the default case.
3026  if (BB == getDefaultDest()) return nullptr;
3027 
3028  ConstantInt *CI = nullptr;
3029  for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
3030  if (i.getCaseSuccessor() == BB) {
3031  if (CI) return nullptr; // Multiple cases lead to BB.
3032  else CI = i.getCaseValue();
3033  }
3034  }
3035  return CI;
3036  }
3037 
3038  /// addCase - Add an entry to the switch instruction...
3039  /// Note:
3040  /// This action invalidates case_end(). Old case_end() iterator will
3041  /// point to the added case.
3042  void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3043 
3044  /// removeCase - This method removes the specified case and its successor
3045  /// from the switch instruction. Note that this operation may reorder the
3046  /// remaining cases at index idx and above.
3047  /// Note:
3048  /// This action invalidates iterators for all cases following the one removed,
3049  /// including the case_end() iterator.
3050  void removeCase(CaseIt i);
3051 
3052  unsigned getNumSuccessors() const { return getNumOperands()/2; }
3053  BasicBlock *getSuccessor(unsigned idx) const {
3054  assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3055  return cast<BasicBlock>(getOperand(idx*2+1));
3056  }
3057  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3058  assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3059  setOperand(idx*2+1, (Value*)NewSucc);
3060  }
3061 
3062  // Methods for support type inquiry through isa, cast, and dyn_cast:
3063  static inline bool classof(const Instruction *I) {
3064  return I->getOpcode() == Instruction::Switch;
3065  }
3066  static inline bool classof(const Value *V) {
3067  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3068  }
3069 private:
3070  BasicBlock *getSuccessorV(unsigned idx) const override;
3071  unsigned getNumSuccessorsV() const override;
3072  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3073 };
3074 
3075 template <>
3077 };
3078 
3080 
3081 
3082 //===----------------------------------------------------------------------===//
3083 // IndirectBrInst Class
3084 //===----------------------------------------------------------------------===//
3085 
3086 //===---------------------------------------------------------------------------
3087 /// IndirectBrInst - Indirect Branch Instruction.
3088 ///
3090  void *operator new(size_t, unsigned) = delete;
3091  unsigned ReservedSpace;
3092  // Operand[0] = Value to switch on
3093  // Operand[1] = Default basic block destination
3094  // Operand[2n ] = Value to match
3095  // Operand[2n+1] = BasicBlock to go to on match
3096  IndirectBrInst(const IndirectBrInst &IBI);
3097  void init(Value *Address, unsigned NumDests);
3098  void growOperands();
3099  // allocate space for exactly zero operands
3100  void *operator new(size_t s) {
3101  return User::operator new(s);
3102  }
3103  /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3104  /// Address to jump to. The number of expected destinations can be specified
3105  /// here to make memory allocation more efficient. This constructor can also
3106  /// autoinsert before another instruction.
3107  IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
3108 
3109  /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3110  /// Address to jump to. The number of expected destinations can be specified
3111  /// here to make memory allocation more efficient. This constructor also
3112  /// autoinserts at the end of the specified BasicBlock.
3113  IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
3114 protected:
3115  // Note: Instruction needs to be a friend here to call cloneImpl.
3116  friend class Instruction;
3117  IndirectBrInst *cloneImpl() const;
3118 
3119 public:
3120  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3121  Instruction *InsertBefore = nullptr) {
3122  return new IndirectBrInst(Address, NumDests, InsertBefore);
3123  }
3124  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3125  BasicBlock *InsertAtEnd) {
3126  return new IndirectBrInst(Address, NumDests, InsertAtEnd);
3127  }
3128 
3129  /// Provide fast operand accessors.
3131 
3132  // Accessor Methods for IndirectBrInst instruction.
3133  Value *getAddress() { return getOperand(0); }
3134  const Value *getAddress() const { return getOperand(0); }
3135  void setAddress(Value *V) { setOperand(0, V); }
3136 
3137 
3138  /// getNumDestinations - return the number of possible destinations in this
3139  /// indirectbr instruction.
3140  unsigned getNumDestinations() const { return getNumOperands()-1; }
3141 
3142  /// getDestination - Return the specified destination.
3143  BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3144  const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3145 
3146  /// addDestination - Add a destination.
3147  ///
3148  void addDestination(BasicBlock *Dest);
3149 
3150  /// removeDestination - This method removes the specified successor from the
3151  /// indirectbr instruction.
3152  void removeDestination(unsigned i);
3153 
3154  unsigned getNumSuccessors() const { return getNumOperands()-1; }
3155  BasicBlock *getSuccessor(unsigned i) const {
3156  return cast<BasicBlock>(getOperand(i+1));
3157  }
3158  void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3159  setOperand(i+1, (Value*)NewSucc);
3160  }
3161 
3162  // Methods for support type inquiry through isa, cast, and dyn_cast:
3163  static inline bool classof(const Instruction *I) {
3164  return I->getOpcode() == Instruction::IndirectBr;
3165  }
3166  static inline bool classof(const Value *V) {
3167  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3168  }
3169 private:
3170  BasicBlock *getSuccessorV(unsigned idx) const override;
3171  unsigned getNumSuccessorsV() const override;
3172  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3173 };
3174 
3175 template <>
3177 };
3178 
3180 
3181 
3182 //===----------------------------------------------------------------------===//
3183 // InvokeInst Class
3184 //===----------------------------------------------------------------------===//
3185 
3186 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
3187 /// calling convention of the call.
3188 ///
3189 class InvokeInst : public TerminatorInst {
3190  AttributeSet AttributeList;
3191  FunctionType *FTy;
3192  InvokeInst(const InvokeInst &BI);
3193  void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3194  ArrayRef<Value *> Args, const Twine &NameStr) {
3195  init(cast<FunctionType>(
3196  cast<PointerType>(Func->getType())->getElementType()),
3197  Func, IfNormal, IfException, Args, NameStr);
3198  }
3199  void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3200  BasicBlock *IfException, ArrayRef<Value *> Args,
3201  const Twine &NameStr);
3202 
3203  /// Construct an InvokeInst given a range of arguments.
3204  ///
3205  /// \brief Construct an InvokeInst from a range of arguments
3206  inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3207  ArrayRef<Value *> Args, unsigned Values,
3208  const Twine &NameStr, Instruction *InsertBefore)
3209  : InvokeInst(cast<FunctionType>(
3210  cast<PointerType>(Func->getType())->getElementType()),
3211  Func, IfNormal, IfException, Args, Values, NameStr,
3212  InsertBefore) {}
3213 
3214  inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3215  BasicBlock *IfException, ArrayRef<Value *> Args,
3216  unsigned Values, const Twine &NameStr,
3217  Instruction *InsertBefore);
3218  /// Construct an InvokeInst given a range of arguments.
3219  ///
3220  /// \brief Construct an InvokeInst from a range of arguments
3221  inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3222  ArrayRef<Value *> Args, unsigned Values,
3223  const Twine &NameStr, BasicBlock *InsertAtEnd);
3224 protected:
3225  // Note: Instruction needs to be a friend here to call cloneImpl.
3226  friend class Instruction;
3227  InvokeInst *cloneImpl() const;
3228 
3229 public:
3230  static InvokeInst *Create(Value *Func,
3231  BasicBlock *IfNormal, BasicBlock *IfException,
3232  ArrayRef<Value *> Args, const Twine &NameStr = "",
3233  Instruction *InsertBefore = nullptr) {
3234  return Create(cast<FunctionType>(
3235  cast<PointerType>(Func->getType())->getElementType()),
3236  Func, IfNormal, IfException, Args, NameStr, InsertBefore);
3237  }
3238  static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3239  BasicBlock *IfException, ArrayRef<Value *> Args,
3240  const Twine &NameStr = "",
3241  Instruction *InsertBefore = nullptr) {
3242  unsigned Values = unsigned(Args.size()) + 3;
3243  return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args,
3244  Values, NameStr, InsertBefore);
3245  }
3246  static InvokeInst *Create(Value *Func,
3247  BasicBlock *IfNormal, BasicBlock *IfException,
3248  ArrayRef<Value *> Args, const Twine &NameStr,
3249  BasicBlock *InsertAtEnd) {
3250  unsigned Values = unsigned(Args.size()) + 3;
3251  return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
3252  Values, NameStr, InsertAtEnd);
3253  }
3254 
3255  /// Provide fast operand accessors
3257 
3258  FunctionType *getFunctionType() const { return FTy; }
3259 
3261  mutateType(FTy->getReturnType());
3262  this->FTy = FTy;
3263  }
3264 
3265  /// getNumArgOperands - Return the number of invoke arguments.
3266  ///
3267  unsigned getNumArgOperands() const { return getNumOperands() - 3; }
3268 
3269  /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
3270  ///
3271  Value *getArgOperand(unsigned i) const { return getOperand(i); }
3272  void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3273 
3274  /// arg_operands - iteration adapter for range-for loops.
3276  return iterator_range<op_iterator>(op_begin(), op_end() - 3);
3277  }
3278 
3279  /// arg_operands - iteration adapter for range-for loops.
3281  return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
3282  }
3283 
3284  /// \brief Wrappers for getting the \c Use of a invoke argument.
3285  const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3286  Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3287 
3288  /// getCallingConv/setCallingConv - Get or set the calling convention of this
3289  /// function call.
3291  return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3292  }
3294  setInstructionSubclassData(static_cast<unsigned>(CC));
3295  }
3296 
3297  /// getAttributes - Return the parameter attributes for this invoke.
3298  ///
3299  const AttributeSet &getAttributes() const { return AttributeList; }
3300 
3301  /// setAttributes - Set the parameter attributes for this invoke.
3302  ///
3303  void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
3304 
3305  /// addAttribute - adds the attribute to the list of attributes.
3306  void addAttribute(unsigned i, Attribute::AttrKind attr);
3307 
3308  /// removeAttribute - removes the attribute from the list of attributes.
3309  void removeAttribute(unsigned i, Attribute attr);
3310 
3311  /// \brief adds the dereferenceable attribute to the list of attributes.
3312  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
3313 
3314  /// \brief adds the dereferenceable_or_null attribute to the list of
3315  /// attributes.
3316  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
3317 
3318  /// \brief Determine whether this call has the given attribute.
3320  assert(A != Attribute::NoBuiltin &&
3321  "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3322  return hasFnAttrImpl(A);
3323  }
3324 
3325  /// \brief Determine whether the call or the callee has the given attributes.
3326  bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3327 
3328  /// \brief Extract the alignment for a call or parameter (0=unknown).
3329  unsigned getParamAlignment(unsigned i) const {
3330  return AttributeList.getParamAlignment(i);
3331  }
3332 
3333  /// \brief Extract the number of dereferenceable bytes for a call or
3334  /// parameter (0=unknown).
3335  uint64_t getDereferenceableBytes(unsigned i) const {
3336  return AttributeList.getDereferenceableBytes(i);
3337  }
3338 
3339  /// \brief Extract the number of dereferenceable_or_null bytes for a call or
3340  /// parameter (0=unknown).
3341  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
3342  return AttributeList.getDereferenceableOrNullBytes(i);
3343  }
3344 
3345  /// \brief Return true if the call should not be treated as a call to a
3346  /// builtin.
3347  bool isNoBuiltin() const {
3348  // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3349  // to check it by hand.
3350  return hasFnAttrImpl(Attribute::NoBuiltin) &&
3351  !hasFnAttrImpl(Attribute::Builtin);
3352  }
3353 
3354  /// \brief Return true if the call should not be inlined.
3355  bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3356  void setIsNoInline() {
3358  }
3359 
3360  /// \brief Determine if the call does not access memory.
3361  bool doesNotAccessMemory() const {
3362  return hasFnAttr(Attribute::ReadNone);
3363  }
3366  }
3367 
3368  /// \brief Determine if the call does not access or only reads memory.
3369  bool onlyReadsMemory() const {
3370  return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3371  }
3374  }
3375 
3376  /// @brief Determine if the call access memmory only using it's pointer
3377  /// arguments.
3378  bool onlyAccessesArgMemory() const {
3379  return hasFnAttr(Attribute::ArgMemOnly);
3380  }
3383  }
3384 
3385  /// \brief Determine if the call cannot return.
3386  bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3389  }
3390 
3391  /// \brief Determine if the call cannot unwind.
3392  bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3395  }
3396 
3397  /// \brief Determine if the invoke cannot be duplicated.
3398  bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3401  }
3402 
3403  /// \brief Determine if the call returns a structure through first
3404  /// pointer argument.
3405  bool hasStructRetAttr() const {
3406  // Be friendly and also check the callee.
3407  return paramHasAttr(1, Attribute::StructRet);
3408  }
3409 
3410  /// \brief Determine if any call argument is an aggregate passed by value.
3411  bool hasByValArgument() const {
3412  return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3413  }
3414 
3415  /// getCalledFunction - Return the function called, or null if this is an
3416  /// indirect function invocation.
3417  ///
3419  return dyn_cast<Function>(Op<-3>());
3420  }
3421 
3422  /// getCalledValue - Get a pointer to the function that is invoked by this
3423  /// instruction
3424  const Value *getCalledValue() const { return Op<-3>(); }
3425  Value *getCalledValue() { return Op<-3>(); }
3426 
3427  /// setCalledFunction - Set the function called.
3429  setCalledFunction(
3430  cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
3431  Fn);
3432  }
3434  this->FTy = FTy;
3435  assert(FTy == cast<FunctionType>(
3436  cast<PointerType>(Fn->getType())->getElementType()));
3437  Op<-3>() = Fn;
3438  }
3439 
3440  // get*Dest - Return the destination basic blocks...
3442  return cast<BasicBlock>(Op<-2>());
3443  }
3445  return cast<BasicBlock>(Op<-1>());
3446  }
3448  Op<-2>() = reinterpret_cast<Value*>(B);
3449  }
3451  Op<-1>() = reinterpret_cast<Value*>(B);
3452  }
3453 
3454  /// getLandingPadInst - Get the landingpad instruction from the landing pad
3455  /// block (the unwind destination).
3456  LandingPadInst *getLandingPadInst() const;
3457 
3458  BasicBlock *getSuccessor(unsigned i) const {
3459  assert(i < 2 && "Successor # out of range for invoke!");
3460  return i == 0 ? getNormalDest() : getUnwindDest();
3461  }
3462 
3463  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3464  assert(idx < 2 && "Successor # out of range for invoke!");
3465  *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3466  }
3467 
3468  unsigned getNumSuccessors() const { return 2; }
3469 
3470  // Methods for support type inquiry through isa, cast, and dyn_cast:
3471  static inline bool classof(const Instruction *I) {
3472  return (I->getOpcode() == Instruction::Invoke);
3473  }
3474  static inline bool classof(const Value *V) {
3475  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3476  }
3477 
3478 private:
3479  BasicBlock *getSuccessorV(unsigned idx) const override;
3480  unsigned getNumSuccessorsV() const override;
3481  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3482 
3483  bool hasFnAttrImpl(Attribute::AttrKind A) const;
3484 
3485  // Shadow Instruction::setInstructionSubclassData with a private forwarding
3486  // method so that subclasses cannot accidentally use it.
3487  void setInstructionSubclassData(unsigned short D) {
3489  }
3490 };
3491 
3492 template <>
3493 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3494 };
3495 
3496 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3497  BasicBlock *IfException, ArrayRef<Value *> Args,
3498  unsigned Values, const Twine &NameStr,
3499  Instruction *InsertBefore)
3500  : TerminatorInst(Ty->getReturnType(), Instruction::Invoke,
3501  OperandTraits<InvokeInst>::op_end(this) - Values, Values,
3502  InsertBefore) {
3503  init(Ty, Func, IfNormal, IfException, Args, NameStr);
3504 }
3505 InvokeInst::InvokeInst(Value *Func,
3506  BasicBlock *IfNormal, BasicBlock *IfException,
3507  ArrayRef<Value *> Args, unsigned Values,
3508  const Twine &NameStr, BasicBlock *InsertAtEnd)
3509  : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3510  ->getElementType())->getReturnType(),
3511  Instruction::Invoke,
3512  OperandTraits<InvokeInst>::op_end(this) - Values,
3513  Values, InsertAtEnd) {
3514  init(Func, IfNormal, IfException, Args, NameStr);
3515 }
3516 
3517 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3518 
3519 //===----------------------------------------------------------------------===//
3520 // ResumeInst Class
3521 //===----------------------------------------------------------------------===//
3522 
3523 //===---------------------------------------------------------------------------
3524 /// ResumeInst - Resume the propagation of an exception.
3525 ///
3526 class ResumeInst : public TerminatorInst {
3527  ResumeInst(const ResumeInst &RI);
3528 
3529  explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3530  ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3531 protected:
3532  // Note: Instruction needs to be a friend here to call cloneImpl.
3533  friend class Instruction;
3534  ResumeInst *cloneImpl() const;
3535 
3536 public:
3537  static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3538  return new(1) ResumeInst(Exn, InsertBefore);
3539  }
3540  static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3541  return new(1) ResumeInst(Exn, InsertAtEnd);
3542  }
3543 
3544  /// Provide fast operand accessors
3546 
3547  /// Convenience accessor.
3548  Value *getValue() const { return Op<0>(); }
3549 
3550  unsigned getNumSuccessors() const { return 0; }
3551 
3552  // Methods for support type inquiry through isa, cast, and dyn_cast:
3553  static inline bool classof(const Instruction *I) {
3554  return I->getOpcode() == Instruction::Resume;
3555  }
3556  static inline bool classof(const Value *V) {
3557  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3558  }
3559 private:
3560  BasicBlock *getSuccessorV(unsigned idx) const override;
3561  unsigned getNumSuccessorsV() const override;
3562  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3563 };
3564 
3565 template <>
3567  public FixedNumOperandTraits<ResumeInst, 1> {
3568 };
3569 
3571 
3572 //===----------------------------------------------------------------------===//
3573 // UnreachableInst Class
3574 //===----------------------------------------------------------------------===//
3575 
3576 //===---------------------------------------------------------------------------
3577 /// UnreachableInst - This function has undefined behavior. In particular, the
3578 /// presence of this instruction indicates some higher level knowledge that the
3579 /// end of the block cannot be reached.
3580 ///
3582  void *operator new(size_t, unsigned) = delete;
3583 protected:
3584  // Note: Instruction needs to be a friend here to call cloneImpl.
3585  friend class Instruction;
3586  UnreachableInst *cloneImpl() const;
3587 
3588 public:
3589  // allocate space for exactly zero operands
3590  void *operator new(size_t s) {
3591  return User::operator new(s, 0);
3592  }
3593  explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
3594  explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3595 
3596  unsigned getNumSuccessors() const { return 0; }
3597 
3598  // Methods for support type inquiry through isa, cast, and dyn_cast:
3599  static inline bool classof(const Instruction *I) {
3600  return I->getOpcode() == Instruction::Unreachable;
3601  }
3602  static inline bool classof(const Value *V) {
3603  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3604  }
3605 private:
3606  BasicBlock *getSuccessorV(unsigned idx) const override;
3607  unsigned getNumSuccessorsV() const override;
3608  void setSuccessorV(unsigned idx, BasicBlock *B) override;
3609 };
3610 
3611 //===----------------------------------------------------------------------===//
3612 // TruncInst Class
3613 //===----------------------------------------------------------------------===//
3614 
3615 /// \brief This class represents a truncation of integer types.
3616 class TruncInst : public CastInst {
3617 protected:
3618  // Note: Instruction needs to be a friend here to call cloneImpl.
3619  friend class Instruction;
3620  /// \brief Clone an identical TruncInst
3621  TruncInst *cloneImpl() const;
3622 
3623 public:
3624  /// \brief Constructor with insert-before-instruction semantics
3625  TruncInst(
3626  Value *S, ///< The value to be truncated
3627  Type *Ty, ///< The (smaller) type to truncate to
3628  const Twine &NameStr = "", ///< A name for the new instruction
3629  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3630  );
3631 
3632  /// \brief Constructor with insert-at-end-of-block semantics
3633  TruncInst(
3634  Value *S, ///< The value to be truncated
3635  Type *Ty, ///< The (smaller) type to truncate to
3636  const Twine &NameStr, ///< A name for the new instruction
3637  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3638  );
3639 
3640  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3641  static inline bool classof(const Instruction *I) {
3642  return I->getOpcode() == Trunc;
3643  }
3644  static inline bool classof(const Value *V) {
3645  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3646  }
3647 };
3648 
3649 //===----------------------------------------------------------------------===//
3650 // ZExtInst Class
3651 //===----------------------------------------------------------------------===//
3652 
3653 /// \brief This class represents zero extension of integer types.
3654 class ZExtInst : public CastInst {
3655 protected:
3656  // Note: Instruction needs to be a friend here to call cloneImpl.
3657  friend class Instruction;
3658  /// \brief Clone an identical ZExtInst
3659  ZExtInst *cloneImpl() const;
3660 
3661 public:
3662  /// \brief Constructor with insert-before-instruction semantics
3663  ZExtInst(
3664  Value *S, ///< The value to be zero extended
3665  Type *Ty, ///< The type to zero extend to
3666  const Twine &NameStr = "", ///< A name for the new instruction
3667  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3668  );
3669 
3670  /// \brief Constructor with insert-at-end semantics.
3671  ZExtInst(
3672  Value *S, ///< The value to be zero extended
3673  Type *Ty, ///< The type to zero extend to
3674  const Twine &NameStr, ///< A name for the new instruction
3675  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3676  );
3677 
3678  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3679  static inline bool classof(const Instruction *I) {
3680  return I->getOpcode() == ZExt;
3681  }
3682  static inline bool classof(const Value *V) {
3683  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3684  }
3685 };
3686 
3687 //===----------------------------------------------------------------------===//
3688 // SExtInst Class
3689 //===----------------------------------------------------------------------===//
3690 
3691 /// \brief This class represents a sign extension of integer types.
3692 class SExtInst : public CastInst {
3693 protected:
3694  // Note: Instruction needs to be a friend here to call cloneImpl.
3695  friend class Instruction;
3696  /// \brief Clone an identical SExtInst
3697  SExtInst *cloneImpl() const;
3698 
3699 public:
3700  /// \brief Constructor with insert-before-instruction semantics
3701  SExtInst(
3702  Value *S, ///< The value to be sign extended
3703  Type *Ty, ///< The type to sign extend to
3704  const Twine &NameStr = "", ///< A name for the new instruction
3705  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3706  );
3707 
3708  /// \brief Constructor with insert-at-end-of-block semantics
3709  SExtInst(
3710  Value *S, ///< The value to be sign extended
3711  Type *Ty, ///< The type to sign extend to
3712  const Twine &NameStr, ///< A name for the new instruction
3713  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3714  );
3715 
3716  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3717  static inline bool classof(const Instruction *I) {
3718  return I->getOpcode() == SExt;
3719  }
3720  static inline bool classof(const Value *V) {
3721  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3722  }
3723 };
3724 
3725 //===----------------------------------------------------------------------===//
3726 // FPTruncInst Class
3727 //===----------------------------------------------------------------------===//
3728 
3729 /// \brief This class represents a truncation of floating point types.
3730 class FPTruncInst : public CastInst {
3731 protected:
3732  // Note: Instruction needs to be a friend here to call cloneImpl.
3733  friend class Instruction;
3734  /// \brief Clone an identical FPTruncInst
3735  FPTruncInst *cloneImpl() const;
3736 
3737 public:
3738  /// \brief Constructor with insert-before-instruction semantics
3739  FPTruncInst(
3740  Value *S, ///< The value to be truncated
3741  Type *Ty, ///< The type to truncate to
3742  const Twine &NameStr = "", ///< A name for the new instruction
3743  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3744  );
3745 
3746  /// \brief Constructor with insert-before-instruction semantics
3747  FPTruncInst(
3748  Value *S, ///< The value to be truncated
3749  Type *Ty, ///< The type to truncate to
3750  const Twine &NameStr, ///< A name for the new instruction
3751  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3752  );
3753 
3754  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3755  static inline bool classof(const Instruction *I) {
3756  return I->getOpcode() == FPTrunc;
3757  }
3758  static inline bool classof(const Value *V) {
3759  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3760  }
3761 };
3762 
3763 //===----------------------------------------------------------------------===//
3764 // FPExtInst Class
3765 //===----------------------------------------------------------------------===//
3766 
3767 /// \brief This class represents an extension of floating point types.
3768 class FPExtInst : public CastInst {
3769 protected:
3770  // Note: Instruction needs to be a friend here to call cloneImpl.
3771  friend class Instruction;
3772  /// \brief Clone an identical FPExtInst
3773  FPExtInst *cloneImpl() const;
3774 
3775 public:
3776  /// \brief Constructor with insert-before-instruction semantics
3777  FPExtInst(
3778  Value *S, ///< The value to be extended
3779  Type *Ty, ///< The type to extend to
3780  const Twine &NameStr = "", ///< A name for the new instruction
3781  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3782  );
3783 
3784  /// \brief Constructor with insert-at-end-of-block semantics
3785  FPExtInst(
3786  Value *S, ///< The value to be extended
3787  Type *Ty, ///< The type to extend to
3788  const Twine &NameStr, ///< A name for the new instruction
3789  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3790  );
3791 
3792  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3793  static inline bool classof(const Instruction *I) {
3794  return I->getOpcode() == FPExt;
3795  }
3796  static inline bool classof(const Value *V) {
3797  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3798  }
3799 };
3800 
3801 //===----------------------------------------------------------------------===//
3802 // UIToFPInst Class
3803 //===----------------------------------------------------------------------===//
3804 
3805 /// \brief This class represents a cast unsigned integer to floating point.
3806 class UIToFPInst : public CastInst {
3807 protected:
3808  // Note: Instruction needs to be a friend here to call cloneImpl.
3809  friend class Instruction;
3810  /// \brief Clone an identical UIToFPInst
3811  UIToFPInst *cloneImpl() const;
3812 
3813 public:
3814  /// \brief Constructor with insert-before-instruction semantics
3815  UIToFPInst(
3816  Value *S, ///< The value to be converted
3817  Type *Ty, ///< The type to convert to
3818  const Twine &NameStr = "", ///< A name for the new instruction
3819  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3820  );
3821 
3822  /// \brief Constructor with insert-at-end-of-block semantics
3823  UIToFPInst(
3824  Value *S, ///< The value to be converted
3825  Type *Ty, ///< The type to convert to
3826  const Twine &NameStr, ///< A name for the new instruction
3827  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3828  );
3829 
3830  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3831  static inline bool classof(const Instruction *I) {
3832  return I->getOpcode() == UIToFP;
3833  }
3834  static inline bool classof(const Value *V) {
3835  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3836  }
3837 };
3838 
3839 //===----------------------------------------------------------------------===//
3840 // SIToFPInst Class
3841 //===----------------------------------------------------------------------===//
3842 
3843 /// \brief This class represents a cast from signed integer to floating point.
3844 class SIToFPInst : public CastInst {
3845 protected:
3846  // Note: Instruction needs to be a friend here to call cloneImpl.
3847  friend class Instruction;
3848  /// \brief Clone an identical SIToFPInst
3849  SIToFPInst *cloneImpl() const;
3850 
3851 public:
3852  /// \brief Constructor with insert-before-instruction semantics
3853  SIToFPInst(
3854  Value *S, ///< The value to be converted
3855  Type *Ty, ///< The type to convert to
3856  const Twine &NameStr = "", ///< A name for the new instruction
3857  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3858  );
3859 
3860  /// \brief Constructor with insert-at-end-of-block semantics
3861  SIToFPInst(
3862  Value *S, ///< The value to be converted
3863  Type *Ty, ///< The type to convert to
3864  const Twine &NameStr, ///< A name for the new instruction
3865  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3866  );
3867 
3868  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3869  static inline bool classof(const Instruction *I) {
3870  return I->getOpcode() == SIToFP;
3871  }
3872  static inline bool classof(const Value *V) {
3873  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3874  }
3875 };
3876 
3877 //===----------------------------------------------------------------------===//
3878 // FPToUIInst Class
3879 //===----------------------------------------------------------------------===//
3880 
3881 /// \brief This class represents a cast from floating point to unsigned integer
3882 class FPToUIInst : public CastInst {
3883 protected:
3884  // Note: Instruction needs to be a friend here to call cloneImpl.
3885  friend class Instruction;
3886  /// \brief Clone an identical FPToUIInst
3887  FPToUIInst *cloneImpl() const;
3888 
3889 public:
3890  /// \brief Constructor with insert-before-instruction semantics
3891  FPToUIInst(
3892  Value *S, ///< The value to be converted
3893  Type *Ty, ///< The type to convert to
3894  const Twine &NameStr = "", ///< A name for the new instruction
3895  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3896  );
3897 
3898  /// \brief Constructor with insert-at-end-of-block semantics
3899  FPToUIInst(
3900  Value *S, ///< The value to be converted
3901  Type *Ty, ///< The type to convert to
3902  const Twine &NameStr, ///< A name for the new instruction
3903  BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3904  );
3905 
3906  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3907  static inline bool classof(const Instruction *I) {
3908  return I->getOpcode() == FPToUI;
3909  }
3910  static inline bool classof(const Value *V) {
3911  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3912  }
3913 };
3914 
3915 //===----------------------------------------------------------------------===//
3916 // FPToSIInst Class
3917 //===----------------------------------------------------------------------===//
3918 
3919 /// \brief This class represents a cast from floating point to signed integer.
3920 class FPToSIInst : public CastInst {
3921 protected:
3922  // Note: Instruction needs to be a friend here to call cloneImpl.
3923  friend class Instruction;
3924  /// \brief Clone an identical FPToSIInst
3925  FPToSIInst *cloneImpl() const;
3926 
3927 public:
3928  /// \brief Constructor with insert-before-instruction semantics
3929  FPToSIInst(
3930  Value *S, ///< The value to be converted
3931  Type *Ty, ///< The type to convert to
3932  const Twine &NameStr = "", ///< A name for the new instruction
3933  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3934  );
3935 
3936  /// \brief Constructor with insert-at-end-of-block semantics
3937  FPToSIInst(
3938  Value *S, ///< The value to be converted
3939  Type *Ty, ///< The type to convert to
3940  const Twine &NameStr, ///< A name for the new instruction
3941  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3942  );
3943 
3944  /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3945  static inline bool classof(const Instruction *I) {
3946  return I->getOpcode() == FPToSI;
3947  }
3948  static inline bool classof(const Value *V) {
3949  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3950  }
3951 };
3952 
3953 //===----------------------------------------------------------------------===//
3954 // IntToPtrInst Class
3955 //===----------------------------------------------------------------------===//
3956 
3957 /// \brief This class represents a cast from an integer to a pointer.
3958 class IntToPtrInst : public CastInst {
3959 public:
3960  /// \brief Constructor with insert-before-instruction semantics
3961  IntToPtrInst(
3962  Value *S, ///< The value to be converted
3963  Type *Ty, ///< The type to convert to
3964  const Twine &NameStr = "", ///< A name for the new instruction
3965  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3966  );
3967 
3968  /// \brief Constructor with insert-at-end-of-block semantics
3969  IntToPtrInst(
3970  Value *S, ///< The value to be converted
3971  Type *Ty, ///< The type to convert to
3972  const Twine &NameStr, ///< A name for the new instruction
3973  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3974  );
3975 
3976  // Note: Instruction needs to be a friend here to call cloneImpl.
3977  friend class Instruction;
3978  /// \brief Clone an identical IntToPtrInst
3979  IntToPtrInst *cloneImpl() const;
3980 
3981  /// \brief Returns the address space of this instruction's pointer type.
3982  unsigned getAddressSpace() const {
3983  return getType()->getPointerAddressSpace();
3984  }
3985 
3986  // Methods for support type inquiry through isa, cast, and dyn_cast:
3987  static inline bool classof(const Instruction *I) {
3988  return I->getOpcode() == IntToPtr;
3989  }
3990  static inline bool classof(const Value *V) {
3991  return isa<Instruction>(V) && classof(cast<Instruction>(V));
3992  }
3993 };
3994 
3995 //===----------------------------------------------------------------------===//
3996 // PtrToIntInst Class
3997 //===----------------------------------------------------------------------===//
3998 
3999 /// \brief This class represents a cast from a pointer to an integer
4000 class PtrToIntInst : public CastInst {
4001 protected:
4002  // Note: Instruction needs to be a friend here to call cloneImpl.
4003  friend class Instruction;
4004  /// \brief Clone an identical PtrToIntInst
4005  PtrToIntInst *cloneImpl() const;
4006 
4007 public:
4008  /// \brief Constructor with insert-before-instruction semantics
4009  PtrToIntInst(
4010  Value *S, ///< The value to be converted
4011  Type *Ty, ///< The type to convert to
4012  const Twine &NameStr = "", ///< A name for the new instruction
4013  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4014  );
4015 
4016  /// \brief Constructor with insert-at-end-of-block semantics
4017  PtrToIntInst(
4018  Value *S, ///< The value to be converted
4019  Type *Ty, ///< The type to convert to
4020  const Twine &NameStr, ///< A name for the new instruction
4021  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4022  );
4023 
4024  /// \brief Gets the pointer operand.
4026  /// \brief Gets the pointer operand.
4027  const Value *getPointerOperand() const { return getOperand(0); }
4028  /// \brief Gets the operand index of the pointer operand.
4029  static unsigned getPointerOperandIndex() { return 0U; }
4030 
4031  /// \brief Returns the address space of the pointer operand.
4032  unsigned getPointerAddressSpace() const {
4034  }
4035 
4036  // Methods for support type inquiry through isa, cast, and dyn_cast:
4037  static inline bool classof(const Instruction *I) {
4038  return I->getOpcode() == PtrToInt;
4039  }
4040  static inline bool classof(const Value *V) {
4041  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4042  }
4043 };
4044 
4045 //===----------------------------------------------------------------------===//
4046 // BitCastInst Class
4047 //===----------------------------------------------------------------------===//
4048 
4049 /// \brief This class represents a no-op cast from one type to another.
4050 class BitCastInst : public CastInst {
4051 protected:
4052  // Note: Instruction needs to be a friend here to call cloneImpl.
4053  friend class Instruction;
4054  /// \brief Clone an identical BitCastInst
4055  BitCastInst *cloneImpl() const;
4056 
4057 public:
4058  /// \brief Constructor with insert-before-instruction semantics
4059  BitCastInst(
4060  Value *S, ///< The value to be casted
4061  Type *Ty, ///< The type to casted to
4062  const Twine &NameStr = "", ///< A name for the new instruction
4063  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4064  );
4065 
4066  /// \brief Constructor with insert-at-end-of-block semantics
4067  BitCastInst(
4068  Value *S, ///< The value to be casted
4069  Type *Ty, ///< The type to casted to
4070  const Twine &NameStr, ///< A name for the new instruction
4071  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4072  );
4073 
4074  // Methods for support type inquiry through isa, cast, and dyn_cast:
4075  static inline bool classof(const Instruction *I) {
4076  return I->getOpcode() == BitCast;
4077  }
4078  static inline bool classof(const Value *V) {
4079  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4080  }
4081 };
4082 
4083 //===----------------------------------------------------------------------===//
4084 // AddrSpaceCastInst Class
4085 //===----------------------------------------------------------------------===//
4086 
4087 /// \brief This class represents a conversion between pointers from
4088 /// one address space to another.
4089 class AddrSpaceCastInst : public CastInst {
4090 protected:
4091  // Note: Instruction needs to be a friend here to call cloneImpl.
4092  friend class Instruction;
4093  /// \brief Clone an identical AddrSpaceCastInst
4094  AddrSpaceCastInst *cloneImpl() const;
4095 
4096 public:
4097  /// \brief Constructor with insert-before-instruction semantics
4099  Value *S, ///< The value to be casted
4100  Type *Ty, ///< The type to casted to
4101  const Twine &NameStr = "", ///< A name for the new instruction
4102  Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4103  );
4104 
4105  /// \brief Constructor with insert-at-end-of-block semantics
4107  Value *S, ///< The value to be casted
4108  Type *Ty, ///< The type to casted to
4109  const Twine &NameStr, ///< A name for the new instruction
4110  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4111  );
4112 
4113  // Methods for support type inquiry through isa, cast, and dyn_cast:
4114  static inline bool classof(const Instruction *I) {
4115  return I->getOpcode() == AddrSpaceCast;
4116  }
4117  static inline bool classof(const Value *V) {
4118  return isa<Instruction>(V) && classof(cast<Instruction>(V));
4119  }
4120 };
4121 
4122 } // End llvm namespace
4123 
4124 #endif
static unsigned getInsertedValueOperandIndex()
const Value * getAddress() const
const Use & getOperandUse(unsigned i) const
Definition: User.h:129
BasicBlock * getSuccessor(unsigned i) const
void removeAttribute(unsigned i, Attribute attr)
removeAttribute - removes the attribute from the list of attributes.
ReturnInst - Return a value (possibly void), from a function.
Value * getValueOperand()
Definition: Instructions.h:406
const Value * getCalledValue() const
getCalledValue - 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:111
void setAttributes(const AttributeSet &Attrs)
setAttributes - Set the parameter attributes for this invoke.
AllocaInst(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="", Instruction *InsertBefore=nullptr)
static bool isEquality(Predicate Pred)
Determine if this is an equality predicate.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
AtomicOrdering getFailureOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:597
void setDoesNotThrow()
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:679
ConstantIntTy * getCaseValue()
Resolves case value for current case.
void getShuffleMask(SmallVectorImpl< int > &Result) const
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - Add an incoming value to the end of the PHI list
ExtractValueInst - This instruction extracts a struct member or array element value from an aggregate...
*p = old <signed v ? old : v
Definition: Instructions.h:704
iterator_range< CaseIt > cases()
cases - iteration adapter for range-for loops.
static bool classof(const Value *V)
Value * getAggregateOperand()
static bool classof(const Instruction *I)
static bool classof(const Instruction *I)
Definition: Instructions.h:419
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:878
Type * getSourceElementType() const
Definition: Instructions.h:926
static bool classof(const Value *V)
bool isVolatile() const
isVolatile - Return true if this is a store to a volatile memory location.
Definition: Instructions.h:351
SynchronizationScope getSynchScope() const
Definition: Instructions.h:383
ArrayRef< unsigned > getIndices() const
Various leaf nodes.
Definition: ISDOpcodes.h:60
void setCalledFunction(Value *Fn)
setCalledFunction - Set the function called.
void allocHungoffUses(unsigned N)
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:753
static bool classof(const Instruction *I)
void setAlignment(unsigned Align)
AtomicOrdering getSuccessOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:592
FenceInst - an instruction for ordering other memory operations.
Definition: Instructions.h:445
unsigned getSuccessorIndex() const
Returns TerminatorInst's successor index for current case successor.
ExtractElementInst * cloneImpl() const
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
Definition: Instructions.h:515
bool isAtLeastAcquire(AtomicOrdering Ord)
Returns true if the ordering is at least as strong as acquire (i.e.
Definition: Instructions.h:56
PtrToIntInst * cloneImpl() const
Clone an identical PtrToIntInst.
int getMaskValue(unsigned i) const
bool hasFnAttr(Attribute::AttrKind A) const
Determine whether this call has the given attribute.
iterator_range< const_op_iterator > arg_operands() const
arg_operands - 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:487
This class represents zero extension of integer types.
unsigned getNumOperands() const
Definition: User.h:138
unsigned getNumSuccessors() const
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:976
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Value * getValue() const
Convenience accessor.
bool isSimple() const
Definition: Instructions.h:401
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:787
Value * getPointerOperand()
Gets the pointer operand.
CallInst - 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:256
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
static bool classof(const Value *V)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
Definition: Type.cpp:738
Function * getCalledFunction() const
getCalledFunction - Return the function called, or null if this is an indirect function invocation...
CaseIt case_begin()
Returns a read/write iterator that points to the first case in SwitchInst.
*p = old <unsigned v ? old : v
Definition: Instructions.h:708
void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
Definition: Instructions.h:125
CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum)
Initializes case iterator for given SwitchInst and for given case number.
void setVolatile(bool V)
setVolatile - Specify whether this is a volatile cmpxchg.
Definition: Instructions.h:550
*p = old >unsigned v ? old : v
Definition: Instructions.h:706
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
static bool classof(const Value *V)
static bool classof(const Value *V)
iterator_range< op_iterator > arg_operands()
arg_operands - iteration adapter for range-for loops.
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:713
bool doesNotThrow() const
Determine if the call cannot unwind.
static bool classof(const Instruction *I)
static bool isEquality(Predicate P)
isEquality - Return true if this predicate is either EQ or NE.
unsigned getNumIndices() const
void setSuccessor(unsigned i, BasicBlock *NewSucc)
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
Definition: Attributes.cpp:997
F(f)
This class represents a sign extension of integer types.
LoadInst - an instruction for reading from memory.
Definition: Instructions.h:177
static bool classof(const Value *V)
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:822
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
Definition: Instructions.h:674
void setAddress(Value *V)
Hexagon Common GEP
LoadInst(Value *Ptr, const char *NameStr=nullptr, bool isVolatile=false, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:221
CaseIt(SwitchInst *SI, unsigned CaseNum)
static Instruction * CreateFree(Value *Source, Instruction *InsertBefore)
CreateFree - Generate the IR for a call to the builtin free function.
static bool classof(const Value *V)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: Type.cpp:216
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
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:956
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:780
bool isSimple() const
Definition: Instructions.h:279
*p = old >signed v ? old : v
Definition: Instructions.h:702
void setSynchScope(SynchronizationScope SynchScope)
Specify whether this cmpxchg is atomic and orders other operations with respect to all concurrently e...
Definition: Instructions.h:586
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:183
Value * removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true)
ConstantInt * findCaseDest(BasicBlock *BB)
findCaseDest - 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
FPExtInst * cloneImpl() const
Clone an identical FPExtInst.
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BasicBlock *InsertAtEnd)
void setVolatile(bool V)
setVolatile - Specify whether this is a volatile RMW or not.
Definition: Instructions.h:744
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
isArrayAllocation - Return true if there is an allocation size parameter to the allocation instructio...
ArrayRef< unsigned > getIndices() const
static bool classof(const Instruction *I)
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:708
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:268
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:869
static bool isRelational(Predicate P)
isRelational - 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:707
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:504
SelectInst - 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:79
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:389
bool hasFnAttr(StringRef A) const
Determine whether this call has the given attribute.
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool isUnordered() const
Definition: Instructions.h:280
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
static bool classof(const Value *V)
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
void setSynchScope(SynchronizationScope xthread)
Specify whether this store instruction is ordered with respect to all concurrently executing threads...
Definition: Instructions.h:390
static bool classof(const Value *V)
void setOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this fence.
Definition: Instructions.h:475
bool onlyAccessesArgMemory() const
Determine if the call access memmory only using it's pointer arguments.
void setIsInBounds(bool b=true)
setIsInBounds - 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
getNumArgOperands - Return the number of call arguments.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
VectorType * getVectorOperandType() const
unsigned getNumIndices() const
const Value * getCalledValue() const
getCalledValue - 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...
FCmpInst * cloneImpl() const
Clone an identical FCmpInst.
SynchronizationScope
Definition: Instructions.h:49
bool isCommutative() const
Determine if this relation is commutative.
bool isMustTailCall() const
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.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
Value * getPointerOperand()
Type * getPointerOperandType() const
getPointerOperandType - Method to return the pointer operand as a PointerType.
Definition: Instructions.h:971
block_iterator block_begin()
unsigned getNumSuccessors() const
Value * getFalseValue()
Function does not access memory.
Definition: Attributes.h:99
BasicBlock * getDestination(unsigned i)
getDestination - Return the specified destination.
Hidden pointer to structure to return.
Definition: Attributes.h:114
iterator_range< ConstCaseIt > cases() const
cases - iteration adapter for range-for loops.
static bool classof(const Instruction *I)
SynchronizationScope getSynchScope() const
Definition: Instructions.h:261
This class represents a cast from a pointer to an integer.
AtomicOrdering
Definition: Instructions.h:38
bool doesNotThrow() const
Determine if the call cannot unwind.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:414
void setUnwindDest(BasicBlock *B)
UIToFPInst * cloneImpl() const
Clone an identical UIToFPInst.
~AllocaInst() override
const_op_iterator idx_end() const
Definition: Instructions.h:957
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: Instructions.h:273
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
bool isVolatile() const
isVolatile - Return true if this is a cmpxchg from a volatile memory location.
Definition: Instructions.h:544
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
Definition: Instructions.h:769
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:887
void setCleanup(bool V)
setCleanup - Indicate that this landingpad instruction is a cleanup.
static bool classof(const Instruction *I)
BitCastInst * cloneImpl() const
Clone an identical BitCastInst.
static bool classof(const Value *V)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static bool classof(const Instruction *I)
Definition: Instructions.h:295
VectorType * getType() const
getType - 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.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:686
void setNormalDest(BasicBlock *B)
bool hasFnAttr(Attribute::AttrKind A) const
Determine whether this call has the given attribute.
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
getIncomingBlock - Return incoming basic block corresponding to an operand of the PHI...
op_iterator idx_begin()
Definition: Instructions.h:954
StoreInst * cloneImpl() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
Value * getInsertedValueOperand()
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.
Pass structure by value.
Definition: Attributes.h:73
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
static bool classof(const Value *V)
unsigned getNumClauses() const
getNumClauses - 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.
void setInstructionSubclassData(unsigned short D)
Definition: Instruction.h:499
StoreInst - an instruction for storing to memory.
Definition: Instructions.h:316
This class represents a cast from floating point to signed integer.
BasicBlock * getIncomingBlock(Value::const_user_iterator I) const
getIncomingBlock - Return incoming basic block corresponding to value use iterator.
const Value * getPointerOperand() const
Gets the pointer operand.
static bool classof(const Value *V)
Definition: Instructions.h:158
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)
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
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:134
bool isAtomic() const
isAtomic - 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
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
Definition: Casting.h:222
bool isInBounds() const
isInBounds - Determine whether the GEP has the inbounds flag.
void addAttribute(unsigned i, Attribute::AttrKind attr)
addAttribute - adds the attribute to the list of attributes.
PointerType - Class to represent pointers.
Definition: DerivedTypes.h:449
OtherOps getOpcode() const
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
FPTruncInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
SIToFPInst * cloneImpl() const
Clone an identical SIToFPInst.
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
Definition: Instructions.h:830
LoadInst * cloneImpl() const
static bool classof(const Instruction *I)
bool isFilter(unsigned Idx) const
isFilter - Return 'true' if the clause and index Idx is a filter clause.
static bool classof(const Value *V)
static unsigned getPointerOperandIndex()
Definition: Instructions.h:609
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
always inline
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
void setDoesNotAccessMemory()
VAArgInst(Value *List, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
Definition: Instructions.h:365
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:35
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:775
static unsigned getAggregateOperandIndex()
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
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:411
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
BranchInst - Conditional or Unconditional Branch instruction.
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
Definition: Type.h:226
const Value * getAggregateOperand() const
bool isEquality() const
isEquality - 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).
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
Definition: Constant.h:41
PointerType * getType() const
getType - Overload to return most specific pointer type
Definition: Instructions.h:115
const Value * getCondition() const
ResumeInst - Resume the propagation of an exception.
void setFailureOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:576
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
Definition: Instructions.h:149
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
void setCalledFunction(FunctionType *FTy, Value *Fn)
IndirectBrInst - Indirect Branch Instruction.
unsigned getAlignment() const
getAlignment - Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:130
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const
Determine whether the call or the callee has the given attributes.
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:185
bool hasAllZeroIndices() const
hasAllZeroIndices - Return true if all of the indices of this GEP are zeros.
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - 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:908
static unsigned getPointerOperandIndex()
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:143
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:894
This instruction compares its operands according to the predicate given to the constructor.
const Value * getValueOperand() const
Definition: Instructions.h:407
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:118
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:706
Value * getPointerOperand()
Definition: Instructions.h:284
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)
Function doesn't unwind stack.
Definition: Attributes.h:96
iterator_range< const_op_iterator > arg_operands() const
arg_operands - iteration adapter for range-for loops.
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:760
static bool classof(const Value *V)
static Type * getGEPReturnType(Type *ElTy, Value *Ptr, ArrayRef< Value * > IdxList)
Definition: Instructions.h:987
bool isUnordered() const
Definition: Instructions.h:402
void setTailCallKind(TailCallKind TCK)
void setSourceElementType(Type *Ty)
Definition: Instructions.h:928
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:714
Mark the function as not returning.
Definition: Attributes.h:95
Value * getCondition()
CaseIteratorT< SwitchInstTy, ConstantIntTy, BasicBlockTy > Self
static bool classof(const Value *V)
Definition: Instructions.h:422
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
void setTailCall(bool isTC=true)
FunctionType * getFunctionType() const
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
FPToUIInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Instruction *I)
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:395
bool hasAllConstantIndices() const
hasAllConstantIndices - Return true if all of the indices of this GEP are constant integers...
static unsigned getIncomingValueNumForOperand(unsigned i)
bool isNoInline() const
Return true if the call should not be inlined.
static bool isValidOperands(const Value *Vec, const Value *Idx)
isValidOperands - Return true if an extractelement instruction can be formed with the specified opera...
const Value * getTrueValue() const
static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex)
Initializes case iterator for given SwitchInst and for given TerminatorInst's successor index...
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:854
Call cannot be duplicated.
Definition: Attributes.h:86
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
unsigned getNumSuccessors() const
FunctionType * getFunctionType() const
bool isRelational() const
isRelational - 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:645
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
static bool classof(const Value *V)
Definition: Instructions.h:496
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:938
void setOnlyAccessesArgMemory()
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success...
Definition: Instructions.h:630
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.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, BasicBlock *InsertAtEnd)
bool isConditional() const
SequentialType - This is the superclass of the array, pointer and vector type classes.
Definition: DerivedTypes.h:310
idx_iterator idx_begin() const
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile=false, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:189
static bool classof(const Value *V)
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * getValOperand()
Definition: Instructions.h:783
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:372
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
static bool classof(const Instruction *I)
void setIncomingBlock(unsigned i, BasicBlock *BB)
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
AtomicCmpXchgInst * cloneImpl() const
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
unsigned getVectorNumElements() const
Definition: Type.cpp:212
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
GetGEPReturnType - Returns the pointer type returned by the GEP instruction, which may be a vector of...
Definition: Instructions.h:982
static bool classof(const Instruction *I)
Definition: Instructions.h:792
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 getNumSuccessors() const
const BasicBlock * getDestination(unsigned i) const
static bool classof(const Instruction *I)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
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
isStaticAlloca - Return true if this alloca is in the entry block of the function and is a constant s...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
const Value * getCompareOperand() const
Definition: Instructions.h:612
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Callee is recognized as a builtin, despite nobuiltin attribute on its declaration.
Definition: Attributes.h:71
void mutateFunctionType(FunctionType *FTy)
const Value * getValOperand() const
Definition: Instructions.h:784
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore)
TailCallKind getTailCallKind() const
This class represents a range of values.
Definition: ConstantRange.h:43
bool isVolatile() const
isVolatile - Return true if this is a load from a volatile memory location.
Definition: Instructions.h:232
bool isEquality() const
Determine if this is an equality predicate.
This class represents a cast from floating point to unsigned integer.
BasicBlockTy * getCaseSuccessor()
Resolves successor for current case.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
SequentialType * getType() const
Definition: Instructions.h:922
void setCannotDuplicate()
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition: InstrTypes.h:799
static CallInst * Create(FunctionType *Ty, Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Function * getCalledFunction() const
getCalledFunction - 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:250
const Value * getAggregateOperand() const
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.
ZExtInst * cloneImpl() const
Clone an identical ZExtInst.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:289
CaseIt findCaseValue(const ConstantInt *C)
findCaseValue - Search all of the case values for the specified constant.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
BinOp getOperation() const
Definition: Instructions.h:726
static bool classof(const Instruction *I)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:765
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
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:122
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:576
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
SynchronizationScope getSynchScope() const
Definition: Instructions.h:480
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
A range adaptor for a pair of iterators.
VectorType - Class to represent vector types.
Definition: DerivedTypes.h:362
BasicBlock ** block_iterator
void setVolatile(bool V)
setVolatile - Specify whether this is a volatile store or not.
Definition: Instructions.h:355
Class for arbitrary precision integers.
Definition: APInt.h:73
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
VAArgInst(Value *List, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
void setWeak(bool IsWeak)
Definition: Instructions.h:560
void setResultElementType(Type *Ty)
Definition: Instructions.h:929
bool isCommutative() const
Determine if this is a commutative predicate.
Function only reads from memory.
Definition: Attributes.h:100
static bool classof(const Value *V)
LLVM_ATTRIBUTE_UNUSED_RESULT 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:285
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
isInlineAsm - Check if this call is an inline asm statement.
const AttributeSet & getAttributes() const
getAttributes - Return the parameter attributes for this call.
static CallInst * Create(Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
Definition: Type.cpp:51
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="")
CreateMalloc - Generate the IR for a call to malloc:
const Value * getNewValOperand() const
Definition: Instructions.h:615
AllocaInst * cloneImpl() const
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, AtomicOrdering Order, SynchronizationScope SynchScope=CrossThread, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:203
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:298
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:378
ConstCaseIt case_default() const
void setCalledFunction(Value *Fn)
setCalledFunction - Set the function called.
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).
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:293
Value * getCondition() const
const AttributeSet & getAttributes() const
getAttributes - Return the parameter attributes for this invoke.
BasicBlock * getDefaultDest() const
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:469
bool hasAttrSomewhere(Attribute::AttrKind Attr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
Definition: Attributes.cpp:973
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
Definition: Instructions.h:243
void setOperation(BinOp Operation)
Definition: Instructions.h:730
Value * getPointerOperand()
Definition: Instructions.h:779
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).
Callee isn't recognized as a builtin.
Definition: Attributes.h:84
void setOnlyAccessesArgMemory()
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool isCatch(unsigned Idx) const
isCatch - 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
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
void setArgOperand(unsigned i, Value *v)
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:902
static bool classof(const Value *V)
Definition: Instructions.h:795
bool isTailCall() const
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:705
Compile-time customization of User operands.
Definition: User.h:34
void size_t size
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
ExtractElementInst - This instruction extracts a single (scalar) element from a VectorType value...
unsigned getNumSuccessors() const
VectorType * getType() const
getType - 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:781
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.
bool isAtLeastRelease(AtomicOrdering Ord)
Returns true if the ordering is at least as strong as release (i.e.
Definition: Instructions.h:64
unsigned getNumCases() const
getNumCases - return the number of 'cases' in this switch instruction, except the default case ...
Funciton can access memory only using pointers based on its arguments.
Definition: Attributes.h:101
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:471
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setDoesNotReturn()
static CallInst * Create(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd)
void reserveClauses(unsigned Size)
reserveClauses - Grow the size of the operand list to accommodate the new number of clauses...
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static bool classof(const Value *V)
static bool classof(const Value *V)
Definition: Instructions.h:648
void setCondition(Value *V)
const_block_iterator block_begin() const
Use & getArgOperandUse(unsigned i)
SwitchInst - Multiway switch.
iterator_range< op_iterator > arg_operands()
arg_operands - iteration adapter for range-for loops.
static unsigned getPointerOperandIndex()
Definition: Instructions.h:286
const Value * getPointerOperand() const
Definition: Instructions.h:608
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:556
GetElementPtrInst * cloneImpl() const
void setAttributes(const AttributeSet &Attrs)
setAttributes - Set the parameter attributes for this call.
Type * getReturnType() const
Definition: DerivedTypes.h:121
Function can return twice.
Definition: Attributes.h:104
const ARM::ArchExtKind Kind
iterator_range< idx_iterator > indices() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:618
This class represents a truncation of floating point types.
void setSuccessOrdering(AtomicOrdering Ordering)
Set the ordering constraint on this cmpxchg.
Definition: Instructions.h:569
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:700
LLVM Value Representation.
Definition: Value.h:69
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
getOpcode() returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:112
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
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
Definition: Type.cpp:713
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
bool hasIndices() const
const Value * getArraySize() const
getArraySize - Get the number of elements allocated.
Definition: Instructions.h:110
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
bool hasIndices() const
void setCallingConv(CallingConv::ID CC)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
InvokeInst - Invoke instruction.
void setSynchScope(SynchronizationScope SynchScope)
Specify whether this RMW orders other operations with respect to all concurrently executing threads...
Definition: Instructions.h:763
static bool classof(const Instruction *I)
Definition: Instructions.h:493
TruncInst * cloneImpl() const
Clone an identical TruncInst.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
bool isCleanup() const
isCleanup - Return 'true' if this landingpad instruction is a cleanup.
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
const Value * getFalseValue() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
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:93
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
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
getAllocatedType - Return the type that is being allocated by the instruction.
Definition: Instructions.h:122
op_range incoming_values()
This class represents an extension of floating point types.
bool isRelational() const
Determine if this a relational predicate.
void setVolatile(bool V)
setVolatile - Specify whether this is a volatile load or not.
Definition: Instructions.h:236
SynchronizationScope getSynchScope() const
Returns whether this cmpxchg is atomic between threads or only within a single thread.
Definition: Instructions.h:603
const Value * getPointerOperand() const
Definition: Instructions.h:410
void setCannotDuplicate()
FPTruncInst * cloneImpl() const
Clone an identical FPTruncInst.
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of invoke arguments.
InsertValueInst * cloneImpl() const
Value * getPointerOperand()
Definition: Instructions.h:409
unsigned getNumSuccessors() const
int getBasicBlockIndex(const BasicBlock *BB) const
getBasicBlockIndex - Return the first index of the specified basic block in the value list for this P...
unsigned getNumDestinations() const
getNumDestinations - return the number of possible destinations in this indirectbr instruction...
const Value * getPointerOperand() const
Definition: Instructions.h:962
Value * getCalledValue()
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Type * getResultElementType() const
Definition: Instructions.h:931
static unsigned getPointerOperandIndex()
Definition: Instructions.h:965
const_op_iterator idx_begin() const
Definition: Instructions.h:955
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:699
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)
AllocaInst - an instruction to allocate memory on the stack.
Definition: Instructions.h:76
static bool classof(const Instruction *I)
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:64
bool operator==(const Self &RHS) const
bool isVolatile() const
isVolatile - Return true if this is a RMW on a volatile memory location.
Definition: Instructions.h:738
static bool classof(const Instruction *I)
Definition: Instructions.h:155
const Value * getPointerOperand() const
Definition: Instructions.h:285
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:195
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...