Fix getHandlerNames() interface. Now it populate clinet supplied small vector with...
authorDevang Patel <dpatel@apple.com>
Thu, 22 Oct 2009 01:01:24 +0000 (01:01 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 22 Oct 2009 01:01:24 +0000 (01:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84820 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Metadata.h
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Metadata.cpp

index 91ab55b175f3efac8bc70b796c428de4d59118ee..a9c242c5085977fa7dcd2f6918538f266883d78d 100644 (file)
@@ -287,7 +287,7 @@ public:
 
   /// getHandlerNames - Get handler names. This is used by bitcode
   /// writer.
-  const StringMap<unsigned> *getHandlerNames();
+  void getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&N) const;
 
   /// ValueIsDeleted - This handler is used to update metadata store
   /// when a value is deleted.
index a8c1ef7c728fc3c91aa5e63cdb2eb0dbb939ffa2..947b8958a12d0d1e5108a63a25ddf90030392818 100644 (file)
@@ -602,11 +602,13 @@ static void WriteModuleMetadataStore(const Module *M,
   // Write metadata kinds
   // METADATA_KIND - [n x [id, name]]
   MetadataContext &TheMetadata = M->getContext().getMetadata();
-  const StringMap<unsigned> *Kinds = TheMetadata.getHandlerNames();
-  for (StringMap<unsigned>::const_iterator
-         I = Kinds->begin(), E = Kinds->end(); I != E; ++I) {
-    Record.push_back(I->second);
-    StringRef KName = I->first();
+  SmallVector<std::pair<unsigned, StringRef>, 4> Names;
+  TheMetadata.getHandlerNames(Names);
+  for (SmallVector<std::pair<unsigned, StringRef>, 4>::iterator 
+         I = Names.begin(),
+         E = Names.end(); I != E; ++I) {
+    Record.push_back(I->first);
+    StringRef KName = I->second;
     for (unsigned i = 0, e = KName.size(); i != e; ++i)
       Record.push_back(KName[i]);
     if (!StartedMetadataBlock)  {
index 6ee2ece0f0da0d3e7334964d1b8fd9fdd1c3c821..e6ed81ede02c2b2a055fd04cb52e34dd0930796c 100644 (file)
@@ -1295,7 +1295,7 @@ class AssemblyWriter {
   TypePrinting TypePrinter;
   AssemblyAnnotationWriter *AnnotationWriter;
   std::vector<const Type*> NumberedTypes;
-  DenseMap<unsigned, const char *> MDNames;
+  DenseMap<unsigned, StringRef> MDNames;
 
 public:
   inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
@@ -1306,11 +1306,12 @@ public:
     // FIXME: Provide MDPrinter
     if (M) {
       MetadataContext &TheMetadata = M->getContext().getMetadata();
-      const StringMap<unsigned> *Names = TheMetadata.getHandlerNames();
-      for (StringMapConstIterator<unsigned> I = Names->begin(),
-             E = Names->end(); I != E; ++I) {
-        const StringMapEntry<unsigned> &Entry = *I;
-        MDNames[I->second] = Entry.getKeyData();
+      SmallVector<std::pair<unsigned, StringRef>, 4> Names;
+      TheMetadata.getHandlerNames(Names);
+      for (SmallVector<std::pair<unsigned, StringRef>, 4>::iterator 
+             I = Names.begin(),
+             E = Names.end(); I != E; ++I) {
+      MDNames[I->first] = I->second;
       }
     }
   }
index 3e3ea7725a51b5cdab3ad5f40552475201425088..f45114c6ff18df8ca9cdea9de63b15bcd38404f6 100644 (file)
@@ -305,9 +305,12 @@ MetadataContext::getMDs(const Instruction *Inst) {
 }
 
 /// getHandlerNames - Get handler names. This is used by bitcode
-/// writer.
-const StringMap<unsigned> *MetadataContext::getHandlerNames() {
-  return &MDHandlerNames;
+/// writer and aswm writer.
+void MetadataContext::
+getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&Names) const {
+  for (StringMap<unsigned>::const_iterator I = MDHandlerNames.begin(),
+         E = MDHandlerNames.end(); I != E; ++I) 
+    Names.push_back(std::make_pair(I->second, I->first()));
 }
 
 /// ValueIsCloned - This handler is used to update metadata store