LLVM 19.0.0git
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
llvm::ConstantExpr Class Reference

A constant value that is initialized with an expression using other constant values. More...

#include "llvm/IR/Constants.h"

Inheritance diagram for llvm::ConstantExpr:
Inheritance graph
[legend]

Public Member Functions

 DECLARE_TRANSPARENT_OPERAND_ACCESSORS (Constant)
 Transparently provide more efficient getOperand methods.
 
bool isCast () const
 Return true if this is a convert constant expression.
 
unsigned getOpcode () const
 Return the opcode at the root of this constant expression.
 
ArrayRef< int > getShuffleMask () const
 Assert that this is a shufflevector and return the mask.
 
ConstantgetShuffleMaskForBitcode () const
 Assert that this is a shufflevector and return the mask.
 
const chargetOpcodeName () const
 Return a string representation for an opcode.
 
ConstantgetWithOperands (ArrayRef< Constant * > Ops) const
 This returns the current constant expression with the operands replaced with the specified values.
 
ConstantgetWithOperands (ArrayRef< Constant * > Ops, Type *Ty, bool OnlyIfReduced=false, Type *SrcTy=nullptr) const
 Get the current expression with the operands replaced.
 
InstructiongetAsInstruction () const
 Returns an Instruction which implements the same operation as this ConstantExpr.
 
- Public Member Functions inherited from llvm::Constant
void operator= (const Constant &)=delete
 
 Constant (const Constant &)=delete
 
bool isNullValue () const
 Return true if this is the value that would be returned by getNullValue.
 
bool isOneValue () const
 Returns true if the value is one.
 
bool isNotOneValue () const
 Return true if the value is not the one value, or, for vectors, does not contain one value elements.
 
bool isAllOnesValue () const
 Return true if this is the value that would be returned by getAllOnesValue.
 
bool isNegativeZeroValue () const
 Return true if the value is what would be returned by getZeroValueForNegation.
 
bool isZeroValue () const
 Return true if the value is negative zero or null value.
 
bool isNotMinSignedValue () const
 Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest signed value elements.
 
bool isMinSignedValue () const
 Return true if the value is the smallest signed value.
 
bool isFiniteNonZeroFP () const
 Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector constant with all finite and non-zero elements.
 
bool isNormalFP () const
 Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scalar constant or a vector constant with all normal elements.
 
bool hasExactInverseFP () const
 Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplicative inverse for each element in the vector.
 
bool isNaN () const
 Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN elements.
 
bool isElementWiseEqual (Value *Y) const
 Return true if this constant and a constant 'Y' are element-wise equal.
 
bool containsUndefOrPoisonElement () const
 Return true if this is a vector constant that includes any undef or poison elements.
 
bool containsPoisonElement () const
 Return true if this is a vector constant that includes any poison elements.
 
bool containsUndefElement () const
 Return true if this is a vector constant that includes any strictly undef (not poison) elements.
 
bool containsConstantExpression () const
 Return true if this is a fixed width vector constant that includes any constant expressions.
 
bool isThreadDependent () const
 Return true if the value can vary between threads.
 
bool isDLLImportDependent () const
 Return true if the value is dependent on a dllimport variable.
 
bool isConstantUsed () const
 Return true if the constant has users other than constant expressions and other dangling things.
 
bool needsRelocation () const
 This method classifies the entry according to whether or not it may generate a relocation entry (either static or dynamic).
 
bool needsDynamicRelocation () const
 
ConstantgetAggregateElement (unsigned Elt) const
 For aggregates (struct/array/vector) return the constant that corresponds to the specified element if possible, or null if not.
 
ConstantgetAggregateElement (Constant *Elt) const
 
ConstantgetSplatValue (bool AllowPoison=false) const
 If all elements of the vector constant have the same value, return that value.
 
const APIntgetUniqueInteger () const
 If C is a constant integer then return its value, otherwise C must be a vector of constant integers, all equal, and the common value is returned.
 
void destroyConstant ()
 Called if some element of this constant is no longer valid.
 
void handleOperandChange (Value *, Value *)
 This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does work on constants.
 
void removeDeadConstantUsers () const
 If there are any dead constant users dangling off of this constant, remove them.
 
bool hasOneLiveUse () const
 Return true if the constant has exactly one live use.
 
bool hasZeroLiveUses () const
 Return true if the constant has no live uses.
 
const ConstantstripPointerCasts () const
 
ConstantstripPointerCasts ()
 
bool isManifestConstant () const
 Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only ConstantData.
 
- Public Member Functions inherited from llvm::User
 User (const User &)=delete
 
void operator delete (void *Usr)
 Free memory allocated for User and Use objects.
 
void operator delete (void *Usr, unsigned)
 Placement delete - required by std, called if the ctor throws.
 
void operator delete (void *Usr, unsigned, unsigned)
 Placement delete - required by std, called if the ctor throws.
 
const UsegetOperandList () const
 
UsegetOperandList ()
 
ValuegetOperand (unsigned i) const
 
void setOperand (unsigned i, Value *Val)
 
const UsegetOperandUse (unsigned i) const
 
UsegetOperandUse (unsigned i)
 
unsigned getNumOperands () const
 
ArrayRef< const uint8_t > getDescriptor () const
 Returns the descriptor co-allocated with this User instance.
 
