llvm.org GIT mirror llvm / 17aa92c
Make NamedMDNode not be a subclass of Value, and simplify the interface for creating and populating NamedMDNodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109061 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
19 changed file(s) with 99 addition(s) and 275 deletion(s). Raw diff Collapse all Expand all
176176 //===----------------------------------------------------------------------===//
177177 /// NamedMDNode - a tuple of MDNodes.
178178 /// NamedMDNode is always named. All NamedMDNode operand has a type of metadata.
179 class NamedMDNode : public Value, public ilist_node {
179 class NamedMDNode : public ilist_node {
180180 friend class SymbolTableListTraits;
181181 friend struct ilist_traits;
182182 friend class LLVMContextImpl;
183 friend class Module;
183184 NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
184185
185186 std::string Name;
187188 void *Operands; // SmallVector, 4>
188189
189190 void setParent(Module *M) { Parent = M; }
191
190192 protected:
191 explicit NamedMDNode(LLVMContext &C, const Twine &N, MDNode*const *Vals,
192 unsigned NumVals, Module *M = 0);
193 explicit NamedMDNode(const Twine &N);
194
193195 public:
194 static NamedMDNode *Create(LLVMContext &C, const Twine &N,
195 MDNode *const *MDs,
196 unsigned NumMDs, Module *M = 0) {
197 return new NamedMDNode(C, N, MDs, NumMDs, M);
198 }
199
200 static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
201
202196 /// eraseFromParent - Drop all references and remove the node from parent
203197 /// module.
204198 void eraseFromParent();
222216 /// addOperand - Add metadata operand.
223217 void addOperand(MDNode *M);
224218
225 /// setName - Set the name of this named metadata.
226 void setName(const Twine &NewName);
227
228219 /// getName - Return a constant reference to this named metadata's name.
229220 StringRef getName() const;
230221
231 /// Methods for support type inquiry through isa, cast, and dyn_cast:
232 static inline bool classof(const NamedMDNode *) { return true; }
233 static bool classof(const Value *V) {
234 return V->getValueID() == NamedMDNodeVal;
235 }
222 /// print - Implement operator<< on NamedMDNode.
223 void print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW = 0) const;
236224 };
237225
238226 } // end llvm namespace
2727 class FunctionType;
2828 class GVMaterializer;
2929 class LLVMContext;
30 class MDSymbolTable;
3130
3231 template<> struct ilist_traits
3332 : public SymbolTableListTraits {
6059 };
6160
6261 template<> struct ilist_traits
63 : public SymbolTableListTraitse> {
62 : public ilist_default_traitse> {
6463 // createSentinel is used to get hold of a node that marks the end of
6564 // the list...
6665 NamedMDNode *createSentinel() const {
7170 NamedMDNode *provideInitialHead() const { return createSentinel(); }
7271 NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); }
7372 static void noteHead(NamedMDNode*, NamedMDNode*) {}
74 void addNodeToList(NamedMDNode *N);
75 void removeNodeFromList(NamedMDNode *N);
73 void addNodeToList(NamedMDNode *N) {}
74 void removeNodeFromList(NamedMDNode *N) {}
7675 private:
7776 mutable ilist_node Sentinel;
7877 };
9998 /// The type for the list of aliases.
10099 typedef iplist AliasListType;
101100 /// The type for the list of named metadata.
102 typedef iplist NamedMDListType;
101 typedef ilist NamedMDListType;
103102
104103 /// The type for the list of dependent libraries.
105104 typedef std::vector LibraryListType;
150149 std::string ModuleID; ///< Human readable identifier for the module
151150 std::string TargetTriple; ///< Platform target triple Module compiled on
152151 std::string DataLayout; ///< Target data description
153 MDSymbolTable *NamedMDSymTab; ///< NamedMDNode names.
152 void *NamedMDSymTab; ///< NamedMDNode names.
154153
155154 friend class Constant;
156155
330329 /// NamedMDNode with the specified name is not found.
331330 NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
332331
332 /// eraseNamedMetadata - Remove the given NamedMDNode from this module
333 /// and delete it.
334 void eraseNamedMetadata(NamedMDNode *NMD);
335
333336 /// @}
334337 /// @name Type Accessors
335338 /// @{
416419 static iplist Module::*getSublistAccess(GlobalAlias*) {
417420 return &Module::AliasList;
418421 }
419 /// Get the Module's list of named metadata (constant).
420 const NamedMDListType &getNamedMDList() const { return NamedMDList; }
421 /// Get the Module's list of named metadata.
422 NamedMDListType &getNamedMDList() { return NamedMDList; }
423 static iplist Module::*getSublistAccess(NamedMDNode *) {
424 return &Module::NamedMDList;
425 }
426422 /// Get the symbol table of global variable and function identifiers
427423 const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
428424 /// Get the Module's symbol table of global variable and function identifiers.
431427 const TypeSymbolTable &getTypeSymbolTable() const { return *TypeSymTab; }
432428 /// Get the Module's symbol table of types
433429 TypeSymbolTable &getTypeSymbolTable() { return *TypeSymTab; }
434 /// Get the symbol table of named metadata
435 const MDSymbolTable &getMDSymbolTable() const { return *NamedMDSymTab; }
436 /// Get the Module's symbol table of named metadata
437 MDSymbolTable &getMDSymbolTable() { return *NamedMDSymTab; }
438430
439431 /// @}
440432 /// @name Global Variable Iteration
219219 ConstantPointerNullVal, // This is an instance of ConstantPointerNull
220220 MDNodeVal, // This is an instance of MDNode
221221 MDStringVal, // This is an instance of MDString
222 NamedMDNodeVal, // This is an instance of NamedMDNode
223222 InlineAsmVal, // This is an instance of InlineAsm
224223 PseudoSourceValueVal, // This is an instance of PseudoSourceValue
225224 FixedStackPseudoSourceValueVal, // This is an instance of
127127 /// @}
128128 };
129129
130 /// This class provides a symbol table of name/NamedMDNode pairs. It is
131 /// essentially a StringMap wrapper.
132
133 class MDSymbolTable {
134 friend class SymbolTableListTraits;
135 /// @name Types
136 /// @{
137 private:
138 /// @brief A mapping of names to metadata
139 typedef StringMap MDMap;
140
141 public:
142 /// @brief An iterator over a ValueMap.
143 typedef MDMap::iterator iterator;
144
145 /// @brief A const_iterator over a ValueMap.
146 typedef MDMap::const_iterator const_iterator;
147
148 /// @}
149 /// @name Constructors
150 /// @{
151 public:
152
153 MDSymbolTable(const MDNode &); // DO NOT IMPLEMENT
154 void operator=(const MDSymbolTable &); // DO NOT IMPLEMENT
155 MDSymbolTable() : mmap(0) {}
156 ~MDSymbolTable();
157
158 /// @}
159 /// @name Accessors
160 /// @{
161 public:
162
163 /// This method finds the value with the given \p Name in the
164 /// the symbol table.
165 /// @returns the NamedMDNode associated with the \p Name
166 /// @brief Lookup a named Value.
167 NamedMDNode *lookup(StringRef Name) const { return mmap.lookup(Name); }
168
169 /// @returns true iff the symbol table is empty
170 /// @brief Determine if the symbol table is empty
171 inline bool empty() const { return mmap.empty(); }
172
173 /// @brief The number of name/type pairs is returned.
174 inline unsigned size() const { return unsigned(mmap.size()); }
175
176 /// @}
177 /// @name Iteration
178 /// @{
179 public:
180 /// @brief Get an iterator that from the beginning of the symbol table.
181 inline iterator begin() { return mmap.begin(); }
182
183 /// @brief Get a const_iterator that from the beginning of the symbol table.
184 inline const_iterator begin() const { return mmap.begin(); }
185
186 /// @brief Get an iterator to the end of the symbol table.
187 inline iterator end() { return mmap.end(); }
188
189 /// @brief Get a const_iterator to the end of the symbol table.
190 inline const_iterator end() const { return mmap.end(); }
191
192 /// @}
193 /// @name Mutators
194 /// @{
195 public:
196 /// insert - The method inserts a new entry into the stringmap. This will
197 /// replace existing entry, if any.
198 void insert(StringRef Name, NamedMDNode *Node) {
199 StringMapEntry &Entry =
200 mmap.GetOrCreateValue(Name, Node);
201 if (Entry.getValue() != Node) {
202 mmap.remove(&Entry);
203 (void) mmap.GetOrCreateValue(Name, Node);
204 }
205 }
206
207 /// This method removes a NamedMDNode from the symbol table.
208 void remove(StringRef Name) { mmap.erase(Name); }
209
210 /// @}
211 /// @name Internal Data
212 /// @{
213 private:
214 MDMap mmap; ///< The map that holds the symbol table.
215 /// @}
216 };
217
218130 } // End llvm namespace
219131
220132 #endif
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/Analysis/DebugInfo.h"
15 #include "llvm/Target/TargetMachine.h" // FIXME: LAYERING VIOLATION!
1615 #include "llvm/Constants.h"
1716 #include "llvm/DerivedTypes.h"
1817 #include "llvm/Intrinsics.h"
2120 #include "llvm/Module.h"
2221 #include "llvm/Analysis/ValueTracking.h"
2322 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/SmallString.h"
2424 #include "llvm/Support/Debug.h"
2525 #include "llvm/Support/Dwarf.h"
2626 #include "llvm/Support/raw_ostream.h"
10711071 char One = '\1';
10721072 if (FName.startswith(StringRef(&One, 1)))
10731073 FName = FName.substr(1);
1074 NamedMDNode *FnLocals = M.getNamedMetadata(Twine("llvm.dbg.lv.", FName));
1075 if (!FnLocals)
1076 FnLocals = NamedMDNode::Create(VMContext, Twine("llvm.dbg.lv.", FName),
1077 NULL, 0, &M);
1074
1075 SmallString<32> Out;
1076 NamedMDNode *FnLocals =
1077 M.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", FName).toStringRef(Out));
10781078 FnLocals->addOperand(Node);
10791079 }
10801080 return DIVariable(Node);
542542 ParseToken(lltok::lbrace, "Expected '{' here"))
543543 return true;
544544
545 SmallVector Elts;
545 NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
546546 if (Lex.getKind() != lltok::rbrace)
547547 do {
548548 if (ParseToken(lltok::exclaim, "Expected '!' here"))
550550
551551 MDNode *N = 0;
552552 if (ParseMDNodeID(N)) return true;
553 Elts.push_back(N);
553 NMD->addOperand(N);
554554 } while (EatIfPresent(lltok::comma));
555555
556556 if (ParseToken(lltok::rbrace, "expected end of metadata node"))
557557 return true;
558558
559 NamedMDNode::Create(Context, Name, Elts.data(), Elts.size(), M);
560559 return false;
561560 }
562561
800800
801801 // Read named metadata elements.
802802 unsigned Size = Record.size();
803 SmallVector Elts;
803 NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name);
804804 for (unsigned i = 0; i != Size; ++i) {
805805 MDNode *MD = dyn_cast(MDValueList.getValueFwdRef(Record[i]));
806806 if (MD == 0)
807807 return Error("Malformed metadata record");
808 Elts.push_back(MD);
809 }
810 Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(),
811 Elts.size(), TheModule);
812 MDValueList.AssignValue(V, NextMDValueNo++);
808 NMD->addOperand(MD);
809 }
813810 break;
814811 }
815812 case bitc::METADATA_FN_NODE:
508508 Record.clear();
509509 }
510510
511 static void WriteModuleMetadata(const ValueEnumerator &VE,
511 static void WriteModuleMetadata(const Module *M,
512 const ValueEnumerator &VE,
512513 BitstreamWriter &Stream) {
513514 const ValueEnumerator::ValueList &Vals = VE.getMDValues();
514515 bool StartedMetadataBlock = false;
543544 // Emit the finished record.
544545 Stream.EmitRecord(bitc::METADATA_STRING, Record, MDSAbbrev);
545546 Record.clear();
546 } else if (const NamedMDNode *NMD = dyn_cast(Vals[i].first)) {
547 if (!StartedMetadataBlock) {
548 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
549 StartedMetadataBlock = true;
550 }
551
552 // Write name.
553 StringRef Str = NMD->getName();
554 for (unsigned i = 0, e = Str.size(); i != e; ++i)
555 Record.push_back(Str[i]);
556 Stream.EmitRecord(bitc::METADATA_NAME, Record, 0/*TODO*/);
557 Record.clear();
558
559 // Write named metadata operands.
560 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
561 Record.push_back(VE.getValueID(NMD->getOperand(i)));
562 Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
563 Record.clear();
564 }
547 }
548 }
549
550 // Write named metadata.
551 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
552 E = M->named_metadata_end(); I != E; ++I) {
553 const NamedMDNode *NMD = I;
554 if (!StartedMetadataBlock) {
555 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
556 StartedMetadataBlock = true;
557 }
558
559 // Write name.
560 StringRef Str = NMD->getName();
561 for (unsigned i = 0, e = Str.size(); i != e; ++i)
562 Record.push_back(Str[i]);
563 Stream.EmitRecord(bitc::METADATA_NAME, Record, 0/*TODO*/);
564 Record.clear();
565
566 // Write named metadata operands.
567 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
568 Record.push_back(VE.getValueID(NMD->getOperand(i)));
569 Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
570 Record.clear();
565571 }
566572
567573 if (StartedMetadataBlock)
15291535 WriteModuleConstants(VE, Stream);
15301536
15311537 // Emit metadata.
1532 WriteModuleMetadata(VE, Stream);
1538 WriteModuleMetadata(M, VE, Stream);
15331539
15341540 // Emit function bodies.
15351541 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
7474 // Insert constants and metadata that are named at module level into the slot
7575 // pool so that the module symbol table can refer to them...
7676 EnumerateValueSymbolTable(M->getValueSymbolTable());
77 EnumerateMDSymbolTable(M->getMDSymbolTable());
77 EnumerateNamedMetadata(M);
7878
7979 SmallVector, 8> MDs;
8080
206206 EnumerateValue(VI->getValue());
207207 }
208208
209 /// EnumerateMDSymbolTable - Insert all of the values in the specified metadata
210 /// table.
211 void ValueEnumerator::EnumerateMDSymbolTable(const MDSymbolTable &MST) {
212 for (MDSymbolTable::const_iterator MI = MST.begin(), ME = MST.end();
213 MI != ME; ++MI)
214 EnumerateValue(MI->getValue());
209 /// EnumerateNamedMetadata - Insert all of the values referenced by
210 /// named metadata in the specified module.
211 void ValueEnumerator::EnumerateNamedMetadata(const Module *M) {
212 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
213 E = M->named_metadata_end(); I != E; ++I)
214 EnumerateNamedMDNode(I);
215215 }
216216
217217 void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
218 // Check to see if it's already in!
219 unsigned &MDValueID = MDValueMap[MD];
220 if (MDValueID) {
221 // Increment use count.
222 MDValues[MDValueID-1].second++;
223 return;
224 }
225
226 // Enumerate the type of this value.
227 EnumerateType(MD->getType());
228
229218 for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
230219 if (MDNode *E = MD->getOperand(i))
231220 EnumerateValue(E);
232 MDValues.push_back(std::make_pair(MD, 1U));
233 MDValueMap[MD] = Values.size();
234221 }
235222
236223 void ValueEnumerator::EnumerateMetadata(const Value *MD) {
271258 assert(!V->getType()->isVoidTy() && "Can't insert void values!");
272259 if (isa(V) || isa(V))
273260 return EnumerateMetadata(V);
274 else if (const NamedMDNode *NMD = dyn_cast(V))
275 return EnumerateNamedMDNode(NMD);
276261
277262 // Check to see if it's already in!
278263 unsigned &ValueID = ValueMap[V];
140140
141141 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
142142 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
143 void EnumerateMDSymbolTable(const MDSymbolTable &ST);
143 void EnumerateNamedMetadata(const Module *M);
144144 };
145145
146146 } // End llvm namespace
544544 for (Module::const_named_metadata_iterator I = Src->named_metadata_begin(),
545545 E = Src->named_metadata_end(); I != E; ++I) {
546546 const NamedMDNode *SrcNMD = I;
547 NamedMDNode *DestNMD = Dest->getNamedMetadata(SrcNMD->getName());
548 if (!DestNMD)
549 NamedMDNode::Create(SrcNMD, Dest);
550 else {
551 // Add Src elements into Dest node.
552 for (unsigned i = 0, e = SrcNMD->getNumOperands(); i != e; ++i)
553 DestNMD->addOperand(SrcNMD->getOperand(i));
554 }
547 NamedMDNode *DestNMD = Dest->getOrInsertNamedMetadata(SrcNMD->getName());
548 // Add Src elements into Dest node.
549 for (unsigned i = 0, e = SrcNMD->getNumOperands(); i != e; ++i)
550 DestNMD->addOperand(SrcNMD->getOperand(i));
555551 }
556552 }
557553
126126 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
127127 E = M->named_metadata_end(); I != E; ++I) {
128128 const NamedMDNode &NMD = *I;
129 SmallVector MDs;
129 NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
130130 for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
131 MDs.push_back(cast(MapValue(NMD.getOperand(i), VMap)));
132 NamedMDNode::Create(New->getContext(), NMD.getName(),
133 MDs.data(), MDs.size(), New);
131 NewNMD->addOperand(cast(MapValue(NMD.getOperand(i), VMap)));
134132 }
135133
136134 // Update metadata attach with instructions.
6262
6363 if (const GlobalValue *GV = dyn_cast(V))
6464 return GV->getParent();
65 if (const NamedMDNode *NMD = dyn_cast(V))
66 return NMD->getParent();
6765 return 0;
6866 }
6967
21102108 W.printModule(this);
21112109 }
21122110
2111 void NamedMDNode::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2112 SlotTracker SlotTable(getParent());
2113 formatted_raw_ostream OS(ROS);
2114 AssemblyWriter W(OS, SlotTable, getParent(), AAW);
2115 W.printNamedMDNode(this);
2116 }
2117
21132118 void Type::print(raw_ostream &OS) const {
21142119 if (this == 0) {
21152120 OS << "";
21472152 SlotTracker SlotTable(F);
21482153 AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
21492154 W.printMDNodeBody(N);
2150 } else if (const NamedMDNode *N = dyn_cast(this)) {
2151 SlotTracker SlotTable(N->getParent());
2152 AssemblyWriter W(OS, SlotTable, N->getParent(), AAW);
2153 W.printNamedMDNode(N);
21542155 } else if (const Constant *C = dyn_cast(this)) {
21552156 TypePrinting TypePrinter;
21562157 TypePrinter.print(C->getType(), OS);
329329 // NamedMDNode implementation.
330330 //
331331
332 // SymbolTableListTraits specialization for MDSymbolTable.
333 void ilist_traits::addNodeToList(NamedMDNode *N) {
334 assert(N->getParent() == 0 && "Value already in a container!!");
335 Module *Owner = getListOwner();
336 N->setParent(Owner);
337 MDSymbolTable &ST = Owner->getMDSymbolTable();
338 ST.insert(N->getName(), N);
339 }
340
341 void ilist_traits::removeNodeFromList(NamedMDNode *N) {
342 N->setParent(0);
343 Module *Owner = getListOwner();
344 MDSymbolTable &ST = Owner->getMDSymbolTable();
345 ST.remove(N->getName());
346 }
347
348332 static SmallVector, 4> &getNMDOps(void *Operands) {
349333 return *(SmallVector, 4>*)Operands;
350334 }
351335
352 NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
353 MDNode *const *MDs,
354 unsigned NumMDs, Module *ParentModule)
355 : Value(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
356 setName(N);
357 Operands = new SmallVector, 4>();
358
359 SmallVector, 4> &Node = getNMDOps(Operands);
360 for (unsigned i = 0; i != NumMDs; ++i)
361 Node.push_back(TrackingVH(MDs[i]));
362
363 if (ParentModule)
364 ParentModule->getNamedMDList().push_back(this);
365 }
366
367 NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
368 assert(NMD && "Invalid source NamedMDNode!");
369 SmallVector Elems;
370 Elems.reserve(NMD->getNumOperands());
371
372 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
373 Elems.push_back(NMD->getOperand(i));
374 return new NamedMDNode(NMD->getContext(), NMD->getName().data(),
375 Elems.data(), Elems.size(), M);
336 NamedMDNode::NamedMDNode(const Twine &N)
337 : Name(N.str()), Parent(0),
338 Operands(new SmallVector, 4>()) {
376339 }
377340
378341 NamedMDNode::~NamedMDNode() {
399362 /// eraseFromParent - Drop all references and remove the node from parent
400363 /// module.
401364 void NamedMDNode::eraseFromParent() {
402 getParent()->getNamedMDList().erase(this);
365 getParent()->eraseNamedMetadata(this);
403366 }
404367
405368 /// dropAllReferences - Remove all uses and clear node vector.
406369 void NamedMDNode::dropAllReferences() {
407370 getNMDOps(Operands).clear();
408 }
409
410 /// setName - Set the name of this named metadata.
411 void NamedMDNode::setName(const Twine &NewName) {
412 assert (!NewName.isTriviallyEmpty() && "Invalid named metadata name!");
413
414 SmallString<256> NameData;
415 StringRef NameRef = NewName.toStringRef(NameData);
416
417 // Name isn't changing?
418 if (getName() == NameRef)
419 return;
420
421 Name = NameRef.str();
422 if (Parent)
423 Parent->getMDSymbolTable().insert(NameRef, this);
424371 }
425372
426373 /// getName - Return a constant reference to this named metadata's name.
6060 : Context(C), Materializer(NULL), ModuleID(MID), DataLayout("") {
6161 ValSymTab = new ValueSymbolTable();
6262 TypeSymTab = new TypeSymbolTable();
63 NamedMDSymTab = new MDSymbolTable();
63 NamedMDSymTab = new StringMap();
6464 }
6565
6666 Module::~Module() {
7272 NamedMDList.clear();
7373 delete ValSymTab;
7474 delete TypeSymTab;
75 delete NamedMDSymTab;
75 delete static_cast *>(NamedMDSymTab);
7676 }
7777
7878 /// Target endian information...
315315 NamedMDNode *Module::getNamedMetadata(const Twine &Name) const {
316316 SmallString<256> NameData;
317317 StringRef NameRef = Name.toStringRef(NameData);
318 return NamedMDSymTab->lookup(NameRef);
318 return static_cast *>(NamedMDSymTab)->lookup(NameRef);
319319 }
320320
321321 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
322322 /// with the specified name. This method returns a new NamedMDNode if a
323323 /// NamedMDNode with the specified name is not found.
324324 NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
325 NamedMDNode *NMD = NamedMDSymTab->lookup(Name);
326 if (!NMD)
327 NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this);
325 NamedMDNode *&NMD =
326 (*static_cast *>(NamedMDSymTab))[Name];
327 if (!NMD) {
328 NMD = new NamedMDNode(Name);
329 NMD->setParent(this);
330 NamedMDList.push_back(NMD);
331 }
328332 return NMD;
333 }
334
335 void Module::eraseNamedMetadata(NamedMDNode *NMD) {
336 static_cast *>(NamedMDSymTab)->erase(NMD->getName());
337 NamedMDList.erase(NMD);
329338 }
330339
331340 //===----------------------------------------------------------------------===//
138138 } else if (Argument *A = dyn_cast(V)) {
139139 if (Function *P = A->getParent())
140140 ST = &P->getValueSymbolTable();
141 } else if (NamedMDNode *N = dyn_cast(V)) {
142 if (Module *P = N->getParent()) {
143 ST = &P->getValueSymbolTable();
144 }
145141 } else if (isa(V))
146142 return true;
147143 else {
114114 //DEBUG(dbgs() << "\n");
115115 }
116116 }
117
118 MDSymbolTable::~MDSymbolTable() { }
503503 if (!MD)
504504 continue;
505505
506 Assert2(!MD->isFunctionLocal(),
507 "Named metadata operand cannot be function local!", &NMD, MD);
506 Assert1(!MD->isFunctionLocal(),
507 "Named metadata operand cannot be function local!", MD);
508508 visitMDNode(*MD, 0);
509509 }
510510 }
129129 MDNode *n = MDNode::get(Context, &V, 1);
130130 MDNode *n2 = MDNode::get(Context, &V2, 1);
131131
132 MDNode *Nodes[2] = { n, n2 };
133
134132 Module M("MyModule", Context);
135133 const char *Name = "llvm.NMD1";
136 NamedMDNode *NMD = NamedMDNode::Create(Context, Name, &Nodes[0], 2, &M);
134 NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name);
135 NMD->addOperand(n);
136 NMD->addOperand(n2);
137
137138 std::string Str;
138139 raw_string_ostream oss(Str);
139140 NMD->print(oss);