Clauses in a landingpad are always Constant. Use a stricter type.
[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   // Note that 'musttail' implies 'tail'.
1283   enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
1284   TailCallKind getTailCallKind() const {
1285     return TailCallKind(getSubclassDataFromInstruction() & 3);
1286   }
1287   bool isTailCall() const {
1288     return (getSubclassDataFromInstruction() & 3) != TCK_None;
1289   }
1290   bool isMustTailCall() const {
1291     return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1292   }
1293   void setTailCall(bool isTC = true) {
1294     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1295                                unsigned(isTC ? TCK_Tail : TCK_None));
1296   }
1297   void setTailCallKind(TailCallKind TCK) {
1298     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1299                                unsigned(TCK));
1300   }
1301
1302   /// Provide fast operand accessors
1303   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1304
1305   /// getNumArgOperands - Return the number of call arguments.
1306   ///
1307   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1308
1309   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1310   ///
1311   Value *getArgOperand(unsigned i) const { return getOperand(i); }
1312   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1313
1314   /// arg_operands - iteration adapter for range-for loops.
1315   iterator_range<op_iterator> arg_operands() {
1316     // The last operand in the op list is the callee - it's not one of the args
1317     // so we don't want to iterate over it.
1318     return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1319   }
1320
1321   /// arg_operands - iteration adapter for range-for loops.
1322   iterator_range<const_op_iterator> arg_operands() const {
1323     return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
1324   }
1325
1326   /// \brief Wrappers for getting the \c Use of a call argument.
1327   const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1328   Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1329
1330   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1331   /// function call.
1332   CallingConv::ID getCallingConv() const {
1333     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1334   }
1335   void setCallingConv(CallingConv::ID CC) {
1336     setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1337                                (static_cast<unsigned>(CC) << 2));
1338   }
1339
1340   /// getAttributes - Return the parameter attributes for this call.
1341   ///
1342   const AttributeSet &getAttributes() const { return AttributeList; }
1343
1344   /// setAttributes - Set the parameter attributes for this call.
1345   ///
1346   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1347
1348   /// addAttribute - adds the attribute to the list of attributes.
1349   void addAttribute(unsigned i, Attribute::AttrKind attr);
1350
1351   /// removeAttribute - removes the attribute from the list of attributes.
1352   void removeAttribute(unsigned i, Attribute attr);
1353
1354   /// \brief Determine whether this call has the given attribute.
1355   bool hasFnAttr(Attribute::AttrKind A) const {
1356     assert(A != Attribute::NoBuiltin &&
1357            "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1358     return hasFnAttrImpl(A);
1359   }
1360
1361   /// \brief Determine whether the call or the callee has the given attributes.
1362   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1363
1364   /// \brief Extract the alignment for a call or parameter (0=unknown).
1365   unsigned getParamAlignment(unsigned i) const {
1366     return AttributeList.getParamAlignment(i);
1367   }
1368
1369   /// \brief Return true if the call should not be treated as a call to a
1370   /// builtin.
1371   bool isNoBuiltin() const {
1372     return hasFnAttrImpl(Attribute::NoBuiltin) &&
1373       !hasFnAttrImpl(Attribute::Builtin);
1374   }
1375
1376   /// \brief Return true if the call should not be inlined.
1377   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1378   void setIsNoInline() {
1379     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1380   }
1381
1382   /// \brief Return true if the call can return twice
1383   bool canReturnTwice() const {
1384     return hasFnAttr(Attribute::ReturnsTwice);
1385   }
1386   void setCanReturnTwice() {
1387     addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1388   }
1389
1390   /// \brief Determine if the call does not access memory.
1391   bool doesNotAccessMemory() const {
1392     return hasFnAttr(Attribute::ReadNone);
1393   }
1394   void setDoesNotAccessMemory() {
1395     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1396   }
1397
1398   /// \brief Determine if the call does not access or only reads memory.
1399   bool onlyReadsMemory() const {
1400     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1401   }
1402   void setOnlyReadsMemory() {
1403     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1404   }
1405
1406   /// \brief Determine if the call cannot return.
1407   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1408   void setDoesNotReturn() {
1409     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1410   }
1411
1412   /// \brief Determine if the call cannot unwind.
1413   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1414   void setDoesNotThrow() {
1415     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1416   }
1417
1418   /// \brief Determine if the call cannot be duplicated.
1419   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1420   void setCannotDuplicate() {
1421     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1422   }
1423
1424   /// \brief Determine if the call returns a structure through first
1425   /// pointer argument.
1426   bool hasStructRetAttr() const {
1427     // Be friendly and also check the callee.
1428     return paramHasAttr(1, Attribute::StructRet);
1429   }
1430
1431   /// \brief Determine if any call argument is an aggregate passed by value.
1432   bool hasByValArgument() const {
1433     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1434   }
1435
1436   /// getCalledFunction - Return the function called, or null if this is an
1437   /// indirect function invocation.
1438   ///
1439   Function *getCalledFunction() const {
1440     return dyn_cast<Function>(Op<-1>());
1441   }
1442
1443   /// getCalledValue - Get a pointer to the function that is invoked by this
1444   /// instruction.
1445   const Value *getCalledValue() const { return Op<-1>(); }
1446         Value *getCalledValue()       { return Op<-1>(); }
1447
1448   /// setCalledFunction - Set the function called.
1449   void setCalledFunction(Value* Fn) {
1450     Op<-1>() = Fn;
1451   }
1452
1453   /// isInlineAsm - Check if this call is an inline asm statement.
1454   bool isInlineAsm() const {
1455     return isa<InlineAsm>(Op<-1>());
1456   }
1457
1458   // Methods for support type inquiry through isa, cast, and dyn_cast:
1459   static inline bool classof(const Instruction *I) {
1460     return I->getOpcode() == Instruction::Call;
1461   }
1462   static inline bool classof(const Value *V) {
1463     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1464   }
1465 private:
1466
1467   bool hasFnAttrImpl(Attribute::AttrKind A) const;
1468
1469   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1470   // method so that subclasses cannot accidentally use it.
1471   void setInstructionSubclassData(unsigned short D) {
1472     Instruction::setInstructionSubclassData(D);
1473   }
1474 };
1475
1476 template <>
1477 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1478 };
1479
1480 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1481                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1482   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1483                                    ->getElementType())->getReturnType(),
1484                 Instruction::Call,
1485                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1486                 unsigned(Args.size() + 1), InsertAtEnd) {
1487   init(Func, Args, NameStr);
1488 }
1489
1490 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1491                    const Twine &NameStr, Instruction *InsertBefore)
1492   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1493                                    ->getElementType())->getReturnType(),
1494                 Instruction::Call,
1495                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1496                 unsigned(Args.size() + 1), InsertBefore) {
1497   init(Func, Args, NameStr);
1498 }
1499
1500
1501 // Note: if you get compile errors about private methods then
1502 //       please update your code to use the high-level operand
1503 //       interfaces. See line 943 above.
1504 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1505
1506 //===----------------------------------------------------------------------===//
1507 //                               SelectInst Class
1508 //===----------------------------------------------------------------------===//
1509
1510 /// SelectInst - This class represents the LLVM 'select' instruction.
1511 ///
1512 class SelectInst : public Instruction {
1513   void init(Value *C, Value *S1, Value *S2) {
1514     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1515     Op<0>() = C;
1516     Op<1>() = S1;
1517     Op<2>() = S2;
1518   }
1519
1520   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1521              Instruction *InsertBefore)
1522     : Instruction(S1->getType(), Instruction::Select,
1523                   &Op<0>(), 3, InsertBefore) {
1524     init(C, S1, S2);
1525     setName(NameStr);
1526   }
1527   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1528              BasicBlock *InsertAtEnd)
1529     : Instruction(S1->getType(), Instruction::Select,
1530                   &Op<0>(), 3, InsertAtEnd) {
1531     init(C, S1, S2);
1532     setName(NameStr);
1533   }
1534 protected:
1535   SelectInst *clone_impl() const override;
1536 public:
1537   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1538                             const Twine &NameStr = "",
1539                             Instruction *InsertBefore = nullptr) {
1540     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1541   }
1542   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1543                             const Twine &NameStr,
1544                             BasicBlock *InsertAtEnd) {
1545     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1546   }
1547
1548   const Value *getCondition() const { return Op<0>(); }
1549   const Value *getTrueValue() const { return Op<1>(); }
1550   const Value *getFalseValue() const { return Op<2>(); }
1551   Value *getCondition() { return Op<0>(); }
1552   Value *getTrueValue() { return Op<1>(); }
1553   Value *getFalseValue() { return Op<2>(); }
1554
1555   /// areInvalidOperands - Return a string if the specified operands are invalid
1556   /// for a select operation, otherwise return null.
1557   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1558
1559   /// Transparently provide more efficient getOperand methods.
1560   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1561
1562   OtherOps getOpcode() const {
1563     return static_cast<OtherOps>(Instruction::getOpcode());
1564   }
1565
1566   // Methods for support type inquiry through isa, cast, and dyn_cast:
1567   static inline bool classof(const Instruction *I) {
1568     return I->getOpcode() == Instruction::Select;
1569   }
1570   static inline bool classof(const Value *V) {
1571     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1572   }
1573 };
1574
1575 template <>
1576 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1577 };
1578
1579 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1580
1581 //===----------------------------------------------------------------------===//
1582 //                                VAArgInst Class
1583 //===----------------------------------------------------------------------===//
1584
1585 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1586 /// an argument of the specified type given a va_list and increments that list
1587 ///
1588 class VAArgInst : public UnaryInstruction {
1589 protected:
1590   VAArgInst *clone_impl() const override;
1591
1592 public:
1593   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1594              Instruction *InsertBefore = nullptr)
1595     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1596     setName(NameStr);
1597   }
1598   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1599             BasicBlock *InsertAtEnd)
1600     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1601     setName(NameStr);
1602   }
1603
1604   Value *getPointerOperand() { return getOperand(0); }
1605   const Value *getPointerOperand() const { return getOperand(0); }
1606   static unsigned getPointerOperandIndex() { return 0U; }
1607
1608   // Methods for support type inquiry through isa, cast, and dyn_cast:
1609   static inline bool classof(const Instruction *I) {
1610     return I->getOpcode() == VAArg;
1611   }
1612   static inline bool classof(const Value *V) {
1613     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1614   }
1615 };
1616
1617 //===----------------------------------------------------------------------===//
1618 //                                ExtractElementInst Class
1619 //===----------------------------------------------------------------------===//
1620
1621 /// ExtractElementInst - This instruction extracts a single (scalar)
1622 /// element from a VectorType value
1623 ///
1624 class ExtractElementInst : public Instruction {
1625   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1626                      Instruction *InsertBefore = nullptr);
1627   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1628                      BasicBlock *InsertAtEnd);
1629 protected:
1630   ExtractElementInst *clone_impl() const override;
1631
1632 public:
1633   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1634                                    const Twine &NameStr = "",
1635                                    Instruction *InsertBefore = nullptr) {
1636     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1637   }
1638   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1639                                    const Twine &NameStr,
1640                                    BasicBlock *InsertAtEnd) {
1641     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1642   }
1643
1644   /// isValidOperands - Return true if an extractelement instruction can be
1645   /// formed with the specified operands.
1646   static bool isValidOperands(const Value *Vec, const Value *Idx);
1647
1648   Value *getVectorOperand() { return Op<0>(); }
1649   Value *getIndexOperand() { return Op<1>(); }
1650   const Value *getVectorOperand() const { return Op<0>(); }
1651   const Value *getIndexOperand() const { return Op<1>(); }
1652
1653   VectorType *getVectorOperandType() const {
1654     return cast<VectorType>(getVectorOperand()->getType());
1655   }
1656
1657
1658   /// Transparently provide more efficient getOperand methods.
1659   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1660
1661   // Methods for support type inquiry through isa, cast, and dyn_cast:
1662   static inline bool classof(const Instruction *I) {
1663     return I->getOpcode() == Instruction::ExtractElement;
1664   }
1665   static inline bool classof(const Value *V) {
1666     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1667   }
1668 };
1669
1670 template <>
1671 struct OperandTraits<ExtractElementInst> :
1672   public FixedNumOperandTraits<ExtractElementInst, 2> {
1673 };
1674
1675 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1676
1677 //===----------------------------------------------------------------------===//
1678 //                                InsertElementInst Class
1679 //===----------------------------------------------------------------------===//
1680
1681 /// InsertElementInst - This instruction inserts a single (scalar)
1682 /// element into a VectorType value
1683 ///
1684 class InsertElementInst : public Instruction {
1685   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1686                     const Twine &NameStr = "",
1687                     Instruction *InsertBefore = nullptr);
1688   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1689                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1690 protected:
1691   InsertElementInst *clone_impl() const override;
1692
1693 public:
1694   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1695                                    const Twine &NameStr = "",
1696                                    Instruction *InsertBefore = nullptr) {
1697     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1698   }
1699   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1700                                    const Twine &NameStr,
1701                                    BasicBlock *InsertAtEnd) {
1702     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1703   }
1704
1705   /// isValidOperands - Return true if an insertelement instruction can be
1706   /// formed with the specified operands.
1707   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1708                               const Value *Idx);
1709
1710   /// getType - Overload to return most specific vector type.
1711   ///
1712   VectorType *getType() const {
1713     return cast<VectorType>(Instruction::getType());
1714   }
1715
1716   /// Transparently provide more efficient getOperand methods.
1717   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1718
1719   // Methods for support type inquiry through isa, cast, and dyn_cast:
1720   static inline bool classof(const Instruction *I) {
1721     return I->getOpcode() == Instruction::InsertElement;
1722   }
1723   static inline bool classof(const Value *V) {
1724     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1725   }
1726 };
1727
1728 template <>
1729 struct OperandTraits<InsertElementInst> :
1730   public FixedNumOperandTraits<InsertElementInst, 3> {
1731 };
1732
1733 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1734
1735 //===----------------------------------------------------------------------===//
1736 //                           ShuffleVectorInst Class
1737 //===----------------------------------------------------------------------===//
1738
1739 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1740 /// input vectors.
1741 ///
1742 class ShuffleVectorInst : public Instruction {
1743 protected:
1744   ShuffleVectorInst *clone_impl() const override;
1745
1746 public:
1747   // allocate space for exactly three operands
1748   void *operator new(size_t s) {
1749     return User::operator new(s, 3);
1750   }
1751   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1752                     const Twine &NameStr = "",
1753                     Instruction *InsertBefor = nullptr);
1754   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1755                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1756
1757   /// isValidOperands - Return true if a shufflevector instruction can be
1758   /// formed with the specified operands.
1759   static bool isValidOperands(const Value *V1, const Value *V2,
1760                               const Value *Mask);
1761
1762   /// getType - Overload to return most specific vector type.
1763   ///
1764   VectorType *getType() const {
1765     return cast<VectorType>(Instruction::getType());
1766   }
1767
1768   /// Transparently provide more efficient getOperand methods.
1769   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1770
1771   Constant *getMask() const {
1772     return cast<Constant>(getOperand(2));
1773   }
1774
1775   /// getMaskValue - Return the index from the shuffle mask for the specified
1776   /// output result.  This is either -1 if the element is undef or a number less
1777   /// than 2*numelements.
1778   static int getMaskValue(Constant *Mask, unsigned i);
1779
1780   int getMaskValue(unsigned i) const {
1781     return getMaskValue(getMask(), i);
1782   }
1783
1784   /// getShuffleMask - Return the full mask for this instruction, where each
1785   /// element is the element number and undef's are returned as -1.
1786   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1787
1788   void getShuffleMask(SmallVectorImpl<int> &Result) const {
1789     return getShuffleMask(getMask(), Result);
1790   }
1791
1792   SmallVector<int, 16> getShuffleMask() const {
1793     SmallVector<int, 16> Mask;
1794     getShuffleMask(Mask);
1795     return Mask;
1796   }
1797
1798
1799   // Methods for support type inquiry through isa, cast, and dyn_cast:
1800   static inline bool classof(const Instruction *I) {
1801     return I->getOpcode() == Instruction::ShuffleVector;
1802   }
1803   static inline bool classof(const Value *V) {
1804     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1805   }
1806 };
1807
1808 template <>
1809 struct OperandTraits<ShuffleVectorInst> :
1810   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1811 };
1812
1813 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1814
1815 //===----------------------------------------------------------------------===//
1816 //                                ExtractValueInst Class
1817 //===----------------------------------------------------------------------===//
1818
1819 /// ExtractValueInst - This instruction extracts a struct member or array
1820 /// element value from an aggregate value.
1821 ///
1822 class ExtractValueInst : public UnaryInstruction {
1823   SmallVector<unsigned, 4> Indices;
1824
1825   ExtractValueInst(const ExtractValueInst &EVI);
1826   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1827
1828   /// Constructors - Create a extractvalue instruction with a base aggregate
1829   /// value and a list of indices.  The first ctor can optionally insert before
1830   /// an existing instruction, the second appends the new instruction to the
1831   /// specified BasicBlock.
1832   inline ExtractValueInst(Value *Agg,
1833                           ArrayRef<unsigned> Idxs,
1834                           const Twine &NameStr,
1835                           Instruction *InsertBefore);
1836   inline ExtractValueInst(Value *Agg,
1837                           ArrayRef<unsigned> Idxs,
1838                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1839
1840   // allocate space for exactly one operand
1841   void *operator new(size_t s) {
1842     return User::operator new(s, 1);
1843   }
1844 protected:
1845   ExtractValueInst *clone_impl() const override;
1846
1847 public:
1848   static ExtractValueInst *Create(Value *Agg,
1849                                   ArrayRef<unsigned> Idxs,
1850                                   const Twine &NameStr = "",
1851                                   Instruction *InsertBefore = nullptr) {
1852     return new
1853       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1854   }
1855   static ExtractValueInst *Create(Value *Agg,
1856                                   ArrayRef<unsigned> Idxs,
1857                                   const Twine &NameStr,
1858                                   BasicBlock *InsertAtEnd) {
1859     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1860   }
1861
1862   /// getIndexedType - Returns the type of the element that would be extracted
1863   /// with an extractvalue instruction with the specified parameters.
1864   ///
1865   /// Null is returned if the indices are invalid for the specified type.
1866   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1867
1868   typedef const unsigned* idx_iterator;
1869   inline idx_iterator idx_begin() const { return Indices.begin(); }
1870   inline idx_iterator idx_end()   const { return Indices.end(); }
1871
1872   Value *getAggregateOperand() {
1873     return getOperand(0);
1874   }
1875   const Value *getAggregateOperand() const {
1876     return getOperand(0);
1877   }
1878   static unsigned getAggregateOperandIndex() {
1879     return 0U;                      // get index for modifying correct operand
1880   }
1881
1882   ArrayRef<unsigned> getIndices() const {
1883     return Indices;
1884   }
1885
1886   unsigned getNumIndices() const {
1887     return (unsigned)Indices.size();
1888   }
1889
1890   bool hasIndices() const {
1891     return true;
1892   }
1893
1894   // Methods for support type inquiry through isa, cast, and dyn_cast:
1895   static inline bool classof(const Instruction *I) {
1896     return I->getOpcode() == Instruction::ExtractValue;
1897   }
1898   static inline bool classof(const Value *V) {
1899     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1900   }
1901 };
1902
1903 ExtractValueInst::ExtractValueInst(Value *Agg,
1904                                    ArrayRef<unsigned> Idxs,
1905                                    const Twine &NameStr,
1906                                    Instruction *InsertBefore)
1907   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1908                      ExtractValue, Agg, InsertBefore) {
1909   init(Idxs, NameStr);
1910 }
1911 ExtractValueInst::ExtractValueInst(Value *Agg,
1912                                    ArrayRef<unsigned> Idxs,
1913                                    const Twine &NameStr,
1914                                    BasicBlock *InsertAtEnd)
1915   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1916                      ExtractValue, Agg, InsertAtEnd) {
1917   init(Idxs, NameStr);
1918 }
1919
1920
1921 //===----------------------------------------------------------------------===//
1922 //                                InsertValueInst Class
1923 //===----------------------------------------------------------------------===//
1924
1925 /// InsertValueInst - This instruction inserts a struct field of array element
1926 /// value into an aggregate value.
1927 ///
1928 class InsertValueInst : public Instruction {
1929   SmallVector<unsigned, 4> Indices;
1930
1931   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1932   InsertValueInst(const InsertValueInst &IVI);
1933   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1934             const Twine &NameStr);
1935
1936   /// Constructors - Create a insertvalue instruction with a base aggregate
1937   /// value, a value to insert, and a list of indices.  The first ctor can
1938   /// optionally insert before an existing instruction, the second appends
1939   /// the new instruction to the specified BasicBlock.
1940   inline InsertValueInst(Value *Agg, Value *Val,
1941                          ArrayRef<unsigned> Idxs,
1942                          const Twine &NameStr,
1943                          Instruction *InsertBefore);
1944   inline InsertValueInst(Value *Agg, Value *Val,
1945                          ArrayRef<unsigned> Idxs,
1946                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1947
1948   /// Constructors - These two constructors are convenience methods because one
1949   /// and two index insertvalue instructions are so common.
1950   InsertValueInst(Value *Agg, Value *Val,
1951                   unsigned Idx, const Twine &NameStr = "",
1952                   Instruction *InsertBefore = nullptr);
1953   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1954                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1955 protected:
1956   InsertValueInst *clone_impl() const override;
1957 public:
1958   // allocate space for exactly two operands
1959   void *operator new(size_t s) {
1960     return User::operator new(s, 2);
1961   }
1962
1963   static InsertValueInst *Create(Value *Agg, Value *Val,
1964                                  ArrayRef<unsigned> Idxs,
1965                                  const Twine &NameStr = "",
1966                                  Instruction *InsertBefore = nullptr) {
1967     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1968   }
1969   static InsertValueInst *Create(Value *Agg, Value *Val,
1970                                  ArrayRef<unsigned> Idxs,
1971                                  const Twine &NameStr,
1972                                  BasicBlock *InsertAtEnd) {
1973     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1974   }
1975
1976   /// Transparently provide more efficient getOperand methods.
1977   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1978
1979   typedef const unsigned* idx_iterator;
1980   inline idx_iterator idx_begin() const { return Indices.begin(); }
1981   inline idx_iterator idx_end()   const { return Indices.end(); }
1982
1983   Value *getAggregateOperand() {
1984     return getOperand(0);
1985   }
1986   const Value *getAggregateOperand() const {
1987     return getOperand(0);
1988   }
1989   static unsigned getAggregateOperandIndex() {
1990     return 0U;                      // get index for modifying correct operand
1991   }
1992
1993   Value *getInsertedValueOperand() {
1994     return getOperand(1);
1995   }
1996   const Value *getInsertedValueOperand() const {
1997     return getOperand(1);
1998   }
1999   static unsigned getInsertedValueOperandIndex() {
2000     return 1U;                      // get index for modifying correct operand
2001   }
2002
2003   ArrayRef<unsigned> getIndices() const {
2004     return Indices;
2005   }
2006
2007   unsigned getNumIndices() const {
2008     return (unsigned)Indices.size();
2009   }
2010
2011   bool hasIndices() const {
2012     return true;
2013   }
2014
2015   // Methods for support type inquiry through isa, cast, and dyn_cast:
2016   static inline bool classof(const Instruction *I) {
2017     return I->getOpcode() == Instruction::InsertValue;
2018   }
2019   static inline bool classof(const Value *V) {
2020     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2021   }
2022 };
2023
2024 template <>
2025 struct OperandTraits<InsertValueInst> :
2026   public FixedNumOperandTraits<InsertValueInst, 2> {
2027 };
2028
2029 InsertValueInst::InsertValueInst(Value *Agg,
2030                                  Value *Val,
2031                                  ArrayRef<unsigned> Idxs,
2032                                  const Twine &NameStr,
2033                                  Instruction *InsertBefore)
2034   : Instruction(Agg->getType(), InsertValue,
2035                 OperandTraits<InsertValueInst>::op_begin(this),
2036                 2, InsertBefore) {
2037   init(Agg, Val, Idxs, NameStr);
2038 }
2039 InsertValueInst::InsertValueInst(Value *Agg,
2040                                  Value *Val,
2041                                  ArrayRef<unsigned> Idxs,
2042                                  const Twine &NameStr,
2043                                  BasicBlock *InsertAtEnd)
2044   : Instruction(Agg->getType(), InsertValue,
2045                 OperandTraits<InsertValueInst>::op_begin(this),
2046                 2, InsertAtEnd) {
2047   init(Agg, Val, Idxs, NameStr);
2048 }
2049
2050 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2051
2052 //===----------------------------------------------------------------------===//
2053 //                               PHINode Class
2054 //===----------------------------------------------------------------------===//
2055
2056 // PHINode - The PHINode class is used to represent the magical mystical PHI
2057 // node, that can not exist in nature, but can be synthesized in a computer
2058 // scientist's overactive imagination.
2059 //
2060 class PHINode : public Instruction {
2061   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2062   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
2063   /// the number actually in use.
2064   unsigned ReservedSpace;
2065   PHINode(const PHINode &PN);
2066   // allocate space for exactly zero operands
2067   void *operator new(size_t s) {
2068     return User::operator new(s, 0);
2069   }
2070   explicit PHINode(Type *Ty, unsigned NumReservedValues,
2071                    const Twine &NameStr = "",
2072                    Instruction *InsertBefore = nullptr)
2073     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2074       ReservedSpace(NumReservedValues) {
2075     setName(NameStr);
2076     OperandList = allocHungoffUses(ReservedSpace);
2077   }
2078
2079   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2080           BasicBlock *InsertAtEnd)
2081     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2082       ReservedSpace(NumReservedValues) {
2083     setName(NameStr);
2084     OperandList = allocHungoffUses(ReservedSpace);
2085   }
2086 protected:
2087   // allocHungoffUses - this is more complicated than the generic
2088   // User::allocHungoffUses, because we have to allocate Uses for the incoming
2089   // values and pointers to the incoming blocks, all in one allocation.
2090   Use *allocHungoffUses(unsigned) const;
2091
2092   PHINode *clone_impl() const override;
2093 public:
2094   /// Constructors - NumReservedValues is a hint for the number of incoming
2095   /// edges that this phi node will have (use 0 if you really have no idea).
2096   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2097                          const Twine &NameStr = "",
2098                          Instruction *InsertBefore = nullptr) {
2099     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2100   }
2101   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2102                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
2103     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2104   }
2105   ~PHINode();
2106
2107   /// Provide fast operand accessors
2108   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2109
2110   // Block iterator interface. This provides access to the list of incoming
2111   // basic blocks, which parallels the list of incoming values.
2112
2113   typedef BasicBlock **block_iterator;
2114   typedef BasicBlock * const *const_block_iterator;
2115
2116   block_iterator block_begin() {
2117     Use::UserRef *ref =
2118       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2119     return reinterpret_cast<block_iterator>(ref + 1);
2120   }
2121
2122   const_block_iterator block_begin() const {
2123     const Use::UserRef *ref =
2124       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2125     return reinterpret_cast<const_block_iterator>(ref + 1);
2126   }
2127
2128   block_iterator block_end() {
2129     return block_begin() + getNumOperands();
2130   }
2131
2132   const_block_iterator block_end() const {
2133     return block_begin() + getNumOperands();
2134   }
2135
2136   /// getNumIncomingValues - Return the number of incoming edges
2137   ///
2138   unsigned getNumIncomingValues() const { return getNumOperands(); }
2139
2140   /// getIncomingValue - Return incoming value number x
2141   ///
2142   Value *getIncomingValue(unsigned i) const {
2143     return getOperand(i);
2144   }
2145   void setIncomingValue(unsigned i, Value *V) {
2146     setOperand(i, V);
2147   }
2148   static unsigned getOperandNumForIncomingValue(unsigned i) {
2149     return i;
2150   }
2151   static unsigned getIncomingValueNumForOperand(unsigned i) {
2152     return i;
2153   }
2154
2155   /// getIncomingBlock - Return incoming basic block number @p i.
2156   ///
2157   BasicBlock *getIncomingBlock(unsigned i) const {
2158     return block_begin()[i];
2159   }
2160
2161   /// getIncomingBlock - Return incoming basic block corresponding
2162   /// to an operand of the PHI.
2163   ///
2164   BasicBlock *getIncomingBlock(const Use &U) const {
2165     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2166     return getIncomingBlock(unsigned(&U - op_begin()));
2167   }
2168
2169   /// getIncomingBlock - Return incoming basic block corresponding
2170   /// to value use iterator.
2171   ///
2172   BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2173     return getIncomingBlock(I.getUse());
2174   }
2175
2176   void setIncomingBlock(unsigned i, BasicBlock *BB) {
2177     block_begin()[i] = BB;
2178   }
2179
2180   /// addIncoming - Add an incoming value to the end of the PHI list
2181   ///
2182   void addIncoming(Value *V, BasicBlock *BB) {
2183     assert(V && "PHI node got a null value!");
2184     assert(BB && "PHI node got a null basic block!");
2185     assert(getType() == V->getType() &&
2186            "All operands to PHI node must be the same type as the PHI node!");
2187     if (NumOperands == ReservedSpace)
2188       growOperands();  // Get more space!
2189     // Initialize some new operands.
2190     ++NumOperands;
2191     setIncomingValue(NumOperands - 1, V);
2192     setIncomingBlock(NumOperands - 1, BB);
2193   }
2194
2195   /// removeIncomingValue - Remove an incoming value.  This is useful if a
2196   /// predecessor basic block is deleted.  The value removed is returned.
2197   ///
2198   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2199   /// is true), the PHI node is destroyed and any uses of it are replaced with
2200   /// dummy values.  The only time there should be zero incoming values to a PHI
2201   /// node is when the block is dead, so this strategy is sound.
2202   ///
2203   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2204
2205   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2206     int Idx = getBasicBlockIndex(BB);
2207     assert(Idx >= 0 && "Invalid basic block argument to remove!");
2208     return removeIncomingValue(Idx, DeletePHIIfEmpty);
2209   }
2210
2211   /// getBasicBlockIndex - Return the first index of the specified basic
2212   /// block in the value list for this PHI.  Returns -1 if no instance.
2213   ///
2214   int getBasicBlockIndex(const BasicBlock *BB) const {
2215     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2216       if (block_begin()[i] == BB)
2217         return i;
2218     return -1;
2219   }
2220
2221   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2222     int Idx = getBasicBlockIndex(BB);
2223     assert(Idx >= 0 && "Invalid basic block argument!");
2224     return getIncomingValue(Idx);
2225   }
2226
2227   /// hasConstantValue - If the specified PHI node always merges together the
2228   /// same value, return the value, otherwise return null.
2229   Value *hasConstantValue() const;
2230
2231   /// Methods for support type inquiry through isa, cast, and dyn_cast:
2232   static inline bool classof(const Instruction *I) {
2233     return I->getOpcode() == Instruction::PHI;
2234   }
2235   static inline bool classof(const Value *V) {
2236     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2237   }
2238  private:
2239   void growOperands();
2240 };
2241
2242 template <>
2243 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2244 };
2245
2246 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2247
2248 //===----------------------------------------------------------------------===//
2249 //                           LandingPadInst Class
2250 //===----------------------------------------------------------------------===//
2251
2252 //===---------------------------------------------------------------------------
2253 /// LandingPadInst - The landingpad instruction holds all of the information
2254 /// necessary to generate correct exception handling. The landingpad instruction
2255 /// cannot be moved from the top of a landing pad block, which itself is
2256 /// accessible only from the 'unwind' edge of an invoke. This uses the
2257 /// SubclassData field in Value to store whether or not the landingpad is a
2258 /// cleanup.
2259 ///
2260 class LandingPadInst : public Instruction {
2261   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
2262   /// the number actually in use.
2263   unsigned ReservedSpace;
2264   LandingPadInst(const LandingPadInst &LP);
2265 public:
2266   enum ClauseType { Catch, Filter };
2267 private:
2268   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2269   // Allocate space for exactly zero operands.
2270   void *operator new(size_t s) {
2271     return User::operator new(s, 0);
2272   }
2273   void growOperands(unsigned Size);
2274   void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2275
2276   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2277                           unsigned NumReservedValues, const Twine &NameStr,
2278                           Instruction *InsertBefore);
2279   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2280                           unsigned NumReservedValues, const Twine &NameStr,
2281                           BasicBlock *InsertAtEnd);
2282 protected:
2283   LandingPadInst *clone_impl() const override;
2284 public:
2285   /// Constructors - NumReservedClauses is a hint for the number of incoming
2286   /// clauses that this landingpad will have (use 0 if you really have no idea).
2287   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2288                                 unsigned NumReservedClauses,
2289                                 const Twine &NameStr = "",
2290                                 Instruction *InsertBefore = nullptr);
2291   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2292                                 unsigned NumReservedClauses,
2293                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
2294   ~LandingPadInst();
2295
2296   /// Provide fast operand accessors
2297   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2298
2299   /// getPersonalityFn - Get the personality function associated with this
2300   /// landing pad.
2301   Value *getPersonalityFn() const { return getOperand(0); }
2302
2303   /// isCleanup - Return 'true' if this landingpad instruction is a
2304   /// cleanup. I.e., it should be run when unwinding even if its landing pad
2305   /// doesn't catch the exception.
2306   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2307
2308   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2309   void setCleanup(bool V) {
2310     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2311                                (V ? 1 : 0));
2312   }
2313
2314   /// Add a catch or filter clause to the landing pad.
2315   void addClause(Constant *ClauseVal);
2316
2317   /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2318   /// determine what type of clause this is.
2319   Constant *getClause(unsigned Idx) const {
2320     return cast<Constant>(OperandList[Idx + 1]);
2321   }
2322
2323   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2324   bool isCatch(unsigned Idx) const {
2325     return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2326   }
2327
2328   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2329   bool isFilter(unsigned Idx) const {
2330     return isa<ArrayType>(OperandList[Idx + 1]->getType());
2331   }
2332
2333   /// getNumClauses - Get the number of clauses for this landing pad.
2334   unsigned getNumClauses() const { return getNumOperands() - 1; }
2335
2336   /// reserveClauses - Grow the size of the operand list to accommodate the new
2337   /// number of clauses.
2338   void reserveClauses(unsigned Size) { growOperands(Size); }
2339
2340   // Methods for support type inquiry through isa, cast, and dyn_cast:
2341   static inline bool classof(const Instruction *I) {
2342     return I->getOpcode() == Instruction::LandingPad;
2343   }
2344   static inline bool classof(const Value *V) {
2345     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2346   }
2347 };
2348
2349 template <>
2350 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2351 };
2352
2353 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2354
2355 //===----------------------------------------------------------------------===//
2356 //                               ReturnInst Class
2357 //===----------------------------------------------------------------------===//
2358
2359 //===---------------------------------------------------------------------------
2360 /// ReturnInst - Return a value (possibly void), from a function.  Execution
2361 /// does not continue in this function any longer.
2362 ///
2363 class ReturnInst : public TerminatorInst {
2364   ReturnInst(const ReturnInst &RI);
2365
2366 private:
2367   // ReturnInst constructors:
2368   // ReturnInst()                  - 'ret void' instruction
2369   // ReturnInst(    null)          - 'ret void' instruction
2370   // ReturnInst(Value* X)          - 'ret X'    instruction
2371   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
2372   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
2373   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
2374   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
2375   //
2376   // NOTE: If the Value* passed is of type void then the constructor behaves as
2377   // if it was passed NULL.
2378   explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2379                       Instruction *InsertBefore = nullptr);
2380   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2381   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2382 protected:
2383   ReturnInst *clone_impl() const override;
2384 public:
2385   static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2386                             Instruction *InsertBefore = nullptr) {
2387     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2388   }
2389   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2390                             BasicBlock *InsertAtEnd) {
2391     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2392   }
2393   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2394     return new(0) ReturnInst(C, InsertAtEnd);
2395   }
2396   virtual ~ReturnInst();
2397
2398   /// Provide fast operand accessors
2399   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2400
2401   /// Convenience accessor. Returns null if there is no return value.
2402   Value *getReturnValue() const {
2403     return getNumOperands() != 0 ? getOperand(0) : nullptr;
2404   }
2405
2406   unsigned getNumSuccessors() const { return 0; }
2407
2408   // Methods for support type inquiry through isa, cast, and dyn_cast:
2409   static inline bool classof(const Instruction *I) {
2410     return (I->getOpcode() == Instruction::Ret);
2411   }
2412   static inline bool classof(const Value *V) {
2413     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2414   }
2415  private:
2416   BasicBlock *getSuccessorV(unsigned idx) const override;
2417   unsigned getNumSuccessorsV() const override;
2418   void setSuccessorV(unsigned idx, BasicBlock *B) override;
2419 };
2420
2421 template <>
2422 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2423 };
2424
2425 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2426
2427 //===----------------------------------------------------------------------===//
2428 //                               BranchInst Class
2429 //===----------------------------------------------------------------------===//
2430
2431 //===---------------------------------------------------------------------------
2432 /// BranchInst - Conditional or Unconditional Branch instruction.
2433 ///
2434 class BranchInst : public TerminatorInst {
2435   /// Ops list - Branches are strange.  The operands are ordered:
2436   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2437   /// they don't have to check for cond/uncond branchness. These are mostly
2438   /// accessed relative from op_end().
2439   BranchInst(const BranchInst &BI);
2440   void AssertOK();
2441   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2442   // BranchInst(BB *B)                           - 'br B'
2443   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2444   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2445   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2446   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2447   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2448   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2449   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2450              Instruction *InsertBefore = nullptr);
2451   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2452   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2453              BasicBlock *InsertAtEnd);
2454 protected:
2455   BranchInst *clone_impl() const override;
2456 public:
2457   static BranchInst *Create(BasicBlock *IfTrue,
2458                             Instruction *InsertBefore = nullptr) {
2459     return new(1) BranchInst(IfTrue, InsertBefore);
2460   }
2461   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2462                             Value *Cond, Instruction *InsertBefore = nullptr) {
2463     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2464   }
2465   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2466     return new(1) BranchInst(IfTrue, InsertAtEnd);
2467   }
2468   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2469                             Value *Cond, BasicBlock *InsertAtEnd) {
2470     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2471   }
2472
2473   /// Transparently provide more efficient getOperand methods.
2474   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2475
2476   bool isUnconditional() const { return getNumOperands() == 1; }
2477   bool isConditional()   const { return getNumOperands() == 3; }
2478
2479   Value *getCondition() const {
2480     assert(isConditional() && "Cannot get condition of an uncond branch!");
2481     return Op<-3>();
2482   }
2483
2484   void setCondition(Value *V) {
2485     assert(isConditional() && "Cannot set condition of unconditional branch!");
2486     Op<-3>() = V;
2487   }
2488
2489   unsigned getNumSuccessors() const { return 1+isConditional(); }
2490
2491   BasicBlock *getSuccessor(unsigned i) const {
2492     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2493     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2494   }
2495
2496   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2497     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2498     *(&Op<-1>() - idx) = (Value*)NewSucc;
2499   }
2500
2501   /// \brief Swap the successors of this branch instruction.
2502   ///
2503   /// Swaps the successors of the branch instruction. This also swaps any
2504   /// branch weight metadata associated with the instruction so that it
2505   /// continues to map correctly to each operand.
2506   void swapSuccessors();
2507
2508   // Methods for support type inquiry through isa, cast, and dyn_cast:
2509   static inline bool classof(const Instruction *I) {
2510     return (I->getOpcode() == Instruction::Br);
2511   }
2512   static inline bool classof(const Value *V) {
2513     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2514   }
2515 private:
2516   BasicBlock *getSuccessorV(unsigned idx) const override;
2517   unsigned getNumSuccessorsV() const override;
2518   void setSuccessorV(unsigned idx, BasicBlock *B) override;
2519 };
2520
2521 template <>
2522 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2523 };
2524
2525 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2526
2527 //===----------------------------------------------------------------------===//
2528 //                               SwitchInst Class
2529 //===----------------------------------------------------------------------===//
2530
2531 //===---------------------------------------------------------------------------
2532 /// SwitchInst - Multiway switch
2533 ///
2534 class SwitchInst : public TerminatorInst {
2535   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2536   unsigned ReservedSpace;
2537   // Operand[0]    = Value to switch on
2538   // Operand[1]    = Default basic block destination
2539   // Operand[2n  ] = Value to match
2540   // Operand[2n+1] = BasicBlock to go to on match
2541   SwitchInst(const SwitchInst &SI);
2542   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2543   void growOperands();
2544   // allocate space for exactly zero operands
2545   void *operator new(size_t s) {
2546     return User::operator new(s, 0);
2547   }
2548   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2549   /// switch on and a default destination.  The number of additional cases can
2550   /// be specified here to make memory allocation more efficient.  This
2551   /// constructor can also autoinsert before another instruction.
2552   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2553              Instruction *InsertBefore);
2554
2555   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2556   /// switch on and a default destination.  The number of additional cases can
2557   /// be specified here to make memory allocation more efficient.  This
2558   /// constructor also autoinserts at the end of the specified BasicBlock.
2559   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2560              BasicBlock *InsertAtEnd);
2561 protected:
2562   SwitchInst *clone_impl() const override;
2563 public:
2564
2565   // -2
2566   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2567
2568   template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2569   class CaseIteratorT {
2570   protected:
2571
2572     SwitchInstTy *SI;
2573     unsigned Index;
2574
2575   public:
2576
2577     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2578
2579     /// Initializes case iterator for given SwitchInst and for given
2580     /// case number.
2581     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2582       this->SI = SI;
2583       Index = CaseNum;
2584     }
2585
2586     /// Initializes case iterator for given SwitchInst and for given
2587     /// TerminatorInst's successor index.
2588     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2589       assert(SuccessorIndex < SI->getNumSuccessors() &&
2590              "Successor index # out of range!");
2591       return SuccessorIndex != 0 ?
2592              Self(SI, SuccessorIndex - 1) :
2593              Self(SI, DefaultPseudoIndex);
2594     }
2595
2596     /// Resolves case value for current case.
2597     ConstantIntTy *getCaseValue() {
2598       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2599       return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2600     }
2601
2602     /// Resolves successor for current case.
2603     BasicBlockTy *getCaseSuccessor() {
2604       assert((Index < SI->getNumCases() ||
2605               Index == DefaultPseudoIndex) &&
2606              "Index out the number of cases.");
2607       return SI->getSuccessor(getSuccessorIndex());
2608     }
2609
2610     /// Returns number of current case.
2611     unsigned getCaseIndex() const { return Index; }
2612
2613     /// Returns TerminatorInst's successor index for current case successor.
2614     unsigned getSuccessorIndex() const {
2615       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2616              "Index out the number of cases.");
2617       return Index != DefaultPseudoIndex ? Index + 1 : 0;
2618     }
2619
2620     Self operator++() {
2621       // Check index correctness after increment.
2622       // Note: Index == getNumCases() means end().
2623       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2624       ++Index;
2625       return *this;
2626     }
2627     Self operator++(int) {
2628       Self tmp = *this;
2629       ++(*this);
2630       return tmp;
2631     }
2632     Self operator--() {
2633       // Check index correctness after decrement.
2634       // Note: Index == getNumCases() means end().
2635       // Also allow "-1" iterator here. That will became valid after ++.
2636       assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2637              "Index out the number of cases.");
2638       --Index;
2639       return *this;
2640     }
2641     Self operator--(int) {
2642       Self tmp = *this;
2643       --(*this);
2644       return tmp;
2645     }
2646     bool operator==(const Self& RHS) const {
2647       assert(RHS.SI == SI && "Incompatible operators.");
2648       return RHS.Index == Index;
2649     }
2650     bool operator!=(const Self& RHS) const {
2651       assert(RHS.SI == SI && "Incompatible operators.");
2652       return RHS.Index != Index;
2653     }
2654   };
2655
2656   typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2657     ConstCaseIt;
2658
2659   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2660
2661     typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2662
2663   public:
2664
2665     CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2666     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2667
2668     /// Sets the new value for current case.
2669     void setValue(ConstantInt *V) {
2670       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2671       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2672     }
2673
2674     /// Sets the new successor for current case.
2675     void setSuccessor(BasicBlock *S) {
2676       SI->setSuccessor(getSuccessorIndex(), S);
2677     }
2678   };
2679
2680   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2681                             unsigned NumCases,
2682                             Instruction *InsertBefore = nullptr) {
2683     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2684   }
2685   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2686                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2687     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2688   }
2689
2690   ~SwitchInst();
2691
2692   /// Provide fast operand accessors
2693   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2694
2695   // Accessor Methods for Switch stmt
2696   Value *getCondition() const { return getOperand(0); }
2697   void setCondition(Value *V) { setOperand(0, V); }
2698
2699   BasicBlock *getDefaultDest() const {
2700     return cast<BasicBlock>(getOperand(1));
2701   }
2702
2703   void setDefaultDest(BasicBlock *DefaultCase) {
2704     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2705   }
2706
2707   /// getNumCases - return the number of 'cases' in this switch instruction,
2708   /// except the default case
2709   unsigned getNumCases() const {
2710     return getNumOperands()/2 - 1;
2711   }
2712
2713   /// Returns a read/write iterator that points to the first
2714   /// case in SwitchInst.
2715   CaseIt case_begin() {
2716     return CaseIt(this, 0);
2717   }
2718   /// Returns a read-only iterator that points to the first
2719   /// case in the SwitchInst.
2720   ConstCaseIt case_begin() const {
2721     return ConstCaseIt(this, 0);
2722   }
2723
2724   /// Returns a read/write iterator that points one past the last
2725   /// in the SwitchInst.
2726   CaseIt case_end() {
2727     return CaseIt(this, getNumCases());
2728   }
2729   /// Returns a read-only iterator that points one past the last
2730   /// in the SwitchInst.
2731   ConstCaseIt case_end() const {
2732     return ConstCaseIt(this, getNumCases());
2733   }
2734   /// Returns an iterator that points to the default case.
2735   /// Note: this iterator allows to resolve successor only. Attempt
2736   /// to resolve case value causes an assertion.
2737   /// Also note, that increment and decrement also causes an assertion and
2738   /// makes iterator invalid.
2739   CaseIt case_default() {
2740     return CaseIt(this, DefaultPseudoIndex);
2741   }
2742   ConstCaseIt case_default() const {
2743     return ConstCaseIt(this, DefaultPseudoIndex);
2744   }
2745
2746   /// findCaseValue - Search all of the case values for the specified constant.
2747   /// If it is explicitly handled, return the case iterator of it, otherwise
2748   /// return default case iterator to indicate
2749   /// that it is handled by the default handler.
2750   CaseIt findCaseValue(const ConstantInt *C) {
2751     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2752       if (i.getCaseValue() == C)
2753         return i;
2754     return case_default();
2755   }
2756   ConstCaseIt findCaseValue(const ConstantInt *C) const {
2757     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2758       if (i.getCaseValue() == C)
2759         return i;
2760     return case_default();
2761   }
2762
2763   /// findCaseDest - Finds the unique case value for a given successor. Returns
2764   /// null if the successor is not found, not unique, or is the default case.
2765   ConstantInt *findCaseDest(BasicBlock *BB) {
2766     if (BB == getDefaultDest()) return nullptr;
2767
2768     ConstantInt *CI = nullptr;
2769     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2770       if (i.getCaseSuccessor() == BB) {
2771         if (CI) return nullptr;   // Multiple cases lead to BB.
2772         else CI = i.getCaseValue();
2773       }
2774     }
2775     return CI;
2776   }
2777
2778   /// addCase - Add an entry to the switch instruction...
2779   /// Note:
2780   /// This action invalidates case_end(). Old case_end() iterator will
2781   /// point to the added case.
2782   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2783
2784   /// removeCase - This method removes the specified case and its successor
2785   /// from the switch instruction. Note that this operation may reorder the
2786   /// remaining cases at index idx and above.
2787   /// Note:
2788   /// This action invalidates iterators for all cases following the one removed,
2789   /// including the case_end() iterator.
2790   void removeCase(CaseIt i);
2791
2792   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2793   BasicBlock *getSuccessor(unsigned idx) const {
2794     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2795     return cast<BasicBlock>(getOperand(idx*2+1));
2796   }
2797   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2798     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2799     setOperand(idx*2+1, (Value*)NewSucc);
2800   }
2801
2802   // Methods for support type inquiry through isa, cast, and dyn_cast:
2803   static inline bool classof(const Instruction *I) {
2804     return I->getOpcode() == Instruction::Switch;
2805   }
2806   static inline bool classof(const Value *V) {
2807     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2808   }
2809 private:
2810   BasicBlock *getSuccessorV(unsigned idx) const override;
2811   unsigned getNumSuccessorsV() const override;
2812   void setSuccessorV(unsigned idx, BasicBlock *B) override;
2813 };
2814
2815 template <>
2816 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2817 };
2818
2819 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2820
2821
2822 //===----------------------------------------------------------------------===//
2823 //                             IndirectBrInst Class
2824 //===----------------------------------------------------------------------===//
2825
2826 //===---------------------------------------------------------------------------
2827 /// IndirectBrInst - Indirect Branch Instruction.
2828 ///
2829 class IndirectBrInst : public TerminatorInst {
2830   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2831   unsigned ReservedSpace;
2832   // Operand[0]    = Value to switch on
2833   // Operand[1]    = Default basic block destination
2834   // Operand[2n  ] = Value to match
2835   // Operand[2n+1] = BasicBlock to go to on match
2836   IndirectBrInst(const IndirectBrInst &IBI);
2837   void init(Value *Address, unsigned NumDests);
2838   void growOperands();
2839   // allocate space for exactly zero operands
2840   void *operator new(size_t s) {
2841     return User::operator new(s, 0);
2842   }
2843   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2844   /// Address to jump to.  The number of expected destinations can be specified
2845   /// here to make memory allocation more efficient.  This constructor can also
2846   /// autoinsert before another instruction.
2847   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2848
2849   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2850   /// Address to jump to.  The number of expected destinations can be specified
2851   /// here to make memory allocation more efficient.  This constructor also
2852   /// autoinserts at the end of the specified BasicBlock.
2853   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2854 protected:
2855   IndirectBrInst *clone_impl() const override;
2856 public:
2857   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2858                                 Instruction *InsertBefore = nullptr) {
2859     return new IndirectBrInst(Address, NumDests, InsertBefore);
2860   }
2861   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2862                                 BasicBlock *InsertAtEnd) {
2863     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2864   }
2865   ~IndirectBrInst();
2866
2867   /// Provide fast operand accessors.
2868   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2869
2870   // Accessor Methods for IndirectBrInst instruction.
2871   Value *getAddress() { return getOperand(0); }
2872   const Value *getAddress() const { return getOperand(0); }
2873   void setAddress(Value *V) { setOperand(0, V); }
2874
2875
2876   /// getNumDestinations - return the number of possible destinations in this
2877   /// indirectbr instruction.
2878   unsigned getNumDestinations() const { return getNumOperands()-1; }
2879
2880   /// getDestination - Return the specified destination.
2881   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2882   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2883
2884   /// addDestination - Add a destination.
2885   ///
2886   void addDestination(BasicBlock *Dest);
2887
2888   /// removeDestination - This method removes the specified successor from the
2889   /// indirectbr instruction.
2890   void removeDestination(unsigned i);
2891
2892   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2893   BasicBlock *getSuccessor(unsigned i) const {
2894     return cast<BasicBlock>(getOperand(i+1));
2895   }
2896   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2897     setOperand(i+1, (Value*)NewSucc);
2898   }
2899
2900   // Methods for support type inquiry through isa, cast, and dyn_cast:
2901   static inline bool classof(const Instruction *I) {
2902     return I->getOpcode() == Instruction::IndirectBr;
2903   }
2904   static inline bool classof(const Value *V) {
2905     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2906   }
2907 private:
2908   BasicBlock *getSuccessorV(unsigned idx) const override;
2909   unsigned getNumSuccessorsV() const override;
2910   void setSuccessorV(unsigned idx, BasicBlock *B) override;
2911 };
2912
2913 template <>
2914 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2915 };
2916
2917 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2918
2919
2920 //===----------------------------------------------------------------------===//
2921 //                               InvokeInst Class
2922 //===----------------------------------------------------------------------===//
2923
2924 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2925 /// calling convention of the call.
2926 ///
2927 class InvokeInst : public TerminatorInst {
2928   AttributeSet AttributeList;
2929   InvokeInst(const InvokeInst &BI);
2930   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2931             ArrayRef<Value *> Args, const Twine &NameStr);
2932
2933   /// Construct an InvokeInst given a range of arguments.
2934   ///
2935   /// \brief Construct an InvokeInst from a range of arguments
2936   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2937                     ArrayRef<Value *> Args, unsigned Values,
2938                     const Twine &NameStr, Instruction *InsertBefore);
2939
2940   /// Construct an InvokeInst given a range of arguments.
2941   ///
2942   /// \brief Construct an InvokeInst from a range of arguments
2943   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2944                     ArrayRef<Value *> Args, unsigned Values,
2945                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2946 protected:
2947   InvokeInst *clone_impl() const override;
2948 public:
2949   static InvokeInst *Create(Value *Func,
2950                             BasicBlock *IfNormal, BasicBlock *IfException,
2951                             ArrayRef<Value *> Args, const Twine &NameStr = "",
2952                             Instruction *InsertBefore = nullptr) {
2953     unsigned Values = unsigned(Args.size()) + 3;
2954     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2955                                   Values, NameStr, InsertBefore);
2956   }
2957   static InvokeInst *Create(Value *Func,
2958                             BasicBlock *IfNormal, BasicBlock *IfException,
2959                             ArrayRef<Value *> Args, const Twine &NameStr,
2960                             BasicBlock *InsertAtEnd) {
2961     unsigned Values = unsigned(Args.size()) + 3;
2962     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2963                                   Values, NameStr, InsertAtEnd);
2964   }
2965
2966   /// Provide fast operand accessors
2967   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2968
2969   /// getNumArgOperands - Return the number of invoke arguments.
2970   ///
2971   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2972
2973   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2974   ///
2975   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2976   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2977
2978   /// arg_operands - iteration adapter for range-for loops.
2979   iterator_range<op_iterator> arg_operands() {
2980     return iterator_range<op_iterator>(op_begin(), op_end() - 3);
2981   }
2982
2983   /// arg_operands - iteration adapter for range-for loops.
2984   iterator_range<const_op_iterator> arg_operands() const {
2985     return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
2986   }
2987
2988   /// \brief Wrappers for getting the \c Use of a invoke argument.
2989   const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
2990   Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
2991
2992   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2993   /// function call.
2994   CallingConv::ID getCallingConv() const {
2995     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2996   }
2997   void setCallingConv(CallingConv::ID CC) {
2998     setInstructionSubclassData(static_cast<unsigned>(CC));
2999   }
3000
3001   /// getAttributes - Return the parameter attributes for this invoke.
3002   ///
3003   const AttributeSet &getAttributes() const { return AttributeList; }
3004
3005   /// setAttributes - Set the parameter attributes for this invoke.
3006   ///
3007   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
3008
3009   /// addAttribute - adds the attribute to the list of attributes.
3010   void addAttribute(unsigned i, Attribute::AttrKind attr);
3011
3012   /// removeAttribute - removes the attribute from the list of attributes.
3013   void removeAttribute(unsigned i, Attribute attr);
3014
3015   /// \brief Determine whether this call has the given attribute.
3016   bool hasFnAttr(Attribute::AttrKind A) const {
3017     assert(A != Attribute::NoBuiltin &&
3018            "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3019     return hasFnAttrImpl(A);
3020   }
3021
3022   /// \brief Determine whether the call or the callee has the given attributes.
3023   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3024
3025   /// \brief Extract the alignment for a call or parameter (0=unknown).
3026   unsigned getParamAlignment(unsigned i) const {
3027     return AttributeList.getParamAlignment(i);
3028   }
3029
3030   /// \brief Return true if the call should not be treated as a call to a
3031   /// builtin.
3032   bool isNoBuiltin() const {
3033     // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3034     // to check it by hand.
3035     return hasFnAttrImpl(Attribute::NoBuiltin) &&
3036       !hasFnAttrImpl(Attribute::Builtin);
3037   }
3038
3039   /// \brief Return true if the call should not be inlined.
3040   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3041   void setIsNoInline() {
3042     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3043   }
3044
3045   /// \brief Determine if the call does not access memory.
3046   bool doesNotAccessMemory() const {
3047     return hasFnAttr(Attribute::ReadNone);
3048   }
3049   void setDoesNotAccessMemory() {
3050     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3051   }
3052
3053   /// \brief Determine if the call does not access or only reads memory.
3054   bool onlyReadsMemory() const {
3055     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3056   }
3057   void setOnlyReadsMemory() {
3058     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3059   }
3060
3061   /// \brief Determine if the call cannot return.
3062   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3063   void setDoesNotReturn() {
3064     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3065   }
3066
3067   /// \brief Determine if the call cannot unwind.
3068   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3069   void setDoesNotThrow() {
3070     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3071   }
3072
3073   /// \brief Determine if the invoke cannot be duplicated.
3074   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3075   void setCannotDuplicate() {
3076     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3077   }
3078
3079   /// \brief Determine if the call returns a structure through first
3080   /// pointer argument.
3081   bool hasStructRetAttr() const {
3082     // Be friendly and also check the callee.
3083     return paramHasAttr(1, Attribute::StructRet);
3084   }
3085
3086   /// \brief Determine if any call argument is an aggregate passed by value.
3087   bool hasByValArgument() const {
3088     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3089   }
3090
3091   /// getCalledFunction - Return the function called, or null if this is an
3092   /// indirect function invocation.
3093   ///
3094   Function *getCalledFunction() const {
3095     return dyn_cast<Function>(Op<-3>());
3096   }
3097
3098   /// getCalledValue - Get a pointer to the function that is invoked by this
3099   /// instruction
3100   const Value *getCalledValue() const { return Op<-3>(); }
3101         Value *getCalledValue()       { return Op<-3>(); }
3102
3103   /// setCalledFunction - Set the function called.
3104   void setCalledFunction(Value* Fn) {
3105     Op<-3>() = Fn;
3106   }
3107
3108   // get*Dest - Return the destination basic blocks...
3109   BasicBlock *getNormalDest() const {
3110     return cast<BasicBlock>(Op<-2>());
3111   }
3112   BasicBlock *getUnwindDest() const {
3113     return cast<BasicBlock>(Op<-1>());
3114   }
3115   void setNormalDest(BasicBlock *B) {
3116     Op<-2>() = reinterpret_cast<Value*>(B);
3117   }
3118   void setUnwindDest(BasicBlock *B) {
3119     Op<-1>() = reinterpret_cast<Value*>(B);
3120   }
3121
3122   /// getLandingPadInst - Get the landingpad instruction from the landing pad
3123   /// block (the unwind destination).
3124   LandingPadInst *getLandingPadInst() const;
3125
3126   BasicBlock *getSuccessor(unsigned i) const {
3127     assert(i < 2 && "Successor # out of range for invoke!");
3128     return i == 0 ? getNormalDest() : getUnwindDest();
3129   }
3130
3131   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3132     assert(idx < 2 && "Successor # out of range for invoke!");
3133     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3134   }
3135
3136   unsigned getNumSuccessors() const { return 2; }
3137
3138   // Methods for support type inquiry through isa, cast, and dyn_cast:
3139   static inline bool classof(const Instruction *I) {
3140     return (I->getOpcode() == Instruction::Invoke);
3141   }
3142   static inline bool classof(const Value *V) {
3143     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3144   }
3145
3146 private:
3147   BasicBlock *getSuccessorV(unsigned idx) const override;
3148   unsigned getNumSuccessorsV() const override;
3149   void setSuccessorV(unsigned idx, BasicBlock *B) override;
3150
3151   bool hasFnAttrImpl(Attribute::AttrKind A) const;
3152
3153   // Shadow Instruction::setInstructionSubclassData with a private forwarding
3154   // method so that subclasses cannot accidentally use it.
3155   void setInstructionSubclassData(unsigned short D) {
3156     Instruction::setInstructionSubclassData(D);
3157   }
3158 };
3159
3160 template <>
3161 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3162 };
3163
3164 InvokeInst::InvokeInst(Value *Func,
3165                        BasicBlock *IfNormal, BasicBlock *IfException,
3166                        ArrayRef<Value *> Args, unsigned Values,
3167                        const Twine &NameStr, Instruction *InsertBefore)
3168   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3169                                       ->getElementType())->getReturnType(),
3170                    Instruction::Invoke,
3171                    OperandTraits<InvokeInst>::op_end(this) - Values,
3172                    Values, InsertBefore) {
3173   init(Func, IfNormal, IfException, Args, NameStr);
3174 }
3175 InvokeInst::InvokeInst(Value *Func,
3176                        BasicBlock *IfNormal, BasicBlock *IfException,
3177                        ArrayRef<Value *> Args, unsigned Values,
3178                        const Twine &NameStr, BasicBlock *InsertAtEnd)
3179   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3180                                       ->getElementType())->getReturnType(),
3181                    Instruction::Invoke,
3182                    OperandTraits<InvokeInst>::op_end(this) - Values,
3183                    Values, InsertAtEnd) {
3184   init(Func, IfNormal, IfException, Args, NameStr);
3185 }
3186
3187 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3188
3189 //===----------------------------------------------------------------------===//
3190 //                              ResumeInst Class
3191 //===----------------------------------------------------------------------===//
3192
3193 //===---------------------------------------------------------------------------
3194 /// ResumeInst - Resume the propagation of an exception.
3195 ///
3196 class ResumeInst : public TerminatorInst {
3197   ResumeInst(const ResumeInst &RI);
3198
3199   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3200   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3201 protected:
3202   ResumeInst *clone_impl() const override;
3203 public:
3204   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3205     return new(1) ResumeInst(Exn, InsertBefore);
3206   }
3207   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3208     return new(1) ResumeInst(Exn, InsertAtEnd);
3209   }
3210
3211   /// Provide fast operand accessors
3212   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3213
3214   /// Convenience accessor.
3215   Value *getValue() const { return Op<0>(); }
3216
3217   unsigned getNumSuccessors() const { return 0; }
3218
3219   // Methods for support type inquiry through isa, cast, and dyn_cast:
3220   static inline bool classof(const Instruction *I) {
3221     return I->getOpcode() == Instruction::Resume;
3222   }
3223   static inline bool classof(const Value *V) {
3224     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3225   }
3226 private:
3227   BasicBlock *getSuccessorV(unsigned idx) const override;
3228   unsigned getNumSuccessorsV() const override;
3229   void setSuccessorV(unsigned idx, BasicBlock *B) override;
3230 };
3231
3232 template <>
3233 struct OperandTraits<ResumeInst> :
3234     public FixedNumOperandTraits<ResumeInst, 1> {
3235 };
3236
3237 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3238
3239 //===----------------------------------------------------------------------===//
3240 //                           UnreachableInst Class
3241 //===----------------------------------------------------------------------===//
3242
3243 //===---------------------------------------------------------------------------
3244 /// UnreachableInst - This function has undefined behavior.  In particular, the
3245 /// presence of this instruction indicates some higher level knowledge that the
3246 /// end of the block cannot be reached.
3247 ///
3248 class UnreachableInst : public TerminatorInst {
3249   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3250 protected:
3251   UnreachableInst *clone_impl() const override;
3252
3253 public:
3254   // allocate space for exactly zero operands
3255   void *operator new(size_t s) {
3256     return User::operator new(s, 0);
3257   }
3258   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
3259   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3260
3261   unsigned getNumSuccessors() const { return 0; }
3262
3263   // Methods for support type inquiry through isa, cast, and dyn_cast:
3264   static inline bool classof(const Instruction *I) {
3265     return I->getOpcode() == Instruction::Unreachable;
3266   }
3267   static inline bool classof(const Value *V) {
3268     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3269   }
3270 private:
3271   BasicBlock *getSuccessorV(unsigned idx) const override;
3272   unsigned getNumSuccessorsV() const override;
3273   void setSuccessorV(unsigned idx, BasicBlock *B) override;
3274 };
3275
3276 //===----------------------------------------------------------------------===//
3277 //                                 TruncInst Class
3278 //===----------------------------------------------------------------------===//
3279
3280 /// \brief This class represents a truncation of integer types.
3281 class TruncInst : public CastInst {
3282 protected:
3283   /// \brief Clone an identical TruncInst
3284   TruncInst *clone_impl() const override;
3285
3286 public:
3287   /// \brief Constructor with insert-before-instruction semantics
3288   TruncInst(
3289     Value *S,                           ///< The value to be truncated
3290     Type *Ty,                           ///< The (smaller) type to truncate to
3291     const Twine &NameStr = "",          ///< A name for the new instruction
3292     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3293   );
3294
3295   /// \brief Constructor with insert-at-end-of-block semantics
3296   TruncInst(
3297     Value *S,                     ///< The value to be truncated
3298     Type *Ty,                     ///< The (smaller) type to truncate to
3299     const Twine &NameStr,         ///< A name for the new instruction
3300     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3301   );
3302
3303   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3304   static inline bool classof(const Instruction *I) {
3305     return I->getOpcode() == Trunc;
3306   }
3307   static inline bool classof(const Value *V) {
3308     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3309   }
3310 };
3311
3312 //===----------------------------------------------------------------------===//
3313 //                                 ZExtInst Class
3314 //===----------------------------------------------------------------------===//
3315
3316 /// \brief This class represents zero extension of integer types.
3317 class ZExtInst : public CastInst {
3318 protected:
3319   /// \brief Clone an identical ZExtInst
3320   ZExtInst *clone_impl() const override;
3321
3322 public:
3323   /// \brief Constructor with insert-before-instruction semantics
3324   ZExtInst(
3325     Value *S,                           ///< The value to be zero extended
3326     Type *Ty,                           ///< The type to zero extend to
3327     const Twine &NameStr = "",          ///< A name for the new instruction
3328     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3329   );
3330
3331   /// \brief Constructor with insert-at-end semantics.
3332   ZExtInst(
3333     Value *S,                     ///< The value to be zero extended
3334     Type *Ty,                     ///< The type to zero extend to
3335     const Twine &NameStr,         ///< A name for the new instruction
3336     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3337   );
3338
3339   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3340   static inline bool classof(const Instruction *I) {
3341     return I->getOpcode() == ZExt;
3342   }
3343   static inline bool classof(const Value *V) {
3344     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3345   }
3346 };
3347
3348 //===----------------------------------------------------------------------===//
3349 //                                 SExtInst Class
3350 //===----------------------------------------------------------------------===//
3351
3352 /// \brief This class represents a sign extension of integer types.
3353 class SExtInst : public CastInst {
3354 protected:
3355   /// \brief Clone an identical SExtInst
3356   SExtInst *clone_impl() const override;
3357
3358 public:
3359   /// \brief Constructor with insert-before-instruction semantics
3360   SExtInst(
3361     Value *S,                           ///< The value to be sign extended
3362     Type *Ty,                           ///< The type to sign extend to
3363     const Twine &NameStr = "",          ///< A name for the new instruction
3364     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3365   );
3366
3367   /// \brief Constructor with insert-at-end-of-block semantics
3368   SExtInst(
3369     Value *S,                     ///< The value to be sign extended
3370     Type *Ty,                     ///< The type to sign extend to
3371     const Twine &NameStr,         ///< A name for the new instruction
3372     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3373   );
3374
3375   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3376   static inline bool classof(const Instruction *I) {
3377     return I->getOpcode() == SExt;
3378   }
3379   static inline bool classof(const Value *V) {
3380     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3381   }
3382 };
3383
3384 //===----------------------------------------------------------------------===//
3385 //                                 FPTruncInst Class
3386 //===----------------------------------------------------------------------===//
3387
3388 /// \brief This class represents a truncation of floating point types.
3389 class FPTruncInst : public CastInst {
3390 protected:
3391   /// \brief Clone an identical FPTruncInst
3392   FPTruncInst *clone_impl() const override;
3393
3394 public:
3395   /// \brief Constructor with insert-before-instruction semantics
3396   FPTruncInst(
3397     Value *S,                           ///< The value to be truncated
3398     Type *Ty,                           ///< The type to truncate to
3399     const Twine &NameStr = "",          ///< A name for the new instruction
3400     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3401   );
3402
3403   /// \brief Constructor with insert-before-instruction semantics
3404   FPTruncInst(
3405     Value *S,                     ///< The value to be truncated
3406     Type *Ty,                     ///< The type to truncate to
3407     const Twine &NameStr,         ///< A name for the new instruction
3408     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3409   );
3410
3411   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3412   static inline bool classof(const Instruction *I) {
3413     return I->getOpcode() == FPTrunc;
3414   }
3415   static inline bool classof(const Value *V) {
3416     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3417   }
3418 };
3419
3420 //===----------------------------------------------------------------------===//
3421 //                                 FPExtInst Class
3422 //===----------------------------------------------------------------------===//
3423
3424 /// \brief This class represents an extension of floating point types.
3425 class FPExtInst : public CastInst {
3426 protected:
3427   /// \brief Clone an identical FPExtInst
3428   FPExtInst *clone_impl() const override;
3429
3430 public:
3431   /// \brief Constructor with insert-before-instruction semantics
3432   FPExtInst(
3433     Value *S,                           ///< The value to be extended
3434     Type *Ty,                           ///< The type to extend to
3435     const Twine &NameStr = "",          ///< A name for the new instruction
3436     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3437   );
3438
3439   /// \brief Constructor with insert-at-end-of-block semantics
3440   FPExtInst(
3441     Value *S,                     ///< The value to be extended
3442     Type *Ty,                     ///< The type to extend to
3443     const Twine &NameStr,         ///< A name for the new instruction
3444     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3445   );
3446
3447   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3448   static inline bool classof(const Instruction *I) {
3449     return I->getOpcode() == FPExt;
3450   }
3451   static inline bool classof(const Value *V) {
3452     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3453   }
3454 };
3455
3456 //===----------------------------------------------------------------------===//
3457 //                                 UIToFPInst Class
3458 //===----------------------------------------------------------------------===//
3459
3460 /// \brief This class represents a cast unsigned integer to floating point.
3461 class UIToFPInst : public CastInst {
3462 protected:
3463   /// \brief Clone an identical UIToFPInst
3464   UIToFPInst *clone_impl() const override;
3465
3466 public:
3467   /// \brief Constructor with insert-before-instruction semantics
3468   UIToFPInst(
3469     Value *S,                           ///< The value to be converted
3470     Type *Ty,                           ///< The type to convert to
3471     const Twine &NameStr = "",          ///< A name for the new instruction
3472     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3473   );
3474
3475   /// \brief Constructor with insert-at-end-of-block semantics
3476   UIToFPInst(
3477     Value *S,                     ///< The value to be converted
3478     Type *Ty,                     ///< The type to convert to
3479     const Twine &NameStr,         ///< A name for the new instruction
3480     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3481   );
3482
3483   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3484   static inline bool classof(const Instruction *I) {
3485     return I->getOpcode() == UIToFP;
3486   }
3487   static inline bool classof(const Value *V) {
3488     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3489   }
3490 };
3491
3492 //===----------------------------------------------------------------------===//
3493 //                                 SIToFPInst Class
3494 //===----------------------------------------------------------------------===//
3495
3496 /// \brief This class represents a cast from signed integer to floating point.
3497 class SIToFPInst : public CastInst {
3498 protected:
3499   /// \brief Clone an identical SIToFPInst
3500   SIToFPInst *clone_impl() const override;
3501
3502 public:
3503   /// \brief Constructor with insert-before-instruction semantics
3504   SIToFPInst(
3505     Value *S,                           ///< The value to be converted
3506     Type *Ty,                           ///< The type to convert to
3507     const Twine &NameStr = "",          ///< A name for the new instruction
3508     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3509   );
3510
3511   /// \brief Constructor with insert-at-end-of-block semantics
3512   SIToFPInst(
3513     Value *S,                     ///< The value to be converted
3514     Type *Ty,                     ///< The type to convert to
3515     const Twine &NameStr,         ///< A name for the new instruction
3516     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3517   );
3518
3519   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3520   static inline bool classof(const Instruction *I) {
3521     return I->getOpcode() == SIToFP;
3522   }
3523   static inline bool classof(const Value *V) {
3524     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3525   }
3526 };
3527
3528 //===----------------------------------------------------------------------===//
3529 //                                 FPToUIInst Class
3530 //===----------------------------------------------------------------------===//
3531
3532 /// \brief This class represents a cast from floating point to unsigned integer
3533 class FPToUIInst  : public CastInst {
3534 protected:
3535   /// \brief Clone an identical FPToUIInst
3536   FPToUIInst *clone_impl() const override;
3537
3538 public:
3539   /// \brief Constructor with insert-before-instruction semantics
3540   FPToUIInst(
3541     Value *S,                           ///< The value to be converted
3542     Type *Ty,                           ///< The type to convert to
3543     const Twine &NameStr = "",          ///< A name for the new instruction
3544     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3545   );
3546
3547   /// \brief Constructor with insert-at-end-of-block semantics
3548   FPToUIInst(
3549     Value *S,                     ///< The value to be converted
3550     Type *Ty,                     ///< The type to convert to
3551     const Twine &NameStr,         ///< A name for the new instruction
3552     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
3553   );
3554
3555   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3556   static inline bool classof(const Instruction *I) {
3557     return I->getOpcode() == FPToUI;
3558   }
3559   static inline bool classof(const Value *V) {
3560     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3561   }
3562 };
3563
3564 //===----------------------------------------------------------------------===//
3565 //                                 FPToSIInst Class
3566 //===----------------------------------------------------------------------===//
3567
3568 /// \brief This class represents a cast from floating point to signed integer.
3569 class FPToSIInst  : public CastInst {
3570 protected:
3571   /// \brief Clone an identical FPToSIInst
3572   FPToSIInst *clone_impl() const override;
3573
3574 public:
3575   /// \brief Constructor with insert-before-instruction semantics
3576   FPToSIInst(
3577     Value *S,                           ///< The value to be converted
3578     Type *Ty,                           ///< The type to convert to
3579     const Twine &NameStr = "",          ///< A name for the new instruction
3580     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3581   );
3582
3583   /// \brief Constructor with insert-at-end-of-block semantics
3584   FPToSIInst(
3585     Value *S,                     ///< The value to be converted
3586     Type *Ty,                     ///< The type to convert to
3587     const Twine &NameStr,         ///< A name for the new instruction
3588     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3589   );
3590
3591   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3592   static inline bool classof(const Instruction *I) {
3593     return I->getOpcode() == FPToSI;
3594   }
3595   static inline bool classof(const Value *V) {
3596     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3597   }
3598 };
3599
3600 //===----------------------------------------------------------------------===//
3601 //                                 IntToPtrInst Class
3602 //===----------------------------------------------------------------------===//
3603
3604 /// \brief This class represents a cast from an integer to a pointer.
3605 class IntToPtrInst : public CastInst {
3606 public:
3607   /// \brief Constructor with insert-before-instruction semantics
3608   IntToPtrInst(
3609     Value *S,                           ///< The value to be converted
3610     Type *Ty,                           ///< The type to convert to
3611     const Twine &NameStr = "",          ///< A name for the new instruction
3612     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3613   );
3614
3615   /// \brief Constructor with insert-at-end-of-block semantics
3616   IntToPtrInst(
3617     Value *S,                     ///< The value to be converted
3618     Type *Ty,                     ///< The type to convert to
3619     const Twine &NameStr,         ///< A name for the new instruction
3620     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3621   );
3622
3623   /// \brief Clone an identical IntToPtrInst
3624   IntToPtrInst *clone_impl() const override;
3625
3626   /// \brief Returns the address space of this instruction's pointer type.
3627   unsigned getAddressSpace() const {
3628     return getType()->getPointerAddressSpace();
3629   }
3630
3631   // Methods for support type inquiry through isa, cast, and dyn_cast:
3632   static inline bool classof(const Instruction *I) {
3633     return I->getOpcode() == IntToPtr;
3634   }
3635   static inline bool classof(const Value *V) {
3636     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3637   }
3638 };
3639
3640 //===----------------------------------------------------------------------===//
3641 //                                 PtrToIntInst Class
3642 //===----------------------------------------------------------------------===//
3643
3644 /// \brief This class represents a cast from a pointer to an integer
3645 class PtrToIntInst : public CastInst {
3646 protected:
3647   /// \brief Clone an identical PtrToIntInst
3648   PtrToIntInst *clone_impl() const override;
3649
3650 public:
3651   /// \brief Constructor with insert-before-instruction semantics
3652   PtrToIntInst(
3653     Value *S,                           ///< The value to be converted
3654     Type *Ty,                           ///< The type to convert to
3655     const Twine &NameStr = "",          ///< A name for the new instruction
3656     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3657   );
3658
3659   /// \brief Constructor with insert-at-end-of-block semantics
3660   PtrToIntInst(
3661     Value *S,                     ///< The value to be converted
3662     Type *Ty,                     ///< The type to convert to
3663     const Twine &NameStr,         ///< A name for the new instruction
3664     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3665   );
3666
3667   /// \brief Gets the pointer operand.
3668   Value *getPointerOperand() { return getOperand(0); }
3669   /// \brief Gets the pointer operand.
3670   const Value *getPointerOperand() const { return getOperand(0); }
3671   /// \brief Gets the operand index of the pointer operand.
3672   static unsigned getPointerOperandIndex() { return 0U; }
3673
3674   /// \brief Returns the address space of the pointer operand.
3675   unsigned getPointerAddressSpace() const {
3676     return getPointerOperand()->getType()->getPointerAddressSpace();
3677   }
3678
3679   // Methods for support type inquiry through isa, cast, and dyn_cast:
3680   static inline bool classof(const Instruction *I) {
3681     return I->getOpcode() == PtrToInt;
3682   }
3683   static inline bool classof(const Value *V) {
3684     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3685   }
3686 };
3687
3688 //===----------------------------------------------------------------------===//
3689 //                             BitCastInst Class
3690 //===----------------------------------------------------------------------===//
3691
3692 /// \brief This class represents a no-op cast from one type to another.
3693 class BitCastInst : public CastInst {
3694 protected:
3695   /// \brief Clone an identical BitCastInst
3696   BitCastInst *clone_impl() const override;
3697
3698 public:
3699   /// \brief Constructor with insert-before-instruction semantics
3700   BitCastInst(
3701     Value *S,                           ///< The value to be casted
3702     Type *Ty,                           ///< The type to casted to
3703     const Twine &NameStr = "",          ///< A name for the new instruction
3704     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3705   );
3706
3707   /// \brief Constructor with insert-at-end-of-block semantics
3708   BitCastInst(
3709     Value *S,                     ///< The value to be casted
3710     Type *Ty,                     ///< The type to casted to
3711     const Twine &NameStr,         ///< A name for the new instruction
3712     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3713   );
3714
3715   // Methods for support type inquiry through isa, cast, and dyn_cast:
3716   static inline bool classof(const Instruction *I) {
3717     return I->getOpcode() == BitCast;
3718   }
3719   static inline bool classof(const Value *V) {
3720     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3721   }
3722 };
3723
3724 //===----------------------------------------------------------------------===//
3725 //                          AddrSpaceCastInst Class
3726 //===----------------------------------------------------------------------===//
3727
3728 /// \brief This class represents a conversion between pointers from
3729 /// one address space to another.
3730 class AddrSpaceCastInst : public CastInst {
3731 protected:
3732   /// \brief Clone an identical AddrSpaceCastInst
3733   AddrSpaceCastInst *clone_impl() const override;
3734
3735 public:
3736   /// \brief Constructor with insert-before-instruction semantics
3737   AddrSpaceCastInst(
3738     Value *S,                           ///< The value to be casted
3739     Type *Ty,                           ///< The type to casted to
3740     const Twine &NameStr = "",          ///< A name for the new instruction
3741     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3742   );
3743
3744   /// \brief Constructor with insert-at-end-of-block semantics
3745   AddrSpaceCastInst(
3746     Value *S,                     ///< The value to be casted
3747     Type *Ty,                     ///< The type to casted to
3748     const Twine &NameStr,         ///< A name for the new instruction
3749     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3750   );
3751
3752   // Methods for support type inquiry through isa, cast, and dyn_cast:
3753   static inline bool classof(const Instruction *I) {
3754     return I->getOpcode() == AddrSpaceCast;
3755   }
3756   static inline bool classof(const Value *V) {
3757     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3758   }
3759 };
3760
3761 } // End llvm namespace
3762
3763 #endif