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