LLVM  mainline
llvm::Constant Class Reference

This is an important base class in LLVM. More...

#include <Constant.h>

Inheritance diagram for llvm::Constant:
[legend]
Collaboration diagram for llvm::Constant:
[legend]

List of all members.

## Public Member Functions

bool isNullValue () const
isNullValue - Return true if this is the value that would be returned by getNullValue.
bool isOneValue () const
Returns true if the value is one.
bool isAllOnesValue () const
isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.
bool isNegativeZeroValue () const
isNegativeZeroValue - 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.
bool isMinSignedValue () const
Return true if the value is the smallest signed value.
bool canTrap () const
canTrap - Return true if evaluation of this constant could trap.
bool isDLLImportDependent () const
Return true if the value is dependent on a dllimport variable.
bool isConstantUsed () const
isConstantUsed - Return true if the constant has users other than constant exprs and other dangling things.
bool needsRelocation () const
This method classifies the entry according to whether or not it may generate a relocation entry.
ConstantgetAggregateElement (unsigned Elt) const
getAggregateElement - 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 () const
getSplatValue - If this is a splat vector constant, meaning that all of the elements 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 *, Use *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does work on constants.
removeDeadConstantUsers - If there are any dead constant users dangling off of this constant, remove them.
ConstantstripPointerCasts ()
Strip off pointer casts, all-zero GEPs, and aliases.
const ConstantstripPointerCasts () const

## Static Public Member Functions

static bool classof (const Value *V)
static ConstantgetNullValue (Type *Ty)
static ConstantgetAllOnesValue (Type *Ty)
Get the all ones value.
static ConstantgetIntegerValue (Type *Ty, const APInt &V)
getIntegerValue - Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value.

## Protected Member Functions

Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)

## Detailed Description

This is an important base class in LLVM.

It provides the common facilities of all constant values in an LLVM program. A constant is a value that is immutable at runtime. Functions are constants because their address is immutable. Same with global variables.

All constants share the capabilities provided in this class. All constants can have a null value. They can have an operand list. Constants can be simple (integer and floating point values), complex (arrays and structures), or expression based (computations yielding a constant value composed of only certain operators and other constant values).

Note that Constants are immutable (once created they never change) and are fully shared by structural equivalence. This means that two structurally equivalent constants will always have the same address. Constants are created on demand as needed and never deleted: thus clients don't have to worry about the lifetime of the objects. LLVM Constant Representation

Definition at line 41 of file Constant.h.

## Constructor & Destructor Documentation

 llvm::Constant::Constant ( Type * ty, ValueTy vty, Use * Ops, unsigned NumOps )  [inline, protected]

Definition at line 47 of file Constant.h.

## Member Function Documentation

 bool Constant::canTrap ( ) const

canTrap - Return true if evaluation of this constant could trap.

This is true for things like constant expressions that could divide by zero.

Definition at line 374 of file Constants.cpp.

References canTrapImpl().

Referenced by SplitCriticalSideEffectEdges().

 static bool llvm::Constant::classof ( const Value * V )  [inline, static]
 void Constant::destroyConstant ( )

Called if some element of this constant is no longer valid.

At this point only other constants may be on the use_list for this constant. Any constants on our Use list must also be destroy'd. The implementation must be sure to remove the constant from the list of available cached constants. Implementations should implement destroyConstantImpl to remove constants from any pools/maps they are contained it.

First call destroyConstantImpl on the subclass. This gives the subclass a chance to remove the constant from any maps/pools it's contained in.

Definition at line 299 of file Constants.cpp.

 Constant * Constant::getAggregateElement ( unsigned Elt ) const

getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to the specified element if possible, or null if not.

This can return null if the element index is a ConstantExpr, or if 'this' is a constant expr.

Definition at line 270 of file Constants.cpp.

References llvm::CS.

 Constant * Constant::getAggregateElement ( Constant * Elt ) const

Definition at line 292 of file Constants.cpp.

References getAggregateElement(), and llvm::Value::getType().

 Constant * Constant::getAllOnesValue ( Type * Ty )  [static]

Get the all ones value.

Returns:
the value for an integer or vector of integer constant of the given type that has all its bits set to true.

Definition at line 250 of file Constants.cpp.

 Constant * Constant::getIntegerValue ( Type * Ty, const APInt & V )  [static]

getIntegerValue - Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value.

Definition at line 233 of file Constants.cpp.

Referenced by SimplifyX86extrq(), SimplifyX86insertq(), and llvm::InstCombiner::visitReturnInst().

 Constant * Constant::getSplatValue ( ) const

