[cfe-commits] r67429 - /cfe/trunk/lib/CodeGen/Mangle.cpp

Chris Lattner sabre at nondot.org
Fri Mar 20 23:19:20 PDT 2009


Author: lattner
Date: Sat Mar 21 01:19:20 2009
New Revision: 67429

URL: http://llvm.org/viewvc/llvm-project?rev=67429&view=rev
Log:
simplify CXXNameMangler::mangle, making it exit earlier for C functions.
This speeds up a testcase in 3810 by ~16%.


Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=67429&r1=67428&r2=67429&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Mar 21 01:19:20 2009
@@ -62,40 +62,41 @@
   //            ::= <special-name>
 
   // FIXME: Actually use a visitor to decode these?
-  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    bool RequiresMangling = false;
-    // Clang's "overloadable" attribute extension to C/C++ implies
-    // name mangling (always).
-    if (FD->getAttr<OverloadableAttr>())
-      RequiresMangling = true;
-    // No mangled in an "implicit extern C" header.
-    else if (Context.getSourceManager().getFileCharacteristic(FD->getLocation())
-          == SrcMgr::C_ExternCSystem)
-      RequiresMangling = false;
-    else if (Context.getLangOptions().CPlusPlus && !FD->isMain()) {
-      // C++ requires name mangling, unless we're in a C linkage
-      // specification.
-      RequiresMangling = true;
-
-      for (const DeclContext *DC = FD->getDeclContext(); 
-           !DC->isTranslationUnit(); DC = DC->getParent()) {
-        if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
-          // extern "C" functions don't use name mangling
-          if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
-            RequiresMangling = false;
-          break;
-        }
-      }
-    }
+  const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+  if (!FD)  // Can only mangle functions so far.
+    return false;
+  
+  // Clang's "overloadable" attribute extension to C/C++ implies
+  // name mangling (always).
+  if (FD->getAttr<OverloadableAttr>())
+    ; // fall into mangling code unconditionally.
+  else if (// C functions are not mangled
+           !Context.getLangOptions().CPlusPlus ||
+           // "main" is not mangled in C++
+           FD->isMain() ||
+           // No mangling in an "implicit extern C" header.
+           Context.getSourceManager().getFileCharacteristic(FD->getLocation())
+                == SrcMgr::C_ExternCSystem)
+    return false;
+  else {
+    // No name mangling in a C linkage specification.
 
-    if (RequiresMangling) {
-      Out << "_Z";
-      mangleFunctionEncoding(FD);
-      return true;
+    for (const DeclContext *DC = FD->getDeclContext(); 
+         !DC->isTranslationUnit(); DC = DC->getParent()) {
+      if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
+        // extern "C" functions don't use name mangling.
+        if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
+          return false;
+        // Others do.
+        break;
+      }
     }
-  } 
+  }
 
-  return false;
+  // If we get here, mangle the decl name!
+  Out << "_Z";
+  mangleFunctionEncoding(FD);
+  return true;
 }
 
 void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {





More information about the cfe-commits mailing list