[llvm] r226533 - Bitcode: Add ValueEnumerator::getMetadataOrNullID(), NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 19 17:00:24 PST 2015
Author: dexonsmith
Date: Mon Jan 19 19:00:23 2015
New Revision: 226533
URL: http://llvm.org/viewvc/llvm-project?rev=226533&view=rev
Log:
Bitcode: Add ValueEnumerator::getMetadataOrNullID(), NFC
Modified:
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=226533&r1=226532&r2=226533&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Jan 19 19:00:23 2015
@@ -768,12 +768,9 @@ static void WriteMDNode(const MDNode *N,
SmallVectorImpl<uint64_t> &Record) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Metadata *MD = N->getOperand(i);
- if (!MD) {
- Record.push_back(0);
- continue;
- }
- assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata");
- Record.push_back(VE.getMetadataID(MD) + 1);
+ assert(!(MD && isa<LocalAsMetadata>(MD)) &&
+ "Unexpected function-local metadata");
+ Record.push_back(VE.getMetadataOrNullID(MD));
}
Stream.EmitRecord(N->isDistinct() ? bitc::METADATA_DISTINCT_NODE
: bitc::METADATA_NODE,
@@ -789,12 +786,7 @@ static void WriteMDLocation(const MDLoca
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);
+ Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev);
Record.clear();
@@ -1754,8 +1746,8 @@ static void WriteFunction(const Function
Vals.push_back(DL.getLine());
Vals.push_back(DL.getCol());
- Vals.push_back(Scope ? VE.getMetadataID(Scope) + 1 : 0);
- Vals.push_back(IA ? VE.getMetadataID(IA) + 1 : 0);
+ Vals.push_back(VE.getMetadataOrNullID(Scope));
+ Vals.push_back(VE.getMetadataOrNullID(IA));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
Vals.clear();
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=226533&r1=226532&r2=226533&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Mon Jan 19 19:00:23 2015
@@ -410,12 +410,6 @@ unsigned ValueEnumerator::getValueID(con
return I->second-1;
}
-unsigned ValueEnumerator::getMetadataID(const Metadata *MD) const {
- auto I = MDValueMap.find(MD);
- assert(I != MDValueMap.end() && "Metadata not in slotcalculator!");
- return I->second - 1;
-}
-
void ValueEnumerator::dump() const {
print(dbgs(), ValueMap, "Default");
dbgs() << '\n';
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h?rev=226533&r1=226532&r2=226533&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h Mon Jan 19 19:00:23 2015
@@ -109,7 +109,14 @@ public:
const char *Name) const;
unsigned getValueID(const Value *V) const;
- unsigned getMetadataID(const Metadata *V) const;
+ unsigned getMetadataID(const Metadata *MD) const {
+ auto ID = getMetadataOrNullID(MD);
+ assert(ID != 0 && "Metadata not in slotcalculator!");
+ return ID - 1;
+ }
+ unsigned getMetadataOrNullID(const Metadata *MD) const {
+ return MDValueMap.lookup(MD);
+ }
bool hasMDString() const { return HasMDString; }
bool hasMDLocation() const { return HasMDLocation; }
More information about the llvm-commits
mailing list