From b23b3067db7079b2e01735c42512269c7ec8605b Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 29 Dec 2015 23:00:22 +0000 Subject: [PATCH] Rename MDValue* to Metadata* (NFC) Renamed MDValue* to Metadata*, and MDValueToValIDMap to MetadataToIDs, as per review for r255909. llvm-svn: 256593 --- include/llvm/IR/GVMaterializer.h | 4 +- lib/Bitcode/Reader/BitcodeReader.cpp | 265 +++++++++++++------------ lib/Bitcode/Writer/ValueEnumerator.cpp | 16 +- lib/Bitcode/Writer/ValueEnumerator.h | 6 +- lib/Linker/IRMover.cpp | 20 +- 5 files changed, 158 insertions(+), 153 deletions(-) diff --git a/include/llvm/IR/GVMaterializer.h b/include/llvm/IR/GVMaterializer.h index 489cbf58dfa..6cb593c7a3d 100644 --- a/include/llvm/IR/GVMaterializer.h +++ b/include/llvm/IR/GVMaterializer.h @@ -52,8 +52,8 @@ public: /// instantiations. If OnlyTempMD is true, only those that have remained /// temporary metadata are recorded in the map. virtual void - saveMDValueList(DenseMap &MDValueToValIDMap, - bool OnlyTempMD) {} + saveMetadataList(DenseMap &MetadataToIDs, + bool OnlyTempMD) {} virtual std::vector getIdentifiedStructTypes() const = 0; }; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index dd898a7f322..2e670d584ec 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -94,35 +94,35 @@ public: void resolveConstantForwardRefs(); }; -class BitcodeReaderMDValueList { +class BitcodeReaderMetadataList { unsigned NumFwdRefs; bool AnyFwdRefs; unsigned MinFwdRef; unsigned MaxFwdRef; - std::vector MDValuePtrs; + std::vector MetadataPtrs; LLVMContext &Context; public: - BitcodeReaderMDValueList(LLVMContext &C) + BitcodeReaderMetadataList(LLVMContext &C) : NumFwdRefs(0), AnyFwdRefs(false), Context(C) {} // vector compatibility methods - unsigned size() const { return MDValuePtrs.size(); } - void resize(unsigned N) { MDValuePtrs.resize(N); } - void push_back(Metadata *MD) { MDValuePtrs.emplace_back(MD); } - void clear() { MDValuePtrs.clear(); } - Metadata *back() const { return MDValuePtrs.back(); } - void pop_back() { MDValuePtrs.pop_back(); } - bool empty() const { return MDValuePtrs.empty(); } + unsigned size() const { return MetadataPtrs.size(); } + void resize(unsigned N) { MetadataPtrs.resize(N); } + void push_back(Metadata *MD) { MetadataPtrs.emplace_back(MD); } + void clear() { MetadataPtrs.clear(); } + Metadata *back() const { return MetadataPtrs.back(); } + void pop_back() { MetadataPtrs.pop_back(); } + bool empty() const { return MetadataPtrs.empty(); } Metadata *operator[](unsigned i) const { - assert(i < MDValuePtrs.size()); - return MDValuePtrs[i]; + assert(i < MetadataPtrs.size()); + return MetadataPtrs[i]; } void shrinkTo(unsigned N) { assert(N <= size() && "Invalid shrinkTo request!"); - MDValuePtrs.resize(N); + MetadataPtrs.resize(N); } Metadata *getValueFwdRef(unsigned Idx); @@ -152,7 +152,7 @@ class BitcodeReader : public GVMaterializer { std::vector TypeList; BitcodeReaderValueList ValueList; - BitcodeReaderMDValueList MDValueList; + BitcodeReaderMetadataList MetadataList; std::vector ComdatList; SmallVector InstructionList; @@ -270,12 +270,12 @@ public: void setStripDebugInfo() override; /// 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 /// temporary metadata. This interface is used when metadata linking is /// performed as a postpass, such as during function importing. - void saveMDValueList(DenseMap &MDValueToValIDMap, - bool OnlyTempMD) override; + void saveMetadataList(DenseMap &MetadataToIDs, + bool OnlyTempMD) override; private: /// Parse the "IDENTIFICATION_BLOCK_ID" block, populate the @@ -294,7 +294,7 @@ private: return ValueList.getValueFwdRef(ID, Ty); } Metadata *getFnMetadataByID(unsigned ID) { - return MDValueList.getValueFwdRef(ID); + return MetadataList.getValueFwdRef(ID); } BasicBlock *getBasicBlock(unsigned ID) const { 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) : Context(Context), Buffer(Buffer), ValueList(Context), - MDValueList(Context) {} + MetadataList(Context) {} BitcodeReader::BitcodeReader(LLVMContext &Context) : Context(Context), Buffer(nullptr), ValueList(Context), - MDValueList(Context) {} + MetadataList(Context) {} std::error_code BitcodeReader::materializeForwardReferencedFunctions() { if (WillMaterializeAllForwardRefs) @@ -601,7 +601,7 @@ void BitcodeReader::freeState() { Buffer = nullptr; std::vector().swap(TypeList); ValueList.clear(); - MDValueList.clear(); + MetadataList.clear(); std::vector().swap(ComdatList); std::vector().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()) { push_back(MD); return; @@ -1044,7 +1044,7 @@ void BitcodeReaderMDValueList::assignValue(Metadata *MD, unsigned Idx) { if (Idx >= size()) resize(Idx+1); - TrackingMDRef &OldMD = MDValuePtrs[Idx]; + TrackingMDRef &OldMD = MetadataPtrs[Idx]; if (!OldMD) { OldMD.reset(MD); return; @@ -1056,11 +1056,11 @@ void BitcodeReaderMDValueList::assignValue(Metadata *MD, unsigned Idx) { --NumFwdRefs; } -Metadata *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) { +Metadata *BitcodeReaderMetadataList::getValueFwdRef(unsigned Idx) { if (Idx >= size()) resize(Idx + 1); - if (Metadata *MD = MDValuePtrs[Idx]) + if (Metadata *MD = MetadataPtrs[Idx]) return MD; // 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. Metadata *MD = MDNode::getTemporary(Context, None).release(); - MDValuePtrs[Idx].reset(MD); + MetadataPtrs[Idx].reset(MD); return MD; } -void BitcodeReaderMDValueList::tryToResolveCycles() { +void BitcodeReaderMetadataList::tryToResolveCycles() { if (!AnyFwdRefs) // Nothing to do. return; @@ -1090,7 +1090,7 @@ void BitcodeReaderMDValueList::tryToResolveCycles() { // Resolve any cycles. for (unsigned I = MinFwdRef, E = MaxFwdRef + 1; I != E; ++I) { - auto &MD = MDValuePtrs[I]; + auto &MD = MetadataPtrs[I]; auto *N = dyn_cast_or_null(MD); if (!N) continue; @@ -1867,20 +1867,20 @@ static int64_t unrotateSign(uint64_t U) { return U & 1 ? ~(U >> 1) : U >> 1; } /// module level metadata. std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { IsMetadataMaterialized = true; - unsigned NextMDValueNo = MDValueList.size(); + unsigned NextMetadataNo = MetadataList.size(); if (ModuleLevel && SeenModuleValuesRecord) { // 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 // 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 - // to reset back to 0 to fill the MDValueList in with the parsed module - // The function-level metadata parsing should have reset the MDValueList + // to reset back to 0 to fill the MetadataList in with the parsed module + // The function-level metadata parsing should have reset the MetadataList // size back to the value reported by the METADATA_VALUE record, saved in // NumModuleMDs. - assert(NumModuleMDs == MDValueList.size() && - "Expected MDValueList to only contain module level values"); - NextMDValueNo = 0; + assert(NumModuleMDs == MetadataList.size() && + "Expected MetadataList to only contain module level values"); + NextMetadataNo = 0; } if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID)) @@ -1888,8 +1888,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { SmallVector Record; - auto getMD = - [&](unsigned ID) -> Metadata *{ return MDValueList.getValueFwdRef(ID); }; + auto getMD = [&](unsigned ID) -> Metadata * { + return MetadataList.getValueFwdRef(ID); + }; auto getMDOrNull = [&](unsigned ID) -> Metadata *{ if (ID) return getMD(ID - 1); @@ -1913,9 +1914,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { case BitstreamEntry::Error: return error("Malformed block"); case BitstreamEntry::EndBlock: - MDValueList.tryToResolveCycles(); + MetadataList.tryToResolveCycles(); assert((!(ModuleLevel && SeenModuleValuesRecord) || - NumModuleMDs == MDValueList.size()) && + NumModuleMDs == MetadataList.size()) && "Inconsistent bitcode: METADATA_VALUES mismatch"); return std::error_code(); case BitstreamEntry::Record: @@ -1944,7 +1945,8 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { unsigned Size = Record.size(); NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name); for (unsigned i = 0; i != Size; ++i) { - MDNode *MD = dyn_cast_or_null(MDValueList.getValueFwdRef(Record[i])); + MDNode *MD = + dyn_cast_or_null(MetadataList.getValueFwdRef(Record[i])); if (!MD) return error("Invalid record"); 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 // to be legal, but there's no upgrade path. auto dropRecord = [&] { - MDValueList.assignValue(MDNode::get(Context, None), NextMDValueNo++); + MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo++); }; if (Record.size() != 2) { dropRecord(); @@ -1974,9 +1976,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { break; } - MDValueList.assignValue( + MetadataList.assignValue( LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_OLD_NODE: { @@ -1991,7 +1993,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { if (!Ty) return error("Invalid record"); if (Ty->isMetadataTy()) - Elts.push_back(MDValueList.getValueFwdRef(Record[i+1])); + Elts.push_back(MetadataList.getValueFwdRef(Record[i + 1])); else if (!Ty->isVoidTy()) { auto *MD = ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty)); @@ -2001,7 +2003,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { } else Elts.push_back(nullptr); } - MDValueList.assignValue(MDNode::get(Context, Elts), NextMDValueNo++); + MetadataList.assignValue(MDNode::get(Context, Elts), NextMetadataNo++); break; } case bitc::METADATA_VALUE: { @@ -2012,9 +2014,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { if (Ty->isMetadataTy() || Ty->isVoidTy()) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_DISTINCT_NODE: @@ -2024,10 +2026,10 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { SmallVector Elts; Elts.reserve(Record.size()); for (unsigned ID : Record) - Elts.push_back(ID ? MDValueList.getValueFwdRef(ID - 1) : nullptr); - MDValueList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts) - : MDNode::get(Context, Elts), - NextMDValueNo++); + Elts.push_back(ID ? MetadataList.getValueFwdRef(ID - 1) : nullptr); + MetadataList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts) + : MDNode::get(Context, Elts), + NextMetadataNo++); break; } case bitc::METADATA_LOCATION: { @@ -2036,13 +2038,13 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { unsigned Line = Record[1]; unsigned Column = Record[2]; - MDNode *Scope = cast(MDValueList.getValueFwdRef(Record[3])); + MDNode *Scope = cast(MetadataList.getValueFwdRef(Record[3])); Metadata *InlinedAt = - Record[4] ? MDValueList.getValueFwdRef(Record[4] - 1) : nullptr; - MDValueList.assignValue( + Record[4] ? MetadataList.getValueFwdRef(Record[4] - 1) : nullptr; + MetadataList.assignValue( GET_OR_DISTINCT(DILocation, Record[0], (Context, Line, Column, Scope, InlinedAt)), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_GENERIC_DEBUG: { @@ -2058,63 +2060,65 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { auto *Header = getMDString(Record[3]); SmallVector DwarfOps; for (unsigned I = 4, E = Record.size(); I != E; ++I) - DwarfOps.push_back(Record[I] ? MDValueList.getValueFwdRef(Record[I] - 1) - : nullptr); - MDValueList.assignValue(GET_OR_DISTINCT(GenericDINode, Record[0], - (Context, Tag, Header, DwarfOps)), - NextMDValueNo++); + DwarfOps.push_back( + Record[I] ? MetadataList.getValueFwdRef(Record[I] - 1) : nullptr); + MetadataList.assignValue( + GET_OR_DISTINCT(GenericDINode, Record[0], + (Context, Tag, Header, DwarfOps)), + NextMetadataNo++); break; } case bitc::METADATA_SUBRANGE: { if (Record.size() != 3) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DISubrange, Record[0], (Context, Record[1], unrotateSign(Record[2]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_ENUMERATOR: { if (Record.size() != 3) return error("Invalid record"); - MDValueList.assignValue(GET_OR_DISTINCT(DIEnumerator, Record[0], - (Context, unrotateSign(Record[1]), - getMDString(Record[2]))), - NextMDValueNo++); + MetadataList.assignValue( + GET_OR_DISTINCT( + DIEnumerator, Record[0], + (Context, unrotateSign(Record[1]), getMDString(Record[2]))), + NextMetadataNo++); break; } case bitc::METADATA_BASIC_TYPE: { if (Record.size() != 6) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIBasicType, Record[0], (Context, Record[1], getMDString(Record[2]), Record[3], Record[4], Record[5])), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_DERIVED_TYPE: { if (Record.size() != 12) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIDerivedType, Record[0], (Context, Record[1], getMDString(Record[2]), getMDOrNull(Record[3]), Record[4], getMDOrNull(Record[5]), getMDOrNull(Record[6]), Record[7], Record[8], Record[9], Record[10], getMDOrNull(Record[11]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_COMPOSITE_TYPE: { if (Record.size() != 16) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DICompositeType, Record[0], (Context, Record[1], getMDString(Record[2]), getMDOrNull(Record[3]), Record[4], @@ -2123,17 +2127,17 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { getMDOrNull(Record[11]), Record[12], getMDOrNull(Record[13]), getMDOrNull(Record[14]), getMDString(Record[15]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_SUBROUTINE_TYPE: { if (Record.size() != 3) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DISubroutineType, Record[0], (Context, Record[1], getMDOrNull(Record[2]))), - NextMDValueNo++); + NextMetadataNo++); break; } @@ -2141,12 +2145,12 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { if (Record.size() != 6) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIModule, Record[0], (Context, getMDOrNull(Record[1]), - getMDString(Record[2]), getMDString(Record[3]), - getMDString(Record[4]), getMDString(Record[5]))), - NextMDValueNo++); + getMDString(Record[2]), getMDString(Record[3]), + getMDString(Record[4]), getMDString(Record[5]))), + NextMetadataNo++); break; } @@ -2154,10 +2158,10 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { if (Record.size() != 3) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIFile, Record[0], (Context, getMDString(Record[1]), getMDString(Record[2]))), - NextMDValueNo++); + NextMetadataNo++); break; } 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 // distinct. It's always distinct. - MDValueList.assignValue( + MetadataList.assignValue( DICompileUnit::getDistinct( Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]), Record[4], getMDString(Record[5]), @@ -2176,7 +2180,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { getMDOrNull(Record[13]), Record.size() <= 15 ? 0 : getMDOrNull(Record[15]), Record.size() <= 14 ? 0 : Record[14]), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_SUBPROGRAM: { @@ -2193,7 +2197,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { getMDOrNull(Record[10]), Record[11], Record[12], Record[13], Record[14], getMDOrNull(Record[15 + 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. if (HasFn && Record[15]) { @@ -2213,92 +2217,92 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { if (Record.size() != 5) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DILexicalBlock, Record[0], (Context, getMDOrNull(Record[1]), getMDOrNull(Record[2]), Record[3], Record[4])), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_LEXICAL_BLOCK_FILE: { if (Record.size() != 4) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DILexicalBlockFile, Record[0], (Context, getMDOrNull(Record[1]), getMDOrNull(Record[2]), Record[3])), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_NAMESPACE: { if (Record.size() != 5) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DINamespace, Record[0], (Context, getMDOrNull(Record[1]), getMDOrNull(Record[2]), getMDString(Record[3]), Record[4])), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_MACRO: { if (Record.size() != 5) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIMacro, Record[0], (Context, Record[1], Record[2], getMDString(Record[3]), getMDString(Record[4]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_MACRO_FILE: { if (Record.size() != 5) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIMacroFile, Record[0], (Context, Record[1], Record[2], getMDOrNull(Record[3]), getMDOrNull(Record[4]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_TEMPLATE_TYPE: { if (Record.size() != 3) return error("Invalid record"); - MDValueList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter, - Record[0], - (Context, getMDString(Record[1]), - getMDOrNull(Record[2]))), - NextMDValueNo++); + MetadataList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter, + Record[0], + (Context, getMDString(Record[1]), + getMDOrNull(Record[2]))), + NextMetadataNo++); break; } case bitc::METADATA_TEMPLATE_VALUE: { if (Record.size() != 5) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DITemplateValueParameter, Record[0], (Context, Record[1], getMDString(Record[2]), getMDOrNull(Record[3]), getMDOrNull(Record[4]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_GLOBAL_VAR: { if (Record.size() != 11) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIGlobalVariable, Record[0], (Context, getMDOrNull(Record[1]), getMDString(Record[2]), getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], getMDOrNull(Record[6]), Record[7], Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]))), - NextMDValueNo++); + NextMetadataNo++); break; } 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 // DW_TAG_arg_variable. bool HasTag = Record.size() > 8; - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DILocalVariable, Record[0], (Context, getMDOrNull(Record[1 + HasTag]), getMDString(Record[2 + HasTag]), getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag], getMDOrNull(Record[5 + HasTag]), Record[6 + HasTag], Record[7 + HasTag])), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_EXPRESSION: { if (Record.size() < 1) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIExpression, Record[0], (Context, makeArrayRef(Record).slice(1))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_OBJC_PROPERTY: { if (Record.size() != 8) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIObjCProperty, Record[0], (Context, getMDString(Record[1]), getMDOrNull(Record[2]), Record[3], getMDString(Record[4]), getMDString(Record[5]), Record[6], getMDOrNull(Record[7]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_IMPORTED_ENTITY: { if (Record.size() != 6) return error("Invalid record"); - MDValueList.assignValue( + MetadataList.assignValue( GET_OR_DISTINCT(DIImportedEntity, Record[0], (Context, Record[1], getMDOrNull(Record[2]), getMDOrNull(Record[3]), Record[4], getMDString(Record[5]))), - NextMDValueNo++); + NextMetadataNo++); break; } case bitc::METADATA_STRING: { std::string String(Record.begin(), Record.end()); llvm::UpgradeMDStringConstant(String); Metadata *MD = MDString::get(Context, String); - MDValueList.assignValue(MD, NextMDValueNo++); + MetadataList.assignValue(MD, NextMetadataNo++); break; } case bitc::METADATA_KIND: { @@ -3062,22 +3066,21 @@ std::error_code BitcodeReader::materializeMetadata() { void BitcodeReader::setStripDebugInfo() { StripDebugInfo = true; } -void BitcodeReader::saveMDValueList( - DenseMap &MDValueToValIDMap, bool OnlyTempMD) { - for (unsigned ValID = 0; ValID < MDValueList.size(); ++ValID) { - Metadata *MD = MDValueList[ValID]; +void BitcodeReader::saveMetadataList( + DenseMap &MetadataToIDs, bool OnlyTempMD) { + for (unsigned ID = 0; ID < MetadataList.size(); ++ID) { + Metadata *MD = MetadataList[ID]; auto *N = dyn_cast_or_null(MD); // Save all values if !OnlyTempMD, otherwise just the temporary metadata. if (!OnlyTempMD || (N && N->isTemporary())) { // Will call this after materializing each function, in order to // handle remapping of the function's instructions/metadata. // See if we already have an entry in that case. - if (OnlyTempMD && MDValueToValIDMap.count(MD)) { - assert(MDValueToValIDMap[MD] == ValID && - "Inconsistent metadata value id"); + if (OnlyTempMD && MetadataToIDs.count(MD)) { + assert(MetadataToIDs[MD] == ID && "Inconsistent metadata value id"); 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 // metadata ids starting after the module-level metadata ids. Otherwise, // we would have to parse the module-level metadata block to prime the - // MDValueList when we are lazy loading metadata during function - // importing. Initialize the MDValueList size here based on the + // MetadataList when we are lazy loading metadata during function + // importing. Initialize the MetadataList size here based on the // record value, regardless of whether we are doing lazy metadata // loading, so that we have consistent handling and assertion // checking in parseMetadata for module-level metadata. NumModuleMDs = Record[0]; SeenModuleValuesRecord = true; - assert(MDValueList.size() == 0); - MDValueList.resize(NumModuleMDs); + assert(MetadataList.size() == 0); + MetadataList.resize(NumModuleMDs); break; } Record.clear(); @@ -3887,7 +3890,7 @@ std::error_code BitcodeReader::parseMetadataAttachment(Function &F) { auto K = MDKindMap.find(Record[I]); if (K == MDKindMap.end()) return error("Invalid ID"); - Metadata *MD = MDValueList.getValueFwdRef(Record[I + 1]); + Metadata *MD = MetadataList.getValueFwdRef(Record[I + 1]); F.setMetadata(K->second, cast(MD)); } continue; @@ -3901,7 +3904,7 @@ std::error_code BitcodeReader::parseMetadataAttachment(Function &F) { MDKindMap.find(Kind); if (I == MDKindMap.end()) return error("Invalid ID"); - Metadata *Node = MDValueList.getValueFwdRef(Record[i + 1]); + Metadata *Node = MetadataList.getValueFwdRef(Record[i + 1]); if (isa(Node)) // Drop the attachment. This used to be legal, but there's no // upgrade path. @@ -3937,7 +3940,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { InstructionList.clear(); unsigned ModuleValueListSize = ValueList.size(); - unsigned ModuleMDValueListSize = MDValueList.size(); + unsigned ModuleMetadataListSize = MetadataList.size(); // Add all the function arguments to the value table. for (Argument &I : F->args()) @@ -4067,8 +4070,10 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { unsigned ScopeID = Record[2], IAID = Record[3]; MDNode *Scope = nullptr, *IA = nullptr; - if (ScopeID) Scope = cast(MDValueList.getValueFwdRef(ScopeID-1)); - if (IAID) IA = cast(MDValueList.getValueFwdRef(IAID-1)); + if (ScopeID) + Scope = cast(MetadataList.getValueFwdRef(ScopeID - 1)); + if (IAID) + IA = cast(MetadataList.getValueFwdRef(IAID - 1)); LastLoc = DebugLoc::get(Line, Col, Scope, IA); I->setDebugLoc(LastLoc); I = nullptr; @@ -5189,7 +5194,7 @@ OutOfRecordLoop: // Trim the value list down to the size it was before we parsed this function. ValueList.shrinkTo(ModuleValueListSize); - MDValueList.shrinkTo(ModuleMDValueListSize); + MetadataList.shrinkTo(ModuleMetadataListSize); std::vector().swap(FunctionBBs); return std::error_code(); } @@ -5220,7 +5225,7 @@ void BitcodeReader::releaseBuffer() { Buffer.release(); } std::error_code BitcodeReader::materialize(GlobalValue *GV) { // 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 (std::error_code EC = materializeMetadata()) return EC; diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index faf82a7926e..e07563b5a39 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -405,7 +405,7 @@ unsigned ValueEnumerator::getValueID(const Value *V) const { void ValueEnumerator::dump() const { print(dbgs(), ValueMap, "Default"); dbgs() << '\n'; - print(dbgs(), MDValueMap, "MetaData"); + print(dbgs(), MetadataMap, "MetaData"); dbgs() << '\n'; } @@ -522,7 +522,7 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { // EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph. // // 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; // Visit operands first to minimize RAUW. @@ -535,10 +535,10 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { HasDILocation |= isa(MD); HasGenericDINode |= isa(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. MDs.push_back(MD); - MDValueMap[MD] = MDs.size(); + MetadataMap[MD] = MDs.size(); } /// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata @@ -546,12 +546,12 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { void ValueEnumerator::EnumerateFunctionLocalMetadata( const LocalAsMetadata *Local) { // Check to see if it's already in! - unsigned &MDValueID = MDValueMap[Local]; - if (MDValueID) + unsigned &MetadataID = MetadataMap[Local]; + if (MetadataID) return; MDs.push_back(Local); - MDValueID = MDs.size(); + MetadataID = MDs.size(); EnumerateValue(Local->getValue()); @@ -758,7 +758,7 @@ void ValueEnumerator::purgeFunction() { for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i) ValueMap.erase(Values[i].first); 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) ValueMap.erase(BasicBlocks[i]); diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index abe383d7ee4..9fb8325150e 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -63,7 +63,7 @@ private: std::vector MDs; SmallVector FunctionLocalMDs; typedef DenseMap MetadataMapType; - MetadataMapType MDValueMap; + MetadataMapType MetadataMap; bool HasMDString; bool HasDILocation; bool HasGenericDINode; @@ -93,7 +93,7 @@ private: /// before incorporation. 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. unsigned NumModuleMDs; @@ -117,7 +117,7 @@ public: return ID - 1; } unsigned getMetadataOrNullID(const Metadata *MD) const { - return MDValueMap.lookup(MD); + return MetadataMap.lookup(MD); } unsigned numMDs() const { return MDs.size(); } diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index 4a31c4a1a97..fa6e37517fc 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -415,7 +415,7 @@ class IRLinker { /// the value id. Used to correlate temporary metadata created during /// function importing with the final metadata parsed during the subsequent /// metadata linking postpass. - DenseMap MDValueToValIDMap; + DenseMap MetadataToIDs; /// Association between metadata value id and temporary metadata that /// remains unmapped after function importing. Saved during function @@ -642,8 +642,8 @@ Metadata *IRLinker::mapTemporaryMetadata(Metadata *MD) { return nullptr; // If this temporary metadata has a value id recorded during function // parsing, record that in the ValIDToTempMDMap if one was provided. - if (MDValueToValIDMap.count(MD)) { - unsigned Idx = MDValueToValIDMap[MD]; + if (MetadataToIDs.count(MD)) { + unsigned Idx = MetadataToIDs[MD]; // Check if we created a temp MD when importing a different function from // this module. If so, reuse it the same temporary metadata, otherwise // 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 // metadata has a value id recorded during metadata parsing, replace // the temporary metadata with the final mapped metadata now. - if (MDValueToValIDMap.count(OrigMD)) { - unsigned Idx = MDValueToValIDMap[OrigMD]; + if (MetadataToIDs.count(OrigMD)) { + unsigned Idx = MetadataToIDs[OrigMD]; // Nothing to do if we didn't need to create a temporary metadata during // function importing. if (!ValIDToTempMDMap->count(Idx)) @@ -1111,7 +1111,7 @@ bool IRLinker::linkFunctionBody(Function &Dst, Function &Src) { // a function and before remapping metadata on instructions below // in RemapInstruction, as the saved mapping is used to handle // the temporary metadata hanging off instructions. - SrcM.getMaterializer()->saveMDValueList(MDValueToValIDMap, true); + SrcM.getMaterializer()->saveMetadataList(MetadataToIDs, true); // Link in the prefix data. if (Src.hasPrefixData()) @@ -1210,7 +1210,7 @@ void IRLinker::findNeededSubprograms(ValueToValueMapTy &ValueMap) { // importing), see which DISubprogram MD from the source has an associated // temporary metadata node, which means the SP was needed by an imported // function. - for (auto MDI : MDValueToValIDMap) { + for (auto MDI : MetadataToIDs) { const MDNode *Node = dyn_cast(MDI.first); if (!Node) continue; @@ -1514,7 +1514,7 @@ bool IRLinker::run() { // Ensure metadata materialized if (SrcM.getMaterializer()->materializeMetadata()) return true; - SrcM.getMaterializer()->saveMDValueList(MDValueToValIDMap, false); + SrcM.getMaterializer()->saveMetadataList(MetadataToIDs, false); } linkNamedMDNodes(); @@ -1523,10 +1523,10 @@ bool IRLinker::run() { // Handle anything left in the ValIDToTempMDMap, such as metadata nodes // not reached by the dbg.cu NamedMD (i.e. only reached from // 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 // mapping on each one. - for (auto MDI : MDValueToValIDMap) { + for (auto MDI : MetadataToIDs) { if (!ValIDToTempMDMap->count(MDI.second)) continue; MapMetadata(MDI.first, ValueMap, ValueMapperFlags, &TypeMap,