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/IR/DiagnosticInfo.h"
18 #include "llvm/Object/SymbolicFile.h"
21 class FunctionInfoIndex;
27 /// This class is used to read just the function 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 FunctionInfoIndex
31 class FunctionIndexObjectFile : public SymbolicFile {
32 std::unique_ptr<FunctionInfoIndex> Index;
35 FunctionIndexObjectFile(MemoryBufferRef Object,
36 std::unique_ptr<FunctionInfoIndex> I);
37 ~FunctionIndexObjectFile() override;
39 // TODO: Walk through FunctionMap entries for function 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_impl() const override {
54 llvm_unreachable("not implemented");
55 return basic_symbol_iterator(BasicSymbolRef());
57 basic_symbol_iterator symbol_end_impl() const override {
58 llvm_unreachable("not implemented");
59 return basic_symbol_iterator(BasicSymbolRef());
62 const FunctionInfoIndex &getIndex() const {
63 return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
65 FunctionInfoIndex &getIndex() { return *Index; }
66 std::unique_ptr<FunctionInfoIndex> takeIndex();
68 static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
70 /// \brief Finds and returns bitcode embedded in the given object file, or an
71 /// error code if not found.
72 static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
74 /// \brief Finds and returns bitcode in the given memory buffer (which may
75 /// be either a bitcode file or a native object file with embedded bitcode),
76 /// or an error code if not found.
77 static ErrorOr<MemoryBufferRef>
78 findBitcodeInMemBuffer(MemoryBufferRef Object);
80 /// \brief Looks for function summary in the given memory buffer,
81 /// returns true if found, else false.
83 hasFunctionSummaryInMemBuffer(MemoryBufferRef Object,
84 DiagnosticHandlerFunction DiagnosticHandler);
86 /// \brief Parse function index in the given memory buffer.
87 /// Return new FunctionIndexObjectFile instance containing parsed function
89 static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
90 create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
93 /// \brief Parse the function summary information for function with the
94 /// given name out of the given buffer. Parsed information is
95 /// stored on the index object saved in this object.
97 findFunctionSummaryInMemBuffer(MemoryBufferRef Object,
98 DiagnosticHandlerFunction DiagnosticHandler,
99 StringRef FunctionName);
103 /// Parse the function index out of an IR file and return the function
104 /// index object if found, or nullptr if not.
105 ErrorOr<std::unique_ptr<FunctionInfoIndex>>
106 getFunctionIndexForFile(StringRef Path,
107 DiagnosticHandlerFunction DiagnosticHandler);