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
This commit is contained in:
Chris Lattner 2007-02-11 01:08:35 +00:00
parent f41916e75d
commit 046800a712
6 changed files with 23 additions and 34 deletions

View File

@ -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()) {

View File

@ -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

View File

@ -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

View File

@ -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<LoadInst>(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()) {

View File

@ -144,12 +144,12 @@ bool PruneEH::SimplifyFunction(Function *F) {
if (InvokeInst *II = dyn_cast<InvokeInst>(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<Value*>(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

View File

@ -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