More changes from Chris' review: simplify getIndices and avoid

copying its return value.

llvm-svn: 52627
This commit is contained in:
Dan Gohman 2008-06-23 16:39:44 +00:00
parent 4193f34538
commit a469bdbcdf
1 changed files with 6 additions and 8 deletions

View File

@ -712,10 +712,8 @@ const SmallVector<unsigned, 4> &ConstantExpr::getIndices() const {
if (const ExtractValueConstantExpr *EVCE = if (const ExtractValueConstantExpr *EVCE =
dyn_cast<ExtractValueConstantExpr>(this)) dyn_cast<ExtractValueConstantExpr>(this))
return EVCE->Indices; return EVCE->Indices;
if (const InsertValueConstantExpr *IVCE =
dyn_cast<InsertValueConstantExpr>(this)) return cast<InsertValueConstantExpr>(this)->Indices;
return IVCE->Indices;
assert(0 && "ConstantExpr does not have indices!");
} }
/// ConstantExpr::get* - Return some common constants without having to /// ConstantExpr::get* - Return some common constants without having to
@ -829,7 +827,7 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const {
Op2 = (OpNo == 2) ? Op : getOperand(2); Op2 = (OpNo == 2) ? Op : getOperand(2);
return ConstantExpr::getShuffleVector(Op0, Op1, Op2); return ConstantExpr::getShuffleVector(Op0, Op1, Op2);
case Instruction::InsertValue: { case Instruction::InsertValue: {
const SmallVector<unsigned, 4> Indices = getIndices(); const SmallVector<unsigned, 4> &Indices = getIndices();
Op0 = (OpNo == 0) ? Op : getOperand(0); Op0 = (OpNo == 0) ? Op : getOperand(0);
Op1 = (OpNo == 1) ? Op : getOperand(1); Op1 = (OpNo == 1) ? Op : getOperand(1);
return ConstantExpr::getInsertValue(Op0, Op1, return ConstantExpr::getInsertValue(Op0, Op1,
@ -837,7 +835,7 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const {
} }
case Instruction::ExtractValue: { case Instruction::ExtractValue: {
assert(OpNo == 0 && "ExtractaValue has only one operand!"); assert(OpNo == 0 && "ExtractaValue has only one operand!");
const SmallVector<unsigned, 4> Indices = getIndices(); const SmallVector<unsigned, 4> &Indices = getIndices();
return return
ConstantExpr::getExtractValue(Op, &Indices[0], Indices.size()); ConstantExpr::getExtractValue(Op, &Indices[0], Indices.size());
} }
@ -897,12 +895,12 @@ getWithOperands(const std::vector<Constant*> &Ops) const {
case Instruction::ShuffleVector: case Instruction::ShuffleVector:
return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]); return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
case Instruction::InsertValue: { case Instruction::InsertValue: {
const SmallVector<unsigned, 4> Indices = getIndices(); const SmallVector<unsigned, 4> &Indices = getIndices();
return ConstantExpr::getInsertValue(Ops[0], Ops[1], return ConstantExpr::getInsertValue(Ops[0], Ops[1],
&Indices[0], Indices.size()); &Indices[0], Indices.size());
} }
case Instruction::ExtractValue: { case Instruction::ExtractValue: {
const SmallVector<unsigned, 4> Indices = getIndices(); const SmallVector<unsigned, 4> &Indices = getIndices();
return ConstantExpr::getExtractValue(Ops[0], return ConstantExpr::getExtractValue(Ops[0],
&Indices[0], Indices.size()); &Indices[0], Indices.size());
} }