[llvm] llvm-reduce: Use takeName instead of setName when cloning functions (PR #133393)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 01:05:08 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133393

None

>From 4b6268e8976f1a17ed669c5c2722dfb90aa2d328 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Mar 2025 15:01:30 +0700
Subject: [PATCH] llvm-reduce: Use takeName instead of setName when cloning
 functions

---
 llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp      | 4 +---
 llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
index 5b1363d3293a6..5d9e9bae9c61e 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -107,15 +107,13 @@ static void extractArgumentsFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
 
     auto *ClonedFunc = CloneFunction(F, VMap);
     // In order to preserve function order, we move Clone after old Function
+    ClonedFunc->takeName(F);
     ClonedFunc->removeFromParent();
     Program.getFunctionList().insertAfter(F->getIterator(), ClonedFunc);
 
     replaceFunctionCalls(*F, *ClonedFunc, ArgIndexesToKeep);
-    // Rename Cloned Function to Old's name
-    std::string FName = std::string(F->getName());
     F->replaceAllUsesWith(ClonedFunc);
     F->eraseFromParent();
-    ClonedFunc->setName(FName);
   }
 }
 
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
index 66d4bd3048171..32bceb74afa70 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
@@ -184,11 +184,9 @@ static void substituteOperandWithArgument(Function *OldF,
   // Replace all OldF uses with NewF.
   replaceFunctionCalls(OldF, NewF);
 
-  // Rename NewF to OldF's name.
-  std::string FName = OldF->getName().str();
+  NewF->takeName(OldF);
   OldF->replaceAllUsesWith(NewF);
   OldF->eraseFromParent();
-  NewF->setName(FName);
 }
 
 static void reduceOperandsToArgs(Oracle &O, ReducerWorkItem &WorkItem) {



More information about the llvm-commits mailing list