[llvm-commits] [llvm] r92224 - in /llvm/trunk: include/llvm/Metadata.h lib/Bitcode/Writer/BitcodeWriter.cpp lib/VMCore/AsmWriter.cpp lib/VMCore/Metadata.cpp

Chris Lattner sabre at nondot.org
Mon Dec 28 12:10:43 PST 2009


Author: lattner
Date: Mon Dec 28 14:10:43 2009
New Revision: 92224

URL: http://llvm.org/viewvc/llvm-project?rev=92224&view=rev
Log:
rename getHandlerNames to getMDKindNames, simplify its interface
and simplify all the clients that use it.

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

Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92224&r1=92223&r2=92224&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Mon Dec 28 14:10:43 2009
@@ -244,9 +244,9 @@
   /// the same metadata to In2.
   void copyMD(Instruction *In1, Instruction *In2);
 
-  /// getHandlerNames - Populate client supplied smallvector using custom
-  /// metadata name and ID.
-  void getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&) const;
+  /// getMDKindNames - Populate client supplied SmallVector with the name for
+  /// each custom metadata ID.   ID #0 is not used, so it is filled in as empty.
+  void getMDKindNames(SmallVectorImpl<StringRef> &) const;
 
   /// ValueIsDeleted - This handler is used to update metadata store
   /// when a value is deleted.

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=92224&r1=92223&r2=92224&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Dec 28 14:10:43 2009
@@ -593,35 +593,30 @@
     Stream.ExitBlock();
 }
 
-static void WriteModuleMetadataStore(const Module *M,
-                                     const ValueEnumerator &VE,
-                                     BitstreamWriter &Stream) {
-
-  bool StartedMetadataBlock = false;
+static void WriteModuleMetadataStore(const Module *M, BitstreamWriter &Stream) {
   SmallVector<uint64_t, 64> Record;
 
   // Write metadata kinds
   // METADATA_KIND - [n x [id, name]]
   MetadataContext &TheMetadata = M->getContext().getMetadata();
-  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)  {
-      Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
-      StartedMetadataBlock = true;
-    }
+  SmallVector<StringRef, 4> Names;
+  TheMetadata.getMDKindNames(Names);
+  
+  assert(Names[0] == "" && "MDKind #0 is invalid");
+  if (Names.size() == 1) return;
+
+  Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+  
+  for (unsigned MDKindID = 1, e = Names.size(); MDKindID != e; ++MDKindID) {
+    Record.push_back(MDKindID);
+    StringRef KName = Names[MDKindID];
+    Record.append(KName.begin(), KName.end());
+    
     Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
     Record.clear();
   }
 
-  if (StartedMetadataBlock)
-    Stream.ExitBlock();
+  Stream.ExitBlock();
 }
 
 static void WriteConstants(unsigned FirstVal, unsigned LastVal,
@@ -1466,7 +1461,7 @@
       WriteFunction(*I, VE, Stream);
 
   // Emit metadata.
-  WriteModuleMetadataStore(M, VE, Stream);
+  WriteModuleMetadataStore(M, Stream);
 
   // Emit the type symbol table information.
   WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);

Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=92224&r1=92223&r2=92224&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Mon Dec 28 14:10:43 2009
@@ -1330,8 +1330,8 @@
   TypePrinting TypePrinter;
   AssemblyAnnotationWriter *AnnotationWriter;
   std::vector<const Type*> NumberedTypes;
-  DenseMap<unsigned, StringRef> MDNames;
-
+  SmallVector<StringRef, 8> MDNames;
+  
 public:
   inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
                         const Module *M,
@@ -1339,16 +1339,8 @@
     : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
     AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
     // FIXME: Provide MDPrinter
-    if (M) {
-      MetadataContext &TheMetadata = M->getContext().getMetadata();
-      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;
-      }
-    }
+    if (M)
+      M->getContext().getMetadata().getMDKindNames(MDNames);
   }
 
   void write(const Module *M) { printModule(M); }
@@ -2075,14 +2067,14 @@
     }
   }
 
-  // Print post operand alignment for load/store
+  // Print post operand alignment for load/store.
   if (isa<LoadInst>(I) && cast<LoadInst>(I).getAlignment()) {
     Out << ", align " << cast<LoadInst>(I).getAlignment();
   } else if (isa<StoreInst>(I) && cast<StoreInst>(I).getAlignment()) {
     Out << ", align " << cast<StoreInst>(I).getAlignment();
   }
 
-  // Print Metadata info
+  // Print Metadata info.
   if (!MDNames.empty()) {
     MetadataContext &TheMetadata = I.getContext().getMetadata();
     typedef SmallVector<std::pair<unsigned, MDNode*>, 2> MDMapTy;

Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92224&r1=92223&r2=92224&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Dec 28 14:10:43 2009
@@ -290,9 +290,9 @@
   /// the same metadata to In2.
   void copyMD(Instruction *In1, Instruction *In2);
 
-  /// getHandlerNames - Populate client-supplied smallvector using custom
+  /// getMDKindNames - Populate client-supplied smallvector using custom
   /// metadata name and ID.
-  void getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&) const;
+  void getMDKindNames(SmallVectorImpl<StringRef> &) const;
 
   /// ValueIsDeleted - This handler is used to update metadata store
   /// when a value is deleted.
@@ -415,12 +415,13 @@
 /// getHandlerNames - Populate client supplied smallvector using custome
 /// metadata name and ID.
 void MetadataContextImpl::
-getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&Names) const {
-  Names.resize(MDHandlerNames.size());
+getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
+  Names.resize(MDHandlerNames.size()+1);
+  Names[0] = "";
   for (StringMap<unsigned>::const_iterator I = MDHandlerNames.begin(),
          E = MDHandlerNames.end(); I != E; ++I) 
     // MD Handlers are numbered from 1.
-    Names[I->second - 1] = std::make_pair(I->second, I->first());
+    Names[I->second] = I->first();
 }
 
 /// ValueIsCloned - This handler is used to update metadata store
@@ -520,9 +521,8 @@
 
 /// getHandlerNames - Populate client supplied smallvector using custome
 /// metadata name and ID.
-void MetadataContext::
-getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&N) const {
-  pImpl->getHandlerNames(N);
+void MetadataContext::getMDKindNames(SmallVectorImpl<StringRef> &N) const {
+  pImpl->getMDKindNames(N);
 }
 
 /// ValueIsDeleted - This handler is used to update metadata store





More information about the llvm-commits mailing list