[llvm-commits] CVS: llvm/lib/VMCore/ConstantHandling.cpp Constants.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed May 14 12:54:51 PDT 2003
Changes in directory llvm/lib/VMCore:
ConstantHandling.cpp updated: 1.29 -> 1.30
Constants.cpp updated: 1.37 -> 1.38
---
Log message:
Remove unnecessary casts
---
Diffs of the changes:
Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.29 llvm/lib/VMCore/ConstantHandling.cpp:1.30
--- llvm/lib/VMCore/ConstantHandling.cpp:1.29 Tue May 13 21:47:13 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp Wed May 14 12:51:05 2003
@@ -91,7 +91,7 @@
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::Cast) {
- Constant *Op = (Constant*)cast<Constant>(CE->getOperand(0));
+ Constant *Op = const_cast<Constant*>(CE->getOperand(0));
// Try to not produce a cast of a cast, which is almost always redundant.
if (!Op->getType()->isFloatingPoint() &&
!CE->getType()->isFloatingPoint() &&
@@ -166,7 +166,7 @@
dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
if (CAT->getElementType() == SAT->getElementType())
return ConstantExpr::getGetElementPtr(
- (Constant*)cast<Constant>(CE->getOperand(0)), IdxList);
+ (Constant*)CE->getOperand(0), IdxList);
return 0;
}
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.37 llvm/lib/VMCore/Constants.cpp:1.38
--- llvm/lib/VMCore/Constants.cpp:1.37 Tue May 13 16:37:02 2003
+++ llvm/lib/VMCore/Constants.cpp Wed May 14 12:51:05 2003
@@ -411,30 +411,31 @@
}
}
-void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *To) {
- assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
+void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV) {
+ assert(isa<Constant>(ToV) && "Cannot make Constant refer to non-constant!");
+ Constant *To = cast<Constant>(ToV);
Constant *Replacement = 0;
if (getOpcode() == Instruction::GetElementPtr) {
std::vector<Constant*> Indices;
- Constant *Pointer = cast<Constant>(getOperand(0));
+ Constant *Pointer = getOperand(0);
Indices.reserve(getNumOperands()-1);
- if (Pointer == From) Pointer = cast<Constant>(To);
+ if (Pointer == From) Pointer = To;
for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
- Constant *Val = cast<Constant>(getOperand(i));
- if (Val == From) Val = cast<Constant>(To);
+ Constant *Val = getOperand(i);
+ if (Val == From) Val = To;
Indices.push_back(Val);
}
Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices);
} else if (getOpcode() == Instruction::Cast) {
assert(getOperand(0) == From && "Cast only has one use!");
- Replacement = ConstantExpr::getCast(cast<Constant>(To), getType());
+ Replacement = ConstantExpr::getCast(To, getType());
} else if (getNumOperands() == 2) {
- Constant *C1 = cast<Constant>(getOperand(0));
- Constant *C2 = cast<Constant>(getOperand(1));
- if (C1 == From) C1 = cast<Constant>(To);
- if (C2 == From) C2 = cast<Constant>(To);
+ Constant *C1 = getOperand(0);
+ Constant *C2 = getOperand(1);
+ if (C1 == From) C1 = To;
+ if (C2 == From) C2 = To;
Replacement = ConstantExpr::get(getOpcode(), C1, C2);
} else {
assert(0 && "Unknown ConstantExpr type!");
More information about the llvm-commits
mailing list