forked from OSchip/llvm-project
Use ArrayRef in the (protected) constructors of ConstantArray, ConstantStruct and ConstantVector.
llvm-svn: 135905
This commit is contained in:
parent
d1b7849d49
commit
89d9b81a3a
|
@ -329,7 +329,7 @@ class ConstantArray : public Constant {
|
||||||
std::vector<Constant*> >;
|
std::vector<Constant*> >;
|
||||||
ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
|
ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
|
||||||
protected:
|
protected:
|
||||||
ConstantArray(ArrayType *T, const std::vector<Constant*> &Val);
|
ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
|
||||||
public:
|
public:
|
||||||
// ConstantArray accessors
|
// ConstantArray accessors
|
||||||
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
|
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
|
||||||
|
@ -400,7 +400,7 @@ class ConstantStruct : public Constant {
|
||||||
std::vector<Constant*> >;
|
std::vector<Constant*> >;
|
||||||
ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
|
ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
|
||||||
protected:
|
protected:
|
||||||
ConstantStruct(StructType *T, const std::vector<Constant*> &Val);
|
ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
|
||||||
public:
|
public:
|
||||||
// ConstantStruct accessors
|
// ConstantStruct accessors
|
||||||
static Constant *get(StructType *T, ArrayRef<Constant*> V);
|
static Constant *get(StructType *T, ArrayRef<Constant*> V);
|
||||||
|
@ -461,7 +461,7 @@ class ConstantVector : public Constant {
|
||||||
std::vector<Constant*> >;
|
std::vector<Constant*> >;
|
||||||
ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
|
ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
|
||||||
protected:
|
protected:
|
||||||
ConstantVector(VectorType *T, const std::vector<Constant*> &Val);
|
ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
|
||||||
public:
|
public:
|
||||||
// ConstantVector accessors
|
// ConstantVector accessors
|
||||||
static Constant *get(ArrayRef<Constant*> V);
|
static Constant *get(ArrayRef<Constant*> V);
|
||||||
|
|
|
@ -573,21 +573,16 @@ bool ConstantFP::isExactlyValue(const APFloat &V) const {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
ConstantArray::ConstantArray(ArrayType *T,
|
ConstantArray::ConstantArray(ArrayType *T, ArrayRef<Constant *> V)
|
||||||
const std::vector<Constant*> &V)
|
|
||||||
: Constant(T, ConstantArrayVal,
|
: Constant(T, ConstantArrayVal,
|
||||||
OperandTraits<ConstantArray>::op_end(this) - V.size(),
|
OperandTraits<ConstantArray>::op_end(this) - V.size(),
|
||||||
V.size()) {
|
V.size()) {
|
||||||
assert(V.size() == T->getNumElements() &&
|
assert(V.size() == T->getNumElements() &&
|
||||||
"Invalid initializer vector for constant array");
|
"Invalid initializer vector for constant array");
|
||||||
Use *OL = OperandList;
|
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
||||||
for (std::vector<Constant*>::const_iterator I = V.begin(), E = V.end();
|
assert(V[i]->getType() == T->getElementType() &&
|
||||||
I != E; ++I, ++OL) {
|
|
||||||
Constant *C = *I;
|
|
||||||
assert(C->getType() == T->getElementType() &&
|
|
||||||
"Initializer for array element doesn't match array element type!");
|
"Initializer for array element doesn't match array element type!");
|
||||||
*OL = C;
|
std::copy(V.begin(), V.end(), op_begin());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *ConstantArray::get(ArrayType *Ty, ArrayRef<Constant*> V) {
|
Constant *ConstantArray::get(ArrayType *Ty, ArrayRef<Constant*> V) {
|
||||||
|
@ -653,21 +648,16 @@ StructType *ConstantStruct::getTypeForElements(ArrayRef<Constant*> V,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConstantStruct::ConstantStruct(StructType *T,
|
ConstantStruct::ConstantStruct(StructType *T, ArrayRef<Constant *> V)
|
||||||
const std::vector<Constant*> &V)
|
|
||||||
: Constant(T, ConstantStructVal,
|
: Constant(T, ConstantStructVal,
|
||||||
OperandTraits<ConstantStruct>::op_end(this) - V.size(),
|
OperandTraits<ConstantStruct>::op_end(this) - V.size(),
|
||||||
V.size()) {
|
V.size()) {
|
||||||
assert((T->isOpaque() || V.size() == T->getNumElements()) &&
|
assert((T->isOpaque() || V.size() == T->getNumElements()) &&
|
||||||
"Invalid initializer vector for constant structure");
|
"Invalid initializer vector for constant structure");
|
||||||
Use *OL = OperandList;
|
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
||||||
for (std::vector<Constant*>::const_iterator I = V.begin(), E = V.end();
|
assert((T->isOpaque() || V[i]->getType() == T->getElementType(i)) &&
|
||||||
I != E; ++I, ++OL) {
|
|
||||||
Constant *C = *I;
|
|
||||||
assert((T->isOpaque() || C->getType() == T->getElementType(I-V.begin())) &&
|
|
||||||
"Initializer for struct element doesn't match struct element type!");
|
"Initializer for struct element doesn't match struct element type!");
|
||||||
*OL = C;
|
std::copy(V.begin(), V.end(), op_begin());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConstantStruct accessors.
|
// ConstantStruct accessors.
|
||||||
|
@ -692,19 +682,14 @@ Constant* ConstantStruct::get(StructType *T, ...) {
|
||||||
return get(T, Values);
|
return get(T, Values);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantVector::ConstantVector(VectorType *T,
|
ConstantVector::ConstantVector(VectorType *T, ArrayRef<Constant *> V)
|
||||||
const std::vector<Constant*> &V)
|
|
||||||
: Constant(T, ConstantVectorVal,
|
: Constant(T, ConstantVectorVal,
|
||||||
OperandTraits<ConstantVector>::op_end(this) - V.size(),
|
OperandTraits<ConstantVector>::op_end(this) - V.size(),
|
||||||
V.size()) {
|
V.size()) {
|
||||||
Use *OL = OperandList;
|
for (size_t i = 0, e = V.size(); i != e; i++)
|
||||||
for (std::vector<Constant*>::const_iterator I = V.begin(), E = V.end();
|
assert(V[i]->getType() == T->getElementType() &&
|
||||||
I != E; ++I, ++OL) {
|
|
||||||
Constant *C = *I;
|
|
||||||
assert(C->getType() == T->getElementType() &&
|
|
||||||
"Initializer for vector element doesn't match vector element type!");
|
"Initializer for vector element doesn't match vector element type!");
|
||||||
*OL = C;
|
std::copy(V.begin(), V.end(), op_begin());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConstantVector accessors.
|
// ConstantVector accessors.
|
||||||
|
|
Loading…
Reference in New Issue