[llvm-commits] CVS: llvm/lib/Transforms/ExprTypeConvert.cpp LevelRaise.cpp TransformInternals.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Sep 10 12:05:14 PDT 2002
Changes in directory llvm/lib/Transforms:
ExprTypeConvert.cpp updated: 1.52 -> 1.53
LevelRaise.cpp updated: 1.68 -> 1.69
TransformInternals.cpp updated: 1.27 -> 1.28
---
Log message:
Simplify code (somtimes dramatically), by using the new "auto-insert" feature
of instruction constructors.
---
Diffs of the changes:
Index: llvm/lib/Transforms/ExprTypeConvert.cpp
diff -u llvm/lib/Transforms/ExprTypeConvert.cpp:1.52 llvm/lib/Transforms/ExprTypeConvert.cpp:1.53
--- llvm/lib/Transforms/ExprTypeConvert.cpp:1.52 Mon Sep 9 15:25:21 2002
+++ llvm/lib/Transforms/ExprTypeConvert.cpp Tue Sep 10 12:02:54 2002
@@ -101,21 +101,14 @@
// If we have a scale, apply it first...
if (Expr.Var) {
// Expr.Var is not neccesarily unsigned right now, insert a cast now.
- if (Expr.Var->getType() != Type::UIntTy) {
- Instruction *CI = new CastInst(Expr.Var, Type::UIntTy);
- if (Expr.Var->hasName()) CI->setName(Expr.Var->getName()+"-uint");
- It = ++BB->getInstList().insert(It, CI);
- Expr.Var = CI;
- }
-
- if (Scale != 1) {
- Instruction *ScI =
- BinaryOperator::create(Instruction::Mul, Expr.Var,
- ConstantUInt::get(Type::UIntTy, Scale));
- if (Expr.Var->hasName()) ScI->setName(Expr.Var->getName()+"-scl");
- It = ++BB->getInstList().insert(It, ScI);
- Expr.Var = ScI;
- }
+ if (Expr.Var->getType() != Type::UIntTy)
+ Expr.Var = new CastInst(Expr.Var, Type::UIntTy,
+ Expr.Var->getName()+"-uint", It);
+
+ if (Scale != 1)
+ Expr.Var = BinaryOperator::create(Instruction::Mul, Expr.Var,
+ ConstantUInt::get(Type::UIntTy, Scale),
+ Expr.Var->getName()+"-scl", It);
} else {
// If we are not scaling anything, just make the offset be the "var"...
@@ -126,13 +119,9 @@
// If we have an offset now, add it in...
if (Offset != 0) {
assert(Expr.Var && "Var must be nonnull by now!");
-
- Instruction *AddI =
- BinaryOperator::create(Instruction::Add, Expr.Var,
- ConstantUInt::get(Type::UIntTy, Offset));
- if (Expr.Var->hasName()) AddI->setName(Expr.Var->getName()+"-off");
- It = ++BB->getInstList().insert(It, AddI);
- Expr.Var = AddI;
+ Expr.Var = BinaryOperator::create(Instruction::Add, Expr.Var,
+ ConstantUInt::get(Type::UIntTy, Offset),
+ Expr.Var->getName()+"-off", It);
}
Instruction *NewI = new MallocInst(AllocTy, Expr.Var, Name);
@@ -971,9 +960,8 @@
assert(LoadedTy->isFirstClassType());
if (Indices.size() != 1) { // Do not generate load X, 0
- Src = new GetElementPtrInst(Src, Indices, Name+".idx");
// Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(Src));
+ Src = new GetElementPtrInst(Src, Indices, Name+".idx", I);
}
}
@@ -1008,10 +996,9 @@
assert(Offset == 0 && "Offset changed!");
assert(NewTy == Ty && "Did not convert to correct type!");
+ // Insert the GEP instruction before this store.
SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
- SrcPtr->getName()+".idx");
- // Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(SrcPtr));
+ SrcPtr->getName()+".idx", I);
}
Res = new StoreInst(NewVal, SrcPtr);
@@ -1038,10 +1025,9 @@
assert(Offset == 0 && ValTy);
+ // Insert the GEP instruction before this store.
SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
- SrcPtr->getName()+".idx");
- // Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(SrcPtr));
+ SrcPtr->getName()+".idx", I);
}
Res = new StoreInst(Constant::getNullValue(ValTy), SrcPtr);
@@ -1064,8 +1050,8 @@
if (DataSize != 1) {
// Insert a multiply of the old element type is not a unit size...
Index = BinaryOperator::create(Instruction::Mul, Index,
- ConstantUInt::get(Type::UIntTy, DataSize));
- It = ++BIL.insert(It, cast<Instruction>(Index));
+ ConstantUInt::get(Type::UIntTy, DataSize),
+ "scale", It);
}
// Perform the conversion now...
@@ -1146,8 +1132,7 @@
// Create a cast to convert it to the right type, we know that this
// is a lossless cast...
//
- Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast");
- It = ++BIL.insert(It, cast<Instruction>(Params[i]));
+ Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast", It);
}
Meth = NewVal; // Update call destination to new value
Index: llvm/lib/Transforms/LevelRaise.cpp
diff -u llvm/lib/Transforms/LevelRaise.cpp:1.68 llvm/lib/Transforms/LevelRaise.cpp:1.69
--- llvm/lib/Transforms/LevelRaise.cpp:1.68 Mon Sep 2 20:07:29 2002
+++ llvm/lib/Transforms/LevelRaise.cpp Tue Sep 10 12:02:54 2002
@@ -179,8 +179,7 @@
}
GetElementPtrInst *GEP = new GetElementPtrInst(SrcPtr, Indices,
- AddOp2->getName());
- BI = ++BB->getInstList().insert(BI, GEP);
+ AddOp2->getName(), BI);
Instruction *NCI = new CastInst(GEP, AddOp1->getType());
ReplaceInstWithInst(BB->getInstList(), BI, NCI);
@@ -354,11 +353,11 @@
if (ElTy) {
PRINT_PEEPHOLE1("cast-for-first:in", CI);
+ std::string Name = CI->getName(); CI->setName("");
+
// Insert the new T cast instruction... stealing old T's name
GetElementPtrInst *GEP = new GetElementPtrInst(Src, Indices,
- CI->getName());
- CI->setName("");
- BI = ++BB->getInstList().insert(BI, GEP);
+ Name, BI);
// Make the old cast instruction reference the new GEP instead of
// the old src value.
@@ -397,10 +396,9 @@
PRINT_PEEPHOLE3("st-src-cast:in ", Pointer, Val, SI);
// Insert the new T cast instruction... stealing old T's name
+ std::string Name(CI->getName()); CI->setName("");
CastInst *NCI = new CastInst(Val, CSPT->getElementType(),
- CI->getName());
- CI->setName("");
- BI = ++BB->getInstList().insert(BI, NCI);
+ Name, BI);
// Replace the old store with a new one!
ReplaceInstWithInst(BB->getInstList(), BI,
@@ -436,11 +434,10 @@
PRINT_PEEPHOLE2("load-src-cast:in ", Pointer, LI);
// Create the new load instruction... loading the pre-casted value
- LoadInst *NewLI = new LoadInst(CastSrc, LI->getName());
+ LoadInst *NewLI = new LoadInst(CastSrc, LI->getName(), BI);
// Insert the new T cast instruction... stealing old T's name
CastInst *NCI = new CastInst(NewLI, LI->getType(), CI->getName());
- BI = ++BB->getInstList().insert(BI, NewLI);
// Replace the old store with a new one!
ReplaceInstWithInst(BB->getInstList(), BI, NCI);
Index: llvm/lib/Transforms/TransformInternals.cpp
diff -u llvm/lib/Transforms/TransformInternals.cpp:1.27 llvm/lib/Transforms/TransformInternals.cpp:1.28
--- llvm/lib/Transforms/TransformInternals.cpp:1.27 Fri Aug 30 17:53:08 2002
+++ llvm/lib/Transforms/TransformInternals.cpp Tue Sep 10 12:02:55 2002
@@ -141,35 +141,25 @@
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);
}
}
More information about the llvm-commits
mailing list