API changes for class Use size reduction, wave 1.
[oota-llvm.git] / include / llvm / InstrTypes.h
1 //===-- llvm/InstrTypes.h - Important Instruction subclasses ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines various meta classes of instructions that exist in the VM
11 // representation.  Specific concrete subclasses of these may be found in the
12 // i*.h files...
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INSTRUCTION_TYPES_H
17 #define LLVM_INSTRUCTION_TYPES_H
18
19 #include "llvm/Instruction.h"
20
21 namespace llvm {
22
23 //===----------------------------------------------------------------------===//
24 //                            TerminatorInst Class
25 //===----------------------------------------------------------------------===//
26
27 /// TerminatorInst - Subclasses of this class are all able to terminate a basic
28 /// block.  Thus, these are all the flow control type of operations.
29 ///
30 class TerminatorInst : public Instruction {
31 protected:
32   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
33                  Use *Ops, unsigned NumOps,
34                  Instruction *InsertBefore = 0)
35     : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
36
37   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
38                  Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
39     : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
40
41   // Out of line virtual method, so the vtable, etc has a home.
42   ~TerminatorInst();
43
44   /// Virtual methods - Terminators should overload these and provide inline
45   /// overrides of non-V methods.
46   virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
47   virtual unsigned getNumSuccessorsV() const = 0;
48   virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
49 public:
50
51   virtual Instruction *clone() const = 0;
52
53   /// getNumSuccessors - Return the number of successors that this terminator
54   /// has.
55   unsigned getNumSuccessors() const {
56     return getNumSuccessorsV();
57   }
58
59   /// getSuccessor - Return the specified successor.
60   ///
61   BasicBlock *getSuccessor(unsigned idx) const {
62     return getSuccessorV(idx);
63   }
64
65   /// setSuccessor - Update the specified successor to point at the provided
66   /// block.
67   void setSuccessor(unsigned idx, BasicBlock *B) {
68     setSuccessorV(idx, B);
69   }
70
71   // Methods for support type inquiry through isa, cast, and dyn_cast:
72   static inline bool classof(const TerminatorInst *) { return true; }
73   static inline bool classof(const Instruction *I) {
74     return I->getOpcode() >= TermOpsBegin && I->getOpcode() < TermOpsEnd;
75   }
76   static inline bool classof(const Value *V) {
77     return isa<Instruction>(V) && classof(cast<Instruction>(V));
78   }
79 };
80
81 //===----------------------------------------------------------------------===//
82 //                          UnaryInstruction Class
83 //===----------------------------------------------------------------------===//
84
85 class UnaryInstruction : public Instruction {
86   void *operator new(size_t, unsigned); // Do not implement
87   Use Op;
88   
89   // avoiding warning: 'this' : used in base member initializer list
90   UnaryInstruction* this_() { return this; }
91 protected:
92   UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB =0)
93     : Instruction(Ty, iType, &Op, 1, IB), Op(V, this_()) {
94   }
95   UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
96     : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) {
97   }
98 public:
99   // allocate space for exactly one operand
100   void *operator new(size_t s) {
101     return User::operator new(s, 1);
102   }
103
104   // Out of line virtual method, so the vtable, etc has a home.
105   ~UnaryInstruction();
106
107   // Transparently provide more efficient getOperand methods.
108   Value *getOperand(unsigned i) const {
109     assert(i == 0 && "getOperand() out of range!");
110     return Op;
111   }
112   void setOperand(unsigned i, Value *Val) {
113     assert(i == 0 && "setOperand() out of range!");
114     Op = Val;
115   }
116   unsigned getNumOperands() const { return 1; }
117   
118   // Methods for support type inquiry through isa, cast, and dyn_cast:
119   static inline bool classof(const UnaryInstruction *) { return true; }
120   static inline bool classof(const Instruction *I) {
121     return I->getOpcode() == Instruction::Malloc ||
122            I->getOpcode() == Instruction::Alloca ||
123            I->getOpcode() == Instruction::Free ||
124            I->getOpcode() == Instruction::Load ||
125            I->getOpcode() == Instruction::VAArg ||
126            (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
127   }
128   static inline bool classof(const Value *V) {
129     return isa<Instruction>(V) && classof(cast<Instruction>(V));
130   }
131 };
132
133 //===----------------------------------------------------------------------===//
134 //                           BinaryOperator Class
135 //===----------------------------------------------------------------------===//
136
137 class BinaryOperator : public Instruction {
138   void *operator new(size_t, unsigned); // Do not implement
139   Use Ops[2];
140 protected:
141   void init(BinaryOps iType);
142   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
143                  const std::string &Name, Instruction *InsertBefore);
144   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
145                  const std::string &Name, BasicBlock *InsertAtEnd);
146 public:
147   // allocate space for exactly two operands
148   void *operator new(size_t s) {
149     return User::operator new(s, 2);
150   }
151
152   /// Transparently provide more efficient getOperand methods.
153   Value *getOperand(unsigned i) const {
154     assert(i < 2 && "getOperand() out of range!");
155     return Ops[i];
156   }
157   void setOperand(unsigned i, Value *Val) {
158     assert(i < 2 && "setOperand() out of range!");
159     Ops[i] = Val;
160   }
161   unsigned getNumOperands() const { return 2; }
162
163   /// create() - Construct a binary instruction, given the opcode and the two
164   /// operands.  Optionally (if InstBefore is specified) insert the instruction
165   /// into a BasicBlock right before the specified instruction.  The specified
166   /// Instruction is allowed to be a dereferenced end iterator.
167   ///
168   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
169                                 const std::string &Name = "",
170                                 Instruction *InsertBefore = 0);
171
172   /// create() - Construct a binary instruction, given the opcode and the two
173   /// operands.  Also automatically insert this instruction to the end of the
174   /// BasicBlock specified.
175   ///
176   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
177                                 const std::string &Name,
178                                 BasicBlock *InsertAtEnd);
179
180   /// create* - These methods just forward to create, and are useful when you
181   /// statically know what type of instruction you're going to create.  These
182   /// helpers just save some typing.
183 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
184   static BinaryOperator *create##OPC(Value *V1, Value *V2, \
185                                      const std::string &Name = "") {\
186     return create(Instruction::OPC, V1, V2, Name);\
187   }
188 #include "llvm/Instruction.def"
189 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
190   static BinaryOperator *create##OPC(Value *V1, Value *V2, \
191                                      const std::string &Name, BasicBlock *BB) {\
192     return create(Instruction::OPC, V1, V2, Name, BB);\
193   }
194 #include "llvm/Instruction.def"
195 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
196   static BinaryOperator *create##OPC(Value *V1, Value *V2, \
197                                      const std::string &Name, Instruction *I) {\
198     return create(Instruction::OPC, V1, V2, Name, I);\
199   }
200 #include "llvm/Instruction.def"
201
202
203   /// Helper functions to construct and inspect unary operations (NEG and NOT)
204   /// via binary operators SUB and XOR:
205   ///
206   /// createNeg, createNot - Create the NEG and NOT
207   ///     instructions out of SUB and XOR instructions.
208   ///
209   static BinaryOperator *createNeg(Value *Op, const std::string &Name = "",
210                                    Instruction *InsertBefore = 0);
211   static BinaryOperator *createNeg(Value *Op, const std::string &Name,
212                                    BasicBlock *InsertAtEnd);
213   static BinaryOperator *createNot(Value *Op, const std::string &Name = "",
214                                    Instruction *InsertBefore = 0);
215   static BinaryOperator *createNot(Value *Op, const std::string &Name,
216                                    BasicBlock *InsertAtEnd);
217
218   /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction.
219   ///
220   static bool isNeg(const Value *V);
221   static bool isNot(const Value *V);
222
223   /// getNegArgument, getNotArgument - Helper functions to extract the
224   ///     unary argument of a NEG or NOT operation implemented via Sub or Xor.
225   ///
226   static const Value *getNegArgument(const Value *BinOp);
227   static       Value *getNegArgument(      Value *BinOp);
228   static const Value *getNotArgument(const Value *BinOp);
229   static       Value *getNotArgument(      Value *BinOp);
230
231   BinaryOps getOpcode() const {
232     return static_cast<BinaryOps>(Instruction::getOpcode());
233   }
234
235   virtual BinaryOperator *clone() const;
236
237   /// swapOperands - Exchange the two operands to this instruction.
238   /// This instruction is safe to use on any binary instruction and
239   /// does not modify the semantics of the instruction.  If the
240   /// instruction is order dependent (SetLT f.e.) the opcode is
241   /// changed.  If the instruction cannot be reversed (ie, it's a Div),
242   /// then return true.
243   ///
244   bool swapOperands();
245
246   // Methods for support type inquiry through isa, cast, and dyn_cast:
247   static inline bool classof(const BinaryOperator *) { return true; }
248   static inline bool classof(const Instruction *I) {
249     return I->getOpcode() >= BinaryOpsBegin && I->getOpcode() < BinaryOpsEnd;
250   }
251   static inline bool classof(const Value *V) {
252     return isa<Instruction>(V) && classof(cast<Instruction>(V));
253   }
254 };
255
256 //===----------------------------------------------------------------------===//
257 //                               CastInst Class
258 //===----------------------------------------------------------------------===//
259
260 /// CastInst - This is the base class for all instructions that perform data
261 /// casts. It is simply provided so that instruction category testing
262 /// can be performed with code like:
263 ///
264 /// if (isa<CastInst>(Instr)) { ... }
265 /// @brief Base class of casting instructions.
266 class CastInst : public UnaryInstruction {
267   /// @brief Copy constructor
268   CastInst(const CastInst &CI)
269     : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) {
270   }
271   /// @brief Do not allow default construction
272   CastInst(); 
273 protected:
274   /// @brief Constructor with insert-before-instruction semantics for subclasses
275   CastInst(const Type *Ty, unsigned iType, Value *S, 
276            const std::string &Name = "", Instruction *InsertBefore = 0)
277     : UnaryInstruction(Ty, iType, S, InsertBefore) {
278     setName(Name);
279   }
280   /// @brief Constructor with insert-at-end-of-block semantics for subclasses
281   CastInst(const Type *Ty, unsigned iType, Value *S, 
282            const std::string &Name, BasicBlock *InsertAtEnd)
283     : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
284     setName(Name);
285   }
286 public:
287   /// Provides a way to construct any of the CastInst subclasses using an 
288   /// opcode instead of the subclass's constructor. The opcode must be in the
289   /// CastOps category (Instruction::isCast(opcode) returns true). This
290   /// constructor has insert-before-instruction semantics to automatically
291   /// insert the new CastInst before InsertBefore (if it is non-null).
292   /// @brief Construct any of the CastInst subclasses
293   static CastInst *create(
294     Instruction::CastOps,    ///< The opcode of the cast instruction
295     Value *S,                ///< The value to be casted (operand 0)
296     const Type *Ty,          ///< The type to which cast should be made
297     const std::string &Name = "", ///< Name for the instruction
298     Instruction *InsertBefore = 0 ///< Place to insert the instruction
299   );
300   /// Provides a way to construct any of the CastInst subclasses using an
301   /// opcode instead of the subclass's constructor. The opcode must be in the
302   /// CastOps category. This constructor has insert-at-end-of-block semantics
303   /// to automatically insert the new CastInst at the end of InsertAtEnd (if
304   /// its non-null).
305   /// @brief Construct any of the CastInst subclasses
306   static CastInst *create(
307     Instruction::CastOps,    ///< The opcode for the cast instruction
308     Value *S,                ///< The value to be casted (operand 0)
309     const Type *Ty,          ///< The type to which operand is casted
310     const std::string &Name, ///< The name for the instruction
311     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
312   );
313
314   /// @brief Create a ZExt or BitCast cast instruction
315   static CastInst *createZExtOrBitCast(
316     Value *S,                ///< The value to be casted (operand 0)
317     const Type *Ty,          ///< The type to which cast should be made
318     const std::string &Name = "", ///< Name for the instruction
319     Instruction *InsertBefore = 0 ///< Place to insert the instruction
320   );
321
322   /// @brief Create a ZExt or BitCast cast instruction
323   static CastInst *createZExtOrBitCast(
324     Value *S,                ///< The value to be casted (operand 0)
325     const Type *Ty,          ///< The type to which operand is casted
326     const std::string &Name, ///< The name for the instruction
327     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
328   );
329
330   /// @brief Create a SExt or BitCast cast instruction
331   static CastInst *createSExtOrBitCast(
332     Value *S,                ///< The value to be casted (operand 0)
333     const Type *Ty,          ///< The type to which cast should be made
334     const std::string &Name = "", ///< Name for the instruction
335     Instruction *InsertBefore = 0 ///< Place to insert the instruction
336   );
337
338   /// @brief Create a BitCast or a PtrToInt cast instruction
339   static CastInst *createPointerCast(
340     Value *S,                ///< The pointer value to be casted (operand 0)
341     const Type *Ty,          ///< The type to which operand is casted
342     const std::string &Name, ///< The name for the instruction
343     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
344   );
345
346   /// @brief Create a BitCast or a PtrToInt cast instruction
347   static CastInst *createPointerCast(
348     Value *S,                ///< The pointer value to be casted (operand 0)
349     const Type *Ty,          ///< The type to which cast should be made
350     const std::string &Name = "", ///< Name for the instruction
351     Instruction *InsertBefore = 0 ///< Place to insert the instruction
352   );
353
354   /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
355   static CastInst *createIntegerCast(
356     Value *S,                ///< The pointer value to be casted (operand 0)
357     const Type *Ty,          ///< The type to which cast should be made
358     bool isSigned,           ///< Whether to regard S as signed or not
359     const std::string &Name = "", ///< Name for the instruction
360     Instruction *InsertBefore = 0 ///< Place to insert the instruction
361   );
362
363   /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
364   static CastInst *createIntegerCast(
365     Value *S,                ///< The integer value to be casted (operand 0)
366     const Type *Ty,          ///< The integer type to which operand is casted
367     bool isSigned,           ///< Whether to regard S as signed or not
368     const std::string &Name, ///< The name for the instruction
369     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
370   );
371
372   /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
373   static CastInst *createFPCast(
374     Value *S,                ///< The floating point value to be casted 
375     const Type *Ty,          ///< The floating point type to cast to
376     const std::string &Name = "", ///< Name for the instruction
377     Instruction *InsertBefore = 0 ///< Place to insert the instruction
378   );
379
380   /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
381   static CastInst *createFPCast(
382     Value *S,                ///< The floating point value to be casted 
383     const Type *Ty,          ///< The floating point type to cast to
384     const std::string &Name, ///< The name for the instruction
385     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
386   );
387
388   /// @brief Create a SExt or BitCast cast instruction
389   static CastInst *createSExtOrBitCast(
390     Value *S,                ///< The value to be casted (operand 0)
391     const Type *Ty,          ///< The type to which operand is casted
392     const std::string &Name, ///< The name for the instruction
393     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
394   );
395
396   /// @brief Create a Trunc or BitCast cast instruction
397   static CastInst *createTruncOrBitCast(
398     Value *S,                ///< The value to be casted (operand 0)
399     const Type *Ty,          ///< The type to which cast should be made
400     const std::string &Name = "", ///< Name for the instruction
401     Instruction *InsertBefore = 0 ///< Place to insert the instruction
402   );
403
404   /// @brief Create a Trunc or BitCast cast instruction
405   static CastInst *createTruncOrBitCast(
406     Value *S,                ///< The value to be casted (operand 0)
407     const Type *Ty,          ///< The type to which operand is casted
408     const std::string &Name, ///< The name for the instruction
409     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
410   );
411
412   /// @brief Check whether it is valid to call getCastOpcode for these types.
413   static bool isCastable(
414     const Type *SrcTy, ///< The Type from which the value should be cast.
415     const Type *DestTy ///< The Type to which the value should be cast.
416   );
417
418   /// Returns the opcode necessary to cast Val into Ty using usual casting
419   /// rules.
420   /// @brief Infer the opcode for cast operand and type
421   static Instruction::CastOps getCastOpcode(
422     const Value *Val, ///< The value to cast
423     bool SrcIsSigned, ///< Whether to treat the source as signed
424     const Type *Ty,   ///< The Type to which the value should be casted
425     bool DstIsSigned  ///< Whether to treate the dest. as signed
426   );
427
428   /// There are several places where we need to know if a cast instruction 
429   /// only deals with integer source and destination types. To simplify that
430   /// logic, this method is provided.
431   /// @returns true iff the cast has only integral typed operand and dest type.
432   /// @brief Determine if this is an integer-only cast.
433   bool isIntegerCast() const;
434
435   /// A lossless cast is one that does not alter the basic value. It implies
436   /// a no-op cast but is more stringent, preventing things like int->float,
437   /// long->double, int->ptr, or vector->anything. 
438   /// @returns true iff the cast is lossless.
439   /// @brief Determine if this is a lossless cast.
440   bool isLosslessCast() const;
441
442   /// A no-op cast is one that can be effected without changing any bits. 
443   /// It implies that the source and destination types are the same size. The
444   /// IntPtrTy argument is used to make accurate determinations for casts 
445   /// involving Integer and Pointer types. They are no-op casts if the integer
446   /// is the same size as the pointer. However, pointer size varies with 
447   /// platform. Generally, the result of TargetData::getIntPtrType() should be
448   /// passed in. If that's not available, use Type::Int64Ty, which will make
449   /// the isNoopCast call conservative.
450   /// @brief Determine if this cast is a no-op cast. 
451   bool isNoopCast(
452     const Type *IntPtrTy ///< Integer type corresponding to pointer
453   ) const;
454
455   /// Determine how a pair of casts can be eliminated, if they can be at all.
456   /// This is a helper function for both CastInst and ConstantExpr.
457   /// @returns 0 if the CastInst pair can't be eliminated
458   /// @returns Instruction::CastOps value for a cast that can replace 
459   /// the pair, casting SrcTy to DstTy.
460   /// @brief Determine if a cast pair is eliminable
461   static unsigned isEliminableCastPair(
462     Instruction::CastOps firstOpcode,  ///< Opcode of first cast
463     Instruction::CastOps secondOpcode, ///< Opcode of second cast
464     const Type *SrcTy, ///< SrcTy of 1st cast
465     const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
466     const Type *DstTy, ///< DstTy of 2nd cast
467     const Type *IntPtrTy ///< Integer type corresponding to Ptr types
468   );
469
470   /// @brief Return the opcode of this CastInst
471   Instruction::CastOps getOpcode() const { 
472     return Instruction::CastOps(Instruction::getOpcode()); 
473   }
474
475   /// @brief Return the source type, as a convenience
476   const Type* getSrcTy() const { return getOperand(0)->getType(); }
477   /// @brief Return the destination type, as a convenience
478   const Type* getDestTy() const { return getType(); }
479
480   /// This method can be used to determine if a cast from S to DstTy using
481   /// Opcode op is valid or not. 
482   /// @returns true iff the proposed cast is valid.
483   /// @brief Determine if a cast is valid without creating one.
484   static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
485
486   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
487   static inline bool classof(const CastInst *) { return true; }
488   static inline bool classof(const Instruction *I) {
489     return I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd;
490   }
491   static inline bool classof(const Value *V) {
492     return isa<Instruction>(V) && classof(cast<Instruction>(V));
493   }
494 };
495
496 //===----------------------------------------------------------------------===//
497 //                               CmpInst Class
498 //===----------------------------------------------------------------------===//
499
500 /// This class is the base class for the comparison instructions. 
501 /// @brief Abstract base class of comparison instructions.
502 class CmpInst: public Instruction {
503   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
504   CmpInst(); // do not implement
505 protected:
506   CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS,
507           const std::string &Name = "", Instruction *InsertBefore = 0);
508   
509   CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS,
510           const std::string &Name, BasicBlock *InsertAtEnd);
511
512   Use Ops[2]; // CmpInst instructions always have 2 operands, optimize
513
514 public:
515   // allocate space for exactly two operands
516   void *operator new(size_t s) {
517     return User::operator new(s, 2);
518   }
519   /// Construct a compare instruction, given the opcode, the predicate and 
520   /// the two operands.  Optionally (if InstBefore is specified) insert the 
521   /// instruction into a BasicBlock right before the specified instruction.  
522   /// The specified Instruction is allowed to be a dereferenced end iterator.
523   /// @brief Create a CmpInst
524   static CmpInst *create(OtherOps Op, unsigned short predicate, Value *S1, 
525                          Value *S2, const std::string &Name = "",
526                          Instruction *InsertBefore = 0);
527
528   /// Construct a compare instruction, given the opcode, the predicate and the 
529   /// two operands.  Also automatically insert this instruction to the end of 
530   /// the BasicBlock specified.
531   /// @brief Create a CmpInst
532   static CmpInst *create(OtherOps Op, unsigned short predicate, Value *S1, 
533                          Value *S2, const std::string &Name, 
534                          BasicBlock *InsertAtEnd);
535
536   /// @brief Get the opcode casted to the right type
537   OtherOps getOpcode() const {
538     return static_cast<OtherOps>(Instruction::getOpcode());
539   }
540
541   /// The predicate for CmpInst is defined by the subclasses but stored in 
542   /// the SubclassData field (see Value.h).  We allow it to be fetched here
543   /// as the predicate but there is no enum type for it, just the raw unsigned 
544   /// short. This facilitates comparison of CmpInst instances without delving
545   /// into the subclasses since predicate values are distinct between the
546   /// CmpInst subclasses.
547   /// @brief Return the predicate for this instruction.
548   unsigned short getPredicate() const {
549     return SubclassData;
550   }
551
552   /// @brief Provide more efficient getOperand methods.
553   Value *getOperand(unsigned i) const {
554     assert(i < 2 && "getOperand() out of range!");
555     return Ops[i];
556   }
557   void setOperand(unsigned i, Value *Val) {
558     assert(i < 2 && "setOperand() out of range!");
559     Ops[i] = Val;
560   }
561
562   /// @brief CmpInst instructions always have 2 operands.
563   unsigned getNumOperands() const { return 2; }
564
565   /// This is just a convenience that dispatches to the subclasses.
566   /// @brief Swap the operands and adjust predicate accordingly to retain
567   /// the same comparison.
568   void swapOperands();
569
570   /// This is just a convenience that dispatches to the subclasses.
571   /// @brief Determine if this CmpInst is commutative.
572   bool isCommutative();
573
574   /// This is just a convenience that dispatches to the subclasses.
575   /// @brief Determine if this is an equals/not equals predicate.
576   bool isEquality();
577
578   /// @returns true if the predicate is unsigned, false otherwise.
579   /// @brief Determine if the predicate is an unsigned operation.
580   static bool isUnsigned(unsigned short predicate);
581
582   /// @returns true if the predicate is signed, false otherwise.
583   /// @brief Determine if the predicate is an signed operation.
584   static bool isSigned(unsigned short predicate);
585
586   /// @brief Determine if the predicate is an ordered operation.
587   static bool isOrdered(unsigned short predicate);
588
589   /// @brief Determine if the predicate is an unordered operation.
590   static bool isUnordered(unsigned short predicate);
591
592   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
593   static inline bool classof(const CmpInst *) { return true; }
594   static inline bool classof(const Instruction *I) {
595     return I->getOpcode() == Instruction::ICmp || 
596            I->getOpcode() == Instruction::FCmp;
597   }
598   static inline bool classof(const Value *V) {
599     return isa<Instruction>(V) && classof(cast<Instruction>(V));
600   }
601 };
602
603 } // End llvm namespace
604
605 #endif