summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Writer
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2015-11-20 14:51:27 +0000
committerTeresa Johnson <tejohnson@google.com>2015-11-20 14:51:27 +0000
commitd4d3dfd8ef1c58b5ec900ce8c349ccf35dcd2912 (patch)
treede6683a8ad44e5959fd94dd8ff7912500acca507 /llvm/lib/Bitcode/Writer
parentd8d9839ae67dacb569dcc3e1fcabdbeefb62fe8b (diff)
downloadbcm5719-llvm-d4d3dfd8ef1c58b5ec900ce8c349ccf35dcd2912.tar.gz
bcm5719-llvm-d4d3dfd8ef1c58b5ec900ce8c349ccf35dcd2912.zip
[ThinLTO] Add MODULE_CODE_METADATA_VALUES record
Summary: This is split out from the ThinLTO metadata mapping patch http://reviews.llvm.org/D14752. To avoid needing to parse the module level metadata during function importing, a new module-level record is added which holds the number of module-level metadata values. This is required because metadata value ids are assigned implicitly during parsing, and the function-level metadata ids start after the module-level metadata ids. I made a change to this version of the code compared to D14752 in order to add more consistent and thorough assertion checking of the new record value. We now unconditionally use the record value to initialize the MDValueList size, and handle it the same in parseMetadata for all module level metadata cases (lazy loading or not). Reviewers: dexonsmith, joker.eph Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D14825 llvm-svn: 253668
Diffstat (limited to 'llvm/lib/Bitcode/Writer')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp15
-rw-r--r--llvm/lib/Bitcode/Writer/ValueEnumerator.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7586112325e..b1b699765bd 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -776,6 +776,21 @@ static uint64_t WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.clear();
}
+ // Write a record indicating the number of module-level metadata IDs
+ // This is needed because the ids of metadata are assigned implicitly
+ // based on their ordering in the bitcode, with the function-level
+ // metadata ids starting after the module-level metadata ids. For
+ // function importing where we lazy load the metadata as a postpass,
+ // we want to avoid parsing the module-level metadata before parsing
+ // the imported functions.
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_METADATA_VALUES));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
+ unsigned MDValsAbbrev = Stream.EmitAbbrev(Abbv);
+ Vals.push_back(VE.numMDs());
+ Stream.EmitRecord(bitc::MODULE_CODE_METADATA_VALUES, Vals, MDValsAbbrev);
+ Vals.clear();
+
uint64_t VSTOffsetPlaceholder =
WriteValueSymbolTableForwardDecl(M->getValueSymbolTable(), Stream);
return VSTOffsetPlaceholder;
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.h b/llvm/lib/Bitcode/Writer/ValueEnumerator.h
index 92d166e3ba9..abe383d7ee4 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.h
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.h
@@ -119,6 +119,7 @@ public:
unsigned getMetadataOrNullID(const Metadata *MD) const {
return MDValueMap.lookup(MD);
}
+ unsigned numMDs() const { return MDs.size(); }
bool hasMDString() const { return HasMDString; }
bool hasDILocation() const { return HasDILocation; }
OpenPOWER on IntegriCloud