use Constant::getAggregateElement to simplify a bunch of code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148934 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2012-01-25 06:48:06 +00:00
parent 969ba287cd
commit a1f00f4d48
5 changed files with 68 additions and 189 deletions

View File

@ -1493,19 +1493,12 @@ Value *llvm::FindInsertedValue(Value *V, ArrayRef<unsigned> idx_range,
"Not looking at a struct or array?");
assert(ExtractValueInst::getIndexedType(V->getType(), idx_range) &&
"Invalid indices for type?");
CompositeType *PTy = cast<CompositeType>(V->getType());
if (isa<UndefValue>(V))
return UndefValue::get(ExtractValueInst::getIndexedType(PTy, idx_range));
if (isa<ConstantAggregateZero>(V))
return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy,
idx_range));
if (isa<ConstantArray>(V) || isa<ConstantStruct>(V))
// Recursively process this constant
return FindInsertedValue(cast<Constant>(V)->getOperand(idx_range[0]),
idx_range.slice(1), InsertBefore);
if (ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(V))
return CDS->getElementAsConstant(idx_range[0]);
if (Constant *C = dyn_cast<Constant>(V)) {
C = C->getAggregateElement(idx_range[0]);
if (C == 0) return 0;
return FindInsertedValue(C, idx_range.slice(1), InsertBefore);
}
if (InsertValueInst *I = dyn_cast<InsertValueInst>(V)) {
// Loop the indices for the insertvalue instruction in parallel with the