MutableArrayRef< uint8_t > getDescriptor ()
 Returns the descriptor co-allocated with this User instance.
 
void setGlobalVariableNumOperands (unsigned NumOps)
 Set the number of operands on a GlobalVariable.
 
void setNumHungOffUseOperands (unsigned NumOps)
 Subclasses with hung off uses need to manage the operand count themselves.
 
bool isDroppable () const
 A droppable user is a user for which uses can be dropped without affecting correctness and should be dropped rather than preventing a transformation from happening.
 
op_iterator op_begin ()
 
const_op_iterator op_begin () const
 
op_iterator op_end ()
 
const_op_iterator op_end () const
 
op_range operands ()
 
const_op_range operands () const
 
value_op_iterator value_op_begin ()
 
value_op_iterator value_op_end ()
 
iterator_range< value_op_iteratoroperand_values ()
 
const_value_op_iterator value_op_begin () const
 
const_value_op_iterator value_op_end () const
 
iterator_range< const_value_op_iteratoroperand_values () const
 
void dropAllReferences ()
 Drop all references to operands.
 
bool replaceUsesOfWith (Value *From, Value *To)
 Replace uses of one Value with another.
 
- Public Member Functions inherited from llvm::Value
 Value (const Value &)=delete
 
Valueoperator= (const Value &)=delete
 
void deleteValue ()
 Delete a pointer to a generic Value.
 
void dump () const
 Support for debugging, callable in GDB: V->dump()
 
TypegetType () const
 All values are typed, get the type of this value.
 
LLVMContextgetContext () const
 All values hold a context through their type.
 
bool hasName () const
 
ValueNamegetValueName () const
 
void setValueName (ValueName *VN)
 
StringRef getName () const
 Return a constant reference to the value's name.
 
void setName (const Twine &Name)
 Change the name of the value.
 
void takeName (Value *V)
 Transfer the name from V to this value.
 
std::string getNameOrAsOperand () const
 
void replaceAllUsesWith (Value *V)
 Change all uses of this to point to a new Value.
 
void replaceNonMetadataUsesWith (Value *V)
 Change non-metadata uses of this to point to a new Value.
 
void replaceUsesWithIf (Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
 Go through the uses list for this definition and make each use point to "V" if the callback ShouldReplace returns true for the given Use.
 
void replaceUsesOutsideBlock (Value *V, BasicBlock *BB)
 replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V" instead of "this" when the use is outside the block.
 
void assertModuleIsMaterializedImpl () const
 
void assertModuleIsMaterialized () const
 
bool use_empty () const
 
bool materialized_use_empty () const
 
use_iterator materialized_use_begin ()
 
const_use_iterator materialized_use_begin () const
 
use_iterator use_begin ()
 
const_use_iterator use_begin () const
 
use_iterator use_end ()
 
const_use_iterator use_end () const
 
iterator_range< use_iteratormaterialized_uses ()
 
iterator_range< const_use_iteratormaterialized_uses () const
 
iterator_range< use_iteratoruses ()
 
iterator_range< const_use_iteratoruses () const
 
bool user_empty () const
 
user_iterator materialized_user_begin ()
 
const_user_iterator materialized_user_begin () const
 
user_iterator user_begin ()
 
const_user_iterator user_begin () const
 
user_iterator user_end ()
 
const_user_iterator user_end () const
 
Useruser_back ()
 
const Useruser_back () const
 
iterator_range< user_iteratormaterialized_users ()
 
iterator_range< const_user_iteratormaterialized_users () const
 
iterator_range< user_iteratorusers ()
 
iterator_range< const_user_iteratorusers () const
 
bool hasOneUse () const
 Return true if there is exactly one use of this value.
 
bool hasNUses (unsigned N) const
 Return true if this Value has exactly N uses.
 
bool hasNUsesOrMore (unsigned N) const
 Return true if this value has N uses or more.
 
bool hasOneUser () const
 Return true if there is exactly one user of this value.
 
UsegetSingleUndroppableUse ()
 Return true if there is exactly one use of this value that cannot be dropped.
 
const UsegetSingleUndroppableUse () const
 
UsergetUniqueUndroppableUser ()
 Return true if there is exactly one unique user of this value that cannot be dropped (that user can have multiple uses of this value).
 
const UsergetUniqueUndroppableUser () const
 
bool hasNUndroppableUses (unsigned N) const
 Return true if there this value.
 
bool hasNUndroppableUsesOrMore (unsigned N) const
 Return true if this value has N uses or more.
 
void dropDroppableUses (llvm::function_ref< bool(const Use *)> ShouldDrop=[](const Use *) { return true;})
 Remove every uses that can safely be removed.
 
void dropDroppableUsesIn (User &Usr)
 Remove every use of this value in User that can safely be removed.
 
bool isUsedInBasicBlock (const BasicBlock *BB) const
 Check if this value is used in the specified basic block.
 
unsigned getNumUses () const
 This method computes the number of uses of this Value.
 
void addUse (Use &U)
 This method should only be used by the Use class.
 
unsigned getValueID () const
 Return an ID for the concrete type of this object.
 
unsigned getRawSubclassOptionalData () const
 Return the raw optional flags value contained in this value.
 
void clearSubclassOptionalData ()
 Clear the optional flags contained in this value.
 
bool hasSameSubclassOptionalData (const Value *V) const
 Check the optional flags for equality.
 
bool hasValueHandle () const
 Return true if there is a value handle associated with this value.
 
bool isUsedByMetadata () const
 Return true if there is metadata referencing this value.
 
bool isSwiftError () const
 Return true if this value is a swifterror value.
 
const ValuestripPointerCasts () const
 Strip off pointer casts, all-zero GEPs and address space casts.
 
ValuestripPointerCasts ()
 
const ValuestripPointerCastsAndAliases () const
 Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
 
ValuestripPointerCastsAndAliases ()
 
const ValuestripPointerCastsSameRepresentation () const
 Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the result stays the same.
 
ValuestripPointerCastsSameRepresentation ()
 
const ValuestripPointerCastsForAliasAnalysis () const
 Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
 
ValuestripPointerCastsForAliasAnalysis ()
 
const ValuestripInBoundsConstantOffsets () const
 Strip off pointer casts and all-constant inbounds GEPs.
 
ValuestripInBoundsConstantOffsets ()
 
const ValuestripAndAccumulateConstantOffsets (const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
 Accumulate the constant offset this value has compared to a base pointer.
 
ValuestripAndAccumulateConstantOffsets (const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false)
 
const ValuestripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset) const
 This is a wrapper around stripAndAccumulateConstantOffsets with the in-bounds requirement set to false.
 
ValuestripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset)
 
const ValuestripInBoundsOffsets (function_ref< void(const Value *)> Func=[](const Value *) {}) const
 Strip off pointer casts and inbounds GEPs.
 
ValuestripInBoundsOffsets (function_ref< void(const Value *)> Func=[](const Value *) {})
 
std::optional< int64_t > getPointerOffsetFrom (const Value *Other, const DataLayout &DL) const
 If this ptr is provably equal to Other plus a constant offset, return that offset in bytes.
 
bool canBeFreed () const
 Return true if the memory object referred to by V can by freed in the scope for which the SSA value defining the allocation is statically defined.
 
uint64_t getPointerDereferenceableBytes (const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
 Returns the number of bytes known to be dereferenceable for the pointer value.
 
Align getPointerAlignment (const DataLayout &DL) const
 Returns an alignment of the pointer value.
 
const ValueDoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB) const
 Translate PHI node to its predecessor from the given basic block.
 
ValueDoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB)
 
void mutateType (Type *Ty)
 Mutate the type of this Value to be of the specified type.
 
template<class Compare >
void sortUseList (Compare Cmp)
 Sort the use-list.
 
void reverseUseList ()
 Reverse the use-list.
 
void print (raw_ostream &O, bool IsForDebug=false) const
 Implement operator<< on Value.
 
void print (raw_ostream &O, ModuleSlotTracker &MST, bool IsForDebug=false) const
 
void printAsOperand (raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
 Print the name of this Value out to the specified raw_ostream.
 
void printAsOperand (raw_ostream &O, bool PrintType, ModuleSlotTracker &MST) const
 

Static Public Member Functions

static ConstantgetAlignOf (Type *Ty)
 getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the return type is an i64).
 
static ConstantgetSizeOf (Type *Ty)
 getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a target independent way (Note: the return type is an i64).
 
static ConstantgetNeg (Constant *C, bool HasNSW=false)
 
static ConstantgetNot (Constant *C)
 
