diff options
-rw-r--r-- | llvm/include/llvm/Transforms/Utils/Cloning.h | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneModule.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/SplitModule.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/bugpoint/CrashDebugger.cpp | 22 | ||||
-rw-r--r-- | llvm/tools/bugpoint/ExtractFunction.cpp | 4 | ||||
-rw-r--r-- | llvm/tools/bugpoint/Miscompilation.cpp | 24 | ||||
-rw-r--r-- | llvm/tools/llc/llc.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/opt/opt.cpp | 8 | ||||
-rw-r--r-- | llvm/unittests/Transforms/Utils/Cloning.cpp | 2 |
10 files changed, 54 insertions, 53 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/Cloning.h b/llvm/include/llvm/Transforms/Utils/Cloning.h index 178bae76cef..9d8faf1e2c6 100644 --- a/llvm/include/llvm/Transforms/Utils/Cloning.h +++ b/llvm/include/llvm/Transforms/Utils/Cloning.h @@ -49,15 +49,15 @@ class ReturnInst; /// Return an exact copy of the specified module /// -std::unique_ptr<Module> CloneModule(const Module *M); -std::unique_ptr<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. std::unique_ptr<Module> -CloneModule(const Module *M, ValueToValueMapTy &VMap, +CloneModule(const Module &M, ValueToValueMapTy &VMap, function_ref<bool(const GlobalValue *)> ShouldCloneDefinition); /// ClonedCodeInfo - This struct can be used to capture information about code diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp index 5c1f678b4d9..9bca88a54b3 100644 --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -259,7 +259,7 @@ void splitAndWriteThinLTOBitcode( ValueToValueMapTy VMap; std::unique_ptr<Module> MergedM( - CloneModule(&M, VMap, [&](const GlobalValue *GV) -> bool { + CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool { if (const auto *C = GV->getComdat()) if (MergedMComdats.count(C)) return true; diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index 8fee1085422..c441cdf6e8d 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -32,33 +32,33 @@ static void copyComdat(GlobalObject *Dst, const GlobalObject *Src) { /// copies of global variables and functions, and making their (initializers and /// references, respectively) refer to the right globals. /// -std::unique_ptr<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); } -std::unique_ptr<Module> llvm::CloneModule(const Module *M, +std::unique_ptr<Module> llvm::CloneModule(const Module &M, ValueToValueMapTy &VMap) { return CloneModule(M, VMap, [](const GlobalValue *GV) { return true; }); } std::unique_ptr<Module> llvm::CloneModule( - const Module *M, ValueToValueMapTy &VMap, + const Module &M, ValueToValueMapTy &VMap, function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) { // First off, we need to create the new module. 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()); - + llvm::make_unique<Module>(M.getModuleIdentifier(), M.getContext()); + New->setDataLayout(M.getDataLayout()); + New->setTargetTriple(M.getTargetTriple()); + New->setModuleInlineAsm(M.getModuleInlineAsm()); + // Loop over all of the global variables, making corresponding globals in the // new module. Here we add them to the VMap and to the new Module. We // don't worry about attributes or initializers, they will come later. // - for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); + for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { GlobalVariable *GV = new GlobalVariable(*New, I->getValueType(), @@ -72,7 +72,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // Loop over the functions in the module, making external functions as before - for (const Function &I : *M) { + for (const Function &I : M) { Function *NF = Function::Create(cast<FunctionType>(I.getValueType()), I.getLinkage(), I.getName(), New.get()); NF->copyAttributesFrom(&I); @@ -80,7 +80,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // Loop over the aliases in the module - for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; ++I) { if (!ShouldCloneDefinition(&*I)) { // An alias cannot act as an external reference, so we need to create @@ -114,7 +114,7 @@ std::unique_ptr<Module> llvm::CloneModule( // have been created, loop through and copy the global variable referrers // over... We also set the attributes on the global now. // - for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); + for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (I->isDeclaration()) continue; @@ -139,7 +139,7 @@ std::unique_ptr<Module> llvm::CloneModule( // Similarly, copy over function bodies now... // - for (const Function &I : *M) { + for (const Function &I : M) { if (I.isDeclaration()) continue; @@ -169,7 +169,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // And aliases - for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; ++I) { // We already dealt with undefined aliases above. if (!ShouldCloneDefinition(&*I)) @@ -180,8 +180,9 @@ std::unique_ptr<Module> llvm::CloneModule( } // And named metadata.... - for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), - E = M->named_metadata_end(); I != E; ++I) { + for (Module::const_named_metadata_iterator I = M.named_metadata_begin(), + E = M.named_metadata_end(); + I != E; ++I) { const NamedMDNode &NMD = *I; NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName()); for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) @@ -194,7 +195,7 @@ std::unique_ptr<Module> llvm::CloneModule( extern "C" { LLVMModuleRef LLVMCloneModule(LLVMModuleRef M) { - return wrap(CloneModule(unwrap(M)).release()); + return wrap(CloneModule(*unwrap(M)).release()); } } diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp index 968eb0208f4..7966fa43712 100644 --- a/llvm/lib/Transforms/Utils/SplitModule.cpp +++ b/llvm/lib/Transforms/Utils/SplitModule.cpp @@ -270,7 +270,7 @@ void llvm::SplitModule( for (unsigned I = 0; I < N; ++I) { ValueToValueMapTy VMap; std::unique_ptr<Module> MPart( - CloneModule(M.get(), VMap, [&](const GlobalValue *GV) { + CloneModule(*M, VMap, [&](const GlobalValue *GV) { if (ClusterIDMap.count(GV)) return (ClusterIDMap[GV] == I); else diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index a3b274df18c..a5766833b6e 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -150,7 +150,7 @@ bool ReduceCrashingGlobalInitializers::TestGlobalVariables( std::vector<GlobalVariable *> &GVs) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - std::unique_ptr<Module> M = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram(), VMap); // Convert list to set for fast lookup... std::set<GlobalVariable *> GVSet; @@ -244,7 +244,7 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector<Function *> &Funcs) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - Module *M = CloneModule(BD.getProgram(), VMap).release(); + Module *M = CloneModule(*BD.getProgram(), VMap).release(); // Convert list to set for fast lookup... std::set<Function *> Functions; @@ -388,7 +388,7 @@ public: bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - std::unique_ptr<Module> M = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet<BasicBlock *, 8> Blocks; @@ -507,7 +507,7 @@ bool ReduceCrashingConditionals::TestBlocks( std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - std::unique_ptr<Module> M = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet<const BasicBlock *, 8> Blocks; @@ -611,7 +611,7 @@ public: bool ReduceSimplifyCFG::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - std::unique_ptr<Module> M = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet<const BasicBlock *, 8> Blocks; @@ -703,7 +703,7 @@ bool ReduceCrashingInstructions::TestInsts( std::vector<const Instruction *> &Insts) { // Clone the program to try hacking it apart... ValueToValueMapTy VMap; - Module *M = CloneModule(BD.getProgram(), VMap).release(); + Module *M = CloneModule(*BD.getProgram(), VMap).release(); // Convert list to set for fast lookup... SmallPtrSet<Instruction *, 32> Instructions; @@ -778,7 +778,7 @@ public: bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) { ValueToValueMapTy VMap; - Module *M = CloneModule(BD.getProgram(), VMap).release(); + 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); @@ -858,7 +858,7 @@ bool ReduceCrashingNamedMDOps::TestNamedMDOps( outs() << " named metadata operands: "; ValueToValueMapTy VMap; - Module *M = CloneModule(BD.getProgram(), VMap).release(); + 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. @@ -900,7 +900,7 @@ static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { // Now try to reduce the number of global variable initializers in the // module to something small. - std::unique_ptr<Module> M = CloneModule(OrigM); + std::unique_ptr<Module> M = CloneModule(*OrigM); bool DeletedInit = false; for (GlobalVariable &GV : M->globals()) { @@ -1120,7 +1120,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { // Attempt to strip debug info metadata. auto stripMetadata = [&](std::function<bool(Module &)> strip) { - std::unique_ptr<Module> M = CloneModule(BD.getProgram()); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram()); strip(*M); if (TestFn(BD, M.get())) BD.setNewProgram(M.release()); @@ -1166,7 +1166,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { // Try to clean up the testcase by running funcresolve and globaldce... if (!BugpointIsInterrupted) { outs() << "\n*** Attempting to perform final cleanups: "; - std::unique_ptr<Module> M = CloneModule(BD.getProgram()); + std::unique_ptr<Module> M = CloneModule(*BD.getProgram()); M = BD.performFinalCleanups(M.release(), true); // Find out if the pass still crashes on the cleaned up program... diff --git a/llvm/tools/bugpoint/ExtractFunction.cpp b/llvm/tools/bugpoint/ExtractFunction.cpp index a9023573f9d..d010855accb 100644 --- a/llvm/tools/bugpoint/ExtractFunction.cpp +++ b/llvm/tools/bugpoint/ExtractFunction.cpp @@ -85,7 +85,7 @@ std::unique_ptr<Module> BugDriver::deleteInstructionFromProgram(const Instruction *I, unsigned Simplification) { // FIXME, use vmap? - std::unique_ptr<Module> Clone = CloneModule(Program); + std::unique_ptr<Module> Clone = CloneModule(*Program); const BasicBlock *PBB = I->getParent(); const Function *PF = PBB->getParent(); @@ -318,7 +318,7 @@ llvm::SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, } ValueToValueMapTy NewVMap; - std::unique_ptr<Module> New = CloneModule(M, NewVMap); + std::unique_ptr<Module> New = CloneModule(*M, NewVMap); // Remove the Test functions from the Safe module std::set<Function *> TestFunctions; diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp index 80f4cea2348..a6ca65388d2 100644 --- a/llvm/tools/bugpoint/Miscompilation.cpp +++ b/llvm/tools/bugpoint/Miscompilation.cpp @@ -230,8 +230,8 @@ static Expected<std::unique_ptr<Module>> testMergedProgram(const BugDriver &BD, const Module &M2, bool &Broken) { // Resulting merge of M1 and M2. - auto Merged = CloneModule(&M1); - if (Linker::linkModules(*Merged, CloneModule(&M2))) + auto Merged = CloneModule(M1); + if (Linker::linkModules(*Merged, CloneModule(M2))) // TODO: Shouldn't we thread the error up instead of exiting? exit(1); @@ -266,7 +266,7 @@ ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function *> &Funcs) { // 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).release(); + Module *Clone = CloneModule(*BD.getProgram(), VMap).release(); Module *Orig = BD.swapProgramIn(Clone); std::vector<Function *> FuncsOnClone; @@ -277,7 +277,7 @@ ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function *> &Funcs) { // Split the module into the two halves of the program we want. VMap.clear(); - std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> ToNotOptimize = CloneModule(*BD.getProgram(), VMap); std::unique_ptr<Module> ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); @@ -316,7 +316,7 @@ ExtractLoops(BugDriver &BD, return MadeChange; ValueToValueMapTy VMap; - std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> ToNotOptimize = CloneModule(*BD.getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize.get(), MiscompiledFunctions, VMap) .release(); @@ -377,8 +377,8 @@ ExtractLoops(BugDriver &BD, outs() << " Testing after loop extraction:\n"; // Clone modules, the tester function will free them. std::unique_ptr<Module> TOLEBackup = - CloneModule(ToOptimizeLoopExtracted.get(), VMap); - std::unique_ptr<Module> TNOBackup = CloneModule(ToNotOptimize.get(), VMap); + CloneModule(*ToOptimizeLoopExtracted, VMap); + std::unique_ptr<Module> TNOBackup = CloneModule(*ToNotOptimize, VMap); for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i) MiscompiledFunctions[i] = cast<Function>(VMap[MiscompiledFunctions[i]]); @@ -508,7 +508,7 @@ ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock *> &BBs) { // Split the module into the two halves of the program we want. ValueToValueMapTy VMap; - Module *Clone = CloneModule(BD.getProgram(), VMap).release(); + Module *Clone = CloneModule(*BD.getProgram(), VMap).release(); Module *Orig = BD.swapProgramIn(Clone); std::vector<Function *> FuncsOnClone; std::vector<BasicBlock *> BBsOnClone; @@ -522,7 +522,7 @@ ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock *> &BBs) { } VMap.clear(); - std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); + std::unique_ptr<Module> ToNotOptimize = CloneModule(*BD.getProgram(), VMap); std::unique_ptr<Module> ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); @@ -577,7 +577,7 @@ ExtractBlocks(BugDriver &BD, } ValueToValueMapTy VMap; - Module *ProgClone = CloneModule(BD.getProgram(), VMap).release(); + Module *ProgClone = CloneModule(*BD.getProgram(), VMap).release(); Module *ToExtract = SplitFunctionsOutOfModule(ProgClone, MiscompiledFunctions, VMap) .release(); @@ -770,7 +770,7 @@ Error BugDriver::debugMiscompilation() { // 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).release(); + Module *ToNotOptimize = CloneModule(*getProgram(), VMap).release(); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, *MiscompiledFunctions, VMap) .release(); @@ -1037,7 +1037,7 @@ Error BugDriver::debugCodeGenerator() { // Split the module into the two halves of the program we want. ValueToValueMapTy VMap; - std::unique_ptr<Module> ToNotCodeGen = CloneModule(getProgram(), VMap); + std::unique_ptr<Module> ToNotCodeGen = CloneModule(*getProgram(), VMap); std::unique_ptr<Module> ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen.get(), *Funcs, VMap); diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 1639b46ec79..60b49aec7ea 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -565,7 +565,7 @@ static int compileModule(char **argv, LLVMContext &Context) { // in the future. SmallVector<char, 0> CompileTwiceBuffer; if (CompileTwice) { - std::unique_ptr<Module> M2(llvm::CloneModule(M.get())); + std::unique_ptr<Module> M2(llvm::CloneModule(*M)); PM.run(*M2); CompileTwiceBuffer = Buffer; Buffer.clear(); diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 236c9022587..8e839b23907 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -765,10 +765,10 @@ int main(int argc, char **argv) { // If requested, run all passes again with the same pass manager to catch // bugs caused by persistent state in the passes if (RunTwice) { - std::unique_ptr<Module> M2(CloneModule(M.get())); - Passes.run(*M2); - CompileTwiceBuffer = Buffer; - Buffer.clear(); + std::unique_ptr<Module> M2(CloneModule(*M)); + Passes.run(*M2); + CompileTwiceBuffer = Buffer; + Buffer.clear(); } // Now that we have all of the passes ready, run them. diff --git a/llvm/unittests/Transforms/Utils/Cloning.cpp b/llvm/unittests/Transforms/Utils/Cloning.cpp index fe4e2ba7e94..2ce19bd51a8 100644 --- a/llvm/unittests/Transforms/Utils/Cloning.cpp +++ b/llvm/unittests/Transforms/Utils/Cloning.cpp @@ -527,7 +527,7 @@ protected: DBuilder.finalize(); } - void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); } + void CreateNewModule() { NewM = llvm::CloneModule(*OldM).release(); } LLVMContext C; Module *OldM; |