From 793a990774826a0c20b0da66cec0991badfb8b63 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 22 Jun 2010 16:05:32 +0000 Subject: Add a new variant of getMangledName that caches the mangling for decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106547 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a9a55bfd15..5ab7a1befd 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -210,6 +210,41 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, } } +llvm::StringRef CodeGenModule::getMangledName(GlobalDecl GD) { + const NamedDecl *ND = cast(GD.getDecl()); + + llvm::StringRef &Str = MangledDeclNames[GD.getCanonicalDecl()]; + if (!Str.empty()) + return Str; + + if (!getMangleContext().shouldMangleDeclName(ND)) { + IdentifierInfo *II = ND->getIdentifier(); + assert(II && "Attempt to mangle unnamed decl."); + + Str = II->getName(); + return Str; + } + + llvm::SmallString<256> Buffer; + if (const CXXConstructorDecl *D = dyn_cast(ND)) + getMangleContext().mangleCXXCtor(D, GD.getCtorType(), Buffer); + else if (const CXXDestructorDecl *D = dyn_cast(ND)) + getMangleContext().mangleCXXDtor(D, GD.getDtorType(), Buffer); + else if (const BlockDecl *BD = dyn_cast(ND)) + getMangleContext().mangleBlock(BD, Buffer); + else + getMangleContext().mangleName(ND, Buffer); + + // Allocate space for the mangled name. + size_t Length = Buffer.size(); + char *Name = MangledNamesAllocator.Allocate(Length); + std::copy(Buffer.begin(), Buffer.end(), Name); + + Str = llvm::StringRef(Name, Length); + + return Str; +} + void CodeGenModule::getMangledName(MangleBuffer &Buffer, GlobalDecl GD) { const NamedDecl *ND = cast(GD.getDecl()); -- cgit v1.2.3-18-g5258