21 #ifndef LLVM_IR_CONSTANTS_H
22 #define LLVM_IR_CONSTANTS_H
40 template<
class ConstantClass,
class TypeClass,
class ValType>
42 template<
class ConstantClass,
class TypeClass>
44 template<
class ConstantClass,
class TypeClass>
52 virtual void anchor();
59 void *
operator new(
size_t s) {
60 return User::operator
new(s, 0);
70 static Constant *
get(
Type *Ty, uint64_t V,
bool isSigned =
false);
79 bool isSigned =
false);
209 bool uge(uint64_t Num)
const {
234 virtual void anchor();
242 void *
operator new(
size_t s) {
243 return User::operator
new(s, 0);
305 void *
operator new(
size_t s) {
306 return User::operator
new(s, 0);
386 static Constant *get(
StructType *T, ...) END_WITH_NULL;
392 return get(getTypeForElements(V, Packed), V);
396 return get(getTypeForElements(Ctx, V, Packed), V);
402 bool Packed =
false);
406 bool Packed =
false);
417 virtual void destroyConstant();
418 virtual void replaceUsesOfWithOnConstant(
Value *From,
Value *To,
Use *U);
444 static Constant *get(
ArrayRef<Constant*> V);
448 static Constant *getSplat(
unsigned NumElts, Constant *Elt);
462 Constant *getSplatValue()
const;
464 virtual void destroyConstant();
465 virtual void replaceUsesOfWithOnConstant(
Value *From,
Value *To,
Use *U);
489 Value::ConstantPointerNullVal, 0, 0) {}
493 void *
operator new(
size_t s) {
494 return User::operator
new(s, 0);
500 virtual void destroyConstant();
511 return V->
getValueID() == ConstantPointerNullVal;
528 const char *DataElements;
539 :
Constant(ty, VT, 0, 0), DataElements(Data), Next(0) {}
546 void *
operator new(
size_t s) {
547 return User::operator
new(s, 0);
608 assert(
isString() &&
"Not a string");
617 assert(
isCString() &&
"Isn't a C string");
636 const char *getElementPointer(
unsigned Elt)
const;
648 virtual void anchor();
654 void *
operator new(
size_t s) {
655 return User::operator
new(s, 0);
675 bool AddNull =
true);
700 virtual void anchor();
706 void *
operator new(
size_t s) {
707 return User::operator
new(s, 0);
750 void *
operator new(
size_t s) {
return User::operator
new(s, 2); }
792 std::pair<unsigned, std::vector<Constant*> > >;
796 ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
797 : Constant(ty, ConstantExprVal, Ops, NumOps) {
799 setValueSubclassData(Opcode);
810 static Constant *getAlignOf(Type *Ty);
816 static Constant *getSizeOf(Type *Ty);
821 static Constant *getOffsetOf(
StructType *STy,
unsigned FieldNo);
826 static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
828 static Constant *getNeg(Constant *
C,
bool HasNUW =
false,
bool HasNSW =
false);
829 static Constant *getFNeg(Constant *
C);
830 static Constant *getNot(Constant *
C);
831 static Constant *getAdd(Constant *C1, Constant *C2,
832 bool HasNUW =
false,
bool HasNSW =
false);
833 static Constant *getFAdd(Constant *C1, Constant *C2);
834 static Constant *getSub(Constant *C1, Constant *C2,
835 bool HasNUW =
false,
bool HasNSW =
false);
836 static Constant *getFSub(Constant *C1, Constant *C2);
837 static Constant *getMul(Constant *C1, Constant *C2,
838 bool HasNUW =
false,
bool HasNSW =
false);
839 static Constant *getFMul(Constant *C1, Constant *C2);
840 static Constant *getUDiv(Constant *C1, Constant *C2,
bool isExact =
false);
841 static Constant *getSDiv(Constant *C1, Constant *C2,
bool isExact =
false);
842 static Constant *getFDiv(Constant *C1, Constant *C2);
843 static Constant *getURem(Constant *C1, Constant *C2);
844 static Constant *getSRem(Constant *C1, Constant *C2);
845 static Constant *getFRem(Constant *C1, Constant *C2);
846 static Constant *getAnd(Constant *C1, Constant *C2);
847 static Constant *getOr(Constant *C1, Constant *C2);
848 static Constant *getXor(Constant *C1, Constant *C2);
849 static Constant *getShl(Constant *C1, Constant *C2,
850 bool HasNUW =
false,
bool HasNSW =
false);
851 static Constant *getLShr(Constant *C1, Constant *C2,
bool isExact =
false);
852 static Constant *getAShr(Constant *C1, Constant *C2,
bool isExact =
false);
853 static Constant *getTrunc (Constant *
C, Type *Ty);
854 static Constant *getSExt (Constant *
C, Type *Ty);
855 static Constant *getZExt (Constant *
C, Type *Ty);
856 static Constant *getFPTrunc (Constant *
C, Type *Ty);
857 static Constant *getFPExtend(Constant *
C, Type *Ty);
858 static Constant *getUIToFP (Constant *
C, Type *Ty);
859 static Constant *getSIToFP (Constant *
C, Type *Ty);
860 static Constant *getFPToUI (Constant *
C, Type *Ty);
861 static Constant *getFPToSI (Constant *
C, Type *Ty);
862 static Constant *getPtrToInt(Constant *
C, Type *Ty);
863 static Constant *getIntToPtr(Constant *
C, Type *Ty);
864 static Constant *getBitCast (Constant *
C, Type *Ty);
865 static Constant *getAddrSpaceCast(Constant *
C, Type *Ty);
867 static Constant *
getNSWNeg(Constant *
C) {
return getNeg(C,
false,
true); }
868 static Constant *
getNUWNeg(Constant *
C) {
return getNeg(C,
true,
false); }
869 static Constant *
getNSWAdd(Constant *C1, Constant *C2) {
870 return getAdd(C1, C2,
false,
true);
872 static Constant *
getNUWAdd(Constant *C1, Constant *C2) {
873 return getAdd(C1, C2,
true,
false);
875 static Constant *
getNSWSub(Constant *C1, Constant *C2) {
876 return getSub(C1, C2,
false,
true);
878 static Constant *
getNUWSub(Constant *C1, Constant *C2) {
879 return getSub(C1, C2,
true,
false);
881 static Constant *
getNSWMul(Constant *C1, Constant *C2) {
882 return getMul(C1, C2,
false,
true);
884 static Constant *
getNUWMul(Constant *C1, Constant *C2) {
885 return getMul(C1, C2,
true,
false);
887 static Constant *
getNSWShl(Constant *C1, Constant *C2) {
888 return getShl(C1, C2,
false,
true);
890 static Constant *
getNUWShl(Constant *C1, Constant *C2) {
891 return getShl(C1, C2,
true,
false);
894 return getSDiv(C1, C2,
true);
897 return getUDiv(C1, C2,
true);
900 return getAShr(C1, C2,
true);
903 return getLShr(C1, C2,
true);
909 static Constant *getBinOpIdentity(
unsigned Opcode, Type *Ty);
915 static Constant *getBinOpAbsorber(
unsigned Opcode, Type *Ty);
922 static Constant *getCast(
929 static Constant *getZExtOrBitCast(
935 static Constant *getSExtOrBitCast(
941 static Constant *getTruncOrBitCast(
947 static Constant *getPointerCast(
953 static Constant *getIntegerCast(
960 static Constant *getFPCast(
969 bool isCompare()
const;
973 bool hasIndices()
const;
980 bool isGEPWithNoNotionalOverIndexing()
const;
984 static Constant *getSelect(Constant *
C, Constant *V1, Constant *
V2);
989 static Constant *
get(
unsigned Opcode, Constant *C1, Constant *C2,
993 static Constant *getCompare(
unsigned short pred, Constant *C1, Constant *C2);
998 static Constant *getICmp(
unsigned short pred, Constant *LHS, Constant *RHS);
999 static Constant *getFCmp(
unsigned short pred, Constant *LHS, Constant *RHS);
1006 bool InBounds =
false) {
1013 bool InBounds =
false) {
1017 return getGetElementPtr(C, cast<Value>(Idx), InBounds);
1019 static Constant *getGetElementPtr(Constant *
C,
1021 bool InBounds =
false);
1027 return getGetElementPtr(C, IdxList,
true);
1034 return getGetElementPtr(C, Idx,
true);
1038 return getGetElementPtr(C, IdxList,
true);
1041 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
1042 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
1043 static Constant *getShuffleVector(Constant *V1, Constant *
V2, Constant *Mask);
1045 static Constant *getInsertValue(Constant *Agg, Constant *Val,
1049 unsigned getOpcode()
const {
return getSubclassDataFromValue(); }
1053 unsigned getPredicate()
const;
1060 const char *getOpcodeName()
const;
1064 Constant *getWithOperandReplaced(
unsigned OpNo, Constant *Op)
const;
1070 return getWithOperands(Ops,
getType());
1088 virtual void destroyConstant();
1089 virtual void replaceUsesOfWithOnConstant(
Value *From,
Value *To,
Use *U);
1099 void setValueSubclassData(
unsigned short D) {
1128 void *
operator new(
size_t s) {
1129 return User::operator
new(s, 0);
1143 UndefValue *getStructElement(
unsigned Elt)
const;
1151 UndefValue *getElementValue(
unsigned Idx)
const;
1153 virtual void destroyConstant();
static bool isValueValidForType(Type *Ty, uint64_t V)
Determine if the value is in range for the given type.
static ConstantInt * getFalse(LLVMContext &Context)
IntegerType * getType() const
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
APFloat getElementAsAPFloat(unsigned i) const
uint64_t getZExtValue() const
Get zero extended value.
VectorType * getType() const
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
size_t size() const
size - Get the string size.
static Constant * getNSWAdd(Constant *C1, Constant *C2)
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
Constant * getElementAsConstant(unsigned i) const
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Constant * getSplatValue() const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
StringRef substr(size_t Start, size_t N=npos) const
static Constant * getNUWShl(Constant *C1, Constant *C2)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
bool isMinusOne() const
Determine if the value is all ones.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool isMinValue(bool isSigned) const
Determine if the value is minimal.
ArrayType * getType() const
bool isNegative() const
Determine sign of this APInt.
bool uge(uint64_t Num) const
Determine if the value is greater or equal to the given number.
StringRef getAsCString() const
const APInt & getValue() const
Return the constant's value.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Constant * getSequentialElement() const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static Constant * getNUWNeg(Constant *C)
static Constant * getExactAShr(Constant *C1, Constant *C2)
double getElementAsDouble(unsigned i) const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
ConstantAggregateZero(Type *ty)
static bool classof(const Value *V)
This file implements a class to represent arbitrary precision integral constant values and operations...
uint64_t getZExtValue() const
Return the zero extended value.
ConstantPointerNull(PointerType *T)
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
static Constant * getInBoundsGetElementPtr(Constant *C, Constant *Idx)
static bool classof(const Value *V)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
Get the constant's value with a saturation limit.
static bool classof(const Value *V)
unsigned getActiveBits() const
Compute the number of active bits in the value.
SequentialType * getType() const
bool isExactlyValue(double V) const
bool isZero() const
isZero - Return true if the value is positive or negative zero.
static Constant * getNSWNeg(Constant *C)
size_t size() const
size - Get the array size.
virtual void destroyConstant()
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool isNaN() const
isNaN - Return true if the value is a NaN.
static Constant * getImpl(StringRef Bytes, Type *Ty)
LLVM Basic Block Representation.
bool isMaxValue(bool isSigned) const
Determine if the value is maximal.
LLVM Constant Representation.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
uint64_t getElementByteSize() const
getElementByteSize - Return the size in bytes of the elements in the data.
int64_t getSExtValue() const
Get sign extended value.
StringRef getAsString() const
StringRef getRawDataValues() const
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getNSWShl(Constant *C1, Constant *C2)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getValueID() const
opStatus convert(const fltSemantics &, roundingMode, bool *)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool isMaxValue() const
Determine if this is the largest unsigned value.
static bool isValueValidForType(Type *Ty, const APFloat &V)
isValueValidForType - return true if Ty is big enough to represent V.
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Integer representation type.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
uint64_t getElementAsInteger(unsigned i) const
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
virtual void destroyConstant()
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayType * getType() const
Class for constant integers.
static Constant * getNUWMul(Constant *C1, Constant *C2)
BasicBlock * getBasicBlock() const
static Constant * getNSWSub(Constant *C1, Constant *C2)
bool equalsInt(uint64_t V) const
Determine if this constant's value is same as an unsigned char.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Get a ConstantInt for a specific signed value.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static ConstantInt * getTrue(LLVMContext &Context)
void setValueSubclassData(unsigned short D)
#define LLVM_DELETED_FUNCTION
Class for arbitrary precision integers.
static ConstantFP * getNegativeZero(Type *Ty)
static Constant * getAnon(LLVMContext &Ctx, ArrayRef< Constant * > V, bool Packed=false)
StructType * getType() const
~ConstantDataSequential()
static bool isElementTypeCompatible(const Type *Ty)
bool isMinValue() const
Determine if this is the smallest unsigned value.
bool isAllOnesValue() const
Determine if all bits are set.
bool isNegative() const
isNegative - Return true if the sign bit is set.
Constant * getElementValue(Constant *C) const
static Constant * getNSWMul(Constant *C1, Constant *C2)
static Constant * getInBoundsGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList)
bool isMinSignedValue() const
Determine if this is the smallest signed value.
float getElementAsFloat(unsigned i) const
static Constant * getExactLShr(Constant *C1, Constant *C2)
static Constant * getZeroValueForNegation(Type *Ty)
unsigned getNumElements() const
getNumElements - Return the number of elements in the array or vector.
bool isString() const
isString - This method returns true if this is an array of i8.
PointerType * getType() const
virtual void destroyConstant()
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U)
const APFloat & getValueAPF() const
bool isExactlyValue(const APFloat &V) const
Type * getElementType() const
getElementType - Return the element type of the array/vector.
virtual void destroyConstant()
Function * getFunction() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
LLVM Value Representation.
bool isZero() const
Returns true if and only if the float is plus or minus zero.
Constant * getStructElement(unsigned Elt) const
static Constant * getGetElementPtr(Constant *C, Constant *Idx, bool InBounds=false)
static Constant * getExactUDiv(Constant *C1, Constant *C2)
static bool classof(const Value *V)
static Constant * getNUWSub(Constant *C1, Constant *C2)
static Constant * getInBoundsGetElementPtr(Constant *C, ArrayRef< Value * > IdxList)
int64_t getSExtValue() const
Return the sign extended value.
static Constant * getNUWAdd(Constant *C1, Constant *C2)
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
const fltSemantics & getSemantics() const
bool isOne() const
Determine if the value is one.
static ConstantFP * getInfinity(Type *Ty, bool Negative=false)