Clang format a few prior patches (NFC)
[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
22 namespace object {
23 class ObjectFile;
24
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
28 /// object.
29 class FunctionIndexObjectFile : public SymbolicFile {
30   std::unique_ptr<FunctionInfoIndex> Index;
31
32 public:
33   FunctionIndexObjectFile(MemoryBufferRef Object,
34                           std::unique_ptr<FunctionInfoIndex> I);
35   ~FunctionIndexObjectFile() override;
36
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");
41   }
42   std::error_code printSymbolName(raw_ostream &OS,
43                                   DataRefImpl Symb) const override {
44     llvm_unreachable("not implemented");
45     return std::error_code();
46   }
47   uint32_t getSymbolFlags(DataRefImpl Symb) const override {
48     llvm_unreachable("not implemented");
49     return 0;
50   }
51   basic_symbol_iterator symbol_begin_impl() const override {
52     llvm_unreachable("not implemented");
53     return basic_symbol_iterator(BasicSymbolRef());
54   }
55   basic_symbol_iterator symbol_end_impl() const override {
56     llvm_unreachable("not implemented");
57     return basic_symbol_iterator(BasicSymbolRef());
58   }
59
60   const FunctionInfoIndex &getIndex() const {
61     return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
62   }
63   FunctionInfoIndex &getIndex() { return *Index; }
64   std::unique_ptr<FunctionInfoIndex> takeIndex();
65
66   static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
67
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);
71
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>
76   findBitcodeInMemBuffer(MemoryBufferRef Object);
77
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);
82
83   /// \brief Parse function index in the given memory buffer.
84   /// Return new FunctionIndexObjectFile instance containing parsed function
85   /// summary/index.
86   static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
87   create(MemoryBufferRef Object, LLVMContext &Context, bool IsLazy = false);
88
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,
93                                                  LLVMContext &Context,
94                                                  StringRef FunctionName);
95 };
96 }
97 }
98
99 #endif