[PATCH] D28751: [ThinLTO] Add a recursive step in Metadata lazy-loading
Mehdi AMINI via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 15 16:37:27 PST 2017
mehdi_amini updated this revision to Diff 84508.
mehdi_amini added a comment.
Add a comment, and handles correctly uniquing cycles (even if I didn't encounter any when bootstrapping clang)
https://reviews.llvm.org/D28751
Files:
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Index: llvm/lib/Bitcode/Reader/MetadataLoader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -768,13 +768,12 @@
unsigned ID, PlaceholderQueue &Placeholders) {
assert(ID < (MDStringRef.size()) + GlobalMetadataBitPosIndex.size());
assert(ID >= MDStringRef.size() && "Unexpected lazy-loading of MDString");
-#ifndef NDEBUG
// Lookup first if the metadata hasn't already been loaded.
if (auto *MD = MetadataList.lookup(ID)) {
auto *N = dyn_cast_or_null<MDNode>(MD);
- assert(N && N->isTemporary() && "Lazy loading an already loaded metadata");
+ if (!N->isTemporary())
+ return;
}
-#endif
SmallVector<uint64_t, 64> Record;
StringRef Blob;
IndexCursor.JumpToBit(GlobalMetadataBitPosIndex[ID - MDStringRef.size()]);
@@ -827,8 +826,20 @@
auto getMD = [&](unsigned ID) -> Metadata * {
if (ID < MDStringRef.size())
return lazyLoadOneMDString(ID);
- if (!IsDistinct)
- return MetadataList.getMetadataFwdRef(ID);
+ if (!IsDistinct) {
+ if (auto *MD = MetadataList.lookup(ID))
+ return MD;
+ // Create a temporary, it is needed before recursing in case there are
+ // uniquing cycles.
+ auto *TempMD = MetadataList.getMetadataFwdRef(ID);
+ // If lazy-loading is enabled, we try recursively to load the operand
+ // instead of creating a temporary.
+ if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
+ lazyLoadOneMetadata(ID, Placeholders);
+ return MetadataList.lookup(ID);
+ }
+ return TempMD;
+ }
if (auto *MD = MetadataList.getMetadataIfResolved(ID))
return MD;
return &Placeholders.getPlaceholderOp(ID);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28751.84508.patch
Type: text/x-patch
Size: 1794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170116/0c636368/attachment.bin>
More information about the llvm-commits
mailing list