From 046800a7125cd497613efc0e1ea15cb595666585 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 11 Feb 2007 01:08:35 +0000 Subject: [PATCH] simplify name juggling through the use of Value::takeName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34175 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/ArgumentPromotion.cpp | 6 ++--- .../IPO/DeadArgumentElimination.cpp | 22 +++++++------------ lib/Transforms/IPO/ExtractFunction.cpp | 5 ++--- lib/Transforms/IPO/GlobalOpt.cpp | 14 +++++------- lib/Transforms/IPO/PruneEH.cpp | 6 ++--- lib/Transforms/IPO/RaiseAllocations.cpp | 4 ++-- 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 3c57649f4e7..4c1b2c3f281 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -455,9 +455,7 @@ Function *ArgPromotion::DoPromotion(Function *F, if (!Call->use_empty()) { Call->replaceAllUsesWith(New); - std::string Name = Call->getName(); - Call->setName(""); - New->setName(Name); + New->takeName(Call); } // Finally, remove the old call from the program, reducing the use-count of @@ -479,7 +477,7 @@ Function *ArgPromotion::DoPromotion(Function *F, // If this is an unmodified argument, move the name and users over to the // new version. I->replaceAllUsesWith(I2); - I2->setName(I->getName()); + I2->takeName(I); AA.replaceWithNewValue(I, I2); ++I2; } else if (I->use_empty()) { diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index b39b2508d05..5963c9e800e 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -150,10 +150,10 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { unsigned NumArgs = Params.size(); // Create the new function body and insert it into the module... - std::string Name = Fn.getName(); Fn.setName(""); - Function *NF = new Function(NFTy, Fn.getLinkage(), Name); + Function *NF = new Function(NFTy, Fn.getLinkage()); NF->setCallingConv(Fn.getCallingConv()); Fn.getParent()->getFunctionList().insert(&Fn, NF); + NF->takeName(&Fn); // Loop over all of the callers of the function, transforming the call sites // to pass in a smaller number of arguments into the new function. @@ -182,11 +182,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { if (!Call->use_empty()) Call->replaceAllUsesWith(Constant::getNullValue(Call->getType())); - if (Call->hasName()) { - std::string Name = Call->getName(); - Call->setName(""); - New->setName(Name); - } + New->takeName(Call); // Finally, remove the old call from the program, reducing the use-count of // F. @@ -206,7 +202,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { I2 = NF->arg_begin(); I != E; ++I, ++I2) { // Move the name and users over to the new version. I->replaceAllUsesWith(I2); - I2->setName(I->getName()); + I2->takeName(I); } // Finally, nuke the old function. @@ -509,10 +505,10 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); // Create the new function body and insert it into the module... - std::string Name = F->getName(); F->setName(""); - Function *NF = new Function(NFTy, F->getLinkage(), Name); + Function *NF = new Function(NFTy, F->getLinkage()); NF->setCallingConv(F->getCallingConv()); F->getParent()->getFunctionList().insert(F, NF); + NF->takeName(F); // Loop over all of the callers of the function, transforming the call sites // to pass in a smaller number of arguments into the new function. @@ -554,9 +550,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { Call->replaceAllUsesWith(Constant::getNullValue(Call->getType())); else { Call->replaceAllUsesWith(New); - std::string Name = Call->getName(); - Call->setName(""); - New->setName(Name); + New->takeName(Call); } } @@ -581,7 +575,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { // If this is a live argument, move the name and users over to the new // version. I->replaceAllUsesWith(I2); - I2->setName(I->getName()); + I2->takeName(I); ++I2; } else { // If this argument is dead, replace any uses of it with null constants diff --git a/lib/Transforms/IPO/ExtractFunction.cpp b/lib/Transforms/IPO/ExtractFunction.cpp index ae1eb224783..afaf38d2808 100644 --- a/lib/Transforms/IPO/ExtractFunction.cpp +++ b/lib/Transforms/IPO/ExtractFunction.cpp @@ -90,16 +90,15 @@ namespace { for (Module::iterator I = M.begin(); ; ++I) { if (&*I != Named) { Function *New = new Function(I->getFunctionType(), - GlobalValue::ExternalLinkage, - I->getName()); + GlobalValue::ExternalLinkage); New->setCallingConv(I->getCallingConv()); - I->setName(""); // Remove Old name // If it's not the named function, delete the body of the function I->dropAllReferences(); M.getFunctionList().push_back(New); NewFunctions.push_back(New); + New->takeName(I); } if (&*I == Last) break; // Stop after processing the last function diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 5be5ace315f..f5b12712f3a 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -1189,14 +1189,13 @@ static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { } else if (!UI->use_empty()) { // Change the load into a load of bool then a select. LoadInst *LI = cast(UI); - - std::string Name = LI->getName(); LI->setName(""); - LoadInst *NLI = new LoadInst(NewGV, Name+".b", LI); + LoadInst *NLI = new LoadInst(NewGV, LI->getName()+".b", LI); Value *NSI; if (IsOneZero) - NSI = new ZExtInst(NLI, LI->getType(), Name, LI); + NSI = new ZExtInst(NLI, LI->getType(), "", LI); else - NSI = new SelectInst(NLI, OtherVal, InitVal, Name, LI); + NSI = new SelectInst(NLI, OtherVal, InitVal, "", LI); + NSI->takeName(LI); LI->replaceAllUsesWith(NSI); } UI->eraseFromParent(); @@ -1519,10 +1518,9 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, // Create the new global and insert it next to the existing list. GlobalVariable *NGV = new GlobalVariable(CA->getType(), GCL->isConstant(), - GCL->getLinkage(), CA, - GCL->getName()); - GCL->setName(""); + GCL->getLinkage(), CA); GCL->getParent()->getGlobalList().insert(GCL, NGV); + NGV->takeName(GCL); // Nuke the old list, replacing any uses with the new one. if (!GCL->use_empty()) { diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index d6043a1df5b..271a8fa0d06 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -144,12 +144,12 @@ bool PruneEH::SimplifyFunction(Function *F) { if (InvokeInst *II = dyn_cast(BB->getTerminator())) if (Function *F = II->getCalledFunction()) if (DoesNotUnwind.count(CG[F])) { - // Insert a call instruction before the invoke... - std::string Name = II->getName(); II->setName(""); + // Insert a call instruction before the invoke. CallInst *Call = new CallInst(II->getCalledValue(), std::vector(II->op_begin()+3, II->op_end()), - Name, II); + "", II); + Call->takeName(II); Call->setCallingConv(II->getCallingConv()); // Anything that used the value produced by the invoke instruction diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp index b689de70830..aeb41738419 100644 --- a/lib/Transforms/IPO/RaiseAllocations.cpp +++ b/lib/Transforms/IPO/RaiseAllocations.cpp @@ -164,8 +164,8 @@ bool RaiseAllocations::runOnModule(Module &M) { CastInst::createIntegerCast(Source, Type::Int32Ty, false/*ZExt*/, "MallocAmtCast", I); - std::string Name(I->getName()); I->setName(""); - MallocInst *MI = new MallocInst(Type::Int8Ty, Source, Name, I); + MallocInst *MI = new MallocInst(Type::Int8Ty, Source, "", I); + MI->takeName(I); I->replaceAllUsesWith(MI); // If the old instruction was an invoke, add an unconditional branch -- 2.34.1