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