AsmWriter: Only collect attachment names once per module
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 24 Apr 2015 21:03:05 +0000 (21:03 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 24 Apr 2015 21:03:05 +0000 (21:03 +0000)
Collect metadata names once per `AssemblyWriter` instead of every time
we need to print some attachments.  Just a drive-by; this caught my eye
while I was refactoring the code in r235772.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235774 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/AsmWriter.cpp

index 7d0422d8c0af9f3370139d6a5815a6e8190838f4..54a370d08fb334094033527b32fbdc22d857e20d 100644 (file)
@@ -1943,6 +1943,7 @@ class AssemblyWriter {
   SetVector<const Comdat *> Comdats;
   bool ShouldPreserveUseListOrder;
   UseListOrderStack UseListOrders;
+  SmallVector<StringRef, 8> MDNames;
 
 public:
   /// Construct an AssemblyWriter with an external SlotTracker
@@ -2967,8 +2968,9 @@ void AssemblyWriter::printMetadataAttachments(
   if (MDs.empty())
     return;
 
-  SmallVector<StringRef, 8> MDNames;
-  TheModule->getMDKindNames(MDNames);
+  if (MDNames.empty())
+    TheModule->getMDKindNames(MDNames);
+
   for (const auto &I : MDs) {
     unsigned Kind = I.first;
     if (Kind < MDNames.size()) {