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