From 18d705086f7f3f0d460aae88b26daecdae5f634e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 9 Dec 2015 00:34:10 +0000 Subject: [PATCH] Return std::unique_ptr from SplitFunctionsOutOfModule. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255084 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/BugDriver.h | 10 +++++----- tools/bugpoint/ExtractFunction.cpp | 17 ++++++----------- tools/bugpoint/Miscompilation.cpp | 28 ++++++++++++++-------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index 45fcf74aa6b..20efff3fda5 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -331,11 +331,11 @@ void DeleteGlobalInitializer(GlobalVariable *GV); // void DeleteFunctionBody(Function *F); -/// SplitFunctionsOutOfModule - Given a module and a list of functions in the -/// module, split the functions OUT of the specified module, and place them in -/// the new module. -Module *SplitFunctionsOutOfModule(Module *M, const std::vector &F, - ValueToValueMapTy &VMap); +/// Given a module and a list of functions in the module, split the functions +/// OUT of the specified module, and place them in the new module. +std::unique_ptr +SplitFunctionsOutOfModule(Module *M, const std::vector &F, + ValueToValueMapTy &VMap); } // End llvm namespace diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 62c3f3e9f25..fe0ab69dc16 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -303,13 +303,8 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, } } - -/// SplitFunctionsOutOfModule - Given a module and a list of functions in the -/// module, split the functions OUT of the specified module, and place them in -/// the new module. -Module * -llvm::SplitFunctionsOutOfModule(Module *M, - const std::vector &F, +std::unique_ptr +llvm::SplitFunctionsOutOfModule(Module *M, const std::vector &F, ValueToValueMapTy &VMap) { // Make sure functions & globals are all external so that linkage // between the two modules will work. @@ -323,7 +318,7 @@ llvm::SplitFunctionsOutOfModule(Module *M, } ValueToValueMapTy NewVMap; - Module *New = CloneModule(M, NewVMap).release(); + std::unique_ptr New = CloneModule(M, NewVMap); // Remove the Test functions from the Safe module std::set TestFunctions; @@ -364,9 +359,9 @@ llvm::SplitFunctionsOutOfModule(Module *M, // Make sure that there is a global ctor/dtor array in both halves of the // module if they both have static ctor/dtor functions. - SplitStaticCtorDtor("llvm.global_ctors", M, New, NewVMap); - SplitStaticCtorDtor("llvm.global_dtors", M, New, NewVMap); - + SplitStaticCtorDtor("llvm.global_ctors", M, New.get(), NewVMap); + SplitStaticCtorDtor("llvm.global_dtors", M, New.get(), NewVMap); + return New; } diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index d2aba92c7c9..0c8b313c6a8 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -280,8 +280,8 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, // Split the module into the two halves of the program we want. VMap.clear(); Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap).release(); - Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, FuncsOnClone, - VMap); + Module *ToOptimize = + SplitFunctionsOutOfModule(ToNotOptimize, FuncsOnClone, VMap).release(); // Run the predicate, note that the predicate will delete both input modules. bool Broken = TestFn(BD, ToOptimize, ToNotOptimize, Error); @@ -319,8 +319,8 @@ static bool ExtractLoops(BugDriver &BD, ValueToValueMapTy VMap; std::unique_ptr ToNotOptimize = CloneModule(BD.getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize.get(), - MiscompiledFunctions, - VMap); + MiscompiledFunctions, VMap) + .release(); std::unique_ptr ToOptimizeLoopExtracted = BD.extractLoop(ToOptimize); if (!ToOptimizeLoopExtracted) { @@ -519,9 +519,8 @@ bool ReduceMiscompiledBlocks::TestFuncs(const std::vector &BBs, VMap.clear(); Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap).release(); - Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, - FuncsOnClone, - VMap); + Module *ToOptimize = + SplitFunctionsOutOfModule(ToNotOptimize, FuncsOnClone, VMap).release(); // Try the extraction. If it doesn't work, then the block extractor crashed // or something, in which case bugpoint can't chase down this possibility. @@ -580,9 +579,9 @@ static bool ExtractBlocks(BugDriver &BD, ValueToValueMapTy VMap; Module *ProgClone = CloneModule(BD.getProgram(), VMap).release(); - Module *ToExtract = SplitFunctionsOutOfModule(ProgClone, - MiscompiledFunctions, - VMap); + Module *ToExtract = + SplitFunctionsOutOfModule(ProgClone, MiscompiledFunctions, VMap) + .release(); std::unique_ptr Extracted = BD.extractMappedBlocksFromModule(Blocks, ToExtract); if (!Extracted) { @@ -762,9 +761,9 @@ void BugDriver::debugMiscompilation(std::string *Error) { outs() << "Outputting reduced bitcode files which expose the problem:\n"; ValueToValueMapTy VMap; Module *ToNotOptimize = CloneModule(getProgram(), VMap).release(); - Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, - MiscompiledFunctions, - VMap); + Module *ToOptimize = + SplitFunctionsOutOfModule(ToNotOptimize, MiscompiledFunctions, VMap) + .release(); outs() << " Non-optimized portion: "; EmitProgressBitcode(ToNotOptimize, "tonotoptimize", true); @@ -1038,7 +1037,8 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { // Split the module into the two halves of the program we want. ValueToValueMapTy VMap; Module *ToNotCodeGen = CloneModule(getProgram(), VMap).release(); - Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap); + Module *ToCodeGen = + SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap).release(); // Condition the modules CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen); -- 2.34.1