21 #ifndef LLVM_IR_CONSTANTS_H 22 #define LLVM_IR_CONSTANTS_H 68 void *
operator new(
size_t s) {
return User::operator
new(s, 0); }
75 return V->
getValueID() >= ConstantDataFirstVal &&
91 void destroyConstantImpl();
103 static Constant *
get(
Type *Ty, uint64_t V,
bool isSigned =
false);
112 bool isSigned =
false);
185 static bool isValueValidForType(
Type *Ty, uint64_t V);
186 static bool isValueValidForType(
Type *Ty, int64_t V);
242 bool uge(uint64_t Num)
const {
271 void destroyConstantImpl();
293 static Constant *getNaN(
Type *Ty,
bool Negative =
false, uint64_t Payload = 0);
294 static Constant *getQNaN(
Type *Ty,
bool Negative =
false,
295 APInt *Payload =
nullptr);
296 static Constant *getSNaN(
Type *Ty,
bool Negative =
false,
297 APInt *Payload =
nullptr);
299 static Constant *getInfinity(
Type *Ty,
bool Negative =
false);
302 static bool isValueValidForType(
Type *Ty,
const APFloat &V);
323 bool isExactlyValue(
const APFloat &V)
const;
329 return isExactlyValue(FV);
347 void destroyConstantImpl();
356 Constant *getSequentialElement()
const;
360 Constant *getStructElement(
unsigned Elt)
const;
367 Constant *getElementValue(
unsigned Idx)
const;
370 unsigned getNumElements()
const;
375 return V->
getValueID() == ConstantAggregateZeroVal;
400 return V->
getValueID() >= ConstantAggregateFirstVal &&
420 void destroyConstantImpl();
452 void destroyConstantImpl();
459 template <
typename... Csts>
464 return get(
T, Values);
470 return get(getTypeForElements(V, Packed), V);
474 return get(getTypeForElements(Ctx, V, Packed), V);
480 bool Packed =
false);
484 bool Packed =
false);
506 void destroyConstantImpl();
545 void destroyConstantImpl();
561 return V->
getValueID() == ConstantPointerNullVal;
580 const char *DataElements;
588 void destroyConstantImpl();
592 :
ConstantData(ty, VT), DataElements(Data), Next(nullptr) {}
604 static bool isElementTypeCompatible(
Type *Ty);
608 uint64_t getElementAsInteger(
unsigned i)
const;
612 APInt getElementAsAPInt(
unsigned i)
const;
616 APFloat getElementAsAPFloat(
unsigned i)
const;
620 float getElementAsFloat(
unsigned i)
const;
624 double getElementAsDouble(
unsigned i)
const;
629 Constant *getElementAsConstant(
unsigned i)
const;
638 Type *getElementType()
const;
641 unsigned getNumElements()
const;
645 uint64_t getElementByteSize()
const;
648 bool isString(
unsigned CharSize = 8)
const;
652 bool isCString()
const;
657 assert(isString() &&
"Not a string");
658 return getRawDataValues();
664 assert(isCString() &&
"Isn't a C string");
676 return V->
getValueID() == ConstantDataArrayVal ||
681 const char *getElementPointer(
unsigned Elt)
const;
702 template <
typename ElementTy>
704 const char *
Data =
reinterpret_cast<const char *
>(Elts.data());
705 return getRaw(
StringRef(Data, Elts.size() *
sizeof(ElementTy)), Elts.
size(),
706 Type::getScalarTy<ElementTy>(
Context));
711 template <
typename ArrayTy>
742 bool AddNull =
true);
752 return V->
getValueID() == ConstantDataArrayVal;
811 return V->
getValueID() == ConstantDataVectorVal;
824 void destroyConstantImpl();
834 return V->
getValueID() == ConstantTokenNoneVal;
845 void *
operator new(
size_t s) {
return User::operator
new(s, 2); }
847 void destroyConstantImpl();
893 void destroyConstantImpl();
898 :
Constant(ty, ConstantExprVal, Ops, NumOps) {
933 bool HasNUW =
false,
bool HasNSW =
false);
936 bool HasNUW =
false,
bool HasNSW =
false);
939 bool HasNUW =
false,
bool HasNSW =
false);
951 bool HasNUW =
false,
bool HasNSW =
false);
958 bool OnlyIfReduced =
false);
960 bool OnlyIfReduced =
false);
966 bool OnlyIfReduced =
false);
968 bool OnlyIfReduced =
false);
970 bool OnlyIfReduced =
false);
972 bool OnlyIfReduced =
false);
978 return getAdd(C1, C2,
false,
true);
982 return getAdd(C1, C2,
true,
false);
986 return getSub(C1, C2,
false,
true);
990 return getSub(C1, C2,
true,
false);
994 return getMul(C1, C2,
false,
true);
998 return getMul(C1, C2,
true,
false);
1002 return getShl(C1, C2,
false,
true);
1006 return getShl(C1, C2,
true,
false);
1010 return getSDiv(C1, C2,
true);
1014 return getUDiv(C1, C2,
true);
1018 return getAShr(C1, C2,
true);
1022 return getLShr(C1, C2,
true);
1032 static Constant *getBinOpIdentity(
unsigned Opcode,
Type *Ty,
1033 bool AllowRHSConstant =
false);
1039 static Constant *getBinOpAbsorber(
unsigned Opcode,
Type *Ty);
1051 bool OnlyIfReduced =
false);
1066 static Constant *getTruncOrBitCast(
1080 static Constant *getPointerBitCastOrAddrSpaceCast(
1099 bool isCast()
const;
1102 bool isCompare()
const;
1106 bool hasIndices()
const;
1113 bool isGEPWithNoNotionalOverIndexing()
const;
1119 Type *OnlyIfReducedTy =
nullptr);
1126 Type *OnlyIfReducedTy =
nullptr);
1133 unsigned Flags = 0,
Type *OnlyIfReducedTy =
nullptr);
1139 bool OnlyIfReduced =
false);
1145 bool OnlyIfReduced =
false);
1147 bool OnlyIfReduced =
false);
1156 bool InBounds =
false,
1158 Type *OnlyIfReducedTy =
nullptr) {
1159 return getGetElementPtr(
1161 InBounds, InRangeIndex, OnlyIfReducedTy);
1164 bool InBounds =
false,
1166 Type *OnlyIfReducedTy =
nullptr) {
1170 return getGetElementPtr(Ty, C, cast<Value>(Idx), InBounds, InRangeIndex,
1175 bool InBounds =
false,
1177 Type *OnlyIfReducedTy =
nullptr);
1183 return getGetElementPtr(Ty, C, IdxList,
true);
1190 return getGetElementPtr(Ty, C, Idx,
true);
1194 return getGetElementPtr(Ty, C, IdxList,
true);
1198 Type *OnlyIfReducedTy =
nullptr);
1200 Type *OnlyIfReducedTy =
nullptr);
1202 Type *OnlyIfReducedTy =
nullptr);
1204 Type *OnlyIfReducedTy =
nullptr);
1207 Type *OnlyIfReducedTy =
nullptr);
1221 const char *getOpcodeName()
const;
1231 return getWithOperands(Ops,
getType());
1244 bool OnlyIfReduced =
false,
1245 Type *SrcTy =
nullptr)
const;
1291 void destroyConstantImpl();
1305 UndefValue *getStructElement(
unsigned Elt)
const;
1312 UndefValue *getElementValue(
unsigned Idx)
const;
1315 unsigned getNumElements()
const;
1325 #endif // LLVM_IR_CONSTANTS_H A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
unsigned short getSubclassDataFromValue() const
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getValueID() const
Return an ID for the concrete type of this object.
This class represents lattice values for constants.
static Constant * getNSWAdd(Constant *C1, Constant *C2)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static Constant * getExactSDiv(Constant *C1, Constant *C2)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
StringRef getAsCString() const
If this array is isCString(), then this method returns the array (without the trailing null byte) as ...
static Constant * getNUWShl(Constant *C1, Constant *C2)
const fltSemantics & getSemantics() const
bool equalsInt(uint64_t V) const
A helper method that can be used to determine if the constant contained within is equal to a constant...
static Constant * getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy)
get() constructor - Return a constant with array type with an element count and element type matching...
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static Constant * getTrue(Type *Ty)
For a boolean type or a vector of boolean type, return true or a vector with every element true...
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Function * getFunction() const
The address of a basic block.
bool isExactlyValue(double V) const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
'undef' values are things that do not have specified contents.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static Constant * getNUWNeg(Constant *C)
bool uge(uint64_t Num) const
This function will return true iff this constant represents a value with active bits bigger than 64 b...
static Constant * getExactAShr(Constant *C1, Constant *C2)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
This file implements a class to represent arbitrary precision integral constant values and operations...
All zero aggregate value.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
A constant value that is initialized with an expression using other constant values.
int64_t getSExtValue() const
Get sign extended value.
Type * getType() const
All values are typed, get the type of this value.
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
static Constant * getGetElementPtr(Type *Ty, Constant *C, Constant *Idx, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
bool isNegative() const
Return true if the sign bit is set.
Class to represent array types.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const APInt & getValue() const
Return the constant as an APInt value reference.
BasicBlock * getBasicBlock() const
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static Constant * getNSWNeg(Constant *C)
Class to represent pointers.
VectorType * getType() const
Specialize the getType() method to always return a VectorType, which reduces the amount of casting ne...
bool isNegative() const
Determine sign of this APInt.
bool isAllOnesValue() const
Determine if all bits are set.
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
LLVM Basic Block Representation.
static Constant * getAnon(LLVMContext &Ctx, ArrayRef< Constant *> V, bool Packed=false)
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
A constant token which is empty.
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
ConstantFP - Floating Point Values [float, double].
bool isOneValue() const
Determine if this is a value of 1.
static Constant * getNSWShl(Constant *C1, Constant *C2)
bool isMinSignedValue() const
Determine if this is the smallest signed value.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isMaxValue(bool isSigned) const
This function will return true iff this constant represents the largest value that may be represented...
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Class to represent integer types.
Constant Vector Declarations.
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
Constant * getWithOperands(ArrayRef< Constant *> Ops) const
This returns the current constant expression with the operands replaced with the specified values...
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, Constant *Idx)
Constant * getSplatValue() const
If this is a splat vector constant, meaning that all of the elements have the same value...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const APFloat & getValueAPF() const
bool isMinValue(bool isSigned) const
This function will return true iff this constant represents the smallest value that may be represente...
This is the superclass of the array and vector type classes.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool isMaxSignedValue() const
Determine if this is the largest signed value.
This is the shared class of boolean and integer constants.
BlockVerifier::State From
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
A constant pointer value that points to null.
static Constant * getNUWMul(Constant *C1, Constant *C2)
bool isMaxValue() const
Determine if this is the largest unsigned value.
static Constant * getNSWSub(Constant *C1, Constant *C2)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
ValueTy
Concrete subclass of this.
void setValueSubclassData(unsigned short D)
Class to represent vector types.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
static Constant * getFalse(Type *Ty)
For a boolean type or a vector of boolean type, return false or a vector with every element false...
~ConstantDataSequential()
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Common super class of ArrayType, StructType and VectorType.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Value *> IdxList)
static Constant * getNSWMul(Constant *C1, Constant *C2)
SequentialType * getType() const
Specialize the getType() method to always return a SequentialType, which reduces the amount of castin...
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
bool isZero() const
Return true if the value is positive or negative zero.
VectorType * getType() const
Specialize the getType() method to always return a VectorType, which reduces the amount of casting ne...
bool isNaN() const
Return true if the value is a NaN.
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList)
Create an "inbounds" getelementptr.
static Constant * getExactLShr(Constant *C1, Constant *C2)
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool isInfinity() const
Return true if the value is infinity.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Compile-time customization of User operands.
bool isMinValue() const
Determine if this is the smallest unsigned value.
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for aggregate constants (with operands).
traits class for checking whether type T is a base class for all the given types in the variadic list...
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static Constant * getAnon(ArrayRef< Constant *> V, bool Packed=false)
Return an anonymous struct that has the specified elements.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
StringRef - Represent a constant reference to a string, i.e.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
static bool isSplat(ArrayRef< Value *> VL)
ConstantData(Type *Ty, ValueTy VT)
static Constant * getExactUDiv(Constant *C1, Constant *C2)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
static Constant * getNUWSub(Constant *C1, Constant *C2)
Base class for constants with no operands.
static Constant * getNUWAdd(Constant *C1, Constant *C2)
StructType * getType() const
Specialization - reduce amount of casting.
bool isNullValue() const
Determine if all bits are clear.