[llvm-commits] [llvm] r77144 - in /llvm/trunk: include/llvm/Target/ELFTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/Sparc/SparcTargetAsmInfo.cpp lib/Target/Sparc/SparcTargetAsmInfo.h lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.h

Chris Lattner sabre at nondot.org
Sun Jul 26 00:34:24 PDT 2009


Author: lattner
Date: Sun Jul 26 02:33:58 2009
New Revision: 77144

URL: http://llvm.org/viewvc/llvm-project?rev=77144&view=rev
Log:
remove a densemap from TargetAsmInfo that was uniquing the targetflags strings,
just use a smallstring instead.

Modified:
    llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp
    llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h

Modified: llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Sun Jul 26 02:33:58 2009
@@ -41,7 +41,8 @@
     
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
                                                   SectionKind Kind) const;
-    virtual std::string printSectionFlags(unsigned flags) const;
+    virtual void getSectionFlags(unsigned Flags,
+                                 SmallVectorImpl<char> &Str) const;
 
     const Section *DataRelSection;
     const Section *DataRelLocalSection;

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun Jul 26 02:33:58 2009
@@ -16,12 +16,13 @@
 #ifndef LLVM_TARGET_ASM_INFO_H
 #define LLVM_TARGET_ASM_INFO_H
 
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/DataTypes.h"
 #include <string>
 
 namespace llvm {
+  template <typename T> class SmallVectorImpl;
+  
   // DWARF encoding query type
   namespace DwarfEncoding {
     enum Target {
@@ -235,8 +236,6 @@
       static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
       static bool isPod() { return true; }
     };
-
-    typedef DenseMap<unsigned, std::string, KeyInfo> FlagsStringsMapType;
   }
 
   class TargetMachine;
@@ -269,7 +268,6 @@
   class TargetAsmInfo {
   private:
     mutable StringMap<Section> Sections;
-    mutable SectionFlags::FlagsStringsMapType FlagsStrings;
   protected:
     /// TM - The current TargetMachine.
     const TargetMachine &TM;
@@ -746,8 +744,11 @@
       return 0;
     }
     
-    const std::string &getSectionFlags(unsigned Flags) const;
-    virtual std::string printSectionFlags(unsigned flags) const { return ""; }
+    /// Turn the specified flags into a string that can be printed to the
+    /// assembly file.
+    virtual void getSectionFlags(unsigned Flags,
+                                 SmallVectorImpl<char> &Str) const {
+    }
 
 // FIXME: Eliminate this.
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Jul 26 02:33:58 2009
@@ -135,12 +135,16 @@
     // If section is named we need to switch into it via special '.section'
     // directive and also append funky flags. Otherwise - section name is just
     // some magic assembler directive.
-    if (NS->hasFlag(SectionFlags::Named))
+    if (NS->hasFlag(SectionFlags::Named)) {
       O << TAI->getSwitchToSectionDirective()
-        << CurrentSection
-        << TAI->getSectionFlags(NS->getFlags());
-    else
+        << CurrentSection;
+      
+      SmallString<32> FlagsStr;
+      TAI->getSectionFlags(NS->getFlags(), FlagsStr);
+      O << FlagsStr.c_str();
+    } else {
       O << CurrentSection;
+    }
     O << TAI->getDataSectionStartSuffix() << '\n';
   }
 

Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Sun Jul 26 02:33:58 2009
@@ -168,38 +168,44 @@
   return getReadOnlySection();
 }
 
-std::string ELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
-  std::string Flags = ",\"";
+void ELFTargetAsmInfo::getSectionFlags(unsigned Flags,
+                                       SmallVectorImpl<char> &Str) const {
+  Str.push_back(',');
+  Str.push_back('"');
+  
+  if (!(Flags & SectionFlags::Debug))
+    Str.push_back('a');
+  if (Flags & SectionFlags::Code)
+    Str.push_back('x');
+  if (Flags & SectionFlags::Writable)
+    Str.push_back('w');
+  if (Flags & SectionFlags::Mergeable)
+    Str.push_back('M');
+  if (Flags & SectionFlags::Strings)
+    Str.push_back('S');
+  if (Flags & SectionFlags::TLS)
+    Str.push_back('T');
 
-  if (!(flags & SectionFlags::Debug))
-    Flags += 'a';
-  if (flags & SectionFlags::Code)
-    Flags += 'x';
-  if (flags & SectionFlags::Writable)
-    Flags += 'w';
-  if (flags & SectionFlags::Mergeable)
-    Flags += 'M';
-  if (flags & SectionFlags::Strings)
-    Flags += 'S';
-  if (flags & SectionFlags::TLS)
-    Flags += 'T';
-
-  Flags += "\",";
+  Str.push_back('"');
+  Str.push_back(',');
 
   // If comment string is '@', e.g. as on ARM - use '%' instead
   if (strcmp(CommentString, "@") == 0)
-    Flags += '%';
+    Str.push_back('%');
   else
-    Flags += '@';
+    Str.push_back('@');
 
-  // FIXME: There can be exceptions here
-  if (flags & SectionFlags::BSS)
-    Flags += "nobits";
+  const char *KindStr;
+  if (Flags & SectionFlags::BSS)
+    KindStr = "nobits";
   else
-    Flags += "progbits";
-
-  if (unsigned entitySize = SectionFlags::getEntitySize(flags))
-    Flags += "," + utostr(entitySize);
-
-  return Flags;
+    KindStr = "progbits";
+  
+  Str.append(KindStr, KindStr+strlen(KindStr));
+
+  if (unsigned entitySize = SectionFlags::getEntitySize(Flags)) {
+    Str.push_back(',');
+    std::string Size = utostr(entitySize);
+    Str.append(Size.begin(), Size.end());
+  }
 }

Modified: llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp Sun Jul 26 02:33:58 2009
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "SparcTargetAsmInfo.h"
-
+#include "llvm/ADT/SmallVector.h"
 using namespace llvm;
 
 SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const TargetMachine &TM):
@@ -32,19 +32,22 @@
                                  /* Override */ true);
 }
 
-std::string SparcELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
-  if (flags & SectionFlags::Mergeable)
-    return ELFTargetAsmInfo::printSectionFlags(flags);
-
-  std::string Flags;
-  if (!(flags & SectionFlags::Debug))
-    Flags += ",#alloc";
-  if (flags & SectionFlags::Code)
-    Flags += ",#execinstr";
-  if (flags & SectionFlags::Writable)
-    Flags += ",#write";
-  if (flags & SectionFlags::TLS)
-    Flags += ",#tls";
 
-  return Flags;
+void SparcELFTargetAsmInfo::getSectionFlags(unsigned Flags,
+                                            SmallVectorImpl<char> &Str) const {
+  if (Flags & SectionFlags::Mergeable)
+    return ELFTargetAsmInfo::getSectionFlags(Flags, Str);
+
+  // FIXME: Inefficient.
+  std::string Res;
+  if (!(Flags & SectionFlags::Debug))
+    Res += ",#alloc";
+  if (Flags & SectionFlags::Code)
+    Res += ",#execinstr";
+  if (Flags & SectionFlags::Writable)
+    Res += ",#write";
+  if (Flags & SectionFlags::TLS)
+    Res += ",#tls";
+
+  Str.append(Res.begin(), Res.end());
 }

Modified: llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h Sun Jul 26 02:33:58 2009
@@ -25,7 +25,9 @@
   struct SparcELFTargetAsmInfo : public ELFTargetAsmInfo {
     explicit SparcELFTargetAsmInfo(const TargetMachine &TM);
 
-    std::string printSectionFlags(unsigned flags) const;
+    virtual void getSectionFlags(unsigned Flags,
+                                 SmallVectorImpl<char> &Str) const;
+
   };
 
 } // namespace llvm

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun Jul 26 02:33:58 2009
@@ -416,19 +416,6 @@
   return &S;
 }
 
-const std::string&
-TargetAsmInfo::getSectionFlags(unsigned Flags) const {
-  SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
-
-  // We didn't print these flags yet, print and save them to map. This reduces
-  // amount of heap trashing due to std::string construction / concatenation.
-  if (I == FlagsStrings.end())
-    I = FlagsStrings.insert(std::make_pair(Flags,
-                                           printSectionFlags(Flags))).first;
-
-  return I->second;
-}
-
 unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
   unsigned Size = 0;
   do {

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Sun Jul 26 02:33:58 2009
@@ -274,17 +274,18 @@
   return ".rdata$linkonce";
 }
 
-std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
-  std::string Flags = ",\"";
 
-  if (flags & SectionFlags::Code)
-    Flags += 'x';
-  if (flags & SectionFlags::Writable)
-    Flags += 'w';
+void X86COFFTargetAsmInfo::getSectionFlags(unsigned Flags,
+                                           SmallVectorImpl<char> &Str) const {
+  // FIXME: Inefficient.
+  std::string Res = ",\"";
+  if (Flags & SectionFlags::Code)
+    Res += 'x';
+  if (Flags & SectionFlags::Writable)
+    Res += 'w';
+  Res += "\"";
 
-  Flags += "\"";
-
-  return Flags;
+  Str.append(Res.begin(), Res.end());
 }
 
 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h?rev=77144&r1=77143&r2=77144&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Sun Jul 26 02:33:58 2009
@@ -55,7 +55,9 @@
                                            bool Global) const;
     virtual const char *
     getSectionPrefixForUniqueGlobal(SectionKind kind) const;
-    virtual std::string printSectionFlags(unsigned flags) const;
+    
+    virtual void getSectionFlags(unsigned Flags,
+                                 SmallVectorImpl<char> &Str) const;
   };
 
   struct X86WinTargetAsmInfo : public X86GenericTargetAsmInfo {





More information about the llvm-commits mailing list