LLVM API Documentation
#include <InstrTypes.h>
Public Member Functions | |
| bool | isIntegerCast () const |
| Determine if this is an integer-only cast. | |
| bool | isLosslessCast () const |
| Determine if this is a lossless cast. | |
| bool | isNoopCast (const Type *IntPtrTy) const |
| Determine if this cast is a no-op cast. | |
| Instruction::CastOps | getOpcode () const |
| Return the opcode of this CastInst. | |
| const Type * | getSrcTy () const |
| Return the source type, as a convenience. | |
| const Type * | getDestTy () const |
| Return the destination type, as a convenience. | |
Static Public Member Functions | |
| static CastInst * | Create (Instruction::CastOps, Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Construct any of the CastInst subclasses. | |
| static CastInst * | Create (Instruction::CastOps, Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Construct any of the CastInst subclasses. | |
| static CastInst * | CreateZExtOrBitCast (Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Create a ZExt or BitCast cast instruction. | |
| static CastInst * | CreateZExtOrBitCast (Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create a ZExt or BitCast cast instruction. | |
| static CastInst * | CreateSExtOrBitCast (Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Create a SExt or BitCast cast instruction. | |
| static CastInst * | CreateSExtOrBitCast (Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create a SExt or BitCast cast instruction. | |
| static CastInst * | CreatePointerCast (Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create a BitCast or a PtrToInt cast instruction. | |
| static CastInst * | CreatePointerCast (Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Create a BitCast or a PtrToInt cast instruction. | |
| static CastInst * | CreateIntegerCast (Value *S, const Type *Ty, bool isSigned, const std::string &Name="", Instruction *InsertBefore=0) |
| Create a ZExt, BitCast, or Trunc for int -> int casts. | |
| static CastInst * | CreateIntegerCast (Value *S, const Type *Ty, bool isSigned, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create a ZExt, BitCast, or Trunc for int -> int casts. | |
| static CastInst * | CreateFPCast (Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Create an FPExt, BitCast, or FPTrunc for fp -> fp casts. | |
| static CastInst * | CreateFPCast (Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create an FPExt, BitCast, or FPTrunc for fp -> fp casts. | |
| static CastInst * | CreateTruncOrBitCast (Value *S, const Type *Ty, const std::string &Name="", Instruction *InsertBefore=0) |
| Create a Trunc or BitCast cast instruction. | |
| static CastInst * | CreateTruncOrBitCast (Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| Create a Trunc or BitCast cast instruction. | |
| static bool | isCastable (const Type *SrcTy, const Type *DestTy) |
| Check whether it is valid to call getCastOpcode for these types. | |
| static Instruction::CastOps | getCastOpcode (const Value *Val, bool SrcIsSigned, const Type *Ty, bool DstIsSigned) |
| Infer the opcode for cast operand and type. | |
| static unsigned | isEliminableCastPair (Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, const Type *SrcTy, const Type *MidTy, const Type *DstTy, const Type *IntPtrTy) |
| Determine if a cast pair is eliminable. | |
| static bool | castIsValid (Instruction::CastOps op, Value *S, const Type *DstTy) |
| Determine if a cast is valid without creating one. | |
| static bool | classof (const CastInst *) |
| Methods for support type inquiry through isa, cast, and dyn_cast:. | |
| static bool | classof (const Instruction *I) |
| Methods for support type inquiry through isa, cast, and dyn_cast:. | |
| static bool | classof (const Value *V) |
Protected Member Functions | |
| CastInst (const Type *Ty, unsigned iType, Value *S, const std::string &NameStr="", Instruction *InsertBefore=0) | |
| Constructor with insert-before-instruction semantics for subclasses. | |
| CastInst (const Type *Ty, unsigned iType, Value *S, const std::string &NameStr, BasicBlock *InsertAtEnd) | |
| Constructor with insert-at-end-of-block semantics for subclasses. | |
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)) { ... }
Definition at line 848 of file InstrTypes.h.
| llvm::CastInst::CastInst | ( | const Type * | Ty, | |
| unsigned | iType, | |||
| Value * | S, | |||
| const std::string & | NameStr = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [inline, protected] |
Constructor with insert-before-instruction semantics for subclasses.
Definition at line 857 of file InstrTypes.h.
| llvm::CastInst::CastInst | ( | const Type * | Ty, | |
| unsigned | iType, | |||
| Value * | S, | |||
| const std::string & | NameStr, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [inline, protected] |
Constructor with insert-at-end-of-block semantics for subclasses.
Definition at line 863 of file InstrTypes.h.
| CastInst * CastInst::Create | ( | Instruction::CastOps | op, | |
| Value * | S, | |||
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Construct any of the CastInst subclasses.
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 (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).
| op | The opcode of the cast instruction |
| S | The value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 1922 of file Instructions.cpp.
References llvm::BitCast, llvm::FPToUI, llvm::FPTrunc, llvm::PtrToInt, llvm::Attribute::SExt, llvm::UIToFP, and llvm::ZExt.
Referenced by llvm::NoFolder::CreateCast(), llvm::IRBuilder< preserveNames, T >::CreateCast(), CreateFPCast(), CreateIntegerCast(), CreatePointerCast(), CreateSExtOrBitCast(), CreateTruncOrBitCast(), CreateZExtOrBitCast(), llvm::SCEVExpander::InsertCastOfTo(), llvm::InsertProfilingInitCall(), OptimizeNoopCopyExpression(), and llvm::UpgradeIntrinsicCall().
| CastInst * CastInst::Create | ( | Instruction::CastOps | op, | |
| Value * | S, | |||
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Construct any of the CastInst subclasses.
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).
| op | The opcode for the cast instruction |
| S | The value to be casted (operand 0) |
| Ty | The type to which operand is casted |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 1944 of file Instructions.cpp.
References llvm::BitCast, llvm::FPToUI, llvm::FPTrunc, llvm::PtrToInt, llvm::Attribute::SExt, llvm::UIToFP, and llvm::ZExt.
| CastInst * CastInst::CreateZExtOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create a ZExt or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 1966 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), and ZExt.
Referenced by llvm::SCEVExpander::visitZeroExtendExpr().
| CastInst * CastInst::CreateZExtOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create a ZExt or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which operand is casted |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 1974 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), and ZExt.
| CastInst * CastInst::CreateSExtOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create a SExt or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 1982 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), and llvm::Attribute::SExt.
Referenced by llvm::SCEVExpander::visitSignExtendExpr().
| CastInst * CastInst::CreateSExtOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create a SExt or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which operand is casted |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 1990 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), and llvm::Attribute::SExt.
| CastInst * CastInst::CreatePointerCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create a BitCast or a PtrToInt cast instruction.
| S | The pointer value to be casted (operand 0) |
| Ty | The type to which operand is casted |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 2014 of file Instructions.cpp.
References BitCast, Create(), llvm::Value::getType(), llvm::Type::isInteger(), and PtrToInt.
| CastInst * CastInst::CreatePointerCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create a BitCast or a PtrToInt cast instruction.
| S | The pointer value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 2027 of file Instructions.cpp.
References BitCast, Create(), llvm::Value::getType(), llvm::Type::isInteger(), and PtrToInt.
| CastInst * CastInst::CreateIntegerCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| bool | isSigned, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create a ZExt, BitCast, or Trunc for int -> int casts.
| S | The pointer value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| isSigned | Whether to regard S as signed or not |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 2039 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isInteger(), opcode, llvm::Attribute::SExt, and ZExt.
Referenced by llvm::NoFolder::CreateIntCast(), llvm::IRBuilder< preserveNames, T >::CreateIntCast(), LowerPartSelect(), and LowerPartSet().
| CastInst * CastInst::CreateIntegerCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| bool | isSigned, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create a ZExt, BitCast, or Trunc for int -> int casts.
| S | The integer value to be casted (operand 0) |
| Ty | The integer type to which operand is casted |
| isSigned | Whether to regard S as signed or not |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 2052 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isInteger(), opcode, llvm::Attribute::SExt, and ZExt.
| CastInst * CastInst::CreateFPCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
| S | The floating point value to be casted |
| Ty | The floating point type to cast to |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 2065 of file Instructions.cpp.
References BitCast, Create(), FPTrunc, llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isFloatingPoint(), and opcode.
| CastInst * CastInst::CreateFPCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
| S | The floating point value to be casted |
| Ty | The floating point type to cast to |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 2078 of file Instructions.cpp.
References BitCast, Create(), FPTrunc, llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isFloatingPoint(), and opcode.
| CastInst * CastInst::CreateTruncOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name = "", |
|||
| Instruction * | InsertBefore = 0 | |||
| ) | [static] |
Create a Trunc or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which cast should be made |
| Name | Name for the instruction |
| InsertBefore | Place to insert the instruction |
Definition at line 1998 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), and llvm::Value::getType().
Referenced by llvm::SCEVExpander::visitTruncateExpr().
| CastInst * CastInst::CreateTruncOrBitCast | ( | Value * | S, | |
| const Type * | Ty, | |||
| const std::string & | Name, | |||
| BasicBlock * | InsertAtEnd | |||
| ) | [static] |
Create a Trunc or BitCast cast instruction.
| S | The value to be casted (operand 0) |
| Ty | The type to which operand is casted |
| Name | The name for the instruction |
| InsertAtEnd | The block to insert the instruction into |
Definition at line 2006 of file Instructions.cpp.
References BitCast, Create(), llvm::Type::getPrimitiveSizeInBits(), and llvm::Value::getType().
Check whether it is valid to call getCastOpcode for these types.
| SrcTy | The Type from which the value should be cast. |
| DestTy | The Type to which the value should be cast. |
Definition at line 2093 of file Instructions.cpp.
References llvm::Type::getPrimitiveSizeInBits(), llvm::Type::isFirstClassType(), llvm::Type::isFloatingPoint(), and llvm::Type::isInteger().
| Instruction::CastOps CastInst::getCastOpcode | ( | const Value * | Val, | |
| bool | SrcIsSigned, | |||
| const Type * | Ty, | |||
| bool | DstIsSigned | |||
| ) | [static] |
Infer the opcode for cast operand and type.
Returns the opcode necessary to cast Val into Ty using usual casting rules.
| Val | The value to cast |
| SrcIsSigned | Whether to treat the source as signed |
| Ty | The Type to which the value should be casted |
| DstIsSigned | Whether to treate the dest. as signed |
Definition at line 2156 of file Instructions.cpp.
References llvm::BitCast, llvm::FPToUI, llvm::FPTrunc, llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isFirstClassType(), llvm::Type::isFloatingPoint(), llvm::Type::isInteger(), llvm::PtrToInt, llvm::Attribute::SExt, llvm::UIToFP, and llvm::ZExt.
Referenced by llvm::InsertProfilingInitCall(), and llvm::UpgradeIntrinsicCall().
| bool CastInst::isIntegerCast | ( | ) | const |
Determine if this is an integer-only cast.
There are several places where we need to know if a cast instruction only deals with integer source and destination types. To simplify that logic, this method is provided.
Definition at line 1701 of file Instructions.cpp.
References BitCast, getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Type::isInteger(), llvm::Attribute::SExt, and ZExt.
| bool CastInst::isLosslessCast | ( | ) | const |
Determine if this is a lossless cast.
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, long->double, int->ptr, or vector->anything.
Definition at line 1713 of file Instructions.cpp.
References BitCast, getOpcode(), llvm::User::getOperand(), and llvm::Value::getType().
Referenced by isSafeToEliminateVarargsCast().
| bool CastInst::isNoopCast | ( | const Type * | IntPtrTy | ) | const |
Determine if this cast is a no-op cast.
Determine if a cast is a no-op.
A no-op cast is one that can be effected without changing any bits. It implies that the source and destination types are the same size. The IntPtrTy argument is used to make accurate determinations for casts involving Integer and Pointer types. They are no-op casts if the integer is the same size as the pointer. However, pointer size varies with platform. Generally, the result of TargetData::getIntPtrType() should be passed in. If that's not available, use Type::Int64Ty, which will make the isNoopCast call conservative.
This function determines if the CastInst does not require any bits to be changed in order to effect the cast. Essentially, it identifies cases where no code gen is necessary for the cast, hence the name no-op cast. For example, the following are all no-op casts: # bitcast i32* x to i8* # bitcast <2 x i32> x to <4 x i16> # ptrtoint i32* x to i32 ; on 32-bit plaforms only
| IntPtrTy | Integer type corresponding to pointer |
Definition at line 1738 of file Instructions.cpp.
References BitCast, FPToUI, FPTrunc, getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), PtrToInt, llvm::Attribute::SExt, UIToFP, and ZExt.
| unsigned CastInst::isEliminableCastPair | ( | Instruction::CastOps | firstOp, | |
| Instruction::CastOps | secondOp, | |||
| const Type * | SrcTy, | |||
| const Type * | MidTy, | |||
| const Type * | DstTy, | |||
| const Type * | IntPtrTy | |||
| ) | [static] |
Determine if a cast pair is eliminable.
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.
Instruction::CastOps value for a cast that can replace the pair, casting SrcTy to DstTy.
| firstOp | Opcode of first cast |
| secondOp | Opcode of second cast |
| SrcTy | SrcTy of 1st cast |
| MidTy | DstTy of 1st cast & SrcTy of 2nd cast |
| DstTy | DstTy of 2nd cast |
| IntPtrTy | Integer type corresponding to Ptr types |
Definition at line 1771 of file Instructions.cpp.
References BitCast, llvm::Type::getPrimitiveSizeInBits(), llvm::Type::isFloatingPoint(), llvm::Type::isInteger(), and ZExt.
| Instruction::CastOps llvm::CastInst::getOpcode | ( | ) | const [inline] |
Return the opcode of this CastInst.
Reimplemented from llvm::Instruction.
Definition at line 1053 of file InstrTypes.h.
Referenced by llvm::BitCastInst::BitCastInst(), llvm::FPExtInst::FPExtInst(), llvm::FPToSIInst::FPToSIInst(), llvm::FPToUIInst::FPToUIInst(), llvm::FPTruncInst::FPTruncInst(), llvm::IntToPtrInst::IntToPtrInst(), isEliminableCastPair(), isIntegerCast(), isLosslessCast(), isNoopCast(), OptimizeNoopCopyExpression(), llvm::PtrToIntInst::PtrToIntInst(), llvm::SExtInst::SExtInst(), llvm::SIToFPInst::SIToFPInst(), llvm::TruncInst::TruncInst(), llvm::UIToFPInst::UIToFPInst(), and llvm::ZExtInst::ZExtInst().
| const Type* llvm::CastInst::getSrcTy | ( | ) | const [inline] |
| const Type* llvm::CastInst::getDestTy | ( | ) | const [inline] |
| bool CastInst::castIsValid | ( | Instruction::CastOps | op, | |
| Value * | S, | |||
| const Type * | DstTy | |||
| ) | [static] |
Determine if a cast is valid without creating one.
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not.
Definition at line 2254 of file Instructions.cpp.
References BitCast, FPToUI, FPTrunc, llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::Type::isFirstClassType(), llvm::Type::isFPOrFPVector(), llvm::Type::isInteger(), llvm::Type::isIntOrIntVector(), PtrToInt, llvm::Attribute::SExt, UIToFP, and ZExt.
Referenced by llvm::BitCastInst::BitCastInst(), llvm::FPExtInst::FPExtInst(), llvm::FPToSIInst::FPToSIInst(), llvm::FPToUIInst::FPToUIInst(), llvm::FPTruncInst::FPTruncInst(), llvm::IntToPtrInst::IntToPtrInst(), llvm::PtrToIntInst::PtrToIntInst(), llvm::SExtInst::SExtInst(), llvm::SIToFPInst::SIToFPInst(), llvm::TruncInst::TruncInst(), llvm::UIToFPInst::UIToFPInst(), and llvm::ZExtInst::ZExtInst().
| static bool llvm::CastInst::classof | ( | const CastInst * | ) | [inline, static] |
Methods for support type inquiry through isa, cast, and dyn_cast:.
Definition at line 1069 of file InstrTypes.h.
| static bool llvm::CastInst::classof | ( | const Instruction * | ) | [inline, static] |
Methods for support type inquiry through isa, cast, and dyn_cast:.
Reimplemented from llvm::UnaryInstruction.
Reimplemented in llvm::TruncInst, llvm::ZExtInst, llvm::SExtInst, llvm::FPTruncInst, llvm::FPExtInst, llvm::UIToFPInst, llvm::SIToFPInst, llvm::FPToUIInst, llvm::FPToSIInst, llvm::IntToPtrInst, llvm::PtrToIntInst, and llvm::BitCastInst.
Definition at line 1070 of file InstrTypes.h.
| static bool llvm::CastInst::classof | ( | const Value * | V | ) | [inline, static] |
Reimplemented from llvm::UnaryInstruction.
Reimplemented in llvm::TruncInst, llvm::ZExtInst, llvm::SExtInst, llvm::FPTruncInst, llvm::FPExtInst, llvm::UIToFPInst, llvm::SIToFPInst, llvm::FPToUIInst, llvm::FPToSIInst, llvm::IntToPtrInst, llvm::PtrToIntInst, and llvm::BitCastInst.
Definition at line 1073 of file InstrTypes.h.