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