From 5bc2a0e513b345ce6788f2d399e90c307ff98186 Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Mon, 11 Feb 2019 22:01:13 +0000 Subject: [PATCH] [IRReader] Expose getLazyIRModule Currently there is no way to lazy-load an in-memory IR module without first writing it to disk. This patch just exposes the existing implementation of getLazyIRModule. This is effectively a revert of rL212364 Differential Revision: https://reviews.llvm.org/D56203 llvm-svn: 353755 --- include/llvm/IRReader/IRReader.h | 11 +++++++++++ lib/IRReader/IRReader.cpp | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/llvm/IRReader/IRReader.h b/include/llvm/IRReader/IRReader.h index e0213700afe..05171300b60 100644 --- a/include/llvm/IRReader/IRReader.h +++ b/include/llvm/IRReader/IRReader.h @@ -20,11 +20,22 @@ namespace llvm { class StringRef; +class MemoryBuffer; class MemoryBufferRef; class Module; class SMDiagnostic; class LLVMContext; +/// If the given MemoryBuffer holds a bitcode image, return a Module +/// for it which does lazy deserialization of function bodies. Otherwise, +/// attempt to parse it as LLVM Assembly and return a fully populated +/// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode +/// reader to optionally enable lazy metadata loading. This takes ownership +/// of \p Buffer. +std::unique_ptr getLazyIRModule(std::unique_ptr Buffer, + SMDiagnostic &Err, LLVMContext &Context, + bool ShouldLazyLoadMetadata = false); + /// If the given file holds a bitcode image, return a Module /// for it which does lazy deserialization of function bodies. Otherwise, /// attempt to parse it as LLVM Assembly and return a fully populated diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp index ec4422b04e6..7ca6c2fca52 100644 --- a/lib/IRReader/IRReader.cpp +++ b/lib/IRReader/IRReader.cpp @@ -29,9 +29,9 @@ static const char *const TimeIRParsingGroupDescription = "LLVM IR Parsing"; static const char *const TimeIRParsingName = "parse"; static const char *const TimeIRParsingDescription = "Parse IR"; -static std::unique_ptr -getLazyIRModule(std::unique_ptr Buffer, SMDiagnostic &Err, - LLVMContext &Context, bool ShouldLazyLoadMetadata) { +std::unique_ptr +llvm::getLazyIRModule(std::unique_ptr Buffer, SMDiagnostic &Err, + LLVMContext &Context, bool ShouldLazyLoadMetadata) { if (isBitcode((const unsigned char *)Buffer->getBufferStart(), (const unsigned char *)Buffer->getBufferEnd())) { Expected> ModuleOrErr = getOwningLazyBitcodeModule(