1 //===- FunctionIndexObjectFile.h - Function 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 FunctionIndexObjectFile template class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
15 #define LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
17 #include "llvm/Object/SymbolicFile.h"
20 class FunctionInfoIndex;
26 /// This class is used to read just the function summary index related
27 /// sections out of the given object (which may contain a single module's
28 /// bitcode or be a combined index bitcode file). It builds a FunctionInfoIndex
30 class FunctionIndexObjectFile : public SymbolicFile {
31 std::unique_ptr<FunctionInfoIndex> Index;
34 FunctionIndexObjectFile(MemoryBufferRef Object,
35 std::unique_ptr<FunctionInfoIndex> I);
36 ~FunctionIndexObjectFile() override;
38 // TODO: Walk through FunctionMap entries for function symbols.
39 // However, currently these interfaces are not used by any consumers.
40 void moveSymbolNext(DataRefImpl &Symb) const override {
41 llvm_unreachable("not implemented");
43 std::error_code printSymbolName(raw_ostream &OS,
44 DataRefImpl Symb) const override {
45 llvm_unreachable("not implemented");
46 return std::error_code();
48 uint32_t getSymbolFlags(DataRefImpl Symb) const override {
49 llvm_unreachable("not implemented");
52 basic_symbol_iterator symbol_begin_impl() const override {
53 llvm_unreachable("not implemented");
54 return basic_symbol_iterator(BasicSymbolRef());
56 basic_symbol_iterator symbol_end_impl() const override {
57 llvm_unreachable("not implemented");
58 return basic_symbol_iterator(BasicSymbolRef());
61 const FunctionInfoIndex &getIndex() const {
62 return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
64 FunctionInfoIndex &getIndex() { return *Index; }
65 std::unique_ptr<FunctionInfoIndex> takeIndex();
67 static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
69 /// \brief Finds and returns bitcode embedded in the given object file, or an
70 /// error code if not found.
71 static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
73 /// \brief Finds and returns bitcode in the given memory buffer (which may
74 /// be either a bitcode file or a native object file with embedded bitcode),
75 /// or an error code if not found.
76 static ErrorOr<MemoryBufferRef>
77 findBitcodeInMemBuffer(MemoryBufferRef Object);
79 /// \brief Looks for function summary in the given memory buffer,
80 /// returns true if found, else false.
81 static bool hasFunctionSummaryInMemBuffer(MemoryBufferRef Object,
82 LLVMContext &Context);
84 /// \brief Parse function index in the given memory buffer.
85 /// Return new FunctionIndexObjectFile instance containing parsed function
87 static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
88 create(MemoryBufferRef Object, LLVMContext &Context,
89 const Module *ExportingModule = nullptr, bool IsLazy = false);
91 /// \brief Parse the function summary information for function with the
92 /// given name out of the given buffer. Parsed information is
93 /// stored on the index object saved in this object.
94 std::error_code findFunctionSummaryInMemBuffer(MemoryBufferRef Object,
96 StringRef FunctionName);