Convert InsertValueInst and ExtractValueInst APIs to use ArrayRef.
[oota-llvm.git] / include / llvm / 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_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
18
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include <iterator>
26
27 namespace llvm {
28
29 class ConstantInt;
30 class ConstantRange;
31 class APInt;
32 class LLVMContext;
33
34 //===----------------------------------------------------------------------===//
35 //                                AllocaInst Class
36 //===----------------------------------------------------------------------===//
37
38 /// AllocaInst - an instruction to allocate memory on the stack
39 ///
40 class AllocaInst : public UnaryInstruction {
41 protected:
42   virtual AllocaInst *clone_impl() const;
43 public:
44   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
45                       const Twine &Name = "", Instruction *InsertBefore = 0);
46   AllocaInst(const Type *Ty, Value *ArraySize,
47              const Twine &Name, BasicBlock *InsertAtEnd);
48
49   AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
50   AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
51
52   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
53              const Twine &Name = "", Instruction *InsertBefore = 0);
54   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
55              const Twine &Name, BasicBlock *InsertAtEnd);
56
57   // Out of line virtual method, so the vtable, etc. has a home.
58   virtual ~AllocaInst();
59
60   /// isArrayAllocation - Return true if there is an allocation size parameter
61   /// to the allocation instruction that is not 1.
62   ///
63   bool isArrayAllocation() const;
64
65   /// getArraySize - Get the number of elements allocated. For a simple
66   /// allocation of a single element, this will return a constant 1 value.
67   ///
68   const Value *getArraySize() const { return getOperand(0); }
69   Value *getArraySize() { return getOperand(0); }
70
71   /// getType - Overload to return most specific pointer type
72   ///
73   const PointerType *getType() const {
74     return reinterpret_cast<const PointerType*>(Instruction::getType());
75   }
76
77   /// getAllocatedType - Return the type that is being allocated by the
78   /// instruction.
79   ///
80   Type *getAllocatedType() const;
81
82   /// getAlignment - Return the alignment of the memory that is being allocated
83   /// by the instruction.
84   ///
85   unsigned getAlignment() const {
86     return (1u << getSubclassDataFromInstruction()) >> 1;
87   }
88   void setAlignment(unsigned Align);
89
90   /// isStaticAlloca - Return true if this alloca is in the entry block of the
91   /// function and is a constant size.  If so, the code generator will fold it
92   /// into the prolog/epilog code, so it is basically free.
93   bool isStaticAlloca() const;
94
95   // Methods for support type inquiry through isa, cast, and dyn_cast:
96   static inline bool classof(const AllocaInst *) { return true; }
97   static inline bool classof(const Instruction *I) {
98     return (I->getOpcode() == Instruction::Alloca);
99   }
100   static inline bool classof(const Value *V) {
101     return isa<Instruction>(V) && classof(cast<Instruction>(V));
102   }
103 private:
104   // Shadow Instruction::setInstructionSubclassData with a private forwarding
105   // method so that subclasses cannot accidentally use it.
106   void setInstructionSubclassData(unsigned short D) {
107     Instruction::setInstructionSubclassData(D);
108   }
109 };
110
111
112 //===----------------------------------------------------------------------===//
113 //                                LoadInst Class
114 //===----------------------------------------------------------------------===//
115
116 /// LoadInst - an instruction for reading from memory.  This uses the
117 /// SubclassData field in Value to store whether or not the load is volatile.
118 ///
119 class LoadInst : public UnaryInstruction {
120   void AssertOK();
121 protected:
122   virtual LoadInst *clone_impl() const;
123 public:
124   LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
125   LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
126   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
127            Instruction *InsertBefore = 0);
128   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
129            unsigned Align, Instruction *InsertBefore = 0);
130   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
131            BasicBlock *InsertAtEnd);
132   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
133            unsigned Align, BasicBlock *InsertAtEnd);
134
135   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
136   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
137   explicit LoadInst(Value *Ptr, const char *NameStr = 0,
138                     bool isVolatile = false,  Instruction *InsertBefore = 0);
139   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
140            BasicBlock *InsertAtEnd);
141
142   /// isVolatile - Return true if this is a load from a volatile memory
143   /// location.
144   ///
145   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
146
147   /// setVolatile - Specify whether this is a volatile load or not.
148   ///
149   void setVolatile(bool V) {
150     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
151                                (V ? 1 : 0));
152   }
153
154   /// getAlignment - Return the alignment of the access that is being performed
155   ///
156   unsigned getAlignment() const {
157     return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
158   }
159
160   void setAlignment(unsigned Align);
161
162   Value *getPointerOperand() { return getOperand(0); }
163   const Value *getPointerOperand() const { return getOperand(0); }
164   static unsigned getPointerOperandIndex() { return 0U; }
165
166   unsigned getPointerAddressSpace() const {
167     return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
168   }
169
170
171   // Methods for support type inquiry through isa, cast, and dyn_cast:
172   static inline bool classof(const LoadInst *) { return true; }
173   static inline bool classof(const Instruction *I) {
174     return I->getOpcode() == Instruction::Load;
175   }
176   static inline bool classof(const Value *V) {
177     return isa<Instruction>(V) && classof(cast<Instruction>(V));
178   }
179 private:
180   // Shadow Instruction::setInstructionSubclassData with a private forwarding
181   // method so that subclasses cannot accidentally use it.
182   void setInstructionSubclassData(unsigned short D) {
183     Instruction::setInstructionSubclassData(D);
184   }
185 };
186
187
188 //===----------------------------------------------------------------------===//
189 //                                StoreInst Class
190 //===----------------------------------------------------------------------===//
191
192 /// StoreInst - an instruction for storing to memory
193 ///
194 class StoreInst : public Instruction {
195   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
196   void AssertOK();
197 protected:
198   virtual StoreInst *clone_impl() const;
199 public:
200   // allocate space for exactly two operands
201   void *operator new(size_t s) {
202     return User::operator new(s, 2);
203   }
204   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
205   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
206   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
207             Instruction *InsertBefore = 0);
208   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
209             unsigned Align, Instruction *InsertBefore = 0);
210   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
211   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
212             unsigned Align, BasicBlock *InsertAtEnd);
213
214
215   /// isVolatile - Return true if this is a load from a volatile memory
216   /// location.
217   ///
218   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
219
220   /// setVolatile - Specify whether this is a volatile load or not.
221   ///
222   void setVolatile(bool V) {
223     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
224                                (V ? 1 : 0));
225   }
226
227   /// Transparently provide more efficient getOperand methods.
228   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
229
230   /// getAlignment - Return the alignment of the access that is being performed
231   ///
232   unsigned getAlignment() const {
233     return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
234   }
235
236   void setAlignment(unsigned Align);
237
238   Value *getValueOperand() { return getOperand(0); }
239   const Value *getValueOperand() const { return getOperand(0); }
240
241   Value *getPointerOperand() { return getOperand(1); }
242   const Value *getPointerOperand() const { return getOperand(1); }
243   static unsigned getPointerOperandIndex() { return 1U; }
244
245   unsigned getPointerAddressSpace() const {
246     return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
247   }
248
249   // Methods for support type inquiry through isa, cast, and dyn_cast:
250   static inline bool classof(const StoreInst *) { return true; }
251   static inline bool classof(const Instruction *I) {
252     return I->getOpcode() == Instruction::Store;
253   }
254   static inline bool classof(const Value *V) {
255     return isa<Instruction>(V) && classof(cast<Instruction>(V));
256   }
257 private:
258   // Shadow Instruction::setInstructionSubclassData with a private forwarding
259   // method so that subclasses cannot accidentally use it.
260   void setInstructionSubclassData(unsigned short D) {
261     Instruction::setInstructionSubclassData(D);
262   }
263 };
264
265 template <>
266 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
267 };
268
269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
270
271 //===----------------------------------------------------------------------===//
272 //                             GetElementPtrInst Class
273 //===----------------------------------------------------------------------===//
274
275 // checkGEPType - Simple wrapper function to give a better assertion failure
276 // message on bad indexes for a gep instruction.
277 //
278 static inline const Type *checkGEPType(const Type *Ty) {
279   assert(Ty && "Invalid GetElementPtrInst indices for type!");
280   return Ty;
281 }
282
283 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
284 /// access elements of arrays and structs
285 ///
286 class GetElementPtrInst : public Instruction {
287   GetElementPtrInst(const GetElementPtrInst &GEPI);
288   void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
289             const Twine &NameStr);
290   void init(Value *Ptr, Value *Idx, const Twine &NameStr);
291
292   template<typename RandomAccessIterator>
293   void init(Value *Ptr,
294             RandomAccessIterator IdxBegin,
295             RandomAccessIterator IdxEnd,
296             const Twine &NameStr,
297             // This argument ensures that we have an iterator we can
298             // do arithmetic on in constant time
299             std::random_access_iterator_tag) {
300     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
301
302     if (NumIdx > 0) {
303       // This requires that the iterator points to contiguous memory.
304       init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
305                                      // we have to build an array here
306     }
307     else {
308       init(Ptr, 0, NumIdx, NameStr);
309     }
310   }
311
312   /// getIndexedType - Returns the type of the element that would be loaded with
313   /// a load instruction with the specified parameters.
314   ///
315   /// Null is returned if the indices are invalid for the specified
316   /// pointer type.
317   ///
318   template<typename RandomAccessIterator>
319   static Type *getIndexedType(const Type *Ptr,
320                               RandomAccessIterator IdxBegin,
321                               RandomAccessIterator IdxEnd,
322                               // This argument ensures that we
323                               // have an iterator we can do
324                               // arithmetic on in constant time
325                               std::random_access_iterator_tag) {
326     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
327
328     if (NumIdx > 0)
329       // This requires that the iterator points to contiguous memory.
330       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
331     else
332       return getIndexedType(Ptr, (Value *const*)0, NumIdx);
333   }
334
335   /// Constructors - Create a getelementptr instruction with a base pointer an
336   /// list of indices. The first ctor can optionally insert before an existing
337   /// instruction, the second appends the new instruction to the specified
338   /// BasicBlock.
339   template<typename RandomAccessIterator>
340   inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
341                            RandomAccessIterator IdxEnd,
342                            unsigned Values,
343                            const Twine &NameStr,
344                            Instruction *InsertBefore);
345   template<typename RandomAccessIterator>
346   inline GetElementPtrInst(Value *Ptr,
347                            RandomAccessIterator IdxBegin,
348                            RandomAccessIterator IdxEnd,
349                            unsigned Values,
350                            const Twine &NameStr, BasicBlock *InsertAtEnd);
351
352   /// Constructors - These two constructors are convenience methods because one
353   /// and two index getelementptr instructions are so common.
354   GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
355                     Instruction *InsertBefore = 0);
356   GetElementPtrInst(Value *Ptr, Value *Idx,
357                     const Twine &NameStr, BasicBlock *InsertAtEnd);
358 protected:
359   virtual GetElementPtrInst *clone_impl() const;
360 public:
361   template<typename RandomAccessIterator>
362   static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
363                                    RandomAccessIterator IdxEnd,
364                                    const Twine &NameStr = "",
365                                    Instruction *InsertBefore = 0) {
366     typename std::iterator_traits<RandomAccessIterator>::difference_type
367       Values = 1 + std::distance(IdxBegin, IdxEnd);
368     return new(Values)
369       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
370   }
371   template<typename RandomAccessIterator>
372   static GetElementPtrInst *Create(Value *Ptr,
373                                    RandomAccessIterator IdxBegin,
374                                    RandomAccessIterator IdxEnd,
375                                    const Twine &NameStr,
376                                    BasicBlock *InsertAtEnd) {
377     typename std::iterator_traits<RandomAccessIterator>::difference_type
378       Values = 1 + std::distance(IdxBegin, IdxEnd);
379     return new(Values)
380       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
381   }
382
383   /// Constructors - These two creators are convenience methods because one
384   /// index getelementptr instructions are so common.
385   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
386                                    const Twine &NameStr = "",
387                                    Instruction *InsertBefore = 0) {
388     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
389   }
390   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
391                                    const Twine &NameStr,
392                                    BasicBlock *InsertAtEnd) {
393     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
394   }
395
396   /// Create an "inbounds" getelementptr. See the documentation for the
397   /// "inbounds" flag in LangRef.html for details.
398   template<typename RandomAccessIterator>
399   static GetElementPtrInst *CreateInBounds(Value *Ptr,
400                                            RandomAccessIterator IdxBegin,
401                                            RandomAccessIterator IdxEnd,
402                                            const Twine &NameStr = "",
403                                            Instruction *InsertBefore = 0) {
404     GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
405                                     NameStr, InsertBefore);
406     GEP->setIsInBounds(true);
407     return GEP;
408   }
409   template<typename RandomAccessIterator>
410   static GetElementPtrInst *CreateInBounds(Value *Ptr,
411                                            RandomAccessIterator IdxBegin,
412                                            RandomAccessIterator IdxEnd,
413                                            const Twine &NameStr,
414                                            BasicBlock *InsertAtEnd) {
415     GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
416                                     NameStr, InsertAtEnd);
417     GEP->setIsInBounds(true);
418     return GEP;
419   }
420   static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
421                                            const Twine &NameStr = "",
422                                            Instruction *InsertBefore = 0) {
423     GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
424     GEP->setIsInBounds(true);
425     return GEP;
426   }
427   static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
428                                            const Twine &NameStr,
429                                            BasicBlock *InsertAtEnd) {
430     GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
431     GEP->setIsInBounds(true);
432     return GEP;
433   }
434
435   /// Transparently provide more efficient getOperand methods.
436   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
437
438   // getType - Overload to return most specific pointer type...
439   const PointerType *getType() const {
440     return reinterpret_cast<const PointerType*>(Instruction::getType());
441   }
442
443   /// getIndexedType - Returns the type of the element that would be loaded with
444   /// a load instruction with the specified parameters.
445   ///
446   /// Null is returned if the indices are invalid for the specified
447   /// pointer type.
448   ///
449   template<typename RandomAccessIterator>
450   static Type *getIndexedType(const Type *Ptr, RandomAccessIterator IdxBegin,
451                               RandomAccessIterator IdxEnd) {
452     return getIndexedType(Ptr, IdxBegin, IdxEnd,
453                           typename std::iterator_traits<RandomAccessIterator>::
454                           iterator_category());
455   }
456
457   // FIXME: Use ArrayRef
458   static Type *getIndexedType(const Type *Ptr,
459                               Value* const *Idx, unsigned NumIdx);
460   static Type *getIndexedType(const Type *Ptr,
461                               Constant* const *Idx, unsigned NumIdx);
462
463   static Type *getIndexedType(const Type *Ptr,
464                               uint64_t const *Idx, unsigned NumIdx);
465   static Type *getIndexedType(const Type *Ptr, Value *Idx);
466
467   inline op_iterator       idx_begin()       { return op_begin()+1; }
468   inline const_op_iterator idx_begin() const { return op_begin()+1; }
469   inline op_iterator       idx_end()         { return op_end(); }
470   inline const_op_iterator idx_end()   const { return op_end(); }
471
472   Value *getPointerOperand() {
473     return getOperand(0);
474   }
475   const Value *getPointerOperand() const {
476     return getOperand(0);
477   }
478   static unsigned getPointerOperandIndex() {
479     return 0U;                      // get index for modifying correct operand
480   }
481
482   unsigned getPointerAddressSpace() const {
483     return cast<PointerType>(getType())->getAddressSpace();
484   }
485
486   /// getPointerOperandType - Method to return the pointer operand as a
487   /// PointerType.
488   const PointerType *getPointerOperandType() const {
489     return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
490   }
491
492
493   unsigned getNumIndices() const {  // Note: always non-negative
494     return getNumOperands() - 1;
495   }
496
497   bool hasIndices() const {
498     return getNumOperands() > 1;
499   }
500
501   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
502   /// zeros.  If so, the result pointer and the first operand have the same
503   /// value, just potentially different types.
504   bool hasAllZeroIndices() const;
505
506   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
507   /// constant integers.  If so, the result pointer and the first operand have
508   /// a constant offset between them.
509   bool hasAllConstantIndices() const;
510
511   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
512   /// See LangRef.html for the meaning of inbounds on a getelementptr.
513   void setIsInBounds(bool b = true);
514
515   /// isInBounds - Determine whether the GEP has the inbounds flag.
516   bool isInBounds() const;
517
518   // Methods for support type inquiry through isa, cast, and dyn_cast:
519   static inline bool classof(const GetElementPtrInst *) { return true; }
520   static inline bool classof(const Instruction *I) {
521     return (I->getOpcode() == Instruction::GetElementPtr);
522   }
523   static inline bool classof(const Value *V) {
524     return isa<Instruction>(V) && classof(cast<Instruction>(V));
525   }
526 };
527
528 template <>
529 struct OperandTraits<GetElementPtrInst> :
530   public VariadicOperandTraits<GetElementPtrInst, 1> {
531 };
532
533 template<typename RandomAccessIterator>
534 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
535                                      RandomAccessIterator IdxBegin,
536                                      RandomAccessIterator IdxEnd,
537                                      unsigned Values,
538                                      const Twine &NameStr,
539                                      Instruction *InsertBefore)
540   : Instruction(PointerType::get(checkGEPType(
541                                    getIndexedType(Ptr->getType(),
542                                                   IdxBegin, IdxEnd)),
543                                  cast<PointerType>(Ptr->getType())
544                                    ->getAddressSpace()),
545                 GetElementPtr,
546                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
547                 Values, InsertBefore) {
548   init(Ptr, IdxBegin, IdxEnd, NameStr,
549        typename std::iterator_traits<RandomAccessIterator>
550        ::iterator_category());
551 }
552 template<typename RandomAccessIterator>
553 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
554                                      RandomAccessIterator IdxBegin,
555                                      RandomAccessIterator IdxEnd,
556                                      unsigned Values,
557                                      const Twine &NameStr,
558                                      BasicBlock *InsertAtEnd)
559   : Instruction(PointerType::get(checkGEPType(
560                                    getIndexedType(Ptr->getType(),
561                                                   IdxBegin, IdxEnd)),
562                                  cast<PointerType>(Ptr->getType())
563                                    ->getAddressSpace()),
564                 GetElementPtr,
565                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
566                 Values, InsertAtEnd) {
567   init(Ptr, IdxBegin, IdxEnd, NameStr,
568        typename std::iterator_traits<RandomAccessIterator>
569        ::iterator_category());
570 }
571
572
573 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
574
575
576 //===----------------------------------------------------------------------===//
577 //                               ICmpInst Class
578 //===----------------------------------------------------------------------===//
579
580 /// This instruction compares its operands according to the predicate given
581 /// to the constructor. It only operates on integers or pointers. The operands
582 /// must be identical types.
583 /// @brief Represent an integer comparison operator.
584 class ICmpInst: public CmpInst {
585 protected:
586   /// @brief Clone an identical ICmpInst
587   virtual ICmpInst *clone_impl() const;
588 public:
589   /// @brief Constructor with insert-before-instruction semantics.
590   ICmpInst(
591     Instruction *InsertBefore,  ///< Where to insert
592     Predicate pred,  ///< The predicate to use for the comparison
593     Value *LHS,      ///< The left-hand-side of the expression
594     Value *RHS,      ///< The right-hand-side of the expression
595     const Twine &NameStr = ""  ///< Name of the instruction
596   ) : CmpInst(makeCmpResultType(LHS->getType()),
597               Instruction::ICmp, pred, LHS, RHS, NameStr,
598               InsertBefore) {
599     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
600            pred <= CmpInst::LAST_ICMP_PREDICATE &&
601            "Invalid ICmp predicate value");
602     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
603           "Both operands to ICmp instruction are not of the same type!");
604     // Check that the operands are the right type
605     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
606             getOperand(0)->getType()->isPointerTy()) &&
607            "Invalid operand types for ICmp instruction");
608   }
609
610   /// @brief Constructor with insert-at-end semantics.
611   ICmpInst(
612     BasicBlock &InsertAtEnd, ///< Block to insert into.
613     Predicate pred,  ///< The predicate to use for the comparison
614     Value *LHS,      ///< The left-hand-side of the expression
615     Value *RHS,      ///< The right-hand-side of the expression
616     const Twine &NameStr = ""  ///< Name of the instruction
617   ) : CmpInst(makeCmpResultType(LHS->getType()),
618               Instruction::ICmp, pred, LHS, RHS, NameStr,
619               &InsertAtEnd) {
620     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
621           pred <= CmpInst::LAST_ICMP_PREDICATE &&
622           "Invalid ICmp predicate value");
623     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
624           "Both operands to ICmp instruction are not of the same type!");
625     // Check that the operands are the right type
626     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
627             getOperand(0)->getType()->isPointerTy()) &&
628            "Invalid operand types for ICmp instruction");
629   }
630
631   /// @brief Constructor with no-insertion semantics
632   ICmpInst(
633     Predicate pred, ///< The predicate to use for the comparison
634     Value *LHS,     ///< The left-hand-side of the expression
635     Value *RHS,     ///< The right-hand-side of the expression
636     const Twine &NameStr = "" ///< Name of the instruction
637   ) : CmpInst(makeCmpResultType(LHS->getType()),
638               Instruction::ICmp, pred, LHS, RHS, NameStr) {
639     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
640            pred <= CmpInst::LAST_ICMP_PREDICATE &&
641            "Invalid ICmp predicate value");
642     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
643           "Both operands to ICmp instruction are not of the same type!");
644     // Check that the operands are the right type
645     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
646             getOperand(0)->getType()->isPointerTy()) &&
647            "Invalid operand types for ICmp instruction");
648   }
649
650   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
651   /// @returns the predicate that would be the result if the operand were
652   /// regarded as signed.
653   /// @brief Return the signed version of the predicate
654   Predicate getSignedPredicate() const {
655     return getSignedPredicate(getPredicate());
656   }
657
658   /// This is a static version that you can use without an instruction.
659   /// @brief Return the signed version of the predicate.
660   static Predicate getSignedPredicate(Predicate pred);
661
662   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
663   /// @returns the predicate that would be the result if the operand were
664   /// regarded as unsigned.
665   /// @brief Return the unsigned version of the predicate
666   Predicate getUnsignedPredicate() const {
667     return getUnsignedPredicate(getPredicate());
668   }
669
670   /// This is a static version that you can use without an instruction.
671   /// @brief Return the unsigned version of the predicate.
672   static Predicate getUnsignedPredicate(Predicate pred);
673
674   /// isEquality - Return true if this predicate is either EQ or NE.  This also
675   /// tests for commutativity.
676   static bool isEquality(Predicate P) {
677     return P == ICMP_EQ || P == ICMP_NE;
678   }
679
680   /// isEquality - Return true if this predicate is either EQ or NE.  This also
681   /// tests for commutativity.
682   bool isEquality() const {
683     return isEquality(getPredicate());
684   }
685
686   /// @returns true if the predicate of this ICmpInst is commutative
687   /// @brief Determine if this relation is commutative.
688   bool isCommutative() const { return isEquality(); }
689
690   /// isRelational - Return true if the predicate is relational (not EQ or NE).
691   ///
692   bool isRelational() const {
693     return !isEquality();
694   }
695
696   /// isRelational - Return true if the predicate is relational (not EQ or NE).
697   ///
698   static bool isRelational(Predicate P) {
699     return !isEquality(P);
700   }
701
702   /// Initialize a set of values that all satisfy the predicate with C.
703   /// @brief Make a ConstantRange for a relation with a constant value.
704   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
705
706   /// Exchange the two operands to this instruction in such a way that it does
707   /// not modify the semantics of the instruction. The predicate value may be
708   /// changed to retain the same result if the predicate is order dependent
709   /// (e.g. ult).
710   /// @brief Swap operands and adjust predicate.
711   void swapOperands() {
712     setPredicate(getSwappedPredicate());
713     Op<0>().swap(Op<1>());
714   }
715
716   // Methods for support type inquiry through isa, cast, and dyn_cast:
717   static inline bool classof(const ICmpInst *) { return true; }
718   static inline bool classof(const Instruction *I) {
719     return I->getOpcode() == Instruction::ICmp;
720   }
721   static inline bool classof(const Value *V) {
722     return isa<Instruction>(V) && classof(cast<Instruction>(V));
723   }
724
725 };
726
727 //===----------------------------------------------------------------------===//
728 //                               FCmpInst Class
729 //===----------------------------------------------------------------------===//
730
731 /// This instruction compares its operands according to the predicate given
732 /// to the constructor. It only operates on floating point values or packed
733 /// vectors of floating point values. The operands must be identical types.
734 /// @brief Represents a floating point comparison operator.
735 class FCmpInst: public CmpInst {
736 protected:
737   /// @brief Clone an identical FCmpInst
738   virtual FCmpInst *clone_impl() const;
739 public:
740   /// @brief Constructor with insert-before-instruction semantics.
741   FCmpInst(
742     Instruction *InsertBefore, ///< Where to insert
743     Predicate pred,  ///< The predicate to use for the comparison
744     Value *LHS,      ///< The left-hand-side of the expression
745     Value *RHS,      ///< The right-hand-side of the expression
746     const Twine &NameStr = ""  ///< Name of the instruction
747   ) : CmpInst(makeCmpResultType(LHS->getType()),
748               Instruction::FCmp, pred, LHS, RHS, NameStr,
749               InsertBefore) {
750     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
751            "Invalid FCmp predicate value");
752     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
753            "Both operands to FCmp instruction are not of the same type!");
754     // Check that the operands are the right type
755     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
756            "Invalid operand types for FCmp instruction");
757   }
758
759   /// @brief Constructor with insert-at-end semantics.
760   FCmpInst(
761     BasicBlock &InsertAtEnd, ///< Block to insert into.
762     Predicate pred,  ///< The predicate to use for the comparison
763     Value *LHS,      ///< The left-hand-side of the expression
764     Value *RHS,      ///< The right-hand-side of the expression
765     const Twine &NameStr = ""  ///< Name of the instruction
766   ) : CmpInst(makeCmpResultType(LHS->getType()),
767               Instruction::FCmp, pred, LHS, RHS, NameStr,
768               &InsertAtEnd) {
769     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
770            "Invalid FCmp predicate value");
771     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
772            "Both operands to FCmp instruction are not of the same type!");
773     // Check that the operands are the right type
774     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
775            "Invalid operand types for FCmp instruction");
776   }
777
778   /// @brief Constructor with no-insertion semantics
779   FCmpInst(
780     Predicate pred, ///< The predicate to use for the comparison
781     Value *LHS,     ///< The left-hand-side of the expression
782     Value *RHS,     ///< The right-hand-side of the expression
783     const Twine &NameStr = "" ///< Name of the instruction
784   ) : CmpInst(makeCmpResultType(LHS->getType()),
785               Instruction::FCmp, pred, LHS, RHS, NameStr) {
786     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
787            "Invalid FCmp predicate value");
788     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
789            "Both operands to FCmp instruction are not of the same type!");
790     // Check that the operands are the right type
791     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
792            "Invalid operand types for FCmp instruction");
793   }
794
795   /// @returns true if the predicate of this instruction is EQ or NE.
796   /// @brief Determine if this is an equality predicate.
797   bool isEquality() const {
798     return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
799            getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
800   }
801
802   /// @returns true if the predicate of this instruction is commutative.
803   /// @brief Determine if this is a commutative predicate.
804   bool isCommutative() const {
805     return isEquality() ||
806            getPredicate() == FCMP_FALSE ||
807            getPredicate() == FCMP_TRUE ||
808            getPredicate() == FCMP_ORD ||
809            getPredicate() == FCMP_UNO;
810   }
811
812   /// @returns true if the predicate is relational (not EQ or NE).
813   /// @brief Determine if this a relational predicate.
814   bool isRelational() const { return !isEquality(); }
815
816   /// Exchange the two operands to this instruction in such a way that it does
817   /// not modify the semantics of the instruction. The predicate value may be
818   /// changed to retain the same result if the predicate is order dependent
819   /// (e.g. ult).
820   /// @brief Swap operands and adjust predicate.
821   void swapOperands() {
822     setPredicate(getSwappedPredicate());
823     Op<0>().swap(Op<1>());
824   }
825
826   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
827   static inline bool classof(const FCmpInst *) { return true; }
828   static inline bool classof(const Instruction *I) {
829     return I->getOpcode() == Instruction::FCmp;
830   }
831   static inline bool classof(const Value *V) {
832     return isa<Instruction>(V) && classof(cast<Instruction>(V));
833   }
834 };
835
836 //===----------------------------------------------------------------------===//
837 /// CallInst - This class represents a function call, abstracting a target
838 /// machine's calling convention.  This class uses low bit of the SubClassData
839 /// field to indicate whether or not this is a tail call.  The rest of the bits
840 /// hold the calling convention of the call.
841 ///
842 class CallInst : public Instruction {
843   AttrListPtr AttributeList; ///< parameter attributes for call
844   CallInst(const CallInst &CI);
845   void init(Value *Func, Value* const *Params, unsigned NumParams);
846   void init(Value *Func, Value *Actual1, Value *Actual2);
847   void init(Value *Func, Value *Actual);
848   void init(Value *Func);
849
850   template<typename RandomAccessIterator>
851   void init(Value *Func,
852             RandomAccessIterator ArgBegin,
853             RandomAccessIterator ArgEnd,
854             const Twine &NameStr,
855             // This argument ensures that we have an iterator we can
856             // do arithmetic on in constant time
857             std::random_access_iterator_tag) {
858     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
859
860     // This requires that the iterator points to contiguous memory.
861     init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
862     setName(NameStr);
863   }
864
865   /// Construct a CallInst given a range of arguments. RandomAccessIterator
866   /// must be a random-access iterator pointing to contiguous storage
867   /// (e.g. a std::vector<>::iterator). Checks are made for
868   /// random-accessness but not for contiguous storage as that would
869   /// incur runtime overhead.
870   /// @brief Construct a CallInst from a range of arguments
871   template<typename RandomAccessIterator>
872   CallInst(Value *Func,
873            RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
874            const Twine &NameStr, Instruction *InsertBefore);
875
876   /// Construct a CallInst given a range of arguments.  RandomAccessIterator
877   /// must be a random-access iterator pointing to contiguous storage
878   /// (e.g. a std::vector<>::iterator).  Checks are made for
879   /// random-accessness but not for contiguous storage as that would
880   /// incur runtime overhead.
881   /// @brief Construct a CallInst from a range of arguments
882   template<typename RandomAccessIterator>
883   inline CallInst(Value *Func,
884                   RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
885                   const Twine &NameStr, BasicBlock *InsertAtEnd);
886
887   CallInst(Value *F, Value *Actual, const Twine &NameStr,
888            Instruction *InsertBefore);
889   CallInst(Value *F, Value *Actual, const Twine &NameStr,
890            BasicBlock *InsertAtEnd);
891   explicit CallInst(Value *F, const Twine &NameStr,
892                     Instruction *InsertBefore);
893   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
894 protected:
895   virtual CallInst *clone_impl() const;
896 public:
897   template<typename RandomAccessIterator>
898   static CallInst *Create(Value *Func,
899                           RandomAccessIterator ArgBegin,
900                           RandomAccessIterator ArgEnd,
901                           const Twine &NameStr = "",
902                           Instruction *InsertBefore = 0) {
903     return new(unsigned(ArgEnd - ArgBegin + 1))
904       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
905   }
906   template<typename RandomAccessIterator>
907   static CallInst *Create(Value *Func,
908                           RandomAccessIterator ArgBegin,
909                           RandomAccessIterator ArgEnd,
910                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
911     return new(unsigned(ArgEnd - ArgBegin + 1))
912       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
913   }
914   static CallInst *Create(Value *F, Value *Actual,
915                           const Twine &NameStr = "",
916                           Instruction *InsertBefore = 0) {
917     return new(2) CallInst(F, Actual, NameStr, InsertBefore);
918   }
919   static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
920                           BasicBlock *InsertAtEnd) {
921     return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
922   }
923   static CallInst *Create(Value *F, const Twine &NameStr = "",
924                           Instruction *InsertBefore = 0) {
925     return new(1) CallInst(F, NameStr, InsertBefore);
926   }
927   static CallInst *Create(Value *F, const Twine &NameStr,
928                           BasicBlock *InsertAtEnd) {
929     return new(1) CallInst(F, NameStr, InsertAtEnd);
930   }
931   /// CreateMalloc - Generate the IR for a call to malloc:
932   /// 1. Compute the malloc call's argument as the specified type's size,
933   ///    possibly multiplied by the array size if the array size is not
934   ///    constant 1.
935   /// 2. Call malloc with that argument.
936   /// 3. Bitcast the result of the malloc call to the specified type.
937   static Instruction *CreateMalloc(Instruction *InsertBefore,
938                                    const Type *IntPtrTy, const Type *AllocTy,
939                                    Value *AllocSize, Value *ArraySize = 0,
940                                    Function* MallocF = 0,
941                                    const Twine &Name = "");
942   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
943                                    const Type *IntPtrTy, const Type *AllocTy,
944                                    Value *AllocSize, Value *ArraySize = 0,
945                                    Function* MallocF = 0,
946                                    const Twine &Name = "");
947   /// CreateFree - Generate the IR for a call to the builtin free function.
948   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
949   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
950
951   ~CallInst();
952
953   bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
954   void setTailCall(bool isTC = true) {
955     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
956                                unsigned(isTC));
957   }
958
959   /// Provide fast operand accessors
960   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
961
962   /// getNumArgOperands - Return the number of call arguments.
963   ///
964   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
965
966   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
967   ///
968   Value *getArgOperand(unsigned i) const { return getOperand(i); }
969   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
970
971   /// getCallingConv/setCallingConv - Get or set the calling convention of this
972   /// function call.
973   CallingConv::ID getCallingConv() const {
974     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
975   }
976   void setCallingConv(CallingConv::ID CC) {
977     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
978                                (static_cast<unsigned>(CC) << 1));
979   }
980
981   /// getAttributes - Return the parameter attributes for this call.
982   ///
983   const AttrListPtr &getAttributes() const { return AttributeList; }
984
985   /// setAttributes - Set the parameter attributes for this call.
986   ///
987   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
988
989   /// addAttribute - adds the attribute to the list of attributes.
990   void addAttribute(unsigned i, Attributes attr);
991
992   /// removeAttribute - removes the attribute from the list of attributes.
993   void removeAttribute(unsigned i, Attributes attr);
994
995   /// @brief Determine whether the call or the callee has the given attribute.
996   bool paramHasAttr(unsigned i, Attributes attr) const;
997
998   /// @brief Extract the alignment for a call or parameter (0=unknown).
999   unsigned getParamAlignment(unsigned i) const {
1000     return AttributeList.getParamAlignment(i);
1001   }
1002
1003   /// @brief Return true if the call should not be inlined.
1004   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1005   void setIsNoInline(bool Value = true) {
1006     if (Value) addAttribute(~0, Attribute::NoInline);
1007     else removeAttribute(~0, Attribute::NoInline);
1008   }
1009
1010   /// @brief Determine if the call does not access memory.
1011   bool doesNotAccessMemory() const {
1012     return paramHasAttr(~0, Attribute::ReadNone);
1013   }
1014   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1015     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1016     else removeAttribute(~0, Attribute::ReadNone);
1017   }
1018
1019   /// @brief Determine if the call does not access or only reads memory.
1020   bool onlyReadsMemory() const {
1021     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1022   }
1023   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1024     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1025     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1026   }
1027
1028   /// @brief Determine if the call cannot return.
1029   bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1030   void setDoesNotReturn(bool DoesNotReturn = true) {
1031     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1032     else removeAttribute(~0, Attribute::NoReturn);
1033   }
1034
1035   /// @brief Determine if the call cannot unwind.
1036   bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1037   void setDoesNotThrow(bool DoesNotThrow = true) {
1038     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1039     else removeAttribute(~0, Attribute::NoUnwind);
1040   }
1041
1042   /// @brief Determine if the call returns a structure through first
1043   /// pointer argument.
1044   bool hasStructRetAttr() const {
1045     // Be friendly and also check the callee.
1046     return paramHasAttr(1, Attribute::StructRet);
1047   }
1048
1049   /// @brief Determine if any call argument is an aggregate passed by value.
1050   bool hasByValArgument() const {
1051     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1052   }
1053
1054   /// getCalledFunction - Return the function called, or null if this is an
1055   /// indirect function invocation.
1056   ///
1057   Function *getCalledFunction() const {
1058     return dyn_cast<Function>(Op<-1>());
1059   }
1060
1061   /// getCalledValue - Get a pointer to the function that is invoked by this
1062   /// instruction.
1063   const Value *getCalledValue() const { return Op<-1>(); }
1064         Value *getCalledValue()       { return Op<-1>(); }
1065
1066   /// setCalledFunction - Set the function called.
1067   void setCalledFunction(Value* Fn) {
1068     Op<-1>() = Fn;
1069   }
1070
1071   /// isInlineAsm - Check if this call is an inline asm statement.
1072   bool isInlineAsm() const {
1073     return isa<InlineAsm>(Op<-1>());
1074   }
1075
1076   // Methods for support type inquiry through isa, cast, and dyn_cast:
1077   static inline bool classof(const CallInst *) { return true; }
1078   static inline bool classof(const Instruction *I) {
1079     return I->getOpcode() == Instruction::Call;
1080   }
1081   static inline bool classof(const Value *V) {
1082     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1083   }
1084 private:
1085   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1086   // method so that subclasses cannot accidentally use it.
1087   void setInstructionSubclassData(unsigned short D) {
1088     Instruction::setInstructionSubclassData(D);
1089   }
1090 };
1091
1092 template <>
1093 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1094 };
1095
1096 template<typename RandomAccessIterator>
1097 CallInst::CallInst(Value *Func,
1098                    RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1099                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1100   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1101                                    ->getElementType())->getReturnType(),
1102                 Instruction::Call,
1103                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1104                 unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1105   init(Func, ArgBegin, ArgEnd, NameStr,
1106        typename std::iterator_traits<RandomAccessIterator>
1107        ::iterator_category());
1108 }
1109
1110 template<typename RandomAccessIterator>
1111 CallInst::CallInst(Value *Func,
1112                    RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1113                    const Twine &NameStr, Instruction *InsertBefore)
1114   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1115                                    ->getElementType())->getReturnType(),
1116                 Instruction::Call,
1117                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1118                 unsigned(ArgEnd - ArgBegin + 1), InsertBefore) {
1119   init(Func, ArgBegin, ArgEnd, NameStr,
1120        typename std::iterator_traits<RandomAccessIterator>
1121        ::iterator_category());
1122 }
1123
1124
1125 // Note: if you get compile errors about private methods then
1126 //       please update your code to use the high-level operand
1127 //       interfaces. See line 943 above.
1128 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1129
1130 //===----------------------------------------------------------------------===//
1131 //                               SelectInst Class
1132 //===----------------------------------------------------------------------===//
1133
1134 /// SelectInst - This class represents the LLVM 'select' instruction.
1135 ///
1136 class SelectInst : public Instruction {
1137   void init(Value *C, Value *S1, Value *S2) {
1138     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1139     Op<0>() = C;
1140     Op<1>() = S1;
1141     Op<2>() = S2;
1142   }
1143
1144   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1145              Instruction *InsertBefore)
1146     : Instruction(S1->getType(), Instruction::Select,
1147                   &Op<0>(), 3, InsertBefore) {
1148     init(C, S1, S2);
1149     setName(NameStr);
1150   }
1151   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1152              BasicBlock *InsertAtEnd)
1153     : Instruction(S1->getType(), Instruction::Select,
1154                   &Op<0>(), 3, InsertAtEnd) {
1155     init(C, S1, S2);
1156     setName(NameStr);
1157   }
1158 protected:
1159   virtual SelectInst *clone_impl() const;
1160 public:
1161   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1162                             const Twine &NameStr = "",
1163                             Instruction *InsertBefore = 0) {
1164     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1165   }
1166   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1167                             const Twine &NameStr,
1168                             BasicBlock *InsertAtEnd) {
1169     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1170   }
1171
1172   const Value *getCondition() const { return Op<0>(); }
1173   const Value *getTrueValue() const { return Op<1>(); }
1174   const Value *getFalseValue() const { return Op<2>(); }
1175   Value *getCondition() { return Op<0>(); }
1176   Value *getTrueValue() { return Op<1>(); }
1177   Value *getFalseValue() { return Op<2>(); }
1178
1179   /// areInvalidOperands - Return a string if the specified operands are invalid
1180   /// for a select operation, otherwise return null.
1181   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1182
1183   /// Transparently provide more efficient getOperand methods.
1184   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1185
1186   OtherOps getOpcode() const {
1187     return static_cast<OtherOps>(Instruction::getOpcode());
1188   }
1189
1190   // Methods for support type inquiry through isa, cast, and dyn_cast:
1191   static inline bool classof(const SelectInst *) { return true; }
1192   static inline bool classof(const Instruction *I) {
1193     return I->getOpcode() == Instruction::Select;
1194   }
1195   static inline bool classof(const Value *V) {
1196     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1197   }
1198 };
1199
1200 template <>
1201 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1202 };
1203
1204 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1205
1206 //===----------------------------------------------------------------------===//
1207 //                                VAArgInst Class
1208 //===----------------------------------------------------------------------===//
1209
1210 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1211 /// an argument of the specified type given a va_list and increments that list
1212 ///
1213 class VAArgInst : public UnaryInstruction {
1214 protected:
1215   virtual VAArgInst *clone_impl() const;
1216
1217 public:
1218   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1219              Instruction *InsertBefore = 0)
1220     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1221     setName(NameStr);
1222   }
1223   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1224             BasicBlock *InsertAtEnd)
1225     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1226     setName(NameStr);
1227   }
1228
1229   Value *getPointerOperand() { return getOperand(0); }
1230   const Value *getPointerOperand() const { return getOperand(0); }
1231   static unsigned getPointerOperandIndex() { return 0U; }
1232
1233   // Methods for support type inquiry through isa, cast, and dyn_cast:
1234   static inline bool classof(const VAArgInst *) { return true; }
1235   static inline bool classof(const Instruction *I) {
1236     return I->getOpcode() == VAArg;
1237   }
1238   static inline bool classof(const Value *V) {
1239     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1240   }
1241 };
1242
1243 //===----------------------------------------------------------------------===//
1244 //                                ExtractElementInst Class
1245 //===----------------------------------------------------------------------===//
1246
1247 /// ExtractElementInst - This instruction extracts a single (scalar)
1248 /// element from a VectorType value
1249 ///
1250 class ExtractElementInst : public Instruction {
1251   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1252                      Instruction *InsertBefore = 0);
1253   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1254                      BasicBlock *InsertAtEnd);
1255 protected:
1256   virtual ExtractElementInst *clone_impl() const;
1257
1258 public:
1259   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1260                                    const Twine &NameStr = "",
1261                                    Instruction *InsertBefore = 0) {
1262     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1263   }
1264   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1265                                    const Twine &NameStr,
1266                                    BasicBlock *InsertAtEnd) {
1267     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1268   }
1269
1270   /// isValidOperands - Return true if an extractelement instruction can be
1271   /// formed with the specified operands.
1272   static bool isValidOperands(const Value *Vec, const Value *Idx);
1273
1274   Value *getVectorOperand() { return Op<0>(); }
1275   Value *getIndexOperand() { return Op<1>(); }
1276   const Value *getVectorOperand() const { return Op<0>(); }
1277   const Value *getIndexOperand() const { return Op<1>(); }
1278
1279   const VectorType *getVectorOperandType() const {
1280     return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1281   }
1282
1283
1284   /// Transparently provide more efficient getOperand methods.
1285   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1286
1287   // Methods for support type inquiry through isa, cast, and dyn_cast:
1288   static inline bool classof(const ExtractElementInst *) { return true; }
1289   static inline bool classof(const Instruction *I) {
1290     return I->getOpcode() == Instruction::ExtractElement;
1291   }
1292   static inline bool classof(const Value *V) {
1293     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1294   }
1295 };
1296
1297 template <>
1298 struct OperandTraits<ExtractElementInst> :
1299   public FixedNumOperandTraits<ExtractElementInst, 2> {
1300 };
1301
1302 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1303
1304 //===----------------------------------------------------------------------===//
1305 //                                InsertElementInst Class
1306 //===----------------------------------------------------------------------===//
1307
1308 /// InsertElementInst - This instruction inserts a single (scalar)
1309 /// element into a VectorType value
1310 ///
1311 class InsertElementInst : public Instruction {
1312   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1313                     const Twine &NameStr = "",
1314                     Instruction *InsertBefore = 0);
1315   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1316                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1317 protected:
1318   virtual InsertElementInst *clone_impl() const;
1319
1320 public:
1321   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1322                                    const Twine &NameStr = "",
1323                                    Instruction *InsertBefore = 0) {
1324     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1325   }
1326   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1327                                    const Twine &NameStr,
1328                                    BasicBlock *InsertAtEnd) {
1329     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1330   }
1331
1332   /// isValidOperands - Return true if an insertelement instruction can be
1333   /// formed with the specified operands.
1334   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1335                               const Value *Idx);
1336
1337   /// getType - Overload to return most specific vector type.
1338   ///
1339   const VectorType *getType() const {
1340     return reinterpret_cast<const VectorType*>(Instruction::getType());
1341   }
1342
1343   /// Transparently provide more efficient getOperand methods.
1344   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1345
1346   // Methods for support type inquiry through isa, cast, and dyn_cast:
1347   static inline bool classof(const InsertElementInst *) { return true; }
1348   static inline bool classof(const Instruction *I) {
1349     return I->getOpcode() == Instruction::InsertElement;
1350   }
1351   static inline bool classof(const Value *V) {
1352     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1353   }
1354 };
1355
1356 template <>
1357 struct OperandTraits<InsertElementInst> :
1358   public FixedNumOperandTraits<InsertElementInst, 3> {
1359 };
1360
1361 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1362
1363 //===----------------------------------------------------------------------===//
1364 //                           ShuffleVectorInst Class
1365 //===----------------------------------------------------------------------===//
1366
1367 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1368 /// input vectors.
1369 ///
1370 class ShuffleVectorInst : public Instruction {
1371 protected:
1372   virtual ShuffleVectorInst *clone_impl() const;
1373
1374 public:
1375   // allocate space for exactly three operands
1376   void *operator new(size_t s) {
1377     return User::operator new(s, 3);
1378   }
1379   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1380                     const Twine &NameStr = "",
1381                     Instruction *InsertBefor = 0);
1382   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1383                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1384
1385   /// isValidOperands - Return true if a shufflevector instruction can be
1386   /// formed with the specified operands.
1387   static bool isValidOperands(const Value *V1, const Value *V2,
1388                               const Value *Mask);
1389
1390   /// getType - Overload to return most specific vector type.
1391   ///
1392   const VectorType *getType() const {
1393     return reinterpret_cast<const VectorType*>(Instruction::getType());
1394   }
1395
1396   /// Transparently provide more efficient getOperand methods.
1397   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1398
1399   /// getMaskValue - Return the index from the shuffle mask for the specified
1400   /// output result.  This is either -1 if the element is undef or a number less
1401   /// than 2*numelements.
1402   int getMaskValue(unsigned i) const;
1403
1404   // Methods for support type inquiry through isa, cast, and dyn_cast:
1405   static inline bool classof(const ShuffleVectorInst *) { return true; }
1406   static inline bool classof(const Instruction *I) {
1407     return I->getOpcode() == Instruction::ShuffleVector;
1408   }
1409   static inline bool classof(const Value *V) {
1410     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1411   }
1412 };
1413
1414 template <>
1415 struct OperandTraits<ShuffleVectorInst> :
1416   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1417 };
1418
1419 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1420
1421 //===----------------------------------------------------------------------===//
1422 //                                ExtractValueInst Class
1423 //===----------------------------------------------------------------------===//
1424
1425 /// ExtractValueInst - This instruction extracts a struct member or array
1426 /// element value from an aggregate value.
1427 ///
1428 class ExtractValueInst : public UnaryInstruction {
1429   SmallVector<unsigned, 4> Indices;
1430
1431   ExtractValueInst(const ExtractValueInst &EVI);
1432   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1433
1434   /// Constructors - Create a extractvalue instruction with a base aggregate
1435   /// value and a list of indices.  The first ctor can optionally insert before
1436   /// an existing instruction, the second appends the new instruction to the
1437   /// specified BasicBlock.
1438   inline ExtractValueInst(Value *Agg,
1439                           ArrayRef<unsigned> Idxs,
1440                           const Twine &NameStr,
1441                           Instruction *InsertBefore);
1442   inline ExtractValueInst(Value *Agg,
1443                           ArrayRef<unsigned> Idxs,
1444                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1445
1446   // allocate space for exactly one operand
1447   void *operator new(size_t s) {
1448     return User::operator new(s, 1);
1449   }
1450 protected:
1451   virtual ExtractValueInst *clone_impl() const;
1452
1453 public:
1454   static ExtractValueInst *Create(Value *Agg,
1455                                   ArrayRef<unsigned> Idxs,
1456                                   const Twine &NameStr = "",
1457                                   Instruction *InsertBefore = 0) {
1458     return new
1459       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1460   }
1461   static ExtractValueInst *Create(Value *Agg,
1462                                   ArrayRef<unsigned> Idxs,
1463                                   const Twine &NameStr,
1464                                   BasicBlock *InsertAtEnd) {
1465     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1466   }
1467
1468   /// getIndexedType - Returns the type of the element that would be extracted
1469   /// with an extractvalue instruction with the specified parameters.
1470   ///
1471   /// Null is returned if the indices are invalid for the specified type.
1472   static Type *getIndexedType(const Type *Agg, ArrayRef<unsigned> Idxs);
1473
1474   typedef const unsigned* idx_iterator;
1475   inline idx_iterator idx_begin() const { return Indices.begin(); }
1476   inline idx_iterator idx_end()   const { return Indices.end(); }
1477
1478   Value *getAggregateOperand() {
1479     return getOperand(0);
1480   }
1481   const Value *getAggregateOperand() const {
1482     return getOperand(0);
1483   }
1484   static unsigned getAggregateOperandIndex() {
1485     return 0U;                      // get index for modifying correct operand
1486   }
1487
1488   ArrayRef<unsigned> getIndices() const {
1489     return Indices;
1490   }
1491
1492   unsigned getNumIndices() const {
1493     return (unsigned)Indices.size();
1494   }
1495
1496   bool hasIndices() const {
1497     return true;
1498   }
1499
1500   // Methods for support type inquiry through isa, cast, and dyn_cast:
1501   static inline bool classof(const ExtractValueInst *) { return true; }
1502   static inline bool classof(const Instruction *I) {
1503     return I->getOpcode() == Instruction::ExtractValue;
1504   }
1505   static inline bool classof(const Value *V) {
1506     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1507   }
1508 };
1509
1510 ExtractValueInst::ExtractValueInst(Value *Agg,
1511                                    ArrayRef<unsigned> Idxs,
1512                                    const Twine &NameStr,
1513                                    Instruction *InsertBefore)
1514   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1515                      ExtractValue, Agg, InsertBefore) {
1516   init(Idxs, NameStr);
1517 }
1518 ExtractValueInst::ExtractValueInst(Value *Agg,
1519                                    ArrayRef<unsigned> Idxs,
1520                                    const Twine &NameStr,
1521                                    BasicBlock *InsertAtEnd)
1522   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1523                      ExtractValue, Agg, InsertAtEnd) {
1524   init(Idxs, NameStr);
1525 }
1526
1527
1528 //===----------------------------------------------------------------------===//
1529 //                                InsertValueInst Class
1530 //===----------------------------------------------------------------------===//
1531
1532 /// InsertValueInst - This instruction inserts a struct field of array element
1533 /// value into an aggregate value.
1534 ///
1535 class InsertValueInst : public Instruction {
1536   SmallVector<unsigned, 4> Indices;
1537
1538   void *operator new(size_t, unsigned); // Do not implement
1539   InsertValueInst(const InsertValueInst &IVI);
1540   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1541             const Twine &NameStr);
1542
1543   /// Constructors - Create a insertvalue instruction with a base aggregate
1544   /// value, a value to insert, and a list of indices.  The first ctor can
1545   /// optionally insert before an existing instruction, the second appends
1546   /// the new instruction to the specified BasicBlock.
1547   inline InsertValueInst(Value *Agg, Value *Val,
1548                          ArrayRef<unsigned> Idxs,
1549                          const Twine &NameStr,
1550                          Instruction *InsertBefore);
1551   inline InsertValueInst(Value *Agg, Value *Val,
1552                          ArrayRef<unsigned> Idxs,
1553                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1554
1555   /// Constructors - These two constructors are convenience methods because one
1556   /// and two index insertvalue instructions are so common.
1557   InsertValueInst(Value *Agg, Value *Val,
1558                   unsigned Idx, const Twine &NameStr = "",
1559                   Instruction *InsertBefore = 0);
1560   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1561                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1562 protected:
1563   virtual InsertValueInst *clone_impl() const;
1564 public:
1565   // allocate space for exactly two operands
1566   void *operator new(size_t s) {
1567     return User::operator new(s, 2);
1568   }
1569
1570   static InsertValueInst *Create(Value *Agg, Value *Val,
1571                                  ArrayRef<unsigned> Idxs,
1572                                  const Twine &NameStr = "",
1573                                  Instruction *InsertBefore = 0) {
1574     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1575   }
1576   static InsertValueInst *Create(Value *Agg, Value *Val,
1577                                  ArrayRef<unsigned> Idxs,
1578                                  const Twine &NameStr,
1579                                  BasicBlock *InsertAtEnd) {
1580     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1581   }
1582
1583   /// Transparently provide more efficient getOperand methods.
1584   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1585
1586   typedef const unsigned* idx_iterator;
1587   inline idx_iterator idx_begin() const { return Indices.begin(); }
1588   inline idx_iterator idx_end()   const { return Indices.end(); }
1589
1590   Value *getAggregateOperand() {
1591     return getOperand(0);
1592   }
1593   const Value *getAggregateOperand() const {
1594     return getOperand(0);
1595   }
1596   static unsigned getAggregateOperandIndex() {
1597     return 0U;                      // get index for modifying correct operand
1598   }
1599
1600   Value *getInsertedValueOperand() {
1601     return getOperand(1);
1602   }
1603   const Value *getInsertedValueOperand() const {
1604     return getOperand(1);
1605   }
1606   static unsigned getInsertedValueOperandIndex() {
1607     return 1U;                      // get index for modifying correct operand
1608   }
1609
1610   ArrayRef<unsigned> getIndices() const {
1611     return Indices;
1612   }
1613
1614   unsigned getNumIndices() const {
1615     return (unsigned)Indices.size();
1616   }
1617
1618   bool hasIndices() const {
1619     return true;
1620   }
1621
1622   // Methods for support type inquiry through isa, cast, and dyn_cast:
1623   static inline bool classof(const InsertValueInst *) { return true; }
1624   static inline bool classof(const Instruction *I) {
1625     return I->getOpcode() == Instruction::InsertValue;
1626   }
1627   static inline bool classof(const Value *V) {
1628     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1629   }
1630 };
1631
1632 template <>
1633 struct OperandTraits<InsertValueInst> :
1634   public FixedNumOperandTraits<InsertValueInst, 2> {
1635 };
1636
1637 InsertValueInst::InsertValueInst(Value *Agg,
1638                                  Value *Val,
1639                                  ArrayRef<unsigned> Idxs,
1640                                  const Twine &NameStr,
1641                                  Instruction *InsertBefore)
1642   : Instruction(Agg->getType(), InsertValue,
1643                 OperandTraits<InsertValueInst>::op_begin(this),
1644                 2, InsertBefore) {
1645   init(Agg, Val, Idxs, NameStr);
1646 }
1647 InsertValueInst::InsertValueInst(Value *Agg,
1648                                  Value *Val,
1649                                  ArrayRef<unsigned> Idxs,
1650                                  const Twine &NameStr,
1651                                  BasicBlock *InsertAtEnd)
1652   : Instruction(Agg->getType(), InsertValue,
1653                 OperandTraits<InsertValueInst>::op_begin(this),
1654                 2, InsertAtEnd) {
1655   init(Agg, Val, Idxs, NameStr);
1656 }
1657
1658 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1659
1660 //===----------------------------------------------------------------------===//
1661 //                               PHINode Class
1662 //===----------------------------------------------------------------------===//
1663
1664 // PHINode - The PHINode class is used to represent the magical mystical PHI
1665 // node, that can not exist in nature, but can be synthesized in a computer
1666 // scientist's overactive imagination.
1667 //
1668 class PHINode : public Instruction {
1669   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1670   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1671   /// the number actually in use.
1672   unsigned ReservedSpace;
1673   PHINode(const PHINode &PN);
1674   // allocate space for exactly zero operands
1675   void *operator new(size_t s) {
1676     return User::operator new(s, 0);
1677   }
1678   explicit PHINode(const Type *Ty, unsigned NumReservedValues,
1679                    const Twine &NameStr = "", Instruction *InsertBefore = 0)
1680     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1681       ReservedSpace(NumReservedValues) {
1682     setName(NameStr);
1683     OperandList = allocHungoffUses(ReservedSpace);
1684   }
1685
1686   PHINode(const Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1687           BasicBlock *InsertAtEnd)
1688     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1689       ReservedSpace(NumReservedValues) {
1690     setName(NameStr);
1691     OperandList = allocHungoffUses(ReservedSpace);
1692   }
1693 protected:
1694   // allocHungoffUses - this is more complicated than the generic
1695   // User::allocHungoffUses, because we have to allocate Uses for the incoming
1696   // values and pointers to the incoming blocks, all in one allocation.
1697   Use *allocHungoffUses(unsigned) const;
1698
1699   virtual PHINode *clone_impl() const;
1700 public:
1701   /// Constructors - NumReservedValues is a hint for the number of incoming
1702   /// edges that this phi node will have (use 0 if you really have no idea).
1703   static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1704                          const Twine &NameStr = "",
1705                          Instruction *InsertBefore = 0) {
1706     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1707   }
1708   static PHINode *Create(const Type *Ty, unsigned NumReservedValues, 
1709                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
1710     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1711   }
1712   ~PHINode();
1713
1714   /// Provide fast operand accessors
1715   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1716
1717   // Block iterator interface. This provides access to the list of incoming
1718   // basic blocks, which parallels the list of incoming values.
1719
1720   typedef BasicBlock **block_iterator;
1721   typedef BasicBlock * const *const_block_iterator;
1722
1723   block_iterator block_begin() {
1724     Use::UserRef *ref =
1725       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1726     return reinterpret_cast<block_iterator>(ref + 1);
1727   }
1728
1729   const_block_iterator block_begin() const {
1730     const Use::UserRef *ref =
1731       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1732     return reinterpret_cast<const_block_iterator>(ref + 1);
1733   }
1734
1735   block_iterator block_end() {
1736     return block_begin() + getNumOperands();
1737   }
1738
1739   const_block_iterator block_end() const {
1740     return block_begin() + getNumOperands();
1741   }
1742
1743   /// getNumIncomingValues - Return the number of incoming edges
1744   ///
1745   unsigned getNumIncomingValues() const { return getNumOperands(); }
1746
1747   /// getIncomingValue - Return incoming value number x
1748   ///
1749   Value *getIncomingValue(unsigned i) const {
1750     return getOperand(i);
1751   }
1752   void setIncomingValue(unsigned i, Value *V) {
1753     setOperand(i, V);
1754   }
1755   static unsigned getOperandNumForIncomingValue(unsigned i) {
1756     return i;
1757   }
1758   static unsigned getIncomingValueNumForOperand(unsigned i) {
1759     return i;
1760   }
1761
1762   /// getIncomingBlock - Return incoming basic block number @p i.
1763   ///
1764   BasicBlock *getIncomingBlock(unsigned i) const {
1765     return block_begin()[i];
1766   }
1767
1768   /// getIncomingBlock - Return incoming basic block corresponding
1769   /// to an operand of the PHI.
1770   ///
1771   BasicBlock *getIncomingBlock(const Use &U) const {
1772     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1773     return getIncomingBlock(unsigned(&U - op_begin()));
1774   }
1775
1776   /// getIncomingBlock - Return incoming basic block corresponding
1777   /// to value use iterator.
1778   ///
1779   template <typename U>
1780   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1781     return getIncomingBlock(I.getUse());
1782   }
1783
1784   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1785     block_begin()[i] = BB;
1786   }
1787
1788   /// addIncoming - Add an incoming value to the end of the PHI list
1789   ///
1790   void addIncoming(Value *V, BasicBlock *BB) {
1791     assert(V && "PHI node got a null value!");
1792     assert(BB && "PHI node got a null basic block!");
1793     assert(getType() == V->getType() &&
1794            "All operands to PHI node must be the same type as the PHI node!");
1795     if (NumOperands == ReservedSpace)
1796       growOperands();  // Get more space!
1797     // Initialize some new operands.
1798     ++NumOperands;
1799     setIncomingValue(NumOperands - 1, V);
1800     setIncomingBlock(NumOperands - 1, BB);
1801   }
1802
1803   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1804   /// predecessor basic block is deleted.  The value removed is returned.
1805   ///
1806   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1807   /// is true), the PHI node is destroyed and any uses of it are replaced with
1808   /// dummy values.  The only time there should be zero incoming values to a PHI
1809   /// node is when the block is dead, so this strategy is sound.
1810   ///
1811   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1812
1813   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1814     int Idx = getBasicBlockIndex(BB);
1815     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1816     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1817   }
1818
1819   /// getBasicBlockIndex - Return the first index of the specified basic
1820   /// block in the value list for this PHI.  Returns -1 if no instance.
1821   ///
1822   int getBasicBlockIndex(const BasicBlock *BB) const {
1823     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
1824       if (block_begin()[i] == BB)
1825         return i;
1826     return -1;
1827   }
1828
1829   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1830     int Idx = getBasicBlockIndex(BB);
1831     assert(Idx >= 0 && "Invalid basic block argument!");
1832     return getIncomingValue(Idx);
1833   }
1834
1835   /// hasConstantValue - If the specified PHI node always merges together the
1836   /// same value, return the value, otherwise return null.
1837   Value *hasConstantValue() const;
1838
1839   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1840   static inline bool classof(const PHINode *) { return true; }
1841   static inline bool classof(const Instruction *I) {
1842     return I->getOpcode() == Instruction::PHI;
1843   }
1844   static inline bool classof(const Value *V) {
1845     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1846   }
1847  private:
1848   void growOperands();
1849 };
1850
1851 template <>
1852 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1853 };
1854
1855 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1856
1857
1858 //===----------------------------------------------------------------------===//
1859 //                               ReturnInst Class
1860 //===----------------------------------------------------------------------===//
1861
1862 //===---------------------------------------------------------------------------
1863 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1864 /// does not continue in this function any longer.
1865 ///
1866 class ReturnInst : public TerminatorInst {
1867   ReturnInst(const ReturnInst &RI);
1868
1869 private:
1870   // ReturnInst constructors:
1871   // ReturnInst()                  - 'ret void' instruction
1872   // ReturnInst(    null)          - 'ret void' instruction
1873   // ReturnInst(Value* X)          - 'ret X'    instruction
1874   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1875   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1876   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1877   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1878   //
1879   // NOTE: If the Value* passed is of type void then the constructor behaves as
1880   // if it was passed NULL.
1881   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1882                       Instruction *InsertBefore = 0);
1883   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1884   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1885 protected:
1886   virtual ReturnInst *clone_impl() const;
1887 public:
1888   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1889                             Instruction *InsertBefore = 0) {
1890     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1891   }
1892   static ReturnInst* Create(LLVMContext &C, Value *retVal,
1893                             BasicBlock *InsertAtEnd) {
1894     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1895   }
1896   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1897     return new(0) ReturnInst(C, InsertAtEnd);
1898   }
1899   virtual ~ReturnInst();
1900
1901   /// Provide fast operand accessors
1902   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1903
1904   /// Convenience accessor. Returns null if there is no return value.
1905   Value *getReturnValue() const {
1906     return getNumOperands() != 0 ? getOperand(0) : 0;
1907   }
1908
1909   unsigned getNumSuccessors() const { return 0; }
1910
1911   // Methods for support type inquiry through isa, cast, and dyn_cast:
1912   static inline bool classof(const ReturnInst *) { return true; }
1913   static inline bool classof(const Instruction *I) {
1914     return (I->getOpcode() == Instruction::Ret);
1915   }
1916   static inline bool classof(const Value *V) {
1917     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1918   }
1919  private:
1920   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1921   virtual unsigned getNumSuccessorsV() const;
1922   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1923 };
1924
1925 template <>
1926 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1927 };
1928
1929 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1930
1931 //===----------------------------------------------------------------------===//
1932 //                               BranchInst Class
1933 //===----------------------------------------------------------------------===//
1934
1935 //===---------------------------------------------------------------------------
1936 /// BranchInst - Conditional or Unconditional Branch instruction.
1937 ///
1938 class BranchInst : public TerminatorInst {
1939   /// Ops list - Branches are strange.  The operands are ordered:
1940   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
1941   /// they don't have to check for cond/uncond branchness. These are mostly
1942   /// accessed relative from op_end().
1943   BranchInst(const BranchInst &BI);
1944   void AssertOK();
1945   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1946   // BranchInst(BB *B)                           - 'br B'
1947   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1948   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1949   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1950   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1951   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1952   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1953   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1954              Instruction *InsertBefore = 0);
1955   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1956   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1957              BasicBlock *InsertAtEnd);
1958 protected:
1959   virtual BranchInst *clone_impl() const;
1960 public:
1961   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1962     return new(1) BranchInst(IfTrue, InsertBefore);
1963   }
1964   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1965                             Value *Cond, Instruction *InsertBefore = 0) {
1966     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1967   }
1968   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1969     return new(1) BranchInst(IfTrue, InsertAtEnd);
1970   }
1971   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1972                             Value *Cond, BasicBlock *InsertAtEnd) {
1973     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1974   }
1975
1976   /// Transparently provide more efficient getOperand methods.
1977   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1978
1979   bool isUnconditional() const { return getNumOperands() == 1; }
1980   bool isConditional()   const { return getNumOperands() == 3; }
1981
1982   Value *getCondition() const {
1983     assert(isConditional() && "Cannot get condition of an uncond branch!");
1984     return Op<-3>();
1985   }
1986
1987   void setCondition(Value *V) {
1988     assert(isConditional() && "Cannot set condition of unconditional branch!");
1989     Op<-3>() = V;
1990   }
1991
1992   unsigned getNumSuccessors() const { return 1+isConditional(); }
1993
1994   BasicBlock *getSuccessor(unsigned i) const {
1995     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1996     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
1997   }
1998
1999   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2000     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2001     *(&Op<-1>() - idx) = (Value*)NewSucc;
2002   }
2003
2004   // Methods for support type inquiry through isa, cast, and dyn_cast:
2005   static inline bool classof(const BranchInst *) { return true; }
2006   static inline bool classof(const Instruction *I) {
2007     return (I->getOpcode() == Instruction::Br);
2008   }
2009   static inline bool classof(const Value *V) {
2010     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2011   }
2012 private:
2013   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2014   virtual unsigned getNumSuccessorsV() const;
2015   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2016 };
2017
2018 template <>
2019 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2020 };
2021
2022 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2023
2024 //===----------------------------------------------------------------------===//
2025 //                               SwitchInst Class
2026 //===----------------------------------------------------------------------===//
2027
2028 //===---------------------------------------------------------------------------
2029 /// SwitchInst - Multiway switch
2030 ///
2031 class SwitchInst : public TerminatorInst {
2032   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2033   unsigned ReservedSpace;
2034   // Operand[0]    = Value to switch on
2035   // Operand[1]    = Default basic block destination
2036   // Operand[2n  ] = Value to match
2037   // Operand[2n+1] = BasicBlock to go to on match
2038   SwitchInst(const SwitchInst &SI);
2039   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2040   void growOperands();
2041   // allocate space for exactly zero operands
2042   void *operator new(size_t s) {
2043     return User::operator new(s, 0);
2044   }
2045   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2046   /// switch on and a default destination.  The number of additional cases can
2047   /// be specified here to make memory allocation more efficient.  This
2048   /// constructor can also autoinsert before another instruction.
2049   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2050              Instruction *InsertBefore);
2051
2052   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2053   /// switch on and a default destination.  The number of additional cases can
2054   /// be specified here to make memory allocation more efficient.  This
2055   /// constructor also autoinserts at the end of the specified BasicBlock.
2056   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2057              BasicBlock *InsertAtEnd);
2058 protected:
2059   virtual SwitchInst *clone_impl() const;
2060 public:
2061   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2062                             unsigned NumCases, Instruction *InsertBefore = 0) {
2063     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2064   }
2065   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2066                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2067     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2068   }
2069   ~SwitchInst();
2070
2071   /// Provide fast operand accessors
2072   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2073
2074   // Accessor Methods for Switch stmt
2075   Value *getCondition() const { return getOperand(0); }
2076   void setCondition(Value *V) { setOperand(0, V); }
2077
2078   BasicBlock *getDefaultDest() const {
2079     return cast<BasicBlock>(getOperand(1));
2080   }
2081
2082   /// getNumCases - return the number of 'cases' in this switch instruction.
2083   /// Note that case #0 is always the default case.
2084   unsigned getNumCases() const {
2085     return getNumOperands()/2;
2086   }
2087
2088   /// getCaseValue - Return the specified case value.  Note that case #0, the
2089   /// default destination, does not have a case value.
2090   ConstantInt *getCaseValue(unsigned i) {
2091     assert(i && i < getNumCases() && "Illegal case value to get!");
2092     return getSuccessorValue(i);
2093   }
2094
2095   /// getCaseValue - Return the specified case value.  Note that case #0, the
2096   /// default destination, does not have a case value.
2097   const ConstantInt *getCaseValue(unsigned i) const {
2098     assert(i && i < getNumCases() && "Illegal case value to get!");
2099     return getSuccessorValue(i);
2100   }
2101
2102   /// findCaseValue - Search all of the case values for the specified constant.
2103   /// If it is explicitly handled, return the case number of it, otherwise
2104   /// return 0 to indicate that it is handled by the default handler.
2105   unsigned findCaseValue(const ConstantInt *C) const {
2106     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2107       if (getCaseValue(i) == C)
2108         return i;
2109     return 0;
2110   }
2111
2112   /// findCaseDest - Finds the unique case value for a given successor. Returns
2113   /// null if the successor is not found, not unique, or is the default case.
2114   ConstantInt *findCaseDest(BasicBlock *BB) {
2115     if (BB == getDefaultDest()) return NULL;
2116
2117     ConstantInt *CI = NULL;
2118     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2119       if (getSuccessor(i) == BB) {
2120         if (CI) return NULL;   // Multiple cases lead to BB.
2121         else CI = getCaseValue(i);
2122       }
2123     }
2124     return CI;
2125   }
2126
2127   /// addCase - Add an entry to the switch instruction...
2128   ///
2129   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2130
2131   /// removeCase - This method removes the specified successor from the switch
2132   /// instruction.  Note that this cannot be used to remove the default
2133   /// destination (successor #0). Also note that this operation may reorder the
2134   /// remaining cases at index idx and above.
2135   ///
2136   void removeCase(unsigned idx);
2137
2138   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2139   BasicBlock *getSuccessor(unsigned idx) const {
2140     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2141     return cast<BasicBlock>(getOperand(idx*2+1));
2142   }
2143   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2144     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2145     setOperand(idx*2+1, (Value*)NewSucc);
2146   }
2147
2148   // getSuccessorValue - Return the value associated with the specified
2149   // successor.
2150   ConstantInt *getSuccessorValue(unsigned idx) const {
2151     assert(idx < getNumSuccessors() && "Successor # out of range!");
2152     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2153   }
2154
2155   // Methods for support type inquiry through isa, cast, and dyn_cast:
2156   static inline bool classof(const SwitchInst *) { return true; }
2157   static inline bool classof(const Instruction *I) {
2158     return I->getOpcode() == Instruction::Switch;
2159   }
2160   static inline bool classof(const Value *V) {
2161     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2162   }
2163 private:
2164   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2165   virtual unsigned getNumSuccessorsV() const;
2166   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2167 };
2168
2169 template <>
2170 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2171 };
2172
2173 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2174
2175
2176 //===----------------------------------------------------------------------===//
2177 //                             IndirectBrInst Class
2178 //===----------------------------------------------------------------------===//
2179
2180 //===---------------------------------------------------------------------------
2181 /// IndirectBrInst - Indirect Branch Instruction.
2182 ///
2183 class IndirectBrInst : public TerminatorInst {
2184   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2185   unsigned ReservedSpace;
2186   // Operand[0]    = Value to switch on
2187   // Operand[1]    = Default basic block destination
2188   // Operand[2n  ] = Value to match
2189   // Operand[2n+1] = BasicBlock to go to on match
2190   IndirectBrInst(const IndirectBrInst &IBI);
2191   void init(Value *Address, unsigned NumDests);
2192   void growOperands();
2193   // allocate space for exactly zero operands
2194   void *operator new(size_t s) {
2195     return User::operator new(s, 0);
2196   }
2197   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2198   /// Address to jump to.  The number of expected destinations can be specified
2199   /// here to make memory allocation more efficient.  This constructor can also
2200   /// autoinsert before another instruction.
2201   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2202
2203   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2204   /// Address to jump to.  The number of expected destinations can be specified
2205   /// here to make memory allocation more efficient.  This constructor also
2206   /// autoinserts at the end of the specified BasicBlock.
2207   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2208 protected:
2209   virtual IndirectBrInst *clone_impl() const;
2210 public:
2211   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2212                                 Instruction *InsertBefore = 0) {
2213     return new IndirectBrInst(Address, NumDests, InsertBefore);
2214   }
2215   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2216                                 BasicBlock *InsertAtEnd) {
2217     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2218   }
2219   ~IndirectBrInst();
2220
2221   /// Provide fast operand accessors.
2222   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2223
2224   // Accessor Methods for IndirectBrInst instruction.
2225   Value *getAddress() { return getOperand(0); }
2226   const Value *getAddress() const { return getOperand(0); }
2227   void setAddress(Value *V) { setOperand(0, V); }
2228
2229
2230   /// getNumDestinations - return the number of possible destinations in this
2231   /// indirectbr instruction.
2232   unsigned getNumDestinations() const { return getNumOperands()-1; }
2233
2234   /// getDestination - Return the specified destination.
2235   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2236   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2237
2238   /// addDestination - Add a destination.
2239   ///
2240   void addDestination(BasicBlock *Dest);
2241
2242   /// removeDestination - This method removes the specified successor from the
2243   /// indirectbr instruction.
2244   void removeDestination(unsigned i);
2245
2246   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2247   BasicBlock *getSuccessor(unsigned i) const {
2248     return cast<BasicBlock>(getOperand(i+1));
2249   }
2250   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2251     setOperand(i+1, (Value*)NewSucc);
2252   }
2253
2254   // Methods for support type inquiry through isa, cast, and dyn_cast:
2255   static inline bool classof(const IndirectBrInst *) { return true; }
2256   static inline bool classof(const Instruction *I) {
2257     return I->getOpcode() == Instruction::IndirectBr;
2258   }
2259   static inline bool classof(const Value *V) {
2260     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2261   }
2262 private:
2263   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2264   virtual unsigned getNumSuccessorsV() const;
2265   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2266 };
2267
2268 template <>
2269 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2270 };
2271
2272 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2273
2274
2275 //===----------------------------------------------------------------------===//
2276 //                               InvokeInst Class
2277 //===----------------------------------------------------------------------===//
2278
2279 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2280 /// calling convention of the call.
2281 ///
2282 class InvokeInst : public TerminatorInst {
2283   AttrListPtr AttributeList;
2284   InvokeInst(const InvokeInst &BI);
2285   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2286             Value* const *Args, unsigned NumArgs);
2287
2288   template<typename RandomAccessIterator>
2289   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2290             RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2291             const Twine &NameStr,
2292             // This argument ensures that we have an iterator we can
2293             // do arithmetic on in constant time
2294             std::random_access_iterator_tag) {
2295     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2296
2297     // This requires that the iterator points to contiguous memory.
2298     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2299     setName(NameStr);
2300   }
2301
2302   /// Construct an InvokeInst given a range of arguments.
2303   /// RandomAccessIterator must be a random-access iterator pointing to
2304   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2305   /// made for random-accessness but not for contiguous storage as
2306   /// that would incur runtime overhead.
2307   ///
2308   /// @brief Construct an InvokeInst from a range of arguments
2309   template<typename RandomAccessIterator>
2310   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2311                     RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2312                     unsigned Values,
2313                     const Twine &NameStr, Instruction *InsertBefore);
2314
2315   /// Construct an InvokeInst given a range of arguments.
2316   /// RandomAccessIterator must be a random-access iterator pointing to
2317   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2318   /// made for random-accessness but not for contiguous storage as
2319   /// that would incur runtime overhead.
2320   ///
2321   /// @brief Construct an InvokeInst from a range of arguments
2322   template<typename RandomAccessIterator>
2323   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2324                     RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2325                     unsigned Values,
2326                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2327 protected:
2328   virtual InvokeInst *clone_impl() const;
2329 public:
2330   template<typename RandomAccessIterator>
2331   static InvokeInst *Create(Value *Func,
2332                             BasicBlock *IfNormal, BasicBlock *IfException,
2333                             RandomAccessIterator ArgBegin,
2334                             RandomAccessIterator ArgEnd,
2335                             const Twine &NameStr = "",
2336                             Instruction *InsertBefore = 0) {
2337     unsigned Values(ArgEnd - ArgBegin + 3);
2338     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2339                                   Values, NameStr, InsertBefore);
2340   }
2341   template<typename RandomAccessIterator>
2342   static InvokeInst *Create(Value *Func,
2343                             BasicBlock *IfNormal, BasicBlock *IfException,
2344                             RandomAccessIterator ArgBegin,
2345                             RandomAccessIterator ArgEnd,
2346                             const Twine &NameStr,
2347                             BasicBlock *InsertAtEnd) {
2348     unsigned Values(ArgEnd - ArgBegin + 3);
2349     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2350                                   Values, NameStr, InsertAtEnd);
2351   }
2352
2353   /// Provide fast operand accessors
2354   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2355
2356   /// getNumArgOperands - Return the number of invoke arguments.
2357   ///
2358   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2359
2360   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2361   ///
2362   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2363   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2364
2365   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2366   /// function call.
2367   CallingConv::ID getCallingConv() const {
2368     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2369   }
2370   void setCallingConv(CallingConv::ID CC) {
2371     setInstructionSubclassData(static_cast<unsigned>(CC));
2372   }
2373
2374   /// getAttributes - Return the parameter attributes for this invoke.
2375   ///
2376   const AttrListPtr &getAttributes() const { return AttributeList; }
2377
2378   /// setAttributes - Set the parameter attributes for this invoke.
2379   ///
2380   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2381
2382   /// addAttribute - adds the attribute to the list of attributes.
2383   void addAttribute(unsigned i, Attributes attr);
2384
2385   /// removeAttribute - removes the attribute from the list of attributes.
2386   void removeAttribute(unsigned i, Attributes attr);
2387
2388   /// @brief Determine whether the call or the callee has the given attribute.
2389   bool paramHasAttr(unsigned i, Attributes attr) const;
2390
2391   /// @brief Extract the alignment for a call or parameter (0=unknown).
2392   unsigned getParamAlignment(unsigned i) const {
2393     return AttributeList.getParamAlignment(i);
2394   }
2395
2396   /// @brief Return true if the call should not be inlined.
2397   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2398   void setIsNoInline(bool Value = true) {
2399     if (Value) addAttribute(~0, Attribute::NoInline);
2400     else removeAttribute(~0, Attribute::NoInline);
2401   }
2402
2403   /// @brief Determine if the call does not access memory.
2404   bool doesNotAccessMemory() const {
2405     return paramHasAttr(~0, Attribute::ReadNone);
2406   }
2407   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2408     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2409     else removeAttribute(~0, Attribute::ReadNone);
2410   }
2411
2412   /// @brief Determine if the call does not access or only reads memory.
2413   bool onlyReadsMemory() const {
2414     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2415   }
2416   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2417     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2418     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2419   }
2420
2421   /// @brief Determine if the call cannot return.
2422   bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2423   void setDoesNotReturn(bool DoesNotReturn = true) {
2424     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2425     else removeAttribute(~0, Attribute::NoReturn);
2426   }
2427
2428   /// @brief Determine if the call cannot unwind.
2429   bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2430   void setDoesNotThrow(bool DoesNotThrow = true) {
2431     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2432     else removeAttribute(~0, Attribute::NoUnwind);
2433   }
2434
2435   /// @brief Determine if the call returns a structure through first
2436   /// pointer argument.
2437   bool hasStructRetAttr() const {
2438     // Be friendly and also check the callee.
2439     return paramHasAttr(1, Attribute::StructRet);
2440   }
2441
2442   /// @brief Determine if any call argument is an aggregate passed by value.
2443   bool hasByValArgument() const {
2444     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2445   }
2446
2447   /// getCalledFunction - Return the function called, or null if this is an
2448   /// indirect function invocation.
2449   ///
2450   Function *getCalledFunction() const {
2451     return dyn_cast<Function>(Op<-3>());
2452   }
2453
2454   /// getCalledValue - Get a pointer to the function that is invoked by this
2455   /// instruction
2456   const Value *getCalledValue() const { return Op<-3>(); }
2457         Value *getCalledValue()       { return Op<-3>(); }
2458
2459   /// setCalledFunction - Set the function called.
2460   void setCalledFunction(Value* Fn) {
2461     Op<-3>() = Fn;
2462   }
2463
2464   // get*Dest - Return the destination basic blocks...
2465   BasicBlock *getNormalDest() const {
2466     return cast<BasicBlock>(Op<-2>());
2467   }
2468   BasicBlock *getUnwindDest() const {
2469     return cast<BasicBlock>(Op<-1>());
2470   }
2471   void setNormalDest(BasicBlock *B) {
2472     Op<-2>() = reinterpret_cast<Value*>(B);
2473   }
2474   void setUnwindDest(BasicBlock *B) {
2475     Op<-1>() = reinterpret_cast<Value*>(B);
2476   }
2477
2478   BasicBlock *getSuccessor(unsigned i) const {
2479     assert(i < 2 && "Successor # out of range for invoke!");
2480     return i == 0 ? getNormalDest() : getUnwindDest();
2481   }
2482
2483   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2484     assert(idx < 2 && "Successor # out of range for invoke!");
2485     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2486   }
2487
2488   unsigned getNumSuccessors() const { return 2; }
2489
2490   // Methods for support type inquiry through isa, cast, and dyn_cast:
2491   static inline bool classof(const InvokeInst *) { return true; }
2492   static inline bool classof(const Instruction *I) {
2493     return (I->getOpcode() == Instruction::Invoke);
2494   }
2495   static inline bool classof(const Value *V) {
2496     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2497   }
2498
2499 private:
2500   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2501   virtual unsigned getNumSuccessorsV() const;
2502   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2503
2504   // Shadow Instruction::setInstructionSubclassData with a private forwarding
2505   // method so that subclasses cannot accidentally use it.
2506   void setInstructionSubclassData(unsigned short D) {
2507     Instruction::setInstructionSubclassData(D);
2508   }
2509 };
2510
2511 template <>
2512 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2513 };
2514
2515 template<typename RandomAccessIterator>
2516 InvokeInst::InvokeInst(Value *Func,
2517                        BasicBlock *IfNormal, BasicBlock *IfException,
2518                        RandomAccessIterator ArgBegin,
2519                        RandomAccessIterator ArgEnd,
2520                        unsigned Values,
2521                        const Twine &NameStr, Instruction *InsertBefore)
2522   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2523                                       ->getElementType())->getReturnType(),
2524                    Instruction::Invoke,
2525                    OperandTraits<InvokeInst>::op_end(this) - Values,
2526                    Values, InsertBefore) {
2527   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2528        typename std::iterator_traits<RandomAccessIterator>
2529        ::iterator_category());
2530 }
2531 template<typename RandomAccessIterator>
2532 InvokeInst::InvokeInst(Value *Func,
2533                        BasicBlock *IfNormal, BasicBlock *IfException,
2534                        RandomAccessIterator ArgBegin,
2535                        RandomAccessIterator ArgEnd,
2536                        unsigned Values,
2537                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2538   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2539                                       ->getElementType())->getReturnType(),
2540                    Instruction::Invoke,
2541                    OperandTraits<InvokeInst>::op_end(this) - Values,
2542                    Values, InsertAtEnd) {
2543   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2544        typename std::iterator_traits<RandomAccessIterator>
2545        ::iterator_category());
2546 }
2547
2548 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2549
2550 //===----------------------------------------------------------------------===//
2551 //                              UnwindInst Class
2552 //===----------------------------------------------------------------------===//
2553
2554 //===---------------------------------------------------------------------------
2555 /// UnwindInst - Immediately exit the current function, unwinding the stack
2556 /// until an invoke instruction is found.
2557 ///
2558 class UnwindInst : public TerminatorInst {
2559   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2560 protected:
2561   virtual UnwindInst *clone_impl() const;
2562 public:
2563   // allocate space for exactly zero operands
2564   void *operator new(size_t s) {
2565     return User::operator new(s, 0);
2566   }
2567   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2568   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2569
2570   unsigned getNumSuccessors() const { return 0; }
2571
2572   // Methods for support type inquiry through isa, cast, and dyn_cast:
2573   static inline bool classof(const UnwindInst *) { return true; }
2574   static inline bool classof(const Instruction *I) {
2575     return I->getOpcode() == Instruction::Unwind;
2576   }
2577   static inline bool classof(const Value *V) {
2578     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2579   }
2580 private:
2581   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2582   virtual unsigned getNumSuccessorsV() const;
2583   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2584 };
2585
2586 //===----------------------------------------------------------------------===//
2587 //                           UnreachableInst Class
2588 //===----------------------------------------------------------------------===//
2589
2590 //===---------------------------------------------------------------------------
2591 /// UnreachableInst - This function has undefined behavior.  In particular, the
2592 /// presence of this instruction indicates some higher level knowledge that the
2593 /// end of the block cannot be reached.
2594 ///
2595 class UnreachableInst : public TerminatorInst {
2596   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2597 protected:
2598   virtual UnreachableInst *clone_impl() const;
2599
2600 public:
2601   // allocate space for exactly zero operands
2602   void *operator new(size_t s) {
2603     return User::operator new(s, 0);
2604   }
2605   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2606   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2607
2608   unsigned getNumSuccessors() const { return 0; }
2609
2610   // Methods for support type inquiry through isa, cast, and dyn_cast:
2611   static inline bool classof(const UnreachableInst *) { return true; }
2612   static inline bool classof(const Instruction *I) {
2613     return I->getOpcode() == Instruction::Unreachable;
2614   }
2615   static inline bool classof(const Value *V) {
2616     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2617   }
2618 private:
2619   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2620   virtual unsigned getNumSuccessorsV() const;
2621   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2622 };
2623
2624 //===----------------------------------------------------------------------===//
2625 //                                 TruncInst Class
2626 //===----------------------------------------------------------------------===//
2627
2628 /// @brief This class represents a truncation of integer types.
2629 class TruncInst : public CastInst {
2630 protected:
2631   /// @brief Clone an identical TruncInst
2632   virtual TruncInst *clone_impl() const;
2633
2634 public:
2635   /// @brief Constructor with insert-before-instruction semantics
2636   TruncInst(
2637     Value *S,                     ///< The value to be truncated
2638     const Type *Ty,               ///< The (smaller) type to truncate to
2639     const Twine &NameStr = "",    ///< A name for the new instruction
2640     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2641   );
2642
2643   /// @brief Constructor with insert-at-end-of-block semantics
2644   TruncInst(
2645     Value *S,                     ///< The value to be truncated
2646     const Type *Ty,               ///< The (smaller) type to truncate to
2647     const Twine &NameStr,         ///< A name for the new instruction
2648     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2649   );
2650
2651   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2652   static inline bool classof(const TruncInst *) { return true; }
2653   static inline bool classof(const Instruction *I) {
2654     return I->getOpcode() == Trunc;
2655   }
2656   static inline bool classof(const Value *V) {
2657     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2658   }
2659 };
2660
2661 //===----------------------------------------------------------------------===//
2662 //                                 ZExtInst Class
2663 //===----------------------------------------------------------------------===//
2664
2665 /// @brief This class represents zero extension of integer types.
2666 class ZExtInst : public CastInst {
2667 protected:
2668   /// @brief Clone an identical ZExtInst
2669   virtual ZExtInst *clone_impl() const;
2670
2671 public:
2672   /// @brief Constructor with insert-before-instruction semantics
2673   ZExtInst(
2674     Value *S,                     ///< The value to be zero extended
2675     const Type *Ty,               ///< The type to zero extend to
2676     const Twine &NameStr = "",    ///< A name for the new instruction
2677     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2678   );
2679
2680   /// @brief Constructor with insert-at-end semantics.
2681   ZExtInst(
2682     Value *S,                     ///< The value to be zero extended
2683     const Type *Ty,               ///< The type to zero extend to
2684     const Twine &NameStr,         ///< A name for the new instruction
2685     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2686   );
2687
2688   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2689   static inline bool classof(const ZExtInst *) { return true; }
2690   static inline bool classof(const Instruction *I) {
2691     return I->getOpcode() == ZExt;
2692   }
2693   static inline bool classof(const Value *V) {
2694     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2695   }
2696 };
2697
2698 //===----------------------------------------------------------------------===//
2699 //                                 SExtInst Class
2700 //===----------------------------------------------------------------------===//
2701
2702 /// @brief This class represents a sign extension of integer types.
2703 class SExtInst : public CastInst {
2704 protected:
2705   /// @brief Clone an identical SExtInst
2706   virtual SExtInst *clone_impl() const;
2707
2708 public:
2709   /// @brief Constructor with insert-before-instruction semantics
2710   SExtInst(
2711     Value *S,                     ///< The value to be sign extended
2712     const Type *Ty,               ///< The type to sign extend to
2713     const Twine &NameStr = "",    ///< A name for the new instruction
2714     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2715   );
2716
2717   /// @brief Constructor with insert-at-end-of-block semantics
2718   SExtInst(
2719     Value *S,                     ///< The value to be sign extended
2720     const Type *Ty,               ///< The type to sign extend to
2721     const Twine &NameStr,         ///< A name for the new instruction
2722     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2723   );
2724
2725   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2726   static inline bool classof(const SExtInst *) { return true; }
2727   static inline bool classof(const Instruction *I) {
2728     return I->getOpcode() == SExt;
2729   }
2730   static inline bool classof(const Value *V) {
2731     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2732   }
2733 };
2734
2735 //===----------------------------------------------------------------------===//
2736 //                                 FPTruncInst Class
2737 //===----------------------------------------------------------------------===//
2738
2739 /// @brief This class represents a truncation of floating point types.
2740 class FPTruncInst : public CastInst {
2741 protected:
2742   /// @brief Clone an identical FPTruncInst
2743   virtual FPTruncInst *clone_impl() const;
2744
2745 public:
2746   /// @brief Constructor with insert-before-instruction semantics
2747   FPTruncInst(
2748     Value *S,                     ///< The value to be truncated
2749     const Type *Ty,               ///< The type to truncate to
2750     const Twine &NameStr = "",    ///< A name for the new instruction
2751     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2752   );
2753
2754   /// @brief Constructor with insert-before-instruction semantics
2755   FPTruncInst(
2756     Value *S,                     ///< The value to be truncated
2757     const Type *Ty,               ///< The type to truncate to
2758     const Twine &NameStr,         ///< A name for the new instruction
2759     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2760   );
2761
2762   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2763   static inline bool classof(const FPTruncInst *) { return true; }
2764   static inline bool classof(const Instruction *I) {
2765     return I->getOpcode() == FPTrunc;
2766   }
2767   static inline bool classof(const Value *V) {
2768     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2769   }
2770 };
2771
2772 //===----------------------------------------------------------------------===//
2773 //                                 FPExtInst Class
2774 //===----------------------------------------------------------------------===//
2775
2776 /// @brief This class represents an extension of floating point types.
2777 class FPExtInst : public CastInst {
2778 protected:
2779   /// @brief Clone an identical FPExtInst
2780   virtual FPExtInst *clone_impl() const;
2781
2782 public:
2783   /// @brief Constructor with insert-before-instruction semantics
2784   FPExtInst(
2785     Value *S,                     ///< The value to be extended
2786     const Type *Ty,               ///< The type to extend to
2787     const Twine &NameStr = "",    ///< A name for the new instruction
2788     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2789   );
2790
2791   /// @brief Constructor with insert-at-end-of-block semantics
2792   FPExtInst(
2793     Value *S,                     ///< The value to be extended
2794     const Type *Ty,               ///< The type to extend to
2795     const Twine &NameStr,         ///< A name for the new instruction
2796     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2797   );
2798
2799   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2800   static inline bool classof(const FPExtInst *) { return true; }
2801   static inline bool classof(const Instruction *I) {
2802     return I->getOpcode() == FPExt;
2803   }
2804   static inline bool classof(const Value *V) {
2805     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2806   }
2807 };
2808
2809 //===----------------------------------------------------------------------===//
2810 //                                 UIToFPInst Class
2811 //===----------------------------------------------------------------------===//
2812
2813 /// @brief This class represents a cast unsigned integer to floating point.
2814 class UIToFPInst : public CastInst {
2815 protected:
2816   /// @brief Clone an identical UIToFPInst
2817   virtual UIToFPInst *clone_impl() const;
2818
2819 public:
2820   /// @brief Constructor with insert-before-instruction semantics
2821   UIToFPInst(
2822     Value *S,                     ///< The value to be converted
2823     const Type *Ty,               ///< The type to convert to
2824     const Twine &NameStr = "",    ///< A name for the new instruction
2825     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2826   );
2827
2828   /// @brief Constructor with insert-at-end-of-block semantics
2829   UIToFPInst(
2830     Value *S,                     ///< The value to be converted
2831     const Type *Ty,               ///< The type to convert to
2832     const Twine &NameStr,         ///< A name for the new instruction
2833     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2834   );
2835
2836   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2837   static inline bool classof(const UIToFPInst *) { return true; }
2838   static inline bool classof(const Instruction *I) {
2839     return I->getOpcode() == UIToFP;
2840   }
2841   static inline bool classof(const Value *V) {
2842     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2843   }
2844 };
2845
2846 //===----------------------------------------------------------------------===//
2847 //                                 SIToFPInst Class
2848 //===----------------------------------------------------------------------===//
2849
2850 /// @brief This class represents a cast from signed integer to floating point.
2851 class SIToFPInst : public CastInst {
2852 protected:
2853   /// @brief Clone an identical SIToFPInst
2854   virtual SIToFPInst *clone_impl() const;
2855
2856 public:
2857   /// @brief Constructor with insert-before-instruction semantics
2858   SIToFPInst(
2859     Value *S,                     ///< The value to be converted
2860     const Type *Ty,               ///< The type to convert to
2861     const Twine &NameStr = "",    ///< A name for the new instruction
2862     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2863   );
2864
2865   /// @brief Constructor with insert-at-end-of-block semantics
2866   SIToFPInst(
2867     Value *S,                     ///< The value to be converted
2868     const Type *Ty,               ///< The type to convert to
2869     const Twine &NameStr,         ///< A name for the new instruction
2870     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2871   );
2872
2873   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2874   static inline bool classof(const SIToFPInst *) { return true; }
2875   static inline bool classof(const Instruction *I) {
2876     return I->getOpcode() == SIToFP;
2877   }
2878   static inline bool classof(const Value *V) {
2879     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2880   }
2881 };
2882
2883 //===----------------------------------------------------------------------===//
2884 //                                 FPToUIInst Class
2885 //===----------------------------------------------------------------------===//
2886
2887 /// @brief This class represents a cast from floating point to unsigned integer
2888 class FPToUIInst  : public CastInst {
2889 protected:
2890   /// @brief Clone an identical FPToUIInst
2891   virtual FPToUIInst *clone_impl() const;
2892
2893 public:
2894   /// @brief Constructor with insert-before-instruction semantics
2895   FPToUIInst(
2896     Value *S,                     ///< The value to be converted
2897     const Type *Ty,               ///< The type to convert to
2898     const Twine &NameStr = "",    ///< A name for the new instruction
2899     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2900   );
2901
2902   /// @brief Constructor with insert-at-end-of-block semantics
2903   FPToUIInst(
2904     Value *S,                     ///< The value to be converted
2905     const Type *Ty,               ///< The type to convert to
2906     const Twine &NameStr,         ///< A name for the new instruction
2907     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2908   );
2909
2910   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2911   static inline bool classof(const FPToUIInst *) { return true; }
2912   static inline bool classof(const Instruction *I) {
2913     return I->getOpcode() == FPToUI;
2914   }
2915   static inline bool classof(const Value *V) {
2916     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2917   }
2918 };
2919
2920 //===----------------------------------------------------------------------===//
2921 //                                 FPToSIInst Class
2922 //===----------------------------------------------------------------------===//
2923
2924 /// @brief This class represents a cast from floating point to signed integer.
2925 class FPToSIInst  : public CastInst {
2926 protected:
2927   /// @brief Clone an identical FPToSIInst
2928   virtual FPToSIInst *clone_impl() const;
2929
2930 public:
2931   /// @brief Constructor with insert-before-instruction semantics
2932   FPToSIInst(
2933     Value *S,                     ///< The value to be converted
2934     const Type *Ty,               ///< The type to convert to
2935     const Twine &NameStr = "",    ///< A name for the new instruction
2936     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2937   );
2938
2939   /// @brief Constructor with insert-at-end-of-block semantics
2940   FPToSIInst(
2941     Value *S,                     ///< The value to be converted
2942     const Type *Ty,               ///< The type to convert to
2943     const Twine &NameStr,         ///< A name for the new instruction
2944     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2945   );
2946
2947   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2948   static inline bool classof(const FPToSIInst *) { return true; }
2949   static inline bool classof(const Instruction *I) {
2950     return I->getOpcode() == FPToSI;
2951   }
2952   static inline bool classof(const Value *V) {
2953     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2954   }
2955 };
2956
2957 //===----------------------------------------------------------------------===//
2958 //                                 IntToPtrInst Class
2959 //===----------------------------------------------------------------------===//
2960
2961 /// @brief This class represents a cast from an integer to a pointer.
2962 class IntToPtrInst : public CastInst {
2963 public:
2964   /// @brief Constructor with insert-before-instruction semantics
2965   IntToPtrInst(
2966     Value *S,                     ///< The value to be converted
2967     const Type *Ty,               ///< The type to convert to
2968     const Twine &NameStr = "",    ///< A name for the new instruction
2969     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2970   );
2971
2972   /// @brief Constructor with insert-at-end-of-block semantics
2973   IntToPtrInst(
2974     Value *S,                     ///< The value to be converted
2975     const Type *Ty,               ///< The type to convert to
2976     const Twine &NameStr,         ///< A name for the new instruction
2977     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2978   );
2979
2980   /// @brief Clone an identical IntToPtrInst
2981   virtual IntToPtrInst *clone_impl() const;
2982
2983   // Methods for support type inquiry through isa, cast, and dyn_cast:
2984   static inline bool classof(const IntToPtrInst *) { return true; }
2985   static inline bool classof(const Instruction *I) {
2986     return I->getOpcode() == IntToPtr;
2987   }
2988   static inline bool classof(const Value *V) {
2989     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2990   }
2991 };
2992
2993 //===----------------------------------------------------------------------===//
2994 //                                 PtrToIntInst Class
2995 //===----------------------------------------------------------------------===//
2996
2997 /// @brief This class represents a cast from a pointer to an integer
2998 class PtrToIntInst : public CastInst {
2999 protected:
3000   /// @brief Clone an identical PtrToIntInst
3001   virtual PtrToIntInst *clone_impl() const;
3002
3003 public:
3004   /// @brief Constructor with insert-before-instruction semantics
3005   PtrToIntInst(
3006     Value *S,                     ///< The value to be converted
3007     const Type *Ty,               ///< The type to convert to
3008     const Twine &NameStr = "",    ///< A name for the new instruction
3009     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3010   );
3011
3012   /// @brief Constructor with insert-at-end-of-block semantics
3013   PtrToIntInst(
3014     Value *S,                     ///< The value to be converted
3015     const Type *Ty,               ///< The type to convert to
3016     const Twine &NameStr,         ///< A name for the new instruction
3017     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3018   );
3019
3020   // Methods for support type inquiry through isa, cast, and dyn_cast:
3021   static inline bool classof(const PtrToIntInst *) { return true; }
3022   static inline bool classof(const Instruction *I) {
3023     return I->getOpcode() == PtrToInt;
3024   }
3025   static inline bool classof(const Value *V) {
3026     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3027   }
3028 };
3029
3030 //===----------------------------------------------------------------------===//
3031 //                             BitCastInst Class
3032 //===----------------------------------------------------------------------===//
3033
3034 /// @brief This class represents a no-op cast from one type to another.
3035 class BitCastInst : public CastInst {
3036 protected:
3037   /// @brief Clone an identical BitCastInst
3038   virtual BitCastInst *clone_impl() const;
3039
3040 public:
3041   /// @brief Constructor with insert-before-instruction semantics
3042   BitCastInst(
3043     Value *S,                     ///< The value to be casted
3044     const Type *Ty,               ///< The type to casted to
3045     const Twine &NameStr = "",    ///< A name for the new instruction
3046     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3047   );
3048
3049   /// @brief Constructor with insert-at-end-of-block semantics
3050   BitCastInst(
3051     Value *S,                     ///< The value to be casted
3052     const Type *Ty,               ///< The type to casted to
3053     const Twine &NameStr,         ///< A name for the new instruction
3054     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3055   );
3056
3057   // Methods for support type inquiry through isa, cast, and dyn_cast:
3058   static inline bool classof(const BitCastInst *) { return true; }
3059   static inline bool classof(const Instruction *I) {
3060     return I->getOpcode() == BitCast;
3061   }
3062   static inline bool classof(const Value *V) {
3063     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3064   }
3065 };
3066
3067 } // End llvm namespace
3068
3069 #endif