class CastInst

Declaration

class CastInst : public UnaryInstruction { /* full declaration omitted */ };

Description

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)) { ... } Base class of casting instructions.

Declared at: llvm/include/llvm/IR/InstrTypes.h:429

Inherits from: UnaryInstruction

Member Variables

Inherited from Value:

protected SubclassOptionalData
protected NumUserOperands
protected IsUsedByMD
protected HasName
protected HasMetadata
protected HasHungOffUses
protected HasDescriptor
public static MaxAlignmentExponent = 32
public static MaximumAlignment = 1ULL << MaxAlignmentExponent

Method Overview

  • protected CastInst(llvm::Type * Ty, unsigned int iType, llvm::Value * S, const llvm::Twine & NameStr, llvm::BasicBlock * InsertAtEnd)
  • protected CastInst(llvm::Type * Ty, unsigned int iType, llvm::Value * S, const llvm::Twine & NameStr = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * Create(Instruction::CastOps, llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * Create(Instruction::CastOps, llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreateBitOrPointerCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateFPCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreateFPCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateIntegerCast(llvm::Value * S, llvm::Type * Ty, bool isSigned, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateIntegerCast(llvm::Value * S, llvm::Type * Ty, bool isSigned, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreatePointerBitCastOrAddrSpaceCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreatePointerBitCastOrAddrSpaceCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreatePointerCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreatePointerCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateSExtOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreateSExtOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateTruncOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static llvm::CastInst * CreateTruncOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateZExtOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name = "", llvm::Instruction * InsertBefore = nullptr)
  • public static llvm::CastInst * CreateZExtOrBitCast(llvm::Value * S, llvm::Type * Ty, const llvm::Twine & Name, llvm::BasicBlock * InsertAtEnd)
  • public static bool castIsValid(Instruction::CastOps op, llvm::Value * S, llvm::Type * DstTy)
  • public static bool castIsValid(Instruction::CastOps op, llvm::Type * SrcTy, llvm::Type * DstTy)
  • public static bool classof(const llvm::Value * V)
  • public static bool classof(const llvm::Instruction * I)
  • public static Instruction::CastOps getCastOpcode(const llvm::Value * Val, bool SrcIsSigned, llvm::Type * Ty, bool DstIsSigned)
  • public llvm::Type * getDestTy() const
  • public Instruction::CastOps getOpcode() const
  • public llvm::Type * getSrcTy() const
  • public static bool isBitCastable(llvm::Type * SrcTy, llvm::Type * DestTy)
  • public static bool isBitOrNoopPointerCastable(llvm::Type * SrcTy, llvm::Type * DestTy, const llvm::DataLayout & DL)
  • public static unsigned int isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, llvm::Type * SrcTy, llvm::Type * MidTy, llvm::Type * DstTy, llvm::Type * SrcIntPtrTy, llvm::Type * MidIntPtrTy, llvm::Type * DstIntPtrTy)
  • public bool isIntegerCast() const
  • public bool isLosslessCast() const
  • public static bool isNoopCast(Instruction::CastOps Opcode, llvm::Type * SrcTy, llvm::Type * DstTy, const llvm::DataLayout & DL)
  • public bool isNoopCast(const llvm::DataLayout & DL) const

Inherited from UnaryInstruction:

Inherited from Instruction:

Inherited from User:

Inherited from Value:

Methods

CastInst(llvm::Type* Ty,
         unsigned int iType,
         llvm::Value* S,
         const llvm::Twine& NameStr,
         llvm::BasicBlock* InsertAtEnd)

Description

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

Declared at: llvm/include/llvm/IR/InstrTypes.h:438

Parameters

llvm::Type* Ty
unsigned int iType
llvm::Value* S
const llvm::Twine& NameStr
llvm::BasicBlock* InsertAtEnd

CastInst(
    llvm::Type* Ty,
    unsigned int iType,
    llvm::Value* S,
    const llvm::Twine& NameStr = "",
    llvm::Instruction* InsertBefore = nullptr)

Description

Constructor with insert-before-instruction semantics for subclasses

Declared at: llvm/include/llvm/IR/InstrTypes.h:432

Parameters

llvm::Type* Ty
unsigned int iType
llvm::Value* S
const llvm::Twine& NameStr = ""
llvm::Instruction* InsertBefore = nullptr

static llvm::CastInst* Create(
    Instruction::CastOps,
    llvm::Value* S,
    llvm::Type* Ty,
    const llvm::Twine& Name = "",
    llvm::Instruction* InsertBefore = nullptr)

Description

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). Construct any of the CastInst subclasses

Declared at: llvm/include/llvm/IR/InstrTypes.h:451

Parameters

Instruction::CastOps
llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

static llvm::CastInst* Create(
    Instruction::CastOps,
    llvm::Value* S,
    llvm::Type* Ty,
    const llvm::Twine& Name,
    llvm::BasicBlock* InsertAtEnd)

Description

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). Construct any of the CastInst subclasses

Declared at: llvm/include/llvm/IR/InstrTypes.h:464

Parameters

Instruction::CastOps
llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

static llvm::CastInst* CreateBitOrPointerCast(
    llvm::Value* S,
    llvm::Type* Ty,
    const llvm::Twine& Name = "",
    llvm::Instruction* InsertBefore = nullptr)

Description

Create a BitCast, a PtrToInt, or an IntToPTr cast instruction. If the value is a pointer type and the destination an integer type, creates a PtrToInt cast. If the value is an integer type and the destination a pointer type, creates an IntToPtr cast. Otherwise, creates a bitcast.

Declared at: llvm/include/llvm/IR/InstrTypes.h:542

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

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

Declared at: llvm/include/llvm/IR/InstrTypes.h:576

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

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

Description

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

Declared at: llvm/include/llvm/IR/InstrTypes.h:568

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

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

Declared at: llvm/include/llvm/IR/InstrTypes.h:550

Parameters

llvm::Value* S
llvm::Type* Ty
bool isSigned
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

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

Declared at: llvm/include/llvm/IR/InstrTypes.h:559

Parameters

llvm::Value* S
llvm::Type* Ty
bool isSigned
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

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

Description

Create a BitCast or an AddrSpaceCast cast instruction.

Declared at: llvm/include/llvm/IR/InstrTypes.h:521

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

static llvm::CastInst*
CreatePointerBitCastOrAddrSpaceCast(
    llvm::Value* S,
    llvm::Type* Ty,
    const llvm::Twine& Name = "",
    llvm::Instruction* InsertBefore = nullptr)

Description

Create a BitCast or an AddrSpaceCast cast instruction.

Declared at: llvm/include/llvm/IR/InstrTypes.h:529

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.

Declared at: llvm/include/llvm/IR/InstrTypes.h:505

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

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

Description

Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.

Declared at: llvm/include/llvm/IR/InstrTypes.h:513

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

Create a SExt or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:497

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

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

Description

Create a SExt or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:489

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

Create a Trunc or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:592

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

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

Description

Create a Trunc or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:584

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

Create a ZExt or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:473

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name = ""
llvm::Instruction* InsertBefore = nullptr

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

Description

Create a ZExt or BitCast cast instruction

Declared at: llvm/include/llvm/IR/InstrTypes.h:481

Parameters

llvm::Value* S
llvm::Type* Ty
const llvm::Twine& Name
llvm::BasicBlock* InsertAtEnd

static bool castIsValid(Instruction::CastOps op,
                        llvm::Value* S,
                        llvm::Type* DstTy)

Declared at: llvm/include/llvm/IR/InstrTypes.h:690

Parameters

Instruction::CastOps op
llvm::Value* S
llvm::Type* DstTy

static bool castIsValid(Instruction::CastOps op,
                        llvm::Type* SrcTy,
                        llvm::Type* DstTy)

Description

This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.

Declared at: llvm/include/llvm/IR/InstrTypes.h:689

Parameters

Instruction::CastOps op
llvm::Type* SrcTy
llvm::Type* DstTy

Returns

true iff the proposed cast is valid. Determine if a cast is valid without creating one.

static bool classof(const llvm::Value* V)

Declared at: llvm/include/llvm/IR/InstrTypes.h:698

Parameters

const llvm::Value* V

static bool classof(const llvm::Instruction* I)

Description

Methods for support type inquiry through isa, cast, and dyn_cast:

Declared at: llvm/include/llvm/IR/InstrTypes.h:695

Parameters

const llvm::Instruction* I

static Instruction::CastOps getCastOpcode(
    const llvm::Value* Val,
    bool SrcIsSigned,
    llvm::Type* Ty,
    bool DstIsSigned)

Description

Returns the opcode necessary to cast Val into Ty using usual casting rules. Infer the opcode for cast operand and type

Declared at: llvm/include/llvm/IR/InstrTypes.h:618

Parameters

const llvm::Value* Val
bool SrcIsSigned
llvm::Type* Ty
bool DstIsSigned

llvm::Type* getDestTy() const

Description

Return the destination type, as a convenience

Declared at: llvm/include/llvm/IR/InstrTypes.h:683

Instruction::CastOps getOpcode() const

Description

Return the opcode of this CastInst

Declared at: llvm/include/llvm/IR/InstrTypes.h:676

llvm::Type* getSrcTy() const

Description

Return the source type, as a convenience

Declared at: llvm/include/llvm/IR/InstrTypes.h:681

static bool isBitCastable(llvm::Type* SrcTy,
                          llvm::Type* DestTy)

Description

Check whether a bitcast between these types is valid

Declared at: llvm/include/llvm/IR/InstrTypes.h:600

Parameters

llvm::Type* SrcTy
llvm::Type* DestTy

static bool isBitOrNoopPointerCastable(
    llvm::Type* SrcTy,
    llvm::Type* DestTy,
    const llvm::DataLayout& DL)

Description

Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op. This ensures that any pointer < ->integer cast has enough bits in the integer and any other cast is a bitcast.

Declared at: llvm/include/llvm/IR/InstrTypes.h:610

Parameters

llvm::Type* SrcTy
llvm::Type* DestTy
const llvm::DataLayout& DL

static unsigned int isEliminableCastPair(
    Instruction::CastOps firstOpcode,
    Instruction::CastOps secondOpcode,
    llvm::Type* SrcTy,
    llvm::Type* MidTy,
    llvm::Type* DstTy,
    llvm::Type* SrcIntPtrTy,
    llvm::Type* MidIntPtrTy,
    llvm::Type* DstIntPtrTy)

Description

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.

Declared at: llvm/include/llvm/IR/InstrTypes.h:664

Parameters

Instruction::CastOps firstOpcode
Instruction::CastOps secondOpcode
llvm::Type* SrcTy
llvm::Type* MidTy
llvm::Type* DstTy
llvm::Type* SrcIntPtrTy
llvm::Type* MidIntPtrTy
llvm::Type* DstIntPtrTy

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. Determine if a cast pair is eliminable

bool isIntegerCast() const

Description

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.

Declared at: llvm/include/llvm/IR/InstrTypes.h:630

Returns

true iff the cast has only integral typed operand and dest type. Determine if this is an integer-only cast.

bool isLosslessCast() const

Description

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.

Declared at: llvm/include/llvm/IR/InstrTypes.h:637

Returns

true iff the cast is lossless. Determine if this is a lossless cast.

static bool isNoopCast(
    Instruction::CastOps Opcode,
    llvm::Type* SrcTy,
    llvm::Type* DstTy,
    const llvm::DataLayout& DL)

Description

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 DataLayout argument is to determine the pointer size when examining 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. Note that a precondition of this method is that the cast is legal - i.e. the instruction formed with these operands would verify.

Declared at: llvm/include/llvm/IR/InstrTypes.h:646

Parameters

Instruction::CastOps Opcode
llvm::Type* SrcTy
llvm::Type* DstTy
const llvm::DataLayout& DL

bool isNoopCast(const llvm::DataLayout& DL) const

Description

Determine if this cast is a no-op cast.

Declared at: llvm/include/llvm/IR/InstrTypes.h:656

Parameters

const llvm::DataLayout& DL
is the DataLayout to determine pointer size.