Simplify code (somtimes dramatically), by using the new "auto-insert" feature

of instruction constructors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3656 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-09-10 17:04:02 +00:00
parent 3ea5cb0df1
commit 2a7c23ef91
7 changed files with 117 additions and 219 deletions
+10 -20
View File
@@ -141,35 +141,25 @@ const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
if (BI) { // Generate code?
BasicBlock *BB = (*BI)->getParent();
if (Expr.Var->getType() != Type::UIntTy) {
CastInst *IdxCast = new CastInst(Expr.Var, Type::UIntTy);
if (Expr.Var->hasName())
IdxCast->setName(Expr.Var->getName()+"-idxcast");
*BI = ++BB->getInstList().insert(*BI, IdxCast);
Expr.Var = IdxCast;
}
if (Expr.Var->getType() != Type::UIntTy)
Expr.Var = new CastInst(Expr.Var, Type::UIntTy,
Expr.Var->getName()+"-idxcast", *BI);
if (ScaleAmt && ScaleAmt != 1) {
// If we have to scale up our index, do so now
Value *ScaleAmtVal = ConstantUInt::get(Type::UIntTy,
(unsigned)ScaleAmt);
Instruction *Scaler = BinaryOperator::create(Instruction::Mul,
Expr.Var, ScaleAmtVal);
if (Expr.Var->hasName())
Scaler->setName(Expr.Var->getName()+"-scale");
*BI = ++BB->getInstList().insert(*BI, Scaler);
Expr.Var = Scaler;
Expr.Var = BinaryOperator::create(Instruction::Mul, Expr.Var,
ScaleAmtVal,
Expr.Var->getName()+"-scale",*BI);
}
if (Index) { // Add an offset to the index
Value *IndexAmt = ConstantUInt::get(Type::UIntTy, (unsigned)Index);
Instruction *Offseter = BinaryOperator::create(Instruction::Add,
Expr.Var, IndexAmt);
if (Expr.Var->hasName())
Offseter->setName(Expr.Var->getName()+"-offset");
*BI = ++BB->getInstList().insert(*BI, Offseter);
Expr.Var = Offseter;
Expr.Var = BinaryOperator::create(Instruction::Add, Expr.Var,
IndexAmt,
Expr.Var->getName()+"-offset",
*BI);
}
}