From ce6a1c97569ce65a60340b20e65abd0787969942 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 22 Oct 2009 01:01:24 +0000 Subject: [PATCH 1/1] Fix getHandlerNames() interface. Now it populate clinet supplied small vector with handler names. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84820 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Metadata.h | 2 +- lib/Bitcode/Writer/BitcodeWriter.cpp | 12 +++++++----- lib/VMCore/AsmWriter.cpp | 13 +++++++------ lib/VMCore/Metadata.cpp | 9 ++++++--- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 91ab55b175f..a9c242c5085 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -287,7 +287,7 @@ public: /// getHandlerNames - Get handler names. This is used by bitcode /// writer. - const StringMap *getHandlerNames(); + void getHandlerNames(SmallVectorImpl >&N) const; /// ValueIsDeleted - This handler is used to update metadata store /// when a value is deleted. diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index a8c1ef7c728..947b8958a12 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -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 *Kinds = TheMetadata.getHandlerNames(); - for (StringMap::const_iterator - I = Kinds->begin(), E = Kinds->end(); I != E; ++I) { - Record.push_back(I->second); - StringRef KName = I->first(); + SmallVector, 4> Names; + TheMetadata.getHandlerNames(Names); + for (SmallVector, 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) { diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 6ee2ece0f0d..e6ed81ede02 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1295,7 +1295,7 @@ class AssemblyWriter { TypePrinting TypePrinter; AssemblyAnnotationWriter *AnnotationWriter; std::vector NumberedTypes; - DenseMap MDNames; + DenseMap 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 *Names = TheMetadata.getHandlerNames(); - for (StringMapConstIterator I = Names->begin(), - E = Names->end(); I != E; ++I) { - const StringMapEntry &Entry = *I; - MDNames[I->second] = Entry.getKeyData(); + SmallVector, 4> Names; + TheMetadata.getHandlerNames(Names); + for (SmallVector, 4>::iterator + I = Names.begin(), + E = Names.end(); I != E; ++I) { + MDNames[I->first] = I->second; } } } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 3e3ea7725a5..f45114c6ff1 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -305,9 +305,12 @@ MetadataContext::getMDs(const Instruction *Inst) { } /// getHandlerNames - Get handler names. This is used by bitcode -/// writer. -const StringMap *MetadataContext::getHandlerNames() { - return &MDHandlerNames; +/// writer and aswm writer. +void MetadataContext:: +getHandlerNames(SmallVectorImpl >&Names) const { + for (StringMap::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 -- 2.34.1