Rename MDValue* to Metadata* (NFC)

Renamed MDValue* to Metadata*, and MDValueToValIDMap to MetadataToIDs,
as per review for r255909.

llvm-svn: 256593
This commit is contained in:
Teresa Johnson 2015-12-29 23:00:22 +00:00
parent 0e4a24a44f
commit b23b3067db
5 changed files with 158 additions and 153 deletions

View File

@ -52,8 +52,8 @@ public:
/// instantiations. If OnlyTempMD is true, only those that have remained /// instantiations. If OnlyTempMD is true, only those that have remained
/// temporary metadata are recorded in the map. /// temporary metadata are recorded in the map.
virtual void virtual void
saveMDValueList(DenseMap<const Metadata *, unsigned> &MDValueToValIDMap, saveMetadataList(DenseMap<const Metadata *, unsigned> &MetadataToIDs,
bool OnlyTempMD) {} bool OnlyTempMD) {}
virtual std::vector<StructType *> getIdentifiedStructTypes() const = 0; virtual std::vector<StructType *> getIdentifiedStructTypes() const = 0;
}; };

View File

@ -94,35 +94,35 @@ public:
void resolveConstantForwardRefs(); void resolveConstantForwardRefs();
}; };
class BitcodeReaderMDValueList { class BitcodeReaderMetadataList {
unsigned NumFwdRefs; unsigned NumFwdRefs;
bool AnyFwdRefs; bool AnyFwdRefs;
unsigned MinFwdRef; unsigned MinFwdRef;
unsigned MaxFwdRef; unsigned MaxFwdRef;
std::vector<TrackingMDRef> MDValuePtrs; std::vector<TrackingMDRef> MetadataPtrs;
LLVMContext &Context; LLVMContext &Context;
public: public:
BitcodeReaderMDValueList(LLVMContext &C) BitcodeReaderMetadataList(LLVMContext &C)
: NumFwdRefs(0), AnyFwdRefs(false), Context(C) {} : NumFwdRefs(0), AnyFwdRefs(false), Context(C) {}
// vector compatibility methods // vector compatibility methods
unsigned size() const { return MDValuePtrs.size(); } unsigned size() const { return MetadataPtrs.size(); }
void resize(unsigned N) { MDValuePtrs.resize(N); } void resize(unsigned N) { MetadataPtrs.resize(N); }
void push_back(Metadata *MD) { MDValuePtrs.emplace_back(MD); } void push_back(Metadata *MD) { MetadataPtrs.emplace_back(MD); }
void clear() { MDValuePtrs.clear(); } void clear() { MetadataPtrs.clear(); }
Metadata *back() const { return MDValuePtrs.back(); } Metadata *back() const { return MetadataPtrs.back(); }
void pop_back() { MDValuePtrs.pop_back(); } void pop_back() { MetadataPtrs.pop_back(); }
bool empty() const { return MDValuePtrs.empty(); } bool empty() const { return MetadataPtrs.empty(); }
Metadata *operator[](unsigned i) const { Metadata *operator[](unsigned i) const {
assert(i < MDValuePtrs.size()); assert(i < MetadataPtrs.size());
return MDValuePtrs[i]; return MetadataPtrs[i];
} }
void shrinkTo(unsigned N) { void shrinkTo(unsigned N) {
assert(N <= size() && "Invalid shrinkTo request!"); assert(N <= size() && "Invalid shrinkTo request!");
MDValuePtrs.resize(N); MetadataPtrs.resize(N);
} }
Metadata *getValueFwdRef(unsigned Idx); Metadata *getValueFwdRef(unsigned Idx);
@ -152,7 +152,7 @@ class BitcodeReader : public GVMaterializer {
std::vector<Type*> TypeList; std::vector<Type*> TypeList;
BitcodeReaderValueList ValueList; BitcodeReaderValueList ValueList;
BitcodeReaderMDValueList MDValueList; BitcodeReaderMetadataList MetadataList;
std::vector<Comdat *> ComdatList; std::vector<Comdat *> ComdatList;
SmallVector<Instruction *, 64> InstructionList; SmallVector<Instruction *, 64> InstructionList;
@ -270,12 +270,12 @@ public:
void setStripDebugInfo() override; void setStripDebugInfo() override;
/// Save the mapping between the metadata values and the corresponding /// Save the mapping between the metadata values and the corresponding
/// value id that were recorded in the MDValueList during parsing. If /// value id that were recorded in the MetadataList during parsing. If
/// OnlyTempMD is true, then only record those entries that are still /// OnlyTempMD is true, then only record those entries that are still
/// temporary metadata. This interface is used when metadata linking is /// temporary metadata. This interface is used when metadata linking is
/// performed as a postpass, such as during function importing. /// performed as a postpass, such as during function importing.
void saveMDValueList(DenseMap<const Metadata *, unsigned> &MDValueToValIDMap, void saveMetadataList(DenseMap<const Metadata *, unsigned> &MetadataToIDs,
bool OnlyTempMD) override; bool OnlyTempMD) override;
private: private:
/// Parse the "IDENTIFICATION_BLOCK_ID" block, populate the /// Parse the "IDENTIFICATION_BLOCK_ID" block, populate the
@ -294,7 +294,7 @@ private:
return ValueList.getValueFwdRef(ID, Ty); return ValueList.getValueFwdRef(ID, Ty);
} }
Metadata *getFnMetadataByID(unsigned ID) { Metadata *getFnMetadataByID(unsigned ID) {
return MDValueList.getValueFwdRef(ID); return MetadataList.getValueFwdRef(ID);
} }
BasicBlock *getBasicBlock(unsigned ID) const { BasicBlock *getBasicBlock(unsigned ID) const {
if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
@ -558,11 +558,11 @@ std::error_code BitcodeReader::error(BitcodeError E) {
BitcodeReader::BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context) BitcodeReader::BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context)
: Context(Context), Buffer(Buffer), ValueList(Context), : Context(Context), Buffer(Buffer), ValueList(Context),
MDValueList(Context) {} MetadataList(Context) {}
BitcodeReader::BitcodeReader(LLVMContext &Context) BitcodeReader::BitcodeReader(LLVMContext &Context)
: Context(Context), Buffer(nullptr), ValueList(Context), : Context(Context), Buffer(nullptr), ValueList(Context),
MDValueList(Context) {} MetadataList(Context) {}
std::error_code BitcodeReader::materializeForwardReferencedFunctions() { std::error_code BitcodeReader::materializeForwardReferencedFunctions() {
if (WillMaterializeAllForwardRefs) if (WillMaterializeAllForwardRefs)
@ -601,7 +601,7 @@ void BitcodeReader::freeState() {
Buffer = nullptr; Buffer = nullptr;
std::vector<Type*>().swap(TypeList); std::vector<Type*>().swap(TypeList);
ValueList.clear(); ValueList.clear();
MDValueList.clear(); MetadataList.clear();
std::vector<Comdat *>().swap(ComdatList); std::vector<Comdat *>().swap(ComdatList);
std::vector<AttributeSet>().swap(MAttributes); std::vector<AttributeSet>().swap(MAttributes);
@ -1035,7 +1035,7 @@ void BitcodeReaderValueList::resolveConstantForwardRefs() {
} }
} }
void BitcodeReaderMDValueList::assignValue(Metadata *MD, unsigned Idx) { void BitcodeReaderMetadataList::assignValue(Metadata *MD, unsigned Idx) {
if (Idx == size()) { if (Idx == size()) {
push_back(MD); push_back(MD);
return; return;
@ -1044,7 +1044,7 @@ void BitcodeReaderMDValueList::assignValue(Metadata *MD, unsigned Idx) {
if (Idx >= size()) if (Idx >= size())
resize(Idx+1); resize(Idx+1);
TrackingMDRef &OldMD = MDValuePtrs[Idx]; TrackingMDRef &OldMD = MetadataPtrs[Idx];
if (!OldMD) { if (!OldMD) {
OldMD.reset(MD); OldMD.reset(MD);
return; return;
@ -1056,11 +1056,11 @@ void BitcodeReaderMDValueList::assignValue(Metadata *MD, unsigned Idx) {
--NumFwdRefs; --NumFwdRefs;
} }
Metadata *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) { Metadata *BitcodeReaderMetadataList::getValueFwdRef(unsigned Idx) {
if (Idx >= size()) if (Idx >= size())
resize(Idx + 1); resize(Idx + 1);
if (Metadata *MD = MDValuePtrs[Idx]) if (Metadata *MD = MetadataPtrs[Idx])
return MD; return MD;
// Track forward refs to be resolved later. // Track forward refs to be resolved later.
@ -1075,11 +1075,11 @@ Metadata *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) {
// Create and return a placeholder, which will later be RAUW'd. // Create and return a placeholder, which will later be RAUW'd.
Metadata *MD = MDNode::getTemporary(Context, None).release(); Metadata *MD = MDNode::getTemporary(Context, None).release();
MDValuePtrs[Idx].reset(MD); MetadataPtrs[Idx].reset(MD);
return MD; return MD;
} }
void BitcodeReaderMDValueList::tryToResolveCycles() { void BitcodeReaderMetadataList::tryToResolveCycles() {
if (!AnyFwdRefs) if (!AnyFwdRefs)
// Nothing to do. // Nothing to do.
return; return;
@ -1090,7 +1090,7 @@ void BitcodeReaderMDValueList::tryToResolveCycles() {
// Resolve any cycles. // Resolve any cycles.
for (unsigned I = MinFwdRef, E = MaxFwdRef + 1; I != E; ++I) { for (unsigned I = MinFwdRef, E = MaxFwdRef + 1; I != E; ++I) {
auto &MD = MDValuePtrs[I]; auto &MD = MetadataPtrs[I];
auto *N = dyn_cast_or_null<MDNode>(MD); auto *N = dyn_cast_or_null<MDNode>(MD);
if (!N) if (!N)
continue; continue;
@ -1867,20 +1867,20 @@ static int64_t unrotateSign(uint64_t U) { return U & 1 ? ~(U >> 1) : U >> 1; }
/// module level metadata. /// module level metadata.
std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
IsMetadataMaterialized = true; IsMetadataMaterialized = true;
unsigned NextMDValueNo = MDValueList.size(); unsigned NextMetadataNo = MetadataList.size();
if (ModuleLevel && SeenModuleValuesRecord) { if (ModuleLevel && SeenModuleValuesRecord) {
// Now that we are parsing the module level metadata, we want to restart // Now that we are parsing the module level metadata, we want to restart
// the numbering of the MD values, and replace temp MD created earlier // the numbering of the MD values, and replace temp MD created earlier
// with their real values. If we saw a METADATA_VALUE record then we // with their real values. If we saw a METADATA_VALUE record then we
// would have set the MDValueList size to the number specified in that // would have set the MetadataList size to the number specified in that
// record, to support parsing function-level metadata first, and we need // record, to support parsing function-level metadata first, and we need
// to reset back to 0 to fill the MDValueList in with the parsed module // to reset back to 0 to fill the MetadataList in with the parsed module
// The function-level metadata parsing should have reset the MDValueList // The function-level metadata parsing should have reset the MetadataList
// size back to the value reported by the METADATA_VALUE record, saved in // size back to the value reported by the METADATA_VALUE record, saved in
// NumModuleMDs. // NumModuleMDs.
assert(NumModuleMDs == MDValueList.size() && assert(NumModuleMDs == MetadataList.size() &&
"Expected MDValueList to only contain module level values"); "Expected MetadataList to only contain module level values");
NextMDValueNo = 0; NextMetadataNo = 0;
} }
if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID)) if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
@ -1888,8 +1888,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
SmallVector<uint64_t, 64> Record; SmallVector<uint64_t, 64> Record;
auto getMD = auto getMD = [&](unsigned ID) -> Metadata * {
[&](unsigned ID) -> Metadata *{ return MDValueList.getValueFwdRef(ID); }; return MetadataList.getValueFwdRef(ID);
};
auto getMDOrNull = [&](unsigned ID) -> Metadata *{ auto getMDOrNull = [&](unsigned ID) -> Metadata *{
if (ID) if (ID)
return getMD(ID - 1); return getMD(ID - 1);
@ -1913,9 +1914,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
case BitstreamEntry::Error: case BitstreamEntry::Error:
return error("Malformed block"); return error("Malformed block");
case BitstreamEntry::EndBlock: case BitstreamEntry::EndBlock:
MDValueList.tryToResolveCycles(); MetadataList.tryToResolveCycles();
assert((!(ModuleLevel && SeenModuleValuesRecord) || assert((!(ModuleLevel && SeenModuleValuesRecord) ||
NumModuleMDs == MDValueList.size()) && NumModuleMDs == MetadataList.size()) &&
"Inconsistent bitcode: METADATA_VALUES mismatch"); "Inconsistent bitcode: METADATA_VALUES mismatch");
return std::error_code(); return std::error_code();
case BitstreamEntry::Record: case BitstreamEntry::Record:
@ -1944,7 +1945,8 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
unsigned Size = Record.size(); unsigned Size = Record.size();
NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name); NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name);
for (unsigned i = 0; i != Size; ++i) { for (unsigned i = 0; i != Size; ++i) {
MDNode *MD = dyn_cast_or_null<MDNode>(MDValueList.getValueFwdRef(Record[i])); MDNode *MD =
dyn_cast_or_null<MDNode>(MetadataList.getValueFwdRef(Record[i]));
if (!MD) if (!MD)
return error("Invalid record"); return error("Invalid record");
NMD->addOperand(MD); NMD->addOperand(MD);
@ -1961,7 +1963,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// If this isn't a LocalAsMetadata record, we're dropping it. This used // If this isn't a LocalAsMetadata record, we're dropping it. This used
// to be legal, but there's no upgrade path. // to be legal, but there's no upgrade path.
auto dropRecord = [&] { auto dropRecord = [&] {
MDValueList.assignValue(MDNode::get(Context, None), NextMDValueNo++); MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo++);
}; };
if (Record.size() != 2) { if (Record.size() != 2) {
dropRecord(); dropRecord();
@ -1974,9 +1976,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
break; break;
} }
MDValueList.assignValue( MetadataList.assignValue(
LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_OLD_NODE: { case bitc::METADATA_OLD_NODE: {
@ -1991,7 +1993,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (!Ty) if (!Ty)
return error("Invalid record"); return error("Invalid record");
if (Ty->isMetadataTy()) if (Ty->isMetadataTy())
Elts.push_back(MDValueList.getValueFwdRef(Record[i+1])); Elts.push_back(MetadataList.getValueFwdRef(Record[i + 1]));
else if (!Ty->isVoidTy()) { else if (!Ty->isVoidTy()) {
auto *MD = auto *MD =
ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty)); ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty));
@ -2001,7 +2003,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
} else } else
Elts.push_back(nullptr); Elts.push_back(nullptr);
} }
MDValueList.assignValue(MDNode::get(Context, Elts), NextMDValueNo++); MetadataList.assignValue(MDNode::get(Context, Elts), NextMetadataNo++);
break; break;
} }
case bitc::METADATA_VALUE: { case bitc::METADATA_VALUE: {
@ -2012,9 +2014,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Ty->isMetadataTy() || Ty->isVoidTy()) if (Ty->isMetadataTy() || Ty->isVoidTy())
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_DISTINCT_NODE: case bitc::METADATA_DISTINCT_NODE:
@ -2024,10 +2026,10 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
SmallVector<Metadata *, 8> Elts; SmallVector<Metadata *, 8> Elts;
Elts.reserve(Record.size()); Elts.reserve(Record.size());
for (unsigned ID : Record) for (unsigned ID : Record)
Elts.push_back(ID ? MDValueList.getValueFwdRef(ID - 1) : nullptr); Elts.push_back(ID ? MetadataList.getValueFwdRef(ID - 1) : nullptr);
MDValueList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts) MetadataList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts)
: MDNode::get(Context, Elts), : MDNode::get(Context, Elts),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_LOCATION: { case bitc::METADATA_LOCATION: {
@ -2036,13 +2038,13 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
unsigned Line = Record[1]; unsigned Line = Record[1];
unsigned Column = Record[2]; unsigned Column = Record[2];
MDNode *Scope = cast<MDNode>(MDValueList.getValueFwdRef(Record[3])); MDNode *Scope = cast<MDNode>(MetadataList.getValueFwdRef(Record[3]));
Metadata *InlinedAt = Metadata *InlinedAt =
Record[4] ? MDValueList.getValueFwdRef(Record[4] - 1) : nullptr; Record[4] ? MetadataList.getValueFwdRef(Record[4] - 1) : nullptr;
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DILocation, Record[0], GET_OR_DISTINCT(DILocation, Record[0],
(Context, Line, Column, Scope, InlinedAt)), (Context, Line, Column, Scope, InlinedAt)),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_GENERIC_DEBUG: { case bitc::METADATA_GENERIC_DEBUG: {
@ -2058,63 +2060,65 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
auto *Header = getMDString(Record[3]); auto *Header = getMDString(Record[3]);
SmallVector<Metadata *, 8> DwarfOps; SmallVector<Metadata *, 8> DwarfOps;
for (unsigned I = 4, E = Record.size(); I != E; ++I) for (unsigned I = 4, E = Record.size(); I != E; ++I)
DwarfOps.push_back(Record[I] ? MDValueList.getValueFwdRef(Record[I] - 1) DwarfOps.push_back(
: nullptr); Record[I] ? MetadataList.getValueFwdRef(Record[I] - 1) : nullptr);
MDValueList.assignValue(GET_OR_DISTINCT(GenericDINode, Record[0], MetadataList.assignValue(
(Context, Tag, Header, DwarfOps)), GET_OR_DISTINCT(GenericDINode, Record[0],
NextMDValueNo++); (Context, Tag, Header, DwarfOps)),
NextMetadataNo++);
break; break;
} }
case bitc::METADATA_SUBRANGE: { case bitc::METADATA_SUBRANGE: {
if (Record.size() != 3) if (Record.size() != 3)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DISubrange, Record[0], GET_OR_DISTINCT(DISubrange, Record[0],
(Context, Record[1], unrotateSign(Record[2]))), (Context, Record[1], unrotateSign(Record[2]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_ENUMERATOR: { case bitc::METADATA_ENUMERATOR: {
if (Record.size() != 3) if (Record.size() != 3)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue(GET_OR_DISTINCT(DIEnumerator, Record[0], MetadataList.assignValue(
(Context, unrotateSign(Record[1]), GET_OR_DISTINCT(
getMDString(Record[2]))), DIEnumerator, Record[0],
NextMDValueNo++); (Context, unrotateSign(Record[1]), getMDString(Record[2]))),
NextMetadataNo++);
break; break;
} }
case bitc::METADATA_BASIC_TYPE: { case bitc::METADATA_BASIC_TYPE: {
if (Record.size() != 6) if (Record.size() != 6)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIBasicType, Record[0], GET_OR_DISTINCT(DIBasicType, Record[0],
(Context, Record[1], getMDString(Record[2]), (Context, Record[1], getMDString(Record[2]),
Record[3], Record[4], Record[5])), Record[3], Record[4], Record[5])),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_DERIVED_TYPE: { case bitc::METADATA_DERIVED_TYPE: {
if (Record.size() != 12) if (Record.size() != 12)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIDerivedType, Record[0], GET_OR_DISTINCT(DIDerivedType, Record[0],
(Context, Record[1], getMDString(Record[2]), (Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4], getMDOrNull(Record[3]), Record[4],
getMDOrNull(Record[5]), getMDOrNull(Record[6]), getMDOrNull(Record[5]), getMDOrNull(Record[6]),
Record[7], Record[8], Record[9], Record[10], Record[7], Record[8], Record[9], Record[10],
getMDOrNull(Record[11]))), getMDOrNull(Record[11]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_COMPOSITE_TYPE: { case bitc::METADATA_COMPOSITE_TYPE: {
if (Record.size() != 16) if (Record.size() != 16)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DICompositeType, Record[0], GET_OR_DISTINCT(DICompositeType, Record[0],
(Context, Record[1], getMDString(Record[2]), (Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4], getMDOrNull(Record[3]), Record[4],
@ -2123,17 +2127,17 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
getMDOrNull(Record[11]), Record[12], getMDOrNull(Record[11]), Record[12],
getMDOrNull(Record[13]), getMDOrNull(Record[14]), getMDOrNull(Record[13]), getMDOrNull(Record[14]),
getMDString(Record[15]))), getMDString(Record[15]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_SUBROUTINE_TYPE: { case bitc::METADATA_SUBROUTINE_TYPE: {
if (Record.size() != 3) if (Record.size() != 3)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DISubroutineType, Record[0], GET_OR_DISTINCT(DISubroutineType, Record[0],
(Context, Record[1], getMDOrNull(Record[2]))), (Context, Record[1], getMDOrNull(Record[2]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
@ -2141,12 +2145,12 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Record.size() != 6) if (Record.size() != 6)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIModule, Record[0], GET_OR_DISTINCT(DIModule, Record[0],
(Context, getMDOrNull(Record[1]), (Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]), getMDString(Record[2]), getMDString(Record[3]),
getMDString(Record[4]), getMDString(Record[5]))), getMDString(Record[4]), getMDString(Record[5]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
@ -2154,10 +2158,10 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Record.size() != 3) if (Record.size() != 3)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIFile, Record[0], (Context, getMDString(Record[1]), GET_OR_DISTINCT(DIFile, Record[0], (Context, getMDString(Record[1]),
getMDString(Record[2]))), getMDString(Record[2]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_COMPILE_UNIT: { case bitc::METADATA_COMPILE_UNIT: {
@ -2166,7 +2170,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// Ignore Record[0], which indicates whether this compile unit is // Ignore Record[0], which indicates whether this compile unit is
// distinct. It's always distinct. // distinct. It's always distinct.
MDValueList.assignValue( MetadataList.assignValue(
DICompileUnit::getDistinct( DICompileUnit::getDistinct(
Context, Record[1], getMDOrNull(Record[2]), Context, Record[1], getMDOrNull(Record[2]),
getMDString(Record[3]), Record[4], getMDString(Record[5]), getMDString(Record[3]), Record[4], getMDString(Record[5]),
@ -2176,7 +2180,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
getMDOrNull(Record[13]), getMDOrNull(Record[13]),
Record.size() <= 15 ? 0 : getMDOrNull(Record[15]), Record.size() <= 15 ? 0 : getMDOrNull(Record[15]),
Record.size() <= 14 ? 0 : Record[14]), Record.size() <= 14 ? 0 : Record[14]),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_SUBPROGRAM: { case bitc::METADATA_SUBPROGRAM: {
@ -2193,7 +2197,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
getMDOrNull(Record[10]), Record[11], Record[12], Record[13], getMDOrNull(Record[10]), Record[11], Record[12], Record[13],
Record[14], getMDOrNull(Record[15 + HasFn]), Record[14], getMDOrNull(Record[15 + HasFn]),
getMDOrNull(Record[16 + HasFn]), getMDOrNull(Record[17 + HasFn]))); getMDOrNull(Record[16 + HasFn]), getMDOrNull(Record[17 + HasFn])));
MDValueList.assignValue(SP, NextMDValueNo++); MetadataList.assignValue(SP, NextMetadataNo++);
// Upgrade sp->function mapping to function->sp mapping. // Upgrade sp->function mapping to function->sp mapping.
if (HasFn && Record[15]) { if (HasFn && Record[15]) {
@ -2213,92 +2217,92 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Record.size() != 5) if (Record.size() != 5)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DILexicalBlock, Record[0], GET_OR_DISTINCT(DILexicalBlock, Record[0],
(Context, getMDOrNull(Record[1]), (Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), Record[3], Record[4])), getMDOrNull(Record[2]), Record[3], Record[4])),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_LEXICAL_BLOCK_FILE: { case bitc::METADATA_LEXICAL_BLOCK_FILE: {
if (Record.size() != 4) if (Record.size() != 4)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DILexicalBlockFile, Record[0], GET_OR_DISTINCT(DILexicalBlockFile, Record[0],
(Context, getMDOrNull(Record[1]), (Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), Record[3])), getMDOrNull(Record[2]), Record[3])),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_NAMESPACE: { case bitc::METADATA_NAMESPACE: {
if (Record.size() != 5) if (Record.size() != 5)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DINamespace, Record[0], GET_OR_DISTINCT(DINamespace, Record[0],
(Context, getMDOrNull(Record[1]), (Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), getMDString(Record[3]), getMDOrNull(Record[2]), getMDString(Record[3]),
Record[4])), Record[4])),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_MACRO: { case bitc::METADATA_MACRO: {
if (Record.size() != 5) if (Record.size() != 5)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIMacro, Record[0], GET_OR_DISTINCT(DIMacro, Record[0],
(Context, Record[1], Record[2], (Context, Record[1], Record[2],
getMDString(Record[3]), getMDString(Record[4]))), getMDString(Record[3]), getMDString(Record[4]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_MACRO_FILE: { case bitc::METADATA_MACRO_FILE: {
if (Record.size() != 5) if (Record.size() != 5)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIMacroFile, Record[0], GET_OR_DISTINCT(DIMacroFile, Record[0],
(Context, Record[1], Record[2], (Context, Record[1], Record[2],
getMDOrNull(Record[3]), getMDOrNull(Record[4]))), getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_TEMPLATE_TYPE: { case bitc::METADATA_TEMPLATE_TYPE: {
if (Record.size() != 3) if (Record.size() != 3)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter, MetadataList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter,
Record[0], Record[0],
(Context, getMDString(Record[1]), (Context, getMDString(Record[1]),
getMDOrNull(Record[2]))), getMDOrNull(Record[2]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_TEMPLATE_VALUE: { case bitc::METADATA_TEMPLATE_VALUE: {
if (Record.size() != 5) if (Record.size() != 5)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DITemplateValueParameter, Record[0], GET_OR_DISTINCT(DITemplateValueParameter, Record[0],
(Context, Record[1], getMDString(Record[2]), (Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), getMDOrNull(Record[4]))), getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_GLOBAL_VAR: { case bitc::METADATA_GLOBAL_VAR: {
if (Record.size() != 11) if (Record.size() != 11)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIGlobalVariable, Record[0], GET_OR_DISTINCT(DIGlobalVariable, Record[0],
(Context, getMDOrNull(Record[1]), (Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]), getMDString(Record[2]), getMDString(Record[3]),
getMDOrNull(Record[4]), Record[5], getMDOrNull(Record[4]), Record[5],
getMDOrNull(Record[6]), Record[7], Record[8], getMDOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[9]), getMDOrNull(Record[10]))), getMDOrNull(Record[9]), getMDOrNull(Record[10]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_LOCAL_VAR: { case bitc::METADATA_LOCAL_VAR: {
@ -2309,56 +2313,56 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// 2nd field used to be an artificial tag, either DW_TAG_auto_variable or // 2nd field used to be an artificial tag, either DW_TAG_auto_variable or
// DW_TAG_arg_variable. // DW_TAG_arg_variable.
bool HasTag = Record.size() > 8; bool HasTag = Record.size() > 8;
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DILocalVariable, Record[0], GET_OR_DISTINCT(DILocalVariable, Record[0],
(Context, getMDOrNull(Record[1 + HasTag]), (Context, getMDOrNull(Record[1 + HasTag]),
getMDString(Record[2 + HasTag]), getMDString(Record[2 + HasTag]),
getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag], getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
getMDOrNull(Record[5 + HasTag]), Record[6 + HasTag], getMDOrNull(Record[5 + HasTag]), Record[6 + HasTag],
Record[7 + HasTag])), Record[7 + HasTag])),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_EXPRESSION: { case bitc::METADATA_EXPRESSION: {
if (Record.size() < 1) if (Record.size() < 1)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIExpression, Record[0], GET_OR_DISTINCT(DIExpression, Record[0],
(Context, makeArrayRef(Record).slice(1))), (Context, makeArrayRef(Record).slice(1))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_OBJC_PROPERTY: { case bitc::METADATA_OBJC_PROPERTY: {
if (Record.size() != 8) if (Record.size() != 8)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIObjCProperty, Record[0], GET_OR_DISTINCT(DIObjCProperty, Record[0],
(Context, getMDString(Record[1]), (Context, getMDString(Record[1]),
getMDOrNull(Record[2]), Record[3], getMDOrNull(Record[2]), Record[3],
getMDString(Record[4]), getMDString(Record[5]), getMDString(Record[4]), getMDString(Record[5]),
Record[6], getMDOrNull(Record[7]))), Record[6], getMDOrNull(Record[7]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_IMPORTED_ENTITY: { case bitc::METADATA_IMPORTED_ENTITY: {
if (Record.size() != 6) if (Record.size() != 6)
return error("Invalid record"); return error("Invalid record");
MDValueList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DIImportedEntity, Record[0], GET_OR_DISTINCT(DIImportedEntity, Record[0],
(Context, Record[1], getMDOrNull(Record[2]), (Context, Record[1], getMDOrNull(Record[2]),
getMDOrNull(Record[3]), Record[4], getMDOrNull(Record[3]), Record[4],
getMDString(Record[5]))), getMDString(Record[5]))),
NextMDValueNo++); NextMetadataNo++);
break; break;
} }
case bitc::METADATA_STRING: { case bitc::METADATA_STRING: {
std::string String(Record.begin(), Record.end()); std::string String(Record.begin(), Record.end());
llvm::UpgradeMDStringConstant(String); llvm::UpgradeMDStringConstant(String);
Metadata *MD = MDString::get(Context, String); Metadata *MD = MDString::get(Context, String);
MDValueList.assignValue(MD, NextMDValueNo++); MetadataList.assignValue(MD, NextMetadataNo++);
break; break;
} }
case bitc::METADATA_KIND: { case bitc::METADATA_KIND: {
@ -3062,22 +3066,21 @@ std::error_code BitcodeReader::materializeMetadata() {
void BitcodeReader::setStripDebugInfo() { StripDebugInfo = true; } void BitcodeReader::setStripDebugInfo() { StripDebugInfo = true; }
void BitcodeReader::saveMDValueList( void BitcodeReader::saveMetadataList(
DenseMap<const Metadata *, unsigned> &MDValueToValIDMap, bool OnlyTempMD) { DenseMap<const Metadata *, unsigned> &MetadataToIDs, bool OnlyTempMD) {
for (unsigned ValID = 0; ValID < MDValueList.size(); ++ValID) { for (unsigned ID = 0; ID < MetadataList.size(); ++ID) {
Metadata *MD = MDValueList[ValID]; Metadata *MD = MetadataList[ID];
auto *N = dyn_cast_or_null<MDNode>(MD); auto *N = dyn_cast_or_null<MDNode>(MD);
// Save all values if !OnlyTempMD, otherwise just the temporary metadata. // Save all values if !OnlyTempMD, otherwise just the temporary metadata.
if (!OnlyTempMD || (N && N->isTemporary())) { if (!OnlyTempMD || (N && N->isTemporary())) {
// Will call this after materializing each function, in order to // Will call this after materializing each function, in order to
// handle remapping of the function's instructions/metadata. // handle remapping of the function's instructions/metadata.
// See if we already have an entry in that case. // See if we already have an entry in that case.
if (OnlyTempMD && MDValueToValIDMap.count(MD)) { if (OnlyTempMD && MetadataToIDs.count(MD)) {
assert(MDValueToValIDMap[MD] == ValID && assert(MetadataToIDs[MD] == ID && "Inconsistent metadata value id");
"Inconsistent metadata value id");
continue; continue;
} }
MDValueToValIDMap[MD] = ValID; MetadataToIDs[MD] = ID;
} }
} }
} }
@ -3677,15 +3680,15 @@ std::error_code BitcodeReader::parseModule(uint64_t ResumeBit,
// based on their ordering in the bitcode, with the function-level // based on their ordering in the bitcode, with the function-level
// metadata ids starting after the module-level metadata ids. Otherwise, // metadata ids starting after the module-level metadata ids. Otherwise,
// we would have to parse the module-level metadata block to prime the // we would have to parse the module-level metadata block to prime the
// MDValueList when we are lazy loading metadata during function // MetadataList when we are lazy loading metadata during function
// importing. Initialize the MDValueList size here based on the // importing. Initialize the MetadataList size here based on the
// record value, regardless of whether we are doing lazy metadata // record value, regardless of whether we are doing lazy metadata
// loading, so that we have consistent handling and assertion // loading, so that we have consistent handling and assertion
// checking in parseMetadata for module-level metadata. // checking in parseMetadata for module-level metadata.
NumModuleMDs = Record[0]; NumModuleMDs = Record[0];
SeenModuleValuesRecord = true; SeenModuleValuesRecord = true;
assert(MDValueList.size() == 0); assert(MetadataList.size() == 0);
MDValueList.resize(NumModuleMDs); MetadataList.resize(NumModuleMDs);
break; break;
} }
Record.clear(); Record.clear();
@ -3887,7 +3890,7 @@ std::error_code BitcodeReader::parseMetadataAttachment(Function &F) {
auto K = MDKindMap.find(Record[I]); auto K = MDKindMap.find(Record[I]);
if (K == MDKindMap.end()) if (K == MDKindMap.end())
return error("Invalid ID"); return error("Invalid ID");
Metadata *MD = MDValueList.getValueFwdRef(Record[I + 1]); Metadata *MD = MetadataList.getValueFwdRef(Record[I + 1]);
F.setMetadata(K->second, cast<MDNode>(MD)); F.setMetadata(K->second, cast<MDNode>(MD));
} }
continue; continue;
@ -3901,7 +3904,7 @@ std::error_code BitcodeReader::parseMetadataAttachment(Function &F) {
MDKindMap.find(Kind); MDKindMap.find(Kind);
if (I == MDKindMap.end()) if (I == MDKindMap.end())
return error("Invalid ID"); return error("Invalid ID");
Metadata *Node = MDValueList.getValueFwdRef(Record[i + 1]); Metadata *Node = MetadataList.getValueFwdRef(Record[i + 1]);
if (isa<LocalAsMetadata>(Node)) if (isa<LocalAsMetadata>(Node))
// Drop the attachment. This used to be legal, but there's no // Drop the attachment. This used to be legal, but there's no
// upgrade path. // upgrade path.
@ -3937,7 +3940,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
InstructionList.clear(); InstructionList.clear();
unsigned ModuleValueListSize = ValueList.size(); unsigned ModuleValueListSize = ValueList.size();
unsigned ModuleMDValueListSize = MDValueList.size(); unsigned ModuleMetadataListSize = MetadataList.size();
// Add all the function arguments to the value table. // Add all the function arguments to the value table.
for (Argument &I : F->args()) for (Argument &I : F->args())
@ -4067,8 +4070,10 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
unsigned ScopeID = Record[2], IAID = Record[3]; unsigned ScopeID = Record[2], IAID = Record[3];
MDNode *Scope = nullptr, *IA = nullptr; MDNode *Scope = nullptr, *IA = nullptr;
if (ScopeID) Scope = cast<MDNode>(MDValueList.getValueFwdRef(ScopeID-1)); if (ScopeID)
if (IAID) IA = cast<MDNode>(MDValueList.getValueFwdRef(IAID-1)); Scope = cast<MDNode>(MetadataList.getValueFwdRef(ScopeID - 1));
if (IAID)
IA = cast<MDNode>(MetadataList.getValueFwdRef(IAID - 1));
LastLoc = DebugLoc::get(Line, Col, Scope, IA); LastLoc = DebugLoc::get(Line, Col, Scope, IA);
I->setDebugLoc(LastLoc); I->setDebugLoc(LastLoc);
I = nullptr; I = nullptr;
@ -5189,7 +5194,7 @@ OutOfRecordLoop:
// Trim the value list down to the size it was before we parsed this function. // Trim the value list down to the size it was before we parsed this function.
ValueList.shrinkTo(ModuleValueListSize); ValueList.shrinkTo(ModuleValueListSize);
MDValueList.shrinkTo(ModuleMDValueListSize); MetadataList.shrinkTo(ModuleMetadataListSize);
std::vector<BasicBlock*>().swap(FunctionBBs); std::vector<BasicBlock*>().swap(FunctionBBs);
return std::error_code(); return std::error_code();
} }
@ -5220,7 +5225,7 @@ void BitcodeReader::releaseBuffer() { Buffer.release(); }
std::error_code BitcodeReader::materialize(GlobalValue *GV) { std::error_code BitcodeReader::materialize(GlobalValue *GV) {
// In older bitcode we must materialize the metadata before parsing // In older bitcode we must materialize the metadata before parsing
// any functions, in order to set up the MDValueList properly. // any functions, in order to set up the MetadataList properly.
if (!SeenModuleValuesRecord) { if (!SeenModuleValuesRecord) {
if (std::error_code EC = materializeMetadata()) if (std::error_code EC = materializeMetadata())
return EC; return EC;

View File

@ -405,7 +405,7 @@ unsigned ValueEnumerator::getValueID(const Value *V) const {
void ValueEnumerator::dump() const { void ValueEnumerator::dump() const {
print(dbgs(), ValueMap, "Default"); print(dbgs(), ValueMap, "Default");
dbgs() << '\n'; dbgs() << '\n';
print(dbgs(), MDValueMap, "MetaData"); print(dbgs(), MetadataMap, "MetaData");
dbgs() << '\n'; dbgs() << '\n';
} }
@ -522,7 +522,7 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
// EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph. // EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph.
// //
// Return early if there's already an ID. // Return early if there's already an ID.
if (!MDValueMap.insert(std::make_pair(MD, 0)).second) if (!MetadataMap.insert(std::make_pair(MD, 0)).second)
return; return;
// Visit operands first to minimize RAUW. // Visit operands first to minimize RAUW.
@ -535,10 +535,10 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
HasDILocation |= isa<DILocation>(MD); HasDILocation |= isa<DILocation>(MD);
HasGenericDINode |= isa<GenericDINode>(MD); HasGenericDINode |= isa<GenericDINode>(MD);
// Replace the dummy ID inserted above with the correct one. MDValueMap may // Replace the dummy ID inserted above with the correct one. MetadataMap may
// have changed by inserting operands, so we need a fresh lookup here. // have changed by inserting operands, so we need a fresh lookup here.
MDs.push_back(MD); MDs.push_back(MD);
MDValueMap[MD] = MDs.size(); MetadataMap[MD] = MDs.size();
} }
/// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata /// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata
@ -546,12 +546,12 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
void ValueEnumerator::EnumerateFunctionLocalMetadata( void ValueEnumerator::EnumerateFunctionLocalMetadata(
const LocalAsMetadata *Local) { const LocalAsMetadata *Local) {
// Check to see if it's already in! // Check to see if it's already in!
unsigned &MDValueID = MDValueMap[Local]; unsigned &MetadataID = MetadataMap[Local];
if (MDValueID) if (MetadataID)
return; return;
MDs.push_back(Local); MDs.push_back(Local);
MDValueID = MDs.size(); MetadataID = MDs.size();
EnumerateValue(Local->getValue()); EnumerateValue(Local->getValue());
@ -758,7 +758,7 @@ void ValueEnumerator::purgeFunction() {
for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i) for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
ValueMap.erase(Values[i].first); ValueMap.erase(Values[i].first);
for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i) for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i)
MDValueMap.erase(MDs[i]); MetadataMap.erase(MDs[i]);
for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i) for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
ValueMap.erase(BasicBlocks[i]); ValueMap.erase(BasicBlocks[i]);

View File

@ -63,7 +63,7 @@ private:
std::vector<const Metadata *> MDs; std::vector<const Metadata *> MDs;
SmallVector<const LocalAsMetadata *, 8> FunctionLocalMDs; SmallVector<const LocalAsMetadata *, 8> FunctionLocalMDs;
typedef DenseMap<const Metadata *, unsigned> MetadataMapType; typedef DenseMap<const Metadata *, unsigned> MetadataMapType;
MetadataMapType MDValueMap; MetadataMapType MetadataMap;
bool HasMDString; bool HasMDString;
bool HasDILocation; bool HasDILocation;
bool HasGenericDINode; bool HasGenericDINode;
@ -93,7 +93,7 @@ private:
/// before incorporation. /// before incorporation.
unsigned NumModuleValues; unsigned NumModuleValues;
/// When a function is incorporated, this is the size of the MDValues list /// When a function is incorporated, this is the size of the Metadatas list
/// before incorporation. /// before incorporation.
unsigned NumModuleMDs; unsigned NumModuleMDs;
@ -117,7 +117,7 @@ public:
return ID - 1; return ID - 1;
} }
unsigned getMetadataOrNullID(const Metadata *MD) const { unsigned getMetadataOrNullID(const Metadata *MD) const {
return MDValueMap.lookup(MD); return MetadataMap.lookup(MD);
} }
unsigned numMDs() const { return MDs.size(); } unsigned numMDs() const { return MDs.size(); }

View File

@ -415,7 +415,7 @@ class IRLinker {
/// the value id. Used to correlate temporary metadata created during /// the value id. Used to correlate temporary metadata created during
/// function importing with the final metadata parsed during the subsequent /// function importing with the final metadata parsed during the subsequent
/// metadata linking postpass. /// metadata linking postpass.
DenseMap<const Metadata *, unsigned> MDValueToValIDMap; DenseMap<const Metadata *, unsigned> MetadataToIDs;
/// Association between metadata value id and temporary metadata that /// Association between metadata value id and temporary metadata that
/// remains unmapped after function importing. Saved during function /// remains unmapped after function importing. Saved during function
@ -642,8 +642,8 @@ Metadata *IRLinker::mapTemporaryMetadata(Metadata *MD) {
return nullptr; return nullptr;
// If this temporary metadata has a value id recorded during function // If this temporary metadata has a value id recorded during function
// parsing, record that in the ValIDToTempMDMap if one was provided. // parsing, record that in the ValIDToTempMDMap if one was provided.
if (MDValueToValIDMap.count(MD)) { if (MetadataToIDs.count(MD)) {
unsigned Idx = MDValueToValIDMap[MD]; unsigned Idx = MetadataToIDs[MD];
// Check if we created a temp MD when importing a different function from // Check if we created a temp MD when importing a different function from
// this module. If so, reuse it the same temporary metadata, otherwise // this module. If so, reuse it the same temporary metadata, otherwise
// add this temporary metadata to the map. // add this temporary metadata to the map.
@ -669,8 +669,8 @@ void IRLinker::replaceTemporaryMetadata(const Metadata *OrigMD,
// created during function importing was provided, and the source // created during function importing was provided, and the source
// metadata has a value id recorded during metadata parsing, replace // metadata has a value id recorded during metadata parsing, replace
// the temporary metadata with the final mapped metadata now. // the temporary metadata with the final mapped metadata now.
if (MDValueToValIDMap.count(OrigMD)) { if (MetadataToIDs.count(OrigMD)) {
unsigned Idx = MDValueToValIDMap[OrigMD]; unsigned Idx = MetadataToIDs[OrigMD];
// Nothing to do if we didn't need to create a temporary metadata during // Nothing to do if we didn't need to create a temporary metadata during
// function importing. // function importing.
if (!ValIDToTempMDMap->count(Idx)) if (!ValIDToTempMDMap->count(Idx))
@ -1111,7 +1111,7 @@ bool IRLinker::linkFunctionBody(Function &Dst, Function &Src) {
// a function and before remapping metadata on instructions below // a function and before remapping metadata on instructions below
// in RemapInstruction, as the saved mapping is used to handle // in RemapInstruction, as the saved mapping is used to handle
// the temporary metadata hanging off instructions. // the temporary metadata hanging off instructions.
SrcM.getMaterializer()->saveMDValueList(MDValueToValIDMap, true); SrcM.getMaterializer()->saveMetadataList(MetadataToIDs, true);
// Link in the prefix data. // Link in the prefix data.
if (Src.hasPrefixData()) if (Src.hasPrefixData())
@ -1210,7 +1210,7 @@ void IRLinker::findNeededSubprograms(ValueToValueMapTy &ValueMap) {
// importing), see which DISubprogram MD from the source has an associated // importing), see which DISubprogram MD from the source has an associated
// temporary metadata node, which means the SP was needed by an imported // temporary metadata node, which means the SP was needed by an imported
// function. // function.
for (auto MDI : MDValueToValIDMap) { for (auto MDI : MetadataToIDs) {
const MDNode *Node = dyn_cast<MDNode>(MDI.first); const MDNode *Node = dyn_cast<MDNode>(MDI.first);
if (!Node) if (!Node)
continue; continue;
@ -1514,7 +1514,7 @@ bool IRLinker::run() {
// Ensure metadata materialized // Ensure metadata materialized
if (SrcM.getMaterializer()->materializeMetadata()) if (SrcM.getMaterializer()->materializeMetadata())
return true; return true;
SrcM.getMaterializer()->saveMDValueList(MDValueToValIDMap, false); SrcM.getMaterializer()->saveMetadataList(MetadataToIDs, false);
} }
linkNamedMDNodes(); linkNamedMDNodes();
@ -1523,10 +1523,10 @@ bool IRLinker::run() {
// Handle anything left in the ValIDToTempMDMap, such as metadata nodes // Handle anything left in the ValIDToTempMDMap, such as metadata nodes
// not reached by the dbg.cu NamedMD (i.e. only reached from // not reached by the dbg.cu NamedMD (i.e. only reached from
// instructions). // instructions).
// Walk the MDValueToValIDMap once to find the set of new (imported) MD // Walk the MetadataToIDs once to find the set of new (imported) MD
// that still has corresponding temporary metadata, and invoke metadata // that still has corresponding temporary metadata, and invoke metadata
// mapping on each one. // mapping on each one.
for (auto MDI : MDValueToValIDMap) { for (auto MDI : MetadataToIDs) {
if (!ValIDToTempMDMap->count(MDI.second)) if (!ValIDToTempMDMap->count(MDI.second))
continue; continue;
MapMetadata(MDI.first, ValueMap, ValueMapperFlags, &TypeMap, MapMetadata(MDI.first, ValueMap, ValueMapperFlags, &TypeMap,