2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/InstrTypes.h - Important Instruction subclasses ----*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This file defines various meta classes of instructions that exist in the VM
|
2005-04-21 20:19:05 +00:00
|
|
|
// representation. Specific concrete subclasses of these may be found in the
|
2001-06-06 20:29:01 +00:00
|
|
|
// i*.h files...
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_INSTRUCTION_TYPES_H
|
|
|
|
#define LLVM_INSTRUCTION_TYPES_H
|
|
|
|
|
|
|
|
#include "llvm/Instruction.h"
|
2008-05-10 08:32:32 +00:00
|
|
|
#include "llvm/OperandTraits.h"
|
2008-09-09 01:02:47 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2009-07-09 23:48:35 +00:00
|
|
|
class LLVMContext;
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TerminatorInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// TerminatorInst - Subclasses of this class are all able to terminate a basic
|
2002-08-25 22:54:55 +00:00
|
|
|
/// block. Thus, these are all the flow control type of operations.
|
|
|
|
///
|
2001-06-06 20:29:01 +00:00
|
|
|
class TerminatorInst : public Instruction {
|
2002-02-19 19:22:45 +00:00
|
|
|
protected:
|
2001-10-13 06:24:10 +00:00
|
|
|
TerminatorInst(const Type *Ty, Instruction::TermOps iType,
|
2007-02-24 00:55:48 +00:00
|
|
|
Use *Ops, unsigned NumOps,
|
|
|
|
Instruction *InsertBefore = 0)
|
|
|
|
: Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
|
2004-05-26 21:41:09 +00:00
|
|
|
|
|
|
|
TerminatorInst(const Type *Ty, Instruction::TermOps iType,
|
2007-02-24 00:55:48 +00:00
|
|
|
Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
|
|
|
|
: Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
|
2004-05-26 21:41:09 +00:00
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
// Out of line virtual method, so the vtable, etc has a home.
|
|
|
|
~TerminatorInst();
|
|
|
|
|
2005-01-29 00:32:51 +00:00
|
|
|
/// Virtual methods - Terminators should overload these and provide inline
|
|
|
|
/// overrides of non-V methods.
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
|
|
|
|
virtual unsigned getNumSuccessorsV() const = 0;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
|
2002-02-19 19:22:45 +00:00
|
|
|
public:
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2009-07-09 23:48:35 +00:00
|
|
|
virtual Instruction *clone(LLVMContext &Context) const = 0;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2005-01-29 00:32:51 +00:00
|
|
|
/// getNumSuccessors - Return the number of successors that this terminator
|
|
|
|
/// has.
|
|
|
|
unsigned getNumSuccessors() const {
|
|
|
|
return getNumSuccessorsV();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSuccessor - Return the specified successor.
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2005-01-29 00:32:51 +00:00
|
|
|
BasicBlock *getSuccessor(unsigned idx) const {
|
|
|
|
return getSuccessorV(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setSuccessor - Update the specified successor to point at the provided
|
|
|
|
/// block.
|
|
|
|
void setSuccessor(unsigned idx, BasicBlock *B) {
|
|
|
|
setSuccessorV(idx, B);
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const TerminatorInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2008-10-17 21:42:45 +00:00
|
|
|
return I->isTerminator();
|
2001-10-02 03:41:24 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2005-01-29 00:32:51 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UnaryInstruction Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class UnaryInstruction : public Instruction {
|
2008-05-13 07:09:08 +00:00
|
|
|
void *operator new(size_t, unsigned); // Do not implement
|
|
|
|
UnaryInstruction(const UnaryInstruction&); // Do not implement
|
|
|
|
|
2005-01-29 00:32:51 +00:00
|
|
|
protected:
|
2009-02-09 17:11:05 +00:00
|
|
|
UnaryInstruction(const Type *Ty, unsigned iType, Value *V,
|
|
|
|
Instruction *IB = 0)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(Ty, iType, &Op<0>(), 1, IB) {
|
|
|
|
Op<0>() = V;
|
2005-01-29 00:32:51 +00:00
|
|
|
}
|
2007-02-24 00:55:48 +00:00
|
|
|
UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(Ty, iType, &Op<0>(), 1, IAE) {
|
|
|
|
Op<0>() = V;
|
2005-01-29 00:32:51 +00:00
|
|
|
}
|
2007-12-09 22:46:10 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly one operand
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 1);
|
|
|
|
}
|
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
// Out of line virtual method, so the vtable, etc has a home.
|
|
|
|
~UnaryInstruction();
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-12-08 04:37:52 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const UnaryInstruction *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Malloc ||
|
|
|
|
I->getOpcode() == Instruction::Alloca ||
|
|
|
|
I->getOpcode() == Instruction::Free ||
|
|
|
|
I->getOpcode() == Instruction::Load ||
|
|
|
|
I->getOpcode() == Instruction::VAArg ||
|
2008-06-06 20:28:12 +00:00
|
|
|
I->getOpcode() == Instruction::ExtractValue ||
|
2007-12-08 04:37:52 +00:00
|
|
|
(I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:32:51 +00:00
|
|
|
};
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
|
|
|
struct OperandTraits<UnaryInstruction> : FixedNumOperandTraits<1> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BinaryOperator Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class BinaryOperator : public Instruction {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // Do not implement
|
2002-02-19 19:22:45 +00:00
|
|
|
protected:
|
2005-01-29 00:32:51 +00:00
|
|
|
void init(BinaryOps iType);
|
2002-09-10 15:36:11 +00:00
|
|
|
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, Instruction *InsertBefore);
|
2004-05-27 00:15:23 +00:00
|
|
|
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
2002-02-19 19:22:45 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
2002-02-19 19:22:45 +00:00
|
|
|
|
2005-01-29 00:32:51 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2005-01-29 00:32:51 +00:00
|
|
|
|
2008-05-16 19:29:10 +00:00
|
|
|
/// Create() - Construct a binary instruction, given the opcode and the two
|
2002-09-10 15:36:11 +00:00
|
|
|
/// operands. Optionally (if InstBefore is specified) insert the instruction
|
|
|
|
/// into a BasicBlock right before the specified instruction. The specified
|
|
|
|
/// Instruction is allowed to be a dereferenced end iterator.
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2008-05-16 19:29:10 +00:00
|
|
|
static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "",
|
2002-09-10 15:36:11 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2008-05-16 19:29:10 +00:00
|
|
|
/// Create() - Construct a binary instruction, given the opcode and the two
|
2004-05-27 00:15:23 +00:00
|
|
|
/// operands. Also automatically insert this instruction to the end of the
|
|
|
|
/// BasicBlock specified.
|
|
|
|
///
|
2008-05-16 19:29:10 +00:00
|
|
|
static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
2004-06-10 01:43:29 +00:00
|
|
|
|
2008-05-21 18:57:33 +00:00
|
|
|
/// Create* - These methods just forward to Create, and are useful when you
|
2004-06-10 01:43:29 +00:00
|
|
|
/// statically know what type of instruction you're going to create. These
|
|
|
|
/// helpers just save some typing.
|
|
|
|
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
|
2008-05-16 19:29:10 +00:00
|
|
|
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "") {\
|
2008-05-16 19:29:10 +00:00
|
|
|
return Create(Instruction::OPC, V1, V2, Name);\
|
2004-06-10 01:43:29 +00:00
|
|
|
}
|
|
|
|
#include "llvm/Instruction.def"
|
|
|
|
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
|
2008-05-16 19:29:10 +00:00
|
|
|
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, BasicBlock *BB) {\
|
2008-05-16 19:29:10 +00:00
|
|
|
return Create(Instruction::OPC, V1, V2, Name, BB);\
|
2004-06-10 01:43:29 +00:00
|
|
|
}
|
|
|
|
#include "llvm/Instruction.def"
|
2004-06-20 05:02:56 +00:00
|
|
|
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
|
2008-05-16 19:29:10 +00:00
|
|
|
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, Instruction *I) {\
|
2008-05-16 19:29:10 +00:00
|
|
|
return Create(Instruction::OPC, V1, V2, Name, I);\
|
2004-06-20 05:02:56 +00:00
|
|
|
}
|
|
|
|
#include "llvm/Instruction.def"
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2002-02-19 19:22:45 +00:00
|
|
|
|
2002-08-25 22:54:55 +00:00
|
|
|
/// Helper functions to construct and inspect unary operations (NEG and NOT)
|
|
|
|
/// via binary operators SUB and XOR:
|
2005-04-21 20:19:05 +00:00
|
|
|
///
|
2008-05-16 19:29:10 +00:00
|
|
|
/// CreateNeg, CreateNot - Create the NEG and NOT
|
2002-08-25 22:54:55 +00:00
|
|
|
/// instructions out of SUB and XOR instructions.
|
|
|
|
///
|
2009-07-13 04:09:18 +00:00
|
|
|
static BinaryOperator *CreateNeg(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name = "",
|
2002-09-10 15:36:11 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-07-13 04:09:18 +00:00
|
|
|
static BinaryOperator *CreateNeg(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name,
|
2004-05-27 00:15:23 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-07-13 04:09:18 +00:00
|
|
|
static BinaryOperator *CreateFNeg(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name = "",
|
2009-06-04 22:49:04 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-07-13 04:09:18 +00:00
|
|
|
static BinaryOperator *CreateFNeg(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name,
|
2009-06-04 22:49:04 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-07-13 20:58:05 +00:00
|
|
|
static BinaryOperator *CreateNot(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name = "",
|
2002-09-10 15:36:11 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-07-13 20:58:05 +00:00
|
|
|
static BinaryOperator *CreateNot(LLVMContext &Context,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *Op, const Twine &Name,
|
2004-05-27 00:15:23 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2002-08-14 17:51:29 +00:00
|
|
|
|
2009-06-04 22:49:04 +00:00
|
|
|
/// isNeg, isFNeg, isNot - Check if the given Value is a
|
|
|
|
/// NEG, FNeg, or NOT instruction.
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2009-07-13 22:18:28 +00:00
|
|
|
static bool isNeg(const Value *V);
|
|
|
|
static bool isFNeg(const Value *V);
|
2006-09-17 19:29:56 +00:00
|
|
|
static bool isNot(const Value *V);
|
2002-08-15 14:15:48 +00:00
|
|
|
|
2002-08-25 22:54:55 +00:00
|
|
|
/// getNegArgument, getNotArgument - Helper functions to extract the
|
2009-06-04 22:49:04 +00:00
|
|
|
/// unary argument of a NEG, FNEG or NOT operation implemented via
|
|
|
|
/// Sub, FSub, or Xor.
|
2005-04-21 20:19:05 +00:00
|
|
|
///
|
2006-09-17 19:29:56 +00:00
|
|
|
static const Value *getNegArgument(const Value *BinOp);
|
|
|
|
static Value *getNegArgument( Value *BinOp);
|
2009-06-04 22:49:04 +00:00
|
|
|
static const Value *getFNegArgument(const Value *BinOp);
|
|
|
|
static Value *getFNegArgument( Value *BinOp);
|
2006-09-17 19:29:56 +00:00
|
|
|
static const Value *getNotArgument(const Value *BinOp);
|
|
|
|
static Value *getNotArgument( Value *BinOp);
|
2002-08-15 14:15:48 +00:00
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
BinaryOps getOpcode() const {
|
2003-11-16 20:21:15 +00:00
|
|
|
return static_cast<BinaryOps>(Instruction::getOpcode());
|
2001-07-07 20:17:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 23:48:35 +00:00
|
|
|
virtual BinaryOperator *clone(LLVMContext &Context) const;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-08-25 22:54:55 +00:00
|
|
|
/// swapOperands - Exchange the two operands to this instruction.
|
|
|
|
/// This instruction is safe to use on any binary instruction and
|
2008-05-09 05:20:27 +00:00
|
|
|
/// does not modify the semantics of the instruction. If the instruction
|
|
|
|
/// cannot be reversed (ie, it's a Div), then return true.
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2001-12-13 00:43:03 +00:00
|
|
|
bool swapOperands();
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const BinaryOperator *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2008-10-17 21:42:45 +00:00
|
|
|
return I->isBinaryOp();
|
2001-10-02 03:41:24 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
|
|
|
struct OperandTraits<BinaryOperator> : FixedNumOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CastInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// CastInst - This is the base class for all instructions that perform data
|
|
|
|
/// casts. It is simply provided so that instruction category testing
|
|
|
|
/// can be performed with code like:
|
|
|
|
///
|
|
|
|
/// if (isa<CastInst>(Instr)) { ... }
|
|
|
|
/// @brief Base class of casting instructions.
|
|
|
|
class CastInst : public UnaryInstruction {
|
|
|
|
/// @brief Copy constructor
|
|
|
|
CastInst(const CastInst &CI)
|
|
|
|
: UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
/// @brief Do not allow default construction
|
2009-02-09 17:11:05 +00:00
|
|
|
CastInst();
|
2006-11-27 01:05:10 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics for subclasses
|
2009-02-09 17:11:05 +00:00
|
|
|
CastInst(const Type *Ty, unsigned iType, Value *S,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "", Instruction *InsertBefore = 0)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, iType, S, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics for subclasses
|
2009-02-09 17:11:05 +00:00
|
|
|
CastInst(const Type *Ty, unsigned iType, Value *S,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, iType, S, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
|
|
|
public:
|
2009-02-09 17:11:05 +00:00
|
|
|
/// Provides a way to construct any of the CastInst subclasses using an
|
2006-11-27 01:05:10 +00:00
|
|
|
/// opcode instead of the subclass's constructor. The opcode must be in the
|
|
|
|
/// CastOps category (Instruction::isCast(opcode) returns true). This
|
|
|
|
/// constructor has insert-before-instruction semantics to automatically
|
|
|
|
/// insert the new CastInst before InsertBefore (if it is non-null).
|
|
|
|
/// @brief Construct any of the CastInst subclasses
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *Create(
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction::CastOps, ///< The opcode of the cast instruction
|
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
/// Provides a way to construct any of the CastInst subclasses using an
|
|
|
|
/// opcode instead of the subclass's constructor. The opcode must be in the
|
|
|
|
/// CastOps category. This constructor has insert-at-end-of-block semantics
|
|
|
|
/// to automatically insert the new CastInst at the end of InsertAtEnd (if
|
|
|
|
/// its non-null).
|
|
|
|
/// @brief Construct any of the CastInst subclasses
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *Create(
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction::CastOps, ///< The opcode for the cast instruction
|
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which operand is casted
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2006-12-04 20:17:56 +00:00
|
|
|
/// @brief Create a ZExt or BitCast cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateZExtOrBitCast(
|
2006-12-04 20:17:56 +00:00
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-04 20:17:56 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create a ZExt or BitCast cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateZExtOrBitCast(
|
2006-12-04 20:17:56 +00:00
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which operand is casted
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-12-04 20:17:56 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create a SExt or BitCast cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateSExtOrBitCast(
|
2006-12-04 20:17:56 +00:00
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
2006-12-04 23:14:27 +00:00
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-04 23:14:27 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
2008-05-16 19:29:10 +00:00
|
|
|
/// @brief Create a SExt or BitCast cast instruction
|
|
|
|
static CastInst *CreateSExtOrBitCast(
|
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which operand is casted
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2006-12-04 23:14:27 +00:00
|
|
|
/// @brief Create a BitCast or a PtrToInt cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreatePointerCast(
|
2006-12-04 23:14:27 +00:00
|
|
|
Value *S, ///< The pointer value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which operand is casted
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-12-04 23:14:27 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create a BitCast or a PtrToInt cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreatePointerCast(
|
2006-12-04 23:14:27 +00:00
|
|
|
Value *S, ///< The pointer value to be casted (operand 0)
|
2006-12-04 20:17:56 +00:00
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-04 20:17:56 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
2006-12-12 00:49:44 +00:00
|
|
|
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateIntegerCast(
|
2006-12-12 00:49:44 +00:00
|
|
|
Value *S, ///< The pointer value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
|
|
|
bool isSigned, ///< Whether to regard S as signed or not
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-12 00:49:44 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateIntegerCast(
|
2006-12-12 00:49:44 +00:00
|
|
|
Value *S, ///< The integer value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The integer type to which operand is casted
|
|
|
|
bool isSigned, ///< Whether to regard S as signed or not
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-12-12 00:49:44 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateFPCast(
|
2009-02-09 17:11:05 +00:00
|
|
|
Value *S, ///< The floating point value to be casted
|
2006-12-12 00:49:44 +00:00
|
|
|
const Type *Ty, ///< The floating point type to cast to
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-12 00:49:44 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateFPCast(
|
2009-02-09 17:11:05 +00:00
|
|
|
Value *S, ///< The floating point value to be casted
|
2006-12-12 00:49:44 +00:00
|
|
|
const Type *Ty, ///< The floating point type to cast to
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-12-12 00:49:44 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2006-12-04 20:17:56 +00:00
|
|
|
/// @brief Create a Trunc or BitCast cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateTruncOrBitCast(
|
2006-12-04 20:17:56 +00:00
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which cast should be made
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name = "", ///< Name for the instruction
|
2006-12-04 20:17:56 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Create a Trunc or BitCast cast instruction
|
2008-05-16 19:29:10 +00:00
|
|
|
static CastInst *CreateTruncOrBitCast(
|
2006-12-04 20:17:56 +00:00
|
|
|
Value *S, ///< The value to be casted (operand 0)
|
|
|
|
const Type *Ty, ///< The type to which operand is casted
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &Name, ///< The name for the instruction
|
2006-12-04 20:17:56 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2008-01-06 10:12:28 +00:00
|
|
|
/// @brief Check whether it is valid to call getCastOpcode for these types.
|
|
|
|
static bool isCastable(
|
|
|
|
const Type *SrcTy, ///< The Type from which the value should be cast.
|
|
|
|
const Type *DestTy ///< The Type to which the value should be cast.
|
|
|
|
);
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
/// Returns the opcode necessary to cast Val into Ty using usual casting
|
2008-01-06 10:12:28 +00:00
|
|
|
/// rules.
|
2006-12-18 08:52:59 +00:00
|
|
|
/// @brief Infer the opcode for cast operand and type
|
2006-11-27 01:05:10 +00:00
|
|
|
static Instruction::CastOps getCastOpcode(
|
|
|
|
const Value *Val, ///< The value to cast
|
2006-12-04 02:43:42 +00:00
|
|
|
bool SrcIsSigned, ///< Whether to treat the source as signed
|
|
|
|
const Type *Ty, ///< The Type to which the value should be casted
|
|
|
|
bool DstIsSigned ///< Whether to treate the dest. as signed
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// There are several places where we need to know if a cast instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
/// only deals with integer source and destination types. To simplify that
|
|
|
|
/// logic, this method is provided.
|
|
|
|
/// @returns true iff the cast has only integral typed operand and dest type.
|
|
|
|
/// @brief Determine if this is an integer-only cast.
|
|
|
|
bool isIntegerCast() const;
|
|
|
|
|
|
|
|
/// A lossless cast is one that does not alter the basic value. It implies
|
|
|
|
/// a no-op cast but is more stringent, preventing things like int->float,
|
2009-02-09 17:11:05 +00:00
|
|
|
/// long->double, int->ptr, or vector->anything.
|
2006-11-27 01:05:10 +00:00
|
|
|
/// @returns true iff the cast is lossless.
|
|
|
|
/// @brief Determine if this is a lossless cast.
|
|
|
|
bool isLosslessCast() const;
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// A no-op cast is one that can be effected without changing any bits.
|
2006-11-27 01:05:10 +00:00
|
|
|
/// It implies that the source and destination types are the same size. The
|
2009-02-09 17:11:05 +00:00
|
|
|
/// IntPtrTy argument is used to make accurate determinations for casts
|
2006-11-27 01:05:10 +00:00
|
|
|
/// involving Integer and Pointer types. They are no-op casts if the integer
|
2009-02-09 17:11:05 +00:00
|
|
|
/// is the same size as the pointer. However, pointer size varies with
|
2006-11-27 01:05:10 +00:00
|
|
|
/// platform. Generally, the result of TargetData::getIntPtrType() should be
|
2006-12-31 05:23:18 +00:00
|
|
|
/// passed in. If that's not available, use Type::Int64Ty, which will make
|
2006-11-27 01:05:10 +00:00
|
|
|
/// the isNoopCast call conservative.
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @brief Determine if this cast is a no-op cast.
|
2006-11-27 01:05:10 +00:00
|
|
|
bool isNoopCast(
|
|
|
|
const Type *IntPtrTy ///< Integer type corresponding to pointer
|
|
|
|
) const;
|
|
|
|
|
|
|
|
/// Determine how a pair of casts can be eliminated, if they can be at all.
|
|
|
|
/// This is a helper function for both CastInst and ConstantExpr.
|
|
|
|
/// @returns 0 if the CastInst pair can't be eliminated
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns Instruction::CastOps value for a cast that can replace
|
2006-11-27 01:05:10 +00:00
|
|
|
/// the pair, casting SrcTy to DstTy.
|
|
|
|
/// @brief Determine if a cast pair is eliminable
|
|
|
|
static unsigned isEliminableCastPair(
|
|
|
|
Instruction::CastOps firstOpcode, ///< Opcode of first cast
|
|
|
|
Instruction::CastOps secondOpcode, ///< Opcode of second cast
|
|
|
|
const Type *SrcTy, ///< SrcTy of 1st cast
|
|
|
|
const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
|
|
|
|
const Type *DstTy, ///< DstTy of 2nd cast
|
2009-07-21 23:19:40 +00:00
|
|
|
const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Return the opcode of this CastInst
|
2009-02-09 17:11:05 +00:00
|
|
|
Instruction::CastOps getOpcode() const {
|
|
|
|
return Instruction::CastOps(Instruction::getOpcode());
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-02 02:08:27 +00:00
|
|
|
/// @brief Return the source type, as a convenience
|
|
|
|
const Type* getSrcTy() const { return getOperand(0)->getType(); }
|
|
|
|
/// @brief Return the destination type, as a convenience
|
|
|
|
const Type* getDestTy() const { return getType(); }
|
|
|
|
|
2007-01-17 02:46:11 +00:00
|
|
|
/// This method can be used to determine if a cast from S to DstTy using
|
2009-02-09 17:11:05 +00:00
|
|
|
/// Opcode op is valid or not.
|
2007-01-17 02:46:11 +00:00
|
|
|
/// @returns true iff the proposed cast is valid.
|
|
|
|
/// @brief Determine if a cast is valid without creating one.
|
|
|
|
static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const CastInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2008-10-17 21:42:45 +00:00
|
|
|
return I->isCast();
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// This class is the base class for the comparison instructions.
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Abstract base class of comparison instructions.
|
2008-05-10 08:32:32 +00:00
|
|
|
// FIXME: why not derive from BinaryOperator?
|
2006-11-20 01:22:35 +00:00
|
|
|
class CmpInst: public Instruction {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2006-11-20 01:22:35 +00:00
|
|
|
CmpInst(); // do not implement
|
|
|
|
protected:
|
2008-05-12 19:01:56 +00:00
|
|
|
CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *LHS, Value *RHS, const Twine &Name = "",
|
2008-05-12 19:01:56 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-12 19:01:56 +00:00
|
|
|
CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *LHS, Value *RHS, const Twine &Name,
|
2008-05-12 19:01:56 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
|
|
|
public:
|
2008-05-12 19:01:56 +00:00
|
|
|
/// This enumeration lists the possible predicates for CmpInst subclasses.
|
|
|
|
/// Values in the range 0-31 are reserved for FCmpInst, while values in the
|
|
|
|
/// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
|
|
|
|
/// predicate values are not overlapping between the classes.
|
|
|
|
enum Predicate {
|
|
|
|
// Opcode U L G E Intuitive operation
|
|
|
|
FCMP_FALSE = 0, /// 0 0 0 0 Always false (always folded)
|
|
|
|
FCMP_OEQ = 1, /// 0 0 0 1 True if ordered and equal
|
|
|
|
FCMP_OGT = 2, /// 0 0 1 0 True if ordered and greater than
|
|
|
|
FCMP_OGE = 3, /// 0 0 1 1 True if ordered and greater than or equal
|
|
|
|
FCMP_OLT = 4, /// 0 1 0 0 True if ordered and less than
|
|
|
|
FCMP_OLE = 5, /// 0 1 0 1 True if ordered and less than or equal
|
|
|
|
FCMP_ONE = 6, /// 0 1 1 0 True if ordered and operands are unequal
|
|
|
|
FCMP_ORD = 7, /// 0 1 1 1 True if ordered (no nans)
|
|
|
|
FCMP_UNO = 8, /// 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
|
|
|
|
FCMP_UEQ = 9, /// 1 0 0 1 True if unordered or equal
|
|
|
|
FCMP_UGT = 10, /// 1 0 1 0 True if unordered or greater than
|
|
|
|
FCMP_UGE = 11, /// 1 0 1 1 True if unordered, greater than, or equal
|
|
|
|
FCMP_ULT = 12, /// 1 1 0 0 True if unordered or less than
|
|
|
|
FCMP_ULE = 13, /// 1 1 0 1 True if unordered, less than, or equal
|
|
|
|
FCMP_UNE = 14, /// 1 1 1 0 True if unordered or not equal
|
|
|
|
FCMP_TRUE = 15, /// 1 1 1 1 Always true (always folded)
|
|
|
|
FIRST_FCMP_PREDICATE = FCMP_FALSE,
|
|
|
|
LAST_FCMP_PREDICATE = FCMP_TRUE,
|
|
|
|
BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
|
|
|
|
ICMP_EQ = 32, /// equal
|
|
|
|
ICMP_NE = 33, /// not equal
|
|
|
|
ICMP_UGT = 34, /// unsigned greater than
|
|
|
|
ICMP_UGE = 35, /// unsigned greater or equal
|
|
|
|
ICMP_ULT = 36, /// unsigned less than
|
|
|
|
ICMP_ULE = 37, /// unsigned less or equal
|
|
|
|
ICMP_SGT = 38, /// signed greater than
|
|
|
|
ICMP_SGE = 39, /// signed greater or equal
|
|
|
|
ICMP_SLT = 40, /// signed less than
|
|
|
|
ICMP_SLE = 41, /// signed less or equal
|
|
|
|
FIRST_ICMP_PREDICATE = ICMP_EQ,
|
|
|
|
LAST_ICMP_PREDICATE = ICMP_SLE,
|
|
|
|
BAD_ICMP_PREDICATE = ICMP_SLE + 1
|
|
|
|
};
|
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
/// Construct a compare instruction, given the opcode, the predicate and
|
|
|
|
/// the two operands. Optionally (if InstBefore is specified) insert the
|
|
|
|
/// instruction into a BasicBlock right before the specified instruction.
|
2006-11-20 01:22:35 +00:00
|
|
|
/// The specified Instruction is allowed to be a dereferenced end iterator.
|
|
|
|
/// @brief Create a CmpInst
|
2009-07-09 23:48:35 +00:00
|
|
|
static CmpInst *Create(LLVMContext &Context, OtherOps Op,
|
|
|
|
unsigned short predicate, Value *S1,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *S2, const Twine &Name = "",
|
2006-11-20 01:22:35 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// Construct a compare instruction, given the opcode, the predicate and the
|
|
|
|
/// two operands. Also automatically insert this instruction to the end of
|
2006-11-20 01:22:35 +00:00
|
|
|
/// the BasicBlock specified.
|
|
|
|
/// @brief Create a CmpInst
|
2009-02-09 17:11:05 +00:00
|
|
|
static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
|
2009-07-25 04:41:11 +00:00
|
|
|
Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2006-12-07 04:18:31 +00:00
|
|
|
/// @brief Get the opcode casted to the right type
|
|
|
|
OtherOps getOpcode() const {
|
|
|
|
return static_cast<OtherOps>(Instruction::getOpcode());
|
|
|
|
}
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Return the predicate for this instruction.
|
2008-05-31 02:47:54 +00:00
|
|
|
Predicate getPredicate() const { return Predicate(SubclassData); }
|
|
|
|
|
|
|
|
/// @brief Set the predicate for this instruction to the specified value.
|
|
|
|
void setPredicate(Predicate P) { SubclassData = P; }
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-31 02:47:54 +00:00
|
|
|
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
|
|
|
|
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns the inverse predicate for the instruction's current predicate.
|
2008-05-31 02:47:54 +00:00
|
|
|
/// @brief Return the inverse of the instruction's predicate.
|
|
|
|
Predicate getInversePredicate() const {
|
|
|
|
return getInversePredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
|
|
|
|
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns the inverse predicate for predicate provided in \p pred.
|
2008-05-31 02:47:54 +00:00
|
|
|
/// @brief Return the inverse of a given predicate
|
|
|
|
static Predicate getInversePredicate(Predicate pred);
|
|
|
|
|
|
|
|
/// For example, EQ->EQ, SLE->SGE, ULT->UGT,
|
|
|
|
/// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns the predicate that would be the result of exchanging the two
|
|
|
|
/// operands of the CmpInst instruction without changing the result
|
|
|
|
/// produced.
|
2008-05-31 02:47:54 +00:00
|
|
|
/// @brief Return the predicate as if the operands were swapped
|
|
|
|
Predicate getSwappedPredicate() const {
|
|
|
|
return getSwappedPredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// This is a static version that you can use without an instruction
|
2008-05-31 02:47:54 +00:00
|
|
|
/// available.
|
|
|
|
/// @brief Return the predicate as if the operands were swapped.
|
|
|
|
static Predicate getSwappedPredicate(Predicate pred);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
|
|
|
/// @brief Provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
|
|
|
/// This is just a convenience that dispatches to the subclasses.
|
2006-12-23 19:06:54 +00:00
|
|
|
/// @brief Swap the operands and adjust predicate accordingly to retain
|
|
|
|
/// the same comparison.
|
2006-11-20 01:22:35 +00:00
|
|
|
void swapOperands();
|
|
|
|
|
|
|
|
/// This is just a convenience that dispatches to the subclasses.
|
|
|
|
/// @brief Determine if this CmpInst is commutative.
|
|
|
|
bool isCommutative();
|
|
|
|
|
|
|
|
/// This is just a convenience that dispatches to the subclasses.
|
|
|
|
/// @brief Determine if this is an equals/not equals predicate.
|
|
|
|
bool isEquality();
|
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
/// @returns true if the predicate is unsigned, false otherwise.
|
|
|
|
/// @brief Determine if the predicate is an unsigned operation.
|
|
|
|
static bool isUnsigned(unsigned short predicate);
|
|
|
|
|
|
|
|
/// @returns true if the predicate is signed, false otherwise.
|
|
|
|
/// @brief Determine if the predicate is an signed operation.
|
|
|
|
static bool isSigned(unsigned short predicate);
|
|
|
|
|
|
|
|
/// @brief Determine if the predicate is an ordered operation.
|
|
|
|
static bool isOrdered(unsigned short predicate);
|
|
|
|
|
|
|
|
/// @brief Determine if the predicate is an unordered operation.
|
|
|
|
static bool isUnordered(unsigned short predicate);
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const CmpInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2009-02-09 17:11:05 +00:00
|
|
|
return I->getOpcode() == Instruction::ICmp ||
|
2009-07-08 03:04:38 +00:00
|
|
|
I->getOpcode() == Instruction::FCmp;
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
// FIXME: these are redundant if CmpInst < BinaryOperator
|
|
|
|
template <>
|
|
|
|
struct OperandTraits<CmpInst> : FixedNumOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|