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