Add support alignment of allocation instructions.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/Instruction.h"
20 #include "llvm/InstrTypes.h"
21
22 namespace llvm {
23
24 class BasicBlock;
25 class ConstantInt;
26 class PointerType;
27
28 //===----------------------------------------------------------------------===//
29 //                             AllocationInst Class
30 //===----------------------------------------------------------------------===//
31
32 /// AllocationInst - This class is the common base class of MallocInst and
33 /// AllocaInst.
34 ///
35 class AllocationInst : public UnaryInstruction {
36   unsigned Alignment;
37 protected:
38   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
39                  const std::string &Name = "", Instruction *InsertBefore = 0);
40   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41                  const std::string &Name, BasicBlock *InsertAtEnd);
42
43 public:
44
45   /// isArrayAllocation - Return true if there is an allocation size parameter
46   /// to the allocation instruction that is not 1.
47   ///
48   bool isArrayAllocation() const;
49
50   /// getArraySize - Get the number of element allocated, for a simple
51   /// allocation of a single element, this will return a constant 1 value.
52   ///
53   inline const Value *getArraySize() const { return getOperand(0); }
54   inline Value *getArraySize() { return getOperand(0); }
55
56   /// getType - Overload to return most specific pointer type
57   ///
58   inline const PointerType *getType() const {
59     return reinterpret_cast<const PointerType*>(Instruction::getType());
60   }
61
62   /// getAllocatedType - Return the type that is being allocated by the
63   /// instruction.
64   ///
65   const Type *getAllocatedType() const;
66
67   /// getAlignment - Return the alignment of the memory that is being allocated
68   /// by the instruction.
69   ///
70   unsigned getAlignment() const { return Alignment; }
71   
72   virtual Instruction *clone() const = 0;
73
74   // Methods for support type inquiry through isa, cast, and dyn_cast:
75   static inline bool classof(const AllocationInst *) { return true; }
76   static inline bool classof(const Instruction *I) {
77     return I->getOpcode() == Instruction::Alloca ||
78            I->getOpcode() == Instruction::Malloc;
79   }
80   static inline bool classof(const Value *V) {
81     return isa<Instruction>(V) && classof(cast<Instruction>(V));
82   }
83 };
84
85
86 //===----------------------------------------------------------------------===//
87 //                                MallocInst Class
88 //===----------------------------------------------------------------------===//
89
90 /// MallocInst - an instruction to allocated memory on the heap
91 ///
92 class MallocInst : public AllocationInst {
93   MallocInst(const MallocInst &MI);
94 public:
95   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
96                       const std::string &Name = "",
97                       Instruction *InsertBefore = 0)
98     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
99   MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
100              BasicBlock *InsertAtEnd)
101     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
102   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align, 
103              const std::string &Name, BasicBlock *InsertAtEnd)
104   : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
105   explicit MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
106                       const std::string &Name = "",
107                       Instruction *InsertBefore = 0)
108   : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
109   
110   virtual MallocInst *clone() const;
111
112   // Methods for support type inquiry through isa, cast, and dyn_cast:
113   static inline bool classof(const MallocInst *) { return true; }
114   static inline bool classof(const Instruction *I) {
115     return (I->getOpcode() == Instruction::Malloc);
116   }
117   static inline bool classof(const Value *V) {
118     return isa<Instruction>(V) && classof(cast<Instruction>(V));
119   }
120 };
121
122
123 //===----------------------------------------------------------------------===//
124 //                                AllocaInst Class
125 //===----------------------------------------------------------------------===//
126
127 /// AllocaInst - an instruction to allocate memory on the stack
128 ///
129 class AllocaInst : public AllocationInst {
130   AllocaInst(const AllocaInst &);
131 public:
132   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
133                       const std::string &Name = "",
134                       Instruction *InsertBefore = 0)
135     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
136   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
137              BasicBlock *InsertAtEnd)
138     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
139   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
140              const std::string &Name, BasicBlock *InsertAtEnd)
141   : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
142   explicit AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
143                       const std::string &Name = "",
144                       Instruction *InsertBefore = 0)
145   : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
146   
147   virtual AllocaInst *clone() const;
148
149   // Methods for support type inquiry through isa, cast, and dyn_cast:
150   static inline bool classof(const AllocaInst *) { return true; }
151   static inline bool classof(const Instruction *I) {
152     return (I->getOpcode() == Instruction::Alloca);
153   }
154   static inline bool classof(const Value *V) {
155     return isa<Instruction>(V) && classof(cast<Instruction>(V));
156   }
157 };
158
159
160 //===----------------------------------------------------------------------===//
161 //                                 FreeInst Class
162 //===----------------------------------------------------------------------===//
163
164 /// FreeInst - an instruction to deallocate memory
165 ///
166 class FreeInst : public UnaryInstruction {
167   void AssertOK();
168 public:
169   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
170   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
171
172   virtual FreeInst *clone() const;
173
174   virtual bool mayWriteToMemory() const { return true; }
175
176   // Methods for support type inquiry through isa, cast, and dyn_cast:
177   static inline bool classof(const FreeInst *) { return true; }
178   static inline bool classof(const Instruction *I) {
179     return (I->getOpcode() == Instruction::Free);
180   }
181   static inline bool classof(const Value *V) {
182     return isa<Instruction>(V) && classof(cast<Instruction>(V));
183   }
184 };
185
186
187 //===----------------------------------------------------------------------===//
188 //                                LoadInst Class
189 //===----------------------------------------------------------------------===//
190
191 /// LoadInst - an instruction for reading from memory.  This uses the
192 /// SubclassData field in Value to store whether or not the load is volatile.
193 ///
194 class LoadInst : public UnaryInstruction {
195   LoadInst(const LoadInst &LI)
196     : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
197     setVolatile(LI.isVolatile());
198
199 #ifndef NDEBUG
200     AssertOK();
201 #endif
202   }
203   void AssertOK();
204 public:
205   LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
206   LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
207   LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
208            Instruction *InsertBefore = 0);
209   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
210            BasicBlock *InsertAtEnd);
211
212   /// isVolatile - Return true if this is a load from a volatile memory
213   /// location.
214   ///
215   bool isVolatile() const { return SubclassData; }
216
217   /// setVolatile - Specify whether this is a volatile load or not.
218   ///
219   void setVolatile(bool V) { SubclassData = V; }
220
221   virtual LoadInst *clone() const;
222
223   virtual bool mayWriteToMemory() const { return isVolatile(); }
224
225   Value *getPointerOperand() { return getOperand(0); }
226   const Value *getPointerOperand() const { return getOperand(0); }
227   static unsigned getPointerOperandIndex() { return 0U; }
228
229   // Methods for support type inquiry through isa, cast, and dyn_cast:
230   static inline bool classof(const LoadInst *) { return true; }
231   static inline bool classof(const Instruction *I) {
232     return I->getOpcode() == Instruction::Load;
233   }
234   static inline bool classof(const Value *V) {
235     return isa<Instruction>(V) && classof(cast<Instruction>(V));
236   }
237 };
238
239
240 //===----------------------------------------------------------------------===//
241 //                                StoreInst Class
242 //===----------------------------------------------------------------------===//
243
244 /// StoreInst - an instruction for storing to memory
245 ///
246 class StoreInst : public Instruction {
247   Use Ops[2];
248   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
249     Ops[0].init(SI.Ops[0], this);
250     Ops[1].init(SI.Ops[1], this);
251     setVolatile(SI.isVolatile());
252 #ifndef NDEBUG
253     AssertOK();
254 #endif
255   }
256   void AssertOK();
257 public:
258   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
259   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
260   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
261             Instruction *InsertBefore = 0);
262   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
263
264
265   /// isVolatile - Return true if this is a load from a volatile memory
266   /// location.
267   ///
268   bool isVolatile() const { return SubclassData; }
269
270   /// setVolatile - Specify whether this is a volatile load or not.
271   ///
272   void setVolatile(bool V) { SubclassData = V; }
273
274   /// Transparently provide more efficient getOperand methods.
275   Value *getOperand(unsigned i) const {
276     assert(i < 2 && "getOperand() out of range!");
277     return Ops[i];
278   }
279   void setOperand(unsigned i, Value *Val) {
280     assert(i < 2 && "setOperand() out of range!");
281     Ops[i] = Val;
282   }
283   unsigned getNumOperands() const { return 2; }
284
285
286   virtual StoreInst *clone() const;
287
288   virtual bool mayWriteToMemory() const { return true; }
289
290   Value *getPointerOperand() { return getOperand(1); }
291   const Value *getPointerOperand() const { return getOperand(1); }
292   static unsigned getPointerOperandIndex() { return 1U; }
293
294   // Methods for support type inquiry through isa, cast, and dyn_cast:
295   static inline bool classof(const StoreInst *) { return true; }
296   static inline bool classof(const Instruction *I) {
297     return I->getOpcode() == Instruction::Store;
298   }
299   static inline bool classof(const Value *V) {
300     return isa<Instruction>(V) && classof(cast<Instruction>(V));
301   }
302 };
303
304
305 //===----------------------------------------------------------------------===//
306 //                             GetElementPtrInst Class
307 //===----------------------------------------------------------------------===//
308
309 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
310 /// access elements of arrays and structs
311 ///
312 class GetElementPtrInst : public Instruction {
313   GetElementPtrInst(const GetElementPtrInst &GEPI)
314     : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
315                   0, GEPI.getNumOperands()) {
316     Use *OL = OperandList = new Use[NumOperands];
317     Use *GEPIOL = GEPI.OperandList;
318     for (unsigned i = 0, E = NumOperands; i != E; ++i)
319       OL[i].init(GEPIOL[i], this);
320   }
321   void init(Value *Ptr, const std::vector<Value*> &Idx);
322   void init(Value *Ptr, Value *Idx0, Value *Idx1);
323   void init(Value *Ptr, Value *Idx);
324 public:
325   /// Constructors - Create a getelementptr instruction with a base pointer an
326   /// list of indices.  The first ctor can optionally insert before an existing
327   /// instruction, the second appends the new instruction to the specified
328   /// BasicBlock.
329   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
330                     const std::string &Name = "", Instruction *InsertBefore =0);
331   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
332                     const std::string &Name, BasicBlock *InsertAtEnd);
333
334   /// Constructors - These two constructors are convenience methods because one
335   /// and two index getelementptr instructions are so common.
336   GetElementPtrInst(Value *Ptr, Value *Idx,
337                     const std::string &Name = "", Instruction *InsertBefore =0);
338   GetElementPtrInst(Value *Ptr, Value *Idx,
339                     const std::string &Name, BasicBlock *InsertAtEnd);
340   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
341                     const std::string &Name = "", Instruction *InsertBefore =0);
342   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
343                     const std::string &Name, BasicBlock *InsertAtEnd);
344   ~GetElementPtrInst();
345
346   virtual GetElementPtrInst *clone() const;
347
348   // getType - Overload to return most specific pointer type...
349   inline const PointerType *getType() const {
350     return reinterpret_cast<const PointerType*>(Instruction::getType());
351   }
352
353   /// getIndexedType - Returns the type of the element that would be loaded with
354   /// a load instruction with the specified parameters.
355   ///
356   /// A null type is returned if the indices are invalid for the specified
357   /// pointer type.
358   ///
359   static const Type *getIndexedType(const Type *Ptr,
360                                     const std::vector<Value*> &Indices,
361                                     bool AllowStructLeaf = false);
362   static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
363                                     bool AllowStructLeaf = false);
364   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
365
366   inline op_iterator       idx_begin()       { return op_begin()+1; }
367   inline const_op_iterator idx_begin() const { return op_begin()+1; }
368   inline op_iterator       idx_end()         { return op_end(); }
369   inline const_op_iterator idx_end()   const { return op_end(); }
370
371   Value *getPointerOperand() {
372     return getOperand(0);
373   }
374   const Value *getPointerOperand() const {
375     return getOperand(0);
376   }
377   static unsigned getPointerOperandIndex() {
378     return 0U;                      // get index for modifying correct operand
379   }
380
381   inline unsigned getNumIndices() const {  // Note: always non-negative
382     return getNumOperands() - 1;
383   }
384
385   inline bool hasIndices() const {
386     return getNumOperands() > 1;
387   }
388
389   // Methods for support type inquiry through isa, cast, and dyn_cast:
390   static inline bool classof(const GetElementPtrInst *) { return true; }
391   static inline bool classof(const Instruction *I) {
392     return (I->getOpcode() == Instruction::GetElementPtr);
393   }
394   static inline bool classof(const Value *V) {
395     return isa<Instruction>(V) && classof(cast<Instruction>(V));
396   }
397 };
398
399 //===----------------------------------------------------------------------===//
400 //                            SetCondInst Class
401 //===----------------------------------------------------------------------===//
402
403 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
404 /// le, or ge.
405 ///
406 class SetCondInst : public BinaryOperator {
407 public:
408   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
409               const std::string &Name = "", Instruction *InsertBefore = 0);
410   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
411               const std::string &Name, BasicBlock *InsertAtEnd);
412
413   /// getInverseCondition - Return the inverse of the current condition opcode.
414   /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
415   ///
416   BinaryOps getInverseCondition() const {
417     return getInverseCondition(getOpcode());
418   }
419
420   /// getInverseCondition - Static version that you can use without an
421   /// instruction available.
422   ///
423   static BinaryOps getInverseCondition(BinaryOps Opcode);
424
425   /// getSwappedCondition - Return the condition opcode that would be the result
426   /// of exchanging the two operands of the setcc instruction without changing
427   /// the result produced.  Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
428   ///
429   BinaryOps getSwappedCondition() const {
430     return getSwappedCondition(getOpcode());
431   }
432
433   /// getSwappedCondition - Static version that you can use without an
434   /// instruction available.
435   ///
436   static BinaryOps getSwappedCondition(BinaryOps Opcode);
437
438
439   // Methods for support type inquiry through isa, cast, and dyn_cast:
440   static inline bool classof(const SetCondInst *) { return true; }
441   static inline bool classof(const Instruction *I) {
442     return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
443            I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
444            I->getOpcode() == SetLT || I->getOpcode() == SetGT;
445   }
446   static inline bool classof(const Value *V) {
447     return isa<Instruction>(V) && classof(cast<Instruction>(V));
448   }
449 };
450
451 //===----------------------------------------------------------------------===//
452 //                                 CastInst Class
453 //===----------------------------------------------------------------------===//
454
455 /// CastInst - This class represents a cast from Operand[0] to the type of
456 /// the instruction (i->getType()).
457 ///
458 class CastInst : public UnaryInstruction {
459   CastInst(const CastInst &CI)
460     : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) {
461   }
462 public:
463   CastInst(Value *S, const Type *Ty, const std::string &Name = "",
464            Instruction *InsertBefore = 0)
465     : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) {
466   }
467   CastInst(Value *S, const Type *Ty, const std::string &Name,
468            BasicBlock *InsertAtEnd)
469     : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) {
470   }
471
472   virtual CastInst *clone() const;
473
474   // Methods for support type inquiry through isa, cast, and dyn_cast:
475   static inline bool classof(const CastInst *) { return true; }
476   static inline bool classof(const Instruction *I) {
477     return I->getOpcode() == Cast;
478   }
479   static inline bool classof(const Value *V) {
480     return isa<Instruction>(V) && classof(cast<Instruction>(V));
481   }
482 };
483
484
485 //===----------------------------------------------------------------------===//
486 //                                 CallInst Class
487 //===----------------------------------------------------------------------===//
488
489 /// CallInst - This class represents a function call, abstracting a target
490 /// machine's calling convention.  This class uses low bit of the SubClassData
491 /// field to indicate whether or not this is a tail call.  The rest of the bits
492 /// hold the calling convention of the call.
493 ///
494 class CallInst : public Instruction {
495   CallInst(const CallInst &CI);
496   void init(Value *Func, const std::vector<Value*> &Params);
497   void init(Value *Func, Value *Actual1, Value *Actual2);
498   void init(Value *Func, Value *Actual);
499   void init(Value *Func);
500
501 public:
502   CallInst(Value *F, const std::vector<Value*> &Par,
503            const std::string &Name = "", Instruction *InsertBefore = 0);
504   CallInst(Value *F, const std::vector<Value*> &Par,
505            const std::string &Name, BasicBlock *InsertAtEnd);
506
507   // Alternate CallInst ctors w/ two actuals, w/ one actual and no
508   // actuals, respectively.
509   CallInst(Value *F, Value *Actual1, Value *Actual2,
510            const std::string& Name = "", Instruction *InsertBefore = 0);
511   CallInst(Value *F, Value *Actual1, Value *Actual2,
512            const std::string& Name, BasicBlock *InsertAtEnd);
513   CallInst(Value *F, Value *Actual, const std::string& Name = "",
514            Instruction *InsertBefore = 0);
515   CallInst(Value *F, Value *Actual, const std::string& Name,
516            BasicBlock *InsertAtEnd);
517   explicit CallInst(Value *F, const std::string &Name = "",
518                     Instruction *InsertBefore = 0);
519   explicit CallInst(Value *F, const std::string &Name,
520                     BasicBlock *InsertAtEnd);
521   ~CallInst();
522
523   virtual CallInst *clone() const;
524   bool mayWriteToMemory() const { return true; }
525
526   bool isTailCall() const           { return SubclassData & 1; }
527   void setTailCall(bool isTailCall = true) {
528     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
529   }
530
531   /// getCallingConv/setCallingConv - Get or set the calling convention of this
532   /// function call.
533   unsigned getCallingConv() const { return SubclassData >> 1; }
534   void setCallingConv(unsigned CC) {
535     SubclassData = (SubclassData & 1) | (CC << 1);
536   }
537
538   /// getCalledFunction - Return the function being called by this instruction
539   /// if it is a direct call.  If it is a call through a function pointer,
540   /// return null.
541   Function *getCalledFunction() const {
542     return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
543   }
544
545   // getCalledValue - Get a pointer to a method that is invoked by this inst.
546   inline const Value *getCalledValue() const { return getOperand(0); }
547   inline       Value *getCalledValue()       { return getOperand(0); }
548
549   // Methods for support type inquiry through isa, cast, and dyn_cast:
550   static inline bool classof(const CallInst *) { return true; }
551   static inline bool classof(const Instruction *I) {
552     return I->getOpcode() == Instruction::Call;
553   }
554   static inline bool classof(const Value *V) {
555     return isa<Instruction>(V) && classof(cast<Instruction>(V));
556   }
557 };
558
559
560 //===----------------------------------------------------------------------===//
561 //                                 ShiftInst Class
562 //===----------------------------------------------------------------------===//
563
564 /// ShiftInst - This class represents left and right shift instructions.
565 ///
566 class ShiftInst : public Instruction {
567   Use Ops[2];
568   ShiftInst(const ShiftInst &SI)
569     : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
570     Ops[0].init(SI.Ops[0], this);
571     Ops[1].init(SI.Ops[1], this);
572   }
573   void init(OtherOps Opcode, Value *S, Value *SA) {
574     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
575     Ops[0].init(S, this);
576     Ops[1].init(SA, this);
577   }
578
579 public:
580   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
581             Instruction *InsertBefore = 0)
582     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
583     init(Opcode, S, SA);
584   }
585   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
586             BasicBlock *InsertAtEnd)
587     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
588     init(Opcode, S, SA);
589   }
590
591   OtherOps getOpcode() const {
592     return static_cast<OtherOps>(Instruction::getOpcode());
593   }
594
595   /// Transparently provide more efficient getOperand methods.
596   Value *getOperand(unsigned i) const {
597     assert(i < 2 && "getOperand() out of range!");
598     return Ops[i];
599   }
600   void setOperand(unsigned i, Value *Val) {
601     assert(i < 2 && "setOperand() out of range!");
602     Ops[i] = Val;
603   }
604   unsigned getNumOperands() const { return 2; }
605
606   virtual ShiftInst *clone() const;
607
608   // Methods for support type inquiry through isa, cast, and dyn_cast:
609   static inline bool classof(const ShiftInst *) { return true; }
610   static inline bool classof(const Instruction *I) {
611     return (I->getOpcode() == Instruction::Shr) |
612            (I->getOpcode() == Instruction::Shl);
613   }
614   static inline bool classof(const Value *V) {
615     return isa<Instruction>(V) && classof(cast<Instruction>(V));
616   }
617 };
618
619 //===----------------------------------------------------------------------===//
620 //                               SelectInst Class
621 //===----------------------------------------------------------------------===//
622
623 /// SelectInst - This class represents the LLVM 'select' instruction.
624 ///
625 class SelectInst : public Instruction {
626   Use Ops[3];
627
628   void init(Value *C, Value *S1, Value *S2) {
629     Ops[0].init(C, this);
630     Ops[1].init(S1, this);
631     Ops[2].init(S2, this);
632   }
633
634   SelectInst(const SelectInst &SI)
635     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
636     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
637   }
638 public:
639   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
640              Instruction *InsertBefore = 0)
641     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
642                   Name, InsertBefore) {
643     init(C, S1, S2);
644   }
645   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
646              BasicBlock *InsertAtEnd)
647     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
648                   Name, InsertAtEnd) {
649     init(C, S1, S2);
650   }
651
652   Value *getCondition() const { return Ops[0]; }
653   Value *getTrueValue() const { return Ops[1]; }
654   Value *getFalseValue() const { return Ops[2]; }
655
656   /// Transparently provide more efficient getOperand methods.
657   Value *getOperand(unsigned i) const {
658     assert(i < 3 && "getOperand() out of range!");
659     return Ops[i];
660   }
661   void setOperand(unsigned i, Value *Val) {
662     assert(i < 3 && "setOperand() out of range!");
663     Ops[i] = Val;
664   }
665   unsigned getNumOperands() const { return 3; }
666
667   OtherOps getOpcode() const {
668     return static_cast<OtherOps>(Instruction::getOpcode());
669   }
670
671   virtual SelectInst *clone() const;
672
673   // Methods for support type inquiry through isa, cast, and dyn_cast:
674   static inline bool classof(const SelectInst *) { return true; }
675   static inline bool classof(const Instruction *I) {
676     return I->getOpcode() == Instruction::Select;
677   }
678   static inline bool classof(const Value *V) {
679     return isa<Instruction>(V) && classof(cast<Instruction>(V));
680   }
681 };
682
683 //===----------------------------------------------------------------------===//
684 //                                VAArgInst Class
685 //===----------------------------------------------------------------------===//
686
687 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
688 /// an argument of the specified type given a va_list and increments that list
689 ///
690 class VAArgInst : public UnaryInstruction {
691   VAArgInst(const VAArgInst &VAA)
692     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
693 public:
694   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
695              Instruction *InsertBefore = 0)
696     : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
697   }
698   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
699             BasicBlock *InsertAtEnd)
700     : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
701   }
702
703   virtual VAArgInst *clone() const;
704   bool mayWriteToMemory() const { return true; }
705
706   // Methods for support type inquiry through isa, cast, and dyn_cast:
707   static inline bool classof(const VAArgInst *) { return true; }
708   static inline bool classof(const Instruction *I) {
709     return I->getOpcode() == VAArg;
710   }
711   static inline bool classof(const Value *V) {
712     return isa<Instruction>(V) && classof(cast<Instruction>(V));
713   }
714 };
715
716 //===----------------------------------------------------------------------===//
717 //                               PHINode Class
718 //===----------------------------------------------------------------------===//
719
720 // PHINode - The PHINode class is used to represent the magical mystical PHI
721 // node, that can not exist in nature, but can be synthesized in a computer
722 // scientist's overactive imagination.
723 //
724 class PHINode : public Instruction {
725   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
726   /// the number actually in use.
727   unsigned ReservedSpace;
728   PHINode(const PHINode &PN);
729 public:
730   PHINode(const Type *Ty, const std::string &Name = "",
731           Instruction *InsertBefore = 0)
732     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
733       ReservedSpace(0) {
734   }
735
736   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
737     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
738       ReservedSpace(0) {
739   }
740
741   ~PHINode();
742
743   /// reserveOperandSpace - This method can be used to avoid repeated
744   /// reallocation of PHI operand lists by reserving space for the correct
745   /// number of operands before adding them.  Unlike normal vector reserves,
746   /// this method can also be used to trim the operand space.
747   void reserveOperandSpace(unsigned NumValues) {
748     resizeOperands(NumValues*2);
749   }
750
751   virtual PHINode *clone() const;
752
753   /// getNumIncomingValues - Return the number of incoming edges
754   ///
755   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
756
757   /// getIncomingValue - Return incoming value #x
758   ///
759   Value *getIncomingValue(unsigned i) const {
760     assert(i*2 < getNumOperands() && "Invalid value number!");
761     return getOperand(i*2);
762   }
763   void setIncomingValue(unsigned i, Value *V) {
764     assert(i*2 < getNumOperands() && "Invalid value number!");
765     setOperand(i*2, V);
766   }
767   unsigned getOperandNumForIncomingValue(unsigned i) {
768     return i*2;
769   }
770
771   /// getIncomingBlock - Return incoming basic block #x
772   ///
773   BasicBlock *getIncomingBlock(unsigned i) const {
774     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
775   }
776   void setIncomingBlock(unsigned i, BasicBlock *BB) {
777     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
778   }
779   unsigned getOperandNumForIncomingBlock(unsigned i) {
780     return i*2+1;
781   }
782
783   /// addIncoming - Add an incoming value to the end of the PHI list
784   ///
785   void addIncoming(Value *V, BasicBlock *BB) {
786     assert(getType() == V->getType() &&
787            "All operands to PHI node must be the same type as the PHI node!");
788     unsigned OpNo = NumOperands;
789     if (OpNo+2 > ReservedSpace)
790       resizeOperands(0);  // Get more space!
791     // Initialize some new operands.
792     NumOperands = OpNo+2;
793     OperandList[OpNo].init(V, this);
794     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
795   }
796
797   /// removeIncomingValue - Remove an incoming value.  This is useful if a
798   /// predecessor basic block is deleted.  The value removed is returned.
799   ///
800   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
801   /// is true), the PHI node is destroyed and any uses of it are replaced with
802   /// dummy values.  The only time there should be zero incoming values to a PHI
803   /// node is when the block is dead, so this strategy is sound.
804   ///
805   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
806
807   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
808     int Idx = getBasicBlockIndex(BB);
809     assert(Idx >= 0 && "Invalid basic block argument to remove!");
810     return removeIncomingValue(Idx, DeletePHIIfEmpty);
811   }
812
813   /// getBasicBlockIndex - Return the first index of the specified basic
814   /// block in the value list for this PHI.  Returns -1 if no instance.
815   ///
816   int getBasicBlockIndex(const BasicBlock *BB) const {
817     Use *OL = OperandList;
818     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
819       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
820     return -1;
821   }
822
823   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
824     return getIncomingValue(getBasicBlockIndex(BB));
825   }
826
827   /// hasConstantValue - If the specified PHI node always merges together the 
828   /// same value, return the value, otherwise return null.
829   ///
830   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
831   
832   /// Methods for support type inquiry through isa, cast, and dyn_cast:
833   static inline bool classof(const PHINode *) { return true; }
834   static inline bool classof(const Instruction *I) {
835     return I->getOpcode() == Instruction::PHI;
836   }
837   static inline bool classof(const Value *V) {
838     return isa<Instruction>(V) && classof(cast<Instruction>(V));
839   }
840  private:
841   void resizeOperands(unsigned NumOperands);
842 };
843
844 //===----------------------------------------------------------------------===//
845 //                               ReturnInst Class
846 //===----------------------------------------------------------------------===//
847
848 //===---------------------------------------------------------------------------
849 /// ReturnInst - Return a value (possibly void), from a function.  Execution
850 /// does not continue in this function any longer.
851 ///
852 class ReturnInst : public TerminatorInst {
853   Use RetVal;  // Possibly null retval.
854   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
855                                                     RI.getNumOperands()) {
856     if (RI.getNumOperands())
857       RetVal.init(RI.RetVal, this);
858   }
859
860   void init(Value *RetVal);
861
862 public:
863   // ReturnInst constructors:
864   // ReturnInst()                  - 'ret void' instruction
865   // ReturnInst(    null)          - 'ret void' instruction
866   // ReturnInst(Value* X)          - 'ret X'    instruction
867   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
868   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
869   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
870   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
871   //
872   // NOTE: If the Value* passed is of type void then the constructor behaves as
873   // if it was passed NULL.
874   ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
875     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
876     init(retVal);
877   }
878   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
879     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
880     init(retVal);
881   }
882   ReturnInst(BasicBlock *InsertAtEnd)
883     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
884   }
885
886   virtual ReturnInst *clone() const;
887
888   // Transparently provide more efficient getOperand methods.
889   Value *getOperand(unsigned i) const {
890     assert(i < getNumOperands() && "getOperand() out of range!");
891     return RetVal;
892   }
893   void setOperand(unsigned i, Value *Val) {
894     assert(i < getNumOperands() && "setOperand() out of range!");
895     RetVal = Val;
896   }
897
898   Value *getReturnValue() const { return RetVal; }
899
900   unsigned getNumSuccessors() const { return 0; }
901
902   // Methods for support type inquiry through isa, cast, and dyn_cast:
903   static inline bool classof(const ReturnInst *) { return true; }
904   static inline bool classof(const Instruction *I) {
905     return (I->getOpcode() == Instruction::Ret);
906   }
907   static inline bool classof(const Value *V) {
908     return isa<Instruction>(V) && classof(cast<Instruction>(V));
909   }
910  private:
911   virtual BasicBlock *getSuccessorV(unsigned idx) const;
912   virtual unsigned getNumSuccessorsV() const;
913   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
914 };
915
916 //===----------------------------------------------------------------------===//
917 //                               BranchInst Class
918 //===----------------------------------------------------------------------===//
919
920 //===---------------------------------------------------------------------------
921 /// BranchInst - Conditional or Unconditional Branch instruction.
922 ///
923 class BranchInst : public TerminatorInst {
924   /// Ops list - Branches are strange.  The operands are ordered:
925   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
926   /// they don't have to check for cond/uncond branchness.
927   Use Ops[3];
928   BranchInst(const BranchInst &BI);
929   void AssertOK();
930 public:
931   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
932   // BranchInst(BB *B)                           - 'br B'
933   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
934   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
935   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
936   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
937   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
938   BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
939     : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
940     assert(IfTrue != 0 && "Branch destination may not be null!");
941     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
942   }
943   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
944              Instruction *InsertBefore = 0)
945     : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
946     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
947     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
948     Ops[2].init(Cond, this);
949 #ifndef NDEBUG
950     AssertOK();
951 #endif
952   }
953
954   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
955     : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
956     assert(IfTrue != 0 && "Branch destination may not be null!");
957     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
958   }
959
960   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
961              BasicBlock *InsertAtEnd)
962     : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
963     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
964     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
965     Ops[2].init(Cond, this);
966 #ifndef NDEBUG
967     AssertOK();
968 #endif
969   }
970
971
972   /// Transparently provide more efficient getOperand methods.
973   Value *getOperand(unsigned i) const {
974     assert(i < getNumOperands() && "getOperand() out of range!");
975     return Ops[i];
976   }
977   void setOperand(unsigned i, Value *Val) {
978     assert(i < getNumOperands() && "setOperand() out of range!");
979     Ops[i] = Val;
980   }
981
982   virtual BranchInst *clone() const;
983
984   inline bool isUnconditional() const { return getNumOperands() == 1; }
985   inline bool isConditional()   const { return getNumOperands() == 3; }
986
987   inline Value *getCondition() const {
988     assert(isConditional() && "Cannot get condition of an uncond branch!");
989     return getOperand(2);
990   }
991
992   void setCondition(Value *V) {
993     assert(isConditional() && "Cannot set condition of unconditional branch!");
994     setOperand(2, V);
995   }
996
997   // setUnconditionalDest - Change the current branch to an unconditional branch
998   // targeting the specified block.
999   // FIXME: Eliminate this ugly method.
1000   void setUnconditionalDest(BasicBlock *Dest) {
1001     if (isConditional()) {  // Convert this to an uncond branch.
1002       NumOperands = 1;
1003       Ops[1].set(0);
1004       Ops[2].set(0);
1005     }
1006     setOperand(0, reinterpret_cast<Value*>(Dest));
1007   }
1008
1009   unsigned getNumSuccessors() const { return 1+isConditional(); }
1010
1011   BasicBlock *getSuccessor(unsigned i) const {
1012     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1013     return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1014                       cast<BasicBlock>(getOperand(1));
1015   }
1016
1017   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1018     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1019     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1020   }
1021
1022   // Methods for support type inquiry through isa, cast, and dyn_cast:
1023   static inline bool classof(const BranchInst *) { return true; }
1024   static inline bool classof(const Instruction *I) {
1025     return (I->getOpcode() == Instruction::Br);
1026   }
1027   static inline bool classof(const Value *V) {
1028     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1029   }
1030 private:
1031   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1032   virtual unsigned getNumSuccessorsV() const;
1033   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1034 };
1035
1036 //===----------------------------------------------------------------------===//
1037 //                               SwitchInst Class
1038 //===----------------------------------------------------------------------===//
1039
1040 //===---------------------------------------------------------------------------
1041 /// SwitchInst - Multiway switch
1042 ///
1043 class SwitchInst : public TerminatorInst {
1044   unsigned ReservedSpace;
1045   // Operand[0]    = Value to switch on
1046   // Operand[1]    = Default basic block destination
1047   // Operand[2n  ] = Value to match
1048   // Operand[2n+1] = BasicBlock to go to on match
1049   SwitchInst(const SwitchInst &RI);
1050   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1051   void resizeOperands(unsigned No);
1052 public:
1053   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1054   /// switch on and a default destination.  The number of additional cases can
1055   /// be specified here to make memory allocation more efficient.  This
1056   /// constructor can also autoinsert before another instruction.
1057   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1058              Instruction *InsertBefore = 0)
1059     : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1060     init(Value, Default, NumCases);
1061   }
1062
1063   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1064   /// switch on and a default destination.  The number of additional cases can
1065   /// be specified here to make memory allocation more efficient.  This
1066   /// constructor also autoinserts at the end of the specified BasicBlock.
1067   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1068              BasicBlock *InsertAtEnd)
1069     : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1070     init(Value, Default, NumCases);
1071   }
1072   ~SwitchInst();
1073
1074
1075   // Accessor Methods for Switch stmt
1076   inline Value *getCondition() const { return getOperand(0); }
1077   void setCondition(Value *V) { setOperand(0, V); }
1078
1079   inline BasicBlock *getDefaultDest() const {
1080     return cast<BasicBlock>(getOperand(1));
1081   }
1082
1083   /// getNumCases - return the number of 'cases' in this switch instruction.
1084   /// Note that case #0 is always the default case.
1085   unsigned getNumCases() const {
1086     return getNumOperands()/2;
1087   }
1088
1089   /// getCaseValue - Return the specified case value.  Note that case #0, the
1090   /// default destination, does not have a case value.
1091   ConstantInt *getCaseValue(unsigned i) {
1092     assert(i && i < getNumCases() && "Illegal case value to get!");
1093     return getSuccessorValue(i);
1094   }
1095
1096   /// getCaseValue - Return the specified case value.  Note that case #0, the
1097   /// default destination, does not have a case value.
1098   const ConstantInt *getCaseValue(unsigned i) const {
1099     assert(i && i < getNumCases() && "Illegal case value to get!");
1100     return getSuccessorValue(i);
1101   }
1102
1103   /// findCaseValue - Search all of the case values for the specified constant.
1104   /// If it is explicitly handled, return the case number of it, otherwise
1105   /// return 0 to indicate that it is handled by the default handler.
1106   unsigned findCaseValue(const ConstantInt *C) const {
1107     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1108       if (getCaseValue(i) == C)
1109         return i;
1110     return 0;
1111   }
1112
1113   /// addCase - Add an entry to the switch instruction...
1114   ///
1115   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1116
1117   /// removeCase - This method removes the specified successor from the switch
1118   /// instruction.  Note that this cannot be used to remove the default
1119   /// destination (successor #0).
1120   ///
1121   void removeCase(unsigned idx);
1122
1123   virtual SwitchInst *clone() const;
1124
1125   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1126   BasicBlock *getSuccessor(unsigned idx) const {
1127     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1128     return cast<BasicBlock>(getOperand(idx*2+1));
1129   }
1130   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1131     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1132     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1133   }
1134
1135   // getSuccessorValue - Return the value associated with the specified
1136   // successor.
1137   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1138     assert(idx < getNumSuccessors() && "Successor # out of range!");
1139     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1140   }
1141
1142   // Methods for support type inquiry through isa, cast, and dyn_cast:
1143   static inline bool classof(const SwitchInst *) { return true; }
1144   static inline bool classof(const Instruction *I) {
1145     return I->getOpcode() == Instruction::Switch;
1146   }
1147   static inline bool classof(const Value *V) {
1148     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1149   }
1150 private:
1151   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1152   virtual unsigned getNumSuccessorsV() const;
1153   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1154 };
1155
1156 //===----------------------------------------------------------------------===//
1157 //                               InvokeInst Class
1158 //===----------------------------------------------------------------------===//
1159
1160 //===---------------------------------------------------------------------------
1161
1162 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1163 /// calling convention of the call.
1164 ///
1165 class InvokeInst : public TerminatorInst {
1166   InvokeInst(const InvokeInst &BI);
1167   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1168             const std::vector<Value*> &Params);
1169 public:
1170   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1171              const std::vector<Value*> &Params, const std::string &Name = "",
1172              Instruction *InsertBefore = 0);
1173   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1174              const std::vector<Value*> &Params, const std::string &Name,
1175              BasicBlock *InsertAtEnd);
1176   ~InvokeInst();
1177
1178   virtual InvokeInst *clone() const;
1179
1180   bool mayWriteToMemory() const { return true; }
1181
1182   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1183   /// function call.
1184   unsigned getCallingConv() const { return SubclassData; }
1185   void setCallingConv(unsigned CC) {
1186     SubclassData = CC;
1187   }
1188
1189   /// getCalledFunction - Return the function called, or null if this is an
1190   /// indirect function invocation.
1191   ///
1192   Function *getCalledFunction() const {
1193     return dyn_cast<Function>(getOperand(0));
1194   }
1195
1196   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1197   inline Value *getCalledValue() const { return getOperand(0); }
1198
1199   // get*Dest - Return the destination basic blocks...
1200   BasicBlock *getNormalDest() const {
1201     return cast<BasicBlock>(getOperand(1));
1202   }
1203   BasicBlock *getUnwindDest() const {
1204     return cast<BasicBlock>(getOperand(2));
1205   }
1206   void setNormalDest(BasicBlock *B) {
1207     setOperand(1, reinterpret_cast<Value*>(B));
1208   }
1209
1210   void setUnwindDest(BasicBlock *B) {
1211     setOperand(2, reinterpret_cast<Value*>(B));
1212   }
1213
1214   inline BasicBlock *getSuccessor(unsigned i) const {
1215     assert(i < 2 && "Successor # out of range for invoke!");
1216     return i == 0 ? getNormalDest() : getUnwindDest();
1217   }
1218
1219   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1220     assert(idx < 2 && "Successor # out of range for invoke!");
1221     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1222   }
1223
1224   unsigned getNumSuccessors() const { return 2; }
1225
1226   // Methods for support type inquiry through isa, cast, and dyn_cast:
1227   static inline bool classof(const InvokeInst *) { return true; }
1228   static inline bool classof(const Instruction *I) {
1229     return (I->getOpcode() == Instruction::Invoke);
1230   }
1231   static inline bool classof(const Value *V) {
1232     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1233   }
1234 private:
1235   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1236   virtual unsigned getNumSuccessorsV() const;
1237   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1238 };
1239
1240
1241 //===----------------------------------------------------------------------===//
1242 //                              UnwindInst Class
1243 //===----------------------------------------------------------------------===//
1244
1245 //===---------------------------------------------------------------------------
1246 /// UnwindInst - Immediately exit the current function, unwinding the stack
1247 /// until an invoke instruction is found.
1248 ///
1249 class UnwindInst : public TerminatorInst {
1250 public:
1251   UnwindInst(Instruction *InsertBefore = 0)
1252     : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1253   }
1254   UnwindInst(BasicBlock *InsertAtEnd)
1255     : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1256   }
1257
1258   virtual UnwindInst *clone() const;
1259
1260   unsigned getNumSuccessors() const { return 0; }
1261
1262   // Methods for support type inquiry through isa, cast, and dyn_cast:
1263   static inline bool classof(const UnwindInst *) { return true; }
1264   static inline bool classof(const Instruction *I) {
1265     return I->getOpcode() == Instruction::Unwind;
1266   }
1267   static inline bool classof(const Value *V) {
1268     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1269   }
1270 private:
1271   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1272   virtual unsigned getNumSuccessorsV() const;
1273   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1274 };
1275
1276 //===----------------------------------------------------------------------===//
1277 //                           UnreachableInst Class
1278 //===----------------------------------------------------------------------===//
1279
1280 //===---------------------------------------------------------------------------
1281 /// UnreachableInst - This function has undefined behavior.  In particular, the
1282 /// presence of this instruction indicates some higher level knowledge that the
1283 /// end of the block cannot be reached.
1284 ///
1285 class UnreachableInst : public TerminatorInst {
1286 public:
1287   UnreachableInst(Instruction *InsertBefore = 0)
1288     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1289   }
1290   UnreachableInst(BasicBlock *InsertAtEnd)
1291     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1292   }
1293
1294   virtual UnreachableInst *clone() const;
1295
1296   unsigned getNumSuccessors() const { return 0; }
1297
1298   // Methods for support type inquiry through isa, cast, and dyn_cast:
1299   static inline bool classof(const UnreachableInst *) { return true; }
1300   static inline bool classof(const Instruction *I) {
1301     return I->getOpcode() == Instruction::Unreachable;
1302   }
1303   static inline bool classof(const Value *V) {
1304     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1305   }
1306 private:
1307   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1308   virtual unsigned getNumSuccessorsV() const;
1309   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1310 };
1311
1312 } // End llvm namespace
1313
1314 #endif