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
This commit is contained in:
Anders Carlsson 2010-06-22 16:05:32 +00:00
Родитель dc5daec0d3
Коммит 793a990774
2 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -210,6 +210,41 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
}
}
llvm::StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
const NamedDecl *ND = cast<NamedDecl>(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<CXXConstructorDecl>(ND))
getMangleContext().mangleCXXCtor(D, GD.getCtorType(), Buffer);
else if (const CXXDestructorDecl *D = dyn_cast<CXXDestructorDecl>(ND))
getMangleContext().mangleCXXDtor(D, GD.getDtorType(), Buffer);
else if (const BlockDecl *BD = dyn_cast<BlockDecl>(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<char>(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<NamedDecl>(GD.getDecl());

Просмотреть файл

@ -151,6 +151,10 @@ class CodeGenModule : public BlockModule {
/// priorities to be emitted when the translation unit is complete.
CtorList GlobalDtors;
/// MangledDeclNames - A map of canonical GlobalDecls to their mangled names.
llvm::DenseMap<GlobalDecl, llvm::StringRef> MangledDeclNames;
llvm::BumpPtrAllocator MangledNamesAllocator;
std::vector<llvm::Constant*> Annotations;
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
@ -460,6 +464,7 @@ public:
AttributeListType &PAL,
unsigned &CallingConv);
llvm::StringRef getMangledName(GlobalDecl GD);
void getMangledName(MangleBuffer &Buffer, GlobalDecl D);
void getMangledName(MangleBuffer &Buffer, const BlockDecl *BD);