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