class CastInst

Declaration

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

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

Inherits from: UnaryInstruction

Member Variables

Inherited from Value:

protected SubclassOptionalData
protected NumUserOperands
protected IsUsedByMD
protected HasName
protected HasHungOffUses
protected HasDescriptor
public static MaxAlignmentExponent = 29
public static MaximumAlignment = 1U << 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 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 bool isCastable(llvm::Type * SrcTy, llvm::Type * DestTy)
  • 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:448

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:442

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:461

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:474

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:552

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:586

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:578

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:560

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:569

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:531

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:539

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:515

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:523

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:507

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:499

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:602

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:594

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:483

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:491

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)

Description

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

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

Parameters

Instruction::CastOps op
llvm::Value* S
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:711

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:708

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:634

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:699

Instruction::CastOps getOpcode() const

Description

Return the opcode of this CastInst

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

llvm::Type* getSrcTy() const

Description

Return the source type, as a convenience

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

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:616

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:626

Parameters

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

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

Description

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

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

Parameters

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

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:680

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:646

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:653

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. Determine if the described cast is a no-op cast.

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

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:672

Parameters

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