mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-29 13:24:25 +00:00
Add some accessor methods to CAZ and UndefValue that help simplify clients.
Make some CDS methods public. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148785 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -310,10 +310,22 @@ protected:
|
|||||||
return User::operator new(s, 0);
|
return User::operator new(s, 0);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
static ConstantAggregateZero* get(Type *Ty);
|
static ConstantAggregateZero *get(Type *Ty);
|
||||||
|
|
||||||
virtual void destroyConstant();
|
virtual void destroyConstant();
|
||||||
|
|
||||||
|
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
||||||
|
/// with the right element type.
|
||||||
|
Constant *getSequentialElement();
|
||||||
|
|
||||||
|
/// getStructElement - If this CAZ has struct type, return a zero with the
|
||||||
|
/// right element type for the specified element.
|
||||||
|
Constant *getStructElement(unsigned Elt);
|
||||||
|
|
||||||
|
/// getElementValue - Return a zero of the right value for the specified GEP
|
||||||
|
/// index.
|
||||||
|
Constant *getElementValue(Constant *C);
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
///
|
///
|
||||||
static bool classof(const ConstantAggregateZero *) { return true; }
|
static bool classof(const ConstantAggregateZero *) { return true; }
|
||||||
@ -568,8 +580,12 @@ protected:
|
|||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void destroyConstant();
|
/// isElementTypeCompatible - 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(const Type *Ty);
|
||||||
|
|
||||||
/// getElementAsInteger - If this is a sequential container of integers (of
|
/// getElementAsInteger - If this is a sequential container of integers (of
|
||||||
/// any size), return the specified element in the low bits of a uint64_t.
|
/// any size), return the specified element in the low bits of a uint64_t.
|
||||||
uint64_t getElementAsInteger(unsigned i) const;
|
uint64_t getElementAsInteger(unsigned i) const;
|
||||||
@ -601,7 +617,13 @@ public:
|
|||||||
/// getElementType - Return the element type of the array/vector.
|
/// getElementType - Return the element type of the array/vector.
|
||||||
Type *getElementType() const;
|
Type *getElementType() 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.
|
||||||
|
uint64_t getElementByteSize() const;
|
||||||
|
|
||||||
|
virtual void destroyConstant();
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
///
|
///
|
||||||
static bool classof(const ConstantDataSequential *) { return true; }
|
static bool classof(const ConstantDataSequential *) { return true; }
|
||||||
@ -610,7 +632,6 @@ public:
|
|||||||
V->getValueID() == ConstantDataVectorVal;
|
V->getValueID() == ConstantDataVectorVal;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
uint64_t getElementByteSize() const;
|
|
||||||
const char *getElementPointer(unsigned Elt) const;
|
const char *getElementPointer(unsigned Elt) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1074,6 +1095,18 @@ public:
|
|||||||
///
|
///
|
||||||
static UndefValue *get(Type *T);
|
static UndefValue *get(Type *T);
|
||||||
|
|
||||||
|
/// getSequentialElement - If this Undef has array or vector type, return a
|
||||||
|
/// undef with the right element type.
|
||||||
|
UndefValue *getSequentialElement();
|
||||||
|
|
||||||
|
/// getStructElement - If this undef has struct type, return a undef with the
|
||||||
|
/// right element type for the specified element.
|
||||||
|
UndefValue *getStructElement(unsigned Elt);
|
||||||
|
|
||||||
|
/// getElementValue - Return an undef of the right value for the specified GEP
|
||||||
|
/// index.
|
||||||
|
UndefValue *getElementValue(Constant *C);
|
||||||
|
|
||||||
virtual void destroyConstant();
|
virtual void destroyConstant();
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
@ -598,6 +598,57 @@ bool ConstantFP::isExactlyValue(const APFloat &V) const {
|
|||||||
return Val.bitwiseIsEqual(V);
|
return Val.bitwiseIsEqual(V);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// ConstantAggregateZero Implementation
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
||||||
|
/// with the right element type.
|
||||||
|
Constant *ConstantAggregateZero::getSequentialElement() {
|
||||||
|
return Constant::getNullValue(
|
||||||
|
cast<SequentialType>(getType())->getElementType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getStructElement - If this CAZ has struct type, return a zero with the
|
||||||
|
/// right element type for the specified element.
|
||||||
|
Constant *ConstantAggregateZero::getStructElement(unsigned Elt) {
|
||||||
|
return Constant::getNullValue(
|
||||||
|
cast<StructType>(getType())->getElementType(Elt));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getElementValue - 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 *ConstantAggregateZero::getElementValue(Constant *C) {
|
||||||
|
if (isa<SequentialType>(getType()))
|
||||||
|
return getSequentialElement();
|
||||||
|
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// UndefValue Implementation
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
/// getSequentialElement - If this undef has array or vector type, return an
|
||||||
|
/// undef with the right element type.
|
||||||
|
UndefValue *UndefValue::getSequentialElement() {
|
||||||
|
return UndefValue::get(cast<SequentialType>(getType())->getElementType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getStructElement - If this undef has struct type, return a zero with the
|
||||||
|
/// right element type for the specified element.
|
||||||
|
UndefValue *UndefValue::getStructElement(unsigned Elt) {
|
||||||
|
return UndefValue::get(cast<StructType>(getType())->getElementType(Elt));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getElementValue - 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 *UndefValue::getElementValue(Constant *C) {
|
||||||
|
if (isa<SequentialType>(getType()))
|
||||||
|
return getSequentialElement();
|
||||||
|
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ConstantXXX Classes
|
// ConstantXXX Classes
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -990,6 +1041,7 @@ bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Factory Function Implementation
|
// Factory Function Implementation
|
||||||
|
|
||||||
@ -1004,7 +1056,7 @@ ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
|
|||||||
return Entry;
|
return Entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// destroyConstant - Remove the constant from the constant table...
|
/// destroyConstant - Remove the constant from the constant table.
|
||||||
///
|
///
|
||||||
void ConstantAggregateZero::destroyConstant() {
|
void ConstantAggregateZero::destroyConstant() {
|
||||||
getContext().pImpl->CAZConstants.erase(getType());
|
getContext().pImpl->CAZConstants.erase(getType());
|
||||||
@ -1924,9 +1976,11 @@ Type *ConstantDataSequential::getElementType() const {
|
|||||||
return getType()->getElementType();
|
return getType()->getElementType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isElementTypeConstantDataCompatible - Return true if this type is valid for
|
/// isElementTypeCompatible - Return true if a ConstantDataSequential can be
|
||||||
/// a ConstantDataSequential. This is i8/i16/i32/i64/float/double.
|
/// formed with a vector or array of the specified element type.
|
||||||
static bool isElementTypeConstantDataCompatible(const Type *Ty) {
|
/// ConstantDataArray only works with normal float and int types that are
|
||||||
|
/// stored densely in memory, not with things like i42 or x86_f80.
|
||||||
|
bool ConstantDataSequential::isElementTypeCompatible(const Type *Ty) {
|
||||||
if (Ty->isFloatTy() || Ty->isDoubleTy()) return true;
|
if (Ty->isFloatTy() || Ty->isDoubleTy()) return true;
|
||||||
if (const IntegerType *IT = dyn_cast<IntegerType>(Ty)) {
|
if (const IntegerType *IT = dyn_cast<IntegerType>(Ty)) {
|
||||||
switch (IT->getBitWidth()) {
|
switch (IT->getBitWidth()) {
|
||||||
@ -1960,13 +2014,13 @@ static bool isAllZeros(StringRef Arr) {
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getImpl - This is the underlying implementation of all of the
|
/// getImpl - This is the underlying implementation of all of the
|
||||||
/// ConstantDataSequential::get methods. They all thunk down to here, providing
|
/// ConstantDataSequential::get methods. They all thunk down to here, providing
|
||||||
/// the correct element type. We take the bytes in as an StringRef because
|
/// the correct element type. We take the bytes in as an StringRef because
|
||||||
/// we *want* an underlying "char*" to avoid TBAA type punning violations.
|
/// we *want* an underlying "char*" to avoid TBAA type punning violations.
|
||||||
Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
|
Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
|
||||||
assert(isElementTypeConstantDataCompatible(cast<SequentialType>(Ty)->
|
assert(isElementTypeCompatible(cast<SequentialType>(Ty)->getElementType()));
|
||||||
getElementType()));
|
|
||||||
// If the elements are all zero, return a CAZ, which is more dense.
|
// If the elements are all zero, return a CAZ, which is more dense.
|
||||||
if (isAllZeros(Elements))
|
if (isAllZeros(Elements))
|
||||||
return ConstantAggregateZero::get(Ty);
|
return ConstantAggregateZero::get(Ty);
|
||||||
|
Reference in New Issue
Block a user