static ConstantgetAdd (Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
 
static ConstantgetSub (Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
 
static ConstantgetMul (Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
 
static ConstantgetXor (Constant *C1, Constant *C2)
 
static ConstantgetShl (Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
 
static ConstantgetTrunc (Constant *C, Type *Ty, bool OnlyIfReduced=false)
 
static ConstantgetPtrToInt (Constant *C, Type *Ty, bool OnlyIfReduced=false)
 
static ConstantgetIntToPtr (Constant *C, Type *Ty, bool OnlyIfReduced=false)
 
static ConstantgetBitCast (Constant *C, Type *Ty, bool OnlyIfReduced=false)
 
static ConstantgetAddrSpaceCast (Constant *C, Type *Ty, bool OnlyIfReduced=false)
 
static ConstantgetNSWNeg (Constant *C)
 
static ConstantgetNSWAdd (Constant *C1, Constant *C2)
 
static ConstantgetNUWAdd (Constant *C1, Constant *C2)
 
static ConstantgetNSWSub (Constant *C1, Constant *C2)
 
static ConstantgetNUWSub (Constant *C1, Constant *C2)
 
static ConstantgetNSWMul (Constant *C1, Constant *C2)
 
static ConstantgetNUWMul (Constant *C1, Constant *C2)
 
static ConstantgetNSWShl (Constant *C1, Constant *C2)
 
static ConstantgetNUWShl (Constant *C1, Constant *C2)
 
static ConstantgetExactLogBase2 (Constant *C)
 If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fixed width vector obtained from logBase2 of C.
 
static ConstantgetBinOpIdentity (unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
 Return the identity constant for a binary opcode.
 
static ConstantgetIntrinsicIdentity (Intrinsic::ID, Type *Ty)
 
static ConstantgetIdentity (Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
 Return the identity constant for a binary or intrinsic Instruction.
 
static ConstantgetBinOpAbsorber (unsigned Opcode, Type *Ty)
 Return the absorbing element for the given binary operation, i.e.
 
static ConstantgetCast (unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
 Convenience function for getting a Cast operation.
 
static ConstantgetTruncOrBitCast (Constant *C, Type *Ty)
 
static ConstantgetPointerCast (Constant *C, Type *Ty)
 Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
 
static ConstantgetPointerBitCastOrAddrSpaceCast (Constant *C, Type *Ty)
 Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
 
static Constantget (unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
 get - Return a binary or shift operator constant expression, folding if possible.
 
static ConstantgetGetElementPtr (Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
 Getelementptr form.
 
static ConstantgetGetElementPtr (Type *Ty, Constant *C, Constant *Idx, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
 
static ConstantgetGetElementPtr (Type *Ty, Constant *C, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
 
static ConstantgetInBoundsGetElementPtr (Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
 Create an "inbounds" getelementptr.
 
static ConstantgetInBoundsGetElementPtr (Type *Ty, Constant *C, Constant *Idx)
 
static ConstantgetInBoundsGetElementPtr (Type *Ty, Constant *C, ArrayRef< Value * > IdxList)
 
static ConstantgetExtractElement (Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
 
static ConstantgetInsertElement (Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
 
static ConstantgetShuffleVector (Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
 
static bool isDesirableBinOp (unsigned Opcode)
 Whether creating a constant expression for this binary operator is desirable.
 
static bool isSupportedBinOp (unsigned Opcode)
 Whether creating a constant expression for this binary operator is supported.
 
static bool isDesirableCastOp (unsigned Opcode)
 Whether creating a constant expression for this cast is desirable.
 
static bool isSupportedCastOp (unsigned Opcode)
 Whether creating a constant expression for this cast is supported.
 
static bool isSupportedGetElementPtr (const Type *SrcElemTy)
 Whether creating a constant expression for this getelementptr type is supported.
 
static bool classof (const Value *V)
 Methods for support type inquiry through isa, cast, and dyn_cast:
 
- Static Public Member Functions inherited from llvm::Constant
static bool classof (const Value *V)
 
static ConstantgetNullValue (Type *Ty)
 Constructor to create a '0' constant of arbitrary type.
 
static ConstantgetAllOnesValue (Type *Ty)
 
static ConstantgetIntegerValue (Type *Ty, const APInt &V)
 Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value.
 
static ConstantreplaceUndefsWith (Constant *C, Constant *Replacement)
 Try to replace undefined constant C or undefined elements in C with Replacement.
 
static ConstantmergeUndefsWith (Constant *C, Constant *Other)
 Merges undefs of a Constant with another Constant, along with the undefs already present.
 
- Static Public Member Functions inherited from llvm::User
static bool classof (const Value *V)
 
- Static Public Member Functions inherited from llvm::Value
static void dropDroppableUse (Use &U)
 Remove the droppable use U.
 

Protected Member Functions

 ConstantExpr (Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
 
 ~ConstantExpr ()=default
 
- Protected Member Functions inherited from llvm::Constant
 Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
 
 ~Constant ()=default
 
- Protected Member Functions inherited from llvm::User
void * operator new (size_t Size)
 Allocate a User with an operand pointer co-allocated.
 
void * operator new (size_t Size, unsigned Us)
 Allocate a User with the operands co-allocated.
 
void * operator new (size_t Size, unsigned Us, unsigned DescBytes)
 Allocate a User with the operands co-allocated.
 
 User (Type *ty, unsigned vty, Use *, unsigned NumOps)
 
void allocHungoffUses (unsigned N, bool IsPhi=false)
 Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
 
void growHungoffUses (unsigned N, bool IsPhi=false)
 Grow the number of hung off uses.
 
 ~User ()=default
 
template<int Idx>
UseOp ()
 
template<int Idx>
const UseOp () const
 
- Protected Member Functions inherited from llvm::Value
 Value (Type *Ty, unsigned scid)
 
 ~Value ()
 Value's destructor should be virtual by design, but that would require that Value and all of its subclasses have a vtable that effectively duplicates the information in the value ID.
 
void getAllMetadata (SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
 Appends all metadata attached to this value to MDs, sorting by KindID.
 
bool hasMetadata () const
 Return true if this value has any metadata attached to it.
 
bool eraseMetadata (unsigned KindID)
 Erase all metadata attachments with the given kind.
 
void eraseMetadataIf (function_ref< bool(unsigned, MDNode *)> Pred)
 Erase all metadata attachments matching the given predicate.
 
void clearMetadata ()
 Erase all metadata attached to this Value.
 
MDNodegetMetadataImpl (unsigned KindID) const
 Get metadata for the given kind, if any.
 
unsigned short getSubclassDataFromValue () const
 
void setValueSubclassData (unsigned short D)
 
MDNodegetMetadata (unsigned KindID) const
 Get the current metadata attachments for the given kind, if any.
 
MDNodegetMetadata (StringRef Kind) const
 
void getMetadata (unsigned KindID, SmallVectorImpl< MDNode * > &MDs) const
 Appends all attachments with the given ID to MDs in insertion order.
 
void getMetadata (StringRef Kind, SmallVectorImpl< MDNode * > &MDs) const
 
bool hasMetadata (unsigned KindID) const
 Return true if this value has the given type of metadata attached.
 
bool hasMetadata (StringRef Kind) const
 
void setMetadata (unsigned KindID, MDNode *Node)
 Set a particular kind of metadata attachment.
 
void setMetadata (StringRef Kind, MDNode *Node)
 
void addMetadata (unsigned KindID, MDNode &MD)
 Add a metadata attachment.
 
void addMetadata (StringRef Kind, MDNode &MD)
 

Friends

struct ConstantExprKeyType
 
class Constant
 

Additional Inherited Members

- Public Types inherited from llvm::User
using op_iterator = Use *
 
using const_op_iterator = const Use *
 
using op_range = iterator_range< op_iterator >
 
using const_op_range = iterator_range< const_op_iterator >
 
- Public Types inherited from llvm::Value
enum  ValueTy
 Concrete subclass of this. More...
 
using use_iterator = use_iterator_impl< Use >
 
using const_use_iterator = use_iterator_impl< const Use >
 
using user_iterator = user_iterator_impl< User >
 
using const_user_iterator = user_iterator_impl< const User >
 
- Static Public Attributes inherited from llvm::Value
static constexpr unsigned MaxAlignmentExponent = 32
 The maximum alignment for instructions.
 
static constexpr uint64_t MaximumAlignment = 1ULL << MaxAlignmentExponent
 
- Protected Types inherited from llvm::Value
enum  : unsigned { NumUserOperandsBits = 27 }
 The number of operands in the subclass. More...
 
- Static Protected Member Functions inherited from llvm::User
template<int Idx, typename U >
static UseOpFrom (const U *that)
 
- Protected Attributes inherited from llvm::Value
unsigned char SubclassOptionalData: 7
 Hold subclass data that can be dropped.
 
unsigned NumUserOperands: NumUserOperandsBits
 
unsigned IsUsedByMD: 1
 
unsigned HasName: 1
 
unsigned HasMetadata: 1
 
unsigned HasHungOffUses: 1
 
unsigned HasDescriptor: 1
 

Detailed Description

A constant value that is initialized with an expression using other constant values.

This class uses the standard Instruction opcodes to define the various constant expressions. The Opcode field for the ConstantExpr class is maintained in the Value::SubclassData field.

Definition at line 1084 of file Constants.h.

Constructor & Destructor Documentation

◆ ConstantExpr()

llvm::ConstantExpr::ConstantExpr ( Type ty,
unsigned  Opcode,
Use Ops,
unsigned  NumOps 
)
inlineprotected

Definition at line 1092 of file Constants.h.

◆ ~ConstantExpr()

llvm::ConstantExpr::~ConstantExpr ( )
protecteddefault

Member Function Documentation

◆ classof()

static bool llvm::ConstantExpr::classof ( const Value V)
inlinestatic

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

Definition at line 1367 of file Constants.h.

◆ DECLARE_TRANSPARENT_OPERAND_ACCESSORS()

llvm::ConstantExpr::DECLARE_TRANSPARENT_OPERAND_ACCESSORS ( Constant  )

Transparently provide more efficient getOperand methods.

◆ get()

Constant * ConstantExpr::get ( unsigned  Opcode,
Constant C1,
Constant C2,
unsigned  Flags = 0,
Type OnlyIfReducedTy = nullptr 
)
static

◆ getAdd()

Constant * ConstantExpr::getAdd ( Constant C1,
Constant C2,
bool  HasNUW = false,
bool  HasNSW = false 
)
static

◆ getAddrSpaceCast()

Constant * ConstantExpr::getAddrSpaceCast ( Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

◆ getAlignOf()

Constant * ConstantExpr::getAlignOf ( Type Ty)
static

getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the return type is an i64).

Definition at line 2420 of file Constants.cpp.

References GEP, llvm::StructType::get(), llvm::Type::getContext(), getGetElementPtr(), llvm::Type::getInt1Ty(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::Constant::getNullValue(), getPtrToInt(), and llvm::PointerType::getUnqual().

Referenced by LLVMAlignOf().

◆ getAsInstruction()

Instruction * ConstantExpr::getAsInstruction ( ) const

◆ getBinOpAbsorber()

Constant * ConstantExpr::getBinOpAbsorber ( unsigned  Opcode,
Type Ty 
)
static

Return the absorbing element for the given binary operation, i.e.

a constant C such that X op C = C and C op X = C for every X. For example, this returns zero for integer multiplication. It returns null if the operator doesn't have an absorbing element.

Definition at line 2699 of file Constants.cpp.

References llvm::Constant::getAllOnesValue(), and llvm::Constant::getNullValue().

Referenced by simplifyAndOrWithICmpEq(), and simplifyWithOpReplaced().

◆ getBinOpIdentity()

Constant * ConstantExpr::getBinOpIdentity ( unsigned  Opcode,
Type Ty,
bool  AllowRHSConstant = false,
bool  NSZ = false 
)
static

Return the identity constant for a binary opcode.

If the binop is not commutative, callers can acquire the operand 1 identity constant by setting AllowRHSConstant to true. For example, any shift has a zero identity constant for operand 1: X shift 0 = X. If this is a fadd/fsub operation and we don't care about signed zeros, then setting NSZ to true returns the identity +0.0 instead of -0.0. Return nullptr if the operator does not have an identity constant.

Definition at line 2628 of file Constants.cpp.

References assert(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::ConstantFP::getZero(), llvm::Instruction::isBinaryOp(), llvm::Instruction::isCommutative(), and llvm_unreachable.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::InstCombinerImpl::foldBinopWithPhiOperands(), foldDependentIVs(), foldSelectBinOpIdentity(), foldSelectICmpAndBinOp(), llvm::InstCombinerImpl::foldSelectIntoOp(), foldSelectShuffleWith1Binop(), llvm::InstCombinerImpl::foldUsingDistributiveLaws(), getIdentity(), getIdentityValue(), LinearizeExprTree(), simplifyAndOrWithICmpEq(), and simplifyWithOpReplaced().

◆ getBitCast()

Constant * ConstantExpr::getBitCast ( Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

◆ getCast()

Constant * ConstantExpr::getCast ( unsigned  ops,
Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

Convenience function for getting a Cast operation.

Parameters
opsThe opcode for the conversion
CThe constant to be converted
TyThe type to which the constant is converted
OnlyIfReducedsee getWithOperands() docs.

Definition at line 2146 of file Constants.cpp.

References assert(), llvm::CallingConv::C, llvm::CastInst::castIsValid(), getAddrSpaceCast(), getBitCast(), getIntToPtr(), getPtrToInt(), getTrunc(), llvm::Instruction::isCast(), isSupportedCastOp(), and llvm_unreachable.

Referenced by llvm::ConstantFoldCastOperand(), llvm::ConstantFolder::FoldCast(), foldMaybeUndesirableCast(), and getWithOperands().

◆ getExactLogBase2()

Constant * ConstantExpr::getExactLogBase2 ( Constant C)
static

If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fixed width vector obtained from logBase2 of C.

Undef vector elements are set to zero. Return a null pointer otherwise.

Definition at line 2599 of file Constants.cpp.

References llvm::CallingConv::C, llvm::ConstantVector::get(), llvm::Constant::getNullValue(), llvm::Type::getScalarType(), I, llvm::APInt::isPowerOf2(), llvm::APInt::logBase2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by detectShiftUntilBitTestIdiom(), takeLog2(), llvm::InstCombinerImpl::visitAnd(), llvm::InstCombinerImpl::visitMul(), and llvm::InstCombinerImpl::visitSDiv().

◆ getExtractElement()

Constant * ConstantExpr::getExtractElement ( Constant Vec,
Constant Idx,
Type OnlyIfReducedTy = nullptr 
)
static

◆ getGetElementPtr() [1/3]

static Constant * llvm::ConstantExpr::getGetElementPtr ( Type Ty,
Constant C,
ArrayRef< Constant * >  IdxList,
GEPNoWrapFlags  NW = GEPNoWrapFlags::none(),
std::optional< ConstantRange InRange = std::nullopt,
Type OnlyIfReducedTy = nullptr 
)
inlinestatic

Getelementptr form.

Value* is only accepted for convenience; all elements must be Constants.

Parameters
InRangethe inrange range if present or std::nullopt.
OnlyIfReducedTysee getWithOperands() docs.

Definition at line 1250 of file Constants.h.

References llvm::CallingConv::C, llvm::ArrayRef< T >::data(), InRange(), and llvm::ArrayRef< T >::size().

Referenced by BuildConstantFromSCEV(), llvm::SanitizerStatReport::create(), llvm::TargetFolder::FoldGEP(), llvm::ConstantFolder::FoldGEP(), getAlignOf(), getSizeOf(), getWithOperands(), LLVMConstGEP2(), OptimizeAwayTrappingUsesOfValue(), simplifyGEPInst(), and splitGlobal().

◆ getGetElementPtr() [2/3]

Constant * ConstantExpr::getGetElementPtr ( Type Ty,
Constant C,
ArrayRef< Value * >  IdxList,
GEPNoWrapFlags  NW = GEPNoWrapFlags::none(),
std::optional< ConstantRange InRange = std::nullopt,
Type OnlyIfReducedTy = nullptr 
)
static

◆ getGetElementPtr() [3/3]

static Constant * llvm::ConstantExpr::getGetElementPtr ( Type Ty,
Constant C,
Constant Idx,
GEPNoWrapFlags  NW = GEPNoWrapFlags::none(),
std::optional< ConstantRange InRange = std::nullopt,
Type OnlyIfReducedTy = nullptr 
)
inlinestatic

Definition at line 1259 of file Constants.h.

References llvm::CallingConv::C, Idx, and InRange().

◆ getIdentity()

Constant * ConstantExpr::getIdentity ( Instruction I,
Type Ty,
bool  AllowRHSConstant = false,
bool  NSZ = false 
)
static

Return the identity constant for a binary or intrinsic Instruction.

The identity constant C is defined as X op C = X and C op X = X where C and X are the first two operands, and the operation is commutative.

Definition at line 2690 of file Constants.cpp.

References getBinOpIdentity(), getIntrinsicIdentity(), I, and II.

◆ getInBoundsGetElementPtr() [1/3]

static Constant * llvm::ConstantExpr::getInBoundsGetElementPtr ( Type Ty,
Constant C,
ArrayRef< Constant * >  IdxList 
)
inlinestatic

Create an "inbounds" getelementptr.

See the documentation for the "inbounds" flag in LangRef.html for details.

Definition at line 1277 of file Constants.h.

References llvm::CallingConv::C, and llvm::GEPNoWrapFlags::inBounds().

Referenced by llvm::IRBuilderBase::CreateGlobalStringPtr(), and LLVMConstInBoundsGEP2().

◆ getInBoundsGetElementPtr() [2/3]

static Constant * llvm::ConstantExpr::getInBoundsGetElementPtr ( Type Ty,
Constant C,
ArrayRef< Value * >  IdxList 
)
inlinestatic

Definition at line 1288 of file Constants.h.

References llvm::CallingConv::C, and llvm::GEPNoWrapFlags::inBounds().

◆ getInBoundsGetElementPtr() [3/3]

static Constant * llvm::ConstantExpr::getInBoundsGetElementPtr ( Type Ty,
Constant C,
Constant Idx 
)
inlinestatic

Definition at line 1281 of file Constants.h.

References llvm::CallingConv::C, Idx, and llvm::GEPNoWrapFlags::inBounds().

◆ getInsertElement()

Constant * ConstantExpr::getInsertElement ( Constant Vec,
Constant Elt,
Constant Idx,
Type OnlyIfReducedTy = nullptr 
)
static

◆ getIntrinsicIdentity()

Constant * ConstantExpr::getIntrinsicIdentity ( Intrinsic::ID  ID,
Type Ty 
)
static

◆ getIntToPtr()

Constant * ConstantExpr::getIntToPtr ( Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

◆ getMul()

Constant * ConstantExpr::getMul ( Constant C1,
Constant C2,
bool  HasNUW = false,
bool  HasNSW = false 
)
static

◆ getNeg()

Constant * ConstantExpr::getNeg ( Constant C,
bool  HasNSW = false 
)
static

◆ getNot()

Constant * ConstantExpr::getNot ( Constant C)
static

◆ getNSWAdd()

static Constant * llvm::ConstantExpr::getNSWAdd ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1139 of file Constants.h.

Referenced by LLVMConstNSWAdd().

◆ getNSWMul()

static Constant * llvm::ConstantExpr::getNSWMul ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1155 of file Constants.h.

Referenced by LLVMConstNSWMul().

◆ getNSWNeg()

static Constant * llvm::ConstantExpr::getNSWNeg ( Constant C)
inlinestatic

Definition at line 1137 of file Constants.h.

References llvm::CallingConv::C.

Referenced by LLVMConstNSWNeg().

◆ getNSWShl()

static Constant * llvm::ConstantExpr::getNSWShl ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1163 of file Constants.h.

◆ getNSWSub()

static Constant * llvm::ConstantExpr::getNSWSub ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1147 of file Constants.h.

Referenced by LLVMConstNSWSub().

◆ getNUWAdd()

static Constant * llvm::ConstantExpr::getNUWAdd ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1143 of file Constants.h.

Referenced by LLVMConstNUWAdd().

◆ getNUWMul()

static Constant * llvm::ConstantExpr::getNUWMul ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1159 of file Constants.h.

Referenced by LLVMConstNUWMul().

◆ getNUWShl()

static Constant * llvm::ConstantExpr::getNUWShl ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1167 of file Constants.h.

◆ getNUWSub()

static Constant * llvm::ConstantExpr::getNUWSub ( Constant C1,
Constant C2 
)
inlinestatic

Definition at line 1151 of file Constants.h.

Referenced by LLVMConstNUWSub().

◆ getOpcode()

unsigned llvm::ConstantExpr::getOpcode ( ) const
inline

Return the opcode at the root of this constant expression.

Definition at line 1302 of file Constants.h.

Referenced by llvm::FunctionComparator::cmpConstants(), getAsInstruction(), getOpcodeName(), getWithOperands(), and isCast().

◆ getOpcodeName()

const char * ConstantExpr::getOpcodeName ( ) const

Return a string representation for an opcode.

Definition at line 2719 of file Constants.cpp.

References getOpcode(), and llvm::Instruction::getOpcodeName().

◆ getPointerBitCastOrAddrSpaceCast()

Constant * ConstantExpr::getPointerBitCastOrAddrSpaceCast ( Constant C,
Type Ty 
)
static

◆ getPointerCast()

Constant * ConstantExpr::getPointerCast ( Constant C,
Type Ty 
)
static

◆ getPtrToInt()

Constant * ConstantExpr::getPtrToInt ( Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

◆ getShl()

Constant * ConstantExpr::getShl ( Constant C1,
Constant C2,
bool  HasNUW = false,
bool  HasNSW = false 
)
static

◆ getShuffleMask()

ArrayRef< int > ConstantExpr::getShuffleMask ( ) const

Assert that this is a shufflevector and return the mask.

See class ShuffleVectorInst for a description of the mask representation.

Definition at line 1517 of file Constants.cpp.

Referenced by getAsInstruction(), and getWithOperands().

◆ getShuffleMaskForBitcode()

Constant * ConstantExpr::getShuffleMaskForBitcode ( ) const

Assert that this is a shufflevector and return the mask.

TODO: This is a temporary hack until we update the bitcode format for shufflevector.

Definition at line 1521 of file Constants.cpp.

◆ getShuffleVector()

Constant * ConstantExpr::getShuffleVector ( Constant V1,
Constant V2,
ArrayRef< int >  Mask,
Type OnlyIfReducedTy = nullptr 
)
static

◆ getSizeOf()

Constant * ConstantExpr::getSizeOf ( Type Ty)
static

getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a target independent way (Note: the return type is an i64).

Definition at line 2410 of file Constants.cpp.

References GEP, llvm::Type::getContext(), getGetElementPtr(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::Constant::getNullValue(), getPtrToInt(), and llvm::PointerType::getUnqual().

Referenced by llvm::IRBuilderBase::CreatePtrDiff(), LLVMBuildArrayMalloc(), LLVMBuildMalloc(), and LLVMSizeOf().

◆ getSub()

Constant * ConstantExpr::getSub ( Constant C1,
Constant C2,
bool  HasNUW = false,
bool  HasNSW = false 
)
static

◆ getTrunc()

Constant * ConstantExpr::getTrunc ( Constant C,
Type Ty,
bool  OnlyIfReduced = false 
)
static

◆ getTruncOrBitCast()

Constant * ConstantExpr::getTruncOrBitCast ( Constant C,
Type Ty 
)
static
Parameters
CThe constant to trunc or bitcast
TyThe type to trunc or bitcast C to

Definition at line 2171 of file Constants.cpp.

References llvm::CallingConv::C, getBitCast(), llvm::Type::getScalarSizeInBits(), and getTrunc().

Referenced by LLVMBuildArrayMalloc(), LLVMBuildMalloc(), and LLVMConstTruncOrBitCast().

◆ getWithOperands() [1/2]

Constant * llvm::ConstantExpr::getWithOperands ( ArrayRef< Constant * >  Ops) const
inline

This returns the current constant expression with the operands replaced with the specified values.

The specified array must have the same number of operands as our current one.

Definition at line 1320 of file Constants.h.

References getType().

◆ getWithOperands() [2/2]

Constant * ConstantExpr::getWithOperands ( ArrayRef< Constant * >  Ops,
Type Ty,
bool  OnlyIfReduced = false,
Type SrcTy = nullptr 
) const

Get the current expression with the operands replaced.

Return the current constant expression with the operands replaced with Ops and the type with Ty. The new operands must have the same number as the current ones.

If OnlyIfReduced is true, nullptr will be returned unless something gets constant-folded, the type changes, or the expression is otherwise canonicalized. This parameter should almost always be false.

Definition at line 1525 of file Constants.cpp.

References assert(), llvm::ArrayRef< T >::begin(), llvm::ArrayRef< T >::end(), get(), getCast(), getExtractElement(), getGetElementPtr(), getInsertElement(), llvm::User::getNumOperands(), getOpcode(), llvm::User::getOperand(), getShuffleMask(), getShuffleVector(), llvm::Value::getType(), llvm::User::op_begin(), llvm::ArrayRef< T >::size(), llvm::ArrayRef< T >::slice(), and llvm::Value::SubclassOptionalData.

◆ getXor()

Constant * ConstantExpr::getXor ( Constant C1,
Constant C2 
)
static

◆ isCast()

bool ConstantExpr::isCast ( ) const

Return true if this is a convert constant expression.

Definition at line 1515 of file Constants.cpp.

References getOpcode(), and llvm::Instruction::isCast().

◆ isDesirableBinOp()

bool ConstantExpr::isDesirableBinOp ( unsigned  Opcode)
static

◆ isDesirableCastOp()

bool ConstantExpr::isDesirableCastOp ( unsigned  Opcode)
static

Whether creating a constant expression for this cast is desirable.

Definition at line 2366 of file Constants.cpp.

References llvm_unreachable.

Referenced by llvm::ConstantFoldCastOperand(), llvm::ConstantFolder::FoldCast(), and foldMaybeUndesirableCast().

◆ isSupportedBinOp()

bool ConstantExpr::isSupportedBinOp ( unsigned  Opcode)
static

Whether creating a constant expression for this binary operator is supported.

Definition at line 2339 of file Constants.cpp.

References llvm_unreachable.

Referenced by get(), and isConstExprSupported().

◆ isSupportedCastOp()

bool ConstantExpr::isSupportedCastOp ( unsigned  Opcode)
static

Whether creating a constant expression for this cast is supported.

Definition at line 2388 of file Constants.cpp.

References llvm_unreachable.

Referenced by getCast(), and isConstExprSupported().

◆ isSupportedGetElementPtr()

static bool llvm::ConstantExpr::isSupportedGetElementPtr ( const Type SrcElemTy)
inlinestatic

Whether creating a constant expression for this getelementptr type is supported.

Definition at line 1362 of file Constants.h.

References llvm::Type::isScalableTy().

Referenced by llvm::TargetFolder::FoldGEP(), llvm::ConstantFolder::FoldGEP(), getGetElementPtr(), isConstExprSupported(), and simplifyGEPInst().

Friends And Related Function Documentation

◆ Constant

friend class Constant
friend

Definition at line 1086 of file Constants.h.

◆ ConstantExprKeyType

friend struct ConstantExprKeyType
friend

Definition at line 1085 of file Constants.h.


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