diff --git a/llvm/include/llvm/LTO/Support.h b/llvm/include/llvm/LTO/Support.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/LTO/Support.h @@ -0,0 +1,22 @@ +//===--------------------- Support.h ----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file contains helper functions related to link-time optimization (LTO). +/// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Module.h" + +namespace llvm { + +void saveTempBitcode(const Module &TheModule, StringRef TempDir, unsigned Count, + StringRef Suffix); + +} // namespace llvm diff --git a/llvm/lib/LTO/CMakeLists.txt b/llvm/lib/LTO/CMakeLists.txt --- a/llvm/lib/LTO/CMakeLists.txt +++ b/llvm/lib/LTO/CMakeLists.txt @@ -4,6 +4,7 @@ LTOModule.cpp LTOCodeGenerator.cpp SummaryBasedOptimizations.cpp + Support.cpp UpdateCompilerUsed.cpp ThinLTOCodeGenerator.cpp diff --git a/llvm/lib/LTO/Support.cpp b/llvm/lib/LTO/Support.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/LTO/Support.cpp @@ -0,0 +1,36 @@ +//===-Support.cpp - LLVM Link Time Optimizer ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file contains helper functions related to link-time optimization (LTO). +/// +//===----------------------------------------------------------------------===// + +#include "llvm/LTO/Support.h" + +#include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/Support/FileSystem.h" + +namespace llvm { + +// Simple helper to save temporary files for debug. +void saveTempBitcode(const Module &TheModule, StringRef TempDir, unsigned Count, + StringRef Suffix) { + if (TempDir.empty()) + return; + // User asked to save temps, let dump the bitcode file after import. + std::string SaveTempPath = (TempDir + llvm::Twine(Count) + Suffix).str(); + std::error_code EC; + raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None); + if (EC) + report_fatal_error(Twine("Failed to open ") + SaveTempPath + + " to save bitcode\n"); + WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true); +} + +} // namespace llvm diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -27,15 +27,16 @@ #include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DiagnosticPrinter.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMRemarkStreamer.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/LTO/LTO.h" #include "llvm/LTO/SummaryBasedOptimizations.h" +#include "llvm/LTO/Support.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Object/IRObjectFile.h" @@ -91,20 +92,6 @@ static cl::opt ThreadCount("threads", cl::init(0)); // Simple helper to save temporary files for debug. -static void saveTempBitcode(const Module &TheModule, StringRef TempDir, - unsigned count, StringRef Suffix) { - if (TempDir.empty()) - return; - // User asked to save temps, let dump the bitcode file after import. - std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str(); - std::error_code EC; - raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None); - if (EC) - report_fatal_error(Twine("Failed to open ") + SaveTempPath + - " to save optimized bitcode\n"); - WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true); -} - static const GlobalValueSummary * getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) { // If there is any strong definition anywhere, get it.