1 //===- ModuleSummaryIndexObjectFile.h - Summary index file implementation -=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the ModuleSummaryIndexObjectFile template class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H
15 #define LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H
17 #include "llvm/IR/DiagnosticInfo.h"
18 #include "llvm/Object/SymbolicFile.h"
21 class ModuleSummaryIndex;
27 /// This class is used to read just the module summary index related
28 /// sections out of the given object (which may contain a single module's
29 /// bitcode or be a combined index bitcode file). It builds a ModuleSummaryIndex
31 class ModuleSummaryIndexObjectFile : public SymbolicFile {
32 std::unique_ptr<ModuleSummaryIndex> Index;
35 ModuleSummaryIndexObjectFile(MemoryBufferRef Object,
36 std::unique_ptr<ModuleSummaryIndex> I);
37 ~ModuleSummaryIndexObjectFile() override;
39 // TODO: Walk through GlobalValueMap entries for symbols.
40 // However, currently these interfaces are not used by any consumers.
41 void moveSymbolNext(DataRefImpl &Symb) const override {
42 llvm_unreachable("not implemented");
44 std::error_code printSymbolName(raw_ostream &OS,
45 DataRefImpl Symb) const override {
46 llvm_unreachable("not implemented");
47 return std::error_code();
49 uint32_t getSymbolFlags(DataRefImpl Symb) const override {
50 llvm_unreachable("not implemented");
53 basic_symbol_iterator symbol_begin() const override {
54 llvm_unreachable("not implemented");
55 return basic_symbol_iterator(BasicSymbolRef());
57 basic_symbol_iterator symbol_end() const override {
58 llvm_unreachable("not implemented");
59 return basic_symbol_iterator(BasicSymbolRef());
62 const ModuleSummaryIndex &getIndex() const {
63 return const_cast<ModuleSummaryIndexObjectFile *>(this)->getIndex();
65 ModuleSummaryIndex &getIndex() { return *Index; }
66 std::unique_ptr<ModuleSummaryIndex> takeIndex();
68 static inline bool classof(const Binary *v) {
69 return v->isModuleSummaryIndex();
72 /// \brief Finds and returns bitcode embedded in the given object file, or an
73 /// error code if not found.
74 static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
76 /// \brief Finds and returns bitcode in the given memory buffer (which may
77 /// be either a bitcode file or a native object file with embedded bitcode),
78 /// or an error code if not found.
79 static ErrorOr<MemoryBufferRef>
80 findBitcodeInMemBuffer(MemoryBufferRef Object);
82 /// \brief Parse module summary index in the given memory buffer.
83 /// Return new ModuleSummaryIndexObjectFile instance containing parsed module
85 static Expected<std::unique_ptr<ModuleSummaryIndexObjectFile>>
86 create(MemoryBufferRef Object);
90 /// Parse the module summary index out of an IR file and return the module
91 /// summary index object if found, or nullptr if not. If Identifier is
92 /// non-empty, it is used as the module ID (module path) in the resulting
93 /// index. This can be used when the index is being read from a file
94 /// containing minimized bitcode just for the thin link.
95 Expected<std::unique_ptr<ModuleSummaryIndex>>
96 getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier = "");