AsmParser/Bitcode: Add support for MDLocation

This adds assembly and bitcode support for `MDLocation`.  The assembly
side is rather big, since this is the first `MDNode` subclass (that
isn't `MDTuple`).  Part of PR21433.

(If you're wondering where the mountains of testcase updates are, we
don't need them until I update `DILocation` and `DebugLoc` to actually
use this class.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225830 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-13 21:10:44 +00:00
parent 7c06364dc0
commit 3b0fe4ec0a
15 changed files with 284 additions and 5 deletions

View File

@ -779,6 +779,25 @@ static void WriteMDNode(const MDNode *N,
Record.clear();
}
static void WriteMDLocation(const MDLocation *N, const ValueEnumerator &VE,
BitstreamWriter &Stream,
SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) {
Record.push_back(N->isDistinct());
Record.push_back(N->getLine());
Record.push_back(N->getColumn());
Record.push_back(VE.getMetadataID(N->getScope()));
// Always emit the inlined-at location, even though it's optional.
if (Metadata *InlinedAt = N->getInlinedAt())
Record.push_back(VE.getMetadataID(InlinedAt) + 1);
else
Record.push_back(0);
Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev);
Record.clear();
}
static void WriteModuleMetadata(const Module *M,
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
@ -798,6 +817,22 @@ static void WriteModuleMetadata(const Module *M,
MDSAbbrev = Stream.EmitAbbrev(Abbv);
}
unsigned LocAbbrev = 0;
if (VE.hasMDLocation()) {
// Abbrev for METADATA_LOCATION.
//
// Assume the column is usually under 128, and always output the inlined-at
// location (it's never more expensive than building an array size 1).
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_LOCATION));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
LocAbbrev = Stream.EmitAbbrev(Abbv);
}
unsigned NameAbbrev = 0;
if (!M->named_metadata_empty()) {
// Abbrev for METADATA_NAME.
@ -810,6 +845,10 @@ static void WriteModuleMetadata(const Module *M,
SmallVector<uint64_t, 64> Record;
for (const Metadata *MD : MDs) {
if (const MDLocation *Loc = dyn_cast<MDLocation>(MD)) {
WriteMDLocation(Loc, VE, Stream, Record, LocAbbrev);
continue;
}
if (const MDNode *N = dyn_cast<MDNode>(MD)) {
WriteMDNode(N, VE, Stream, Record);
continue;