From c15d60b772b1d02134b3d3bdd8e456ed33674279 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 1 May 2017 20:42:32 +0000 Subject: [PATCH] Object: Remove ModuleSummaryIndexObjectFile class. Differential Revision: https://reviews.llvm.org/D32195 llvm-svn: 301832 --- clang/lib/CodeGen/BackendUtil.cpp | 1 - llvm/include/llvm/Bitcode/BitcodeReader.h | 7 ++ llvm/include/llvm/Object/Binary.h | 3 - .../llvm/Object/ModuleSummaryIndexObjectFile.h | 112 ------------------ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 18 +++ llvm/lib/LTO/LTO.cpp | 1 - llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 17 ++- llvm/lib/Object/CMakeLists.txt | 1 - llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp | 129 --------------------- llvm/lib/Transforms/IPO/FunctionImport.cpp | 2 +- llvm/test/tools/llvm-lto/error.ll | 2 +- llvm/tools/llvm-link/llvm-link.cpp | 2 +- llvm/tools/llvm-lto/llvm-lto.cpp | 1 - 13 files changed, 35 insertions(+), 261 deletions(-) delete mode 100644 llvm/include/llvm/Object/ModuleSummaryIndexObjectFile.h delete mode 100644 llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 85788b4..0388380 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -35,7 +35,6 @@ #include "llvm/LTO/LTOBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/SubtargetFeature.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/llvm/include/llvm/Bitcode/BitcodeReader.h b/llvm/include/llvm/Bitcode/BitcodeReader.h index 0701ddb..07fad87 100644 --- a/llvm/include/llvm/Bitcode/BitcodeReader.h +++ b/llvm/include/llvm/Bitcode/BitcodeReader.h @@ -141,6 +141,13 @@ namespace llvm { Expected> getModuleSummaryIndex(MemoryBufferRef Buffer); + /// Parse the module summary index out of an IR file and return the module + /// summary index object if found, or an empty summary if not. If Path refers + /// to an empty file and the -ignore-empty-index-file cl::opt flag is passed + /// this function will return nullptr. + Expected> + getModuleSummaryIndexForFile(StringRef Path); + /// isBitcodeWrapper - Return true if the given bytes are the magic bytes /// for an LLVM IR bitcode wrapper. /// diff --git a/llvm/include/llvm/Object/Binary.h b/llvm/include/llvm/Object/Binary.h index 0678832..f42048e 100644 --- a/llvm/include/llvm/Object/Binary.h +++ b/llvm/include/llvm/Object/Binary.h @@ -42,7 +42,6 @@ protected: ID_MachOUniversalBinary, ID_COFFImportFile, ID_IR, // LLVM IR - ID_ModuleSummaryIndex, // Module summary index // Object and children. ID_StartObjects, @@ -128,8 +127,6 @@ public: return TypeID == ID_IR; } - bool isModuleSummaryIndex() const { return TypeID == ID_ModuleSummaryIndex; } - bool isLittleEndian() const { return !(TypeID == ID_ELF32B || TypeID == ID_ELF64B || TypeID == ID_MachO32B || TypeID == ID_MachO64B); diff --git a/llvm/include/llvm/Object/ModuleSummaryIndexObjectFile.h b/llvm/include/llvm/Object/ModuleSummaryIndexObjectFile.h deleted file mode 100644 index f733f86..0000000 --- a/llvm/include/llvm/Object/ModuleSummaryIndexObjectFile.h +++ /dev/null @@ -1,112 +0,0 @@ -//===- ModuleSummaryIndexObjectFile.h - Summary index file implementation -===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file declares the ModuleSummaryIndexObjectFile template class. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H -#define LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H - -#include "llvm/ADT/StringRef.h" -#include "llvm/Object/Binary.h" -#include "llvm/Object/SymbolicFile.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/ErrorOr.h" -#include "llvm/Support/MemoryBuffer.h" -#include -#include - -namespace llvm { - -class ModuleSummaryIndex; - -namespace object { - -class ObjectFile; - -/// This class is used to read just the module summary index related -/// sections out of the given object (which may contain a single module's -/// bitcode or be a combined index bitcode file). It builds a ModuleSummaryIndex -/// object. -class ModuleSummaryIndexObjectFile : public SymbolicFile { - std::unique_ptr Index; - -public: - ModuleSummaryIndexObjectFile(MemoryBufferRef Object, - std::unique_ptr I); - ~ModuleSummaryIndexObjectFile() override; - - // TODO: Walk through GlobalValueMap entries for symbols. - // However, currently these interfaces are not used by any consumers. - void moveSymbolNext(DataRefImpl &Symb) const override { - llvm_unreachable("not implemented"); - } - - std::error_code printSymbolName(raw_ostream &OS, - DataRefImpl Symb) const override { - llvm_unreachable("not implemented"); - return std::error_code(); - } - - uint32_t getSymbolFlags(DataRefImpl Symb) const override { - llvm_unreachable("not implemented"); - return 0; - } - - basic_symbol_iterator symbol_begin() const override { - llvm_unreachable("not implemented"); - return basic_symbol_iterator(BasicSymbolRef()); - } - basic_symbol_iterator symbol_end() const override { - llvm_unreachable("not implemented"); - return basic_symbol_iterator(BasicSymbolRef()); - } - - const ModuleSummaryIndex &getIndex() const { - return const_cast(this)->getIndex(); - } - ModuleSummaryIndex &getIndex() { return *Index; } - std::unique_ptr takeIndex(); - - static inline bool classof(const Binary *v) { - return v->isModuleSummaryIndex(); - } - - /// \brief Finds and returns bitcode embedded in the given object file, or an - /// error code if not found. - static ErrorOr findBitcodeInObject(const ObjectFile &Obj); - - /// \brief Finds and returns bitcode in the given memory buffer (which may - /// be either a bitcode file or a native object file with embedded bitcode), - /// or an error code if not found. - static ErrorOr - findBitcodeInMemBuffer(MemoryBufferRef Object); - - /// \brief Parse module summary index in the given memory buffer. - /// Return new ModuleSummaryIndexObjectFile instance containing parsed module - /// summary/index. - static Expected> - create(MemoryBufferRef Object); -}; - -} // end namespace object - -/// Parse the module summary index out of an IR file and return the module -/// summary index object if found, or nullptr if not. If Identifier is -/// non-empty, it is used as the module ID (module path) in the resulting -/// index. This can be used when the index is being read from a file -/// containing minimized bitcode just for the thin link. -Expected> -getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier = ""); - -} // end namespace llvm - -#endif // LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 11b0cf1..12d5be5 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -93,6 +93,13 @@ static cl::opt PrintSummaryGUIDs( cl::desc( "Print the global id for each value when reading the module summary")); +// FIXME: This flag should either be removed or moved to clang as a driver flag. +static llvm::cl::opt IgnoreEmptyThinLTOIndexFile( + "ignore-empty-index-file", llvm::cl::ZeroOrMore, + llvm::cl::desc( + "Ignore an empty index file and perform non-ThinLTO compilation"), + llvm::cl::init(false)); + namespace { enum { @@ -5609,3 +5616,14 @@ Expected llvm::hasGlobalValueSummary(MemoryBufferRef Buffer) { return BM->hasSummary(); } + +Expected> +llvm::getModuleSummaryIndexForFile(StringRef Path) { + ErrorOr> FileOrErr = + MemoryBuffer::getFileOrSTDIN(Path); + if (!FileOrErr) + return errorCodeToError(FileOrErr.getError()); + if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize()) + return nullptr; + return getModuleSummaryIndex(**FileOrErr); +} diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 1bc0d73..cc3d964 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -25,7 +25,6 @@ #include "llvm/LTO/LTOBackend.h" #include "llvm/Linker/IRMover.h" #include "llvm/Object/IRObjectFile.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/Error.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 0d845a2..d2fc892 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -33,7 +33,6 @@ #include "llvm/Linker/Linker.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Object/IRObjectFile.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Error.h" @@ -569,21 +568,19 @@ std::unique_ptr ThinLTOCodeGenerator::linkCombinedIndex() { std::unique_ptr CombinedIndex; uint64_t NextModuleId = 0; for (auto &ModuleBuffer : Modules) { - Expected> ObjOrErr = - object::ModuleSummaryIndexObjectFile::create( - ModuleBuffer.getMemBuffer()); - if (!ObjOrErr) { + Expected> IndexOrErr = + getModuleSummaryIndex(ModuleBuffer.getMemBuffer()); + if (!IndexOrErr) { // FIXME diagnose logAllUnhandledErrors( - ObjOrErr.takeError(), errs(), - "error: can't create ModuleSummaryIndexObjectFile for buffer: "); + IndexOrErr.takeError(), errs(), + "error: can't create module summary index for buffer: "); return nullptr; } - auto Index = (*ObjOrErr)->takeIndex(); if (CombinedIndex) { - CombinedIndex->mergeFrom(std::move(Index), ++NextModuleId); + CombinedIndex->mergeFrom(std::move(*IndexOrErr), ++NextModuleId); } else { - CombinedIndex = std::move(Index); + CombinedIndex = std::move(*IndexOrErr); } } return CombinedIndex; diff --git a/llvm/lib/Object/CMakeLists.txt b/llvm/lib/Object/CMakeLists.txt index 2007f56..08365e71 100644 --- a/llvm/lib/Object/CMakeLists.txt +++ b/llvm/lib/Object/CMakeLists.txt @@ -11,7 +11,6 @@ add_llvm_library(LLVMObject IRSymtab.cpp MachOObjectFile.cpp MachOUniversal.cpp - ModuleSummaryIndexObjectFile.cpp ModuleSymbolTable.cpp Object.cpp ObjectFile.cpp diff --git a/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp b/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp deleted file mode 100644 index 91f93a4..0000000 --- a/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp +++ /dev/null @@ -1,129 +0,0 @@ -//==- ModuleSummaryIndexObjectFile.cpp - Summary index file implementation -==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Part of the ModuleSummaryIndexObjectFile class implementation. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Bitcode/BitcodeReader.h" -#include "llvm/IR/ModuleSummaryIndex.h" -#include "llvm/Object/Binary.h" -#include "llvm/Object/Error.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" -#include "llvm/Object/ObjectFile.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/ErrorOr.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/MemoryBuffer.h" -#include -#include -#include - -using namespace llvm; -using namespace object; - -static cl::opt IgnoreEmptyThinLTOIndexFile( - "ignore-empty-index-file", cl::ZeroOrMore, - cl::desc( - "Ignore an empty index file and perform non-ThinLTO compilation"), - cl::init(false)); - -ModuleSummaryIndexObjectFile::ModuleSummaryIndexObjectFile( - MemoryBufferRef Object, std::unique_ptr I) - : SymbolicFile(Binary::ID_ModuleSummaryIndex, Object), Index(std::move(I)) { -} - -ModuleSummaryIndexObjectFile::~ModuleSummaryIndexObjectFile() = default; - -std::unique_ptr ModuleSummaryIndexObjectFile::takeIndex() { - return std::move(Index); -} - -ErrorOr -ModuleSummaryIndexObjectFile::findBitcodeInObject(const ObjectFile &Obj) { - for (const SectionRef &Sec : Obj.sections()) { - if (Sec.isBitcode()) { - StringRef SecContents; - if (std::error_code EC = Sec.getContents(SecContents)) - return EC; - return MemoryBufferRef(SecContents, Obj.getFileName()); - } - } - - return object_error::bitcode_section_not_found; -} - -ErrorOr -ModuleSummaryIndexObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) { - sys::fs::file_magic Type = sys::fs::identify_magic(Object.getBuffer()); - switch (Type) { - case sys::fs::file_magic::bitcode: - return Object; - case sys::fs::file_magic::elf_relocatable: - case sys::fs::file_magic::macho_object: - case sys::fs::file_magic::coff_object: { - Expected> ObjFile = - ObjectFile::createObjectFile(Object, Type); - if (!ObjFile) - return errorToErrorCode(ObjFile.takeError()); - return findBitcodeInObject(*ObjFile->get()); - } - default: - return object_error::invalid_file_type; - } -} - -// Parse module summary index in the given memory buffer. -// Return new ModuleSummaryIndexObjectFile instance containing parsed -// module summary/index. -Expected> -ModuleSummaryIndexObjectFile::create(MemoryBufferRef Object) { - ErrorOr BCOrErr = findBitcodeInMemBuffer(Object); - if (!BCOrErr) - return errorCodeToError(BCOrErr.getError()); - - Expected> IOrErr = - getModuleSummaryIndex(BCOrErr.get()); - - if (!IOrErr) - return IOrErr.takeError(); - - std::unique_ptr Index = std::move(IOrErr.get()); - return llvm::make_unique(Object, - std::move(Index)); -} - -// Parse the module summary index out of an IR file and return the summary -// index object if found, or nullptr if not. -Expected> -llvm::getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier) { - ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(Path); - std::error_code EC = FileOrErr.getError(); - if (EC) - return errorCodeToError(EC); - std::unique_ptr MemBuffer = std::move(FileOrErr.get()); - // If Identifier is non-empty, use it as the buffer identifier, which - // will become the module path in the index. - if (Identifier.empty()) - Identifier = MemBuffer->getBufferIdentifier(); - MemoryBufferRef BufferRef(MemBuffer->getBuffer(), Identifier); - if (IgnoreEmptyThinLTOIndexFile && !BufferRef.getBufferSize()) - return nullptr; - Expected> ObjOrErr = - object::ModuleSummaryIndexObjectFile::create(BufferRef); - if (!ObjOrErr) - return ObjOrErr.takeError(); - - object::ModuleSummaryIndexObjectFile &Obj = **ObjOrErr; - return Obj.takeIndex(); -} diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index d66411f..c7ef249 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" +#include "llvm/Bitcode/BitcodeReader.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/IntrinsicInst.h" @@ -25,7 +26,6 @@ #include "llvm/IRReader/IRReader.h" #include "llvm/Linker/Linker.h" #include "llvm/Object/IRObjectFile.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/SourceMgr.h" diff --git a/llvm/test/tools/llvm-lto/error.ll b/llvm/test/tools/llvm-lto/error.ll index 4a58fba..96bd566 100644 --- a/llvm/test/tools/llvm-lto/error.ll +++ b/llvm/test/tools/llvm-lto/error.ll @@ -5,4 +5,4 @@ ; CHECK-LIST: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file ; RUN: not llvm-lto --thinlto %S/Inputs/empty.bc 2>&1 | FileCheck %s --check-prefix=CHECK-THIN -; CHECK-THIN: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file +; CHECK-THIN: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': Invalid bitcode signature diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index a024b69..27199d5 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/STLExtras.h" +#include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/DiagnosticInfo.h" @@ -23,7 +24,6 @@ #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/Linker/Linker.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 2f00541..86cdf9b 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -23,7 +23,6 @@ #include "llvm/LTO/legacy/LTOCodeGenerator.h" #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h" -#include "llvm/Object/ModuleSummaryIndexObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" -- 2.7.4