diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-21 06:19:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-21 06:19:20 +0000 |
commit | bc7a0299e4b9d6f669726976d00a08f47f03aa3f (patch) | |
tree | f4c5c6b60e44df91c78853178035e47fe72a648f /lib/CodeGen/Mangle.cpp | |
parent | af96def468042cfbed55a4cc12b1bb917ead4f33 (diff) |
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
Diffstat (limited to 'lib/CodeGen/Mangle.cpp')
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 63 |
1 files changed, 32 insertions, 31 deletions
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) { // ::= <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) { |