[llvm-commits] [llvm] r53215 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h lib/CodeGen/AsmPrinter.cpp lib/Target/X86/X86ATTAsmPrinter.cpp lib/Target/X86/X86ATTAsmPrinter.h

Evan Cheng evan.cheng at apple.com
Mon Jul 7 17:55:59 PDT 2008


Author: evancheng
Date: Mon Jul  7 19:55:58 2008
New Revision: 53215

URL: http://llvm.org/viewvc/llvm-project?rev=53215&view=rev
Log:
Avoid unnecessary string construction during asm printing.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.h

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=53215&r1=53214&r2=53215&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Jul  7 19:55:58 2008
@@ -351,6 +351,7 @@
     /// printSuffixedName - This prints a name with preceding 
     /// getPrivateGlobalPrefix and the specified suffix, handling quoted names
     /// correctly.
+    void printSuffixedName(const char *Name, const char* Suffix);
     void printSuffixedName(std::string &Name, const char* Suffix);
 
   private:

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter.cpp Mon Jul  7 19:55:58 2008
@@ -1377,7 +1377,7 @@
     O << ':';
   if (printComment && MBB->getBasicBlock())
     O << '\t' << TAI->getCommentString() << ' '
-      << MBB->getBasicBlock()->getName();
+      << MBB->getBasicBlock()->getNameStart();
 }
 
 /// printPICJumpTableSetLabel - This method prints a set label for the
@@ -1445,10 +1445,14 @@
   }
 }
 
-void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) {
+void AsmPrinter::printSuffixedName(const char *Name, const char* Suffix) {
   if (Name[0]=='\"')
     O << '\"' << TAI->getPrivateGlobalPrefix() << 
-         Name.substr(1, Name.length()-2) << Suffix << '\"';
+         Name[1] << Suffix << '\"';
   else
     O << TAI->getPrivateGlobalPrefix() << Name << Suffix;
 }
+
+void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) {
+  printSuffixedName(Name.c_str(), Suffix);
+}

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp Mon Jul  7 19:55:58 2008
@@ -974,6 +974,16 @@
   EmitGlobalConstant(C);
 }
 
+/// printGVStub - Print stub for a global value.
+///
+void X86ATTAsmPrinter::printGVStub(const char *GV, const char *Prefix) {
+  if (Prefix) O << Prefix;
+  printSuffixedName(GV, "$non_lazy_ptr");
+  O << ":\n\t.indirect_symbol ";
+  if (Prefix) O << Prefix;
+  O << GV << "\n\t.long\t0\n";
+}
+
 
 bool X86ATTAsmPrinter::doFinalization(Module &M) {
   // Print out module-level global variables here.
@@ -1012,7 +1022,7 @@
          i != e; ++i, ++j) {
       SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
                           "self_modifying_code+pure_instructions,5", 0);
-      std::string p = i->getKeyData();
+      const char *p = i->getKeyData();
       printSuffixedName(p, "$stub");
       O << ":\n"
            "\t.indirect_symbol " << p << "\n"
@@ -1021,28 +1031,32 @@
 
     O << '\n';
 
+    // Print global value stubs.
+    bool InStubSection = false;
     if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
       // Add the (possibly multiple) personalities to the set of global values.
       // Only referenced functions get into the Personalities list.
       const std::vector<Function *>& Personalities = MMI->getPersonalities();
-
       for (std::vector<Function *>::const_iterator I = Personalities.begin(),
-             E = Personalities.end(); I != E; ++I)
-        if (*I) GVStubs.insert('_' + (*I)->getName());
+             E = Personalities.end(); I != E; ++I) {
+        if (!*I)
+          continue;
+        if (!InStubSection) {
+          SwitchToDataSection(
+                     "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
+          InStubSection = true;
+        }
+        printGVStub((*I)->getNameStart(), "_");
+      }
     }
 
     // Output stubs for external and common global variables.
-    if (!GVStubs.empty())
+    if (!InStubSection && !GVStubs.empty())
       SwitchToDataSection(
                     "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
     for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
-         i != e; ++i) {
-      std::string p = i->getKeyData();
-      printSuffixedName(p, "$non_lazy_ptr");
-      O << ":\n"
-           "\t.indirect_symbol " << p << "\n"
-           "\t.long\t0\n";
-    }
+         i != e; ++i)
+      printGVStub(i->getKeyData());
 
     // Emit final debug information.
     DW.EndModule();

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.h Mon Jul  7 19:55:58 2008
@@ -120,6 +120,8 @@
   void printPICLabel(const MachineInstr *MI, unsigned Op);
   void printModuleLevelGV(const GlobalVariable* GVar);
 
+  void printGVStub(const char *GV, const char *Prefix = NULL);
+
   bool runOnMachineFunction(MachineFunction &F);
 
   /// getSectionForFunction - Return the section that we should emit the





More information about the llvm-commits mailing list