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