forked from OSchip/llvm-project
IRgen: Switch the C++ mangler interfaces to take the SmallVector to write into,
instead of requiring clients to make a raw_svector_ostream, which is just an implementation detail. llvm-svn: 89548
This commit is contained in:
parent
ef5d75afeb
commit
e128dd18ab
|
@ -151,8 +151,7 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
|
|||
"thread safe statics are currently not supported!");
|
||||
|
||||
llvm::SmallString<256> GuardVName;
|
||||
llvm::raw_svector_ostream GuardVOut(GuardVName);
|
||||
CGM.getMangleContext().mangleGuardVariable(&D, GuardVOut);
|
||||
CGM.getMangleContext().mangleGuardVariable(&D, GuardVName);
|
||||
|
||||
// Create the guard variable.
|
||||
llvm::GlobalValue *GuardV =
|
||||
|
@ -755,8 +754,7 @@ CodeGenModule::GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
|
|||
const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D,
|
||||
CXXCtorType Type) {
|
||||
llvm::SmallString<256> Name;
|
||||
llvm::raw_svector_ostream Out(Name);
|
||||
getMangleContext().mangleCXXCtor(D, Type, Out);
|
||||
getMangleContext().mangleCXXCtor(D, Type, Name);
|
||||
|
||||
Name += '\0';
|
||||
return UniqueMangledName(Name.begin(), Name.end());
|
||||
|
@ -793,8 +791,7 @@ CodeGenModule::GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
|
|||
const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D,
|
||||
CXXDtorType Type) {
|
||||
llvm::SmallString<256> Name;
|
||||
llvm::raw_svector_ostream Out(Name);
|
||||
getMangleContext().mangleCXXDtor(D, Type, Out);
|
||||
getMangleContext().mangleCXXDtor(D, Type, Name);
|
||||
|
||||
Name += '\0';
|
||||
return UniqueMangledName(Name.begin(), Name.end());
|
||||
|
@ -945,8 +942,7 @@ llvm::Constant *CodeGenFunction::GenerateCovariantThunk(llvm::Function *Fn,
|
|||
llvm::Constant *CodeGenModule::BuildThunk(const CXXMethodDecl *MD, bool Extern,
|
||||
int64_t nv, int64_t v) {
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
getMangleContext().mangleThunk(MD, nv, v, Out);
|
||||
getMangleContext().mangleThunk(MD, nv, v, OutName);
|
||||
llvm::GlobalVariable::LinkageTypes linktype;
|
||||
linktype = llvm::GlobalValue::WeakAnyLinkage;
|
||||
if (!Extern)
|
||||
|
@ -957,7 +953,7 @@ llvm::Constant *CodeGenModule::BuildThunk(const CXXMethodDecl *MD, bool Extern,
|
|||
getTypes().GetFunctionType(getTypes().getFunctionInfo(MD),
|
||||
FPT->isVariadic());
|
||||
|
||||
llvm::Function *Fn = llvm::Function::Create(FTy, linktype, Out.str(),
|
||||
llvm::Function *Fn = llvm::Function::Create(FTy, linktype, OutName.str(),
|
||||
&getModule());
|
||||
CodeGenFunction(*this).GenerateThunk(Fn, MD, Extern, nv, v);
|
||||
llvm::Constant *m = llvm::ConstantExpr::getBitCast(Fn, Ptr8Ty);
|
||||
|
@ -969,8 +965,7 @@ llvm::Constant *CodeGenModule::BuildCovariantThunk(const CXXMethodDecl *MD,
|
|||
int64_t v_t, int64_t nv_r,
|
||||
int64_t v_r) {
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
getMangleContext().mangleCovariantThunk(MD, nv_t, v_t, nv_r, v_r, Out);
|
||||
getMangleContext().mangleCovariantThunk(MD, nv_t, v_t, nv_r, v_r, OutName);
|
||||
llvm::GlobalVariable::LinkageTypes linktype;
|
||||
linktype = llvm::GlobalValue::WeakAnyLinkage;
|
||||
if (!Extern)
|
||||
|
@ -981,7 +976,7 @@ llvm::Constant *CodeGenModule::BuildCovariantThunk(const CXXMethodDecl *MD,
|
|||
getTypes().GetFunctionType(getTypes().getFunctionInfo(MD),
|
||||
FPT->isVariadic());
|
||||
|
||||
llvm::Function *Fn = llvm::Function::Create(FTy, linktype, Out.str(),
|
||||
llvm::Function *Fn = llvm::Function::Create(FTy, linktype, OutName.str(),
|
||||
&getModule());
|
||||
CodeGenFunction(*this).GenerateCovariantThunk(Fn, MD, Extern, nv_t, v_t, nv_r,
|
||||
v_r);
|
||||
|
|
|
@ -49,9 +49,8 @@ public:
|
|||
|
||||
llvm::Constant *BuildName(QualType Ty, bool Hidden, bool Extern) {
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
CGM.getMangleContext().mangleCXXRttiName(Ty, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
CGM.getMangleContext().mangleCXXRttiName(Ty, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
llvm::GlobalVariable::LinkageTypes linktype;
|
||||
linktype = llvm::GlobalValue::LinkOnceODRLinkage;
|
||||
|
@ -99,9 +98,8 @@ public:
|
|||
return llvm::Constant::getNullValue(Int8PtrTy);
|
||||
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
C = CGM.getModule().getGlobalVariable(Name);
|
||||
if (C)
|
||||
|
@ -194,10 +192,9 @@ public:
|
|||
llvm::Constant *C;
|
||||
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
CGM.getMangleContext().mangleCXXRtti(CGM.getContext().getTagDeclType(RD),
|
||||
Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
llvm::GlobalVariable *GV;
|
||||
GV = CGM.getModule().getGlobalVariable(Name);
|
||||
|
@ -290,9 +287,8 @@ public:
|
|||
llvm::Constant *C;
|
||||
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
llvm::GlobalVariable *GV;
|
||||
GV = CGM.getModule().getGlobalVariable(Name);
|
||||
|
@ -344,9 +340,8 @@ public:
|
|||
llvm::Constant *C;
|
||||
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
CGM.getMangleContext().mangleCXXRtti(Ty, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
llvm::GlobalVariable *GV;
|
||||
GV = CGM.getModule().getGlobalVariable(Name);
|
||||
|
|
|
@ -791,12 +791,11 @@ llvm::Constant *CodeGenModule::GenerateVtable(const CXXRecordDecl *LayoutClass,
|
|||
const CXXRecordDecl *RD,
|
||||
uint64_t Offset) {
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
if (LayoutClass != RD)
|
||||
getMangleContext().mangleCXXCtorVtable(LayoutClass, Offset/8, RD, Out);
|
||||
getMangleContext().mangleCXXCtorVtable(LayoutClass, Offset/8, RD, OutName);
|
||||
else
|
||||
getMangleContext().mangleCXXVtable(RD, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
getMangleContext().mangleCXXVtable(RD, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
std::vector<llvm::Constant *> methods;
|
||||
llvm::Type *Ptr8Ty=llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext),0);
|
||||
|
@ -1042,9 +1041,8 @@ llvm::Constant *CodeGenModule::GenerateVTT(const CXXRecordDecl *RD) {
|
|||
return 0;
|
||||
|
||||
llvm::SmallString<256> OutName;
|
||||
llvm::raw_svector_ostream Out(OutName);
|
||||
getMangleContext().mangleCXXVTT(RD, Out);
|
||||
llvm::StringRef Name = Out.str();
|
||||
getMangleContext().mangleCXXVTT(RD, OutName);
|
||||
llvm::StringRef Name = OutName.str();
|
||||
|
||||
llvm::GlobalVariable::LinkageTypes linktype;
|
||||
linktype = llvm::GlobalValue::LinkOnceODRLinkage;
|
||||
|
|
|
@ -167,8 +167,7 @@ const char *CodeGenModule::getMangledName(const NamedDecl *ND) {
|
|||
}
|
||||
|
||||
llvm::SmallString<256> Name;
|
||||
llvm::raw_svector_ostream Out(Name);
|
||||
if (!getMangleContext().mangleName(ND, Out)) {
|
||||
if (!getMangleContext().mangleName(ND, Name)) {
|
||||
assert(ND->getIdentifier() && "Attempt to mangle unnamed decl.");
|
||||
return ND->getNameAsCString();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace {
|
|||
/// CXXNameMangler - Manage the mangling of a single name.
|
||||
class VISIBILITY_HIDDEN CXXNameMangler {
|
||||
MangleContext &Context;
|
||||
llvm::raw_ostream &Out;
|
||||
llvm::raw_svector_ostream Out;
|
||||
|
||||
const CXXMethodDecl *Structor;
|
||||
unsigned StructorType;
|
||||
|
@ -41,8 +41,8 @@ class VISIBILITY_HIDDEN CXXNameMangler {
|
|||
llvm::DenseMap<uintptr_t, unsigned> Substitutions;
|
||||
|
||||
public:
|
||||
CXXNameMangler(MangleContext &C, llvm::raw_ostream &os)
|
||||
: Context(C), Out(os), Structor(0), StructorType(0) { }
|
||||
CXXNameMangler(MangleContext &C, llvm::SmallVectorImpl<char> &Res)
|
||||
: Context(C), Out(Res), Structor(0), StructorType(0) { }
|
||||
|
||||
bool mangle(const NamedDecl *D);
|
||||
void mangleCalloffset(int64_t nv, int64_t v);
|
||||
|
@ -1387,7 +1387,8 @@ void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
|
|||
/// and this routine will return false. In this case, the caller should just
|
||||
/// emit the identifier of the declaration (\c D->getIdentifier()) as its
|
||||
/// name.
|
||||
bool MangleContext::mangleName(const NamedDecl *D, llvm::raw_ostream &os) {
|
||||
bool MangleContext::mangleName(const NamedDecl *D,
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
assert(!isa<CXXConstructorDecl>(D) &&
|
||||
"Use mangleCXXCtor for constructor decls!");
|
||||
assert(!isa<CXXDestructorDecl>(D) &&
|
||||
|
@ -1397,102 +1398,82 @@ bool MangleContext::mangleName(const NamedDecl *D, llvm::raw_ostream &os) {
|
|||
getASTContext().getSourceManager(),
|
||||
"Mangling declaration");
|
||||
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
if (!Mangler.mangle(D))
|
||||
return false;
|
||||
|
||||
os.flush();
|
||||
return true;
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
return Mangler.mangle(D);
|
||||
}
|
||||
|
||||
/// \brief Mangles the a thunk with the offset n for the declaration D and
|
||||
/// emits that name to the given output stream.
|
||||
void MangleContext::mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v,
|
||||
llvm::raw_ostream &os) {
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
// FIXME: Hum, we might have to thunk these, fix.
|
||||
assert(!isa<CXXDestructorDecl>(FD) &&
|
||||
"Use mangleCXXDtor for destructor decls!");
|
||||
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleThunk(FD, nv, v);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
/// \brief Mangles the a covariant thunk for the declaration D and emits that
|
||||
/// name to the given output stream.
|
||||
void MangleContext::mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t,
|
||||
int64_t v_t, int64_t nv_r, int64_t v_r,
|
||||
llvm::raw_ostream &os) {
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
// FIXME: Hum, we might have to thunk these, fix.
|
||||
assert(!isa<CXXDestructorDecl>(FD) &&
|
||||
"Use mangleCXXDtor for destructor decls!");
|
||||
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
/// mangleGuardVariable - Returns the mangled name for a guard variable
|
||||
/// for the passed in VarDecl.
|
||||
void MangleContext::mangleGuardVariable(const VarDecl *D,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleGuardVariable(D);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXCtor(D, Type);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXDtor(D, Type);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXVtable(const CXXRecordDecl *RD,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXVtable(RD);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXVTT(RD);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset,
|
||||
const CXXRecordDecl *Type,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXCtorVtable(RD, Offset, Type);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXRtti(QualType Ty, llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
void MangleContext::mangleCXXRtti(QualType Ty,
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXRtti(Ty);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void MangleContext::mangleCXXRttiName(QualType Ty, llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(*this, os);
|
||||
void MangleContext::mangleCXXRttiName(QualType Ty,
|
||||
llvm::SmallVectorImpl<char> &Res) {
|
||||
CXXNameMangler Mangler(*this, Res);
|
||||
Mangler.mangleCXXRttiName(Ty);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
#include "llvm/ADT/DenseMap.h"
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
template<typename T>
|
||||
class SmallVectorImpl;
|
||||
}
|
||||
|
||||
namespace clang {
|
||||
|
@ -57,22 +58,24 @@ public:
|
|||
/// @name Mangler Entry Points
|
||||
/// @{
|
||||
|
||||
bool mangleName(const NamedDecl *D, llvm::raw_ostream &os);
|
||||
bool mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
|
||||
void mangleThunk(const FunctionDecl *FD, int64_t n, int64_t vn,
|
||||
llvm::raw_ostream &os);
|
||||
llvm::SmallVectorImpl<char> &);
|
||||
void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
|
||||
int64_t nv_r, int64_t v_r, llvm::raw_ostream &os);
|
||||
void mangleGuardVariable(const VarDecl *D, llvm::raw_ostream &os);
|
||||
void mangleCXXVtable(const CXXRecordDecl *RD, llvm::raw_ostream &os);
|
||||
void mangleCXXVTT(const CXXRecordDecl *RD, llvm::raw_ostream &os);
|
||||
int64_t nv_r, int64_t v_r,
|
||||
llvm::SmallVectorImpl<char> &);
|
||||
void mangleGuardVariable(const VarDecl *D, llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXVtable(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXVTT(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset,
|
||||
const CXXRecordDecl *Type, llvm::raw_ostream &os);
|
||||
void mangleCXXRtti(QualType T, llvm::raw_ostream &os);
|
||||
void mangleCXXRttiName(QualType T, llvm::raw_ostream &os);
|
||||
const CXXRecordDecl *Type,
|
||||
llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXRtti(QualType T, llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXRttiName(QualType T, llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
||||
llvm::raw_ostream &os);
|
||||
llvm::SmallVectorImpl<char> &);
|
||||
void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
|
||||
llvm::raw_ostream &os);
|
||||
llvm::SmallVectorImpl<char> &);
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue