}
// 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) {
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;
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;
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);
}
}
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)));
}
// (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)
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);
}
}
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);
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
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 {
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
}
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)) {
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) {
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;
}
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;
}
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();