summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2015-11-19 05:52:29 +0000
committerMehdi Amini <mehdi.amini@apple.com>2015-11-19 05:52:29 +0000
commit354f520fbcb0a410a56a3f543640f434cb2d1fa2 (patch)
treef07267e11a60e3bf82517c1c8a84ee0369c21ff6 /llvm
parent00aecfc388173f94e532e376662ff26198064a83 (diff)
downloadbcm5719-llvm-354f520fbcb0a410a56a3f543640f434cb2d1fa2.tar.gz
bcm5719-llvm-354f520fbcb0a410a56a3f543640f434cb2d1fa2.zip
Do not require a Context to extract the FunctionIndex from Bitcode (NFC)
The LLVMContext was only used for Diagnostic. Pass a DiagnosticHandler instead. Differential Revision: http://reviews.llvm.org/D14794 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 253540
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Bitcode/ReaderWriter.h18
-rw-r--r--llvm/include/llvm/Object/FunctionIndexObjectFile.h15
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp39
-rw-r--r--llvm/lib/Object/FunctionIndexObjectFile.cpp14
-rw-r--r--llvm/tools/llvm-link/llvm-link.cpp2
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp34
6 files changed, 71 insertions, 51 deletions
diff --git a/llvm/include/llvm/Bitcode/ReaderWriter.h b/llvm/include/llvm/Bitcode/ReaderWriter.h
index dc039557ae3..1c08ded1656 100644
--- a/llvm/include/llvm/Bitcode/ReaderWriter.h
+++ b/llvm/include/llvm/Bitcode/ReaderWriter.h
@@ -67,7 +67,7 @@ namespace llvm {
DiagnosticHandlerFunction DiagnosticHandler = nullptr);
/// Check if the given bitcode buffer contains a function summary block.
- bool hasFunctionSummary(MemoryBufferRef Buffer, LLVMContext &Context,
+ bool hasFunctionSummary(MemoryBufferRef Buffer,
DiagnosticHandlerFunction DiagnosticHandler);
/// Parse the specified bitcode buffer, returning the function info index.
@@ -77,11 +77,9 @@ namespace llvm {
/// the index. Otherwise skip the function summary section, and only create
/// an index object with a map from function name to function summary offset.
/// The index is used to perform lazy function summary reading later.
- ErrorOr<std::unique_ptr<FunctionInfoIndex>>
- getFunctionInfoIndex(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler,
- const Module *ExportingModule = nullptr,
- bool IsLazy = false);
+ ErrorOr<std::unique_ptr<FunctionInfoIndex>> getFunctionInfoIndex(
+ MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
+ const Module *ExportingModule = nullptr, bool IsLazy = false);
/// This method supports lazy reading of function summary data from the
/// combined index during function importing. When reading the combined index
@@ -89,11 +87,9 @@ namespace llvm {
/// Then this method is called for each function considered for importing,
/// to parse the summary information for the given function name into
/// the index.
- std::error_code
- readFunctionSummary(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler,
- StringRef FunctionName,
- std::unique_ptr<FunctionInfoIndex> Index);
+ std::error_code readFunctionSummary(
+ MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
+ StringRef FunctionName, std::unique_ptr<FunctionInfoIndex> Index);
/// \brief Write the specified module to the specified raw output stream.
///
diff --git a/llvm/include/llvm/Object/FunctionIndexObjectFile.h b/llvm/include/llvm/Object/FunctionIndexObjectFile.h
index 12057447f5c..92b670db49a 100644
--- a/llvm/include/llvm/Object/FunctionIndexObjectFile.h
+++ b/llvm/include/llvm/Object/FunctionIndexObjectFile.h
@@ -14,6 +14,7 @@
#ifndef LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
#define LLVM_OBJECT_FUNCTIONINDEXOBJECTFILE_H
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Object/SymbolicFile.h"
namespace llvm {
@@ -78,22 +79,24 @@ public:
/// \brief Looks for function summary in the given memory buffer,
/// returns true if found, else false.
- static bool hasFunctionSummaryInMemBuffer(MemoryBufferRef Object,
- LLVMContext &Context);
+ static bool
+ hasFunctionSummaryInMemBuffer(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, LLVMContext &Context,
+ create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
const Module *ExportingModule = nullptr, 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,
- LLVMContext &Context,
- StringRef FunctionName);
+ std::error_code
+ findFunctionSummaryInMemBuffer(MemoryBufferRef Object,
+ DiagnosticHandlerFunction DiagnosticHandler,
+ StringRef FunctionName);
};
}
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 9210042e6ed..36bf1e8ef63 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -470,12 +470,11 @@ public:
std::error_code error(BitcodeError E);
std::error_code error(const Twine &Message);
- FunctionIndexBitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context,
+ FunctionIndexBitcodeReader(MemoryBuffer *Buffer,
DiagnosticHandlerFunction DiagnosticHandler,
bool IsLazy = false,
bool CheckFuncSummaryPresenceOnly = false);
- FunctionIndexBitcodeReader(LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler,
+ FunctionIndexBitcodeReader(DiagnosticHandlerFunction DiagnosticHandler,
bool IsLazy = false,
bool CheckFuncSummaryPresenceOnly = false);
~FunctionIndexBitcodeReader() { freeState(); }
@@ -5406,18 +5405,15 @@ std::error_code FunctionIndexBitcodeReader::error(BitcodeError E) {
}
FunctionIndexBitcodeReader::FunctionIndexBitcodeReader(
- MemoryBuffer *Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler, bool IsLazy,
- bool CheckFuncSummaryPresenceOnly)
- : DiagnosticHandler(getDiagHandler(DiagnosticHandler, Context)),
- Buffer(Buffer), IsLazy(IsLazy),
+ MemoryBuffer *Buffer, DiagnosticHandlerFunction DiagnosticHandler,
+ bool IsLazy, bool CheckFuncSummaryPresenceOnly)
+ : DiagnosticHandler(DiagnosticHandler), Buffer(Buffer), IsLazy(IsLazy),
CheckFuncSummaryPresenceOnly(CheckFuncSummaryPresenceOnly) {}
FunctionIndexBitcodeReader::FunctionIndexBitcodeReader(
- LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler,
- bool IsLazy, bool CheckFuncSummaryPresenceOnly)
- : DiagnosticHandler(getDiagHandler(DiagnosticHandler, Context)),
- Buffer(nullptr), IsLazy(IsLazy),
+ DiagnosticHandlerFunction DiagnosticHandler, bool IsLazy,
+ bool CheckFuncSummaryPresenceOnly)
+ : DiagnosticHandler(DiagnosticHandler), Buffer(nullptr), IsLazy(IsLazy),
CheckFuncSummaryPresenceOnly(CheckFuncSummaryPresenceOnly) {}
void FunctionIndexBitcodeReader::freeState() { Buffer = nullptr; }
@@ -5941,11 +5937,11 @@ llvm::getBitcodeProducerString(MemoryBufferRef Buffer, LLVMContext &Context,
// an index object with a map from function name to function summary offset.
// The index is used to perform lazy function summary reading later.
ErrorOr<std::unique_ptr<FunctionInfoIndex>>
-llvm::getFunctionInfoIndex(MemoryBufferRef Buffer, LLVMContext &Context,
+llvm::getFunctionInfoIndex(MemoryBufferRef Buffer,
DiagnosticHandlerFunction DiagnosticHandler,
const Module *ExportingModule, bool IsLazy) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- FunctionIndexBitcodeReader R(Buf.get(), Context, DiagnosticHandler, IsLazy);
+ FunctionIndexBitcodeReader R(Buf.get(), DiagnosticHandler, IsLazy);
std::unique_ptr<FunctionInfoIndex> Index =
llvm::make_unique<FunctionInfoIndex>(ExportingModule);
@@ -5963,11 +5959,10 @@ llvm::getFunctionInfoIndex(MemoryBufferRef Buffer, LLVMContext &Context,
}
// Check if the given bitcode buffer contains a function summary block.
-bool llvm::hasFunctionSummary(MemoryBufferRef Buffer, LLVMContext &Context,
+bool llvm::hasFunctionSummary(MemoryBufferRef Buffer,
DiagnosticHandlerFunction DiagnosticHandler) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- FunctionIndexBitcodeReader R(Buf.get(), Context, DiagnosticHandler, false,
- true);
+ FunctionIndexBitcodeReader R(Buf.get(), DiagnosticHandler, false, true);
auto cleanupOnError = [&](std::error_code EC) {
R.releaseBuffer(); // Never take ownership on error.
@@ -5987,13 +5982,11 @@ bool llvm::hasFunctionSummary(MemoryBufferRef Buffer, LLVMContext &Context,
// Then this method is called for each function considered for importing,
// to parse the summary information for the given function name into
// the index.
-std::error_code
-llvm::readFunctionSummary(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler,
- StringRef FunctionName,
- std::unique_ptr<FunctionInfoIndex> Index) {
+std::error_code llvm::readFunctionSummary(
+ MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
+ StringRef FunctionName, std::unique_ptr<FunctionInfoIndex> Index) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- FunctionIndexBitcodeReader R(Buf.get(), Context, DiagnosticHandler);
+ FunctionIndexBitcodeReader R(Buf.get(), DiagnosticHandler);
auto cleanupOnError = [&](std::error_code EC) {
R.releaseBuffer(); // Never take ownership on error.
diff --git a/llvm/lib/Object/FunctionIndexObjectFile.cpp b/llvm/lib/Object/FunctionIndexObjectFile.cpp
index ee65990c528..f4b2b5562a3 100644
--- a/llvm/lib/Object/FunctionIndexObjectFile.cpp
+++ b/llvm/lib/Object/FunctionIndexObjectFile.cpp
@@ -72,19 +72,20 @@ FunctionIndexObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) {
// Looks for function index in the given memory buffer.
// returns true if found, else false.
bool FunctionIndexObjectFile::hasFunctionSummaryInMemBuffer(
- MemoryBufferRef Object, LLVMContext &Context) {
+ MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler) {
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr)
return false;
- return hasFunctionSummary(BCOrErr.get(), Context, nullptr);
+ return hasFunctionSummary(BCOrErr.get(), DiagnosticHandler);
}
// Parse function index in the given memory buffer.
// Return new FunctionIndexObjectFile instance containing parsed
// function summary/index.
ErrorOr<std::unique_ptr<FunctionIndexObjectFile>>
-FunctionIndexObjectFile::create(MemoryBufferRef Object, LLVMContext &Context,
+FunctionIndexObjectFile::create(MemoryBufferRef Object,
+ DiagnosticHandlerFunction DiagnosticHandler,
const Module *ExportingModule, bool IsLazy) {
std::unique_ptr<FunctionInfoIndex> Index;
@@ -93,7 +94,7 @@ FunctionIndexObjectFile::create(MemoryBufferRef Object, LLVMContext &Context,
return BCOrErr.getError();
ErrorOr<std::unique_ptr<FunctionInfoIndex>> IOrErr = getFunctionInfoIndex(
- BCOrErr.get(), Context, nullptr, ExportingModule, IsLazy);
+ BCOrErr.get(), DiagnosticHandler, ExportingModule, IsLazy);
if (std::error_code EC = IOrErr.getError())
return EC;
@@ -107,11 +108,12 @@ FunctionIndexObjectFile::create(MemoryBufferRef Object, LLVMContext &Context,
// given name out of the given buffer. Parsed information is
// stored on the index object saved in this object.
std::error_code FunctionIndexObjectFile::findFunctionSummaryInMemBuffer(
- MemoryBufferRef Object, LLVMContext &Context, StringRef FunctionName) {
+ MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
+ StringRef FunctionName) {
sys::fs::file_magic Type = sys::fs::identify_magic(Object.getBuffer());
switch (Type) {
case sys::fs::file_magic::bitcode: {
- return readFunctionSummary(Object, Context, nullptr, FunctionName,
+ return readFunctionSummary(Object, DiagnosticHandler, FunctionName,
std::move(Index));
}
default:
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 8d0ce0a040f..c539f75702b 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -148,7 +148,7 @@ loadIndex(LLVMContext &Context, const Module *ExportingModule = nullptr) {
return EC;
MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef();
ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
- object::FunctionIndexObjectFile::create(BufferRef, Context,
+ object::FunctionIndexObjectFile::create(BufferRef, diagnosticHandler,
ExportingModule);
EC = ObjOrErr.getError();
if (EC)
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index c74353282b6..cdf91f9e377 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/LTO/LTOCodeGenerator.h"
#include "llvm/LTO/LTOModule.h"
@@ -119,6 +120,32 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity,
errs() << Msg << "\n";
}
+static void diagnosticHandler(const DiagnosticInfo &DI) {
+ raw_ostream &OS = errs();
+ OS << "llvm-lto: ";
+ switch (DI.getSeverity()) {
+ case DS_Error:
+ OS << "error: ";
+ break;
+ case DS_Warning:
+ OS << "warning: ";
+ break;
+ case DS_Remark:
+ OS << "remark: ";
+ break;
+ case DS_Note:
+ OS << "note: ";
+ break;
+ }
+
+ DiagnosticPrinterRawOStream DP(OS);
+ DI.print(DP);
+ OS << '\n';
+
+ if (DI.getSeverity() == DS_Error)
+ exit(1);
+}
+
static std::unique_ptr<LTOModule>
getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer,
const TargetOptions &Options, std::string &Error) {
@@ -163,7 +190,7 @@ static int listSymbols(StringRef Command, const TargetOptions &Options) {
/// index object if found, or nullptr if not.
static std::unique_ptr<FunctionInfoIndex>
getFunctionIndexForFile(StringRef Path, std::string &Error,
- LLVMContext &Context) {
+ DiagnosticHandlerFunction DiagnosticHandler) {
std::unique_ptr<MemoryBuffer> Buffer;
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(Path);
@@ -174,7 +201,7 @@ getFunctionIndexForFile(StringRef Path, std::string &Error,
Buffer = std::move(BufferOrErr.get());
ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
object::FunctionIndexObjectFile::create(Buffer->getMemBufferRef(),
- Context);
+ DiagnosticHandler);
if (std::error_code EC = ObjOrErr.getError()) {
Error = EC.message();
return nullptr;
@@ -187,13 +214,12 @@ getFunctionIndexForFile(StringRef Path, std::string &Error,
/// This is meant to enable testing of ThinLTO combined index generation,
/// currently available via the gold plugin via -thinlto.
static int createCombinedFunctionIndex(StringRef Command) {
- LLVMContext Context;
FunctionInfoIndex CombinedIndex;
uint64_t NextModuleId = 0;
for (auto &Filename : InputFilenames) {
std::string Error;
std::unique_ptr<FunctionInfoIndex> Index =
- getFunctionIndexForFile(Filename, Error, Context);
+ getFunctionIndexForFile(Filename, Error, diagnosticHandler);
if (!Index) {
errs() << Command << ": error loading file '" << Filename
<< "': " << Error << "\n";
OpenPOWER on IntegriCloud