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