]> granicus.if.org Git - clang/commitdiff
simplify CXXNameMangler::mangle, making it exit earlier for C functions.
authorChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:19:20 +0000 (06:19 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:19:20 +0000 (06:19 +0000)
This speeds up a testcase in 3810 by ~16%.

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

lib/CodeGen/Mangle.cpp

index d54849bd780d507cd1a68927de4c98a116cb1904..e760b83fe6b91bdc3c469ec2af955038d2aa6b67 100644 (file)
@@ -62,40 +62,41 @@ bool CXXNameMangler::mangle(const NamedDecl *D) {
   //            ::= <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.
+
+    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;
       }
     }
+  }
 
-    if (RequiresMangling) {
-      Out << "_Z";
-      mangleFunctionEncoding(FD);
-      return true;
-    }
-  } 
-
-  return false;
+  // If we get here, mangle the decl name!
+  Out << "_Z";
+  mangleFunctionEncoding(FD);
+  return true;
 }
 
 void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {