Skip to content

Commit

Permalink
BitcodeWriter: Move abbreviation for DILocation; almost NFC
Browse files Browse the repository at this point in the history
Simplify ValueEnumerator and WriteModuleMetadata by shifting the logic
for the METADATA_LOCATION abbreviation into WriteDILocation.

The only change is that the abbreviation is emitted later in the
bitcode, just before the first `DILocation` record.  This shouldn't be
observable though.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264302 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Mar 24, 2016
1 parent 7c9efaa commit 3601e72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
33 changes: 17 additions & 16 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,26 @@ static void WriteMDTuple(const MDTuple *N, const ValueEnumerator &VE,
Record.clear();
}

static unsigned createDILocationAbbrev(BitstreamWriter &Stream) {
// 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));
return Stream.EmitAbbrev(Abbv);
}

static void WriteDILocation(const DILocation *N, const ValueEnumerator &VE,
BitstreamWriter &Stream,
SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) {
unsigned &Abbrev) {
if (!Abbrev)
Abbrev = createDILocationAbbrev(Stream);

Record.push_back(N->isDistinct());
Record.push_back(N->getLine());
Record.push_back(N->getColumn());
Expand Down Expand Up @@ -1354,21 +1370,6 @@ static void WriteModuleMetadata(const Module &M,
#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
#include "llvm/IR/Metadata.def"

if (VE.hasDILocation()) {
// 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));
DILocationAbbrev = Stream.EmitAbbrev(Abbv);
}

if (VE.hasGenericDINode()) {
// Abbrev for METADATA_GENERIC_DEBUG.
//
Expand Down
3 changes: 1 addition & 2 deletions lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) {

ValueEnumerator::ValueEnumerator(const Module &M,
bool ShouldPreserveUseListOrder)
: HasMDString(false), HasDILocation(false), HasGenericDINode(false),
: HasMDString(false), HasGenericDINode(false),
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
if (ShouldPreserveUseListOrder)
UseListOrders = predictUseListOrder(M);
Expand Down Expand Up @@ -532,7 +532,6 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
EnumerateValue(C->getValue());

HasMDString |= isa<MDString>(MD);
HasDILocation |= isa<DILocation>(MD);
HasGenericDINode |= isa<GenericDINode>(MD);

// Replace the dummy ID inserted above with the correct one. MetadataMap may
Expand Down
2 changes: 0 additions & 2 deletions lib/Bitcode/Writer/ValueEnumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class ValueEnumerator {
typedef DenseMap<const Metadata *, unsigned> MetadataMapType;
MetadataMapType MetadataMap;
bool HasMDString;
bool HasDILocation;
bool HasGenericDINode;
bool ShouldPreserveUseListOrder;

Expand Down Expand Up @@ -124,7 +123,6 @@ class ValueEnumerator {
unsigned numMDs() const { return MDs.size(); }

bool hasMDString() const { return HasMDString; }
bool hasDILocation() const { return HasDILocation; }
bool hasGenericDINode() const { return HasGenericDINode; }

bool shouldPreserveUseListOrder() const { return ShouldPreserveUseListOrder; }
Expand Down

0 comments on commit 3601e72

Please sign in to comment.