aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-01 22:27:19 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-01 22:27:19 +0000
commit6e1009b65e985412267d5e263a99afbcdd5ae936 (patch)
treed29878235a592736142d339b6a6742b21da270e9 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent3516669a50bb64ee7d27c0bbc00b2439477071bf (diff)
downloadllvm-6e1009b65e985412267d5e263a99afbcdd5ae936.zip
llvm-6e1009b65e985412267d5e263a99afbcdd5ae936.tar.gz
llvm-6e1009b65e985412267d5e263a99afbcdd5ae936.tar.bz2
UseListOrder: Fix blockaddress use-list order
`parseBitcodeFile()` uses the generic `getLazyBitcodeFile()` function as a helper. Since `parseBitcodeFile()` isn't actually lazy -- it calls `MaterializeAllPermanently()` -- bypass the unnecessary call to `materializeForwardReferencedFunctions()` by extracting out a common helper function. This removes the last of the use-list churn caused by blockaddresses. This highlights that we can't reproduce use-list order of globals and constants when parsing lazily -- but that's necessarily out of scope. When we're parsing lazily, we never have all the functions in memory, so the use-lists of globals (and constants that reference globals) are always incomplete. This is part of PR5680. llvm-svn: 214581
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 48fa9390..85dde39 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3503,10 +3503,17 @@ const std::error_category &llvm::BitcodeErrorCategory() {
// External interface
//===----------------------------------------------------------------------===//
-/// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
+/// \brief Get a lazy one-at-time loading module from bitcode.
///
-ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
- LLVMContext &Context) {
+/// This isn't always used in a lazy context. In particular, it's also used by
+/// \a parseBitcodeFile(). If this is truly lazy, then we need to eagerly pull
+/// in forward-referenced functions from block address references.
+///
+/// \param[in] WillMaterializeAll Set to \c true if the caller promises to
+/// materialize everything -- in particular, if this isn't truly lazy.
+static ErrorOr<Module *> getLazyBitcodeModuleImpl(MemoryBuffer *Buffer,
+ LLVMContext &Context,
+ bool WillMaterializeAll) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R = new BitcodeReader(Buffer, Context);
M->setMaterializer(R);
@@ -3520,12 +3527,18 @@ ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
if (std::error_code EC = R->ParseBitcodeInto(M))
return cleanupOnError(EC);
- if (std::error_code EC = R->materializeForwardReferencedFunctions())
- return cleanupOnError(EC);
+ if (!WillMaterializeAll)
+ // Resolve forward references from blockaddresses.
+ if (std::error_code EC = R->materializeForwardReferencedFunctions())
+ return cleanupOnError(EC);
return M;
}
+ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
+ LLVMContext &Context) {
+ return getLazyBitcodeModuleImpl(Buffer, Context, false);
+}
Module *llvm::getStreamedBitcodeModule(const std::string &name,
DataStreamer *streamer,
@@ -3545,7 +3558,8 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBuffer *Buffer,
LLVMContext &Context) {
- ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
+ ErrorOr<Module *> ModuleOrErr =
+ getLazyBitcodeModuleImpl(Buffer, Context, true);
if (!ModuleOrErr)
return ModuleOrErr;
Module *M = ModuleOrErr.get();