Support for ThinLTO function importing and symbol linking.
[oota-llvm.git] / include / llvm / Object / FunctionIndexObjectFile.h
1 //===- FunctionIndexObjectFile.h - Function index file implementation -----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the FunctionIndexObjectFile template class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
15 #define LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
16
17 #include "llvm/Object/SymbolicFile.h"
18
19 namespace llvm {
20 class FunctionInfoIndex;
21 class Module;
22
23 namespace object {
24 class ObjectFile;
25
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
29 /// object.
30 class FunctionIndexObjectFile : public SymbolicFile {
31   std::unique_ptr<FunctionInfoIndex> Index;
32
33 public:
34   FunctionIndexObjectFile(MemoryBufferRef Object,
35                           std::unique_ptr<FunctionInfoIndex> I);
36   ~FunctionIndexObjectFile() override;
37
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");
42   }
43   std::error_code printSymbolName(raw_ostream &OS,
44                                   DataRefImpl Symb) const override {
45     llvm_unreachable("not implemented");
46     return std::error_code();
47   }
48   uint32_t getSymbolFlags(DataRefImpl Symb) const override {
49     llvm_unreachable("not implemented");
50     return 0;
51   }
52   basic_symbol_iterator symbol_begin_impl() const override {
53     llvm_unreachable("not implemented");
54     return basic_symbol_iterator(BasicSymbolRef());
55   }
56   basic_symbol_iterator symbol_end_impl() const override {
57     llvm_unreachable("not implemented");
58     return basic_symbol_iterator(BasicSymbolRef());
59   }
60
61   const FunctionInfoIndex &getIndex() const {
62     return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
63   }
64   FunctionInfoIndex &getIndex() { return *Index; }
65   std::unique_ptr<FunctionInfoIndex> takeIndex();
66
67   static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
68
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);
72
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);
78
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);
83
84   /// \brief Parse function index in the given memory buffer.
85   /// Return new FunctionIndexObjectFile instance containing parsed function
86   /// summary/index.
87   static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
88   create(MemoryBufferRef Object, LLVMContext &Context,
89          const Module *ExportingModule = nullptr, bool IsLazy = false);
90
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,
95                                                  LLVMContext &Context,
96                                                  StringRef FunctionName);
97 };
98 }
99 }
100
101 #endif