[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
This commit is contained in:
Teresa Johnson
2015-11-20 14:51:27 +00:00
parent d8d9839ae6
commit d4d3dfd8ef
5 changed files with 76 additions and 6 deletions

View File

@@ -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;