Do not pass in the same argument to the extracted function more than once, and
authorChris Lattner <sabre@nondot.org>
Wed, 12 May 2004 16:26:18 +0000 (16:26 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 May 2004 16:26:18 +0000 (16:26 +0000)
give the extracted function a more useful name than just foo_code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13493 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/CodeExtractor.cpp

index e3259217a0d544dd86c8c65693cbdb9e3add32d6..4d1093b739dac43d71b805e637e0ef65d2bb61c7 100644 (file)
@@ -226,6 +226,12 @@ void CodeExtractor::findInputsOutputs(Values &inputs, Values &outputs) {
   } // for: basic blocks
 
   NumExitBlocks = ExitBlocks.size();
+
+  // Eliminate duplicates.
+  std::sort(inputs.begin(), inputs.end());
+  inputs.erase(std::unique(inputs.begin(), inputs.end()), inputs.end());
+  std::sort(outputs.begin(), outputs.end());
+  outputs.erase(std::unique(outputs.begin(), outputs.end()), outputs.end());
 }
 
 /// constructFunction - make a function based on inputs and outputs, as follows:
@@ -284,7 +290,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
   // Create the new function
   Function *newFunction = new Function(funcType,
                                        GlobalValue::InternalLinkage,
-                                       oldFunction->getName() + "_code", M);
+                                       oldFunction->getName() + "_" +
+                                       header->getName(), M);
   newFunction->getBasicBlockList().push_back(newRootNode);
 
   // Create an iterator to name all of the arguments we inserted.