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