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,
95 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
98 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
99 : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
103 // allocate space for exactly one operand
104 void *operator new(size_t s) {
105 return User::operator new(s, 1);
108 // Out of line virtual method, so the vtable, etc has a home.
111 /// Transparently provide more efficient getOperand methods.
112 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
114 // Methods for support type inquiry through isa, cast, and dyn_cast:
115 static inline bool classof(const UnaryInstruction *) { return true; }
116 static inline bool classof(const Instruction *I) {
117 return I->getOpcode() == Instruction::Malloc ||
118 I->getOpcode() == Instruction::Alloca ||
119 I->getOpcode() == Instruction::Free ||
120 I->getOpcode() == Instruction::Load ||
121 I->getOpcode() == Instruction::VAArg ||
122 I->getOpcode() == Instruction::ExtractValue ||
123 (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
125 static inline bool classof(const Value *V) {
126 return isa<Instruction>(V) && classof(cast<Instruction>(V));
131 struct OperandTraits<UnaryInstruction> : FixedNumOperandTraits<1> {
134 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
136 //===----------------------------------------------------------------------===//
137 // BinaryOperator Class
138 //===----------------------------------------------------------------------===//
140 class BinaryOperator : public Instruction {
141 void *operator new(size_t, unsigned); // Do not implement
143 void init(BinaryOps iType);
144 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
145 const std::string &Name, Instruction *InsertBefore);
146 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
147 const std::string &Name, BasicBlock *InsertAtEnd);
149 // allocate space for exactly two operands
150 void *operator new(size_t s) {
151 return User::operator new(s, 2);
154 /// Transparently provide more efficient getOperand methods.
155 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
157 /// Create() - Construct a binary instruction, given the opcode and the two
158 /// operands. Optionally (if InstBefore is specified) insert the instruction
159 /// into a BasicBlock right before the specified instruction. The specified
160 /// Instruction is allowed to be a dereferenced end iterator.
162 static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
163 const std::string &Name = "",
164 Instruction *InsertBefore = 0);
166 /// Create() - Construct a binary instruction, given the opcode and the two
167 /// operands. Also automatically insert this instruction to the end of the
168 /// BasicBlock specified.
170 static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
171 const std::string &Name,
172 BasicBlock *InsertAtEnd);
174 /// Create* - These methods just forward to Create, and are useful when you
175 /// statically know what type of instruction you're going to create. These
176 /// helpers just save some typing.
177 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
178 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
179 const std::string &Name = "") {\
180 return Create(Instruction::OPC, V1, V2, Name);\
182 #include "llvm/Instruction.def"
183 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
184 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
185 const std::string &Name, BasicBlock *BB) {\
186 return Create(Instruction::OPC, V1, V2, Name, BB);\
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, Instruction *I) {\
192 return Create(Instruction::OPC, V1, V2, Name, I);\
194 #include "llvm/Instruction.def"
197 /// Helper functions to construct and inspect unary operations (NEG and NOT)
198 /// via binary operators SUB and XOR:
200 /// CreateNeg, CreateNot - Create the NEG and NOT
201 /// instructions out of SUB and XOR instructions.
203 static BinaryOperator *CreateNeg(Value *Op, const std::string &Name = "",
204 Instruction *InsertBefore = 0);
205 static BinaryOperator *CreateNeg(Value *Op, const std::string &Name,
206 BasicBlock *InsertAtEnd);
207 static BinaryOperator *CreateFNeg(Value *Op, const std::string &Name = "",
208 Instruction *InsertBefore = 0);
209 static BinaryOperator *CreateFNeg(Value *Op, const std::string &Name,
210 BasicBlock *InsertAtEnd);
211 static BinaryOperator *CreateNot(Value *Op, const std::string &Name = "",
212 Instruction *InsertBefore = 0);
213 static BinaryOperator *CreateNot(Value *Op, const std::string &Name,
214 BasicBlock *InsertAtEnd);
216 /// isNeg, isFNeg, isNot - Check if the given Value is a
217 /// NEG, FNeg, or NOT instruction.
219 static bool isNeg(const Value *V);
220 static bool isFNeg(const Value *V);
221 static bool isNot(const Value *V);
223 /// getNegArgument, getNotArgument - Helper functions to extract the
224 /// unary argument of a NEG, FNEG or NOT operation implemented via
225 /// Sub, FSub, or Xor.
227 static const Value *getNegArgument(const Value *BinOp);
228 static Value *getNegArgument( Value *BinOp);
229 static const Value *getFNegArgument(const Value *BinOp);
230 static Value *getFNegArgument( Value *BinOp);
231 static const Value *getNotArgument(const Value *BinOp);
232 static Value *getNotArgument( Value *BinOp);
234 BinaryOps getOpcode() const {
235 return static_cast<BinaryOps>(Instruction::getOpcode());
238 virtual BinaryOperator *clone() const;
240 /// swapOperands - Exchange the two operands to this instruction.
241 /// This instruction is safe to use on any binary instruction and
242 /// does not modify the semantics of the instruction. If the instruction
243 /// cannot be reversed (ie, it's a Div), then return true.
247 // Methods for support type inquiry through isa, cast, and dyn_cast:
248 static inline bool classof(const BinaryOperator *) { return true; }
249 static inline bool classof(const Instruction *I) {
250 return I->isBinaryOp();
252 static inline bool classof(const Value *V) {
253 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 struct OperandTraits<BinaryOperator> : FixedNumOperandTraits<2> {
261 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
263 //===----------------------------------------------------------------------===//
265 //===----------------------------------------------------------------------===//
267 /// CastInst - This is the base class for all instructions that perform data
268 /// casts. It is simply provided so that instruction category testing
269 /// can be performed with code like:
271 /// if (isa<CastInst>(Instr)) { ... }
272 /// @brief Base class of casting instructions.
273 class CastInst : public UnaryInstruction {
274 /// @brief Copy constructor
275 CastInst(const CastInst &CI)
276 : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) {
278 /// @brief Do not allow default construction
281 /// @brief Constructor with insert-before-instruction semantics for subclasses
282 CastInst(const Type *Ty, unsigned iType, Value *S,
283 const std::string &NameStr = "", Instruction *InsertBefore = 0)
284 : UnaryInstruction(Ty, iType, S, InsertBefore) {
287 /// @brief Constructor with insert-at-end-of-block semantics for subclasses
288 CastInst(const Type *Ty, unsigned iType, Value *S,
289 const std::string &NameStr, BasicBlock *InsertAtEnd)
290 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
294 /// Provides a way to construct any of the CastInst subclasses using an
295 /// opcode instead of the subclass's constructor. The opcode must be in the
296 /// CastOps category (Instruction::isCast(opcode) returns true). This
297 /// constructor has insert-before-instruction semantics to automatically
298 /// insert the new CastInst before InsertBefore (if it is non-null).
299 /// @brief Construct any of the CastInst subclasses
300 static CastInst *Create(
301 Instruction::CastOps, ///< The opcode of the cast instruction
302 Value *S, ///< The value to be casted (operand 0)
303 const Type *Ty, ///< The type to which cast should be made
304 const std::string &Name = "", ///< Name for the instruction
305 Instruction *InsertBefore = 0 ///< Place to insert the instruction
307 /// Provides a way to construct any of the CastInst subclasses using an
308 /// opcode instead of the subclass's constructor. The opcode must be in the
309 /// CastOps category. This constructor has insert-at-end-of-block semantics
310 /// to automatically insert the new CastInst at the end of InsertAtEnd (if
312 /// @brief Construct any of the CastInst subclasses
313 static CastInst *Create(
314 Instruction::CastOps, ///< The opcode for the cast instruction
315 Value *S, ///< The value to be casted (operand 0)
316 const Type *Ty, ///< The type to which operand is casted
317 const std::string &Name, ///< The name for the instruction
318 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
321 /// @brief Create a ZExt or BitCast cast instruction
322 static CastInst *CreateZExtOrBitCast(
323 Value *S, ///< The value to be casted (operand 0)
324 const Type *Ty, ///< The type to which cast should be made
325 const std::string &Name = "", ///< Name for the instruction
326 Instruction *InsertBefore = 0 ///< Place to insert the instruction
329 /// @brief Create a ZExt or BitCast cast instruction
330 static CastInst *CreateZExtOrBitCast(
331 Value *S, ///< The value to be casted (operand 0)
332 const Type *Ty, ///< The type to which operand is casted
333 const std::string &Name, ///< The name for the instruction
334 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
337 /// @brief Create a SExt or BitCast cast instruction
338 static CastInst *CreateSExtOrBitCast(
339 Value *S, ///< The value to be casted (operand 0)
340 const Type *Ty, ///< The type to which cast should be made
341 const std::string &Name = "", ///< Name for the instruction
342 Instruction *InsertBefore = 0 ///< Place to insert the instruction
345 /// @brief Create a SExt or BitCast cast instruction
346 static CastInst *CreateSExtOrBitCast(
347 Value *S, ///< The value to be casted (operand 0)
348 const Type *Ty, ///< The type to which operand is casted
349 const std::string &Name, ///< The name for the instruction
350 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
353 /// @brief Create a BitCast or a PtrToInt cast instruction
354 static CastInst *CreatePointerCast(
355 Value *S, ///< The pointer value to be casted (operand 0)
356 const Type *Ty, ///< The type to which operand is casted
357 const std::string &Name, ///< The name for the instruction
358 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
361 /// @brief Create a BitCast or a PtrToInt cast instruction
362 static CastInst *CreatePointerCast(
363 Value *S, ///< The pointer value to be casted (operand 0)
364 const Type *Ty, ///< The type to which cast should be made
365 const std::string &Name = "", ///< Name for the instruction
366 Instruction *InsertBefore = 0 ///< Place to insert the instruction
369 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
370 static CastInst *CreateIntegerCast(
371 Value *S, ///< The pointer value to be casted (operand 0)
372 const Type *Ty, ///< The type to which cast should be made
373 bool isSigned, ///< Whether to regard S as signed or not
374 const std::string &Name = "", ///< Name for the instruction
375 Instruction *InsertBefore = 0 ///< Place to insert the instruction
378 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
379 static CastInst *CreateIntegerCast(
380 Value *S, ///< The integer value to be casted (operand 0)
381 const Type *Ty, ///< The integer type to which operand is casted
382 bool isSigned, ///< Whether to regard S as signed or not
383 const std::string &Name, ///< The name for the instruction
384 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
387 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
388 static CastInst *CreateFPCast(
389 Value *S, ///< The floating point value to be casted
390 const Type *Ty, ///< The floating point type to cast to
391 const std::string &Name = "", ///< Name for the instruction
392 Instruction *InsertBefore = 0 ///< Place to insert the instruction
395 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
396 static CastInst *CreateFPCast(
397 Value *S, ///< The floating point value to be casted
398 const Type *Ty, ///< The floating point type to cast to
399 const std::string &Name, ///< The name for the instruction
400 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
403 /// @brief Create a Trunc or BitCast cast instruction
404 static CastInst *CreateTruncOrBitCast(
405 Value *S, ///< The value to be casted (operand 0)
406 const Type *Ty, ///< The type to which cast should be made
407 const std::string &Name = "", ///< Name for the instruction
408 Instruction *InsertBefore = 0 ///< Place to insert the instruction
411 /// @brief Create a Trunc or BitCast cast instruction
412 static CastInst *CreateTruncOrBitCast(
413 Value *S, ///< The value to be casted (operand 0)
414 const Type *Ty, ///< The type to which operand is casted
415 const std::string &Name, ///< The name for the instruction
416 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
419 /// @brief Check whether it is valid to call getCastOpcode for these types.
420 static bool isCastable(
421 const Type *SrcTy, ///< The Type from which the value should be cast.
422 const Type *DestTy ///< The Type to which the value should be cast.
425 /// Returns the opcode necessary to cast Val into Ty using usual casting
427 /// @brief Infer the opcode for cast operand and type
428 static Instruction::CastOps getCastOpcode(
429 const Value *Val, ///< The value to cast
430 bool SrcIsSigned, ///< Whether to treat the source as signed
431 const Type *Ty, ///< The Type to which the value should be casted
432 bool DstIsSigned ///< Whether to treate the dest. as signed
435 /// There are several places where we need to know if a cast instruction
436 /// only deals with integer source and destination types. To simplify that
437 /// logic, this method is provided.
438 /// @returns true iff the cast has only integral typed operand and dest type.
439 /// @brief Determine if this is an integer-only cast.
440 bool isIntegerCast() const;
442 /// A lossless cast is one that does not alter the basic value. It implies
443 /// a no-op cast but is more stringent, preventing things like int->float,
444 /// long->double, int->ptr, or vector->anything.
445 /// @returns true iff the cast is lossless.
446 /// @brief Determine if this is a lossless cast.
447 bool isLosslessCast() const;
449 /// A no-op cast is one that can be effected without changing any bits.
450 /// It implies that the source and destination types are the same size. The
451 /// IntPtrTy argument is used to make accurate determinations for casts
452 /// involving Integer and Pointer types. They are no-op casts if the integer
453 /// is the same size as the pointer. However, pointer size varies with
454 /// platform. Generally, the result of TargetData::getIntPtrType() should be
455 /// passed in. If that's not available, use Type::Int64Ty, which will make
456 /// the isNoopCast call conservative.
457 /// @brief Determine if this cast is a no-op cast.
459 const Type *IntPtrTy ///< Integer type corresponding to pointer
462 /// Determine how a pair of casts can be eliminated, if they can be at all.
463 /// This is a helper function for both CastInst and ConstantExpr.
464 /// @returns 0 if the CastInst pair can't be eliminated
465 /// @returns Instruction::CastOps value for a cast that can replace
466 /// the pair, casting SrcTy to DstTy.
467 /// @brief Determine if a cast pair is eliminable
468 static unsigned isEliminableCastPair(
469 Instruction::CastOps firstOpcode, ///< Opcode of first cast
470 Instruction::CastOps secondOpcode, ///< Opcode of second cast
471 const Type *SrcTy, ///< SrcTy of 1st cast
472 const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
473 const Type *DstTy, ///< DstTy of 2nd cast
474 const Type *IntPtrTy ///< Integer type corresponding to Ptr types
477 /// @brief Return the opcode of this CastInst
478 Instruction::CastOps getOpcode() const {
479 return Instruction::CastOps(Instruction::getOpcode());
482 /// @brief Return the source type, as a convenience
483 const Type* getSrcTy() const { return getOperand(0)->getType(); }
484 /// @brief Return the destination type, as a convenience
485 const Type* getDestTy() const { return getType(); }
487 /// This method can be used to determine if a cast from S to DstTy using
488 /// Opcode op is valid or not.
489 /// @returns true iff the proposed cast is valid.
490 /// @brief Determine if a cast is valid without creating one.
491 static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
493 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
494 static inline bool classof(const CastInst *) { return true; }
495 static inline bool classof(const Instruction *I) {
498 static inline bool classof(const Value *V) {
499 return isa<Instruction>(V) && classof(cast<Instruction>(V));
503 //===----------------------------------------------------------------------===//
505 //===----------------------------------------------------------------------===//
507 /// This class is the base class for the comparison instructions.
508 /// @brief Abstract base class of comparison instructions.
509 // FIXME: why not derive from BinaryOperator?
510 class CmpInst: public Instruction {
511 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
512 CmpInst(); // do not implement
514 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
515 Value *LHS, Value *RHS, const std::string &Name = "",
516 Instruction *InsertBefore = 0);
518 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
519 Value *LHS, Value *RHS, const std::string &Name,
520 BasicBlock *InsertAtEnd);
523 /// This enumeration lists the possible predicates for CmpInst subclasses.
524 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
525 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
526 /// predicate values are not overlapping between the classes.
528 // Opcode U L G E Intuitive operation
529 FCMP_FALSE = 0, /// 0 0 0 0 Always false (always folded)
530 FCMP_OEQ = 1, /// 0 0 0 1 True if ordered and equal
531 FCMP_OGT = 2, /// 0 0 1 0 True if ordered and greater than
532 FCMP_OGE = 3, /// 0 0 1 1 True if ordered and greater than or equal
533 FCMP_OLT = 4, /// 0 1 0 0 True if ordered and less than
534 FCMP_OLE = 5, /// 0 1 0 1 True if ordered and less than or equal
535 FCMP_ONE = 6, /// 0 1 1 0 True if ordered and operands are unequal
536 FCMP_ORD = 7, /// 0 1 1 1 True if ordered (no nans)
537 FCMP_UNO = 8, /// 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
538 FCMP_UEQ = 9, /// 1 0 0 1 True if unordered or equal
539 FCMP_UGT = 10, /// 1 0 1 0 True if unordered or greater than
540 FCMP_UGE = 11, /// 1 0 1 1 True if unordered, greater than, or equal
541 FCMP_ULT = 12, /// 1 1 0 0 True if unordered or less than
542 FCMP_ULE = 13, /// 1 1 0 1 True if unordered, less than, or equal
543 FCMP_UNE = 14, /// 1 1 1 0 True if unordered or not equal
544 FCMP_TRUE = 15, /// 1 1 1 1 Always true (always folded)
545 FIRST_FCMP_PREDICATE = FCMP_FALSE,
546 LAST_FCMP_PREDICATE = FCMP_TRUE,
547 BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
548 ICMP_EQ = 32, /// equal
549 ICMP_NE = 33, /// not equal
550 ICMP_UGT = 34, /// unsigned greater than
551 ICMP_UGE = 35, /// unsigned greater or equal
552 ICMP_ULT = 36, /// unsigned less than
553 ICMP_ULE = 37, /// unsigned less or equal
554 ICMP_SGT = 38, /// signed greater than
555 ICMP_SGE = 39, /// signed greater or equal
556 ICMP_SLT = 40, /// signed less than
557 ICMP_SLE = 41, /// signed less or equal
558 FIRST_ICMP_PREDICATE = ICMP_EQ,
559 LAST_ICMP_PREDICATE = ICMP_SLE,
560 BAD_ICMP_PREDICATE = ICMP_SLE + 1
563 // allocate space for exactly two operands
564 void *operator new(size_t s) {
565 return User::operator new(s, 2);
567 /// Construct a compare instruction, given the opcode, the predicate and
568 /// the two operands. Optionally (if InstBefore is specified) insert the
569 /// instruction into a BasicBlock right before the specified instruction.
570 /// The specified Instruction is allowed to be a dereferenced end iterator.
571 /// @brief Create a CmpInst
572 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
573 Value *S2, const std::string &Name = "",
574 Instruction *InsertBefore = 0);
576 /// Construct a compare instruction, given the opcode, the predicate and the
577 /// two operands. Also automatically insert this instruction to the end of
578 /// the BasicBlock specified.
579 /// @brief Create a CmpInst
580 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
581 Value *S2, const std::string &Name,
582 BasicBlock *InsertAtEnd);
584 /// @brief Get the opcode casted to the right type
585 OtherOps getOpcode() const {
586 return static_cast<OtherOps>(Instruction::getOpcode());
589 /// @brief Return the predicate for this instruction.
590 Predicate getPredicate() const { return Predicate(SubclassData); }
592 /// @brief Set the predicate for this instruction to the specified value.
593 void setPredicate(Predicate P) { SubclassData = P; }
595 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
596 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
597 /// @returns the inverse predicate for the instruction's current predicate.
598 /// @brief Return the inverse of the instruction's predicate.
599 Predicate getInversePredicate() const {
600 return getInversePredicate(getPredicate());
603 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
604 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
605 /// @returns the inverse predicate for predicate provided in \p pred.
606 /// @brief Return the inverse of a given predicate
607 static Predicate getInversePredicate(Predicate pred);
609 /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
610 /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
611 /// @returns the predicate that would be the result of exchanging the two
612 /// operands of the CmpInst instruction without changing the result
614 /// @brief Return the predicate as if the operands were swapped
615 Predicate getSwappedPredicate() const {
616 return getSwappedPredicate(getPredicate());
619 /// This is a static version that you can use without an instruction
621 /// @brief Return the predicate as if the operands were swapped.
622 static Predicate getSwappedPredicate(Predicate pred);
624 /// @brief Provide more efficient getOperand methods.
625 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
627 /// This is just a convenience that dispatches to the subclasses.
628 /// @brief Swap the operands and adjust predicate accordingly to retain
629 /// the same comparison.
632 /// This is just a convenience that dispatches to the subclasses.
633 /// @brief Determine if this CmpInst is commutative.
634 bool isCommutative();
636 /// This is just a convenience that dispatches to the subclasses.
637 /// @brief Determine if this is an equals/not equals predicate.
640 /// @returns true if the predicate is unsigned, false otherwise.
641 /// @brief Determine if the predicate is an unsigned operation.
642 static bool isUnsigned(unsigned short predicate);
644 /// @returns true if the predicate is signed, false otherwise.
645 /// @brief Determine if the predicate is an signed operation.
646 static bool isSigned(unsigned short predicate);
648 /// @brief Determine if the predicate is an ordered operation.
649 static bool isOrdered(unsigned short predicate);
651 /// @brief Determine if the predicate is an unordered operation.
652 static bool isUnordered(unsigned short predicate);
654 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
655 static inline bool classof(const CmpInst *) { return true; }
656 static inline bool classof(const Instruction *I) {
657 return I->getOpcode() == Instruction::ICmp ||
658 I->getOpcode() == Instruction::FCmp;
660 static inline bool classof(const Value *V) {
661 return isa<Instruction>(V) && classof(cast<Instruction>(V));
663 /// @brief Create a result type for fcmp/icmp
664 static const Type* makeCmpResultType(const Type* opnd_type) {
665 if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
666 return VectorType::get(Type::Int1Ty, vt->getNumElements());
673 // FIXME: these are redundant if CmpInst < BinaryOperator
675 struct OperandTraits<CmpInst> : FixedNumOperandTraits<2> {
678 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
680 } // End llvm namespace