[llvm-commits] CVS: llvm/lib/Transforms/Scalar/ADCE.cpp IndVarSimplify.cpp InstructionCombining.cpp Reassociate.cpp ScalarReplAggregates.cpp TailRecursionElimination.cpp
Chris Lattner
sabre at nondot.org
Sat Feb 10 17:23:19 PST 2007
Changes in directory llvm/lib/Transforms/Scalar:
ADCE.cpp updated: 1.102 -> 1.103
IndVarSimplify.cpp updated: 1.109 -> 1.110
InstructionCombining.cpp updated: 1.628 -> 1.629
Reassociate.cpp updated: 1.74 -> 1.75
ScalarReplAggregates.cpp updated: 1.71 -> 1.72
TailRecursionElimination.cpp updated: 1.28 -> 1.29
---
Log message:
Simplify code by using value::takename
---
Diffs of the changes: (+61 -71)
ADCE.cpp | 4 -
IndVarSimplify.cpp | 15 ++-----
InstructionCombining.cpp | 89 ++++++++++++++++++++-----------------------
Reassociate.cpp | 14 ++----
ScalarReplAggregates.cpp | 5 --
TailRecursionElimination.cpp | 5 +-
6 files changed, 61 insertions(+), 71 deletions(-)
Index: llvm/lib/Transforms/Scalar/ADCE.cpp
diff -u llvm/lib/Transforms/Scalar/ADCE.cpp:1.102 llvm/lib/Transforms/Scalar/ADCE.cpp:1.103
--- llvm/lib/Transforms/Scalar/ADCE.cpp:1.102 Mon Feb 5 17:32:05 2007
+++ llvm/lib/Transforms/Scalar/ADCE.cpp Sat Feb 10 19:23:03 2007
@@ -189,8 +189,8 @@
// The function cannot unwind. Convert it to a call with a branch
// after it to the normal destination.
std::vector<Value*> Args(II->op_begin()+3, II->op_end());
- std::string Name = II->getName(); II->setName("");
- CallInst *NewCall = new CallInst(F, Args, Name, II);
+ CallInst *NewCall = new CallInst(F, Args, "", II);
+ NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
II->replaceAllUsesWith(NewCall);
new BranchInst(II->getNormalDest(), II);
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.109 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.110
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.109 Mon Feb 5 17:32:05 2007
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Sat Feb 10 19:23:03 2007
@@ -195,10 +195,10 @@
if (!PN->use_empty()) {
BasicBlock::iterator InsertPos = PN; ++InsertPos;
while (isa<PHINode>(InsertPos)) ++InsertPos;
- std::string Name = PN->getName(); PN->setName("");
Value *PreInc =
new GetElementPtrInst(PN->getIncomingValue(PreheaderIdx),
- NewPhi, Name, InsertPos);
+ NewPhi, "", InsertPos);
+ PreInc->takeName(PN);
PN->replaceAllUsesWith(PreInc);
}
@@ -556,9 +556,7 @@
PN->getType());
DOUT << "INDVARS: Rewrote IV '" << *IndVars.back().second << "' " << *PN
<< " into = " << *NewVal << "\n";
- std::string Name = PN->getName();
- PN->setName("");
- NewVal->setName(Name);
+ NewVal->takeName(PN);
// Replace the old PHI Node with the inserted computation.
PN->replaceAllUsesWith(NewVal);
@@ -581,11 +579,8 @@
SCEVHandle SH = SE->getSCEV(I);
Value *V = Rewriter.expandCodeFor(SH, I, I->getType());
if (V != I) {
- if (isa<Instruction>(V)) {
- std::string Name = I->getName();
- I->setName("");
- V->setName(Name);
- }
+ if (isa<Instruction>(V))
+ V->takeName(I);
I->replaceAllUsesWith(V);
DeadInsts.insert(I);
++NumRemoved;
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.628 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.629
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.628 Sun Feb 4 23:57:49 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Feb 10 19:23:03 2007
@@ -1664,10 +1664,10 @@
}
// Okay, we can do the transformation: create the new PHI node.
- PHINode *NewPN = new PHINode(I.getType(), I.getName());
- I.setName("");
+ PHINode *NewPN = new PHINode(I.getType(), "");
NewPN->reserveOperandSpace(PN->getNumOperands()/2);
InsertNewInstBefore(NewPN, *PN);
+ NewPN->takeName(PN);
// Next, add all of the operands to the PHI.
if (I.getNumOperands() == 2) {
@@ -2814,9 +2814,9 @@
case Instruction::Xor:
if (Op->hasOneUse()) {
// (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
- std::string OpName = Op->getName(); Op->setName("");
- Instruction *And = BinaryOperator::createAnd(X, AndRHS, OpName);
+ Instruction *And = BinaryOperator::createAnd(X, AndRHS);
InsertNewInstBefore(And, TheAnd);
+ And->takeName(Op);
return BinaryOperator::createXor(And, Together);
}
break;
@@ -2826,9 +2826,9 @@
if (Op->hasOneUse() && Together != OpRHS) {
// (X | C1) & C2 --> (X | (C1&C2)) & C2
- std::string Op0Name = Op->getName(); Op->setName("");
- Instruction *Or = BinaryOperator::createOr(X, Together, Op0Name);
+ Instruction *Or = BinaryOperator::createOr(X, Together);
InsertNewInstBefore(Or, TheAnd);
+ Or->takeName(Op);
return BinaryOperator::createAnd(Or, AndRHS);
}
break;
@@ -2859,10 +2859,10 @@
TheAnd.setOperand(0, X);
return &TheAnd;
} else {
- std::string Name = Op->getName(); Op->setName("");
// Pull the XOR out of the AND.
- Instruction *NewAnd = BinaryOperator::createAnd(X, AndRHS, Name);
+ Instruction *NewAnd = BinaryOperator::createAnd(X, AndRHS);
InsertNewInstBefore(NewAnd, TheAnd);
+ NewAnd->takeName(Op);
return BinaryOperator::createXor(NewAnd, AndRHS);
}
}
@@ -3554,17 +3554,17 @@
ConstantInt *C1 = 0; Value *X = 0;
// (X & C1) | C2 --> (X | C2) & (C1|C2)
if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
- Instruction *Or = BinaryOperator::createOr(X, RHS, Op0->getName());
- Op0->setName("");
+ Instruction *Or = BinaryOperator::createOr(X, RHS);
InsertNewInstBefore(Or, I);
+ Or->takeName(Op0);
return BinaryOperator::createAnd(Or, ConstantExpr::getOr(RHS, C1));
}
// (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
- std::string Op0Name = Op0->getName(); Op0->setName("");
- Instruction *Or = BinaryOperator::createOr(X, RHS, Op0Name);
+ Instruction *Or = BinaryOperator::createOr(X, RHS);
InsertNewInstBefore(Or, I);
+ Or->takeName(Op0);
return BinaryOperator::createXor(Or,
ConstantExpr::getAnd(C1, ConstantExpr::getNot(RHS)));
}
@@ -3601,17 +3601,19 @@
// (X^C)|Y -> (X|Y)^C iff Y&C == 0
if (Op0->hasOneUse() && match(Op0, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
MaskedValueIsZero(Op1, C1->getZExtValue())) {
- Instruction *NOr = BinaryOperator::createOr(A, Op1, Op0->getName());
- Op0->setName("");
- return BinaryOperator::createXor(InsertNewInstBefore(NOr, I), C1);
+ Instruction *NOr = BinaryOperator::createOr(A, Op1);
+ InsertNewInstBefore(NOr, I);
+ NOr->takeName(Op0);
+ return BinaryOperator::createXor(NOr, C1);
}
// Y|(X^C) -> (X|Y)^C iff Y&C == 0
if (Op1->hasOneUse() && match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
MaskedValueIsZero(Op0, C1->getZExtValue())) {
- Instruction *NOr = BinaryOperator::createOr(A, Op0, Op1->getName());
- Op0->setName("");
- return BinaryOperator::createXor(InsertNewInstBefore(NOr, I), C1);
+ Instruction *NOr = BinaryOperator::createOr(A, Op0);
+ InsertNewInstBefore(NOr, I);
+ NOr->takeName(Op0);
+ return BinaryOperator::createXor(NOr, C1);
}
// (A & C1)|(B & C2)
@@ -4947,9 +4949,9 @@
else if (Value *NegVal = dyn_castNegVal(BOp0))
return new ICmpInst(I.getPredicate(), NegVal, BOp1);
else if (BO->hasOneUse()) {
- Instruction *Neg = BinaryOperator::createNeg(BOp1, BO->getName());
- BO->setName("");
+ Instruction *Neg = BinaryOperator::createNeg(BOp1);
InsertNewInstBefore(Neg, I);
+ Neg->takeName(BO);
return new ICmpInst(I.getPredicate(), BOp0, Neg);
}
}
@@ -5592,10 +5594,9 @@
Constant *NewRHS = ConstantExpr::get(I.getOpcode(), Op0C, Op1);
Instruction *NewShift =
- BinaryOperator::create(I.getOpcode(), Op0BO->getOperand(0), Op1,
- Op0BO->getName());
- Op0BO->setName("");
+ BinaryOperator::create(I.getOpcode(), Op0BO->getOperand(0), Op1);
InsertNewInstBefore(NewShift, I);
+ NewShift->takeName(Op0BO);
return BinaryOperator::create(Op0BO->getOpcode(), NewShift,
NewRHS);
@@ -5859,13 +5860,13 @@
Amt = InsertNewInstBefore(Tmp, AI);
}
- std::string Name = AI.getName(); AI.setName("");
AllocationInst *New;
if (isa<MallocInst>(AI))
- New = new MallocInst(CastElTy, Amt, AI.getAlignment(), Name);
+ New = new MallocInst(CastElTy, Amt, AI.getAlignment());
else
- New = new AllocaInst(CastElTy, Amt, AI.getAlignment(), Name);
+ New = new AllocaInst(CastElTy, Amt, AI.getAlignment());
InsertNewInstBefore(New, AI);
+ New->takeName(&AI);
// If the allocation has multiple uses, insert a cast and change all things
// that used it to use the new cast. This will also hack on CI, but it will
@@ -6849,11 +6850,10 @@
if (OpToFold) {
Constant *C = GetSelectFoldableConstant(TVI);
- std::string Name = TVI->getName(); TVI->setName("");
Instruction *NewSel =
- new SelectInst(SI.getCondition(), TVI->getOperand(2-OpToFold), C,
- Name);
+ new SelectInst(SI.getCondition(), TVI->getOperand(2-OpToFold), C);
InsertNewInstBefore(NewSel, SI);
+ NewSel->takeName(TVI);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI))
return BinaryOperator::create(BO->getOpcode(), FalseVal, NewSel);
else {
@@ -6875,12 +6875,10 @@
if (OpToFold) {
Constant *C = GetSelectFoldableConstant(FVI);
- std::string Name = FVI->getName();
- FVI->setName("");
Instruction *NewSel =
- new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold),
- Name);
+ new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold));
InsertNewInstBefore(NewSel, SI);
+ NewSel->takeName(FVI);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI))
return BinaryOperator::create(BO->getOpcode(), TrueVal, NewSel);
else
@@ -7349,7 +7347,7 @@
}
if (FT->getReturnType() == Type::VoidTy)
- Caller->setName(""); // Void type should not have a name...
+ Caller->setName(""); // Void type should not have a name.
Instruction *NC;
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
@@ -7363,7 +7361,7 @@
cast<CallInst>(NC)->setCallingConv(cast<CallInst>(Caller)->getCallingConv());
}
- // Insert a cast of the return type as necessary...
+ // Insert a cast of the return type as necessary.
Value *NV = NC;
if (Caller->getType() != NV->getType() && !Caller->use_empty()) {
if (NV->getType() != Type::VoidTy) {
@@ -8459,16 +8457,16 @@
if ((FPred == FCmpInst::FCMP_ONE || FPred == FCmpInst::FCMP_OLE ||
FPred == FCmpInst::FCMP_OGE) && BI.getCondition()->hasOneUse()) {
FCmpInst *I = cast<FCmpInst>(BI.getCondition());
- std::string Name = I->getName(); I->setName("");
FCmpInst::Predicate NewPred = FCmpInst::getInversePredicate(FPred);
- Value *NewSCC = new FCmpInst(NewPred, X, Y, Name, I);
+ Instruction *NewSCC = new FCmpInst(NewPred, X, Y, "", I);
+ NewSCC->takeName(I);
// Swap Destinations and condition...
BI.setCondition(NewSCC);
BI.setSuccessor(0, FalseDest);
BI.setSuccessor(1, TrueDest);
removeFromWorkList(I);
- I->getParent()->getInstList().erase(I);
- WorkList.push_back(cast<Instruction>(NewSCC));
+ I->eraseFromParent();
+ WorkList.push_back(NewSCC);
return &BI;
}
@@ -8480,16 +8478,16 @@
IPred == ICmpInst::ICMP_SLE || IPred == ICmpInst::ICMP_UGE ||
IPred == ICmpInst::ICMP_SGE) && BI.getCondition()->hasOneUse()) {
ICmpInst *I = cast<ICmpInst>(BI.getCondition());
- std::string Name = I->getName(); I->setName("");
ICmpInst::Predicate NewPred = ICmpInst::getInversePredicate(IPred);
- Value *NewSCC = new ICmpInst(NewPred, X, Y, Name, I);
+ Instruction *NewSCC = new ICmpInst(NewPred, X, Y, "", I);
+ NewSCC->takeName(I);
// Swap Destinations and condition...
BI.setCondition(NewSCC);
BI.setSuccessor(0, FalseDest);
BI.setSuccessor(1, TrueDest);
removeFromWorkList(I);
- I->getParent()->getInstList().erase(I);
- WorkList.push_back(cast<Instruction>(NewSCC));
+ I->eraseFromParent();;
+ WorkList.push_back(NewSCC);
return &BI;
}
@@ -9246,9 +9244,8 @@
WorkList.push_back(Result);
AddUsersToWorkList(*Result);
- // Move the name to the new instruction first...
- std::string OldName = I->getName(); I->setName("");
- Result->setName(OldName);
+ // Move the name to the new instruction first.
+ Result->takeName(I);
// Insert the new instruction into the basic block...
BasicBlock *InstParent = I->getParent();
Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.74 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.75
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.74 Mon Feb 5 17:32:05 2007
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp Sat Feb 10 19:23:03 2007
@@ -189,9 +189,8 @@
static Instruction *LowerNegateToMultiply(Instruction *Neg) {
Constant *Cst = ConstantInt::getAllOnesValue(Neg->getType());
- std::string NegName = Neg->getName(); Neg->setName("");
- Instruction *Res = BinaryOperator::createMul(Neg->getOperand(1), Cst, NegName,
- Neg);
+ Instruction *Res = BinaryOperator::createMul(Neg->getOperand(1), Cst, "",Neg);
+ Res->takeName(Neg);
Neg->replaceAllUsesWith(Res);
Neg->eraseFromParent();
return Res;
@@ -405,11 +404,10 @@
// Calculate the negative value of Operand 1 of the sub instruction...
// and set it as the RHS of the add instruction we just made...
//
- std::string Name = Sub->getName();
- Sub->setName("");
Value *NegVal = NegateValue(Sub->getOperand(1), Sub);
Instruction *New =
- BinaryOperator::createAdd(Sub->getOperand(0), NegVal, Name, Sub);
+ BinaryOperator::createAdd(Sub->getOperand(0), NegVal, "", Sub);
+ New->takeName(Sub);
// Everyone now refers to the add instruction.
Sub->replaceAllUsesWith(New);
@@ -432,9 +430,9 @@
Constant *MulCst = ConstantInt::get(Shl->getType(), 1);
MulCst = ConstantExpr::getShl(MulCst, cast<Constant>(Shl->getOperand(1)));
- std::string Name = Shl->getName(); Shl->setName("");
Instruction *Mul = BinaryOperator::createMul(Shl->getOperand(0), MulCst,
- Name, Shl);
+ "", Shl);
+ Mul->takeName(Shl);
Shl->replaceAllUsesWith(Mul);
Shl->eraseFromParent();
return Mul;
Index: llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp
diff -u llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.71 llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.72
--- llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.71 Sat Feb 10 13:55:17 2007
+++ llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp Sat Feb 10 19:23:03 2007
@@ -224,12 +224,11 @@
// getelement ptr instruction to finish the indexing. This may be
// expanded itself once the worklist is rerun.
//
- std::string OldName = GEPI->getName(); // Steal the old name.
std::vector<Value*> NewArgs;
NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
NewArgs.insert(NewArgs.end(), GEPI->op_begin()+3, GEPI->op_end());
- GEPI->setName("");
- RepValue = new GetElementPtrInst(AllocaToUse, NewArgs, OldName, GEPI);
+ RepValue = new GetElementPtrInst(AllocaToUse, NewArgs, "", GEPI);
+ RepValue->takeName(GEPI);
}
// Move all of the users over to the new GEP.
Index: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
diff -u llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.28 llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.29
--- llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.28 Mon Feb 5 17:32:05 2007
+++ llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Sat Feb 10 19:23:03 2007
@@ -360,8 +360,9 @@
// create the new entry block, allowing us to branch back to the old entry.
if (OldEntry == 0) {
OldEntry = &F->getEntryBlock();
- std::string OldName = OldEntry->getName(); OldEntry->setName("tailrecurse");
- BasicBlock *NewEntry = new BasicBlock(OldName, F, OldEntry);
+ BasicBlock *NewEntry = new BasicBlock("", F, OldEntry);
+ NewEntry->takeName(OldEntry);
+ OldEntry->setName("tailrecurse");
new BranchInst(OldEntry, NewEntry);
// If this tail call is marked 'tail' and if there are any allocas in the
More information about the llvm-commits
mailing list