From 6b92316811e1d3be74ab0f535efcd3918853f2f6 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 23 Nov 2015 19:19:11 +0000 Subject: [ThinLTO] Deduplicate function index loading into shared helper (NFC) Add a shared helper routine to read the function index from a file and create/return the function index object. Use it in llvm-link and llvm-lto. llvm-svn: 253903 --- llvm/lib/Object/FunctionIndexObjectFile.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'llvm/lib/Object/FunctionIndexObjectFile.cpp') diff --git a/llvm/lib/Object/FunctionIndexObjectFile.cpp b/llvm/lib/Object/FunctionIndexObjectFile.cpp index f4b2b5562a3..717c56bc901 100644 --- a/llvm/lib/Object/FunctionIndexObjectFile.cpp +++ b/llvm/lib/Object/FunctionIndexObjectFile.cpp @@ -120,3 +120,26 @@ std::error_code FunctionIndexObjectFile::findFunctionSummaryInMemBuffer( return object_error::invalid_file_type; } } + +// Parse the function index out of an IR file and return the function +// index object if found, or nullptr if not. +ErrorOr> +llvm::getFunctionIndexForFile(StringRef Path, + DiagnosticHandlerFunction DiagnosticHandler, + const Module *ExportingModule) { + ErrorOr> FileOrErr = + MemoryBuffer::getFileOrSTDIN(Path); + std::error_code EC = FileOrErr.getError(); + if (EC) + return EC; + MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef(); + ErrorOr> ObjOrErr = + object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler, + ExportingModule); + EC = ObjOrErr.getError(); + if (EC) + return EC; + + object::FunctionIndexObjectFile &Obj = **ObjOrErr; + return Obj.takeIndex(); +} -- cgit v1.2.3