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