[llvm-commits] CVS: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp LowerInvoke.cpp LowerSelect.cpp SimplifyCFG.cpp

Chris Lattner sabre at nondot.org
Sat Feb 10 17:38:07 PST 2007



Changes in directory llvm/lib/Transforms/Utils:

BasicBlockUtils.cpp updated: 1.15 -> 1.16
LowerInvoke.cpp updated: 1.51 -> 1.52
LowerSelect.cpp updated: 1.10 -> 1.11
SimplifyCFG.cpp updated: 1.115 -> 1.116
---
Log message:

simplify code by using Value::takeName


---
Diffs of the changes:  (+26 -32)

 BasicBlockUtils.cpp |    8 +++-----
 LowerInvoke.cpp     |    8 ++++----
 LowerSelect.cpp     |    4 ++--
 SimplifyCFG.cpp     |   38 +++++++++++++++++---------------------
 4 files changed, 26 insertions(+), 32 deletions(-)


Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff -u llvm/lib/Transforms/Utils/BasicBlockUtils.cpp:1.15 llvm/lib/Transforms/Utils/BasicBlockUtils.cpp:1.16
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp:1.15	Fri May 19 14:09:46 2006
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp	Sat Feb 10 19:37:51 2007
@@ -29,14 +29,12 @@
   // Replaces all of the uses of the instruction with uses of the value
   I.replaceAllUsesWith(V);
 
-  std::string OldName = I.getName();
+  // Make sure to propagate a name if there is one already.
+  if (I.hasName() && !V->hasName())
+    V->takeName(&I);
 
   // Delete the unnecessary instruction now...
   BI = BIL.erase(BI);
-
-  // Make sure to propagate a name if there is one already.
-  if (!OldName.empty() && !V->hasName())
-    V->setName(OldName);
 }
 
 


Index: llvm/lib/Transforms/Utils/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.51 llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.52
--- llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.51	Sat Feb  3 18:40:42 2007
+++ llvm/lib/Transforms/Utils/LowerInvoke.cpp	Sat Feb 10 19:37:51 2007
@@ -201,10 +201,10 @@
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
       // Insert a normal call instruction...
-      std::string Name = II->getName(); II->setName("");
       CallInst *NewCall = new CallInst(II->getCalledValue(),
                                        std::vector<Value*>(II->op_begin()+3,
-                                                       II->op_end()), Name, II);
+                                                       II->op_end()), "", II);
+      NewCall->takeName(II);
       NewCall->setCallingConv(II->getCallingConv());
       II->replaceAllUsesWith(NewCall);
 
@@ -258,11 +258,11 @@
   CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
   
   // Insert a normal call instruction.
-  std::string Name = II->getName(); II->setName("");
   CallInst *NewCall = new CallInst(II->getCalledValue(),
                                    std::vector<Value*>(II->op_begin()+3,
-                                                       II->op_end()), Name,
+                                                       II->op_end()), "",
                                    II);
+  NewCall->takeName(II);
   NewCall->setCallingConv(II->getCallingConv());
   II->replaceAllUsesWith(NewCall);
   


Index: llvm/lib/Transforms/Utils/LowerSelect.cpp
diff -u llvm/lib/Transforms/Utils/LowerSelect.cpp:1.10 llvm/lib/Transforms/Utils/LowerSelect.cpp:1.11
--- llvm/lib/Transforms/Utils/LowerSelect.cpp:1.10	Mon Feb  5 17:32:05 2007
+++ llvm/lib/Transforms/Utils/LowerSelect.cpp	Sat Feb 10 19:37:51 2007
@@ -85,8 +85,8 @@
           new BranchInst(NewTrue, NewCont, SI->getCondition(), BB);
 
           // Create a new PHI node in the cont block with the entries we need.
-          std::string Name = SI->getName(); SI->setName("");
-          PHINode *PN = new PHINode(SI->getType(), Name, NewCont->begin());
+          PHINode *PN = new PHINode(SI->getType(), "", NewCont->begin());
+          PN->takeName(SI);
           PN->addIncoming(SI->getTrueValue(), NewTrue);
           PN->addIncoming(SI->getFalseValue(), BB);
 


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.115 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.116
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.115	Tue Jan 30 17:46:24 2007
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp	Sat Feb 10 19:37:51 2007
@@ -213,12 +213,9 @@
   }
     
   // Everything that jumped to BB now goes to Succ.
-  std::string OldName = BB->getName();
   BB->replaceAllUsesWith(Succ);
+  if (!Succ->hasName()) Succ->takeName(BB);
   BB->eraseFromParent();              // Delete the old basic block.
-  
-  if (!OldName.empty() && !Succ->hasName())  // Transfer name if we can
-    Succ->setName(OldName);
   return true;
 }
 
@@ -881,7 +878,7 @@
   if (NT->getType() != Type::VoidTy) {
     I1->replaceAllUsesWith(NT);
     I2->replaceAllUsesWith(NT);
-    NT->setName(I1->getName());
+    NT->takeName(I1);
   }
 
   // Hoisting one of the terminators from our successor is a great thing.
@@ -1154,9 +1151,10 @@
     Value *FalseVal =
       PN->getIncomingValue(PN->getIncomingBlock(0) == IfTrue);
     
-    std::string Name = PN->getName(); PN->setName("");
-    PN->replaceAllUsesWith(new SelectInst(IfCond, TrueVal, FalseVal,
-                                          Name, AfterPHIIt));
+    Value *NV = new SelectInst(IfCond, TrueVal, FalseVal, "", AfterPHIIt);
+    PN->replaceAllUsesWith(NV);
+    NV->takeName(PN);
+    
     BB->getInstList().erase(PN);
   }
   return true;
@@ -1474,9 +1472,9 @@
                   // Clone Cond into the predecessor basic block, and or/and the
                   // two conditions together.
                   Instruction *New = Cond->clone();
-                  New->setName(Cond->getName());
-                  Cond->setName(Cond->getName()+".old");
                   PredBlock->getInstList().insert(PBI, New);
+                  New->takeName(Cond);
+                  Cond->setName(New->getName()+".old");
                   Instruction::BinaryOps Opcode =
                     PBI->getSuccessor(0) == TrueDest ?
                     Instruction::Or : Instruction::And;
@@ -1800,28 +1798,26 @@
     //
     while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
       PN->replaceAllUsesWith(PN->getIncomingValue(0));
-      BB->getInstList().pop_front();  // Delete the phi node...
+      BB->getInstList().pop_front();  // Delete the phi node.
     }
 
-    // Delete the unconditional branch from the predecessor...
+    // Delete the unconditional branch from the predecessor.
     OnlyPred->getInstList().pop_back();
 
-    // Move all definitions in the successor to the predecessor...
+    // Move all definitions in the successor to the predecessor.
     OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
 
     // Make all PHI nodes that referred to BB now refer to Pred as their
-    // source...
+    // source.
     BB->replaceAllUsesWith(OnlyPred);
 
-    std::string OldName = BB->getName();
-
-    // Erase basic block from the function...
+    // Inherit predecessors name if it exists.
+    if (!OnlyPred->hasName())
+      OnlyPred->takeName(BB);
+    
+    // Erase basic block from the function.
     M->getBasicBlockList().erase(BB);
 
-    // Inherit predecessors name if it exists...
-    if (!OldName.empty() && !OnlyPred->hasName())
-      OnlyPred->setName(OldName);
-
     return true;
   }
 






More information about the llvm-commits mailing list