getSplatValue - If this is a splat vector constant, meaning that all of the elements have the same value, return that value.

Otherwise return 0.

Reimplemented in llvm::ConstantDataVector, and llvm::ConstantVector.

Definition at line 1353 of file Constants.cpp.

References getNullValue(), and llvm::Value::getType().

 const APInt & Constant::getUniqueInteger ( ) 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.

Definition at line 1378 of file Constants.cpp.

References C, getAggregateElement(), and getSplatValue().

 void Constant::handleOperandChange ( Value * From, Value * To, Use * U )

This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does work on constants.

Update this constant array to change uses of 'From' to be uses of 'To'.

Basically this method goes through the trouble of building a new constant that is equivalent to the current one, with all uses of From replaced with uses of To. After this construction is completed, all of the users of 'this' are replaced to use the new constant, and then 'this' is deleted. In general, you should not call this method, instead, use Value::replaceAllUsesWith, which automatically dispatches to this method as needed.

This must update the uniquing data structures etc.

Note that we intentionally replace all uses of From with To here. Consider a large array that uses 'From' 1000 times. By handling this case all here, ConstantArray::handleOperandChange is only invoked once, and that single invocation handles all 1000 uses. Handling them one at a time would work, but would be really slow because it would have to unique each updated array instance.

Definition at line 2790 of file Constants.cpp.

 bool Constant::isAllOnesValue ( ) const

isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.

Definition at line 106 of file Constants.cpp.

References getSplatValue().

 bool Constant::isConstantUsed ( ) const

isConstantUsed - Return true if the constant has users other than constant exprs and other dangling things.

Return true if the constant has users other than constant exprs and other dangling things.

Definition at line 421 of file Constants.cpp.

References llvm::dyn_cast(), isConstantUsed(), and llvm::Value::users().

Referenced by isConstantUsed().

 bool Constant::isDLLImportDependent ( ) const

Return true if the value is dependent on a dllimport variable.

Definition at line 412 of file Constants.cpp.

References ConstHasGlobalValuePredicate().

Referenced by ValidLookupTableConstant().

 bool Constant::isMinSignedValue ( ) const

Return true if the value is the smallest signed value.

Definition at line 150 of file Constants.cpp.

References getSplatValue().

Referenced by SimplifyICmpInst().

 bool Constant::isNegativeZeroValue ( ) const

isNegativeZeroValue - Return true if the value is what would be returned by getZeroValueForNegation.

Definition at line 45 of file Constants.cpp.

References llvm::Value::getType(), llvm::Type::isFPOrFPVectorTy(), and isNullValue().

 bool Constant::isNotMinSignedValue ( ) const

Return true if the value is not the smallest signed value.

Definition at line 172 of file Constants.cpp.

References getSplatValue().

Referenced by llvm::InstCombiner::visitMul(), and llvm::InstCombiner::visitSub().

 bool Constant::isNullValue ( ) const
 bool Constant::isOneValue ( ) const

Returns true if the value is one.

Definition at line 128 of file Constants.cpp.

References getSplatValue().

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

Return true if the value can vary between threads.

Definition at line 405 of file Constants.cpp.

References ConstHasGlobalValuePredicate().

Referenced by ValidLookupTableConstant().

 bool Constant::isZeroValue ( ) const

Return true if the value is negative zero or null value.

Definition at line 71 of file Constants.cpp.

References isNullValue().

Referenced by computeKnownBitsFromOperator(), isZero(), and shouldConvert().

 bool Constant::needsRelocation ( ) const

This method classifies the entry according to whether or not it may generate a relocation entry.

This must be conservative, so if it might codegen to a relocatable entry, it should say so.

FIXME: This really should not be in IR.

Definition at line 433 of file Constants.cpp.

Referenced by llvm::TargetLoweringObjectFile::getKindForGlobal().

removeDeadConstantUsers - If there are any dead constant users dangling off of this constant, remove them.

This method is useful for clients that want to check to see if a global is unused, but don't want to deal with potentially dead constants hanging off of the globals.

Definition at line 486 of file Constants.cpp.

 Constant* llvm::Constant::stripPointerCasts ( )  [inline]

Strip off pointer casts, all-zero GEPs, and aliases.

Returns the original uncasted value. If this is called on a non-pointer value, it returns 'this'.

Reimplemented from llvm::Value.

Definition at line 155 of file Constant.h.

 const Constant* llvm::Constant::stripPointerCasts ( ) const [inline]

Reimplemented from llvm::Value.

Definition at line 159 of file Constant.h.

References stripPointerCasts().

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