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"
21 #include "llvm/DerivedTypes.h"
25 //===----------------------------------------------------------------------===//
26 // TerminatorInst Class
27 //===----------------------------------------------------------------------===//
29 /// TerminatorInst - Subclasses of this class are all able to terminate a basic
30 /// block. Thus, these are all the flow control type of operations.
32 class TerminatorInst : public Instruction {
34 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
35 Use *Ops, unsigned NumOps,
36 Instruction *InsertBefore = 0)
37 : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
39 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
40 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
41 : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
43 // Out of line virtual method, so the vtable, etc has a home.
46 /// Virtual methods - Terminators should overload these and provide inline
47 /// overrides of non-V methods.
48 virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
49 virtual unsigned getNumSuccessorsV() const = 0;
50 virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
53 virtual Instruction *clone() const = 0;
55 /// getNumSuccessors - Return the number of successors that this terminator
57 unsigned getNumSuccessors() const {
58 return getNumSuccessorsV();
61 /// getSuccessor - Return the specified successor.
63 BasicBlock *getSuccessor(unsigned idx) const {
64 return getSuccessorV(idx);
67 /// setSuccessor - Update the specified successor to point at the provided
69 void setSuccessor(unsigned idx, BasicBlock *B) {
70 setSuccessorV(idx, B);
73 // Methods for support type inquiry through isa, cast, and dyn_cast:
74 static inline bool classof(const TerminatorInst *) { return true; }
75 static inline bool classof(const Instruction *I) {
76 return I->isTerminator();
78 static inline bool classof(const Value *V) {
79 return isa<Instruction>(V) && classof(cast<Instruction>(V));
84 //===----------------------------------------------------------------------===//
85 // UnaryInstruction Class
86 //===----------------------------------------------------------------------===//
88 class UnaryInstruction : public Instruction {
89 void *operator new(size_t, unsigned); // Do not implement
90 UnaryInstruction(const UnaryInstruction&); // Do not implement
93 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB = 0)
94 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
97 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
98 : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
102 // allocate space for exactly one operand
103 void *operator new(size_t s) {
104 return User::operator new(s, 1);
107 // Out of line virtual method, so the vtable, etc has a home.
110 /// Transparently provide more efficient getOperand methods.
111 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
113 // Methods for support type inquiry through isa, cast, and dyn_cast:
114 static inline bool classof(const UnaryInstruction *) { return true; }
115 static inline bool classof(const Instruction *I) {
116 return I->getOpcode() == Instruction::Malloc ||
117 I->getOpcode() == Instruction::Alloca ||
118 I->getOpcode() == Instruction::Free ||
119 I->getOpcode() == Instruction::Load ||
120 I->getOpcode() == Instruction::VAArg ||
121 I->getOpcode() == Instruction::ExtractValue ||
122 (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
124 static inline bool classof(const Value *V) {
125 return isa<Instruction>(V) && classof(cast<Instruction>(V));
130 struct OperandTraits<UnaryInstruction> : FixedNumOperandTraits<1> {
133 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
135 //===----------------------------------------------------------------------===//
136 // BinaryOperator Class
137 //===----------------------------------------------------------------------===//
139 class BinaryOperator : public Instruction {
140 void *operator new(size_t, unsigned); // Do not implement
142 void init(BinaryOps iType);
143 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
144 const std::string &Name, Instruction *InsertBefore);
145 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
146 const std::string &Name, BasicBlock *InsertAtEnd);
148 // allocate space for exactly two operands
149 void *operator new(size_t s) {
150 return User::operator new(s, 2);
153 /// Transparently provide more efficient getOperand methods.
154 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
156 /// Create() - Construct a binary instruction, given the opcode and the two
157 /// operands. Optionally (if InstBefore is specified) insert the instruction
158 /// into a BasicBlock right before the specified instruction. The specified
159 /// Instruction is allowed to be a dereferenced end iterator.
161 static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
162 const std::string &Name = "",
163 Instruction *InsertBefore = 0);
165 /// Create() - Construct a binary instruction, given the opcode and the two
166 /// operands. Also automatically insert this instruction to the end of the
167 /// BasicBlock specified.
169 static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
170 const std::string &Name,
171 BasicBlock *InsertAtEnd);
173 /// Create* - These methods just forward to Create, and are useful when you
174 /// statically know what type of instruction you're going to create. These
175 /// helpers just save some typing.
176 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
177 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
178 const std::string &Name = "") {\
179 return Create(Instruction::OPC, V1, V2, Name);\
181 #include "llvm/Instruction.def"
182 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
183 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
184 const std::string &Name, BasicBlock *BB) {\
185 return Create(Instruction::OPC, V1, V2, Name, BB);\
187 #include "llvm/Instruction.def"
188 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
189 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
190 const std::string &Name, Instruction *I) {\
191 return Create(Instruction::OPC, V1, V2, Name, I);\
193 #include "llvm/Instruction.def"
196 /// Helper functions to construct and inspect unary operations (NEG and NOT)
197 /// via binary operators SUB and XOR:
199 /// CreateNeg, CreateNot - Create the NEG and NOT
200 /// instructions out of SUB and XOR instructions.
202 static BinaryOperator *CreateNeg(Value *Op, const std::string &Name = "",
203 Instruction *InsertBefore = 0);
204 static BinaryOperator *CreateNeg(Value *Op, const std::string &Name,
205 BasicBlock *InsertAtEnd);
206 static BinaryOperator *CreateNot(Value *Op, const std::string &Name = "",
207 Instruction *InsertBefore = 0);
208 static BinaryOperator *CreateNot(Value *Op, const std::string &Name,
209 BasicBlock *InsertAtEnd);
211 /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction.
213 static bool isNeg(const Value *V);
214 static bool isNot(const Value *V);
216 /// getNegArgument, getNotArgument - Helper functions to extract the
217 /// unary argument of a NEG or NOT operation implemented via Sub or Xor.
219 static const Value *getNegArgument(const Value *BinOp);
220 static Value *getNegArgument( Value *BinOp);
221 static const Value *getNotArgument(const Value *BinOp);
222 static Value *getNotArgument( Value *BinOp);
224 BinaryOps getOpcode() const {
225 return static_cast<BinaryOps>(Instruction::getOpcode());
228 virtual BinaryOperator *clone() const;
230 /// swapOperands - Exchange the two operands to this instruction.
231 /// This instruction is safe to use on any binary instruction and
232 /// does not modify the semantics of the instruction. If the instruction
233 /// cannot be reversed (ie, it's a Div), then return true.
237 // Methods for support type inquiry through isa, cast, and dyn_cast:
238 static inline bool classof(const BinaryOperator *) { return true; }
239 static inline bool classof(const Instruction *I) {
240 return I->isBinaryOp();
242 static inline bool classof(const Value *V) {
243 return isa<Instruction>(V) && classof(cast<Instruction>(V));
248 struct OperandTraits<BinaryOperator> : FixedNumOperandTraits<2> {
251 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
253 //===----------------------------------------------------------------------===//
255 //===----------------------------------------------------------------------===//
257 /// CastInst - This is the base class for all instructions that perform data
258 /// casts. It is simply provided so that instruction category testing
259 /// can be performed with code like:
261 /// if (isa<CastInst>(Instr)) { ... }
262 /// @brief Base class of casting instructions.
263 class CastInst : public UnaryInstruction {
264 /// @brief Copy constructor
265 CastInst(const CastInst &CI)
266 : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) {
268 /// @brief Do not allow default construction
271 /// @brief Constructor with insert-before-instruction semantics for subclasses
272 CastInst(const Type *Ty, unsigned iType, Value *S,
273 const std::string &NameStr = "", Instruction *InsertBefore = 0)
274 : UnaryInstruction(Ty, iType, S, InsertBefore) {
277 /// @brief Constructor with insert-at-end-of-block semantics for subclasses
278 CastInst(const Type *Ty, unsigned iType, Value *S,
279 const std::string &NameStr, BasicBlock *InsertAtEnd)
280 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
284 /// Provides a way to construct any of the CastInst subclasses using an
285 /// opcode instead of the subclass's constructor. The opcode must be in the
286 /// CastOps category (Instruction::isCast(opcode) returns true). This
287 /// constructor has insert-before-instruction semantics to automatically
288 /// insert the new CastInst before InsertBefore (if it is non-null).
289 /// @brief Construct any of the CastInst subclasses
290 static CastInst *Create(
291 Instruction::CastOps, ///< The opcode of the cast instruction
292 Value *S, ///< The value to be casted (operand 0)
293 const Type *Ty, ///< The type to which cast should be made
294 const std::string &Name = "", ///< Name for the instruction
295 Instruction *InsertBefore = 0 ///< Place to insert the instruction
297 /// Provides a way to construct any of the CastInst subclasses using an
298 /// opcode instead of the subclass's constructor. The opcode must be in the
299 /// CastOps category. This constructor has insert-at-end-of-block semantics
300 /// to automatically insert the new CastInst at the end of InsertAtEnd (if
302 /// @brief Construct any of the CastInst subclasses
303 static CastInst *Create(
304 Instruction::CastOps, ///< The opcode for the cast instruction
305 Value *S, ///< The value to be casted (operand 0)
306 const Type *Ty, ///< The type to which operand is casted
307 const std::string &Name, ///< The name for the instruction
308 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
311 /// @brief Create a ZExt or BitCast cast instruction
312 static CastInst *CreateZExtOrBitCast(
313 Value *S, ///< The value to be casted (operand 0)
314 const Type *Ty, ///< The type to which cast should be made
315 const std::string &Name = "", ///< Name for the instruction
316 Instruction *InsertBefore = 0 ///< Place to insert the instruction
319 /// @brief Create a ZExt or BitCast cast instruction
320 static CastInst *CreateZExtOrBitCast(
321 Value *S, ///< The value to be casted (operand 0)
322 const Type *Ty, ///< The type to which operand is casted
323 const std::string &Name, ///< The name for the instruction
324 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
327 /// @brief Create a SExt or BitCast cast instruction
328 static CastInst *CreateSExtOrBitCast(
329 Value *S, ///< The value to be casted (operand 0)
330 const Type *Ty, ///< The type to which cast should be made
331 const std::string &Name = "", ///< Name for the instruction
332 Instruction *InsertBefore = 0 ///< Place to insert the instruction
335 /// @brief Create a SExt or BitCast cast instruction
336 static CastInst *CreateSExtOrBitCast(
337 Value *S, ///< The value to be casted (operand 0)
338 const Type *Ty, ///< The type to which operand is casted
339 const std::string &Name, ///< The name for the instruction
340 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
343 /// @brief Create a BitCast or a PtrToInt cast instruction
344 static CastInst *CreatePointerCast(
345 Value *S, ///< The pointer value to be casted (operand 0)
346 const Type *Ty, ///< The type to which operand is casted
347 const std::string &Name, ///< The name for the instruction
348 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
351 /// @brief Create a BitCast or a PtrToInt cast instruction
352 static CastInst *CreatePointerCast(
353 Value *S, ///< The pointer value to be casted (operand 0)
354 const Type *Ty, ///< The type to which cast should be made
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 pointer value to be casted (operand 0)
362 const Type *Ty, ///< The type to which cast should be made
363 bool isSigned, ///< Whether to regard S as signed or not
364 const std::string &Name = "", ///< Name for the instruction
365 Instruction *InsertBefore = 0 ///< Place to insert the instruction
368 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
369 static CastInst *CreateIntegerCast(
370 Value *S, ///< The integer value to be casted (operand 0)
371 const Type *Ty, ///< The integer type to which operand is casted
372 bool isSigned, ///< Whether to regard S as signed or not
373 const std::string &Name, ///< The name for the instruction
374 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
377 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
378 static CastInst *CreateFPCast(
379 Value *S, ///< The floating point value to be casted
380 const Type *Ty, ///< The floating point type to cast to
381 const std::string &Name = "", ///< Name for the instruction
382 Instruction *InsertBefore = 0 ///< Place to insert the instruction
385 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
386 static CastInst *CreateFPCast(
387 Value *S, ///< The floating point value to be casted
388 const Type *Ty, ///< The floating point type to cast to
389 const std::string &Name, ///< The name for the instruction
390 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
393 /// @brief Create a Trunc or BitCast cast instruction
394 static CastInst *CreateTruncOrBitCast(
395 Value *S, ///< The value to be casted (operand 0)
396 const Type *Ty, ///< The type to which cast should be made
397 const std::string &Name = "", ///< Name for the instruction
398 Instruction *InsertBefore = 0 ///< Place to insert the instruction
401 /// @brief Create a Trunc or BitCast cast instruction
402 static CastInst *CreateTruncOrBitCast(
403 Value *S, ///< The value to be casted (operand 0)
404 const Type *Ty, ///< The type to which operand is casted
405 const std::string &Name, ///< The name for the instruction
406 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
409 /// @brief Check whether it is valid to call getCastOpcode for these types.
410 static bool isCastable(
411 const Type *SrcTy, ///< The Type from which the value should be cast.
412 const Type *DestTy ///< The Type to which the value should be cast.
415 /// Returns the opcode necessary to cast Val into Ty using usual casting
417 /// @brief Infer the opcode for cast operand and type
418 static Instruction::CastOps getCastOpcode(
419 const Value *Val, ///< The value to cast
420 bool SrcIsSigned, ///< Whether to treat the source as signed
421 const Type *Ty, ///< The Type to which the value should be casted
422 bool DstIsSigned ///< Whether to treate the dest. as signed
425 /// There are several places where we need to know if a cast instruction
426 /// only deals with integer source and destination types. To simplify that
427 /// logic, this method is provided.
428 /// @returns true iff the cast has only integral typed operand and dest type.
429 /// @brief Determine if this is an integer-only cast.
430 bool isIntegerCast() const;
432 /// A lossless cast is one that does not alter the basic value. It implies
433 /// a no-op cast but is more stringent, preventing things like int->float,
434 /// long->double, int->ptr, or vector->anything.
435 /// @returns true iff the cast is lossless.
436 /// @brief Determine if this is a lossless cast.
437 bool isLosslessCast() const;
439 /// A no-op cast is one that can be effected without changing any bits.
440 /// It implies that the source and destination types are the same size. The
441 /// IntPtrTy argument is used to make accurate determinations for casts
442 /// involving Integer and Pointer types. They are no-op casts if the integer
443 /// is the same size as the pointer. However, pointer size varies with
444 /// platform. Generally, the result of TargetData::getIntPtrType() should be
445 /// passed in. If that's not available, use Type::Int64Ty, which will make
446 /// the isNoopCast call conservative.
447 /// @brief Determine if this cast is a no-op cast.
449 const Type *IntPtrTy ///< Integer type corresponding to pointer
452 /// Determine how a pair of casts can be eliminated, if they can be at all.
453 /// This is a helper function for both CastInst and ConstantExpr.
454 /// @returns 0 if the CastInst pair can't be eliminated
455 /// @returns Instruction::CastOps value for a cast that can replace
456 /// the pair, casting SrcTy to DstTy.
457 /// @brief Determine if a cast pair is eliminable
458 static unsigned isEliminableCastPair(
459 Instruction::CastOps firstOpcode, ///< Opcode of first cast
460 Instruction::CastOps secondOpcode, ///< Opcode of second cast
461 const Type *SrcTy, ///< SrcTy of 1st cast
462 const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
463 const Type *DstTy, ///< DstTy of 2nd cast
464 const Type *IntPtrTy ///< Integer type corresponding to Ptr types
467 /// @brief Return the opcode of this CastInst
468 Instruction::CastOps getOpcode() const {
469 return Instruction::CastOps(Instruction::getOpcode());
472 /// @brief Return the source type, as a convenience
473 const Type* getSrcTy() const { return getOperand(0)->getType(); }
474 /// @brief Return the destination type, as a convenience
475 const Type* getDestTy() const { return getType(); }
477 /// This method can be used to determine if a cast from S to DstTy using
478 /// Opcode op is valid or not.
479 /// @returns true iff the proposed cast is valid.
480 /// @brief Determine if a cast is valid without creating one.
481 static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
483 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
484 static inline bool classof(const CastInst *) { return true; }
485 static inline bool classof(const Instruction *I) {
488 static inline bool classof(const Value *V) {
489 return isa<Instruction>(V) && classof(cast<Instruction>(V));
493 //===----------------------------------------------------------------------===//
495 //===----------------------------------------------------------------------===//
497 /// This class is the base class for the comparison instructions.
498 /// @brief Abstract base class of comparison instructions.
499 // FIXME: why not derive from BinaryOperator?
500 class CmpInst: public Instruction {
501 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
502 CmpInst(); // do not implement
504 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
505 Value *LHS, Value *RHS, const std::string &Name = "",
506 Instruction *InsertBefore = 0);
508 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
509 Value *LHS, Value *RHS, const std::string &Name,
510 BasicBlock *InsertAtEnd);
513 /// This enumeration lists the possible predicates for CmpInst subclasses.
514 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
515 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
516 /// predicate values are not overlapping between the classes.
518 // Opcode U L G E Intuitive operation
519 FCMP_FALSE = 0, /// 0 0 0 0 Always false (always folded)
520 FCMP_OEQ = 1, /// 0 0 0 1 True if ordered and equal
521 FCMP_OGT = 2, /// 0 0 1 0 True if ordered and greater than
522 FCMP_OGE = 3, /// 0 0 1 1 True if ordered and greater than or equal
523 FCMP_OLT = 4, /// 0 1 0 0 True if ordered and less than
524 FCMP_OLE = 5, /// 0 1 0 1 True if ordered and less than or equal
525 FCMP_ONE = 6, /// 0 1 1 0 True if ordered and operands are unequal
526 FCMP_ORD = 7, /// 0 1 1 1 True if ordered (no nans)
527 FCMP_UNO = 8, /// 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
528 FCMP_UEQ = 9, /// 1 0 0 1 True if unordered or equal
529 FCMP_UGT = 10, /// 1 0 1 0 True if unordered or greater than
530 FCMP_UGE = 11, /// 1 0 1 1 True if unordered, greater than, or equal
531 FCMP_ULT = 12, /// 1 1 0 0 True if unordered or less than
532 FCMP_ULE = 13, /// 1 1 0 1 True if unordered, less than, or equal
533 FCMP_UNE = 14, /// 1 1 1 0 True if unordered or not equal
534 FCMP_TRUE = 15, /// 1 1 1 1 Always true (always folded)
535 FIRST_FCMP_PREDICATE = FCMP_FALSE,
536 LAST_FCMP_PREDICATE = FCMP_TRUE,
537 BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
538 ICMP_EQ = 32, /// equal
539 ICMP_NE = 33, /// not equal
540 ICMP_UGT = 34, /// unsigned greater than
541 ICMP_UGE = 35, /// unsigned greater or equal
542 ICMP_ULT = 36, /// unsigned less than
543 ICMP_ULE = 37, /// unsigned less or equal
544 ICMP_SGT = 38, /// signed greater than
545 ICMP_SGE = 39, /// signed greater or equal
546 ICMP_SLT = 40, /// signed less than
547 ICMP_SLE = 41, /// signed less or equal
548 FIRST_ICMP_PREDICATE = ICMP_EQ,
549 LAST_ICMP_PREDICATE = ICMP_SLE,
550 BAD_ICMP_PREDICATE = ICMP_SLE + 1
553 // allocate space for exactly two operands
554 void *operator new(size_t s) {
555 return User::operator new(s, 2);
557 /// Construct a compare instruction, given the opcode, the predicate and
558 /// the two operands. Optionally (if InstBefore is specified) insert the
559 /// instruction into a BasicBlock right before the specified instruction.
560 /// The specified Instruction is allowed to be a dereferenced end iterator.
561 /// @brief Create a CmpInst
562 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
563 Value *S2, const std::string &Name = "",
564 Instruction *InsertBefore = 0);
566 /// Construct a compare instruction, given the opcode, the predicate and the
567 /// two operands. Also automatically insert this instruction to the end of
568 /// the BasicBlock specified.
569 /// @brief Create a CmpInst
570 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
571 Value *S2, const std::string &Name,
572 BasicBlock *InsertAtEnd);
574 /// @brief Get the opcode casted to the right type
575 OtherOps getOpcode() const {
576 return static_cast<OtherOps>(Instruction::getOpcode());
579 /// @brief Return the predicate for this instruction.
580 Predicate getPredicate() const { return Predicate(SubclassData); }
582 /// @brief Set the predicate for this instruction to the specified value.
583 void setPredicate(Predicate P) { SubclassData = P; }
585 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
586 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
587 /// @returns the inverse predicate for the instruction's current predicate.
588 /// @brief Return the inverse of the instruction's predicate.
589 Predicate getInversePredicate() const {
590 return getInversePredicate(getPredicate());
593 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
594 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
595 /// @returns the inverse predicate for predicate provided in \p pred.
596 /// @brief Return the inverse of a given predicate
597 static Predicate getInversePredicate(Predicate pred);
599 /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
600 /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
601 /// @returns the predicate that would be the result of exchanging the two
602 /// operands of the CmpInst instruction without changing the result
604 /// @brief Return the predicate as if the operands were swapped
605 Predicate getSwappedPredicate() const {
606 return getSwappedPredicate(getPredicate());
609 /// This is a static version that you can use without an instruction
611 /// @brief Return the predicate as if the operands were swapped.
612 static Predicate getSwappedPredicate(Predicate pred);
614 /// @brief Provide more efficient getOperand methods.
615 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
617 /// This is just a convenience that dispatches to the subclasses.
618 /// @brief Swap the operands and adjust predicate accordingly to retain
619 /// the same comparison.
622 /// This is just a convenience that dispatches to the subclasses.
623 /// @brief Determine if this CmpInst is commutative.
624 bool isCommutative();
626 /// This is just a convenience that dispatches to the subclasses.
627 /// @brief Determine if this is an equals/not equals predicate.
630 /// @returns true if the predicate is unsigned, false otherwise.
631 /// @brief Determine if the predicate is an unsigned operation.
632 static bool isUnsigned(unsigned short predicate);
634 /// @returns true if the predicate is signed, false otherwise.
635 /// @brief Determine if the predicate is an signed operation.
636 static bool isSigned(unsigned short predicate);
638 /// @brief Determine if the predicate is an ordered operation.
639 static bool isOrdered(unsigned short predicate);
641 /// @brief Determine if the predicate is an unordered operation.
642 static bool isUnordered(unsigned short predicate);
644 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
645 static inline bool classof(const CmpInst *) { return true; }
646 static inline bool classof(const Instruction *I) {
647 return I->getOpcode() == Instruction::ICmp ||
648 I->getOpcode() == Instruction::FCmp ||
649 I->getOpcode() == Instruction::VICmp ||
650 I->getOpcode() == Instruction::VFCmp;
652 static inline bool classof(const Value *V) {
653 return isa<Instruction>(V) && classof(cast<Instruction>(V));
655 /// @brief Create a result type for fcmp/icmp (but not vicmp/vfcmp)
656 static const Type* makeCmpResultType(const Type* opnd_type) {
657 if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
658 return VectorType::get(Type::Int1Ty, vt->getNumElements());
665 // FIXME: these are redundant if CmpInst < BinaryOperator
667 struct OperandTraits<CmpInst> : FixedNumOperandTraits<2> {
670 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
672 } // End llvm namespace