llvm.org GIT mirror llvm / 6a2cc4c
Object: Remove ModuleSummaryIndexObjectFile class. Differential Revision: https://reviews.llvm.org/D32195 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301832 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 2 years ago
12 changed file(s) with 35 addition(s) and 260 deletion(s). Raw diff Collapse all Expand all
139139 /// Parse the specified bitcode buffer, returning the module summary index.
140140 Expected>
141141 getModuleSummaryIndex(MemoryBufferRef Buffer);
142
143 /// Parse the module summary index out of an IR file and return the module
144 /// summary index object if found, or an empty summary if not. If Path refers
145 /// to an empty file and the -ignore-empty-index-file cl::opt flag is passed
146 /// this function will return nullptr.
147 Expected>
148 getModuleSummaryIndexForFile(StringRef Path);
142149
143150 /// isBitcodeWrapper - Return true if the given bytes are the magic bytes
144151 /// for an LLVM IR bitcode wrapper.
4141 ID_MachOUniversalBinary,
4242 ID_COFFImportFile,
4343 ID_IR, // LLVM IR
44 ID_ModuleSummaryIndex, // Module summary index
4544
4645 // Object and children.
4746 ID_StartObjects,
126125 bool isIR() const {
127126 return TypeID == ID_IR;
128127 }
129
130 bool isModuleSummaryIndex() const { return TypeID == ID_ModuleSummaryIndex; }
131128
132129 bool isLittleEndian() const {
133130 return !(TypeID == ID_ELF32B || TypeID == ID_ELF64B ||
+0
-112
include/llvm/Object/ModuleSummaryIndexObjectFile.h less more
None //===- ModuleSummaryIndexObjectFile.h - Summary index file implementation -===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the ModuleSummaryIndexObjectFile template class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H
14 #define LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H
15
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Object/SymbolicFile.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/ErrorOr.h"
22 #include "llvm/Support/MemoryBuffer.h"
23 #include
24 #include
25
26 namespace llvm {
27
28 class ModuleSummaryIndex;
29
30 namespace object {
31
32 class ObjectFile;
33
34 /// This class is used to read just the module summary index related
35 /// sections out of the given object (which may contain a single module's
36 /// bitcode or be a combined index bitcode file). It builds a ModuleSummaryIndex
37 /// object.
38 class ModuleSummaryIndexObjectFile : public SymbolicFile {
39 std::unique_ptr Index;
40
41 public:
42 ModuleSummaryIndexObjectFile(MemoryBufferRef Object,
43 std::unique_ptr I);
44 ~ModuleSummaryIndexObjectFile() override;
45
46 // TODO: Walk through GlobalValueMap entries for symbols.
47 // However, currently these interfaces are not used by any consumers.
48 void moveSymbolNext(DataRefImpl &Symb) const override {
49 llvm_unreachable("not implemented");
50 }
51
52 std::error_code printSymbolName(raw_ostream &OS,
53 DataRefImpl Symb) const override {
54 llvm_unreachable("not implemented");
55 return std::error_code();
56 }
57
58 uint32_t getSymbolFlags(DataRefImpl Symb) const override {
59 llvm_unreachable("not implemented");
60 return 0;
61 }
62
63 basic_symbol_iterator symbol_begin() const override {
64 llvm_unreachable("not implemented");
65 return basic_symbol_iterator(BasicSymbolRef());
66 }
67 basic_symbol_iterator symbol_end() const override {
68 llvm_unreachable("not implemented");
69 return basic_symbol_iterator(BasicSymbolRef());
70 }
71
72 const ModuleSummaryIndex &getIndex() const {
73 return const_cast(this)->getIndex();
74 }
75 ModuleSummaryIndex &getIndex() { return *Index; }
76 std::unique_ptr takeIndex();
77
78 static inline bool classof(const Binary *v) {
79 return v->isModuleSummaryIndex();
80 }
81
82 /// \brief Finds and returns bitcode embedded in the given object file, or an
83 /// error code if not found.
84 static ErrorOr findBitcodeInObject(const ObjectFile &Obj);
85
86 /// \brief Finds and returns bitcode in the given memory buffer (which may
87 /// be either a bitcode file or a native object file with embedded bitcode),
88 /// or an error code if not found.
89 static ErrorOr
90 findBitcodeInMemBuffer(MemoryBufferRef Object);
91
92 /// \brief Parse module summary index in the given memory buffer.
93 /// Return new ModuleSummaryIndexObjectFile instance containing parsed module
94 /// summary/index.
95 static Expected>
96 create(MemoryBufferRef Object);
97 };
98
99 } // end namespace object
100
101 /// Parse the module summary index out of an IR file and return the module
102 /// summary index object if found, or nullptr if not. If Identifier is
103 /// non-empty, it is used as the module ID (module path) in the resulting
104 /// index. This can be used when the index is being read from a file
105 /// containing minimized bitcode just for the thin link.
106 Expected>
107 getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier = "");
108
109 } // end namespace llvm
110
111 #endif // LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H
9191 "print-summary-global-ids", cl::init(false), cl::Hidden,
9292 cl::desc(
9393 "Print the global id for each value when reading the module summary"));
94
95 // FIXME: This flag should either be removed or moved to clang as a driver flag.
96 static llvm::cl::opt IgnoreEmptyThinLTOIndexFile(
97 "ignore-empty-index-file", llvm::cl::ZeroOrMore,
98 llvm::cl::desc(
99 "Ignore an empty index file and perform non-ThinLTO compilation"),
100 llvm::cl::init(false));
94101
95102 namespace {
96103
56085615
56095616 return BM->hasSummary();
56105617 }
5618
5619 Expected>
5620 llvm::getModuleSummaryIndexForFile(StringRef Path) {
5621 ErrorOr> FileOrErr =
5622 MemoryBuffer::getFileOrSTDIN(Path);
5623 if (!FileOrErr)
5624 return errorCodeToError(FileOrErr.getError());
5625 if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize())
5626 return nullptr;
5627 return getModuleSummaryIndex(**FileOrErr);
5628 }
2424 #include "llvm/LTO/LTOBackend.h"
2525 #include "llvm/Linker/IRMover.h"
2626 #include "llvm/Object/IRObjectFile.h"
27 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
2827 #include "llvm/Support/Error.h"
2928 #include "llvm/Support/ManagedStatic.h"
3029 #include "llvm/Support/MemoryBuffer.h"
3232 #include "llvm/Linker/Linker.h"
3333 #include "llvm/MC/SubtargetFeature.h"
3434 #include "llvm/Object/IRObjectFile.h"
35 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
3635 #include "llvm/Support/CachePruning.h"
3736 #include "llvm/Support/Debug.h"
3837 #include "llvm/Support/Error.h"
568567 std::unique_ptr CombinedIndex;
569568 uint64_t NextModuleId = 0;
570569 for (auto &ModuleBuffer : Modules) {
571 Expected> ObjOrErr =
572 object::ModuleSummaryIndexObjectFile::create(
573 ModuleBuffer.getMemBuffer());
574 if (!ObjOrErr) {
570 Expected> IndexOrErr =
571 getModuleSummaryIndex(ModuleBuffer.getMemBuffer());
572 if (!IndexOrErr) {
575573 // FIXME diagnose
576574 logAllUnhandledErrors(
577 ObjOrErr.takeError(), errs(),
578 "error: can't create ModuleSummaryIndexObjectFile for buffer: ");
575 IndexOrErr.takeError(), errs(),
576 "error: can't create module summary index for buffer: ");
579577 return nullptr;
580578 }
581 auto Index = (*ObjOrErr)->takeIndex();
582579 if (CombinedIndex) {
583 CombinedIndex->mergeFrom(std::move(Index), ++NextModuleId);
580 CombinedIndex->mergeFrom(std::move(*IndexOrErr), ++NextModuleId);
584581 } else {
585 CombinedIndex = std::move(Index);
582 CombinedIndex = std::move(*IndexOrErr);
586583 }
587584 }
588585 return CombinedIndex;
1010 IRSymtab.cpp
1111 MachOObjectFile.cpp
1212 MachOUniversal.cpp
13 ModuleSummaryIndexObjectFile.cpp
1413 ModuleSymbolTable.cpp
1514 Object.cpp
1615 ObjectFile.cpp
+0
-129
lib/Object/ModuleSummaryIndexObjectFile.cpp less more
None //==- ModuleSummaryIndexObjectFile.cpp - Summary index file implementation -==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Part of the ModuleSummaryIndexObjectFile class implementation.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Bitcode/BitcodeReader.h"
16 #include "llvm/IR/ModuleSummaryIndex.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Object/Error.h"
19 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/ErrorOr.h"
24 #include "llvm/Support/FileSystem.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include
27 #include
28 #include
29
30 using namespace llvm;
31 using namespace object;
32
33 static cl::opt IgnoreEmptyThinLTOIndexFile(
34 "ignore-empty-index-file", cl::ZeroOrMore,
35 cl::desc(
36 "Ignore an empty index file and perform non-ThinLTO compilation"),
37 cl::init(false));
38
39 ModuleSummaryIndexObjectFile::ModuleSummaryIndexObjectFile(
40 MemoryBufferRef Object, std::unique_ptr I)
41 : SymbolicFile(Binary::ID_ModuleSummaryIndex, Object), Index(std::move(I)) {
42 }
43
44 ModuleSummaryIndexObjectFile::~ModuleSummaryIndexObjectFile() = default;
45
46 std::unique_ptr ModuleSummaryIndexObjectFile::takeIndex() {
47 return std::move(Index);
48 }
49
50 ErrorOr
51 ModuleSummaryIndexObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
52 for (const SectionRef &Sec : Obj.sections()) {
53 if (Sec.isBitcode()) {
54 StringRef SecContents;
55 if (std::error_code EC = Sec.getContents(SecContents))
56 return EC;
57 return MemoryBufferRef(SecContents, Obj.getFileName());
58 }
59 }
60
61 return object_error::bitcode_section_not_found;
62 }
63
64 ErrorOr
65 ModuleSummaryIndexObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) {
66 sys::fs::file_magic Type = sys::fs::identify_magic(Object.getBuffer());
67 switch (Type) {
68 case sys::fs::file_magic::bitcode:
69 return Object;
70 case sys::fs::file_magic::elf_relocatable:
71 case sys::fs::file_magic::macho_object:
72 case sys::fs::file_magic::coff_object: {
73 Expected> ObjFile =
74 ObjectFile::createObjectFile(Object, Type);
75 if (!ObjFile)
76 return errorToErrorCode(ObjFile.takeError());
77 return findBitcodeInObject(*ObjFile->get());
78 }
79 default:
80 return object_error::invalid_file_type;
81 }
82 }
83
84 // Parse module summary index in the given memory buffer.
85 // Return new ModuleSummaryIndexObjectFile instance containing parsed
86 // module summary/index.
87 Expected>
88 ModuleSummaryIndexObjectFile::create(MemoryBufferRef Object) {
89 ErrorOr BCOrErr = findBitcodeInMemBuffer(Object);
90 if (!BCOrErr)
91 return errorCodeToError(BCOrErr.getError());
92
93 Expected> IOrErr =
94 getModuleSummaryIndex(BCOrErr.get());
95
96 if (!IOrErr)
97 return IOrErr.takeError();
98
99 std::unique_ptr Index = std::move(IOrErr.get());
100 return llvm::make_unique(Object,
101 std::move(Index));
102 }
103
104 // Parse the module summary index out of an IR file and return the summary
105 // index object if found, or nullptr if not.
106 Expected>
107 llvm::getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier) {
108 ErrorOr> FileOrErr =
109 MemoryBuffer::getFileOrSTDIN(Path);
110 std::error_code EC = FileOrErr.getError();
111 if (EC)
112 return errorCodeToError(EC);
113 std::unique_ptr MemBuffer = std::move(FileOrErr.get());
114 // If Identifier is non-empty, use it as the buffer identifier, which
115 // will become the module path in the index.
116 if (Identifier.empty())
117 Identifier = MemBuffer->getBufferIdentifier();
118 MemoryBufferRef BufferRef(MemBuffer->getBuffer(), Identifier);
119 if (IgnoreEmptyThinLTOIndexFile && !BufferRef.getBufferSize())
120 return nullptr;
121 Expected> ObjOrErr =
122 object::ModuleSummaryIndexObjectFile::create(BufferRef);
123 if (!ObjOrErr)
124 return ObjOrErr.takeError();
125
126 object::ModuleSummaryIndexObjectFile &Obj = **ObjOrErr;
127 return Obj.takeIndex();
128 }
1616 #include "llvm/ADT/Statistic.h"
1717 #include "llvm/ADT/StringSet.h"
1818 #include "llvm/ADT/Triple.h"
19 #include "llvm/Bitcode/BitcodeReader.h"
1920 #include "llvm/IR/AutoUpgrade.h"
2021 #include "llvm/IR/DiagnosticPrinter.h"
2122 #include "llvm/IR/IntrinsicInst.h"
2425 #include "llvm/IRReader/IRReader.h"
2526 #include "llvm/Linker/Linker.h"
2627 #include "llvm/Object/IRObjectFile.h"
27 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
2828 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/Support/Debug.h"
3030 #include "llvm/Support/SourceMgr.h"
44 ; CHECK-LIST: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file
55
66 ; RUN: not llvm-lto --thinlto %S/Inputs/empty.bc 2>&1 | FileCheck %s --check-prefix=CHECK-THIN
7 ; CHECK-THIN: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file
7 ; CHECK-THIN: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': Invalid bitcode signature
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/Bitcode/BitcodeReader.h"
1516 #include "llvm/Bitcode/BitcodeWriter.h"
1617 #include "llvm/IR/AutoUpgrade.h"
1718 #include "llvm/IR/DiagnosticInfo.h"
2223 #include "llvm/IR/Verifier.h"
2324 #include "llvm/IRReader/IRReader.h"
2425 #include "llvm/Linker/Linker.h"
25 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
2626 #include "llvm/Support/CommandLine.h"
2727 #include "llvm/Support/FileSystem.h"
2828 #include "llvm/Support/ManagedStatic.h"
2222 #include "llvm/LTO/legacy/LTOCodeGenerator.h"
2323 #include "llvm/LTO/legacy/LTOModule.h"
2424 #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
25 #include "llvm/Object/ModuleSummaryIndexObjectFile.h"
2625 #include "llvm/Support/CommandLine.h"
2726 #include "llvm/Support/FileSystem.h"
2827 #include "llvm/Support/ManagedStatic.h"