aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-05-23 22:54:06 +0000
committerTeresa Johnson <tejohnson@google.com>2016-05-23 22:54:06 +0000
commitdf6edc52777077db08aa9f1ed2d49944731630fa (patch)
tree1ee4b36cda7895e9b3e15bf3b79cef98f09bc6ad /llvm/lib/LTO/LTO.cpp
parent73d7a555b9fe75d0461dfdc52f5a085cb60d3127 (diff)
downloadllvm-df6edc52777077db08aa9f1ed2d49944731630fa.zip
llvm-df6edc52777077db08aa9f1ed2d49944731630fa.tar.gz
llvm-df6edc52777077db08aa9f1ed2d49944731630fa.tar.bz2
[ThinLTO] Refactor module loader handling into new LTO file (NFC)
Moved the ModuleLoader and supporting helper loadModuleFromBuffer out of ThinLTOCodeGenerator and into new LTO.h/LTO.cpp files. This is in preparation for a patch that will utilize these in the gold-plugin. Note that there are some other pending patches (D20268 and D20290) that also plan to refactor common interfaces and functionality into this same pair of new files. llvm-svn: 270509
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
new file mode 100644
index 0000000..5f89e5c
--- /dev/null
+++ b/llvm/lib/LTO/LTO.cpp
@@ -0,0 +1,42 @@
+//===-LTO.cpp - LLVM Link Time Optimizer ----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements functions and classes used to support LTO.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/LTO/LTO.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+
+// Simple helper to load a module from bitcode
+std::unique_ptr<Module> loadModuleFromBuffer(const MemoryBufferRef &Buffer,
+ LLVMContext &Context, bool Lazy) {
+ SMDiagnostic Err;
+ ErrorOr<std::unique_ptr<Module>> ModuleOrErr(nullptr);
+ if (Lazy) {
+ ModuleOrErr =
+ getLazyBitcodeModule(MemoryBuffer::getMemBuffer(Buffer, false), Context,
+ /* ShouldLazyLoadMetadata */ Lazy);
+ } else {
+ ModuleOrErr = parseBitcodeFile(Buffer, Context);
+ }
+ if (std::error_code EC = ModuleOrErr.getError()) {
+ Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
+ EC.message());
+ Err.print("ThinLTO", errs());
+ report_fatal_error("Can't load module, abort.");
+ }
+ return std::move(ModuleOrErr.get());
+}
+}