Add a couple of convenience functions:
[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(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
1810
1811   explicit LandingPadInst(Type *RetTy, Value *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, Value *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, Value *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, Value *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 Value *getPersonalityFn() const { return getOperand(0); }
1849
1850   // Simple accessors.
1851   bool isCleanup() const { return IsCleanup; }
1852   void setCleanup(bool Val) { IsCleanup = Val; }
1853
1854   /// addClause - Add a clause to the landing pad.
1855   void addClause(ClauseType CT, Value *ClauseVal);
1856
1857   /// getClauseType - Return the type of the clause at this index. The two
1858   /// supported clauses are Catch and Filter.
1859   ClauseType getClauseType(unsigned I) const {
1860     assert(I < ClauseIdxs.size() && "Index too large!");
1861     return ClauseIdxs[I];
1862   }
1863
1864   /// getClauseValue - Return the value of the clause at this index.
1865   Value *getClauseValue(unsigned I) const {
1866     assert(I + 1 < getNumOperands() && "Index too large!");
1867     return OperandList[I + 1];
1868   }
1869
1870   /// getNumClauses - Get the number of clauses for this landing pad.
1871   unsigned getNumClauses() const { return getNumOperands() - 1; }
1872
1873   /// reserveClauses - Grow the size of the operand list to accomodate the new
1874   /// number of clauses.
1875   void reserveClauses(unsigned Size);
1876
1877   // Methods for support type inquiry through isa, cast, and dyn_cast:
1878   static inline bool classof(const LandingPadInst *) { return true; }
1879   static inline bool classof(const Instruction *I) {
1880     return I->getOpcode() == Instruction::LandingPad;
1881   }
1882   static inline bool classof(const Value *V) {
1883     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1884   }
1885 };
1886
1887 template <>
1888 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
1889 };
1890
1891 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
1892
1893 //===----------------------------------------------------------------------===//
1894 //                               ReturnInst Class
1895 //===----------------------------------------------------------------------===//
1896
1897 //===---------------------------------------------------------------------------
1898 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1899 /// does not continue in this function any longer.
1900 ///
1901 class ReturnInst : public TerminatorInst {
1902   ReturnInst(const ReturnInst &RI);
1903
1904 private:
1905   // ReturnInst constructors:
1906   // ReturnInst()                  - 'ret void' instruction
1907   // ReturnInst(    null)          - 'ret void' instruction
1908   // ReturnInst(Value* X)          - 'ret X'    instruction
1909   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1910   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1911   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1912   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1913   //
1914   // NOTE: If the Value* passed is of type void then the constructor behaves as
1915   // if it was passed NULL.
1916   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1917                       Instruction *InsertBefore = 0);
1918   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1919   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1920 protected:
1921   virtual ReturnInst *clone_impl() const;
1922 public:
1923   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1924                             Instruction *InsertBefore = 0) {
1925     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1926   }
1927   static ReturnInst* Create(LLVMContext &C, Value *retVal,
1928                             BasicBlock *InsertAtEnd) {
1929     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1930   }
1931   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1932     return new(0) ReturnInst(C, InsertAtEnd);
1933   }
1934   virtual ~ReturnInst();
1935
1936   /// Provide fast operand accessors
1937   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1938
1939   /// Convenience accessor. Returns null if there is no return value.
1940   Value *getReturnValue() const {
1941     return getNumOperands() != 0 ? getOperand(0) : 0;
1942   }
1943
1944   unsigned getNumSuccessors() const { return 0; }
1945
1946   // Methods for support type inquiry through isa, cast, and dyn_cast:
1947   static inline bool classof(const ReturnInst *) { return true; }
1948   static inline bool classof(const Instruction *I) {
1949     return (I->getOpcode() == Instruction::Ret);
1950   }
1951   static inline bool classof(const Value *V) {
1952     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1953   }
1954  private:
1955   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1956   virtual unsigned getNumSuccessorsV() const;
1957   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1958 };
1959
1960 template <>
1961 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1962 };
1963
1964 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1965
1966 //===----------------------------------------------------------------------===//
1967 //                               BranchInst Class
1968 //===----------------------------------------------------------------------===//
1969
1970 //===---------------------------------------------------------------------------
1971 /// BranchInst - Conditional or Unconditional Branch instruction.
1972 ///
1973 class BranchInst : public TerminatorInst {
1974   /// Ops list - Branches are strange.  The operands are ordered:
1975   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
1976   /// they don't have to check for cond/uncond branchness. These are mostly
1977   /// accessed relative from op_end().
1978   BranchInst(const BranchInst &BI);
1979   void AssertOK();
1980   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1981   // BranchInst(BB *B)                           - 'br B'
1982   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1983   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1984   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1985   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1986   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1987   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1988   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1989              Instruction *InsertBefore = 0);
1990   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1991   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1992              BasicBlock *InsertAtEnd);
1993 protected:
1994   virtual BranchInst *clone_impl() const;
1995 public:
1996   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1997     return new(1) BranchInst(IfTrue, InsertBefore);
1998   }
1999   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2000                             Value *Cond, Instruction *InsertBefore = 0) {
2001     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2002   }
2003   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2004     return new(1) BranchInst(IfTrue, InsertAtEnd);
2005   }
2006   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2007                             Value *Cond, BasicBlock *InsertAtEnd) {
2008     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2009   }
2010
2011   /// Transparently provide more efficient getOperand methods.
2012   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2013
2014   bool isUnconditional() const { return getNumOperands() == 1; }
2015   bool isConditional()   const { return getNumOperands() == 3; }
2016
2017   Value *getCondition() const {
2018     assert(isConditional() && "Cannot get condition of an uncond branch!");
2019     return Op<-3>();
2020   }
2021
2022   void setCondition(Value *V) {
2023     assert(isConditional() && "Cannot set condition of unconditional branch!");
2024     Op<-3>() = V;
2025   }
2026
2027   unsigned getNumSuccessors() const { return 1+isConditional(); }
2028
2029   BasicBlock *getSuccessor(unsigned i) const {
2030     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2031     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2032   }
2033
2034   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2035     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2036     *(&Op<-1>() - idx) = (Value*)NewSucc;
2037   }
2038
2039   // Methods for support type inquiry through isa, cast, and dyn_cast:
2040   static inline bool classof(const BranchInst *) { return true; }
2041   static inline bool classof(const Instruction *I) {
2042     return (I->getOpcode() == Instruction::Br);
2043   }
2044   static inline bool classof(const Value *V) {
2045     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2046   }
2047 private:
2048   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2049   virtual unsigned getNumSuccessorsV() const;
2050   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2051 };
2052
2053 template <>
2054 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2055 };
2056
2057 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2058
2059 //===----------------------------------------------------------------------===//
2060 //                               SwitchInst Class
2061 //===----------------------------------------------------------------------===//
2062
2063 //===---------------------------------------------------------------------------
2064 /// SwitchInst - Multiway switch
2065 ///
2066 class SwitchInst : public TerminatorInst {
2067   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2068   unsigned ReservedSpace;
2069   // Operand[0]    = Value to switch on
2070   // Operand[1]    = Default basic block destination
2071   // Operand[2n  ] = Value to match
2072   // Operand[2n+1] = BasicBlock to go to on match
2073   SwitchInst(const SwitchInst &SI);
2074   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2075   void growOperands();
2076   // allocate space for exactly zero operands
2077   void *operator new(size_t s) {
2078     return User::operator new(s, 0);
2079   }
2080   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2081   /// switch on and a default destination.  The number of additional cases can
2082   /// be specified here to make memory allocation more efficient.  This
2083   /// constructor can also autoinsert before another instruction.
2084   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2085              Instruction *InsertBefore);
2086
2087   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2088   /// switch on and a default destination.  The number of additional cases can
2089   /// be specified here to make memory allocation more efficient.  This
2090   /// constructor also autoinserts at the end of the specified BasicBlock.
2091   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2092              BasicBlock *InsertAtEnd);
2093 protected:
2094   virtual SwitchInst *clone_impl() const;
2095 public:
2096   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2097                             unsigned NumCases, Instruction *InsertBefore = 0) {
2098     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2099   }
2100   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2101                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2102     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2103   }
2104   ~SwitchInst();
2105
2106   /// Provide fast operand accessors
2107   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2108
2109   // Accessor Methods for Switch stmt
2110   Value *getCondition() const { return getOperand(0); }
2111   void setCondition(Value *V) { setOperand(0, V); }
2112
2113   BasicBlock *getDefaultDest() const {
2114     return cast<BasicBlock>(getOperand(1));
2115   }
2116
2117   /// getNumCases - return the number of 'cases' in this switch instruction.
2118   /// Note that case #0 is always the default case.
2119   unsigned getNumCases() const {
2120     return getNumOperands()/2;
2121   }
2122
2123   /// getCaseValue - Return the specified case value.  Note that case #0, the
2124   /// default destination, does not have a case value.
2125   ConstantInt *getCaseValue(unsigned i) {
2126     assert(i && i < getNumCases() && "Illegal case value to get!");
2127     return getSuccessorValue(i);
2128   }
2129
2130   /// getCaseValue - Return the specified case value.  Note that case #0, the
2131   /// default destination, does not have a case value.
2132   const ConstantInt *getCaseValue(unsigned i) const {
2133     assert(i && i < getNumCases() && "Illegal case value to get!");
2134     return getSuccessorValue(i);
2135   }
2136
2137   /// findCaseValue - Search all of the case values for the specified constant.
2138   /// If it is explicitly handled, return the case number of it, otherwise
2139   /// return 0 to indicate that it is handled by the default handler.
2140   unsigned findCaseValue(const ConstantInt *C) const {
2141     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2142       if (getCaseValue(i) == C)
2143         return i;
2144     return 0;
2145   }
2146
2147   /// findCaseDest - Finds the unique case value for a given successor. Returns
2148   /// null if the successor is not found, not unique, or is the default case.
2149   ConstantInt *findCaseDest(BasicBlock *BB) {
2150     if (BB == getDefaultDest()) return NULL;
2151
2152     ConstantInt *CI = NULL;
2153     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2154       if (getSuccessor(i) == BB) {
2155         if (CI) return NULL;   // Multiple cases lead to BB.
2156         else CI = getCaseValue(i);
2157       }
2158     }
2159     return CI;
2160   }
2161
2162   /// addCase - Add an entry to the switch instruction...
2163   ///
2164   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2165
2166   /// removeCase - This method removes the specified successor from the switch
2167   /// instruction.  Note that this cannot be used to remove the default
2168   /// destination (successor #0). Also note that this operation may reorder the
2169   /// remaining cases at index idx and above.
2170   ///
2171   void removeCase(unsigned idx);
2172
2173   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2174   BasicBlock *getSuccessor(unsigned idx) const {
2175     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2176     return cast<BasicBlock>(getOperand(idx*2+1));
2177   }
2178   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2179     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2180     setOperand(idx*2+1, (Value*)NewSucc);
2181   }
2182
2183   // getSuccessorValue - Return the value associated with the specified
2184   // successor.
2185   ConstantInt *getSuccessorValue(unsigned idx) const {
2186     assert(idx < getNumSuccessors() && "Successor # out of range!");
2187     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2188   }
2189
2190   // Methods for support type inquiry through isa, cast, and dyn_cast:
2191   static inline bool classof(const SwitchInst *) { return true; }
2192   static inline bool classof(const Instruction *I) {
2193     return I->getOpcode() == Instruction::Switch;
2194   }
2195   static inline bool classof(const Value *V) {
2196     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2197   }
2198 private:
2199   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2200   virtual unsigned getNumSuccessorsV() const;
2201   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2202 };
2203
2204 template <>
2205 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2206 };
2207
2208 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2209
2210
2211 //===----------------------------------------------------------------------===//
2212 //                             IndirectBrInst Class
2213 //===----------------------------------------------------------------------===//
2214
2215 //===---------------------------------------------------------------------------
2216 /// IndirectBrInst - Indirect Branch Instruction.
2217 ///
2218 class IndirectBrInst : public TerminatorInst {
2219   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2220   unsigned ReservedSpace;
2221   // Operand[0]    = Value to switch on
2222   // Operand[1]    = Default basic block destination
2223   // Operand[2n  ] = Value to match
2224   // Operand[2n+1] = BasicBlock to go to on match
2225   IndirectBrInst(const IndirectBrInst &IBI);
2226   void init(Value *Address, unsigned NumDests);
2227   void growOperands();
2228   // allocate space for exactly zero operands
2229   void *operator new(size_t s) {
2230     return User::operator new(s, 0);
2231   }
2232   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2233   /// Address to jump to.  The number of expected destinations can be specified
2234   /// here to make memory allocation more efficient.  This constructor can also
2235   /// autoinsert before another instruction.
2236   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2237
2238   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2239   /// Address to jump to.  The number of expected destinations can be specified
2240   /// here to make memory allocation more efficient.  This constructor also
2241   /// autoinserts at the end of the specified BasicBlock.
2242   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2243 protected:
2244   virtual IndirectBrInst *clone_impl() const;
2245 public:
2246   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2247                                 Instruction *InsertBefore = 0) {
2248     return new IndirectBrInst(Address, NumDests, InsertBefore);
2249   }
2250   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2251                                 BasicBlock *InsertAtEnd) {
2252     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2253   }
2254   ~IndirectBrInst();
2255
2256   /// Provide fast operand accessors.
2257   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2258
2259   // Accessor Methods for IndirectBrInst instruction.
2260   Value *getAddress() { return getOperand(0); }
2261   const Value *getAddress() const { return getOperand(0); }
2262   void setAddress(Value *V) { setOperand(0, V); }
2263
2264
2265   /// getNumDestinations - return the number of possible destinations in this
2266   /// indirectbr instruction.
2267   unsigned getNumDestinations() const { return getNumOperands()-1; }
2268
2269   /// getDestination - Return the specified destination.
2270   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2271   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2272
2273   /// addDestination - Add a destination.
2274   ///
2275   void addDestination(BasicBlock *Dest);
2276
2277   /// removeDestination - This method removes the specified successor from the
2278   /// indirectbr instruction.
2279   void removeDestination(unsigned i);
2280
2281   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2282   BasicBlock *getSuccessor(unsigned i) const {
2283     return cast<BasicBlock>(getOperand(i+1));
2284   }
2285   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2286     setOperand(i+1, (Value*)NewSucc);
2287   }
2288
2289   // Methods for support type inquiry through isa, cast, and dyn_cast:
2290   static inline bool classof(const IndirectBrInst *) { return true; }
2291   static inline bool classof(const Instruction *I) {
2292     return I->getOpcode() == Instruction::IndirectBr;
2293   }
2294   static inline bool classof(const Value *V) {
2295     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2296   }
2297 private:
2298   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2299   virtual unsigned getNumSuccessorsV() const;
2300   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2301 };
2302
2303 template <>
2304 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2305 };
2306
2307 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2308
2309
2310 //===----------------------------------------------------------------------===//
2311 //                               InvokeInst Class
2312 //===----------------------------------------------------------------------===//
2313
2314 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2315 /// calling convention of the call.
2316 ///
2317 class InvokeInst : public TerminatorInst {
2318   AttrListPtr AttributeList;
2319   InvokeInst(const InvokeInst &BI);
2320   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2321             ArrayRef<Value *> Args, const Twine &NameStr);
2322
2323   /// Construct an InvokeInst given a range of arguments.
2324   ///
2325   /// @brief Construct an InvokeInst from a range of arguments
2326   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2327                     ArrayRef<Value *> Args, unsigned Values,
2328                     const Twine &NameStr, Instruction *InsertBefore);
2329
2330   /// Construct an InvokeInst given a range of arguments.
2331   ///
2332   /// @brief Construct an InvokeInst from a range of arguments
2333   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2334                     ArrayRef<Value *> Args, unsigned Values,
2335                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2336 protected:
2337   virtual InvokeInst *clone_impl() const;
2338 public:
2339   static InvokeInst *Create(Value *Func,
2340                             BasicBlock *IfNormal, BasicBlock *IfException,
2341                             ArrayRef<Value *> Args, const Twine &NameStr = "",
2342                             Instruction *InsertBefore = 0) {
2343     unsigned Values = unsigned(Args.size()) + 3;
2344     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2345                                   Values, NameStr, InsertBefore);
2346   }
2347   static InvokeInst *Create(Value *Func,
2348                             BasicBlock *IfNormal, BasicBlock *IfException,
2349                             ArrayRef<Value *> Args, const Twine &NameStr,
2350                             BasicBlock *InsertAtEnd) {
2351     unsigned Values = unsigned(Args.size()) + 3;
2352     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2353                                   Values, NameStr, InsertAtEnd);
2354   }
2355
2356   /// Provide fast operand accessors
2357   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2358
2359   /// getNumArgOperands - Return the number of invoke arguments.
2360   ///
2361   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2362
2363   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2364   ///
2365   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2366   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2367
2368   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2369   /// function call.
2370   CallingConv::ID getCallingConv() const {
2371     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2372   }
2373   void setCallingConv(CallingConv::ID CC) {
2374     setInstructionSubclassData(static_cast<unsigned>(CC));
2375   }
2376
2377   /// getAttributes - Return the parameter attributes for this invoke.
2378   ///
2379   const AttrListPtr &getAttributes() const { return AttributeList; }
2380
2381   /// setAttributes - Set the parameter attributes for this invoke.
2382   ///
2383   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2384
2385   /// addAttribute - adds the attribute to the list of attributes.
2386   void addAttribute(unsigned i, Attributes attr);
2387
2388   /// removeAttribute - removes the attribute from the list of attributes.
2389   void removeAttribute(unsigned i, Attributes attr);
2390
2391   /// @brief Determine whether the call or the callee has the given attribute.
2392   bool paramHasAttr(unsigned i, Attributes attr) const;
2393
2394   /// @brief Extract the alignment for a call or parameter (0=unknown).
2395   unsigned getParamAlignment(unsigned i) const {
2396     return AttributeList.getParamAlignment(i);
2397   }
2398
2399   /// @brief Return true if the call should not be inlined.
2400   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2401   void setIsNoInline(bool Value = true) {
2402     if (Value) addAttribute(~0, Attribute::NoInline);
2403     else removeAttribute(~0, Attribute::NoInline);
2404   }
2405
2406   /// @brief Determine if the call does not access memory.
2407   bool doesNotAccessMemory() const {
2408     return paramHasAttr(~0, Attribute::ReadNone);
2409   }
2410   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2411     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2412     else removeAttribute(~0, Attribute::ReadNone);
2413   }
2414
2415   /// @brief Determine if the call does not access or only reads memory.
2416   bool onlyReadsMemory() const {
2417     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2418   }
2419   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2420     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2421     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2422   }
2423
2424   /// @brief Determine if the call cannot return.
2425   bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2426   void setDoesNotReturn(bool DoesNotReturn = true) {
2427     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2428     else removeAttribute(~0, Attribute::NoReturn);
2429   }
2430
2431   /// @brief Determine if the call cannot unwind.
2432   bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2433   void setDoesNotThrow(bool DoesNotThrow = true) {
2434     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2435     else removeAttribute(~0, Attribute::NoUnwind);
2436   }
2437
2438   /// @brief Determine if the call returns a structure through first
2439   /// pointer argument.
2440   bool hasStructRetAttr() const {
2441     // Be friendly and also check the callee.
2442     return paramHasAttr(1, Attribute::StructRet);
2443   }
2444
2445   /// @brief Determine if any call argument is an aggregate passed by value.
2446   bool hasByValArgument() const {
2447     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2448   }
2449
2450   /// getCalledFunction - Return the function called, or null if this is an
2451   /// indirect function invocation.
2452   ///
2453   Function *getCalledFunction() const {
2454     return dyn_cast<Function>(Op<-3>());
2455   }
2456
2457   /// getCalledValue - Get a pointer to the function that is invoked by this
2458   /// instruction
2459   const Value *getCalledValue() const { return Op<-3>(); }
2460         Value *getCalledValue()       { return Op<-3>(); }
2461
2462   /// setCalledFunction - Set the function called.
2463   void setCalledFunction(Value* Fn) {
2464     Op<-3>() = Fn;
2465   }
2466
2467   // get*Dest - Return the destination basic blocks...
2468   BasicBlock *getNormalDest() const {
2469     return cast<BasicBlock>(Op<-2>());
2470   }
2471   BasicBlock *getUnwindDest() const {
2472     return cast<BasicBlock>(Op<-1>());
2473   }
2474   void setNormalDest(BasicBlock *B) {
2475     Op<-2>() = reinterpret_cast<Value*>(B);
2476   }
2477   void setUnwindDest(BasicBlock *B) {
2478     Op<-1>() = reinterpret_cast<Value*>(B);
2479   }
2480
2481   // getLandingPad - Get the landingpad instruction from the landing pad block
2482   // (the unwind destination).
2483   LandingPadInst *getLandingPad() const;
2484
2485   BasicBlock *getSuccessor(unsigned i) const {
2486     assert(i < 2 && "Successor # out of range for invoke!");
2487     return i == 0 ? getNormalDest() : getUnwindDest();
2488   }
2489
2490   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2491     assert(idx < 2 && "Successor # out of range for invoke!");
2492     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2493   }
2494
2495   unsigned getNumSuccessors() const { return 2; }
2496
2497   // Methods for support type inquiry through isa, cast, and dyn_cast:
2498   static inline bool classof(const InvokeInst *) { return true; }
2499   static inline bool classof(const Instruction *I) {
2500     return (I->getOpcode() == Instruction::Invoke);
2501   }
2502   static inline bool classof(const Value *V) {
2503     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2504   }
2505
2506 private:
2507   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2508   virtual unsigned getNumSuccessorsV() const;
2509   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2510
2511   // Shadow Instruction::setInstructionSubclassData with a private forwarding
2512   // method so that subclasses cannot accidentally use it.
2513   void setInstructionSubclassData(unsigned short D) {
2514     Instruction::setInstructionSubclassData(D);
2515   }
2516 };
2517
2518 template <>
2519 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2520 };
2521
2522 InvokeInst::InvokeInst(Value *Func,
2523                        BasicBlock *IfNormal, BasicBlock *IfException,
2524                        ArrayRef<Value *> Args, unsigned Values,
2525                        const Twine &NameStr, Instruction *InsertBefore)
2526   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2527                                       ->getElementType())->getReturnType(),
2528                    Instruction::Invoke,
2529                    OperandTraits<InvokeInst>::op_end(this) - Values,
2530                    Values, InsertBefore) {
2531   init(Func, IfNormal, IfException, Args, NameStr);
2532 }
2533 InvokeInst::InvokeInst(Value *Func,
2534                        BasicBlock *IfNormal, BasicBlock *IfException,
2535                        ArrayRef<Value *> Args, unsigned Values,
2536                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2537   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2538                                       ->getElementType())->getReturnType(),
2539                    Instruction::Invoke,
2540                    OperandTraits<InvokeInst>::op_end(this) - Values,
2541                    Values, InsertAtEnd) {
2542   init(Func, IfNormal, IfException, Args, NameStr);
2543 }
2544
2545 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2546
2547 //===----------------------------------------------------------------------===//
2548 //                              UnwindInst Class
2549 //===----------------------------------------------------------------------===//
2550
2551 //===---------------------------------------------------------------------------
2552 /// UnwindInst - Immediately exit the current function, unwinding the stack
2553 /// until an invoke instruction is found.
2554 ///
2555 class UnwindInst : public TerminatorInst {
2556   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2557 protected:
2558   virtual UnwindInst *clone_impl() const;
2559 public:
2560   // allocate space for exactly zero operands
2561   void *operator new(size_t s) {
2562     return User::operator new(s, 0);
2563   }
2564   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2565   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2566
2567   unsigned getNumSuccessors() const { return 0; }
2568
2569   // Methods for support type inquiry through isa, cast, and dyn_cast:
2570   static inline bool classof(const UnwindInst *) { return true; }
2571   static inline bool classof(const Instruction *I) {
2572     return I->getOpcode() == Instruction::Unwind;
2573   }
2574   static inline bool classof(const Value *V) {
2575     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2576   }
2577 private:
2578   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2579   virtual unsigned getNumSuccessorsV() const;
2580   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2581 };
2582
2583 //===----------------------------------------------------------------------===//
2584 //                              ResumeInst Class
2585 //===----------------------------------------------------------------------===//
2586
2587 //===---------------------------------------------------------------------------
2588 /// ResumeInst - Resume the propagation of an exception.
2589 ///
2590 class ResumeInst : public TerminatorInst {
2591   ResumeInst(const ResumeInst &RI);
2592
2593   explicit ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore=0);
2594   ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd);
2595 protected:
2596   virtual ResumeInst *clone_impl() const;
2597 public:
2598   static ResumeInst *Create(LLVMContext &C, Value *Exn,
2599                             Instruction *InsertBefore = 0) {
2600     return new(1) ResumeInst(C, Exn, InsertBefore);
2601   }
2602   static ResumeInst *Create(LLVMContext &C, Value *Exn,
2603                             BasicBlock *InsertAtEnd) {
2604     return new(1) ResumeInst(C, Exn, InsertAtEnd);
2605   }
2606
2607   /// Provide fast operand accessors
2608   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2609
2610   /// Convenience accessor.
2611   Value *getResumeValue() const { return Op<0>(); }
2612
2613   unsigned getNumSuccessors() const { return 0; }
2614
2615   // Methods for support type inquiry through isa, cast, and dyn_cast:
2616   static inline bool classof(const ResumeInst *) { return true; }
2617   static inline bool classof(const Instruction *I) {
2618     return I->getOpcode() == Instruction::Resume;
2619   }
2620   static inline bool classof(const Value *V) {
2621     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2622   }
2623 private:
2624   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2625   virtual unsigned getNumSuccessorsV() const;
2626   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2627 };
2628
2629 template <>
2630 struct OperandTraits<ResumeInst> :
2631     public FixedNumOperandTraits<ResumeInst, 1> {
2632 };
2633
2634 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2635
2636 //===----------------------------------------------------------------------===//
2637 //                           UnreachableInst Class
2638 //===----------------------------------------------------------------------===//
2639
2640 //===---------------------------------------------------------------------------
2641 /// UnreachableInst - This function has undefined behavior.  In particular, the
2642 /// presence of this instruction indicates some higher level knowledge that the
2643 /// end of the block cannot be reached.
2644 ///
2645 class UnreachableInst : public TerminatorInst {
2646   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2647 protected:
2648   virtual UnreachableInst *clone_impl() const;
2649
2650 public:
2651   // allocate space for exactly zero operands
2652   void *operator new(size_t s) {
2653     return User::operator new(s, 0);
2654   }
2655   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2656   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2657
2658   unsigned getNumSuccessors() const { return 0; }
2659
2660   // Methods for support type inquiry through isa, cast, and dyn_cast:
2661   static inline bool classof(const UnreachableInst *) { return true; }
2662   static inline bool classof(const Instruction *I) {
2663     return I->getOpcode() == Instruction::Unreachable;
2664   }
2665   static inline bool classof(const Value *V) {
2666     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2667   }
2668 private:
2669   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2670   virtual unsigned getNumSuccessorsV() const;
2671   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2672 };
2673
2674 //===----------------------------------------------------------------------===//
2675 //                                 TruncInst Class
2676 //===----------------------------------------------------------------------===//
2677
2678 /// @brief This class represents a truncation of integer types.
2679 class TruncInst : public CastInst {
2680 protected:
2681   /// @brief Clone an identical TruncInst
2682   virtual TruncInst *clone_impl() const;
2683
2684 public:
2685   /// @brief Constructor with insert-before-instruction semantics
2686   TruncInst(
2687     Value *S,                     ///< The value to be truncated
2688     Type *Ty,               ///< The (smaller) type to truncate to
2689     const Twine &NameStr = "",    ///< A name for the new instruction
2690     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2691   );
2692
2693   /// @brief Constructor with insert-at-end-of-block semantics
2694   TruncInst(
2695     Value *S,                     ///< The value to be truncated
2696     Type *Ty,               ///< The (smaller) type to truncate to
2697     const Twine &NameStr,         ///< A name for the new instruction
2698     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2699   );
2700
2701   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2702   static inline bool classof(const TruncInst *) { return true; }
2703   static inline bool classof(const Instruction *I) {
2704     return I->getOpcode() == Trunc;
2705   }
2706   static inline bool classof(const Value *V) {
2707     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2708   }
2709 };
2710
2711 //===----------------------------------------------------------------------===//
2712 //                                 ZExtInst Class
2713 //===----------------------------------------------------------------------===//
2714
2715 /// @brief This class represents zero extension of integer types.
2716 class ZExtInst : public CastInst {
2717 protected:
2718   /// @brief Clone an identical ZExtInst
2719   virtual ZExtInst *clone_impl() const;
2720
2721 public:
2722   /// @brief Constructor with insert-before-instruction semantics
2723   ZExtInst(
2724     Value *S,                     ///< The value to be zero extended
2725     Type *Ty,               ///< The type to zero extend to
2726     const Twine &NameStr = "",    ///< A name for the new instruction
2727     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2728   );
2729
2730   /// @brief Constructor with insert-at-end semantics.
2731   ZExtInst(
2732     Value *S,                     ///< The value to be zero extended
2733     Type *Ty,               ///< The type to zero extend to
2734     const Twine &NameStr,         ///< A name for the new instruction
2735     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2736   );
2737
2738   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2739   static inline bool classof(const ZExtInst *) { return true; }
2740   static inline bool classof(const Instruction *I) {
2741     return I->getOpcode() == ZExt;
2742   }
2743   static inline bool classof(const Value *V) {
2744     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2745   }
2746 };
2747
2748 //===----------------------------------------------------------------------===//
2749 //                                 SExtInst Class
2750 //===----------------------------------------------------------------------===//
2751
2752 /// @brief This class represents a sign extension of integer types.
2753 class SExtInst : public CastInst {
2754 protected:
2755   /// @brief Clone an identical SExtInst
2756   virtual SExtInst *clone_impl() const;
2757
2758 public:
2759   /// @brief Constructor with insert-before-instruction semantics
2760   SExtInst(
2761     Value *S,                     ///< The value to be sign extended
2762     Type *Ty,               ///< The type to sign extend to
2763     const Twine &NameStr = "",    ///< A name for the new instruction
2764     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2765   );
2766
2767   /// @brief Constructor with insert-at-end-of-block semantics
2768   SExtInst(
2769     Value *S,                     ///< The value to be sign extended
2770     Type *Ty,               ///< The type to sign extend to
2771     const Twine &NameStr,         ///< A name for the new instruction
2772     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2773   );
2774
2775   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2776   static inline bool classof(const SExtInst *) { return true; }
2777   static inline bool classof(const Instruction *I) {
2778     return I->getOpcode() == SExt;
2779   }
2780   static inline bool classof(const Value *V) {
2781     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2782   }
2783 };
2784
2785 //===----------------------------------------------------------------------===//
2786 //                                 FPTruncInst Class
2787 //===----------------------------------------------------------------------===//
2788
2789 /// @brief This class represents a truncation of floating point types.
2790 class FPTruncInst : public CastInst {
2791 protected:
2792   /// @brief Clone an identical FPTruncInst
2793   virtual FPTruncInst *clone_impl() const;
2794
2795 public:
2796   /// @brief Constructor with insert-before-instruction semantics
2797   FPTruncInst(
2798     Value *S,                     ///< The value to be truncated
2799     Type *Ty,               ///< The type to truncate to
2800     const Twine &NameStr = "",    ///< A name for the new instruction
2801     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2802   );
2803
2804   /// @brief Constructor with insert-before-instruction semantics
2805   FPTruncInst(
2806     Value *S,                     ///< The value to be truncated
2807     Type *Ty,               ///< The type to truncate to
2808     const Twine &NameStr,         ///< A name for the new instruction
2809     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2810   );
2811
2812   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2813   static inline bool classof(const FPTruncInst *) { return true; }
2814   static inline bool classof(const Instruction *I) {
2815     return I->getOpcode() == FPTrunc;
2816   }
2817   static inline bool classof(const Value *V) {
2818     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2819   }
2820 };
2821
2822 //===----------------------------------------------------------------------===//
2823 //                                 FPExtInst Class
2824 //===----------------------------------------------------------------------===//
2825
2826 /// @brief This class represents an extension of floating point types.
2827 class FPExtInst : public CastInst {
2828 protected:
2829   /// @brief Clone an identical FPExtInst
2830   virtual FPExtInst *clone_impl() const;
2831
2832 public:
2833   /// @brief Constructor with insert-before-instruction semantics
2834   FPExtInst(
2835     Value *S,                     ///< The value to be extended
2836     Type *Ty,               ///< The type to extend to
2837     const Twine &NameStr = "",    ///< A name for the new instruction
2838     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2839   );
2840
2841   /// @brief Constructor with insert-at-end-of-block semantics
2842   FPExtInst(
2843     Value *S,                     ///< The value to be extended
2844     Type *Ty,               ///< The type to extend to
2845     const Twine &NameStr,         ///< A name for the new instruction
2846     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2847   );
2848
2849   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2850   static inline bool classof(const FPExtInst *) { return true; }
2851   static inline bool classof(const Instruction *I) {
2852     return I->getOpcode() == FPExt;
2853   }
2854   static inline bool classof(const Value *V) {
2855     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2856   }
2857 };
2858
2859 //===----------------------------------------------------------------------===//
2860 //                                 UIToFPInst Class
2861 //===----------------------------------------------------------------------===//
2862
2863 /// @brief This class represents a cast unsigned integer to floating point.
2864 class UIToFPInst : public CastInst {
2865 protected:
2866   /// @brief Clone an identical UIToFPInst
2867   virtual UIToFPInst *clone_impl() const;
2868
2869 public:
2870   /// @brief Constructor with insert-before-instruction semantics
2871   UIToFPInst(
2872     Value *S,                     ///< The value to be converted
2873     Type *Ty,               ///< The type to convert to
2874     const Twine &NameStr = "",    ///< A name for the new instruction
2875     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2876   );
2877
2878   /// @brief Constructor with insert-at-end-of-block semantics
2879   UIToFPInst(
2880     Value *S,                     ///< The value to be converted
2881     Type *Ty,               ///< The type to convert to
2882     const Twine &NameStr,         ///< A name for the new instruction
2883     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2884   );
2885
2886   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2887   static inline bool classof(const UIToFPInst *) { return true; }
2888   static inline bool classof(const Instruction *I) {
2889     return I->getOpcode() == UIToFP;
2890   }
2891   static inline bool classof(const Value *V) {
2892     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2893   }
2894 };
2895
2896 //===----------------------------------------------------------------------===//
2897 //                                 SIToFPInst Class
2898 //===----------------------------------------------------------------------===//
2899
2900 /// @brief This class represents a cast from signed integer to floating point.
2901 class SIToFPInst : public CastInst {
2902 protected:
2903   /// @brief Clone an identical SIToFPInst
2904   virtual SIToFPInst *clone_impl() const;
2905
2906 public:
2907   /// @brief Constructor with insert-before-instruction semantics
2908   SIToFPInst(
2909     Value *S,                     ///< The value to be converted
2910     Type *Ty,               ///< The type to convert to
2911     const Twine &NameStr = "",    ///< A name for the new instruction
2912     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2913   );
2914
2915   /// @brief Constructor with insert-at-end-of-block semantics
2916   SIToFPInst(
2917     Value *S,                     ///< The value to be converted
2918     Type *Ty,               ///< The type to convert to
2919     const Twine &NameStr,         ///< A name for the new instruction
2920     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2921   );
2922
2923   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2924   static inline bool classof(const SIToFPInst *) { return true; }
2925   static inline bool classof(const Instruction *I) {
2926     return I->getOpcode() == SIToFP;
2927   }
2928   static inline bool classof(const Value *V) {
2929     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2930   }
2931 };
2932
2933 //===----------------------------------------------------------------------===//
2934 //                                 FPToUIInst Class
2935 //===----------------------------------------------------------------------===//
2936
2937 /// @brief This class represents a cast from floating point to unsigned integer
2938 class FPToUIInst  : public CastInst {
2939 protected:
2940   /// @brief Clone an identical FPToUIInst
2941   virtual FPToUIInst *clone_impl() const;
2942
2943 public:
2944   /// @brief Constructor with insert-before-instruction semantics
2945   FPToUIInst(
2946     Value *S,                     ///< The value to be converted
2947     Type *Ty,               ///< The type to convert to
2948     const Twine &NameStr = "",    ///< A name for the new instruction
2949     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2950   );
2951
2952   /// @brief Constructor with insert-at-end-of-block semantics
2953   FPToUIInst(
2954     Value *S,                     ///< The value to be converted
2955     Type *Ty,               ///< The type to convert to
2956     const Twine &NameStr,         ///< A name for the new instruction
2957     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2958   );
2959
2960   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2961   static inline bool classof(const FPToUIInst *) { return true; }
2962   static inline bool classof(const Instruction *I) {
2963     return I->getOpcode() == FPToUI;
2964   }
2965   static inline bool classof(const Value *V) {
2966     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2967   }
2968 };
2969
2970 //===----------------------------------------------------------------------===//
2971 //                                 FPToSIInst Class
2972 //===----------------------------------------------------------------------===//
2973
2974 /// @brief This class represents a cast from floating point to signed integer.
2975 class FPToSIInst  : public CastInst {
2976 protected:
2977   /// @brief Clone an identical FPToSIInst
2978   virtual FPToSIInst *clone_impl() const;
2979
2980 public:
2981   /// @brief Constructor with insert-before-instruction semantics
2982   FPToSIInst(
2983     Value *S,                     ///< The value to be converted
2984     Type *Ty,               ///< The type to convert to
2985     const Twine &NameStr = "",    ///< A name for the new instruction
2986     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2987   );
2988
2989   /// @brief Constructor with insert-at-end-of-block semantics
2990   FPToSIInst(
2991     Value *S,                     ///< The value to be converted
2992     Type *Ty,               ///< The type to convert to
2993     const Twine &NameStr,         ///< A name for the new instruction
2994     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2995   );
2996
2997   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2998   static inline bool classof(const FPToSIInst *) { return true; }
2999   static inline bool classof(const Instruction *I) {
3000     return I->getOpcode() == FPToSI;
3001   }
3002   static inline bool classof(const Value *V) {
3003     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3004   }
3005 };
3006
3007 //===----------------------------------------------------------------------===//
3008 //                                 IntToPtrInst Class
3009 //===----------------------------------------------------------------------===//
3010
3011 /// @brief This class represents a cast from an integer to a pointer.
3012 class IntToPtrInst : public CastInst {
3013 public:
3014   /// @brief Constructor with insert-before-instruction semantics
3015   IntToPtrInst(
3016     Value *S,                     ///< The value to be converted
3017     Type *Ty,               ///< The type to convert to
3018     const Twine &NameStr = "",    ///< A name for the new instruction
3019     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3020   );
3021
3022   /// @brief Constructor with insert-at-end-of-block semantics
3023   IntToPtrInst(
3024     Value *S,                     ///< The value to be converted
3025     Type *Ty,               ///< The type to convert to
3026     const Twine &NameStr,         ///< A name for the new instruction
3027     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3028   );
3029
3030   /// @brief Clone an identical IntToPtrInst
3031   virtual IntToPtrInst *clone_impl() const;
3032
3033   // Methods for support type inquiry through isa, cast, and dyn_cast:
3034   static inline bool classof(const IntToPtrInst *) { return true; }
3035   static inline bool classof(const Instruction *I) {
3036     return I->getOpcode() == IntToPtr;
3037   }
3038   static inline bool classof(const Value *V) {
3039     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3040   }
3041 };
3042
3043 //===----------------------------------------------------------------------===//
3044 //                                 PtrToIntInst Class
3045 //===----------------------------------------------------------------------===//
3046
3047 /// @brief This class represents a cast from a pointer to an integer
3048 class PtrToIntInst : public CastInst {
3049 protected:
3050   /// @brief Clone an identical PtrToIntInst
3051   virtual PtrToIntInst *clone_impl() const;
3052
3053 public:
3054   /// @brief Constructor with insert-before-instruction semantics
3055   PtrToIntInst(
3056     Value *S,                     ///< The value to be converted
3057     Type *Ty,               ///< The type to convert to
3058     const Twine &NameStr = "",    ///< A name for the new instruction
3059     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3060   );
3061
3062   /// @brief Constructor with insert-at-end-of-block semantics
3063   PtrToIntInst(
3064     Value *S,                     ///< The value to be converted
3065     Type *Ty,               ///< The type to convert to
3066     const Twine &NameStr,         ///< A name for the new instruction
3067     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3068   );
3069
3070   // Methods for support type inquiry through isa, cast, and dyn_cast:
3071   static inline bool classof(const PtrToIntInst *) { return true; }
3072   static inline bool classof(const Instruction *I) {
3073     return I->getOpcode() == PtrToInt;
3074   }
3075   static inline bool classof(const Value *V) {
3076     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3077   }
3078 };
3079
3080 //===----------------------------------------------------------------------===//
3081 //                             BitCastInst Class
3082 //===----------------------------------------------------------------------===//
3083
3084 /// @brief This class represents a no-op cast from one type to another.
3085 class BitCastInst : public CastInst {
3086 protected:
3087   /// @brief Clone an identical BitCastInst
3088   virtual BitCastInst *clone_impl() const;
3089
3090 public:
3091   /// @brief Constructor with insert-before-instruction semantics
3092   BitCastInst(
3093     Value *S,                     ///< The value to be casted
3094     Type *Ty,               ///< The type to casted to
3095     const Twine &NameStr = "",    ///< A name for the new instruction
3096     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3097   );
3098
3099   /// @brief Constructor with insert-at-end-of-block semantics
3100   BitCastInst(
3101     Value *S,                     ///< The value to be casted
3102     Type *Ty,               ///< The type to casted to
3103     const Twine &NameStr,         ///< A name for the new instruction
3104     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3105   );
3106
3107   // Methods for support type inquiry through isa, cast, and dyn_cast:
3108   static inline bool classof(const BitCastInst *) { return true; }
3109   static inline bool classof(const Instruction *I) {
3110     return I->getOpcode() == BitCast;
3111   }
3112   static inline bool classof(const Value *V) {
3113     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3114   }
3115 };
3116
3117 } // End llvm namespace
3118
3119 #endif