llvm.org GIT mirror llvm / 6aef9f9
Add support for metadata attachments for global variables. This patch adds an IR, assembly and bitcode representation for metadata attachments for globals. Future patches will port existing features to use these new attachments. Differential Revision: http://reviews.llvm.org/D20074 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271348 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
18 changed file(s) with 225 addition(s) and 118 deletion(s). Raw diff Collapse all Expand all
854854 be one ``GCNAME`` record for each garbage collector name referenced in function
855855 ``gc`` attributes within the module. These records can be referenced by 1-based
856856 index in the *gc* fields of ``FUNCTION`` records.
857
858 MODULE_CODE_GLOBALVAR_ATTACHMENT Record
859 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
860
861 ``[GLOBALVAR_ATTACHMENT, valueid, n x [id, mdnode]]``
862
863 The ``GLOBALVAR_ATTACHMENT`` record (code 19) describes the metadata
864 attachments for a global variable. The ``valueid`` is the value index for
865 the global variable, and the remaining fields are pairs of metadata name
866 indices and metadata node indices.
857867
858868 .. _PARAMATTR_BLOCK:
859869
618618 iterate over them as an array, alignment padding would break this
619619 iteration. The maximum alignment is ``1 << 29``.
620620
621 Globals can also have a :ref:`DLL storage class `.
621 Globals can also have a :ref:`DLL storage class ` and
622 an optional list of attached :ref:`metadata `,
622623
623624 Variables and aliases can have a
624625 :ref:`Thread Local Storage Model `.
629630 [unnamed_addr] [AddrSpace] [ExternallyInitialized]
630631 []
631632 [, section "name"] [, comdat [($name)]]
632 [, align ]
633 [, align ] (, !name !N)*
633634
634635 For example, the following defines a global in a numbered address space
635636 with an initializer, section, and alignment:
112112
113113 // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
114114 MODULE_CODE_IFUNC = 18,
115
116 // GLOBALVAR_ATTACHMENT: [valueid, n x [id, mdnode]]
117 MODULE_CODE_GLOBALVAR_ATTACHMENT = 19,
115118 };
116119
117120 /// PARAMATTR blocks have code for defining a parameter attribute set.
7171 /// Bits from GlobalObject::GlobalObjectSubclassData.
7272 enum {
7373 /// Whether this function is materializable.
74 IsMaterializableBit = 1 << 0,
75 HasMetadataHashEntryBit = 1 << 1
74 IsMaterializableBit = 0,
7675 };
77 void setGlobalObjectBit(unsigned Mask, bool Value) {
78 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
79 (Value ? Mask : 0u));
80 }
8176
8277 friend class SymbolTableListTraits;
8378
613608 /// setjmp or other function that gcc recognizes as "returning twice".
614609 bool callsFunctionThatReturnsTwice() const;
615610
616 /// \brief Check if this has any metadata.
617 bool hasMetadata() const { return hasMetadataHashEntry(); }
618
619 /// \brief Get the current metadata attachment, if any.
620 ///
621 /// Returns \c nullptr if such an attachment is missing.
622 /// @{
623 MDNode *getMetadata(unsigned KindID) const;
624 MDNode *getMetadata(StringRef Kind) const;
625 /// @}
626
627 /// \brief Set a particular kind of metadata attachment.
628 ///
629 /// Sets the given attachment to \c MD, erasing it if \c MD is \c nullptr or
630 /// replacing it if it already exists.
631 /// @{
632 void setMetadata(unsigned KindID, MDNode *MD);
633 void setMetadata(StringRef Kind, MDNode *MD);
634 /// @}
635
636 /// \brief Get all current metadata attachments.
637 void
638 getAllMetadata(SmallVectorImpl> &MDs) const;
639
640 /// \brief Drop metadata not in the given list.
641 ///
642 /// Drop all metadata from \c this not included in \c KnownIDs.
643 void dropUnknownMetadata(ArrayRef KnownIDs);
644
645611 /// \brief Set the attached subprogram.
646612 ///
647613 /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
663629 Value::setValueSubclassData(D);
664630 }
665631 void setValueSubclassDataBit(unsigned Bit, bool On);
666
667 bool hasMetadataHashEntry() const {
668 return getGlobalObjectSubClassData() & HasMetadataHashEntryBit;
669 }
670 void setHasMetadataHashEntry(bool HasEntry) {
671 setGlobalObjectBit(HasMetadataHashEntryBit, HasEntry);
672 }
673
674 void clearMetadata();
675632 };
676633
677634 template <>
1919
2020 namespace llvm {
2121 class Comdat;
22 class MDNode;
2223 class Module;
2324
2425 class GlobalObject : public GlobalValue {
3536
3637 std::string Section; // Section to emit this into, empty means default
3738 Comdat *ObjComdat;
38 static const unsigned AlignmentBits = 5;
39 enum {
40 LastAlignmentBit = 4,
41 HasMetadataHashEntryBit,
42
43 GlobalObjectBits,
44 };
3945 static const unsigned GlobalObjectSubClassDataBits =
40 GlobalValueSubClassDataBits - AlignmentBits;
46 GlobalValueSubClassDataBits - GlobalObjectBits;
4147
4248 private:
49 static const unsigned AlignmentBits = LastAlignmentBit + 1;
4350 static const unsigned AlignmentMask = (1 << AlignmentBits) - 1;
51 static const unsigned GlobalObjectMask = (1 << GlobalObjectBits) - 1;
4452
4553 public:
4654 unsigned getAlignment() const {
6270 Comdat *getComdat() { return ObjComdat; }
6371 void setComdat(Comdat *C) { ObjComdat = C; }
6472
73 /// Check if this has any metadata.
74 bool hasMetadata() const { return hasMetadataHashEntry(); }
75
76 /// Get the current metadata attachment, if any.
77 ///
78 /// Returns \c nullptr if such an attachment is missing.
79 /// @{
80 MDNode *getMetadata(unsigned KindID) const;
81 MDNode *getMetadata(StringRef Kind) const;
82 /// @}
83
84 /// Set a particular kind of metadata attachment.
85 ///
86 /// Sets the given attachment to \c MD, erasing it if \c MD is \c nullptr or
87 /// replacing it if it already exists.
88 /// @{
89 void setMetadata(unsigned KindID, MDNode *MD);
90 void setMetadata(StringRef Kind, MDNode *MD);
91 /// @}
92
93 /// Get all current metadata attachments.
94 void
95 getAllMetadata(SmallVectorImpl> &MDs) const;
96
97 /// Drop metadata not in the given list.
98 ///
99 /// Drop all metadata from \c this not included in \c KnownIDs.
100 void dropUnknownMetadata(ArrayRef KnownIDs);
101
65102 void copyAttributesFrom(const GlobalValue *Src) override;
66103
67104 // Methods for support type inquiry through isa, cast, and dyn_cast:
69106 return V->getValueID() == Value::FunctionVal ||
70107 V->getValueID() == Value::GlobalVariableVal;
71108 }
109
110 protected:
111 void clearMetadata();
112
113 private:
114 bool hasMetadataHashEntry() const {
115 return getGlobalValueSubClassData() & (1 << HasMetadataHashEntryBit);
116 }
117 void setHasMetadataHashEntry(bool HasEntry) {
118 unsigned Mask = 1 << HasMetadataHashEntryBit;
119 setGlobalValueSubClassData((~Mask & getGlobalValueSubClassData()) |
120 (HasEntry ? Mask : 0u));
121 }
72122 };
73123
74124 } // End llvm namespace
158158 ///
159159 void eraseFromParent() override;
160160
161 /// Drop all references in preparation to destroy the GlobalVariable. This
162 /// drops not only the reference to the initializer but also to any metadata.
163 void dropAllReferences();
164
161165 // Methods for support type inquiry through isa, cast, and dyn_cast:
162166 static inline bool classof(const Value *V) {
163167 return V->getValueID() == Value::GlobalVariableVal;
890890 unsigned Alignment;
891891 if (ParseOptionalAlignment(Alignment)) return true;
892892 GV->setAlignment(Alignment);
893 } else if (Lex.getKind() == lltok::MetadataVar) {
894 if (ParseGlobalObjectMetadataAttachment(*GV))
895 return true;
893896 } else {
894897 Comdat *C;
895898 if (parseOptionalComdat(Name, C))
17071710 return false;
17081711 }
17091712
1713 /// ParseGlobalObjectMetadataAttachment
1714 /// ::= !dbg !57
1715 bool LLParser::ParseGlobalObjectMetadataAttachment(GlobalObject &GO) {
1716 unsigned MDK;
1717 MDNode *N;
1718 if (ParseMetadataAttachment(MDK, N))
1719 return true;
1720
1721 GO.setMetadata(MDK, N);
1722 return false;
1723 }
1724
17101725 /// ParseOptionalFunctionMetadata
17111726 /// ::= (!dbg !57)*
17121727 bool LLParser::ParseOptionalFunctionMetadata(Function &F) {
1713 while (Lex.getKind() == lltok::MetadataVar) {
1714 unsigned MDK;
1715 MDNode *N;
1716 if (ParseMetadataAttachment(MDK, N))
1728 while (Lex.getKind() == lltok::MetadataVar)
1729 if (ParseGlobalObjectMetadataAttachment(F))
17171730 return true;
1718
1719 F.setMetadata(MDK, N);
1720 }
17211731 return false;
17221732 }
17231733
423423 bool ParseMDNodeVector(SmallVectorImpl &MDs);
424424 bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD);
425425 bool ParseInstructionMetadata(Instruction &Inst);
426 bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO);
426427 bool ParseOptionalFunctionMetadata(Function &F);
427428
428429 template
442442 unsigned &NextMetadataNo);
443443 std::error_code parseMetadataKinds();
444444 std::error_code parseMetadataKindRecord(SmallVectorImpl &Record);
445 std::error_code
446 parseGlobalObjectAttachment(GlobalObject &GO,
447 ArrayRef Record);
445448 std::error_code parseMetadataAttachment(Function &F);
446449 ErrorOr parseModuleTriple();
447450 std::error_code parseUseLists();
38193822 }
38203823 break;
38213824 }
3825 case bitc::MODULE_CODE_GLOBALVAR_ATTACHMENT: {
3826 if (Record.size() % 2 == 0)
3827 return error("Invalid record");
3828 unsigned ValueID = Record[0];
3829 if (ValueID >= ValueList.size())
3830 return error("Invalid record");
3831 if (auto *GV = dyn_cast(ValueList[ValueID]))
3832 parseGlobalObjectAttachment(*GV, ArrayRef(Record).slice(1));
3833 break;
3834 }
38223835 // FUNCTION: [type, callingconv, isproto, linkage, paramattr,
38233836 // alignment, section, visibility, gc, unnamed_addr,
38243837 // prologuedata, dllstorageclass, comdat, prefixdata]
41434156 }
41444157 }
41454158
4159 std::error_code BitcodeReader::parseGlobalObjectAttachment(
4160 GlobalObject &GO, ArrayRef Record) {
4161 assert(Record.size() % 2 == 0);
4162 for (unsigned I = 0, E = Record.size(); I != E; I += 2) {
4163 auto K = MDKindMap.find(Record[I]);
4164 if (K == MDKindMap.end())
4165 return error("Invalid ID");
4166 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[I + 1]);
4167 if (!MD)
4168 return error("Invalid metadata attachment");
4169 GO.setMetadata(K->second, MD);
4170 }
4171 return std::error_code();
4172 }
4173
41464174 /// Parse metadata attachments.
41474175 std::error_code BitcodeReader::parseMetadataAttachment(Function &F) {
41484176 if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID))
41744202 return error("Invalid record");
41754203 if (RecordLength % 2 == 0) {
41764204 // A function attachment.
4177 for (unsigned I = 0; I != RecordLength; I += 2) {
4178 auto K = MDKindMap.find(Record[I]);
4179 if (K == MDKindMap.end())
4180 return error("Invalid ID");
4181 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[I + 1]);
4182 if (!MD)
4183 return error("Invalid metadata attachment");
4184 F.setMetadata(K->second, MD);
4185 }
4205 if (std::error_code EC = parseGlobalObjectAttachment(F, Record))
4206 return EC;
41864207 continue;
41874208 }
41884209
222222 SmallVectorImpl &Record);
223223 void writeModuleMetadata();
224224 void writeFunctionMetadata(const Function &F);
225 void writeMetadataAttachment(const Function &F);
225 void writeFunctionMetadataAttachment(const Function &F);
226 void writeGlobalVariableMetadataAttachment(const GlobalVariable &GV);
227 void pushGlobalMetadataAttachment(SmallVectorImpl &Record,
228 const GlobalObject &GO);
226229 void writeModuleMetadataStore();
227230 void writeOperandBundleTags();
228231 void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
18301833 Stream.ExitBlock();
18311834 }
18321835
1833 void ModuleBitcodeWriter::writeMetadataAttachment(const Function &F) {
1836 void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
1837 SmallVectorImpl &Record, const GlobalObject &GO) {
1838 // [n x [id, mdnode]]
1839 SmallVector, 4> MDs;
1840 GO.getAllMetadata(MDs);
1841 for (const auto &I : MDs) {
1842 Record.push_back(I.first);
1843 Record.push_back(VE.getMetadataID(I.second));
1844 }
1845 }
1846
1847 void ModuleBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
18341848 Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
18351849
18361850 SmallVector Record;
1851
1852 if (F.hasMetadata()) {
1853 pushGlobalMetadataAttachment(Record, F);
1854 Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
1855 Record.clear();
1856 }
18371857
18381858 // Write metadata attachments
18391859 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
18401860 SmallVector, 4> MDs;
1841 F.getAllMetadata(MDs);
1842 if (!MDs.empty()) {
1843 for (const auto &I : MDs) {
1844 Record.push_back(I.first);
1845 Record.push_back(VE.getMetadataID(I.second));
1846 }
1847 Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
1848 Record.clear();
1849 }
1850
18511861 for (const BasicBlock &BB : F)
18521862 for (const Instruction &I : BB) {
18531863 MDs.clear();
28932903 writeValueSymbolTable(F.getValueSymbolTable());
28942904
28952905 if (NeedsMetadataAttachment)
2896 writeMetadataAttachment(F);
2906 writeFunctionMetadataAttachment(F);
28972907 if (VE.shouldPreserveUseListOrder())
28982908 writeUseListBlock(&F);
28992909 VE.purgeFunction();
35953605
35963606 writeValueSymbolTable(M.getValueSymbolTable(),
35973607 /* IsModuleLevel */ true, &FunctionToBitcodeIndex);
3608
3609 for (const GlobalVariable &GV : M.globals())
3610 if (GV.hasMetadata()) {
3611 SmallVector Record;
3612 Record.push_back(VE.getValueID(&GV));
3613 pushGlobalMetadataAttachment(Record, GV);
3614 Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR_ATTACHMENT, Record);
3615 }
35983616
35993617 if (GenerateHash) {
36003618 writeModuleHash(BlockStartPos);
343343 EnumerateNamedMetadata(M);
344344
345345 SmallVector, 8> MDs;
346 for (const GlobalVariable &GV : M.globals()) {
347 GV.getAllMetadata(MDs);
348 for (const auto &I : MDs)
349 EnumerateMetadata(&GV, I.second);
350 }
346351
347352 // Enumerate types used by function bodies and argument lists.
348353 for (const Function &F : M) {
522527 EnumerateMetadata(nullptr, MD->getOperand(i));
523528 }
524529
525 unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const {
526 return F ? getValueID(F) + 1 : 0;
527 }
528
529 void ValueEnumerator::EnumerateMetadata(const Function *F, const Metadata *MD) {
530 EnumerateMetadata(getMetadataFunctionID(F), MD);
530 unsigned ValueEnumerator::getMetadataGlobalID(const GlobalObject *GO) const {
531 return GO ? getValueID(GO) + 1 : 0;
532 }
533
534 void ValueEnumerator::EnumerateMetadata(const GlobalObject *GO,
535 const Metadata *MD) {
536 EnumerateMetadata(getMetadataGlobalID(GO), MD);
531537 }
532538
533539 void ValueEnumerator::EnumerateFunctionLocalMetadata(
534540 const Function &F, const LocalAsMetadata *Local) {
535 EnumerateFunctionLocalMetadata(getMetadataFunctionID(&F), Local);
541 EnumerateFunctionLocalMetadata(getMetadataGlobalID(&F), Local);
536542 }
537543
538544 void ValueEnumerator::dropFunctionFromMetadata(
254254 /// it's an \a MDNode.
255255 const MDNode *enumerateMetadataImpl(unsigned F, const Metadata *MD);
256256
257 unsigned getMetadataFunctionID(const Function *F) const;
257 unsigned getMetadataGlobalID(const GlobalObject *GO) const;
258258
259259 /// Enumerate reachable metadata in (almost) post-order.
260260 ///
271271 /// \a organizeMetadata() will later partition distinct nodes ahead of
272272 /// uniqued ones.
273273 ///{
274 void EnumerateMetadata(const Function *F, const Metadata *MD);
274 void EnumerateMetadata(const GlobalObject *GO, const Metadata *MD);
275275 void EnumerateMetadata(unsigned F, const Metadata *MD);
276276 ///}
277277
680680 /// Add all of the functions arguments, basic blocks, and instructions.
681681 void processFunction();
682682
683 /// Add the metadata directly attached to a GlobalObject.
684 void processGlobalObjectMetadata(const GlobalObject &GO);
685
683686 /// Add all of the metadata from a function.
684687 void processFunctionMetadata(const Function &F);
685688
798801 for (const GlobalVariable &Var : TheModule->globals()) {
799802 if (!Var.hasName())
800803 CreateModuleSlot(&Var);
804 processGlobalObjectMetadata(Var);
801805 }
802806
803807 for (const GlobalAlias &A : TheModule->aliases()) {
881885 ST_DEBUG("end processFunction!\n");
882886 }
883887
884 void SlotTracker::processFunctionMetadata(const Function &F) {
888 void SlotTracker::processGlobalObjectMetadata(const GlobalObject &GO) {
885889 SmallVector, 4> MDs;
886 F.getAllMetadata(MDs);
890 GO.getAllMetadata(MDs);
887891 for (auto &MD : MDs)
888892 CreateMetadataSlot(MD.second);
889
893 }
894
895 void SlotTracker::processFunctionMetadata(const Function &F) {
896 processGlobalObjectMetadata(F);
890897 for (auto &BB : F) {
891898 for (auto &I : BB)
892899 processInstructionMetadata(I);
24722479 if (GV->getAlignment())
24732480 Out << ", align " << GV->getAlignment();
24742481
2482 SmallVector, 4> MDs;
2483 GV->getAllMetadata(MDs);
2484 printMetadataAttachments(MDs, ", ");
2485
24752486 printInfoComment(*GV);
24762487 }
24772488
217217 //===----------------------------------------------------------------------===//
218218
219219 bool Function::isMaterializable() const {
220 return getGlobalObjectSubClassData() & IsMaterializableBit;
220 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
221221 }
222222
223223 void Function::setIsMaterializable(bool V) {
224 setGlobalObjectBit(IsMaterializableBit, V);
224 unsigned Mask = 1 << IsMaterializableBit;
225 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
226 (V ? Mask : 0u));
225227 }
226228
227229 LLVMContext &Function::getContext() const {
8080
8181 unsigned GlobalObject::getGlobalObjectSubClassData() const {
8282 unsigned ValueData = getGlobalValueSubClassData();
83 return ValueData >> AlignmentBits;
83 return ValueData >> GlobalObjectBits;
8484 }
8585
8686 void GlobalObject::setGlobalObjectSubClassData(unsigned Val) {
8787 unsigned OldData = getGlobalValueSubClassData();
88 setGlobalValueSubClassData((OldData & AlignmentMask) |
89 (Val << AlignmentBits));
88 setGlobalValueSubClassData((OldData & GlobalObjectMask) |
89 (Val << GlobalObjectBits));
9090 assert(getGlobalObjectSubClassData() == Val && "representation error");
9191 }
9292
300300 }
301301 }
302302
303 void GlobalVariable::dropAllReferences() {
304 User::dropAllReferences();
305 clearMetadata();
306 }
303307
304308 //===----------------------------------------------------------------------===//
305309 // GlobalIndirectSymbol Implementation
11061106 /// Collection of per-instruction metadata used in this context.
11071107 DenseMap InstructionMetadata;
11081108
1109 /// Collection of per-function metadata used in this context.
1110 DenseMap FunctionMetadata;
1109 /// Collection of per-GlobalObject metadata used in this context.
1110 DenseMap GlobalObjectMetadata;
11111111
11121112 /// DiscriminatorTable - This table maps file:line locations to an
11131113 /// integer representing the next DWARF path discriminator to assign to
12801280 setHasMetadataHashEntry(false);
12811281 }
12821282
1283 MDNode *Function::getMetadata(unsigned KindID) const {
1283 MDNode *GlobalObject::getMetadata(unsigned KindID) const {
12841284 if (!hasMetadata())
12851285 return nullptr;
1286 return getContext().pImpl->FunctionMetadata[this].lookup(KindID);
1287 }
1288
1289 MDNode *Function::getMetadata(StringRef Kind) const {
1286 return getContext().pImpl->GlobalObjectMetadata[this].lookup(KindID);
1287 }
1288
1289 MDNode *GlobalObject::getMetadata(StringRef Kind) const {
12901290 if (!hasMetadata())
12911291 return nullptr;
12921292 return getMetadata(getContext().getMDKindID(Kind));
12931293 }
12941294
1295 void Function::setMetadata(unsigned KindID, MDNode *MD) {
1295 void GlobalObject::setMetadata(unsigned KindID, MDNode *MD) {
12961296 if (MD) {
12971297 if (!hasMetadata())
12981298 setHasMetadataHashEntry(true);
12991299
1300 getContext().pImpl->FunctionMetadata[this].set(KindID, *MD);
1300 getContext().pImpl->GlobalObjectMetadata[this].set(KindID, *MD);
13011301 return;
13021302 }
13031303
13051305 if (!hasMetadata())
13061306 return;
13071307
1308 auto &Store = getContext().pImpl->FunctionMetadata[this];
1308 auto &Store = getContext().pImpl->GlobalObjectMetadata[this];
13091309 Store.erase(KindID);
13101310 if (Store.empty())
13111311 clearMetadata();
13121312 }
13131313
1314 void Function::setMetadata(StringRef Kind, MDNode *MD) {
1314 void GlobalObject::setMetadata(StringRef Kind, MDNode *MD) {
13151315 if (!MD && !hasMetadata())
13161316 return;
13171317 setMetadata(getContext().getMDKindID(Kind), MD);
13181318 }
13191319
1320 void Function::getAllMetadata(
1320 void GlobalObject::getAllMetadata(
13211321 SmallVectorImpl> &MDs) const {
13221322 MDs.clear();
13231323
13241324 if (!hasMetadata())
13251325 return;
13261326
1327 getContext().pImpl->FunctionMetadata[this].getAll(MDs);
1328 }
1329
1330 void Function::dropUnknownMetadata(ArrayRef KnownIDs) {
1327 getContext().pImpl->GlobalObjectMetadata[this].getAll(MDs);
1328 }
1329
1330 void GlobalObject::dropUnknownMetadata(ArrayRef KnownIDs) {
13311331 if (!hasMetadata())
13321332 return;
13331333 if (KnownIDs.empty()) {
13381338 SmallSet KnownSet;
13391339 KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
13401340
1341 auto &Store = getContext().pImpl->FunctionMetadata[this];
1341 auto &Store = getContext().pImpl->GlobalObjectMetadata[this];
13421342 assert(!Store.empty());
13431343
13441344 Store.remove_if([&KnownSet](const std::pair &I) {
13491349 clearMetadata();
13501350 }
13511351
1352 void Function::clearMetadata() {
1352 void GlobalObject::clearMetadata() {
13531353 if (!hasMetadata())
13541354 return;
1355 getContext().pImpl->FunctionMetadata.erase(this);
1355 getContext().pImpl->GlobalObjectMetadata.erase(this);
13561356 setHasMetadataHashEntry(false);
13571357 }
13581358
0 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
11 ; RUN: verify-uselistorder %s
22
3 ; CHECK: @global = global i32 0, !foo [[M2:![0-9]+]], !baz [[M3:![0-9]+]]
4 @global = global i32 0, !foo !2, !baz !3
5
36 ; CHECK-LABEL: @test
4 ; CHECK: ret void, !bar !4, !foo !3
7 ; CHECK: ret void, !foo [[M0:![0-9]+]], !bar [[M1:![0-9]+]]
58 define void @test() !dbg !1 {
69 add i32 2, 1, !bar !0
710 add i32 1, 2, !foo !1
1013 ret void, !foo !0, !bar !1
1114 }
1215
13 ; CHECK-LABEL: define void @test2() !foo !5 !baz !6
16 ; CHECK: define void @test2() !foo [[M2]] !baz [[M3]]
1417 define void @test2() !foo !2 !baz !3 {
1518 unreachable
1619 }
1720
18 ; CHECK-LABEL: define void @test3() !bar !6
19 ; CHECK: unreachable, !bar !7
21 ; CHECK: define void @test3() !bar [[M3]]
22 ; CHECK: unreachable, !bar [[M4:![0-9]+]]
2023 define void @test3() !bar !3 {
2124 unreachable, !bar !4
2225 }
2326
2427 ; CHECK-LABEL: define void @test_attachment_name() {
25 ; CHECK: unreachable, !\342abc !7
28 ; CHECK: unreachable, !\342abc [[M4]]
2629 define void @test_attachment_name() {
2730 ;; Escape the first character when printing text IR, since it's a digit
2831 unreachable, !\34\32abc !4
2932 }
33
34 ; CHECK: [[M2]] = distinct !{}
35 ; CHECK: [[M3]] = distinct !{}
36 ; CHECK: [[M0]] = !DILocation
37 ; CHECK: [[M1]] = distinct !DISubprogram
38 ; CHECK: [[M4]] = distinct !{}
3039
3140 !llvm.module.flags = !{!7}
3241 !llvm.dbg.cu = !{!5}