1 //===-- llvm/InstrTypes.h - Important Instruction subclasses ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTION_TYPES_H
17 #define LLVM_INSTRUCTION_TYPES_H
19 #include "llvm/Instruction.h"
20 #include "llvm/OperandTraits.h"
24 //===----------------------------------------------------------------------===//
25 // TerminatorInst Class
26 //===----------------------------------------------------------------------===//
28 /// TerminatorInst - Subclasses of this class are all able to terminate a basic
29 /// block. Thus, these are all the flow control type of operations.
31 class TerminatorInst : public Instruction {
33 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
34 Use *Ops, unsigned NumOps,
35 Instruction *InsertBefore = 0)
36 : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
38 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
39 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
40 : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
42 // Out of line virtual method, so the vtable, etc has a home.
45 /// Virtual methods - Terminators should overload these and provide inline
46 /// overrides of non-V methods.
47 virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
48 virtual unsigned getNumSuccessorsV() const = 0;
49 virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
52 virtual Instruction *clone() const = 0;
54 /// getNumSuccessors - Return the number of successors that this terminator
56 unsigned getNumSuccessors() const {
57 return getNumSuccessorsV();
60 /// getSuccessor - Return the specified successor.
62 BasicBlock *getSuccessor(unsigned idx) const {
63 return getSuccessorV(idx);
66 /// setSuccessor - Update the specified successor to point at the provided
68 void setSuccessor(unsigned idx, BasicBlock *B) {
69 setSuccessorV(idx, B);
72 // Methods for support type inquiry through isa, cast, and dyn_cast:
73 static inline bool classof(const TerminatorInst *) { return true; }
74 static inline bool classof(const Instruction *I) {
75 return I->getOpcode() >= TermOpsBegin && I->getOpcode() < TermOpsEnd;
77 static inline bool classof(const Value *V) {
78 return isa<Instruction>(V) && classof(cast<Instruction>(V));
83 //===----------------------------------------------------------------------===//
84 // UnaryInstruction Class
85 //===----------------------------------------------------------------------===//
87 class UnaryInstruction : public Instruction {
88 void *operator new(size_t, unsigned); // Do not implement
89 UnaryInstruction(const UnaryInstruction&); // Do not implement
92 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB = 0)
93 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
96 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
97 : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
101 // allocate space for exactly one operand
102 void *operator new(size_t s) {
103 return User::operator new(s, 1);
106 // Out of line virtual method, so the vtable, etc has a home.
109 /// Transparently provide more efficient getOperand methods.
110 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
112 // Methods for support type inquiry through isa, cast, and dyn_cast:
113 static inline bool classof(const UnaryInstruction *) { return true; }
114 static inline bool classof(const Instruction *I) {
115 return I->getOpcode() == Instruction::Malloc ||
116 I->getOpcode() == Instruction::Alloca ||
117 I->getOpcode() == Instruction::Free ||
118 I->getOpcode() == Instruction::Load ||
119 I->getOpcode() == Instruction::VAArg ||
120 I->getOpcode() == Instruction::GetResult ||
121 (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
123 static inline bool classof(const Value *V) {
124 return isa<Instruction>(V) && classof(cast<Instruction>(V));
129 struct OperandTraits<UnaryInstruction> : FixedNumOperandTraits<1> {
132 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
134 //===----------------------------------------------------------------------===//
135 // BinaryOperator Class
136 //===----------------------------------------------------------------------===//
138 class BinaryOperator : public Instruction {
139 void *operator new(size_t, unsigned); // Do not implement
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);
147 // allocate space for exactly two operands
148 void *operator new(size_t s) {
149 return User::operator new(s, 2);
152 /// Transparently provide more efficient getOperand methods.
153 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
155 /// create() - Construct a binary instruction, given the opcode and the two
156 /// operands. Optionally (if InstBefore is specified) insert the instruction
157 /// into a BasicBlock right before the specified instruction. The specified
158 /// Instruction is allowed to be a dereferenced end iterator.
160 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
161 const std::string &Name = "",
162 Instruction *InsertBefore = 0);
164 /// create() - Construct a binary instruction, given the opcode and the two
165 /// operands. Also automatically insert this instruction to the end of the
166 /// BasicBlock specified.
168 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
169 const std::string &Name,
170 BasicBlock *InsertAtEnd);
172 /// create* - These methods just forward to create, and are useful when you
173 /// statically know what type of instruction you're going to create. These
174 /// helpers just save some typing.
175 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
176 static BinaryOperator *create##OPC(Value *V1, Value *V2, \
177 const std::string &Name = "") {\
178 return create(Instruction::OPC, V1, V2, Name);\
180 #include "llvm/Instruction.def"
181 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
182 static BinaryOperator *create##OPC(Value *V1, Value *V2, \
183 const std::string &Name, BasicBlock *BB) {\
184 return create(Instruction::OPC, V1, V2, Name, BB);\
186 #include "llvm/Instruction.def"
187 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
188 static BinaryOperator *create##OPC(Value *V1, Value *V2, \
189 const std::string &Name, Instruction *I) {\
190 return create(Instruction::OPC, V1, V2, Name, I);\
192 #include "llvm/Instruction.def"
195 /// Helper functions to construct and inspect unary operations (NEG and NOT)
196 /// via binary operators SUB and XOR:
198 /// createNeg, createNot - Create the NEG and NOT
199 /// instructions out of SUB and XOR instructions.
201 static BinaryOperator *createNeg(Value *Op, const std::string &Name = "",
202 Instruction *InsertBefore = 0);
203 static BinaryOperator *createNeg(Value *Op, const std::string &Name,
204 BasicBlock *InsertAtEnd);
205 static BinaryOperator *createNot(Value *Op, const std::string &Name = "",
206 Instruction *InsertBefore = 0);
207 static BinaryOperator *createNot(Value *Op, const std::string &Name,
208 BasicBlock *InsertAtEnd);
210 /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction.
212 static bool isNeg(const Value *V);
213 static bool isNot(const Value *V);
215 /// getNegArgument, getNotArgument - Helper functions to extract the
216 /// unary argument of a NEG or NOT operation implemented via Sub or Xor.
218 static const Value *getNegArgument(const Value *BinOp);
219 static Value *getNegArgument( Value *BinOp);
220 static const Value *getNotArgument(const Value *BinOp);
221 static Value *getNotArgument( Value *BinOp);
223 BinaryOps getOpcode() const {
224 return static_cast<BinaryOps>(Instruction::getOpcode());
227 virtual BinaryOperator *clone() const;
229 /// swapOperands - Exchange the two operands to this instruction.
230 /// This instruction is safe to use on any binary instruction and
231 /// does not modify the semantics of the instruction. If the instruction
232 /// cannot be reversed (ie, it's a Div), then return true.
236 // Methods for support type inquiry through isa, cast, and dyn_cast:
237 static inline bool classof(const BinaryOperator *) { return true; }
238 static inline bool classof(const Instruction *I) {
239 return I->getOpcode() >= BinaryOpsBegin && I->getOpcode() < BinaryOpsEnd;
241 static inline bool classof(const Value *V) {
242 return isa<Instruction>(V) && classof(cast<Instruction>(V));
247 struct OperandTraits<BinaryOperator> : FixedNumOperandTraits<2> {
250 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
252 //===----------------------------------------------------------------------===//
254 //===----------------------------------------------------------------------===//
256 /// CastInst - This is the base class for all instructions that perform data
257 /// casts. It is simply provided so that instruction category testing
258 /// can be performed with code like:
260 /// if (isa<CastInst>(Instr)) { ... }
261 /// @brief Base class of casting instructions.
262 class CastInst : public UnaryInstruction {
263 /// @brief Copy constructor
264 CastInst(const CastInst &CI)
265 : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) {
267 /// @brief Do not allow default construction
270 /// @brief Constructor with insert-before-instruction semantics for subclasses
271 CastInst(const Type *Ty, unsigned iType, Value *S,
272 const std::string &Name = "", Instruction *InsertBefore = 0)
273 : UnaryInstruction(Ty, iType, S, InsertBefore) {
276 /// @brief Constructor with insert-at-end-of-block semantics for subclasses
277 CastInst(const Type *Ty, unsigned iType, Value *S,
278 const std::string &Name, BasicBlock *InsertAtEnd)
279 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
283 /// Provides a way to construct any of the CastInst subclasses using an
284 /// opcode instead of the subclass's constructor. The opcode must be in the
285 /// CastOps category (Instruction::isCast(opcode) returns true). This
286 /// constructor has insert-before-instruction semantics to automatically
287 /// insert the new CastInst before InsertBefore (if it is non-null).
288 /// @brief Construct any of the CastInst subclasses
289 static CastInst *create(
290 Instruction::CastOps, ///< The opcode of the cast instruction
291 Value *S, ///< The value to be casted (operand 0)
292 const Type *Ty, ///< The type to which cast should be made
293 const std::string &Name = "", ///< Name for the instruction
294 Instruction *InsertBefore = 0 ///< Place to insert the instruction
296 /// Provides a way to construct any of the CastInst subclasses using an
297 /// opcode instead of the subclass's constructor. The opcode must be in the
298 /// CastOps category. This constructor has insert-at-end-of-block semantics
299 /// to automatically insert the new CastInst at the end of InsertAtEnd (if
301 /// @brief Construct any of the CastInst subclasses
302 static CastInst *create(
303 Instruction::CastOps, ///< The opcode for the cast instruction
304 Value *S, ///< The value to be casted (operand 0)
305 const Type *Ty, ///< The type to which operand is casted
306 const std::string &Name, ///< The name for the instruction
307 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
310 /// @brief Create a ZExt or BitCast cast instruction
311 static CastInst *createZExtOrBitCast(
312 Value *S, ///< The value to be casted (operand 0)
313 const Type *Ty, ///< The type to which cast should be made
314 const std::string &Name = "", ///< Name for the instruction
315 Instruction *InsertBefore = 0 ///< Place to insert the instruction
318 /// @brief Create a ZExt or BitCast cast instruction
319 static CastInst *createZExtOrBitCast(
320 Value *S, ///< The value to be casted (operand 0)
321 const Type *Ty, ///< The type to which operand is casted
322 const std::string &Name, ///< The name for the instruction
323 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
326 /// @brief Create a SExt or BitCast cast instruction
327 static CastInst *createSExtOrBitCast(
328 Value *S, ///< The value to be casted (operand 0)
329 const Type *Ty, ///< The type to which cast should be made
330 const std::string &Name = "", ///< Name for the instruction
331 Instruction *InsertBefore = 0 ///< Place to insert the instruction
334 /// @brief Create a BitCast or a PtrToInt cast instruction
335 static CastInst *createPointerCast(
336 Value *S, ///< The pointer value to be casted (operand 0)
337 const Type *Ty, ///< The type to which operand is casted
338 const std::string &Name, ///< The name for the instruction
339 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
342 /// @brief Create a BitCast or a PtrToInt cast instruction
343 static CastInst *createPointerCast(
344 Value *S, ///< The pointer value to be casted (operand 0)
345 const Type *Ty, ///< The type to which cast should be made
346 const std::string &Name = "", ///< Name for the instruction
347 Instruction *InsertBefore = 0 ///< Place to insert the instruction
350 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
351 static CastInst *createIntegerCast(
352 Value *S, ///< The pointer value to be casted (operand 0)
353 const Type *Ty, ///< The type to which cast should be made
354 bool isSigned, ///< Whether to regard S as signed or not
355 const std::string &Name = "", ///< Name for the instruction
356 Instruction *InsertBefore = 0 ///< Place to insert the instruction
359 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
360 static CastInst *createIntegerCast(
361 Value *S, ///< The integer value to be casted (operand 0)
362 const Type *Ty, ///< The integer type to which operand is casted
363 bool isSigned, ///< Whether to regard S as signed or not
364 const std::string &Name, ///< The name for the instruction
365 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
368 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
369 static CastInst *createFPCast(
370 Value *S, ///< The floating point value to be casted
371 const Type *Ty, ///< The floating point type to cast to
372 const std::string &Name = "", ///< Name for the instruction
373 Instruction *InsertBefore = 0 ///< Place to insert the instruction
376 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
377 static CastInst *createFPCast(
378 Value *S, ///< The floating point value to be casted
379 const Type *Ty, ///< The floating point type to cast to
380 const std::string &Name, ///< The name for the instruction
381 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
384 /// @brief Create a SExt or BitCast cast instruction
385 static CastInst *createSExtOrBitCast(
386 Value *S, ///< The value to be casted (operand 0)
387 const Type *Ty, ///< The type to which operand is casted
388 const std::string &Name, ///< The name for the instruction
389 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
392 /// @brief Create a Trunc or BitCast cast instruction
393 static CastInst *createTruncOrBitCast(
394 Value *S, ///< The value to be casted (operand 0)
395 const Type *Ty, ///< The type to which cast should be made
396 const std::string &Name = "", ///< Name for the instruction
397 Instruction *InsertBefore = 0 ///< Place to insert the instruction
400 /// @brief Create a Trunc or BitCast cast instruction
401 static CastInst *createTruncOrBitCast(
402 Value *S, ///< The value to be casted (operand 0)
403 const Type *Ty, ///< The type to which operand is casted
404 const std::string &Name, ///< The name for the instruction
405 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
408 /// @brief Check whether it is valid to call getCastOpcode for these types.
409 static bool isCastable(
410 const Type *SrcTy, ///< The Type from which the value should be cast.
411 const Type *DestTy ///< The Type to which the value should be cast.
414 /// Returns the opcode necessary to cast Val into Ty using usual casting
416 /// @brief Infer the opcode for cast operand and type
417 static Instruction::CastOps getCastOpcode(
418 const Value *Val, ///< The value to cast
419 bool SrcIsSigned, ///< Whether to treat the source as signed
420 const Type *Ty, ///< The Type to which the value should be casted
421 bool DstIsSigned ///< Whether to treate the dest. as signed
424 /// There are several places where we need to know if a cast instruction
425 /// only deals with integer source and destination types. To simplify that
426 /// logic, this method is provided.
427 /// @returns true iff the cast has only integral typed operand and dest type.
428 /// @brief Determine if this is an integer-only cast.
429 bool isIntegerCast() const;
431 /// A lossless cast is one that does not alter the basic value. It implies
432 /// a no-op cast but is more stringent, preventing things like int->float,
433 /// long->double, int->ptr, or vector->anything.
434 /// @returns true iff the cast is lossless.
435 /// @brief Determine if this is a lossless cast.
436 bool isLosslessCast() const;
438 /// A no-op cast is one that can be effected without changing any bits.
439 /// It implies that the source and destination types are the same size. The
440 /// IntPtrTy argument is used to make accurate determinations for casts
441 /// involving Integer and Pointer types. They are no-op casts if the integer
442 /// is the same size as the pointer. However, pointer size varies with
443 /// platform. Generally, the result of TargetData::getIntPtrType() should be
444 /// passed in. If that's not available, use Type::Int64Ty, which will make
445 /// the isNoopCast call conservative.
446 /// @brief Determine if this cast is a no-op cast.
448 const Type *IntPtrTy ///< Integer type corresponding to pointer
451 /// Determine how a pair of casts can be eliminated, if they can be at all.
452 /// This is a helper function for both CastInst and ConstantExpr.
453 /// @returns 0 if the CastInst pair can't be eliminated
454 /// @returns Instruction::CastOps value for a cast that can replace
455 /// the pair, casting SrcTy to DstTy.
456 /// @brief Determine if a cast pair is eliminable
457 static unsigned isEliminableCastPair(
458 Instruction::CastOps firstOpcode, ///< Opcode of first cast
459 Instruction::CastOps secondOpcode, ///< Opcode of second cast
460 const Type *SrcTy, ///< SrcTy of 1st cast
461 const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
462 const Type *DstTy, ///< DstTy of 2nd cast
463 const Type *IntPtrTy ///< Integer type corresponding to Ptr types
466 /// @brief Return the opcode of this CastInst
467 Instruction::CastOps getOpcode() const {
468 return Instruction::CastOps(Instruction::getOpcode());
471 /// @brief Return the source type, as a convenience
472 const Type* getSrcTy() const { return getOperand(0)->getType(); }
473 /// @brief Return the destination type, as a convenience
474 const Type* getDestTy() const { return getType(); }
476 /// This method can be used to determine if a cast from S to DstTy using
477 /// Opcode op is valid or not.
478 /// @returns true iff the proposed cast is valid.
479 /// @brief Determine if a cast is valid without creating one.
480 static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
482 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
483 static inline bool classof(const CastInst *) { return true; }
484 static inline bool classof(const Instruction *I) {
485 return I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd;
487 static inline bool classof(const Value *V) {
488 return isa<Instruction>(V) && classof(cast<Instruction>(V));
492 //===----------------------------------------------------------------------===//
494 //===----------------------------------------------------------------------===//
496 /// This class is the base class for the comparison instructions.
497 /// @brief Abstract base class of comparison instructions.
498 // FIXME: why not derive from BinaryOperator?
499 class CmpInst: public Instruction {
500 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
501 CmpInst(); // do not implement
503 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
504 Value *LHS, Value *RHS, const std::string &Name = "",
505 Instruction *InsertBefore = 0);
507 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
508 Value *LHS, Value *RHS, const std::string &Name,
509 BasicBlock *InsertAtEnd);
512 /// This enumeration lists the possible predicates for CmpInst subclasses.
513 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
514 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
515 /// predicate values are not overlapping between the classes.
517 // Opcode U L G E Intuitive operation
518 FCMP_FALSE = 0, /// 0 0 0 0 Always false (always folded)
519 FCMP_OEQ = 1, /// 0 0 0 1 True if ordered and equal
520 FCMP_OGT = 2, /// 0 0 1 0 True if ordered and greater than
521 FCMP_OGE = 3, /// 0 0 1 1 True if ordered and greater than or equal
522 FCMP_OLT = 4, /// 0 1 0 0 True if ordered and less than
523 FCMP_OLE = 5, /// 0 1 0 1 True if ordered and less than or equal
524 FCMP_ONE = 6, /// 0 1 1 0 True if ordered and operands are unequal
525 FCMP_ORD = 7, /// 0 1 1 1 True if ordered (no nans)
526 FCMP_UNO = 8, /// 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
527 FCMP_UEQ = 9, /// 1 0 0 1 True if unordered or equal
528 FCMP_UGT = 10, /// 1 0 1 0 True if unordered or greater than
529 FCMP_UGE = 11, /// 1 0 1 1 True if unordered, greater than, or equal
530 FCMP_ULT = 12, /// 1 1 0 0 True if unordered or less than
531 FCMP_ULE = 13, /// 1 1 0 1 True if unordered, less than, or equal
532 FCMP_UNE = 14, /// 1 1 1 0 True if unordered or not equal
533 FCMP_TRUE = 15, /// 1 1 1 1 Always true (always folded)
534 FIRST_FCMP_PREDICATE = FCMP_FALSE,
535 LAST_FCMP_PREDICATE = FCMP_TRUE,
536 BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
537 ICMP_EQ = 32, /// equal
538 ICMP_NE = 33, /// not equal
539 ICMP_UGT = 34, /// unsigned greater than
540 ICMP_UGE = 35, /// unsigned greater or equal
541 ICMP_ULT = 36, /// unsigned less than
542 ICMP_ULE = 37, /// unsigned less or equal
543 ICMP_SGT = 38, /// signed greater than
544 ICMP_SGE = 39, /// signed greater or equal
545 ICMP_SLT = 40, /// signed less than
546 ICMP_SLE = 41, /// signed less or equal
547 FIRST_ICMP_PREDICATE = ICMP_EQ,
548 LAST_ICMP_PREDICATE = ICMP_SLE,
549 BAD_ICMP_PREDICATE = ICMP_SLE + 1
552 // allocate space for exactly two operands
553 void *operator new(size_t s) {
554 return User::operator new(s, 2);
556 /// Construct a compare instruction, given the opcode, the predicate and
557 /// the two operands. Optionally (if InstBefore is specified) insert the
558 /// instruction into a BasicBlock right before the specified instruction.
559 /// The specified Instruction is allowed to be a dereferenced end iterator.
560 /// @brief Create a CmpInst
561 static CmpInst *create(OtherOps Op, unsigned short predicate, Value *S1,
562 Value *S2, const std::string &Name = "",
563 Instruction *InsertBefore = 0);
565 /// Construct a compare instruction, given the opcode, the predicate and the
566 /// two operands. Also automatically insert this instruction to the end of
567 /// the BasicBlock specified.
568 /// @brief Create a CmpInst
569 static CmpInst *create(OtherOps Op, unsigned short predicate, Value *S1,
570 Value *S2, const std::string &Name,
571 BasicBlock *InsertAtEnd);
573 /// @brief Get the opcode casted to the right type
574 OtherOps getOpcode() const {
575 return static_cast<OtherOps>(Instruction::getOpcode());
578 /// The predicate for CmpInst is defined by the subclasses but stored in
579 /// the SubclassData field (see Value.h). We allow it to be fetched here
580 /// as the predicate but there is no enum type for it, just the raw unsigned
581 /// short. This facilitates comparison of CmpInst instances without delving
582 /// into the subclasses since predicate values are distinct between the
583 /// CmpInst subclasses.
584 /// @brief Return the predicate for this instruction.
585 unsigned short getPredicate() const {
589 /// @brief Provide more efficient getOperand methods.
590 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
592 /// This is just a convenience that dispatches to the subclasses.
593 /// @brief Swap the operands and adjust predicate accordingly to retain
594 /// the same comparison.
597 /// This is just a convenience that dispatches to the subclasses.
598 /// @brief Determine if this CmpInst is commutative.
599 bool isCommutative();
601 /// This is just a convenience that dispatches to the subclasses.
602 /// @brief Determine if this is an equals/not equals predicate.
605 /// @returns true if the predicate is unsigned, false otherwise.
606 /// @brief Determine if the predicate is an unsigned operation.
607 static bool isUnsigned(unsigned short predicate);
609 /// @returns true if the predicate is signed, false otherwise.
610 /// @brief Determine if the predicate is an signed operation.
611 static bool isSigned(unsigned short predicate);
613 /// @brief Determine if the predicate is an ordered operation.
614 static bool isOrdered(unsigned short predicate);
616 /// @brief Determine if the predicate is an unordered operation.
617 static bool isUnordered(unsigned short predicate);
619 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
620 static inline bool classof(const CmpInst *) { return true; }
621 static inline bool classof(const Instruction *I) {
622 return I->getOpcode() == Instruction::ICmp ||
623 I->getOpcode() == Instruction::FCmp ||
624 I->getOpcode() == Instruction::VICmp ||
625 I->getOpcode() == Instruction::VFCmp;
627 static inline bool classof(const Value *V) {
628 return isa<Instruction>(V) && classof(cast<Instruction>(V));
633 // FIXME: these are redundant if CmpInst < BinaryOperator
635 struct OperandTraits<CmpInst> : FixedNumOperandTraits<2> {
638 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
640 } // End llvm namespace