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