diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-lto/llvm-lto.cpp')
| -rw-r--r-- | contrib/llvm/tools/llvm-lto/llvm-lto.cpp | 121 |
1 files changed, 81 insertions, 40 deletions
diff --git a/contrib/llvm/tools/llvm-lto/llvm-lto.cpp b/contrib/llvm/tools/llvm-lto/llvm-lto.cpp index 87cd13ad70de..7d71a3e8dfe3 100644 --- a/contrib/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/contrib/llvm/tools/llvm-lto/llvm-lto.cpp @@ -1,4 +1,4 @@ -//===-- llvm-lto: a simple command-line program to link modules with LTO --===// +//===- llvm-lto: a simple command-line program to link modules with LTO ---===// // // The LLVM Compiler Infrastructure // @@ -12,20 +12,36 @@ // //===----------------------------------------------------------------------===// +#include "llvm-c/lto.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" +#include "llvm/ADT/Twine.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" -#include "llvm/CodeGen/CommandFlags.h" +#include "llvm/CodeGen/CommandFlags.def" +#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/LTO/legacy/LTOCodeGenerator.h" #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" @@ -33,7 +49,19 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetOptions.h" +#include <algorithm> +#include <cassert> +#include <cstdint> +#include <cstdlib> #include <list> +#include <map> +#include <memory> +#include <string> +#include <system_error> +#include <tuple> +#include <utility> +#include <vector> using namespace llvm; @@ -128,6 +156,9 @@ static cl::opt<std::string> ThinLTOModuleId( static cl::opt<std::string> ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching.")); +static cl::opt<int> + ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", cl::desc("Set ThinLTO cache pruning interval.")); + static cl::opt<std::string> ThinLTOSaveTempsPrefix( "thinlto-save-temps", cl::desc("Save ThinLTO temp files using filenames created by adding " @@ -179,10 +210,12 @@ static cl::opt<bool> CheckHasObjC( cl::desc("Only check if the module has objective-C defined in it")); namespace { + struct ModuleInfo { std::vector<bool> CanBeHidden; }; -} + +} // end anonymous namespace static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity, const char *Msg, void *) { @@ -205,34 +238,40 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity, } static std::string CurrentActivity; -static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { - raw_ostream &OS = errs(); - OS << "llvm-lto: "; - switch (DI.getSeverity()) { - case DS_Error: - OS << "error"; - break; - case DS_Warning: - OS << "warning"; - break; - case DS_Remark: - OS << "remark"; - break; - case DS_Note: - OS << "note"; - break; - } - if (!CurrentActivity.empty()) - OS << ' ' << CurrentActivity; - OS << ": "; - - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - OS << '\n'; - if (DI.getSeverity() == DS_Error) - exit(1); -} +namespace { + struct LLVMLTODiagnosticHandler : public DiagnosticHandler { + bool handleDiagnostics(const DiagnosticInfo &DI) override { + raw_ostream &OS = errs(); + OS << "llvm-lto: "; + switch (DI.getSeverity()) { + case DS_Error: + OS << "error"; + break; + case DS_Warning: + OS << "warning"; + break; + case DS_Remark: + OS << "remark"; + break; + case DS_Note: + OS << "note"; + break; + } + if (!CurrentActivity.empty()) + OS << ' ' << CurrentActivity; + OS << ": "; + + DiagnosticPrinterRawOStream DP(OS); + DI.print(DP); + OS << '\n'; + + if (DI.getSeverity() == DS_Error) + exit(1); + return true; + } + }; + } static void error(const Twine &Msg) { errs() << "llvm-lto: " << Msg << '\n'; @@ -263,7 +302,8 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer, Buffer = std::move(BufferOrErr.get()); CurrentActivity = ("loading file '" + Path + "'").str(); std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>(); - Context->setDiagnosticHandler(diagnosticHandler, nullptr, true); + Context->setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), + true); ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext( std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(), Options, Path); @@ -277,7 +317,7 @@ void printIndexStats() { for (auto &Filename : InputFilenames) { ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': "); std::unique_ptr<ModuleSummaryIndex> Index = - ExitOnErr(llvm::getModuleSummaryIndexForFile(Filename)); + ExitOnErr(getModuleSummaryIndexForFile(Filename)); // Skip files without a module summary. if (!Index) report_fatal_error(Filename + " does not contain an index"); @@ -396,7 +436,7 @@ std::unique_ptr<ModuleSummaryIndex> loadCombinedIndex() { report_fatal_error("Missing -thinlto-index for ThinLTO promotion stage"); ExitOnError ExitOnErr("llvm-lto: error loading file '" + ThinLTOIndex + "': "); - return ExitOnErr(llvm::getModuleSummaryIndexForFile(ThinLTOIndex)); + return ExitOnErr(getModuleSummaryIndexForFile(ThinLTOIndex)); } static std::unique_ptr<Module> loadModule(StringRef Filename, @@ -433,6 +473,7 @@ public: ThinGenerator.setCodePICModel(getRelocModel()); ThinGenerator.setTargetOptions(Options); ThinGenerator.setCacheDir(ThinLTOCacheDir); + ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval); ThinGenerator.setFreestanding(EnableFreestanding); // Add all the exported symbols to the table of symbols to preserve. @@ -489,7 +530,6 @@ private: raw_fd_ostream OS(OutputFilename, EC, sys::fs::OpenFlags::F_None); error(EC, "error opening the file '" + OutputFilename + "'"); WriteIndexToFile(*CombinedIndex, OS); - return; } /// Load the combined index from disk, then compute and generate @@ -745,7 +785,7 @@ private: /// Load the combined index from disk, then load every file referenced by }; -} // namespace thinlto +} // end namespace thinlto int main(int argc, char **argv) { // Print a stack trace if we signal out. @@ -784,7 +824,7 @@ int main(int argc, char **argv) { std::unique_ptr<MemoryBuffer> BufferOrErr = ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(Filename))); auto Buffer = std::move(BufferOrErr.get()); - if (ExitOnErr(llvm::isBitcodeContainingObjCCategory(*Buffer))) + if (ExitOnErr(isBitcodeContainingObjCCategory(*Buffer))) outs() << "Bitcode " << Filename << " contains ObjC\n"; else outs() << "Bitcode " << Filename << " does not contain ObjC\n"; @@ -808,7 +848,8 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; LLVMContext Context; - Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); + Context.setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), + true); LTOCodeGenerator CodeGen(Context); @@ -822,7 +863,7 @@ int main(int argc, char **argv) { CodeGen.setTargetOptions(Options); CodeGen.setShouldRestoreGlobalsLinkage(RestoreGlobalsLinkage); - llvm::StringSet<llvm::MallocAllocator> DSOSymbolsSet; + StringSet<MallocAllocator> DSOSymbolsSet; for (unsigned i = 0; i < DSOSymbols.size(); ++i) DSOSymbolsSet.insert(DSOSymbols[i]); @@ -899,7 +940,7 @@ int main(int argc, char **argv) { error("writing merged module failed."); } - std::list<tool_output_file> OSs; + std::list<ToolOutputFile> OSs; std::vector<raw_pwrite_stream *> OSPtrs; for (unsigned I = 0; I != Parallelism; ++I) { std::string PartFilename = OutputFilename; @@ -916,7 +957,7 @@ int main(int argc, char **argv) { // Diagnostic messages should have been printed by the handler. error("error compiling the code"); - for (tool_output_file &OS : OSs) + for (ToolOutputFile &OS : OSs) OS.keep(); } else { if (Parallelism != 1) |
