punctuate properly
[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 Instruction *CreateMalloc(Instruction *InsertBefore,
996                                    const Type *IntPtrTy, const Type *AllocTy,
997                                    Value *ArraySize = 0,
998                                    const Twine &Name = "");
999   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1000                                    const Type *IntPtrTy, const Type *AllocTy,
1001                                    Value *ArraySize = 0, Function* MallocF = 0,
1002                                    const Twine &Name = "");
1003
1004   ~CallInst();
1005
1006   bool isTailCall() const           { return SubclassData & 1; }
1007   void setTailCall(bool isTC = true) {
1008     SubclassData = (SubclassData & ~1) | unsigned(isTC);
1009   }
1010
1011   virtual CallInst *clone() const;
1012
1013   /// Provide fast operand accessors
1014   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1015
1016   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1017   /// function call.
1018   CallingConv::ID getCallingConv() const {
1019     return static_cast<CallingConv::ID>(SubclassData >> 1);
1020   }
1021   void setCallingConv(CallingConv::ID CC) {
1022     SubclassData = (SubclassData & 1) | (static_cast<unsigned>(CC) << 1);
1023   }
1024
1025   /// getAttributes - Return the parameter attributes for this call.
1026   ///
1027   const AttrListPtr &getAttributes() const { return AttributeList; }
1028
1029   /// setAttributes - Set the parameter attributes for this call.
1030   ///
1031   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1032
1033   /// addAttribute - adds the attribute to the list of attributes.
1034   void addAttribute(unsigned i, Attributes attr);
1035
1036   /// removeAttribute - removes the attribute from the list of attributes.
1037   void removeAttribute(unsigned i, Attributes attr);
1038
1039   /// @brief Determine whether the call or the callee has the given attribute.
1040   bool paramHasAttr(unsigned i, Attributes attr) const;
1041
1042   /// @brief Extract the alignment for a call or parameter (0=unknown).
1043   unsigned getParamAlignment(unsigned i) const {
1044     return AttributeList.getParamAlignment(i);
1045   }
1046
1047   /// @brief Determine if the call does not access memory.
1048   bool doesNotAccessMemory() const {
1049     return paramHasAttr(~0, Attribute::ReadNone);
1050   }
1051   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1052     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1053     else removeAttribute(~0, Attribute::ReadNone);
1054   }
1055
1056   /// @brief Determine if the call does not access or only reads memory.
1057   bool onlyReadsMemory() const {
1058     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1059   }
1060   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1061     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1062     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1063   }
1064
1065   /// @brief Determine if the call cannot return.
1066   bool doesNotReturn() const {
1067     return paramHasAttr(~0, Attribute::NoReturn);
1068   }
1069   void setDoesNotReturn(bool DoesNotReturn = true) {
1070     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1071     else removeAttribute(~0, Attribute::NoReturn);
1072   }
1073
1074   /// @brief Determine if the call cannot unwind.
1075   bool doesNotThrow() const {
1076     return paramHasAttr(~0, Attribute::NoUnwind);
1077   }
1078   void setDoesNotThrow(bool DoesNotThrow = true) {
1079     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1080     else removeAttribute(~0, Attribute::NoUnwind);
1081   }
1082
1083   /// @brief Determine if the call returns a structure through first
1084   /// pointer argument.
1085   bool hasStructRetAttr() const {
1086     // Be friendly and also check the callee.
1087     return paramHasAttr(1, Attribute::StructRet);
1088   }
1089
1090   /// @brief Determine if any call argument is an aggregate passed by value.
1091   bool hasByValArgument() const {
1092     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1093   }
1094
1095   /// getCalledFunction - Return the function called, or null if this is an
1096   /// indirect function invocation.
1097   ///
1098   Function *getCalledFunction() const {
1099     return dyn_cast<Function>(Op<0>());
1100   }
1101
1102   /// getCalledValue - Get a pointer to the function that is invoked by this
1103   /// instruction.
1104   const Value *getCalledValue() const { return Op<0>(); }
1105         Value *getCalledValue()       { return Op<0>(); }
1106
1107   /// setCalledFunction - Set the function called.
1108   void setCalledFunction(Value* Fn) {
1109     Op<0>() = Fn;
1110   }
1111
1112   // Methods for support type inquiry through isa, cast, and dyn_cast:
1113   static inline bool classof(const CallInst *) { return true; }
1114   static inline bool classof(const Instruction *I) {
1115     return I->getOpcode() == Instruction::Call;
1116   }
1117   static inline bool classof(const Value *V) {
1118     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1119   }
1120 };
1121
1122 template <>
1123 struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
1124 };
1125
1126 template<typename InputIterator>
1127 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1128                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1129   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1130                                    ->getElementType())->getReturnType(),
1131                 Instruction::Call,
1132                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1133                 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1134   init(Func, ArgBegin, ArgEnd, NameStr,
1135        typename std::iterator_traits<InputIterator>::iterator_category());
1136 }
1137
1138 template<typename InputIterator>
1139 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1140                    const Twine &NameStr, Instruction *InsertBefore)
1141   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1142                                    ->getElementType())->getReturnType(),
1143                 Instruction::Call,
1144                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1145                 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1146   init(Func, ArgBegin, ArgEnd, NameStr,
1147        typename std::iterator_traits<InputIterator>::iterator_category());
1148 }
1149
1150 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1151
1152 //===----------------------------------------------------------------------===//
1153 //                               SelectInst Class
1154 //===----------------------------------------------------------------------===//
1155
1156 /// SelectInst - This class represents the LLVM 'select' instruction.
1157 ///
1158 class SelectInst : public Instruction {
1159   void init(Value *C, Value *S1, Value *S2) {
1160     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1161     Op<0>() = C;
1162     Op<1>() = S1;
1163     Op<2>() = S2;
1164   }
1165
1166   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1167              Instruction *InsertBefore)
1168     : Instruction(S1->getType(), Instruction::Select,
1169                   &Op<0>(), 3, InsertBefore) {
1170     init(C, S1, S2);
1171     setName(NameStr);
1172   }
1173   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1174              BasicBlock *InsertAtEnd)
1175     : Instruction(S1->getType(), Instruction::Select,
1176                   &Op<0>(), 3, InsertAtEnd) {
1177     init(C, S1, S2);
1178     setName(NameStr);
1179   }
1180 public:
1181   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1182                             const Twine &NameStr = "",
1183                             Instruction *InsertBefore = 0) {
1184     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1185   }
1186   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1187                             const Twine &NameStr,
1188                             BasicBlock *InsertAtEnd) {
1189     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1190   }
1191
1192   const Value *getCondition() const { return Op<0>(); }
1193   const Value *getTrueValue() const { return Op<1>(); }
1194   const Value *getFalseValue() const { return Op<2>(); }
1195   Value *getCondition() { return Op<0>(); }
1196   Value *getTrueValue() { return Op<1>(); }
1197   Value *getFalseValue() { return Op<2>(); }
1198   
1199   /// areInvalidOperands - Return a string if the specified operands are invalid
1200   /// for a select operation, otherwise return null.
1201   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1202
1203   /// Transparently provide more efficient getOperand methods.
1204   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1205
1206   OtherOps getOpcode() const {
1207     return static_cast<OtherOps>(Instruction::getOpcode());
1208   }
1209
1210   virtual SelectInst *clone() const;
1211
1212   // Methods for support type inquiry through isa, cast, and dyn_cast:
1213   static inline bool classof(const SelectInst *) { return true; }
1214   static inline bool classof(const Instruction *I) {
1215     return I->getOpcode() == Instruction::Select;
1216   }
1217   static inline bool classof(const Value *V) {
1218     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1219   }
1220 };
1221
1222 template <>
1223 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
1224 };
1225
1226 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1227
1228 //===----------------------------------------------------------------------===//
1229 //                                VAArgInst Class
1230 //===----------------------------------------------------------------------===//
1231
1232 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1233 /// an argument of the specified type given a va_list and increments that list
1234 ///
1235 class VAArgInst : public UnaryInstruction {
1236 public:
1237   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1238              Instruction *InsertBefore = 0)
1239     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1240     setName(NameStr);
1241   }
1242   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1243             BasicBlock *InsertAtEnd)
1244     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1245     setName(NameStr);
1246   }
1247
1248   virtual VAArgInst *clone() const;
1249
1250   // Methods for support type inquiry through isa, cast, and dyn_cast:
1251   static inline bool classof(const VAArgInst *) { return true; }
1252   static inline bool classof(const Instruction *I) {
1253     return I->getOpcode() == VAArg;
1254   }
1255   static inline bool classof(const Value *V) {
1256     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1257   }
1258 };
1259
1260 //===----------------------------------------------------------------------===//
1261 //                                ExtractElementInst Class
1262 //===----------------------------------------------------------------------===//
1263
1264 /// ExtractElementInst - This instruction extracts a single (scalar)
1265 /// element from a VectorType value
1266 ///
1267 class ExtractElementInst : public Instruction {
1268   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1269                      Instruction *InsertBefore = 0);
1270   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1271                      BasicBlock *InsertAtEnd);
1272 public:
1273   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1274                                    const Twine &NameStr = "",
1275                                    Instruction *InsertBefore = 0) {
1276     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1277   }
1278   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1279                                    const Twine &NameStr,
1280                                    BasicBlock *InsertAtEnd) {
1281     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1282   }
1283
1284   /// isValidOperands - Return true if an extractelement instruction can be
1285   /// formed with the specified operands.
1286   static bool isValidOperands(const Value *Vec, const Value *Idx);
1287
1288   virtual ExtractElementInst *clone() const;
1289
1290   Value *getVectorOperand() { return Op<0>(); }
1291   Value *getIndexOperand() { return Op<1>(); }
1292   const Value *getVectorOperand() const { return Op<0>(); }
1293   const Value *getIndexOperand() const { return Op<1>(); }
1294   
1295   const VectorType *getVectorOperandType() const {
1296     return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1297   }
1298   
1299   
1300   /// Transparently provide more efficient getOperand methods.
1301   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1302
1303   // Methods for support type inquiry through isa, cast, and dyn_cast:
1304   static inline bool classof(const ExtractElementInst *) { return true; }
1305   static inline bool classof(const Instruction *I) {
1306     return I->getOpcode() == Instruction::ExtractElement;
1307   }
1308   static inline bool classof(const Value *V) {
1309     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1310   }
1311 };
1312
1313 template <>
1314 struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
1315 };
1316
1317 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1318
1319 //===----------------------------------------------------------------------===//
1320 //                                InsertElementInst Class
1321 //===----------------------------------------------------------------------===//
1322
1323 /// InsertElementInst - This instruction inserts a single (scalar)
1324 /// element into a VectorType value
1325 ///
1326 class InsertElementInst : public Instruction {
1327   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1328                     const Twine &NameStr = "",
1329                     Instruction *InsertBefore = 0);
1330   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1331                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1332 public:
1333   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1334                                    const Twine &NameStr = "",
1335                                    Instruction *InsertBefore = 0) {
1336     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1337   }
1338   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1339                                    const Twine &NameStr,
1340                                    BasicBlock *InsertAtEnd) {
1341     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1342   }
1343
1344   /// isValidOperands - Return true if an insertelement instruction can be
1345   /// formed with the specified operands.
1346   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1347                               const Value *Idx);
1348
1349   virtual InsertElementInst *clone() const;
1350
1351   /// getType - Overload to return most specific vector type.
1352   ///
1353   const VectorType *getType() const {
1354     return reinterpret_cast<const VectorType*>(Instruction::getType());
1355   }
1356
1357   /// Transparently provide more efficient getOperand methods.
1358   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1359
1360   // Methods for support type inquiry through isa, cast, and dyn_cast:
1361   static inline bool classof(const InsertElementInst *) { return true; }
1362   static inline bool classof(const Instruction *I) {
1363     return I->getOpcode() == Instruction::InsertElement;
1364   }
1365   static inline bool classof(const Value *V) {
1366     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1367   }
1368 };
1369
1370 template <>
1371 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1372 };
1373
1374 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1375
1376 //===----------------------------------------------------------------------===//
1377 //                           ShuffleVectorInst Class
1378 //===----------------------------------------------------------------------===//
1379
1380 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1381 /// input vectors.
1382 ///
1383 class ShuffleVectorInst : public Instruction {
1384 public:
1385   // allocate space for exactly three operands
1386   void *operator new(size_t s) {
1387     return User::operator new(s, 3);
1388   }
1389   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1390                     const Twine &NameStr = "",
1391                     Instruction *InsertBefor = 0);
1392   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1393                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1394
1395   /// isValidOperands - Return true if a shufflevector instruction can be
1396   /// formed with the specified operands.
1397   static bool isValidOperands(const Value *V1, const Value *V2,
1398                               const Value *Mask);
1399
1400   virtual ShuffleVectorInst *clone() const;
1401
1402   /// getType - Overload to return most specific vector type.
1403   ///
1404   const VectorType *getType() const {
1405     return reinterpret_cast<const VectorType*>(Instruction::getType());
1406   }
1407
1408   /// Transparently provide more efficient getOperand methods.
1409   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1410
1411   /// getMaskValue - Return the index from the shuffle mask for the specified
1412   /// output result.  This is either -1 if the element is undef or a number less
1413   /// than 2*numelements.
1414   int getMaskValue(unsigned i) const;
1415
1416   // Methods for support type inquiry through isa, cast, and dyn_cast:
1417   static inline bool classof(const ShuffleVectorInst *) { return true; }
1418   static inline bool classof(const Instruction *I) {
1419     return I->getOpcode() == Instruction::ShuffleVector;
1420   }
1421   static inline bool classof(const Value *V) {
1422     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1423   }
1424 };
1425
1426 template <>
1427 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1428 };
1429
1430 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1431
1432 //===----------------------------------------------------------------------===//
1433 //                                ExtractValueInst Class
1434 //===----------------------------------------------------------------------===//
1435
1436 /// ExtractValueInst - This instruction extracts a struct member or array
1437 /// element value from an aggregate value.
1438 ///
1439 class ExtractValueInst : public UnaryInstruction {
1440   SmallVector<unsigned, 4> Indices;
1441
1442   ExtractValueInst(const ExtractValueInst &EVI);
1443   void init(const unsigned *Idx, unsigned NumIdx,
1444             const Twine &NameStr);
1445   void init(unsigned Idx, const Twine &NameStr);
1446
1447   template<typename InputIterator>
1448   void init(InputIterator IdxBegin, InputIterator IdxEnd,
1449             const Twine &NameStr,
1450             // This argument ensures that we have an iterator we can
1451             // do arithmetic on in constant time
1452             std::random_access_iterator_tag) {
1453     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1454
1455     // There's no fundamental reason why we require at least one index
1456     // (other than weirdness with &*IdxBegin being invalid; see
1457     // getelementptr's init routine for example). But there's no
1458     // present need to support it.
1459     assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1460
1461     // This requires that the iterator points to contiguous memory.
1462     init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1463                                          // we have to build an array here
1464   }
1465
1466   /// getIndexedType - Returns the type of the element that would be extracted
1467   /// with an extractvalue instruction with the specified parameters.
1468   ///
1469   /// Null is returned if the indices are invalid for the specified
1470   /// pointer type.
1471   ///
1472   static const Type *getIndexedType(const Type *Agg,
1473                                     const unsigned *Idx, unsigned NumIdx);
1474
1475   template<typename InputIterator>
1476   static const Type *getIndexedType(const Type *Ptr,
1477                                     InputIterator IdxBegin,
1478                                     InputIterator IdxEnd,
1479                                     // This argument ensures that we
1480                                     // have an iterator we can do
1481                                     // arithmetic on in constant time
1482                                     std::random_access_iterator_tag) {
1483     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1484
1485     if (NumIdx > 0)
1486       // This requires that the iterator points to contiguous memory.
1487       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1488     else
1489       return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1490   }
1491
1492   /// Constructors - Create a extractvalue instruction with a base aggregate
1493   /// value and a list of indices.  The first ctor can optionally insert before
1494   /// an existing instruction, the second appends the new instruction to the
1495   /// specified BasicBlock.
1496   template<typename InputIterator>
1497   inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1498                           InputIterator IdxEnd,
1499                           const Twine &NameStr,
1500                           Instruction *InsertBefore);
1501   template<typename InputIterator>
1502   inline ExtractValueInst(Value *Agg,
1503                           InputIterator IdxBegin, InputIterator IdxEnd,
1504                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1505
1506   // allocate space for exactly one operand
1507   void *operator new(size_t s) {
1508     return User::operator new(s, 1);
1509   }
1510
1511 public:
1512   template<typename InputIterator>
1513   static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1514                                   InputIterator IdxEnd,
1515                                   const Twine &NameStr = "",
1516                                   Instruction *InsertBefore = 0) {
1517     return new
1518       ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1519   }
1520   template<typename InputIterator>
1521   static ExtractValueInst *Create(Value *Agg,
1522                                   InputIterator IdxBegin, InputIterator IdxEnd,
1523                                   const Twine &NameStr,
1524                                   BasicBlock *InsertAtEnd) {
1525     return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1526   }
1527
1528   /// Constructors - These two creators are convenience methods because one
1529   /// index extractvalue instructions are much more common than those with
1530   /// more than one.
1531   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1532                                   const Twine &NameStr = "",
1533                                   Instruction *InsertBefore = 0) {
1534     unsigned Idxs[1] = { Idx };
1535     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1536   }
1537   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1538                                   const Twine &NameStr,
1539                                   BasicBlock *InsertAtEnd) {
1540     unsigned Idxs[1] = { Idx };
1541     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1542   }
1543
1544   virtual ExtractValueInst *clone() const;
1545
1546   /// getIndexedType - Returns the type of the element that would be extracted
1547   /// with an extractvalue instruction with the specified parameters.
1548   ///
1549   /// Null is returned if the indices are invalid for the specified
1550   /// pointer type.
1551   ///
1552   template<typename InputIterator>
1553   static const Type *getIndexedType(const Type *Ptr,
1554                                     InputIterator IdxBegin,
1555                                     InputIterator IdxEnd) {
1556     return getIndexedType(Ptr, IdxBegin, IdxEnd,
1557                           typename std::iterator_traits<InputIterator>::
1558                           iterator_category());
1559   }
1560   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1561
1562   typedef const unsigned* idx_iterator;
1563   inline idx_iterator idx_begin() const { return Indices.begin(); }
1564   inline idx_iterator idx_end()   const { return Indices.end(); }
1565
1566   Value *getAggregateOperand() {
1567     return getOperand(0);
1568   }
1569   const Value *getAggregateOperand() const {
1570     return getOperand(0);
1571   }
1572   static unsigned getAggregateOperandIndex() {
1573     return 0U;                      // get index for modifying correct operand
1574   }
1575
1576   unsigned getNumIndices() const {  // Note: always non-negative
1577     return (unsigned)Indices.size();
1578   }
1579
1580   bool hasIndices() const {
1581     return true;
1582   }
1583
1584   // Methods for support type inquiry through isa, cast, and dyn_cast:
1585   static inline bool classof(const ExtractValueInst *) { return true; }
1586   static inline bool classof(const Instruction *I) {
1587     return I->getOpcode() == Instruction::ExtractValue;
1588   }
1589   static inline bool classof(const Value *V) {
1590     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1591   }
1592 };
1593
1594 template<typename InputIterator>
1595 ExtractValueInst::ExtractValueInst(Value *Agg,
1596                                    InputIterator IdxBegin,
1597                                    InputIterator IdxEnd,
1598                                    const Twine &NameStr,
1599                                    Instruction *InsertBefore)
1600   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1601                                               IdxBegin, IdxEnd)),
1602                      ExtractValue, Agg, InsertBefore) {
1603   init(IdxBegin, IdxEnd, NameStr,
1604        typename std::iterator_traits<InputIterator>::iterator_category());
1605 }
1606 template<typename InputIterator>
1607 ExtractValueInst::ExtractValueInst(Value *Agg,
1608                                    InputIterator IdxBegin,
1609                                    InputIterator IdxEnd,
1610                                    const Twine &NameStr,
1611                                    BasicBlock *InsertAtEnd)
1612   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1613                                               IdxBegin, IdxEnd)),
1614                      ExtractValue, Agg, InsertAtEnd) {
1615   init(IdxBegin, IdxEnd, NameStr,
1616        typename std::iterator_traits<InputIterator>::iterator_category());
1617 }
1618
1619
1620 //===----------------------------------------------------------------------===//
1621 //                                InsertValueInst Class
1622 //===----------------------------------------------------------------------===//
1623
1624 /// InsertValueInst - This instruction inserts a struct field of array element
1625 /// value into an aggregate value.
1626 ///
1627 class InsertValueInst : public Instruction {
1628   SmallVector<unsigned, 4> Indices;
1629
1630   void *operator new(size_t, unsigned); // Do not implement
1631   InsertValueInst(const InsertValueInst &IVI);
1632   void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1633             const Twine &NameStr);
1634   void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1635
1636   template<typename InputIterator>
1637   void init(Value *Agg, Value *Val,
1638             InputIterator IdxBegin, InputIterator IdxEnd,
1639             const Twine &NameStr,
1640             // This argument ensures that we have an iterator we can
1641             // do arithmetic on in constant time
1642             std::random_access_iterator_tag) {
1643     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1644
1645     // There's no fundamental reason why we require at least one index
1646     // (other than weirdness with &*IdxBegin being invalid; see
1647     // getelementptr's init routine for example). But there's no
1648     // present need to support it.
1649     assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1650
1651     // This requires that the iterator points to contiguous memory.
1652     init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1653                                               // we have to build an array here
1654   }
1655
1656   /// Constructors - Create a insertvalue instruction with a base aggregate
1657   /// value, a value to insert, and a list of indices.  The first ctor can
1658   /// optionally insert before an existing instruction, the second appends
1659   /// the new instruction to the specified BasicBlock.
1660   template<typename InputIterator>
1661   inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1662                          InputIterator IdxEnd,
1663                          const Twine &NameStr,
1664                          Instruction *InsertBefore);
1665   template<typename InputIterator>
1666   inline InsertValueInst(Value *Agg, Value *Val,
1667                          InputIterator IdxBegin, InputIterator IdxEnd,
1668                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1669
1670   /// Constructors - These two constructors are convenience methods because one
1671   /// and two index insertvalue instructions are so common.
1672   InsertValueInst(Value *Agg, Value *Val,
1673                   unsigned Idx, const Twine &NameStr = "",
1674                   Instruction *InsertBefore = 0);
1675   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1676                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1677 public:
1678   // allocate space for exactly two operands
1679   void *operator new(size_t s) {
1680     return User::operator new(s, 2);
1681   }
1682
1683   template<typename InputIterator>
1684   static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1685                                  InputIterator IdxEnd,
1686                                  const Twine &NameStr = "",
1687                                  Instruction *InsertBefore = 0) {
1688     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1689                                NameStr, InsertBefore);
1690   }
1691   template<typename InputIterator>
1692   static InsertValueInst *Create(Value *Agg, Value *Val,
1693                                  InputIterator IdxBegin, InputIterator IdxEnd,
1694                                  const Twine &NameStr,
1695                                  BasicBlock *InsertAtEnd) {
1696     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1697                                NameStr, InsertAtEnd);
1698   }
1699
1700   /// Constructors - These two creators are convenience methods because one
1701   /// index insertvalue instructions are much more common than those with
1702   /// more than one.
1703   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1704                                  const Twine &NameStr = "",
1705                                  Instruction *InsertBefore = 0) {
1706     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1707   }
1708   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1709                                  const Twine &NameStr,
1710                                  BasicBlock *InsertAtEnd) {
1711     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1712   }
1713
1714   virtual InsertValueInst *clone() const;
1715
1716   /// Transparently provide more efficient getOperand methods.
1717   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1718
1719   typedef const unsigned* idx_iterator;
1720   inline idx_iterator idx_begin() const { return Indices.begin(); }
1721   inline idx_iterator idx_end()   const { return Indices.end(); }
1722
1723   Value *getAggregateOperand() {
1724     return getOperand(0);
1725   }
1726   const Value *getAggregateOperand() const {
1727     return getOperand(0);
1728   }
1729   static unsigned getAggregateOperandIndex() {
1730     return 0U;                      // get index for modifying correct operand
1731   }
1732
1733   Value *getInsertedValueOperand() {
1734     return getOperand(1);
1735   }
1736   const Value *getInsertedValueOperand() const {
1737     return getOperand(1);
1738   }
1739   static unsigned getInsertedValueOperandIndex() {
1740     return 1U;                      // get index for modifying correct operand
1741   }
1742
1743   unsigned getNumIndices() const {  // Note: always non-negative
1744     return (unsigned)Indices.size();
1745   }
1746
1747   bool hasIndices() const {
1748     return true;
1749   }
1750
1751   // Methods for support type inquiry through isa, cast, and dyn_cast:
1752   static inline bool classof(const InsertValueInst *) { return true; }
1753   static inline bool classof(const Instruction *I) {
1754     return I->getOpcode() == Instruction::InsertValue;
1755   }
1756   static inline bool classof(const Value *V) {
1757     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1758   }
1759 };
1760
1761 template <>
1762 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1763 };
1764
1765 template<typename InputIterator>
1766 InsertValueInst::InsertValueInst(Value *Agg,
1767                                  Value *Val,
1768                                  InputIterator IdxBegin,
1769                                  InputIterator IdxEnd,
1770                                  const Twine &NameStr,
1771                                  Instruction *InsertBefore)
1772   : Instruction(Agg->getType(), InsertValue,
1773                 OperandTraits<InsertValueInst>::op_begin(this),
1774                 2, InsertBefore) {
1775   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1776        typename std::iterator_traits<InputIterator>::iterator_category());
1777 }
1778 template<typename InputIterator>
1779 InsertValueInst::InsertValueInst(Value *Agg,
1780                                  Value *Val,
1781                                  InputIterator IdxBegin,
1782                                  InputIterator IdxEnd,
1783                                  const Twine &NameStr,
1784                                  BasicBlock *InsertAtEnd)
1785   : Instruction(Agg->getType(), InsertValue,
1786                 OperandTraits<InsertValueInst>::op_begin(this),
1787                 2, InsertAtEnd) {
1788   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1789        typename std::iterator_traits<InputIterator>::iterator_category());
1790 }
1791
1792 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1793
1794 //===----------------------------------------------------------------------===//
1795 //                               PHINode Class
1796 //===----------------------------------------------------------------------===//
1797
1798 // PHINode - The PHINode class is used to represent the magical mystical PHI
1799 // node, that can not exist in nature, but can be synthesized in a computer
1800 // scientist's overactive imagination.
1801 //
1802 class PHINode : public Instruction {
1803   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1804   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1805   /// the number actually in use.
1806   unsigned ReservedSpace;
1807   PHINode(const PHINode &PN);
1808   // allocate space for exactly zero operands
1809   void *operator new(size_t s) {
1810     return User::operator new(s, 0);
1811   }
1812   explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1813                    Instruction *InsertBefore = 0)
1814     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1815       ReservedSpace(0) {
1816     setName(NameStr);
1817   }
1818
1819   PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1820     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1821       ReservedSpace(0) {
1822     setName(NameStr);
1823   }
1824 public:
1825   static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1826                          Instruction *InsertBefore = 0) {
1827     return new PHINode(Ty, NameStr, InsertBefore);
1828   }
1829   static PHINode *Create(const Type *Ty, const Twine &NameStr,
1830                          BasicBlock *InsertAtEnd) {
1831     return new PHINode(Ty, NameStr, InsertAtEnd);
1832   }
1833   ~PHINode();
1834
1835   /// reserveOperandSpace - This method can be used to avoid repeated
1836   /// reallocation of PHI operand lists by reserving space for the correct
1837   /// number of operands before adding them.  Unlike normal vector reserves,
1838   /// this method can also be used to trim the operand space.
1839   void reserveOperandSpace(unsigned NumValues) {
1840     resizeOperands(NumValues*2);
1841   }
1842
1843   virtual PHINode *clone() const;
1844
1845   /// Provide fast operand accessors
1846   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1847
1848   /// getNumIncomingValues - Return the number of incoming edges
1849   ///
1850   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1851
1852   /// getIncomingValue - Return incoming value number x
1853   ///
1854   Value *getIncomingValue(unsigned i) const {
1855     assert(i*2 < getNumOperands() && "Invalid value number!");
1856     return getOperand(i*2);
1857   }
1858   void setIncomingValue(unsigned i, Value *V) {
1859     assert(i*2 < getNumOperands() && "Invalid value number!");
1860     setOperand(i*2, V);
1861   }
1862   static unsigned getOperandNumForIncomingValue(unsigned i) {
1863     return i*2;
1864   }
1865   static unsigned getIncomingValueNumForOperand(unsigned i) {
1866     assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1867     return i/2;
1868   }
1869
1870   /// getIncomingBlock - Return incoming basic block #i.
1871   ///
1872   BasicBlock *getIncomingBlock(unsigned i) const {
1873     return cast<BasicBlock>(getOperand(i*2+1));
1874   }
1875   
1876   /// getIncomingBlock - Return incoming basic block corresponding
1877   /// to an operand of the PHI.
1878   ///
1879   BasicBlock *getIncomingBlock(const Use &U) const {
1880     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1881     return cast<BasicBlock>((&U + 1)->get());
1882   }
1883   
1884   /// getIncomingBlock - Return incoming basic block corresponding
1885   /// to value use iterator.
1886   ///
1887   template <typename U>
1888   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1889     return getIncomingBlock(I.getUse());
1890   }
1891   
1892   
1893   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1894     setOperand(i*2+1, BB);
1895   }
1896   static unsigned getOperandNumForIncomingBlock(unsigned i) {
1897     return i*2+1;
1898   }
1899   static unsigned getIncomingBlockNumForOperand(unsigned i) {
1900     assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1901     return i/2;
1902   }
1903
1904   /// addIncoming - Add an incoming value to the end of the PHI list
1905   ///
1906   void addIncoming(Value *V, BasicBlock *BB) {
1907     assert(V && "PHI node got a null value!");
1908     assert(BB && "PHI node got a null basic block!");
1909     assert(getType() == V->getType() &&
1910            "All operands to PHI node must be the same type as the PHI node!");
1911     unsigned OpNo = NumOperands;
1912     if (OpNo+2 > ReservedSpace)
1913       resizeOperands(0);  // Get more space!
1914     // Initialize some new operands.
1915     NumOperands = OpNo+2;
1916     OperandList[OpNo] = V;
1917     OperandList[OpNo+1] = BB;
1918   }
1919
1920   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1921   /// predecessor basic block is deleted.  The value removed is returned.
1922   ///
1923   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1924   /// is true), the PHI node is destroyed and any uses of it are replaced with
1925   /// dummy values.  The only time there should be zero incoming values to a PHI
1926   /// node is when the block is dead, so this strategy is sound.
1927   ///
1928   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1929
1930   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1931     int Idx = getBasicBlockIndex(BB);
1932     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1933     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1934   }
1935
1936   /// getBasicBlockIndex - Return the first index of the specified basic
1937   /// block in the value list for this PHI.  Returns -1 if no instance.
1938   ///
1939   int getBasicBlockIndex(const BasicBlock *BB) const {
1940     Use *OL = OperandList;
1941     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1942       if (OL[i+1].get() == BB) return i/2;
1943     return -1;
1944   }
1945
1946   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1947     return getIncomingValue(getBasicBlockIndex(BB));
1948   }
1949
1950   /// hasConstantValue - If the specified PHI node always merges together the
1951   /// same value, return the value, otherwise return null.
1952   ///
1953   /// If the PHI has undef operands, but all the rest of the operands are
1954   /// some unique value, return that value if it can be proved that the
1955   /// value dominates the PHI. If DT is null, use a conservative check,
1956   /// otherwise use DT to test for dominance.
1957   ///
1958   Value *hasConstantValue(DominatorTree *DT = 0) const;
1959
1960   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1961   static inline bool classof(const PHINode *) { return true; }
1962   static inline bool classof(const Instruction *I) {
1963     return I->getOpcode() == Instruction::PHI;
1964   }
1965   static inline bool classof(const Value *V) {
1966     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1967   }
1968  private:
1969   void resizeOperands(unsigned NumOperands);
1970 };
1971
1972 template <>
1973 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1974 };
1975
1976 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1977
1978
1979 //===----------------------------------------------------------------------===//
1980 //                               ReturnInst Class
1981 //===----------------------------------------------------------------------===//
1982
1983 //===---------------------------------------------------------------------------
1984 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1985 /// does not continue in this function any longer.
1986 ///
1987 class ReturnInst : public TerminatorInst {
1988   ReturnInst(const ReturnInst &RI);
1989
1990 private:
1991   // ReturnInst constructors:
1992   // ReturnInst()                  - 'ret void' instruction
1993   // ReturnInst(    null)          - 'ret void' instruction
1994   // ReturnInst(Value* X)          - 'ret X'    instruction
1995   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1996   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1997   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1998   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1999   //
2000   // NOTE: If the Value* passed is of type void then the constructor behaves as
2001   // if it was passed NULL.
2002   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2003                       Instruction *InsertBefore = 0);
2004   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2005   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2006 public:
2007   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2008                             Instruction *InsertBefore = 0) {
2009     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2010   }
2011   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2012                             BasicBlock *InsertAtEnd) {
2013     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2014   }
2015   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2016     return new(0) ReturnInst(C, InsertAtEnd);
2017   }
2018   virtual ~ReturnInst();
2019
2020   virtual ReturnInst *clone() const;
2021
2022   /// Provide fast operand accessors
2023   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2024
2025   /// Convenience accessor
2026   Value *getReturnValue(unsigned n = 0) const {
2027     return n < getNumOperands()
2028       ? getOperand(n)
2029       : 0;
2030   }
2031
2032   unsigned getNumSuccessors() const { return 0; }
2033
2034   // Methods for support type inquiry through isa, cast, and dyn_cast:
2035   static inline bool classof(const ReturnInst *) { return true; }
2036   static inline bool classof(const Instruction *I) {
2037     return (I->getOpcode() == Instruction::Ret);
2038   }
2039   static inline bool classof(const Value *V) {
2040     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2041   }
2042  private:
2043   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2044   virtual unsigned getNumSuccessorsV() const;
2045   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2046 };
2047
2048 template <>
2049 struct OperandTraits<ReturnInst> : public OptionalOperandTraits<> {
2050 };
2051
2052 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2053
2054 //===----------------------------------------------------------------------===//
2055 //                               BranchInst Class
2056 //===----------------------------------------------------------------------===//
2057
2058 //===---------------------------------------------------------------------------
2059 /// BranchInst - Conditional or Unconditional Branch instruction.
2060 ///
2061 class BranchInst : public TerminatorInst {
2062   /// Ops list - Branches are strange.  The operands are ordered:
2063   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2064   /// they don't have to check for cond/uncond branchness. These are mostly
2065   /// accessed relative from op_end().
2066   BranchInst(const BranchInst &BI);
2067   void AssertOK();
2068   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2069   // BranchInst(BB *B)                           - 'br B'
2070   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2071   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2072   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2073   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2074   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2075   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2076   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2077              Instruction *InsertBefore = 0);
2078   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2079   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2080              BasicBlock *InsertAtEnd);
2081 public:
2082   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2083     return new(1, true) BranchInst(IfTrue, InsertBefore);
2084   }
2085   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2086                             Value *Cond, Instruction *InsertBefore = 0) {
2087     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2088   }
2089   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2090     return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2091   }
2092   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2093                             Value *Cond, BasicBlock *InsertAtEnd) {
2094     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2095   }
2096
2097   ~BranchInst();
2098
2099   /// Transparently provide more efficient getOperand methods.
2100   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2101
2102   virtual BranchInst *clone() const;
2103
2104   bool isUnconditional() const { return getNumOperands() == 1; }
2105   bool isConditional()   const { return getNumOperands() == 3; }
2106
2107   Value *getCondition() const {
2108     assert(isConditional() && "Cannot get condition of an uncond branch!");
2109     return Op<-3>();
2110   }
2111
2112   void setCondition(Value *V) {
2113     assert(isConditional() && "Cannot set condition of unconditional branch!");
2114     Op<-3>() = V;
2115   }
2116
2117   // setUnconditionalDest - Change the current branch to an unconditional branch
2118   // targeting the specified block.
2119   // FIXME: Eliminate this ugly method.
2120   void setUnconditionalDest(BasicBlock *Dest) {
2121     Op<-1>() = Dest;
2122     if (isConditional()) {  // Convert this to an uncond branch.
2123       Op<-2>() = 0;
2124       Op<-3>() = 0;
2125       NumOperands = 1;
2126       OperandList = op_begin();
2127     }
2128   }
2129
2130   unsigned getNumSuccessors() const { return 1+isConditional(); }
2131
2132   BasicBlock *getSuccessor(unsigned i) const {
2133     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2134     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2135   }
2136
2137   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2138     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2139     *(&Op<-1>() - idx) = NewSucc;
2140   }
2141
2142   // Methods for support type inquiry through isa, cast, and dyn_cast:
2143   static inline bool classof(const BranchInst *) { return true; }
2144   static inline bool classof(const Instruction *I) {
2145     return (I->getOpcode() == Instruction::Br);
2146   }
2147   static inline bool classof(const Value *V) {
2148     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2149   }
2150 private:
2151   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2152   virtual unsigned getNumSuccessorsV() const;
2153   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2154 };
2155
2156 template <>
2157 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2158
2159 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2160
2161 //===----------------------------------------------------------------------===//
2162 //                               SwitchInst Class
2163 //===----------------------------------------------------------------------===//
2164
2165 //===---------------------------------------------------------------------------
2166 /// SwitchInst - Multiway switch
2167 ///
2168 class SwitchInst : public TerminatorInst {
2169   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2170   unsigned ReservedSpace;
2171   // Operand[0]    = Value to switch on
2172   // Operand[1]    = Default basic block destination
2173   // Operand[2n  ] = Value to match
2174   // Operand[2n+1] = BasicBlock to go to on match
2175   SwitchInst(const SwitchInst &RI);
2176   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2177   void resizeOperands(unsigned No);
2178   // allocate space for exactly zero operands
2179   void *operator new(size_t s) {
2180     return User::operator new(s, 0);
2181   }
2182   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2183   /// switch on and a default destination.  The number of additional cases can
2184   /// be specified here to make memory allocation more efficient.  This
2185   /// constructor can also autoinsert before another instruction.
2186   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2187              Instruction *InsertBefore = 0);
2188
2189   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2190   /// switch on and a default destination.  The number of additional cases can
2191   /// be specified here to make memory allocation more efficient.  This
2192   /// constructor also autoinserts at the end of the specified BasicBlock.
2193   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2194              BasicBlock *InsertAtEnd);
2195 public:
2196   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2197                             unsigned NumCases, Instruction *InsertBefore = 0) {
2198     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2199   }
2200   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2201                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2202     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2203   }
2204   ~SwitchInst();
2205
2206   /// Provide fast operand accessors
2207   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2208
2209   // Accessor Methods for Switch stmt
2210   Value *getCondition() const { return getOperand(0); }
2211   void setCondition(Value *V) { setOperand(0, V); }
2212
2213   BasicBlock *getDefaultDest() const {
2214     return cast<BasicBlock>(getOperand(1));
2215   }
2216
2217   /// getNumCases - return the number of 'cases' in this switch instruction.
2218   /// Note that case #0 is always the default case.
2219   unsigned getNumCases() const {
2220     return getNumOperands()/2;
2221   }
2222
2223   /// getCaseValue - Return the specified case value.  Note that case #0, the
2224   /// default destination, does not have a case value.
2225   ConstantInt *getCaseValue(unsigned i) {
2226     assert(i && i < getNumCases() && "Illegal case value to get!");
2227     return getSuccessorValue(i);
2228   }
2229
2230   /// getCaseValue - Return the specified case value.  Note that case #0, the
2231   /// default destination, does not have a case value.
2232   const ConstantInt *getCaseValue(unsigned i) const {
2233     assert(i && i < getNumCases() && "Illegal case value to get!");
2234     return getSuccessorValue(i);
2235   }
2236
2237   /// findCaseValue - Search all of the case values for the specified constant.
2238   /// If it is explicitly handled, return the case number of it, otherwise
2239   /// return 0 to indicate that it is handled by the default handler.
2240   unsigned findCaseValue(const ConstantInt *C) const {
2241     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2242       if (getCaseValue(i) == C)
2243         return i;
2244     return 0;
2245   }
2246
2247   /// findCaseDest - Finds the unique case value for a given successor. Returns
2248   /// null if the successor is not found, not unique, or is the default case.
2249   ConstantInt *findCaseDest(BasicBlock *BB) {
2250     if (BB == getDefaultDest()) return NULL;
2251
2252     ConstantInt *CI = NULL;
2253     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2254       if (getSuccessor(i) == BB) {
2255         if (CI) return NULL;   // Multiple cases lead to BB.
2256         else CI = getCaseValue(i);
2257       }
2258     }
2259     return CI;
2260   }
2261
2262   /// addCase - Add an entry to the switch instruction...
2263   ///
2264   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2265
2266   /// removeCase - This method removes the specified successor from the switch
2267   /// instruction.  Note that this cannot be used to remove the default
2268   /// destination (successor #0).
2269   ///
2270   void removeCase(unsigned idx);
2271
2272   virtual SwitchInst *clone() const;
2273
2274   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2275   BasicBlock *getSuccessor(unsigned idx) const {
2276     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2277     return cast<BasicBlock>(getOperand(idx*2+1));
2278   }
2279   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2280     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2281     setOperand(idx*2+1, NewSucc);
2282   }
2283
2284   // getSuccessorValue - Return the value associated with the specified
2285   // successor.
2286   ConstantInt *getSuccessorValue(unsigned idx) const {
2287     assert(idx < getNumSuccessors() && "Successor # out of range!");
2288     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2289   }
2290
2291   // Methods for support type inquiry through isa, cast, and dyn_cast:
2292   static inline bool classof(const SwitchInst *) { return true; }
2293   static inline bool classof(const Instruction *I) {
2294     return I->getOpcode() == Instruction::Switch;
2295   }
2296   static inline bool classof(const Value *V) {
2297     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2298   }
2299 private:
2300   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2301   virtual unsigned getNumSuccessorsV() const;
2302   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2303 };
2304
2305 template <>
2306 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2307 };
2308
2309 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2310
2311
2312 //===----------------------------------------------------------------------===//
2313 //                               InvokeInst Class
2314 //===----------------------------------------------------------------------===//
2315
2316 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2317 /// calling convention of the call.
2318 ///
2319 class InvokeInst : public TerminatorInst {
2320   AttrListPtr AttributeList;
2321   InvokeInst(const InvokeInst &BI);
2322   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2323             Value* const *Args, unsigned NumArgs);
2324
2325   template<typename InputIterator>
2326   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2327             InputIterator ArgBegin, InputIterator ArgEnd,
2328             const Twine &NameStr,
2329             // This argument ensures that we have an iterator we can
2330             // do arithmetic on in constant time
2331             std::random_access_iterator_tag) {
2332     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2333
2334     // This requires that the iterator points to contiguous memory.
2335     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2336     setName(NameStr);
2337   }
2338
2339   /// Construct an InvokeInst given a range of arguments.
2340   /// InputIterator must be a random-access iterator pointing to
2341   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2342   /// made for random-accessness but not for contiguous storage as
2343   /// that would incur runtime overhead.
2344   ///
2345   /// @brief Construct an InvokeInst from a range of arguments
2346   template<typename InputIterator>
2347   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2348                     InputIterator ArgBegin, InputIterator ArgEnd,
2349                     unsigned Values,
2350                     const Twine &NameStr, Instruction *InsertBefore);
2351
2352   /// Construct an InvokeInst given a range of arguments.
2353   /// InputIterator must be a random-access iterator pointing to
2354   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2355   /// made for random-accessness but not for contiguous storage as
2356   /// that would incur runtime overhead.
2357   ///
2358   /// @brief Construct an InvokeInst from a range of arguments
2359   template<typename InputIterator>
2360   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2361                     InputIterator ArgBegin, InputIterator ArgEnd,
2362                     unsigned Values,
2363                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2364 public:
2365   template<typename InputIterator>
2366   static InvokeInst *Create(Value *Func,
2367                             BasicBlock *IfNormal, BasicBlock *IfException,
2368                             InputIterator ArgBegin, InputIterator ArgEnd,
2369                             const Twine &NameStr = "",
2370                             Instruction *InsertBefore = 0) {
2371     unsigned Values(ArgEnd - ArgBegin + 3);
2372     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2373                                   Values, NameStr, InsertBefore);
2374   }
2375   template<typename InputIterator>
2376   static InvokeInst *Create(Value *Func,
2377                             BasicBlock *IfNormal, BasicBlock *IfException,
2378                             InputIterator ArgBegin, InputIterator ArgEnd,
2379                             const Twine &NameStr,
2380                             BasicBlock *InsertAtEnd) {
2381     unsigned Values(ArgEnd - ArgBegin + 3);
2382     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2383                                   Values, NameStr, InsertAtEnd);
2384   }
2385
2386   virtual InvokeInst *clone() const;
2387
2388   /// Provide fast operand accessors
2389   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2390
2391   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2392   /// function call.
2393   CallingConv::ID getCallingConv() const {
2394     return static_cast<CallingConv::ID>(SubclassData);
2395   }
2396   void setCallingConv(CallingConv::ID CC) {
2397     SubclassData = static_cast<unsigned>(CC);
2398   }
2399
2400   /// getAttributes - Return the parameter attributes for this invoke.
2401   ///
2402   const AttrListPtr &getAttributes() const { return AttributeList; }
2403
2404   /// setAttributes - Set the parameter attributes for this invoke.
2405   ///
2406   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2407
2408   /// addAttribute - adds the attribute to the list of attributes.
2409   void addAttribute(unsigned i, Attributes attr);
2410
2411   /// removeAttribute - removes the attribute from the list of attributes.
2412   void removeAttribute(unsigned i, Attributes attr);
2413
2414   /// @brief Determine whether the call or the callee has the given attribute.
2415   bool paramHasAttr(unsigned i, Attributes attr) const;
2416
2417   /// @brief Extract the alignment for a call or parameter (0=unknown).
2418   unsigned getParamAlignment(unsigned i) const {
2419     return AttributeList.getParamAlignment(i);
2420   }
2421
2422   /// @brief Determine if the call does not access memory.
2423   bool doesNotAccessMemory() const {
2424     return paramHasAttr(~0, Attribute::ReadNone);
2425   }
2426   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2427     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2428     else removeAttribute(~0, Attribute::ReadNone);
2429   }
2430
2431   /// @brief Determine if the call does not access or only reads memory.
2432   bool onlyReadsMemory() const {
2433     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2434   }
2435   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2436     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2437     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2438   }
2439
2440   /// @brief Determine if the call cannot return.
2441   bool doesNotReturn() const {
2442     return paramHasAttr(~0, Attribute::NoReturn);
2443   }
2444   void setDoesNotReturn(bool DoesNotReturn = true) {
2445     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2446     else removeAttribute(~0, Attribute::NoReturn);
2447   }
2448
2449   /// @brief Determine if the call cannot unwind.
2450   bool doesNotThrow() const {
2451     return paramHasAttr(~0, Attribute::NoUnwind);
2452   }
2453   void setDoesNotThrow(bool DoesNotThrow = true) {
2454     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2455     else removeAttribute(~0, Attribute::NoUnwind);
2456   }
2457
2458   /// @brief Determine if the call returns a structure through first
2459   /// pointer argument.
2460   bool hasStructRetAttr() const {
2461     // Be friendly and also check the callee.
2462     return paramHasAttr(1, Attribute::StructRet);
2463   }
2464
2465   /// @brief Determine if any call argument is an aggregate passed by value.
2466   bool hasByValArgument() const {
2467     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2468   }
2469
2470   /// getCalledFunction - Return the function called, or null if this is an
2471   /// indirect function invocation.
2472   ///
2473   Function *getCalledFunction() const {
2474     return dyn_cast<Function>(getOperand(0));
2475   }
2476
2477   /// getCalledValue - Get a pointer to the function that is invoked by this
2478   /// instruction
2479   const Value *getCalledValue() const { return getOperand(0); }
2480         Value *getCalledValue()       { return getOperand(0); }
2481
2482   // get*Dest - Return the destination basic blocks...
2483   BasicBlock *getNormalDest() const {
2484     return cast<BasicBlock>(getOperand(1));
2485   }
2486   BasicBlock *getUnwindDest() const {
2487     return cast<BasicBlock>(getOperand(2));
2488   }
2489   void setNormalDest(BasicBlock *B) {
2490     setOperand(1, B);
2491   }
2492
2493   void setUnwindDest(BasicBlock *B) {
2494     setOperand(2, B);
2495   }
2496
2497   BasicBlock *getSuccessor(unsigned i) const {
2498     assert(i < 2 && "Successor # out of range for invoke!");
2499     return i == 0 ? getNormalDest() : getUnwindDest();
2500   }
2501
2502   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2503     assert(idx < 2 && "Successor # out of range for invoke!");
2504     setOperand(idx+1, NewSucc);
2505   }
2506
2507   unsigned getNumSuccessors() const { return 2; }
2508
2509   // Methods for support type inquiry through isa, cast, and dyn_cast:
2510   static inline bool classof(const InvokeInst *) { return true; }
2511   static inline bool classof(const Instruction *I) {
2512     return (I->getOpcode() == Instruction::Invoke);
2513   }
2514   static inline bool classof(const Value *V) {
2515     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2516   }
2517 private:
2518   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2519   virtual unsigned getNumSuccessorsV() const;
2520   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2521 };
2522
2523 template <>
2524 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2525 };
2526
2527 template<typename InputIterator>
2528 InvokeInst::InvokeInst(Value *Func,
2529                        BasicBlock *IfNormal, BasicBlock *IfException,
2530                        InputIterator ArgBegin, InputIterator ArgEnd,
2531                        unsigned Values,
2532                        const Twine &NameStr, Instruction *InsertBefore)
2533   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2534                                       ->getElementType())->getReturnType(),
2535                    Instruction::Invoke,
2536                    OperandTraits<InvokeInst>::op_end(this) - Values,
2537                    Values, InsertBefore) {
2538   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2539        typename std::iterator_traits<InputIterator>::iterator_category());
2540 }
2541 template<typename InputIterator>
2542 InvokeInst::InvokeInst(Value *Func,
2543                        BasicBlock *IfNormal, BasicBlock *IfException,
2544                        InputIterator ArgBegin, InputIterator ArgEnd,
2545                        unsigned Values,
2546                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2547   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2548                                       ->getElementType())->getReturnType(),
2549                    Instruction::Invoke,
2550                    OperandTraits<InvokeInst>::op_end(this) - Values,
2551                    Values, InsertAtEnd) {
2552   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2553        typename std::iterator_traits<InputIterator>::iterator_category());
2554 }
2555
2556 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2557
2558 //===----------------------------------------------------------------------===//
2559 //                              UnwindInst Class
2560 //===----------------------------------------------------------------------===//
2561
2562 //===---------------------------------------------------------------------------
2563 /// UnwindInst - Immediately exit the current function, unwinding the stack
2564 /// until an invoke instruction is found.
2565 ///
2566 class UnwindInst : public TerminatorInst {
2567   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2568 public:
2569   // allocate space for exactly zero operands
2570   void *operator new(size_t s) {
2571     return User::operator new(s, 0);
2572   }
2573   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2574   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2575
2576   virtual UnwindInst *clone() const;
2577
2578   unsigned getNumSuccessors() const { return 0; }
2579
2580   // Methods for support type inquiry through isa, cast, and dyn_cast:
2581   static inline bool classof(const UnwindInst *) { return true; }
2582   static inline bool classof(const Instruction *I) {
2583     return I->getOpcode() == Instruction::Unwind;
2584   }
2585   static inline bool classof(const Value *V) {
2586     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2587   }
2588 private:
2589   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2590   virtual unsigned getNumSuccessorsV() const;
2591   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2592 };
2593
2594 //===----------------------------------------------------------------------===//
2595 //                           UnreachableInst Class
2596 //===----------------------------------------------------------------------===//
2597
2598 //===---------------------------------------------------------------------------
2599 /// UnreachableInst - This function has undefined behavior.  In particular, the
2600 /// presence of this instruction indicates some higher level knowledge that the
2601 /// end of the block cannot be reached.
2602 ///
2603 class UnreachableInst : public TerminatorInst {
2604   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2605 public:
2606   // allocate space for exactly zero operands
2607   void *operator new(size_t s) {
2608     return User::operator new(s, 0);
2609   }
2610   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2611   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2612
2613   virtual UnreachableInst *clone() const;
2614
2615   unsigned getNumSuccessors() const { return 0; }
2616
2617   // Methods for support type inquiry through isa, cast, and dyn_cast:
2618   static inline bool classof(const UnreachableInst *) { return true; }
2619   static inline bool classof(const Instruction *I) {
2620     return I->getOpcode() == Instruction::Unreachable;
2621   }
2622   static inline bool classof(const Value *V) {
2623     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2624   }
2625 private:
2626   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2627   virtual unsigned getNumSuccessorsV() const;
2628   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2629 };
2630
2631 //===----------------------------------------------------------------------===//
2632 //                                 TruncInst Class
2633 //===----------------------------------------------------------------------===//
2634
2635 /// @brief This class represents a truncation of integer types.
2636 class TruncInst : public CastInst {
2637 public:
2638   /// @brief Constructor with insert-before-instruction semantics
2639   TruncInst(
2640     Value *S,                     ///< The value to be truncated
2641     const Type *Ty,               ///< The (smaller) type to truncate to
2642     const Twine &NameStr = "", ///< A name for the new instruction
2643     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2644   );
2645
2646   /// @brief Constructor with insert-at-end-of-block semantics
2647   TruncInst(
2648     Value *S,                     ///< The value to be truncated
2649     const Type *Ty,               ///< The (smaller) type to truncate to
2650     const Twine &NameStr,   ///< A name for the new instruction
2651     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2652   );
2653
2654   /// @brief Clone an identical TruncInst
2655   virtual TruncInst *clone() const;
2656
2657   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2658   static inline bool classof(const TruncInst *) { return true; }
2659   static inline bool classof(const Instruction *I) {
2660     return I->getOpcode() == Trunc;
2661   }
2662   static inline bool classof(const Value *V) {
2663     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2664   }
2665 };
2666
2667 //===----------------------------------------------------------------------===//
2668 //                                 ZExtInst Class
2669 //===----------------------------------------------------------------------===//
2670
2671 /// @brief This class represents zero extension of integer types.
2672 class ZExtInst : public CastInst {
2673 public:
2674   /// @brief Constructor with insert-before-instruction semantics
2675   ZExtInst(
2676     Value *S,                     ///< The value to be zero extended
2677     const Type *Ty,               ///< The type to zero extend to
2678     const Twine &NameStr = "", ///< A name for the new instruction
2679     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2680   );
2681
2682   /// @brief Constructor with insert-at-end semantics.
2683   ZExtInst(
2684     Value *S,                     ///< The value to be zero extended
2685     const Type *Ty,               ///< The type to zero extend to
2686     const Twine &NameStr,   ///< A name for the new instruction
2687     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2688   );
2689
2690   /// @brief Clone an identical ZExtInst
2691   virtual ZExtInst *clone() const;
2692
2693   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2694   static inline bool classof(const ZExtInst *) { return true; }
2695   static inline bool classof(const Instruction *I) {
2696     return I->getOpcode() == ZExt;
2697   }
2698   static inline bool classof(const Value *V) {
2699     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2700   }
2701 };
2702
2703 //===----------------------------------------------------------------------===//
2704 //                                 SExtInst Class
2705 //===----------------------------------------------------------------------===//
2706
2707 /// @brief This class represents a sign extension of integer types.
2708 class SExtInst : public CastInst {
2709 public:
2710   /// @brief Constructor with insert-before-instruction semantics
2711   SExtInst(
2712     Value *S,                     ///< The value to be sign extended
2713     const Type *Ty,               ///< The type to sign extend to
2714     const Twine &NameStr = "", ///< A name for the new instruction
2715     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2716   );
2717
2718   /// @brief Constructor with insert-at-end-of-block semantics
2719   SExtInst(
2720     Value *S,                     ///< The value to be sign extended
2721     const Type *Ty,               ///< The type to sign extend to
2722     const Twine &NameStr,   ///< A name for the new instruction
2723     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2724   );
2725
2726   /// @brief Clone an identical SExtInst
2727   virtual SExtInst *clone() const;
2728
2729   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2730   static inline bool classof(const SExtInst *) { return true; }
2731   static inline bool classof(const Instruction *I) {
2732     return I->getOpcode() == SExt;
2733   }
2734   static inline bool classof(const Value *V) {
2735     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2736   }
2737 };
2738
2739 //===----------------------------------------------------------------------===//
2740 //                                 FPTruncInst Class
2741 //===----------------------------------------------------------------------===//
2742
2743 /// @brief This class represents a truncation of floating point types.
2744 class FPTruncInst : public CastInst {
2745 public:
2746   /// @brief Constructor with insert-before-instruction semantics
2747   FPTruncInst(
2748     Value *S,                     ///< The value to be truncated
2749     const Type *Ty,               ///< The type to truncate to
2750     const Twine &NameStr = "", ///< A name for the new instruction
2751     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2752   );
2753
2754   /// @brief Constructor with insert-before-instruction semantics
2755   FPTruncInst(
2756     Value *S,                     ///< The value to be truncated
2757     const Type *Ty,               ///< The type to truncate to
2758     const Twine &NameStr,   ///< A name for the new instruction
2759     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2760   );
2761
2762   /// @brief Clone an identical FPTruncInst
2763   virtual FPTruncInst *clone() const;
2764
2765   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2766   static inline bool classof(const FPTruncInst *) { return true; }
2767   static inline bool classof(const Instruction *I) {
2768     return I->getOpcode() == FPTrunc;
2769   }
2770   static inline bool classof(const Value *V) {
2771     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2772   }
2773 };
2774
2775 //===----------------------------------------------------------------------===//
2776 //                                 FPExtInst Class
2777 //===----------------------------------------------------------------------===//
2778
2779 /// @brief This class represents an extension of floating point types.
2780 class FPExtInst : public CastInst {
2781 public:
2782   /// @brief Constructor with insert-before-instruction semantics
2783   FPExtInst(
2784     Value *S,                     ///< The value to be extended
2785     const Type *Ty,               ///< The type to extend to
2786     const Twine &NameStr = "", ///< A name for the new instruction
2787     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2788   );
2789
2790   /// @brief Constructor with insert-at-end-of-block semantics
2791   FPExtInst(
2792     Value *S,                     ///< The value to be extended
2793     const Type *Ty,               ///< The type to extend to
2794     const Twine &NameStr,   ///< A name for the new instruction
2795     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2796   );
2797
2798   /// @brief Clone an identical FPExtInst
2799   virtual FPExtInst *clone() const;
2800
2801   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2802   static inline bool classof(const FPExtInst *) { return true; }
2803   static inline bool classof(const Instruction *I) {
2804     return I->getOpcode() == FPExt;
2805   }
2806   static inline bool classof(const Value *V) {
2807     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2808   }
2809 };
2810
2811 //===----------------------------------------------------------------------===//
2812 //                                 UIToFPInst Class
2813 //===----------------------------------------------------------------------===//
2814
2815 /// @brief This class represents a cast unsigned integer to floating point.
2816 class UIToFPInst : public CastInst {
2817 public:
2818   /// @brief Constructor with insert-before-instruction semantics
2819   UIToFPInst(
2820     Value *S,                     ///< The value to be converted
2821     const Type *Ty,               ///< The type to convert to
2822     const Twine &NameStr = "", ///< A name for the new instruction
2823     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2824   );
2825
2826   /// @brief Constructor with insert-at-end-of-block semantics
2827   UIToFPInst(
2828     Value *S,                     ///< The value to be converted
2829     const Type *Ty,               ///< The type to convert to
2830     const Twine &NameStr,   ///< A name for the new instruction
2831     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2832   );
2833
2834   /// @brief Clone an identical UIToFPInst
2835   virtual UIToFPInst *clone() const;
2836
2837   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2838   static inline bool classof(const UIToFPInst *) { return true; }
2839   static inline bool classof(const Instruction *I) {
2840     return I->getOpcode() == UIToFP;
2841   }
2842   static inline bool classof(const Value *V) {
2843     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2844   }
2845 };
2846
2847 //===----------------------------------------------------------------------===//
2848 //                                 SIToFPInst Class
2849 //===----------------------------------------------------------------------===//
2850
2851 /// @brief This class represents a cast from signed integer to floating point.
2852 class SIToFPInst : public CastInst {
2853 public:
2854   /// @brief Constructor with insert-before-instruction semantics
2855   SIToFPInst(
2856     Value *S,                     ///< The value to be converted
2857     const Type *Ty,               ///< The type to convert to
2858     const Twine &NameStr = "", ///< A name for the new instruction
2859     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2860   );
2861
2862   /// @brief Constructor with insert-at-end-of-block semantics
2863   SIToFPInst(
2864     Value *S,                     ///< The value to be converted
2865     const Type *Ty,               ///< The type to convert to
2866     const Twine &NameStr,   ///< A name for the new instruction
2867     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2868   );
2869
2870   /// @brief Clone an identical SIToFPInst
2871   virtual SIToFPInst *clone() const;
2872
2873   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2874   static inline bool classof(const SIToFPInst *) { return true; }
2875   static inline bool classof(const Instruction *I) {
2876     return I->getOpcode() == SIToFP;
2877   }
2878   static inline bool classof(const Value *V) {
2879     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2880   }
2881 };
2882
2883 //===----------------------------------------------------------------------===//
2884 //                                 FPToUIInst Class
2885 //===----------------------------------------------------------------------===//
2886
2887 /// @brief This class represents a cast from floating point to unsigned integer
2888 class FPToUIInst  : public CastInst {
2889 public:
2890   /// @brief Constructor with insert-before-instruction semantics
2891   FPToUIInst(
2892     Value *S,                     ///< The value to be converted
2893     const Type *Ty,               ///< The type to convert to
2894     const Twine &NameStr = "", ///< A name for the new instruction
2895     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2896   );
2897
2898   /// @brief Constructor with insert-at-end-of-block semantics
2899   FPToUIInst(
2900     Value *S,                     ///< The value to be converted
2901     const Type *Ty,               ///< The type to convert to
2902     const Twine &NameStr,   ///< A name for the new instruction
2903     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2904   );
2905
2906   /// @brief Clone an identical FPToUIInst
2907   virtual FPToUIInst *clone() const;
2908
2909   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2910   static inline bool classof(const FPToUIInst *) { return true; }
2911   static inline bool classof(const Instruction *I) {
2912     return I->getOpcode() == FPToUI;
2913   }
2914   static inline bool classof(const Value *V) {
2915     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2916   }
2917 };
2918
2919 //===----------------------------------------------------------------------===//
2920 //                                 FPToSIInst Class
2921 //===----------------------------------------------------------------------===//
2922
2923 /// @brief This class represents a cast from floating point to signed integer.
2924 class FPToSIInst  : public CastInst {
2925 public:
2926   /// @brief Constructor with insert-before-instruction semantics
2927   FPToSIInst(
2928     Value *S,                     ///< The value to be converted
2929     const Type *Ty,               ///< The type to convert to
2930     const Twine &NameStr = "", ///< A name for the new instruction
2931     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2932   );
2933
2934   /// @brief Constructor with insert-at-end-of-block semantics
2935   FPToSIInst(
2936     Value *S,                     ///< The value to be converted
2937     const Type *Ty,               ///< The type to convert to
2938     const Twine &NameStr,   ///< A name for the new instruction
2939     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2940   );
2941
2942   /// @brief Clone an identical FPToSIInst
2943   virtual FPToSIInst *clone() const;
2944
2945   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2946   static inline bool classof(const FPToSIInst *) { return true; }
2947   static inline bool classof(const Instruction *I) {
2948     return I->getOpcode() == FPToSI;
2949   }
2950   static inline bool classof(const Value *V) {
2951     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2952   }
2953 };
2954
2955 //===----------------------------------------------------------------------===//
2956 //                                 IntToPtrInst Class
2957 //===----------------------------------------------------------------------===//
2958
2959 /// @brief This class represents a cast from an integer to a pointer.
2960 class IntToPtrInst : public CastInst {
2961 public:
2962   /// @brief Constructor with insert-before-instruction semantics
2963   IntToPtrInst(
2964     Value *S,                     ///< The value to be converted
2965     const Type *Ty,               ///< The type to convert to
2966     const Twine &NameStr = "", ///< A name for the new instruction
2967     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2968   );
2969
2970   /// @brief Constructor with insert-at-end-of-block semantics
2971   IntToPtrInst(
2972     Value *S,                     ///< The value to be converted
2973     const Type *Ty,               ///< The type to convert to
2974     const Twine &NameStr,   ///< A name for the new instruction
2975     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2976   );
2977
2978   /// @brief Clone an identical IntToPtrInst
2979   virtual IntToPtrInst *clone() const;
2980
2981   // Methods for support type inquiry through isa, cast, and dyn_cast:
2982   static inline bool classof(const IntToPtrInst *) { return true; }
2983   static inline bool classof(const Instruction *I) {
2984     return I->getOpcode() == IntToPtr;
2985   }
2986   static inline bool classof(const Value *V) {
2987     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2988   }
2989 };
2990
2991 //===----------------------------------------------------------------------===//
2992 //                                 PtrToIntInst Class
2993 //===----------------------------------------------------------------------===//
2994
2995 /// @brief This class represents a cast from a pointer to an integer
2996 class PtrToIntInst : public CastInst {
2997 public:
2998   /// @brief Constructor with insert-before-instruction semantics
2999   PtrToIntInst(
3000     Value *S,                     ///< The value to be converted
3001     const Type *Ty,               ///< The type to convert to
3002     const Twine &NameStr = "", ///< A name for the new instruction
3003     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3004   );
3005
3006   /// @brief Constructor with insert-at-end-of-block semantics
3007   PtrToIntInst(
3008     Value *S,                     ///< The value to be converted
3009     const Type *Ty,               ///< The type to convert to
3010     const Twine &NameStr,   ///< A name for the new instruction
3011     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3012   );
3013
3014   /// @brief Clone an identical PtrToIntInst
3015   virtual PtrToIntInst *clone() const;
3016
3017   // Methods for support type inquiry through isa, cast, and dyn_cast:
3018   static inline bool classof(const PtrToIntInst *) { return true; }
3019   static inline bool classof(const Instruction *I) {
3020     return I->getOpcode() == PtrToInt;
3021   }
3022   static inline bool classof(const Value *V) {
3023     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3024   }
3025 };
3026
3027 //===----------------------------------------------------------------------===//
3028 //                             BitCastInst Class
3029 //===----------------------------------------------------------------------===//
3030
3031 /// @brief This class represents a no-op cast from one type to another.
3032 class BitCastInst : public CastInst {
3033 public:
3034   /// @brief Constructor with insert-before-instruction semantics
3035   BitCastInst(
3036     Value *S,                     ///< The value to be casted
3037     const Type *Ty,               ///< The type to casted to
3038     const Twine &NameStr = "", ///< A name for the new instruction
3039     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3040   );
3041
3042   /// @brief Constructor with insert-at-end-of-block semantics
3043   BitCastInst(
3044     Value *S,                     ///< The value to be casted
3045     const Type *Ty,               ///< The type to casted to
3046     const Twine &NameStr,      ///< A name for the new instruction
3047     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3048   );
3049
3050   /// @brief Clone an identical BitCastInst
3051   virtual BitCastInst *clone() const;
3052
3053   // Methods for support type inquiry through isa, cast, and dyn_cast:
3054   static inline bool classof(const BitCastInst *) { return true; }
3055   static inline bool classof(const Instruction *I) {
3056     return I->getOpcode() == BitCast;
3057   }
3058   static inline bool classof(const Value *V) {
3059     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3060   }
3061 };
3062
3063 } // End llvm namespace
3064
3065 #endif