From: Chris Lattner Date: Sat, 21 Mar 2009 06:19:20 +0000 (+0000) Subject: simplify CXXNameMangler::mangle, making it exit earlier for C functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc7a0299e4b9d6f669726976d00a08f47f03aa3f;p=clang simplify CXXNameMangler::mangle, making it exit earlier for C functions. 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 --- diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index d54849bd78..e760b83fe6 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -62,40 +62,41 @@ bool CXXNameMangler::mangle(const NamedDecl *D) { // ::= // FIXME: Actually use a visitor to decode these? - if (const FunctionDecl *FD = dyn_cast(D)) { - bool RequiresMangling = false; - // Clang's "overloadable" attribute extension to C/C++ implies - // name mangling (always). - if (FD->getAttr()) - 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(DC)) { - // extern "C" functions don't use name mangling - if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) - RequiresMangling = false; - break; - } + const FunctionDecl *FD = dyn_cast(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()) + ; // 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(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) {