simplify name juggling through the use of Value::takeName.
authorChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 01:08:35 +0000 (01:08 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 01:08:35 +0000 (01:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34175 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/ArgumentPromotion.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/IPO/ExtractFunction.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/PruneEH.cpp
lib/Transforms/IPO/RaiseAllocations.cpp

index 3c57649f4e7c0d3adf2a4f06b9853ccdc5f2172d..4c1b2c3f28137c97177c7fcc1ac60c2f66e78657 100644 (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()) {
index b39b2508d05f403b88286f402e9e03673acb3928..5963c9e800eeac95cdb126d62f3befb08674c6fd 100644 (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
index ae1eb224783a1f9b5ce6e01c8c49279d02489cd7..afaf38d280824dd6f7d14bdf3342ba94c42ed4dd 100644 (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
index 5be5ace315f0d315731b07250f9824577b628905..f5b12712f3aec2bbe7a5e37e0df2505a3a5e69c1 100644 (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()) {
index d6043a1df5b057a3198fcb229ccf1ecf8f04836c..271a8fa0d0694bab90c7874e15f4d7d1fa6774dc 100644 (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
index b689de70830421188e2512f571763bf624a98897..aeb41738419c4a9874e7bf1ecb1059485ff81004 100644 (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