summaryrefslogtreecommitdiff
path: root/include/llvm/IR/Constants.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/IR/Constants.h')
-rw-r--r--include/llvm/IR/Constants.h473
1 files changed, 210 insertions, 263 deletions
diff --git a/include/llvm/IR/Constants.h b/include/llvm/IR/Constants.h
index a5a20c9c5701c..2a5d14d946467 100644
--- a/include/llvm/IR/Constants.h
+++ b/include/llvm/IR/Constants.h
@@ -40,26 +40,47 @@ class SequentialType;
struct ConstantExprKeyType;
template <class ConstantClass> struct ConstantAggrKeyType;
+/// Base class for constants with no operands.
+///
+/// These constants have no operands; they represent their data directly.
+/// Since they can be in use by unrelated modules (and are never based on
+/// GlobalValues), it never makes sense to RAUW them.
+class ConstantData : public Constant {
+ void anchor() override;
+ void *operator new(size_t, unsigned) = delete;
+ ConstantData() = delete;
+ ConstantData(const ConstantData &) = delete;
+
+ friend class Constant;
+ Value *handleOperandChangeImpl(Value *From, Value *To) {
+ llvm_unreachable("Constant data does not have operands!");
+ }
+
+protected:
+ explicit ConstantData(Type *Ty, ValueTy VT) : Constant(Ty, VT, nullptr, 0) {}
+ void *operator new(size_t s) { return User::operator new(s, 0); }
+
+public:
+ /// Methods to support type inquiry through isa, cast, and dyn_cast.
+ static bool classof(const Value *V) {
+ return V->getValueID() >= ConstantDataFirstVal &&
+ V->getValueID() <= ConstantDataLastVal;
+ }
+};
+
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
/// represents both boolean and integral constants.
/// @brief Class for constant integers.
-class ConstantInt : public Constant {
+class ConstantInt final : public ConstantData {
void anchor() override;
- void *operator new(size_t, unsigned) = delete;
ConstantInt(const ConstantInt &) = delete;
ConstantInt(IntegerType *Ty, const APInt& V);
APInt Val;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
- // allocate space for exactly zero operands
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
public:
static ConstantInt *getTrue(LLVMContext &Context);
static ConstantInt *getFalse(LLVMContext &Context);
@@ -230,34 +251,26 @@ public:
//===----------------------------------------------------------------------===//
/// ConstantFP - Floating Point Values [float, double]
///
-class ConstantFP : public Constant {
+class ConstantFP final : public ConstantData {
APFloat Val;
void anchor() override;
- void *operator new(size_t, unsigned) = delete;
ConstantFP(const ConstantFP &) = delete;
- friend class LLVMContextImpl;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
ConstantFP(Type *Ty, const APFloat& V);
-protected:
- // allocate space for exactly zero operands
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
+
public:
/// Floating point negation must be implemented with f(x) = -0.0 - x. This
/// method returns the negative zero constant for floating point or vector
/// floating point types; for all other types, it returns the null value.
static Constant *getZeroValueForNegation(Type *Ty);
- /// get() - This returns a ConstantFP, or a vector containing a splat of a
- /// ConstantFP, for the specified value in the specified type. This should
- /// only be used for simple constant values like 2.0/1.0 etc, that are
- /// known-valid both as host double and as the target format.
+ /// This returns a ConstantFP, or a vector containing a splat of a ConstantFP,
+ /// for the specified value in the specified type. This should only be used
+ /// for simple constant values like 2.0/1.0 etc, that are known-valid both as
+ /// host double and as the target format.
static Constant *get(Type* Ty, double V);
static Constant *get(Type* Ty, StringRef Str);
static ConstantFP *get(LLVMContext &Context, const APFloat &V);
@@ -265,24 +278,24 @@ public:
static Constant *getNegativeZero(Type *Ty);
static Constant *getInfinity(Type *Ty, bool Negative = false);
- /// isValueValidForType - return true if Ty is big enough to represent V.
+ /// Return true if Ty is big enough to represent V.
static bool isValueValidForType(Type *Ty, const APFloat &V);
inline const APFloat &getValueAPF() const { return Val; }
- /// isZero - Return true if the value is positive or negative zero.
+ /// Return true if the value is positive or negative zero.
bool isZero() const { return Val.isZero(); }
- /// isNegative - Return true if the sign bit is set.
+ /// Return true if the sign bit is set.
bool isNegative() const { return Val.isNegative(); }
- /// isInfinity - Return true if the value is infinity
+ /// Return true if the value is infinity
bool isInfinity() const { return Val.isInfinity(); }
- /// isNaN - Return true if the value is a NaN.
+ /// Return true if the value is a NaN.
bool isNaN() const { return Val.isNaN(); }
- /// isExactlyValue - We don't rely on operator== working on double values, as
- /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
+ /// We don't rely on operator== working on double values, as it returns true
+ /// for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values. The version with a double operand is retained
/// because it's so convenient to write isExactlyValue(2.0), but please use
@@ -302,44 +315,36 @@ public:
};
//===----------------------------------------------------------------------===//
-/// ConstantAggregateZero - All zero aggregate value
+/// All zero aggregate value
///
-class ConstantAggregateZero : public Constant {
- void *operator new(size_t, unsigned) = delete;
+class ConstantAggregateZero final : public ConstantData {
ConstantAggregateZero(const ConstantAggregateZero &) = delete;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
- explicit ConstantAggregateZero(Type *ty)
- : Constant(ty, ConstantAggregateZeroVal, nullptr, 0) {}
-protected:
- // allocate space for exactly zero operands
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
+ explicit ConstantAggregateZero(Type *Ty)
+ : ConstantData(Ty, ConstantAggregateZeroVal) {}
+
public:
static ConstantAggregateZero *get(Type *Ty);
- /// getSequentialElement - If this CAZ has array or vector type, return a zero
- /// with the right element type.
+ /// If this CAZ has array or vector type, return a zero with the right element
+ /// type.
Constant *getSequentialElement() const;
- /// getStructElement - If this CAZ has struct type, return a zero with the
- /// right element type for the specified element.
+ /// If this CAZ has struct type, return a zero with the right element type for
+ /// the specified element.
Constant *getStructElement(unsigned Elt) const;
- /// getElementValue - Return a zero of the right value for the specified GEP
- /// index.
+ /// Return a zero of the right value for the specified GEP index if we can,
+ /// otherwise return null (e.g. if C is a ConstantExpr).
Constant *getElementValue(Constant *C) const;
- /// getElementValue - Return a zero of the right value for the specified GEP
- /// index.
+ /// Return a zero of the right value for the specified GEP index.
Constant *getElementValue(unsigned Idx) const;
- /// \brief Return the number of elements in the array, vector, or struct.
+ /// Return the number of elements in the array, vector, or struct.
unsigned getNumElements() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -349,20 +354,49 @@ public:
}
};
+/// Base class for aggregate constants (with operands).
+///
+/// These constants are aggregates of other constants, which are stored as
+/// operands.
+///
+/// Subclasses are \a ConstantStruct, \a ConstantArray, and \a
+/// ConstantVector.
+///
+/// \note Some subclasses of \a ConstantData are semantically aggregates --
+/// such as \a ConstantDataArray -- but are not subclasses of this because they
+/// use operands.
+class ConstantAggregate : public Constant {
+protected:
+ ConstantAggregate(CompositeType *T, ValueTy VT, ArrayRef<Constant *> V);
+
+public:
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ static bool classof(const Value *V) {
+ return V->getValueID() >= ConstantAggregateFirstVal &&
+ V->getValueID() <= ConstantAggregateLastVal;
+ }
+};
+
+template <>
+struct OperandTraits<ConstantAggregate>
+ : public VariadicOperandTraits<ConstantAggregate> {};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantAggregate, Constant)
//===----------------------------------------------------------------------===//
/// ConstantArray - Constant Array Declarations
///
-class ConstantArray : public Constant {
+class ConstantArray final : public ConstantAggregate {
friend struct ConstantAggrKeyType<ConstantArray>;
- ConstantArray(const ConstantArray &) = delete;
-
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
+ Value *handleOperandChangeImpl(Value *From, Value *To);
-protected:
ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
+
public:
// ConstantArray accessors
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
@@ -371,12 +405,8 @@ private:
static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
public:
- /// Transparently provide more efficient getOperand methods.
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
-
- /// getType - Specialize the getType() method to always return an ArrayType,
+ /// Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
- ///
inline ArrayType *getType() const {
return cast<ArrayType>(Value::getType());
}
@@ -387,34 +417,24 @@ public:
}
};
-template <>
-struct OperandTraits<ConstantArray> :
- public VariadicOperandTraits<ConstantArray> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
-
//===----------------------------------------------------------------------===//
-// ConstantStruct - Constant Struct Declarations
+// Constant Struct Declarations
//
-class ConstantStruct : public Constant {
+class ConstantStruct final : public ConstantAggregate {
friend struct ConstantAggrKeyType<ConstantStruct>;
- ConstantStruct(const ConstantStruct &) = delete;
-
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
+ Value *handleOperandChangeImpl(Value *From, Value *To);
-protected:
ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
+
public:
// ConstantStruct accessors
static Constant *get(StructType *T, ArrayRef<Constant*> V);
static Constant *get(StructType *T, ...) LLVM_END_WITH_NULL;
- /// getAnon - Return an anonymous struct that has the specified
- /// elements. If the struct is possibly empty, then you must specify a
- /// context.
+ /// Return an anonymous struct that has the specified elements.
+ /// If the struct is possibly empty, then you must specify a context.
static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
return get(getTypeForElements(V, Packed), V);
}
@@ -423,20 +443,16 @@ public:
return get(getTypeForElements(Ctx, V, Packed), V);
}
- /// getTypeForElements - Return an anonymous struct type to use for a constant
- /// with the specified set of elements. The list must not be empty.
+ /// Return an anonymous struct type to use for a constant with the specified
+ /// set of elements. The list must not be empty.
static StructType *getTypeForElements(ArrayRef<Constant*> V,
bool Packed = false);
- /// getTypeForElements - This version of the method allows an empty list.
+ /// This version of the method allows an empty list.
static StructType *getTypeForElements(LLVMContext &Ctx,
ArrayRef<Constant*> V,
bool Packed = false);
- /// Transparently provide more efficient getOperand methods.
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
-
- /// getType() specialization - Reduce amount of casting...
- ///
+ /// Specialization - reduce amount of casting.
inline StructType *getType() const {
return cast<StructType>(Value::getType());
}
@@ -447,27 +463,18 @@ public:
}
};
-template <>
-struct OperandTraits<ConstantStruct> :
- public VariadicOperandTraits<ConstantStruct> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
-
//===----------------------------------------------------------------------===//
-/// ConstantVector - Constant Vector Declarations
+/// Constant Vector Declarations
///
-class ConstantVector : public Constant {
+class ConstantVector final : public ConstantAggregate {
friend struct ConstantAggrKeyType<ConstantVector>;
- ConstantVector(const ConstantVector &) = delete;
-
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
+ Value *handleOperandChangeImpl(Value *From, Value *To);
-protected:
ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
+
public:
// ConstantVector accessors
static Constant *get(ArrayRef<Constant*> V);
@@ -476,22 +483,17 @@ private:
static Constant *getImpl(ArrayRef<Constant *> V);
public:
- /// getSplat - Return a ConstantVector with the specified constant in each
- /// element.
+ /// Return a ConstantVector with the specified constant in each element.
static Constant *getSplat(unsigned NumElts, Constant *Elt);
- /// Transparently provide more efficient getOperand methods.
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
-
- /// getType - Specialize the getType() method to always return a VectorType,
+ /// Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
- ///
inline VectorType *getType() const {
return cast<VectorType>(Value::getType());
}
- /// getSplatValue - If this is a splat constant, meaning that all of the
- /// elements have the same value, return that value. Otherwise return NULL.
+ /// If this is a splat constant, meaning that all of the elements have the
+ /// same value, return that value. Otherwise return NULL.
Constant *getSplatValue() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -500,41 +502,24 @@ public:
}
};
-template <>
-struct OperandTraits<ConstantVector> :
- public VariadicOperandTraits<ConstantVector> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
-
//===----------------------------------------------------------------------===//
-/// ConstantPointerNull - a constant pointer value that points to null
+/// A constant pointer value that points to null
///
-class ConstantPointerNull : public Constant {
- void *operator new(size_t, unsigned) = delete;
+class ConstantPointerNull final : public ConstantData {
ConstantPointerNull(const ConstantPointerNull &) = delete;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
explicit ConstantPointerNull(PointerType *T)
- : Constant(T,
- Value::ConstantPointerNullVal, nullptr, 0) {}
+ : ConstantData(T, Value::ConstantPointerNullVal) {}
-protected:
- // allocate space for exactly zero operands
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
public:
- /// get() - Static factory methods - Return objects of the specified value
+ /// Static factory methods - Return objects of the specified value
static ConstantPointerNull *get(PointerType *T);
- /// getType - Specialize the getType() method to always return an PointerType,
+ /// Specialize the getType() method to always return an PointerType,
/// which reduces the amount of casting needed in parts of the compiler.
- ///
inline PointerType *getType() const {
return cast<PointerType>(Value::getType());
}
@@ -554,116 +539,101 @@ public:
///
/// This is the common base class of ConstantDataArray and ConstantDataVector.
///
-class ConstantDataSequential : public Constant {
+class ConstantDataSequential : public ConstantData {
friend class LLVMContextImpl;
- /// DataElements - A pointer to the bytes underlying this constant (which is
- /// owned by the uniquing StringMap).
+ /// A pointer to the bytes underlying this constant (which is owned by the
+ /// uniquing StringMap).
const char *DataElements;
- /// Next - This forms a link list of ConstantDataSequential nodes that have
+ /// This forms a link list of ConstantDataSequential nodes that have
/// the same value but different type. For example, 0,0,0,1 could be a 4
/// element array of i8, or a 1-element array of i32. They'll both end up in
/// the same StringMap bucket, linked up.
ConstantDataSequential *Next;
- void *operator new(size_t, unsigned) = delete;
ConstantDataSequential(const ConstantDataSequential &) = delete;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
- : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
+ : ConstantData(ty, VT), DataElements(Data), Next(nullptr) {}
~ConstantDataSequential() override { delete Next; }
static Constant *getImpl(StringRef Bytes, Type *Ty);
-protected:
- // allocate space for exactly zero operands.
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
public:
-
- /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
- /// formed with a vector or array of the specified element type.
+ /// Return true if a ConstantDataSequential can be formed with a vector or
+ /// array of the specified element type.
/// ConstantDataArray only works with normal float and int types that are
/// stored densely in memory, not with things like i42 or x86_f80.
static bool isElementTypeCompatible(Type *Ty);
- /// getElementAsInteger - If this is a sequential container of integers (of
- /// any size), return the specified element in the low bits of a uint64_t.
+ /// If this is a sequential container of integers (of any size), return the
+ /// specified element in the low bits of a uint64_t.
uint64_t getElementAsInteger(unsigned i) const;
- /// getElementAsAPFloat - If this is a sequential container of floating point
- /// type, return the specified element as an APFloat.
+ /// If this is a sequential container of floating point type, return the
+ /// specified element as an APFloat.
APFloat getElementAsAPFloat(unsigned i) const;
- /// getElementAsFloat - If this is an sequential container of floats, return
- /// the specified element as a float.
+ /// If this is an sequential container of floats, return the specified element
+ /// as a float.
float getElementAsFloat(unsigned i) const;
- /// getElementAsDouble - If this is an sequential container of doubles, return
- /// the specified element as a double.
+ /// If this is an sequential container of doubles, return the specified
+ /// element as a double.
double getElementAsDouble(unsigned i) const;
- /// getElementAsConstant - Return a Constant for a specified index's element.
+ /// Return a Constant for a specified index's element.
/// Note that this has to compute a new constant to return, so it isn't as
/// efficient as getElementAsInteger/Float/Double.
Constant *getElementAsConstant(unsigned i) const;
- /// getType - Specialize the getType() method to always return a
- /// SequentialType, which reduces the amount of casting needed in parts of the
- /// compiler.
+ /// Specialize the getType() method to always return a SequentialType, which
+ /// reduces the amount of casting needed in parts of the compiler.
inline SequentialType *getType() const {
return cast<SequentialType>(Value::getType());
}
- /// getElementType - Return the element type of the array/vector.
+ /// Return the element type of the array/vector.
Type *getElementType() const;
- /// getNumElements - Return the number of elements in the array or vector.
+ /// Return the number of elements in the array or vector.
unsigned getNumElements() const;
- /// getElementByteSize - Return the size (in bytes) of each element in the
- /// array/vector. The size of the elements is known to be a multiple of one
- /// byte.
+ /// Return the size (in bytes) of each element in the array/vector.
+ /// The size of the elements is known to be a multiple of one byte.
uint64_t getElementByteSize() const;
-
- /// isString - This method returns true if this is an array of i8.
+ /// This method returns true if this is an array of i8.
bool isString() const;
- /// isCString - This method returns true if the array "isString", ends with a
- /// nul byte, and does not contains any other nul bytes.
+ /// This method returns true if the array "isString", ends with a null byte,
+ /// and does not contains any other null bytes.
bool isCString() const;
- /// getAsString - If this array is isString(), then this method returns the
- /// array as a StringRef. Otherwise, it asserts out.
- ///
+ /// If this array is isString(), then this method returns the array as a
+ /// StringRef. Otherwise, it asserts out.
StringRef getAsString() const {
assert(isString() && "Not a string");
return getRawDataValues();
}
- /// getAsCString - If this array is isCString(), then this method returns the
- /// array (without the trailing null byte) as a StringRef. Otherwise, it
- /// asserts out.
- ///
+ /// If this array is isCString(), then this method returns the array (without
+ /// the trailing null byte) as a StringRef. Otherwise, it asserts out.
StringRef getAsCString() const {
assert(isCString() && "Isn't a C string");
StringRef Str = getAsString();
return Str.substr(0, Str.size()-1);
}
- /// getRawDataValues - Return the raw, underlying, bytes of this data. Note
- /// that this is an extremely tricky thing to work with, as it exposes the
- /// host endianness of the data elements.
+ /// Return the raw, underlying, bytes of this data. Note that this is an
+ /// extremely tricky thing to work with, as it exposes the host endianness of
+ /// the data elements.
StringRef getRawDataValues() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
- ///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataArrayVal ||
V->getValueID() == ConstantDataVectorVal;
@@ -673,25 +643,24 @@ private:
};
//===----------------------------------------------------------------------===//
-/// ConstantDataArray - 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. ConstantInt/ConstantFP). This Constant node has no
-/// operands because it stores all of the elements of the constant as densely
-/// packed data, instead of as Value*'s.
-class ConstantDataArray : public ConstantDataSequential {
+/// 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. ConstantInt/ConstantFP). This Constant node has no operands because it
+/// stores all of the elements of the constant as densely packed data, instead
+/// of as Value*'s.
+class ConstantDataArray final : public ConstantDataSequential {
void *operator new(size_t, unsigned) = delete;
ConstantDataArray(const ConstantDataArray &) = delete;
void anchor() override;
friend class ConstantDataSequential;
explicit ConstantDataArray(Type *ty, const char *Data)
- : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
-protected:
- // allocate space for exactly zero operands.
+ : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
+ /// Allocate space for exactly zero operands.
void *operator new(size_t s) {
return User::operator new(s, 0);
}
-public:
+public:
/// get() constructors - Return a constant with array type with an element
/// count and element type matching the ArrayRef passed in. Note that this
/// can return a ConstantAggregateZero object.
@@ -711,48 +680,45 @@ public:
static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
- /// getString - This method constructs a CDS and initializes it with a text
- /// string. The default behavior (AddNull==true) causes a null terminator to
+ /// This method constructs a CDS and initializes it with a text string.
+ /// The default behavior (AddNull==true) causes a null terminator to
/// be placed at the end of the array (increasing the length of the string by
/// one more than the StringRef would normally indicate. Pass AddNull=false
/// to disable this behavior.
static Constant *getString(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
- /// getType - Specialize the getType() method to always return an ArrayType,
+ /// Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
- ///
inline ArrayType *getType() const {
return cast<ArrayType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
- ///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataArrayVal;
}
};
//===----------------------------------------------------------------------===//
-/// ConstantDataVector - 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. ConstantInt/ConstantFP). This Constant node has no
-/// operands because it stores all of the elements of the constant as densely
-/// packed data, instead of as Value*'s.
-class ConstantDataVector : public ConstantDataSequential {
+/// 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. ConstantInt/ConstantFP). This Constant node has no operands because it
+/// stores all of the elements of the constant as densely packed data, instead
+/// of as Value*'s.
+class ConstantDataVector final : public ConstantDataSequential {
void *operator new(size_t, unsigned) = delete;
ConstantDataVector(const ConstantDataVector &) = delete;
void anchor() override;
friend class ConstantDataSequential;
explicit ConstantDataVector(Type *ty, const char *Data)
- : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
-protected:
+ : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
// allocate space for exactly zero operands.
void *operator new(size_t s) {
return User::operator new(s, 0);
}
-public:
+public:
/// get() constructors - Return a constant with vector type with an element
/// count and element type matching the ArrayRef passed in. Note that this
/// can return a ConstantAggregateZero object.
@@ -772,45 +738,38 @@ public:
static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
- /// getSplat - Return a ConstantVector with the specified constant in each
- /// element. The specified constant has to be a of a compatible type (i8/i16/
+ /// Return a ConstantVector with the specified constant in each element.
+ /// The specified constant has to be a of a compatible type (i8/i16/
/// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
static Constant *getSplat(unsigned NumElts, Constant *Elt);
- /// getSplatValue - If this is a splat constant, meaning that all of the
- /// elements have the same value, return that value. Otherwise return NULL.
+ /// If this is a splat constant, meaning that all of the elements have the
+ /// same value, return that value. Otherwise return NULL.
Constant *getSplatValue() const;
- /// getType - Specialize the getType() method to always return a VectorType,
+ /// Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
- ///
inline VectorType *getType() const {
return cast<VectorType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
- ///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataVectorVal;
}
};
//===----------------------------------------------------------------------===//
-/// ConstantTokenNone - a constant token which is empty
+/// A constant token which is empty
///
-class ConstantTokenNone : public Constant {
- void *operator new(size_t, unsigned) = delete;
+class ConstantTokenNone final : public ConstantData {
ConstantTokenNone(const ConstantTokenNone &) = delete;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
explicit ConstantTokenNone(LLVMContext &Context)
- : Constant(Type::getTokenTy(Context), ConstantTokenNoneVal, nullptr, 0) {}
- // allocate space for exactly zero operands
- void *operator new(size_t s) { return User::operator new(s, 0); }
+ : ConstantData(Type::getTokenTy(Context), ConstantTokenNoneVal) {}
public:
/// Return the ConstantTokenNone.
@@ -822,27 +781,26 @@ public:
}
};
-/// BlockAddress - The address of a basic block.
+/// The address of a basic block.
///
-class BlockAddress : public Constant {
+class BlockAddress final : public Constant {
void *operator new(size_t, unsigned) = delete;
void *operator new(size_t s) { return User::operator new(s, 2); }
BlockAddress(Function *F, BasicBlock *BB);
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
+ Value *handleOperandChangeImpl(Value *From, Value *To);
public:
- /// get - Return a BlockAddress for the specified function and basic block.
+ /// Return a BlockAddress for the specified function and basic block.
static BlockAddress *get(Function *F, BasicBlock *BB);
- /// get - Return a BlockAddress for the specified basic block. The basic
+ /// Return a BlockAddress for the specified basic block. The basic
/// block must be embedded into a function.
static BlockAddress *get(BasicBlock *BB);
- /// \brief Lookup an existing \c BlockAddress constant for the given
- /// BasicBlock.
+ /// Lookup an existing \c BlockAddress constant for the given BasicBlock.
///
/// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
static BlockAddress *lookup(const BasicBlock *BB);
@@ -868,7 +826,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
//===----------------------------------------------------------------------===//
-/// ConstantExpr - a constant value that is initialized with an expression using
+/// A constant value that is initialized with an expression using
/// other constant values.
///
/// This class uses the standard Instruction opcodes to define the various
@@ -879,11 +837,11 @@ class ConstantExpr : public Constant {
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
+ Value *handleOperandChangeImpl(Value *From, Value *To);
protected:
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
- : Constant(ty, ConstantExprVal, Ops, NumOps) {
+ : Constant(ty, ConstantExprVal, Ops, NumOps) {
// Operation type (an Instruction opcode) is stored as the SubclassData.
setValueSubclassData(Opcode);
}
@@ -998,12 +956,12 @@ public:
return getLShr(C1, C2, true);
}
- /// getBinOpIdentity - Return the identity for the given binary operation,
+ /// Return the identity for the given binary operation,
/// i.e. a constant C such that X op C = X and C op X = X for every X. It
/// returns null if the operator doesn't have an identity.
static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
- /// getBinOpAbsorber - Return the absorbing element for the given binary
+ /// 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.
@@ -1165,32 +1123,32 @@ public:
ArrayRef<unsigned> Idxs,
Type *OnlyIfReducedTy = nullptr);
- /// getOpcode - Return the opcode at the root of this constant expression
+ /// Return the opcode at the root of this constant expression
unsigned getOpcode() const { return getSubclassDataFromValue(); }
- /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
- /// not an ICMP or FCMP constant expression.
+ /// Return the ICMP or FCMP predicate value. Assert if this is not an ICMP or
+ /// FCMP constant expression.
unsigned getPredicate() const;
- /// getIndices - Assert that this is an insertvalue or exactvalue
+ /// Assert that this is an insertvalue or exactvalue
/// expression and return the list of indices.
ArrayRef<unsigned> getIndices() const;
- /// getOpcodeName - Return a string representation for an opcode.
+ /// Return a string representation for an opcode.
const char *getOpcodeName() const;
- /// getWithOperandReplaced - Return a constant expression identical to this
- /// one, but with the specified operand set to the specified value.
+ /// Return a constant expression identical to this one, but with the specified
+ /// operand set to the specified value.
Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
- /// getWithOperands - 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.
+ /// 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.
Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
return getWithOperands(Ops, getType());
}
- /// \brief Get the current expression with the operands replaced.
+ /// Get the current expression with the operands replaced.
///
/// Return the current constant expression with the operands replaced with \c
/// Ops and the type with \c Ty. The new operands must have the same number
@@ -1203,9 +1161,8 @@ public:
bool OnlyIfReduced = false,
Type *SrcTy = nullptr) const;
- /// getAsInstruction - Returns an Instruction which implements the same
- /// operation as this ConstantExpr. The instruction is not linked to any basic
- /// block.
+ /// Returns an Instruction which implements the same operation as this
+ /// ConstantExpr. The instruction is not linked to any basic block.
///
/// A better approach to this could be to have a constructor for Instruction
/// which would take a ConstantExpr parameter, but that would have spread
@@ -1234,7 +1191,7 @@ struct OperandTraits<ConstantExpr> :
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
//===----------------------------------------------------------------------===//
-/// UndefValue - 'undef' values are things that do not have specified contents.
+/// 'undef' values are things that do not have specified contents.
/// These are used for a variety of purposes, including global variable
/// initializers and operands to instructions. 'undef' values can occur with
/// any first-class type.
@@ -1243,44 +1200,34 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
/// can appear to have different bit patterns at each use. See
/// LangRef.html#undefvalues for details.
///
-class UndefValue : public Constant {
- void *operator new(size_t, unsigned) = delete;
+class UndefValue final : public ConstantData {
UndefValue(const UndefValue &) = delete;
friend class Constant;
void destroyConstantImpl();
- Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
-protected:
- explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
-protected:
- // allocate space for exactly zero operands
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
+ explicit UndefValue(Type *T) : ConstantData(T, UndefValueVal) {}
+
public:
- /// get() - Static factory methods - Return an 'undef' object of the specified
- /// type.
- ///
+ /// Static factory methods - Return an 'undef' object of the specified type.
static UndefValue *get(Type *T);
- /// getSequentialElement - If this Undef has array or vector type, return a
- /// undef with the right element type.
+ /// If this Undef has array or vector type, return a undef with the right
+ /// element type.
UndefValue *getSequentialElement() const;
- /// getStructElement - If this undef has struct type, return a undef with the
- /// right element type for the specified element.
+ /// If this undef has struct type, return a undef with the right element type
+ /// for the specified element.
UndefValue *getStructElement(unsigned Elt) const;
- /// getElementValue - Return an undef of the right value for the specified GEP
- /// index.
+ /// Return an undef of the right value for the specified GEP index if we can,
+ /// otherwise return null (e.g. if C is a ConstantExpr).
UndefValue *getElementValue(Constant *C) const;
- /// getElementValue - Return an undef of the right value for the specified GEP
- /// index.
+ /// Return an undef of the right value for the specified GEP index.
UndefValue *getElementValue(unsigned Idx) const;
- /// \brief Return the number of elements in the array, vector, or struct.
+ /// Return the number of elements in the array, vector, or struct.
unsigned getNumElements() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast: