Convert InsertValueInst and ExtractValueInst APIs to use ArrayRef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135040 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad
2011-07-13 10:26:04 +00:00
parent 5d4f9909c4
commit fc6d3a4986
25 changed files with 188 additions and 425 deletions

View File

@@ -1386,27 +1386,22 @@ int ShuffleVectorInst::getMaskValue(unsigned i) const {
// InsertValueInst Class
//===----------------------------------------------------------------------===//
void InsertValueInst::init(Value *Agg, Value *Val, const unsigned *Idx,
unsigned NumIdx, const Twine &Name) {
void InsertValueInst::init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
const Twine &Name) {
assert(NumOperands == 2 && "NumOperands not initialized?");
assert(ExtractValueInst::getIndexedType(Agg->getType(), Idx, Idx + NumIdx) ==
// There's no fundamental reason why we require at least one index
// (other than weirdness with &*IdxBegin being invalid; see
// getelementptr's init routine for example). But there's no
// present need to support it.
assert(Idxs.size() > 0 && "InsertValueInst must have at least one index");
assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==
Val->getType() && "Inserted value must match indexed type!");
Op<0>() = Agg;
Op<1>() = Val;
Indices.append(Idx, Idx + NumIdx);
setName(Name);
}
void InsertValueInst::init(Value *Agg, Value *Val, unsigned Idx,
const Twine &Name) {
assert(NumOperands == 2 && "NumOperands not initialized?");
assert(ExtractValueInst::getIndexedType(Agg->getType(), Idx) == Val->getType()
&& "Inserted value must match indexed type!");
Op<0>() = Agg;
Op<1>() = Val;
Indices.push_back(Idx);
Indices.append(Idxs.begin(), Idxs.end());
setName(Name);
}
@@ -1419,44 +1414,18 @@ InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
SubclassOptionalData = IVI.SubclassOptionalData;
}
InsertValueInst::InsertValueInst(Value *Agg,
Value *Val,
unsigned Idx,
const Twine &Name,
Instruction *InsertBefore)
: Instruction(Agg->getType(), InsertValue,
OperandTraits<InsertValueInst>::op_begin(this),
2, InsertBefore) {
init(Agg, Val, Idx, Name);
}
InsertValueInst::InsertValueInst(Value *Agg,
Value *Val,
unsigned Idx,
const Twine &Name,
BasicBlock *InsertAtEnd)
: Instruction(Agg->getType(), InsertValue,
OperandTraits<InsertValueInst>::op_begin(this),
2, InsertAtEnd) {
init(Agg, Val, Idx, Name);
}
//===----------------------------------------------------------------------===//
// ExtractValueInst Class
//===----------------------------------------------------------------------===//
void ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
const Twine &Name) {
void ExtractValueInst::init(ArrayRef<unsigned> Idxs, const Twine &Name) {
assert(NumOperands == 1 && "NumOperands not initialized?");
Indices.append(Idx, Idx + NumIdx);
setName(Name);
}
// There's no fundamental reason why we require at least one index.
// But there's no present need to support it.
assert(Idxs.size() > 0 && "ExtractValueInst must have at least one index");
void ExtractValueInst::init(unsigned Idx, const Twine &Name) {
assert(NumOperands == 1 && "NumOperands not initialized?");
Indices.push_back(Idx);
Indices.append(Idxs.begin(), Idxs.end());
setName(Name);
}
@@ -1473,9 +1442,8 @@ ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
// pointer type.
//
Type *ExtractValueInst::getIndexedType(const Type *Agg,
const unsigned *Idxs,
unsigned NumIdx) {
for (unsigned CurIdx = 0; CurIdx != NumIdx; ++CurIdx) {
ArrayRef<unsigned> Idxs) {
for (unsigned CurIdx = 0; CurIdx != Idxs.size(); ++CurIdx) {
unsigned Index = Idxs[CurIdx];
// We can't use CompositeType::indexValid(Index) here.
// indexValid() always returns true for arrays because getelementptr allows
@@ -1499,10 +1467,6 @@ Type *ExtractValueInst::getIndexedType(const Type *Agg,
return const_cast<Type*>(Agg);
}
Type *ExtractValueInst::getIndexedType(const Type *Agg, unsigned Idx) {
return getIndexedType(Agg, &Idx, 1);
}
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//