LLVM API Documentation

Public Member Functions | Static Public Member Functions | Protected Member Functions
llvm::CastInst Class Reference

Base class of casting instructions. More...

#include <InstrTypes.h>

Inheritance diagram for llvm::CastInst:
Inheritance graph
[legend]
Collaboration diagram for llvm::CastInst:
Collaboration graph
[legend]

List of all members.

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 (Type *IntPtrTy) const
 Determine if this cast is a no-op cast.
bool isNoopCast (const DataLayout *DL) const
 Determine if this cast is a no-op cast.
Instruction::CastOps getOpcode () const
 Return the opcode of this CastInst.
TypegetSrcTy () const
 Return the source type, as a convenience.
TypegetDestTy () const
 Return the destination type, as a convenience.

Static Public Member Functions

static CastInstCreate (Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Construct any of the CastInst subclasses.
static CastInstCreate (Instruction::CastOps, Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Construct any of the CastInst subclasses.
static CastInstCreateZExtOrBitCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a ZExt or BitCast cast instruction.
static CastInstCreateZExtOrBitCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a ZExt or BitCast cast instruction.
static CastInstCreateSExtOrBitCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a SExt or BitCast cast instruction.
static CastInstCreateSExtOrBitCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a SExt or BitCast cast instruction.
static CastInstCreatePointerCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
static CastInstCreatePointerCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static CastInstCreatePointerBitCastOrAddrSpaceCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a BitCast or an AddrSpaceCast cast instruction.
static CastInstCreatePointerBitCastOrAddrSpaceCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
 Create a BitCast or an AddrSpaceCast cast instruction.
static CastInstCreateIntegerCast (Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a ZExt, BitCast, or Trunc for int -> int casts.
static CastInstCreateIntegerCast (Value *S, Type *Ty, bool isSigned, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a ZExt, BitCast, or Trunc for int -> int casts.
static CastInstCreateFPCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
static CastInstCreateFPCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
static CastInstCreateTruncOrBitCast (Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a Trunc or BitCast cast instruction.
static CastInstCreateTruncOrBitCast (Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a Trunc or BitCast cast instruction.
static bool isCastable (Type *SrcTy, Type *DestTy)
 Check whether it is valid to call getCastOpcode for these types.
static bool isBitCastable (Type *SrcTy, Type *DestTy)
 Check whether a bitcast between these types is valid.
static Instruction::CastOps getCastOpcode (const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
 Infer the opcode for cast operand and type.
static bool isNoopCast (Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, Type *IntPtrTy)
 Determine if the described cast is a no-op cast.
static unsigned isEliminableCastPair (Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
 Determine if a cast pair is eliminable.
static bool castIsValid (Instruction::CastOps op, Value *S, Type *DstTy)
 Determine if a cast is valid without creating one.
static bool classof (const Instruction *I)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof (const Value *V)
 Methods for support type inquiry through isa, cast, and dyn_cast:

Protected Member Functions

 CastInst (Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
 Constructor with insert-before-instruction semantics for subclasses.
 CastInst (Type *Ty, unsigned iType, Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd)
 Constructor with insert-at-end-of-block semantics for subclasses.

Detailed Description

Base class of casting instructions.

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 386 of file InstrTypes.h.


Constructor & Destructor Documentation

llvm::CastInst::CastInst ( Type Ty,
unsigned  iType,
Value S,
const Twine NameStr = "",
Instruction InsertBefore = nullptr 
) [inline, protected]

Constructor with insert-before-instruction semantics for subclasses.

Definition at line 390 of file InstrTypes.h.

llvm::CastInst::CastInst ( Type Ty,
unsigned  iType,
Value S,
const Twine NameStr,
BasicBlock InsertAtEnd 
) [inline, protected]

Constructor with insert-at-end-of-block semantics for subclasses.

Definition at line 396 of file InstrTypes.h.


Member Function Documentation

bool CastInst::castIsValid ( Instruction::CastOps  op,
Value S,
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.

Returns:
true iff the proposed cast is valid.

Check that the construction parameters for a CastInst are correct. This could be broken out into the separate constructors but it is useful to have it in one place and to eliminate the redundant code for getting the sizes of the types involved.

Definition at line 2830 of file Instructions.cpp.

References llvm::AddrSpaceCast, llvm::dyn_cast(), llvm::FPExt, llvm::FPToSI, llvm::PointerType::getAddressSpace(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::IntToPtr, llvm::Type::isAggregateType(), llvm::Type::isFirstClassType(), llvm::Type::isFPOrFPVectorTy(), llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPointerTy(), llvm::Type::isVectorTy(), llvm::SExt, llvm::SIToFP, and llvm::Trunc.

Referenced by llvm::AddrSpaceCastInst::AddrSpaceCastInst(), llvm::BitCastInst::BitCastInst(), ConstantFoldLoadThroughBitcast(), Create(), llvm::FPExtInst::FPExtInst(), llvm::FPToSIInst::FPToSIInst(), llvm::FPToUIInst::FPToUIInst(), llvm::FPTruncInst::FPTruncInst(), llvm::ConstantExpr::getAddrSpaceCast(), llvm::ConstantExpr::getBitCast(), llvm::ConstantExpr::getCast(), 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 Instruction I) [inline, static]
static bool llvm::CastInst::classof ( const Value V) [inline, static]
CastInst * CastInst::Create ( Instruction::CastOps  op,
Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [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).

Parameters:
opThe opcode of the cast instruction
SThe value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2409 of file Instructions.cpp.

References llvm::AddrSpaceCast, castIsValid(), llvm::FPExt, llvm::FPToSI, llvm::IntToPtr, llvm_unreachable, llvm::SExt, llvm::SIToFP, and llvm::Trunc.

Referenced by BuildNew(), llvm::InstCombiner::commonCastTransforms(), llvm::NoFolder::CreateCast(), llvm::IRBuilder< true, TargetFolder >::CreateCast(), CreateFPCast(), CreateIntegerCast(), CreatePointerBitCastOrAddrSpaceCast(), CreatePointerCast(), CreateSExtOrBitCast(), CreateTruncOrBitCast(), CreateZExtOrBitCast(), llvm::InstCombiner::FoldSelectOpOp(), llvm::ConstantExpr::getAsInstruction(), SinkCast(), SinkShiftAndTruncate(), llvm::UpgradeBitCastInst(), llvm::InstCombiner::visitAnd(), llvm::InstCombiner::visitBitCast(), llvm::InstCombiner::visitCallInst(), llvm::InstCombiner::visitExtractElementInst(), llvm::InstCombiner::visitGetElementPtrInst(), llvm::InstCombiner::visitOr(), and llvm::InstCombiner::visitXor().

CastInst * CastInst::Create ( Instruction::CastOps  op,
Value S,
Type Ty,
const Twine 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).

Parameters:
opThe opcode for the cast instruction
SThe value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2431 of file Instructions.cpp.

References llvm::AddrSpaceCast, castIsValid(), llvm::FPExt, llvm::FPToSI, llvm::IntToPtr, llvm_unreachable, llvm::SExt, llvm::SIToFP, and llvm::Trunc.

CastInst * CastInst::CreateFPCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.

Parameters:
SThe floating point value to be casted
TyThe floating point type to cast to
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2590 of file Instructions.cpp.

References Create(), llvm::FPExt, llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::Type::isFPOrFPVectorTy().

Referenced by llvm::IRBuilder< true, TargetFolder >::CreateFPCast(), and llvm::InstCombiner::visitFPTrunc().

CastInst * CastInst::CreateFPCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.

Parameters:
SThe floating point value to be casted
TyThe floating point type to cast to
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2603 of file Instructions.cpp.

References Create(), llvm::FPExt, llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::Type::isFPOrFPVectorTy().

CastInst * CastInst::CreateIntegerCast ( Value S,
Type Ty,
bool  isSigned,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a ZExt, BitCast, or Trunc for int -> int casts.

Parameters:
SThe pointer value to be casted (operand 0)
TyThe type to which cast should be made
isSignedWhether to regard S as signed or not
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2562 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::SExt, and llvm::Trunc.

Referenced by llvm::NoFolder::CreateIntCast(), llvm::IRBuilder< true, TargetFolder >::CreateIntCast(), createMalloc(), llvm::InstCombiner::visitCallInst(), llvm::InstCombiner::visitPtrToInt(), and llvm::InstCombiner::visitTrunc().

CastInst * CastInst::CreateIntegerCast ( Value S,
Type Ty,
bool  isSigned,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a ZExt, BitCast, or Trunc for int -> int casts.

Parameters:
SThe integer value to be casted (operand 0)
TyThe integer type to which operand is casted
isSignedWhether to regard S as signed or not
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2576 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::SExt, and llvm::Trunc.

CastInst * CastInst::CreatePointerBitCastOrAddrSpaceCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a BitCast or an AddrSpaceCast cast instruction.

Parameters:
SThe pointer value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2536 of file Instructions.cpp.

References llvm::AddrSpaceCast, Create(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), and llvm::Type::isPtrOrPtrVectorTy().

Referenced by llvm::IRBuilder< true, TargetFolder >::CreatePointerBitCastOrAddrSpaceCast(), CreatePointerCast(), and llvm::InstCombiner::visitGetElementPtrInst().

CastInst * CastInst::CreatePointerBitCastOrAddrSpaceCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = 0 
) [static]

Create a BitCast or an AddrSpaceCast cast instruction.

Parameters:
SThe pointer value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2549 of file Instructions.cpp.

References llvm::AddrSpaceCast, Create(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), and llvm::Type::isPtrOrPtrVectorTy().

CastInst * CastInst::CreatePointerCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.

Parameters:
SThe pointer value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2501 of file Instructions.cpp.

References Create(), CreatePointerBitCastOrAddrSpaceCast(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPtrOrPtrVectorTy(), and llvm::Type::isVectorTy().

Referenced by llvm::IRBuilder< true, TargetFolder >::CreatePointerCast().

CastInst * CastInst::CreatePointerCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.

Create a BitCast or a PtrToInt cast instruction.

Parameters:
SThe pointer value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2519 of file Instructions.cpp.

References Create(), CreatePointerBitCastOrAddrSpaceCast(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPtrOrPtrVectorTy(), and llvm::Type::isVectorTy().

CastInst * CastInst::CreateSExtOrBitCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a SExt or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2469 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::SExt.

Referenced by llvm::IRBuilder< true, TargetFolder >::CreateSExtOrBitCast(), and llvm::InstCombiner::visitSub().

CastInst * CastInst::CreateSExtOrBitCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a SExt or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2477 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::SExt.

CastInst * CastInst::CreateTruncOrBitCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a Trunc or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2485 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::Trunc.

Referenced by llvm::IRBuilder< true, TargetFolder >::CreateTruncOrBitCast().

CastInst * CastInst::CreateTruncOrBitCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a Trunc or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2493 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), and llvm::Trunc.

CastInst * CastInst::CreateZExtOrBitCast ( Value S,
Type Ty,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a ZExt or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which cast should be made
NameName for the instruction
InsertBeforePlace to insert the instruction

Definition at line 2453 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), and llvm::Value::getType().

Referenced by llvm::IRBuilder< true, TargetFolder >::CreateZExtOrBitCast(), and llvm::InstCombiner::visitSub().

CastInst * CastInst::CreateZExtOrBitCast ( Value S,
Type Ty,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a ZExt or BitCast cast instruction.

Parameters:
SThe value to be casted (operand 0)
TyThe type to which operand is casted
NameThe name for the instruction
InsertAtEndThe block to insert the instruction into

Definition at line 2461 of file Instructions.cpp.

References Create(), llvm::Type::getScalarSizeInBits(), and llvm::Value::getType().

Instruction::CastOps CastInst::getCastOpcode ( const Value Val,
bool  SrcIsSigned,
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.

Parameters:
ValThe value to cast
SrcIsSignedWhether to treat the source as signed
TyThe Type to which the value should be casted
DstIsSignedWhether to treate the dest. as signed

Definition at line 2727 of file Instructions.cpp.

References llvm::AddrSpaceCast, llvm::FPExt, llvm::FPToSI, llvm::Type::getPointerAddressSpace(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::IntToPtr, llvm::Type::isFirstClassType(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), llvm::Type::isVectorTy(), llvm::Type::isX86_MMXTy(), llvm_unreachable, llvm::SExt, llvm::SIToFP, and llvm::Trunc.

Referenced by CastGEPIndices(), llvm::ConstantFoldCastInstruction(), getFoldedAlignOf(), getFoldedOffsetOf(), and getFoldedSizeOf().

Type* llvm::CastInst::getDestTy ( ) const [inline]

Return the destination type, as a convenience.

Definition at line 630 of file InstrTypes.h.

References llvm::Intrinsic::getType().

Type* llvm::CastInst::getSrcTy ( ) const [inline]

Return the source type, as a convenience.

Definition at line 628 of file InstrTypes.h.

Referenced by llvm::InstCombiner::visitFCmpInst().

bool CastInst::isBitCastable ( Type SrcTy,
Type DestTy 
) [static]

Check whether a bitcast between these types is valid.

Parameters:
SrcTyThe Type from which the value should be cast.
DestTyThe Type to which the value should be cast.

Definition at line 2679 of file Instructions.cpp.

References llvm::Type::getPrimitiveSizeInBits(), llvm::Type::isFirstClassType(), and llvm::Type::isX86_MMXTy().

bool CastInst::isCastable ( Type SrcTy,
Type DestTy 
) [static]

Check whether it is valid to call getCastOpcode for these types.

Parameters:
SrcTyThe Type from which the value should be cast.
DestTyThe Type to which the value should be cast.

Definition at line 2618 of file Instructions.cpp.

References llvm::Type::getPrimitiveSizeInBits(), llvm::Type::isFirstClassType(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), llvm::Type::isVectorTy(), and llvm::Type::isX86_MMXTy().

unsigned CastInst::isEliminableCastPair ( Instruction::CastOps  firstOp,
Instruction::CastOps  secondOp,
Type SrcTy,
Type MidTy,
Type DstTy,
Type SrcIntPtrTy,
Type MidIntPtrTy,
Type DstIntPtrTy 
) [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.

Returns:
0 if the CastInst pair can't be eliminated, otherwise returns Instruction::CastOps value for a cast that can replace the pair, casting SrcTy to DstTy.

This function determines if a pair of casts can be eliminated and what opcode should be used in the elimination. This assumes that there are two instructions like this: F = firstOpcode SrcTy x to MidTy S = secondOpcode MidTy F to DstTy The function returns a resultOpcode so these two casts can be replaced with: Replacement = resultOpcode SrcTy x to DstTy If no such cast is permited, the function returns 0.

Parameters:
firstOpOpcode of first cast
secondOpOpcode of second cast
SrcTySrcTy of 1st cast
MidTyDstTy of 1st cast & SrcTy of 2nd cast
DstTyDstTy of 2nd cast
SrcIntPtrTyInteger type corresponding to Ptr SrcTy, or null
MidIntPtrTyInteger type corresponding to Ptr MidTy, or null
DstIntPtrTyInteger type corresponding to Ptr DstTy, or null

Definition at line 2190 of file Instructions.cpp.

References llvm::AddrSpaceCast, llvm::Type::getPointerAddressSpace(), llvm::Type::getPointerElementType(), llvm::Type::getScalarSizeInBits(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPtrOrPtrVectorTy(), llvm::Type::isVectorTy(), and llvm_unreachable.

Referenced by foldConstantCastPair().

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.

Returns:
true iff the cast has only integral typed operand and dest type.

Definition at line 2091 of file Instructions.cpp.

References getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Type::isIntegerTy(), llvm::SExt, and llvm::Trunc.

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, or int->ptr.

Returns:
true iff the cast is lossless.

Definition at line 2104 of file Instructions.cpp.

References getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), and llvm::Type::isPointerTy().

Referenced by isSafeToEliminateVarargsCast().

bool CastInst::isNoopCast ( Instruction::CastOps  Opcode,
Type SrcTy,
Type DestTy,
Type IntPtrTy 
) [static]

Determine if the described cast is a no-op cast.

Determine if the described 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 DataLayout::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

Parameters:
OpcodeOpcode of cast
SrcTySrcTy of cast
DestTyDstTy of cast
IntPtrTyInteger type corresponding to Ptr types

Definition at line 2129 of file Instructions.cpp.

References llvm::AddrSpaceCast, llvm::FPExt, llvm::FPToSI, llvm::Type::getScalarSizeInBits(), llvm::IntToPtr, llvm_unreachable, llvm::SExt, llvm::SIToFP, and llvm::Trunc.

Referenced by isNoopCast().

bool CastInst::isNoopCast ( Type IntPtrTy) const

Determine if this cast is a no-op cast.

Determine if a cast is a no-op.

Parameters:
IntPtrTyInteger type corresponding to pointer

Definition at line 2159 of file Instructions.cpp.

References getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), and isNoopCast().

Determine if this cast is a no-op cast.

Parameters:
DLDataLayout to get the Int Ptr type from.

Definition at line 2163 of file Instructions.cpp.

References llvm::Value::getContext(), llvm::Type::getInt64Ty(), llvm::DataLayout::getIntPtrType(), getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::IntToPtr, and isNoopCast().


The documentation for this class was generated from the following files: