[llvm-commits] [llvm] r93686 - in /llvm/trunk: include/llvm/Target/Mangler.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/ELFWriter.cpp lib/Target/CBackend/CBackend.cpp lib/Target/Mangler.cpp tools/lto/LTOCodeGenerator.cpp tools/lto/LTOModule.cpp

Chris Lattner sabre at nondot.org
Sun Jan 17 10:22:35 PST 2010


Author: lattner
Date: Sun Jan 17 12:22:35 2010
New Revision: 93686

URL: http://llvm.org/viewvc/llvm-project?rev=93686&view=rev
Log:
now that mangler is in libtarget, it can use MCAsmInfo instead of clients
having to pass various fields from it in.  Simplify.

Modified:
    llvm/trunk/include/llvm/Target/Mangler.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/Target/CBackend/CBackend.cpp
    llvm/trunk/lib/Target/Mangler.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/LTOModule.cpp

Modified: llvm/trunk/include/llvm/Target/Mangler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Mangler.h?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/Mangler.h (original)
+++ llvm/trunk/include/llvm/Target/Mangler.h Sun Jan 17 12:22:35 2010
@@ -19,11 +19,10 @@
 
 namespace llvm {
 class Twine;
-class Type;
-class Module;
 class Value;
 class GlobalValue;
 template <typename T> class SmallVectorImpl; 
+class MCAsmInfo;
 
 class Mangler {
 public:
@@ -34,17 +33,7 @@
   };
 
 private:
-  /// Prefix - This string is added to each symbol that is emitted, unless the
-  /// symbol is marked as not needing this prefix.
-  const char *Prefix;
-
-  /// PrivatePrefix - This string is emitted before each symbol with private
-  /// linkage.
-  const char *PrivatePrefix;
-
-  /// LinkerPrivatePrefix - This string is emitted before each symbol with
-  /// "linker_private" linkage.
-  const char *LinkerPrivatePrefix;
+  const MCAsmInfo &MAI;
 
   /// AnonGlobalIDs - We need to give global values the same name every time
   /// they are mangled.  This keeps track of the number we give to anonymous
@@ -59,8 +48,7 @@
 public:
   // Mangler ctor - if a prefix is specified, it will be prepended onto all
   // symbols.
-  Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "",
-          const char *linkerPrivatePrefix = "");
+  Mangler(const MCAsmInfo &mai) : MAI(mai) {}
 
   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
   /// and the specified global variable's name.  If the global variable doesn't

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Jan 17 12:22:35 2010
@@ -101,8 +101,7 @@
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .Initialize(OutContext, TM);
   
-  Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(),
-                     MAI->getLinkerPrivateGlobalPrefix());
+  Mang = new Mangler(*MAI);
   
   // Allow the target to emit any magic that it wants at the start of the file.
   EmitStartOfAsmFile(M);

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Sun Jan 17 12:22:35 2010
@@ -119,7 +119,7 @@
   // Initialize TargetLoweringObjectFile.
   const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM);
   
-  Mang = new Mangler(M);
+  Mang = new Mangler(*MAI);
 
   // ELF Header
   // ----------

Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Sun Jan 17 12:22:35 2010
@@ -58,6 +58,13 @@
 }
 
 namespace {
+  class CBEMCAsmInfo : public MCAsmInfo {
+  public:
+    CBEMCAsmInfo() {
+      GlobalPrefix = "";
+      PrivateGlobalPrefix = "";
+    }
+  };
   /// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for
   /// any unnamed structure types that are used by the program, and merges
   /// external functions with the same name.
@@ -1869,8 +1876,17 @@
   IL = new IntrinsicLowering(*TD);
   IL->AddPrototypes(M);
 
-  // Ensure that all structure types have names...
-  Mang = new Mangler(M);
+#if 0
+  std::string Triple = TheModule->getTargetTriple();
+  if (Triple.empty())
+    Triple = llvm::sys::getHostTriple();
+  
+  std::string E;
+  if (const Target *Match = TargetRegistry::lookupTarget(Triple, E))
+    TAsm = Match->createAsmInfo(Triple);
+#endif    
+  TAsm = new CBEMCAsmInfo();
+  Mang = new Mangler(*TAsm);
 
   // Keep track of which functions are static ctors/dtors so they can have
   // an attribute added to their prototypes.
@@ -3240,30 +3256,31 @@
 //      of the per target tables
 //      handle multiple constraint codes
 std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) {
-
   assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
 
-  const char *const *table = 0;
-  
   // Grab the translation table from MCAsmInfo if it exists.
-  if (!TAsm) {
-    std::string Triple = TheModule->getTargetTriple();
-    if (Triple.empty())
-      Triple = llvm::sys::getHostTriple();
-
-    std::string E;
-    if (const Target *Match = TargetRegistry::lookupTarget(Triple, E))
-      TAsm = Match->createAsmInfo(Triple);
-  }
-  if (TAsm)
-    table = TAsm->getAsmCBE();
+  const MCAsmInfo *TargetAsm;
+  std::string Triple = TheModule->getTargetTriple();
+  if (Triple.empty())
+    Triple = llvm::sys::getHostTriple();
+  
+  std::string E;
+  if (const Target *Match = TargetRegistry::lookupTarget(Triple, E))
+    TargetAsm = Match->createAsmInfo(Triple);
+  else
+    return c.Codes[0];
+  
+  const char *const *table = TargetAsm->getAsmCBE();
 
   // Search the translation table if it exists.
   for (int i = 0; table && table[i]; i += 2)
-    if (c.Codes[0] == table[i])
+    if (c.Codes[0] == table[i]) {
+      delete TargetAsm;
       return table[i+1];
+    }
 
   // Default is identity.
+  delete TargetAsm;
   return c.Codes[0];
 }
 

Modified: llvm/trunk/lib/Target/Mangler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mangler.cpp?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mangler.cpp (original)
+++ llvm/trunk/lib/Target/Mangler.cpp Sun Jan 17 12:22:35 2010
@@ -13,6 +13,7 @@
 
 #include "llvm/Target/Mangler.h"
 #include "llvm/GlobalValue.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
@@ -29,18 +30,21 @@
   
   // If the global name is not led with \1, add the appropriate prefixes.
   if (Name[0] != '\1') {
-    if (PrefixTy == Mangler::Private)
-      OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
-    else if (PrefixTy == Mangler::LinkerPrivate)
-      OutName.append(LinkerPrivatePrefix,
-                     LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
-    
+    if (PrefixTy == Mangler::Private) {
+      const char *Prefix = MAI.getPrivateGlobalPrefix();
+      OutName.append(Prefix, Prefix+strlen(Prefix));
+    } else if (PrefixTy == Mangler::LinkerPrivate) {
+      const char *Prefix = MAI.getLinkerPrivateGlobalPrefix();
+      OutName.append(Prefix, Prefix+strlen(Prefix));
+    }
+
+    const char *Prefix = MAI.getGlobalPrefix();
     if (Prefix[0] == 0)
       ; // Common noop, no prefix.
     else if (Prefix[1] == 0)
       OutName.push_back(Prefix[0]);  // Common, one character prefix.
     else
-      OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary prefix.
+      OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary length prefix.
   } else {
     Name = Name.substr(1);
   }
@@ -68,14 +72,21 @@
   
   // If the global variable doesn't have a name, return a unique name for the
   // global based on a numbering.
+  if (GV->hasPrivateLinkage() || isImplicitlyPrivate) {
+    const char *Prefix = MAI.getPrivateGlobalPrefix();
+    OutName.append(Prefix, Prefix+strlen(Prefix));
+  } else if (GV->hasLinkerPrivateLinkage()) {
+    const char *Prefix = MAI.getLinkerPrivateGlobalPrefix();
+    OutName.append(Prefix, Prefix+strlen(Prefix));
+  }
   
-  // Anonymous names always get prefixes.
-  if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
-    OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
-  else if (GV->hasLinkerPrivateLinkage())
-    OutName.append(LinkerPrivatePrefix,
-                   LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));;
-  OutName.append(Prefix, Prefix+strlen(Prefix));
+  const char *Prefix = MAI.getGlobalPrefix();
+  if (Prefix[0] == 0)
+    ; // Common noop, no prefix.
+  else if (Prefix[1] == 0)
+    OutName.push_back(Prefix[0]);  // Common, one character prefix.
+  else
+    OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary length prefix.
   
   // Get the ID for the global, assigning a new one if we haven't got one
   // already.
@@ -95,10 +106,3 @@
   getNameWithPrefix(Buf, GV, isImplicitlyPrivate);
   return std::string(Buf.begin(), Buf.end());
 }
-  
-
-Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix,
-                 const char *linkerPrivatePrefix)
-  : Prefix(prefix), PrivatePrefix(privatePrefix),
-    LinkerPrivatePrefix(linkerPrivatePrefix), NextAnonGlobalID(1) {
-}

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Sun Jan 17 12:22:35 2010
@@ -323,8 +323,7 @@
 
         // mark which symbols can not be internalized 
         if ( !_mustPreserveSymbols.empty() ) {
-            Mangler mangler(*mergedModule, 
-                                _target->getMCAsmInfo()->getGlobalPrefix());
+            Mangler mangler(*_target->getMCAsmInfo());
             std::vector<const char*> mustPreserveList;
             for (Module::iterator f = mergedModule->begin(), 
                                         e = mergedModule->end(); f != e; ++f) {

Modified: llvm/trunk/tools/lto/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=93686&r1=93685&r2=93686&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOModule.cpp (original)
+++ llvm/trunk/tools/lto/LTOModule.cpp Sun Jan 17 12:22:35 2010
@@ -439,7 +439,7 @@
         _symbolsParsed = true;
         
         // Use mangler to add GlobalPrefix to names to match linker names.
-        Mangler mangler(*_module, _target->getMCAsmInfo()->getGlobalPrefix());
+        Mangler mangler(*_target->getMCAsmInfo());
 
         // add functions
         for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {





More information about the llvm-commits mailing list