[llvm] r255078 - Return a std::unique_ptr from CloneModule. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 8 15:57:17 PST 2015
Author: rafael
Date: Tue Dec 8 17:57:17 2015
New Revision: 255078
URL: http://llvm.org/viewvc/llvm-project?rev=255078&view=rev
Log:
Return a std::unique_ptr from CloneModule. NFC.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/Cloning.h
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
llvm/trunk/tools/bugpoint/CrashDebugger.cpp
llvm/trunk/tools/bugpoint/ExtractFunction.cpp
llvm/trunk/tools/bugpoint/Miscompilation.cpp
llvm/trunk/unittests/Transforms/Utils/Cloning.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/Cloning.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Cloning.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Cloning.h Tue Dec 8 17:57:17 2015
@@ -48,16 +48,16 @@ class AllocaInst;
class AssumptionCacheTracker;
class DominatorTree;
-/// CloneModule - Return an exact copy of the specified module
+/// Return an exact copy of the specified module
///
-Module *CloneModule(const Module *M);
-Module *CloneModule(const Module *M, ValueToValueMapTy &VMap);
+std::unique_ptr<Module> CloneModule(const Module *M);
+std::unique_ptr<Module> CloneModule(const Module *M, ValueToValueMapTy &VMap);
/// Return a copy of the specified module. The ShouldCloneDefinition function
/// controls whether a specific GlobalValue's definition is cloned. If the
/// function returns false, the module copy will contain an external reference
/// in place of the global definition.
-Module *
+std::unique_ptr<Module>
CloneModule(const Module *M, ValueToValueMapTy &VMap,
std::function<bool(const GlobalValue *)> ShouldCloneDefinition);
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Tue Dec 8 17:57:17 2015
@@ -20,27 +20,28 @@
#include "llvm-c/Core.h"
using namespace llvm;
-/// CloneModule - Return an exact copy of the specified module. This is not as
-/// easy as it might seem because we have to worry about making copies of global
-/// variables and functions, and making their (initializers and references,
-/// respectively) refer to the right globals.
+/// This is not as easy as it might seem because we have to worry about making
+/// copies of global variables and functions, and making their (initializers and
+/// references, respectively) refer to the right globals.
///
-Module *llvm::CloneModule(const Module *M) {
+std::unique_ptr<Module> llvm::CloneModule(const Module *M) {
// Create the value map that maps things from the old module over to the new
// module.
ValueToValueMapTy VMap;
return CloneModule(M, VMap);
}
-Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
+std::unique_ptr<Module> llvm::CloneModule(const Module *M,
+ ValueToValueMapTy &VMap) {
return CloneModule(M, VMap, [](const GlobalValue *GV) { return true; });
}
-Module *llvm::CloneModule(
+std::unique_ptr<Module> llvm::CloneModule(
const Module *M, ValueToValueMapTy &VMap,
std::function<bool(const GlobalValue *)> ShouldCloneDefinition) {
// First off, we need to create the new module.
- Module *New = new Module(M->getModuleIdentifier(), M->getContext());
+ std::unique_ptr<Module> New =
+ llvm::make_unique<Module>(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
@@ -65,8 +66,8 @@ Module *llvm::CloneModule(
// Loop over the functions in the module, making external functions as before
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *NF =
- Function::Create(cast<FunctionType>(I->getType()->getElementType()),
- I->getLinkage(), I->getName(), New);
+ Function::Create(cast<FunctionType>(I->getType()->getElementType()),
+ I->getLinkage(), I->getName(), New.get());
NF->copyAttributesFrom(&*I);
VMap[&*I] = NF;
}
@@ -82,7 +83,8 @@ Module *llvm::CloneModule(
GlobalValue *GV;
if (I->getValueType()->isFunctionTy())
GV = Function::Create(cast<FunctionType>(I->getValueType()),
- GlobalValue::ExternalLinkage, I->getName(), New);
+ GlobalValue::ExternalLinkage, I->getName(),
+ New.get());
else
GV = new GlobalVariable(
*New, I->getValueType(), false, GlobalValue::ExternalLinkage,
@@ -96,7 +98,7 @@ Module *llvm::CloneModule(
}
auto *GA = GlobalAlias::create(I->getValueType(),
I->getType()->getPointerAddressSpace(),
- I->getLinkage(), I->getName(), New);
+ I->getLinkage(), I->getName(), New.get());
GA->copyAttributesFrom(&*I);
VMap[&*I] = GA;
}
@@ -168,7 +170,7 @@ Module *llvm::CloneModule(
extern "C" {
LLVMModuleRef LLVMCloneModule(LLVMModuleRef M) {
- return wrap(CloneModule(unwrap(M)));
+ return wrap(CloneModule(unwrap(M)).release());
}
}
Modified: llvm/trunk/tools/bugpoint/CrashDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/CrashDebugger.cpp?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/CrashDebugger.cpp (original)
+++ llvm/trunk/tools/bugpoint/CrashDebugger.cpp Tue Dec 8 17:57:17 2015
@@ -143,7 +143,7 @@ ReduceCrashingGlobalVariables::TestGloba
std::vector<GlobalVariable*> &GVs) {
// Clone the program to try hacking it apart...
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
// Convert list to set for fast lookup...
std::set<GlobalVariable*> GVSet;
@@ -239,7 +239,7 @@ bool ReduceCrashingFunctions::TestFuncs(
// Clone the program to try hacking it apart...
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
// Convert list to set for fast lookup...
std::set<Function*> Functions;
@@ -346,7 +346,7 @@ namespace {
bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
// Clone the program to try hacking it apart...
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
// Convert list to set for fast lookup...
SmallPtrSet<BasicBlock*, 8> Blocks;
@@ -456,7 +456,7 @@ bool ReduceCrashingInstructions::TestIns
&Insts) {
// Clone the program to try hacking it apart...
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
// Convert list to set for fast lookup...
SmallPtrSet<Instruction*, 64> Instructions;
@@ -532,7 +532,7 @@ public:
bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) {
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
outs() << "Checking for crash with only these named metadata nodes:";
unsigned NumPrint = std::min<size_t>(NamedMDs.size(), 10);
@@ -612,7 +612,7 @@ bool ReduceCrashingNamedMDOps::TestNamed
outs() << " named metadata operands: ";
ValueToValueMapTy VMap;
- Module *M = CloneModule(BD.getProgram(), VMap);
+ Module *M = CloneModule(BD.getProgram(), VMap).release();
// This is a little wasteful. In the future it might be good if we could have
// these dropped during cloning.
@@ -658,7 +658,7 @@ static bool DebugACrash(BugDriver &BD,
BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
// Now try to reduce the number of global variable initializers in the
// module to something small.
- Module *M = CloneModule(BD.getProgram());
+ Module *M = CloneModule(BD.getProgram()).release();
bool DeletedInit = false;
for (Module::global_iterator I = M->global_begin(), E = M->global_end();
@@ -840,7 +840,7 @@ ExitLoops:
// Try to clean up the testcase by running funcresolve and globaldce...
if (!BugpointIsInterrupted) {
outs() << "\n*** Attempting to perform final cleanups: ";
- Module *M = CloneModule(BD.getProgram());
+ Module *M = CloneModule(BD.getProgram()).release();
M = BD.performFinalCleanups(M, true).release();
// Find out if the pass still crashes on the cleaned up program...
Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Tue Dec 8 17:57:17 2015
@@ -86,7 +86,7 @@ std::unique_ptr<Module>
BugDriver::deleteInstructionFromProgram(const Instruction *I,
unsigned Simplification) {
// FIXME, use vmap?
- Module *Clone = CloneModule(Program);
+ Module *Clone = CloneModule(Program).release();
const BasicBlock *PBB = I->getParent();
const Function *PF = PBB->getParent();
@@ -323,7 +323,7 @@ llvm::SplitFunctionsOutOfModule(Module *
}
ValueToValueMapTy NewVMap;
- Module *New = CloneModule(M, NewVMap);
+ Module *New = CloneModule(M, NewVMap).release();
// Remove the Test functions from the Safe module
std::set<Function *> TestFunctions;
Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Tue Dec 8 17:57:17 2015
@@ -228,8 +228,8 @@ static Module *TestMergedProgram(const B
bool &Broken) {
// Link the two portions of the program back to together.
if (!DeleteInputs) {
- M1 = CloneModule(M1);
- M2 = CloneModule(M2);
+ M1 = CloneModule(M1).release();
+ M2 = CloneModule(M2).release();
}
if (Linker::linkModules(*M1, *M2, diagnosticHandler))
exit(1);
@@ -268,7 +268,7 @@ bool ReduceMiscompilingFunctions::TestFu
// we can conclude that a function triggers the bug when in fact one
// needs a larger set of original functions to do so.
ValueToValueMapTy VMap;
- Module *Clone = CloneModule(BD.getProgram(), VMap);
+ Module *Clone = CloneModule(BD.getProgram(), VMap).release();
Module *Orig = BD.swapProgramIn(Clone);
std::vector<Function*> FuncsOnClone;
@@ -279,7 +279,7 @@ bool ReduceMiscompilingFunctions::TestFu
// Split the module into the two halves of the program we want.
VMap.clear();
- Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
+ Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap).release();
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, FuncsOnClone,
VMap);
@@ -317,7 +317,7 @@ static bool ExtractLoops(BugDriver &BD,
if (BugpointIsInterrupted) return MadeChange;
ValueToValueMapTy VMap;
- Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
+ Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap).release();
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
MiscompiledFunctions,
VMap);
@@ -376,8 +376,8 @@ static bool ExtractLoops(BugDriver &BD,
outs() << " Testing after loop extraction:\n";
// Clone modules, the tester function will free them.
- Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted, VMap);
- Module *TNOBackup = CloneModule(ToNotOptimize, VMap);
+ Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted, VMap).release();
+ Module *TNOBackup = CloneModule(ToNotOptimize, VMap).release();
for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i)
MiscompiledFunctions[i] = cast<Function>(VMap[MiscompiledFunctions[i]]);
@@ -506,7 +506,7 @@ bool ReduceMiscompiledBlocks::TestFuncs(
// Split the module into the two halves of the program we want.
ValueToValueMapTy VMap;
- Module *Clone = CloneModule(BD.getProgram(), VMap);
+ Module *Clone = CloneModule(BD.getProgram(), VMap).release();
Module *Orig = BD.swapProgramIn(Clone);
std::vector<Function*> FuncsOnClone;
std::vector<BasicBlock*> BBsOnClone;
@@ -520,7 +520,7 @@ bool ReduceMiscompiledBlocks::TestFuncs(
}
VMap.clear();
- Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
+ Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap).release();
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
FuncsOnClone,
VMap);
@@ -581,7 +581,7 @@ static bool ExtractBlocks(BugDriver &BD,
}
ValueToValueMapTy VMap;
- Module *ProgClone = CloneModule(BD.getProgram(), VMap);
+ Module *ProgClone = CloneModule(BD.getProgram(), VMap).release();
Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
MiscompiledFunctions,
VMap);
@@ -763,7 +763,7 @@ void BugDriver::debugMiscompilation(std:
// Output a bunch of bitcode files for the user...
outs() << "Outputting reduced bitcode files which expose the problem:\n";
ValueToValueMapTy VMap;
- Module *ToNotOptimize = CloneModule(getProgram(), VMap);
+ Module *ToNotOptimize = CloneModule(getProgram(), VMap).release();
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
MiscompiledFunctions,
VMap);
@@ -1039,7 +1039,7 @@ bool BugDriver::debugCodeGenerator(std::
// Split the module into the two halves of the program we want.
ValueToValueMapTy VMap;
- Module *ToNotCodeGen = CloneModule(getProgram(), VMap);
+ Module *ToNotCodeGen = CloneModule(getProgram(), VMap).release();
Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap);
// Condition the modules
Modified: llvm/trunk/unittests/Transforms/Utils/Cloning.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Cloning.cpp?rev=255078&r1=255077&r2=255078&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Cloning.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/Cloning.cpp Tue Dec 8 17:57:17 2015
@@ -436,7 +436,7 @@ protected:
IBuilder.CreateRetVoid();
}
- void CreateNewModule() { NewM = llvm::CloneModule(OldM); }
+ void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); }
LLVMContext C;
Module *OldM;
More information about the llvm-commits
mailing list