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