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;
25 /// This class is used to read just the function summary index related
26 /// sections out of the given object (which may contain a single module's
27 /// bitcode or be a combined index bitcode file). It builds a FunctionInfoIndex
29 class FunctionIndexObjectFile : public SymbolicFile {
30 std::unique_ptr<FunctionInfoIndex> Index;
33 FunctionIndexObjectFile(MemoryBufferRef Object,
34 std::unique_ptr<FunctionInfoIndex> I);
35 ~FunctionIndexObjectFile() override;
37 // TODO: Walk through FunctionMap entries for function symbols.
38 // However, currently these interfaces are not used by any consumers.
39 void moveSymbolNext(DataRefImpl &Symb) const override {
40 llvm_unreachable("not implemented");
42 std::error_code printSymbolName(raw_ostream &OS,
43 DataRefImpl Symb) const override {
44 llvm_unreachable("not implemented");
45 return std::error_code();
47 uint32_t getSymbolFlags(DataRefImpl Symb) const override {
48 llvm_unreachable("not implemented");
51 basic_symbol_iterator symbol_begin_impl() const override {
52 llvm_unreachable("not implemented");
53 return basic_symbol_iterator(BasicSymbolRef());
55 basic_symbol_iterator symbol_end_impl() const override {
56 llvm_unreachable("not implemented");
57 return basic_symbol_iterator(BasicSymbolRef());
60 const FunctionInfoIndex &getIndex() const {
61 return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
63 FunctionInfoIndex &getIndex() { return *Index; }
64 std::unique_ptr<FunctionInfoIndex> takeIndex();
66 static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
68 /// \brief Finds and returns bitcode embedded in the given object file, or an
69 /// error code if not found.
70 static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
72 /// \brief Finds and returns bitcode in the given memory buffer (which may
73 /// be either a bitcode file or a native object file with embedded bitcode),
74 /// or an error code if not found.
75 static ErrorOr<MemoryBufferRef> findBitcodeInMemBuffer(
76 MemoryBufferRef Object);
78 /// \brief Looks for function summary in the given memory buffer,
79 /// returns true if found, else false.
80 static bool hasFunctionSummaryInMemBuffer(MemoryBufferRef Object,
81 LLVMContext &Context);
83 /// \brief Parse function index in the given memory buffer.
84 /// Return new FunctionIndexObjectFile instance containing parsed function
86 static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>> create(
87 MemoryBufferRef Object, LLVMContext &Context, bool IsLazy = false);
89 /// \brief Parse the function summary information for function with the
90 /// given name out of the given buffer. Parsed information is
91 /// stored on the index object saved in this object.
92 std::error_code findFunctionSummaryInMemBuffer(MemoryBufferRef Object,
94 StringRef FunctionName);