From c44a12244f3855660d8244152eb40da4d853289e Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 15 Aug 2016 23:24:57 +0000 Subject: [PATCH] [ThinLTO] Fix temp file dumping, enable via llvm-lto and test it Summary: Fixed a bug in ThinLTOCodeGenerator's temp file dumping. The Twine needs to be passed directly as an argument, or a copy saved into a std::string. It doesn't seem there are any consumers of this, so I added a new option to llvm-lto to enable saving of temp files during ThinLTO, and augmented a test to use it to check post-import but pre-opt bitcode. Reviewers: mehdi_amini Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D23525 llvm-svn: 278761 --- llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 4 ++-- llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll | 10 +++++++++- llvm/tools/llvm-lto/llvm-lto.cpp | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index bfb0980..9224f72 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -78,9 +78,9 @@ static void saveTempBitcode(const Module &TheModule, StringRef TempDir, if (TempDir.empty()) return; // User asked to save temps, let dump the bitcode file after import. - auto SaveTempPath = TempDir + llvm::utostr(count) + Suffix; + std::string SaveTempPath = (TempDir + llvm::utostr(count) + Suffix).str(); std::error_code EC; - raw_fd_ostream OS(SaveTempPath.str(), EC, sys::fs::F_None); + raw_fd_ostream OS(SaveTempPath, EC, sys::fs::F_None); if (EC) report_fatal_error(Twine("Failed to open ") + SaveTempPath + " to save optimized bitcode\n"); diff --git a/llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll b/llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll index 67cc2b7..c1ffdf1 100644 --- a/llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll +++ b/llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll @@ -3,7 +3,15 @@ ; verification error. ; RUN: opt -module-summary %s -o %t1.bc ; RUN: opt -module-summary %p/Inputs/linkonce_resolution_comdat.ll -o %t2.bc -; RUN: llvm-lto -thinlto-action=run %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g +; RUN: llvm-lto -thinlto-action=run %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3. + +; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT1 +; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT2 +; Copy from first module is prevailing and converted to weak_odr, copy +; from second module is preempted and converted to available_externally and +; removed from comdat. +; IMPORT1: define weak_odr i32 @f(i8*) unnamed_addr comdat($c1) { +; IMPORT2: define available_externally i32 @f(i8*) unnamed_addr { ; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1 ; NM1: W f diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index b3b617b..05d1bbd 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -120,6 +120,11 @@ static cl::opt ThinLTOModuleId( static cl::opt ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching.")); +static cl::opt ThinLTOSaveTempsPrefix( + "thinlto-save-temps", + cl::desc("Save ThinLTO temp files using filenames created by adding " + "suffixes to the given file path prefix.")); + static cl::opt SaveModuleFile("save-merged-module", cl::init(false), cl::desc("Write merged LTO module to file before CodeGen")); @@ -672,6 +677,8 @@ private: ThinGenerator.addModule(Filename, InputBuffers.back()->getBuffer()); } + if (!ThinLTOSaveTempsPrefix.empty()) + ThinGenerator.setSaveTempsDir(ThinLTOSaveTempsPrefix); ThinGenerator.run(); auto &Binaries = ThinGenerator.getProducedBinaries(); -- 2.7.4