Files
archived-llvm/include/llvm/Object/FunctionIndexObjectFile.h
Teresa Johnson dc6615addb [ThinLTO] Support for reference graph in per-module and combined summary.
Summary:
This patch adds support for including a full reference graph including
call graph edges and other GV references in the summary.

The reference graph edges can be used to make importing decisions
without materializing any source modules, can be used in the plugin
to make file staging decisions for distributed build systems, and is
expected to have other uses.

The call graph edges are recorded in each function summary in the
bitcode via a list of <CalleeValueIds, StaticCount> tuples when no PGO
data exists, or <CalleeValueId, StaticCount, ProfileCount> pairs when
there is PGO, where the ValueId can be mapped to the function GUID via
the ValueSymbolTable. In the function index in memory, the call graph
edges reference the target via the CalleeGUID instead of the
CalleeValueId.

The reference graph edges are recorded in each summary record with a
list of referenced value IDs, which can be mapped to value GUID via the
ValueSymbolTable.

Addtionally, a new summary record type is added to record references
from global variable initializers. A number of bitcode records and data
structures have been renamed to reflect the newly expanded scope of the
summary beyond functions. More cleanup will follow.

Reviewers: joker.eph, davidxl

Subscribers: joker.eph, llvm-commits

Differential Revision: http://reviews.llvm.org/D17212

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263275 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-11 18:52:24 +00:00

111 lines
4.1 KiB
C++

//===- FunctionIndexObjectFile.h - Function index file implementation -----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file declares the FunctionIndexObjectFile template class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
#define LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Object/SymbolicFile.h"
namespace llvm {
class FunctionInfoIndex;
class Module;
namespace object {
class ObjectFile;
/// This class is used to read just the function summary index related
/// sections out of the given object (which may contain a single module's
/// bitcode or be a combined index bitcode file). It builds a FunctionInfoIndex
/// object.
class FunctionIndexObjectFile : public SymbolicFile {
std::unique_ptr<FunctionInfoIndex> Index;
public:
FunctionIndexObjectFile(MemoryBufferRef Object,
std::unique_ptr<FunctionInfoIndex> I);
~FunctionIndexObjectFile() override;
// TODO: Walk through FunctionMap entries for function symbols.
// However, currently these interfaces are not used by any consumers.
void moveSymbolNext(DataRefImpl &Symb) const override {
llvm_unreachable("not implemented");
}
std::error_code printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const override {
llvm_unreachable("not implemented");
return std::error_code();
}
uint32_t getSymbolFlags(DataRefImpl Symb) const override {
llvm_unreachable("not implemented");
return 0;
}
basic_symbol_iterator symbol_begin_impl() const override {
llvm_unreachable("not implemented");
return basic_symbol_iterator(BasicSymbolRef());
}
basic_symbol_iterator symbol_end_impl() const override {
llvm_unreachable("not implemented");
return basic_symbol_iterator(BasicSymbolRef());
}
const FunctionInfoIndex &getIndex() const {
return const_cast<FunctionIndexObjectFile *>(this)->getIndex();
}
FunctionInfoIndex &getIndex() { return *Index; }
std::unique_ptr<FunctionInfoIndex> takeIndex();
static inline bool classof(const Binary *v) { return v->isFunctionIndex(); }
/// \brief Finds and returns bitcode embedded in the given object file, or an
/// error code if not found.
static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
/// \brief Finds and returns bitcode in the given memory buffer (which may
/// be either a bitcode file or a native object file with embedded bitcode),
/// or an error code if not found.
static ErrorOr<MemoryBufferRef>
findBitcodeInMemBuffer(MemoryBufferRef Object);
/// \brief Looks for summary sections in the given memory buffer,
/// returns true if found, else false.
static bool
hasGlobalValueSummaryInMemBuffer(MemoryBufferRef Object,
DiagnosticHandlerFunction DiagnosticHandler);
/// \brief Parse function index in the given memory buffer.
/// Return new FunctionIndexObjectFile instance containing parsed function
/// summary/index.
static ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
bool IsLazy = false);
/// \brief Parse the function summary information for function with the
/// given name out of the given buffer. Parsed information is
/// stored on the index object saved in this object.
std::error_code
findFunctionSummaryInMemBuffer(MemoryBufferRef Object,
DiagnosticHandlerFunction DiagnosticHandler,
StringRef FunctionName);
};
}
/// Parse the function index out of an IR file and return the function
/// index object if found, or nullptr if not.
ErrorOr<std::unique_ptr<FunctionInfoIndex>>
getFunctionIndexForFile(StringRef Path,
DiagnosticHandlerFunction DiagnosticHandler);
}
#endif