-/// Parse the function index out of an IR file and return the function
-/// index object if found, or nullptr if not.
-static ErrorOr<std::unique_ptr<FunctionInfoIndex>>
-getFunctionIndexForFile(StringRef Path,
- DiagnosticHandlerFunction DiagnosticHandler) {
- std::unique_ptr<MemoryBuffer> Buffer;
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
- MemoryBuffer::getFile(Path);
- if (std::error_code EC = BufferOrErr.getError())
- return EC;
- Buffer = std::move(BufferOrErr.get());
-
- // Don't bother trying to build an index if there is no summary information
- // in this bitcode file.
- if (!object::FunctionIndexObjectFile::hasFunctionSummaryInMemBuffer(
- Buffer->getMemBufferRef(), DiagnosticHandler))
- return std::unique_ptr<FunctionInfoIndex>(nullptr);
-
- ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
- object::FunctionIndexObjectFile::create(Buffer->getMemBufferRef(),
- DiagnosticHandler);
- if (std::error_code EC = ObjOrErr.getError())
- return EC;
- return (*ObjOrErr)->takeIndex();
-}
-