mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
constify some methods and add a new Constant::getAggregateElement
helper method for the common operation of extracting an element out of a constant aggregate. llvm-svn: 148931
This commit is contained in:
parent
473bdbaabc
commit
6791b23efa
@ -97,6 +97,13 @@ public:
|
|||||||
/// constant exprs and other cases we can't handle, we return an empty vector.
|
/// constant exprs and other cases we can't handle, we return an empty vector.
|
||||||
void getVectorElements(SmallVectorImpl<Constant*> &Elts) const;
|
void getVectorElements(SmallVectorImpl<Constant*> &Elts) 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.
|
||||||
|
Constant *getAggregateElement(unsigned Elt) const;
|
||||||
|
Constant *getAggregateElement(Constant *Elt) const;
|
||||||
|
|
||||||
/// destroyConstant - Called if some element of this constant is no longer
|
/// 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
|
/// 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
|
/// constant. Any constants on our Use list must also be destroy'd. The
|
||||||
|
@ -316,19 +316,19 @@ public:
|
|||||||
|
|
||||||
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
||||||
/// with the right element type.
|
/// with the right element type.
|
||||||
Constant *getSequentialElement();
|
Constant *getSequentialElement() const;
|
||||||
|
|
||||||
/// getStructElement - If this CAZ has struct type, return a zero with the
|
/// getStructElement - If this CAZ has struct type, return a zero with the
|
||||||
/// right element type for the specified element.
|
/// right element type for the specified element.
|
||||||
Constant *getStructElement(unsigned Elt);
|
Constant *getStructElement(unsigned Elt) const;
|
||||||
|
|
||||||
/// getElementValue - Return a zero of the right value for the specified GEP
|
/// getElementValue - Return a zero of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
Constant *getElementValue(Constant *C);
|
Constant *getElementValue(Constant *C) const;
|
||||||
|
|
||||||
/// getElementValue - Return a zero of the right value for the specified GEP
|
/// getElementValue - Return a zero of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
Constant *getElementValue(unsigned Idx);
|
Constant *getElementValue(unsigned Idx) const;
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
///
|
///
|
||||||
@ -1157,19 +1157,19 @@ public:
|
|||||||
|
|
||||||
/// getSequentialElement - If this Undef has array or vector type, return a
|
/// getSequentialElement - If this Undef has array or vector type, return a
|
||||||
/// undef with the right element type.
|
/// undef with the right element type.
|
||||||
UndefValue *getSequentialElement();
|
UndefValue *getSequentialElement() const;
|
||||||
|
|
||||||
/// getStructElement - If this undef has struct type, return a undef with the
|
/// getStructElement - If this undef has struct type, return a undef with the
|
||||||
/// right element type for the specified element.
|
/// right element type for the specified element.
|
||||||
UndefValue *getStructElement(unsigned Elt);
|
UndefValue *getStructElement(unsigned Elt) const;
|
||||||
|
|
||||||
/// getElementValue - Return an undef of the right value for the specified GEP
|
/// getElementValue - Return an undef of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
UndefValue *getElementValue(Constant *C);
|
UndefValue *getElementValue(Constant *C) const;
|
||||||
|
|
||||||
/// getElementValue - Return an undef of the right value for the specified GEP
|
/// getElementValue - Return an undef of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
UndefValue *getElementValue(unsigned Idx);
|
UndefValue *getElementValue(unsigned Idx) const;
|
||||||
|
|
||||||
virtual void destroyConstant();
|
virtual void destroyConstant();
|
||||||
|
|
||||||
|
@ -150,6 +150,39 @@ Constant *Constant::getAllOnesValue(Type *Ty) {
|
|||||||
getAllOnesValue(VTy->getElementType()));
|
getAllOnesValue(VTy->getElementType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
Constant *Constant::getAggregateElement(unsigned Elt) const {
|
||||||
|
if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(this))
|
||||||
|
return Elt < CS->getNumOperands() ? CS->getOperand(Elt) : 0;
|
||||||
|
|
||||||
|
if (const ConstantArray *CA = dyn_cast<ConstantArray>(this))
|
||||||
|
return Elt < CA->getNumOperands() ? CA->getOperand(Elt) : 0;
|
||||||
|
|
||||||
|
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
|
||||||
|
return Elt < CV->getNumOperands() ? CV->getOperand(Elt) : 0;
|
||||||
|
|
||||||
|
if (const ConstantAggregateZero *CAZ =dyn_cast<ConstantAggregateZero>(this))
|
||||||
|
return CAZ->getElementValue(Elt);
|
||||||
|
|
||||||
|
if (const UndefValue *UV = dyn_cast<UndefValue>(this))
|
||||||
|
return UV->getElementValue(Elt);
|
||||||
|
|
||||||
|
if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(this))
|
||||||
|
return CDS->getElementAsConstant(Elt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Constant *Constant::getAggregateElement(Constant *Elt) const {
|
||||||
|
assert(isa<IntegerType>(Elt->getType()) && "Index must be an integer");
|
||||||
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt))
|
||||||
|
return getAggregateElement(CI->getZExtValue());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Constant::destroyConstantImpl() {
|
void Constant::destroyConstantImpl() {
|
||||||
// When a Constant is destroyed, there may be lingering
|
// When a Constant is destroyed, there may be lingering
|
||||||
// references to the constant by other constants in the constant pool. These
|
// references to the constant by other constants in the constant pool. These
|
||||||
@ -594,21 +627,21 @@ bool ConstantFP::isExactlyValue(const APFloat &V) const {
|
|||||||
|
|
||||||
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
/// getSequentialElement - If this CAZ has array or vector type, return a zero
|
||||||
/// with the right element type.
|
/// with the right element type.
|
||||||
Constant *ConstantAggregateZero::getSequentialElement() {
|
Constant *ConstantAggregateZero::getSequentialElement() const {
|
||||||
return Constant::getNullValue(
|
return Constant::getNullValue(
|
||||||
cast<SequentialType>(getType())->getElementType());
|
cast<SequentialType>(getType())->getElementType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getStructElement - If this CAZ has struct type, return a zero with the
|
/// getStructElement - If this CAZ has struct type, return a zero with the
|
||||||
/// right element type for the specified element.
|
/// right element type for the specified element.
|
||||||
Constant *ConstantAggregateZero::getStructElement(unsigned Elt) {
|
Constant *ConstantAggregateZero::getStructElement(unsigned Elt) const {
|
||||||
return Constant::getNullValue(
|
return Constant::getNullValue(
|
||||||
cast<StructType>(getType())->getElementType(Elt));
|
cast<StructType>(getType())->getElementType(Elt));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getElementValue - Return a zero of the right value for the specified GEP
|
/// 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).
|
/// index if we can, otherwise return null (e.g. if C is a ConstantExpr).
|
||||||
Constant *ConstantAggregateZero::getElementValue(Constant *C) {
|
Constant *ConstantAggregateZero::getElementValue(Constant *C) const {
|
||||||
if (isa<SequentialType>(getType()))
|
if (isa<SequentialType>(getType()))
|
||||||
return getSequentialElement();
|
return getSequentialElement();
|
||||||
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
||||||
@ -616,7 +649,7 @@ Constant *ConstantAggregateZero::getElementValue(Constant *C) {
|
|||||||
|
|
||||||
/// getElementValue - Return a zero of the right value for the specified GEP
|
/// getElementValue - Return a zero of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
Constant *ConstantAggregateZero::getElementValue(unsigned Idx) {
|
Constant *ConstantAggregateZero::getElementValue(unsigned Idx) const {
|
||||||
if (isa<SequentialType>(getType()))
|
if (isa<SequentialType>(getType()))
|
||||||
return getSequentialElement();
|
return getSequentialElement();
|
||||||
return getStructElement(Idx);
|
return getStructElement(Idx);
|
||||||
@ -629,19 +662,19 @@ Constant *ConstantAggregateZero::getElementValue(unsigned Idx) {
|
|||||||
|
|
||||||
/// getSequentialElement - If this undef has array or vector type, return an
|
/// getSequentialElement - If this undef has array or vector type, return an
|
||||||
/// undef with the right element type.
|
/// undef with the right element type.
|
||||||
UndefValue *UndefValue::getSequentialElement() {
|
UndefValue *UndefValue::getSequentialElement() const {
|
||||||
return UndefValue::get(cast<SequentialType>(getType())->getElementType());
|
return UndefValue::get(cast<SequentialType>(getType())->getElementType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getStructElement - If this undef has struct type, return a zero with the
|
/// getStructElement - If this undef has struct type, return a zero with the
|
||||||
/// right element type for the specified element.
|
/// right element type for the specified element.
|
||||||
UndefValue *UndefValue::getStructElement(unsigned Elt) {
|
UndefValue *UndefValue::getStructElement(unsigned Elt) const {
|
||||||
return UndefValue::get(cast<StructType>(getType())->getElementType(Elt));
|
return UndefValue::get(cast<StructType>(getType())->getElementType(Elt));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getElementValue - Return an undef of the right value for the specified GEP
|
/// 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).
|
/// index if we can, otherwise return null (e.g. if C is a ConstantExpr).
|
||||||
UndefValue *UndefValue::getElementValue(Constant *C) {
|
UndefValue *UndefValue::getElementValue(Constant *C) const {
|
||||||
if (isa<SequentialType>(getType()))
|
if (isa<SequentialType>(getType()))
|
||||||
return getSequentialElement();
|
return getSequentialElement();
|
||||||
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
return getStructElement(cast<ConstantInt>(C)->getZExtValue());
|
||||||
@ -649,7 +682,7 @@ UndefValue *UndefValue::getElementValue(Constant *C) {
|
|||||||
|
|
||||||
/// getElementValue - Return an undef of the right value for the specified GEP
|
/// getElementValue - Return an undef of the right value for the specified GEP
|
||||||
/// index.
|
/// index.
|
||||||
UndefValue *UndefValue::getElementValue(unsigned Idx) {
|
UndefValue *UndefValue::getElementValue(unsigned Idx) const {
|
||||||
if (isa<SequentialType>(getType()))
|
if (isa<SequentialType>(getType()))
|
||||||
return getSequentialElement();
|
return getSequentialElement();
|
||||||
return getStructElement(Idx);
|
return getStructElement(Idx);
|
||||||
|
Loading…
Reference in New Issue
Block a user