Twinify CGObjCMac, this simplifies the code and should reduce std::string

trashing.

llvm-svn: 84439
This commit is contained in:
Daniel Dunbar 2009-10-18 20:48:59 +00:00
parent 9500ad13b0
commit 349e6fbfce
1 changed files with 86 additions and 97 deletions

View File

@ -900,7 +900,7 @@ protected:
/// EmitPropertyList - Emit the given property list. The return /// EmitPropertyList - Emit the given property list. The return
/// value has type PropertyListPtrTy. /// value has type PropertyListPtrTy.
llvm::Constant *EmitPropertyList(const std::string &Name, llvm::Constant *EmitPropertyList(llvm::Twine Name,
const Decl *Container, const Decl *Container,
const ObjCContainerDecl *OCD, const ObjCContainerDecl *OCD,
const ObjCCommonTypesHelper &ObjCTypes); const ObjCCommonTypesHelper &ObjCTypes);
@ -924,7 +924,7 @@ protected:
/// \param Align - The alignment for the variable, or 0. /// \param Align - The alignment for the variable, or 0.
/// \param AddToUsed - Whether the variable should be added to /// \param AddToUsed - Whether the variable should be added to
/// "llvm.used". /// "llvm.used".
llvm::GlobalVariable *CreateMetadataVar(const std::string &Name, llvm::GlobalVariable *CreateMetadataVar(llvm::Twine Name,
llvm::Constant *Init, llvm::Constant *Init,
const char *Section, const char *Section,
unsigned Align, unsigned Align,
@ -1025,7 +1025,7 @@ private:
/// EmitMethodList - Emit the method list for the given /// EmitMethodList - Emit the method list for the given
/// implementation. The return value has type MethodListPtrTy. /// implementation. The return value has type MethodListPtrTy.
llvm::Constant *EmitMethodList(const std::string &Name, llvm::Constant *EmitMethodList(llvm::Twine Name,
const char *Section, const char *Section,
const ConstantVector &Methods); const ConstantVector &Methods);
@ -1040,7 +1040,7 @@ private:
/// - begin, end: The method list to output. /// - begin, end: The method list to output.
/// ///
/// The return value has type MethodDescriptionListPtrTy. /// The return value has type MethodDescriptionListPtrTy.
llvm::Constant *EmitMethodDescList(const std::string &Name, llvm::Constant *EmitMethodDescList(llvm::Twine Name,
const char *Section, const char *Section,
const ConstantVector &Methods); const ConstantVector &Methods);
@ -1066,7 +1066,7 @@ private:
/// EmitProtocolList - Generate the list of referenced /// EmitProtocolList - Generate the list of referenced
/// protocols. The return value has type ProtocolListPtrTy. /// protocols. The return value has type ProtocolListPtrTy.
llvm::Constant *EmitProtocolList(const std::string &Name, llvm::Constant *EmitProtocolList(llvm::Twine Name,
ObjCProtocolDecl::protocol_iterator begin, ObjCProtocolDecl::protocol_iterator begin,
ObjCProtocolDecl::protocol_iterator end); ObjCProtocolDecl::protocol_iterator end);
@ -1197,7 +1197,7 @@ private:
/// EmitMethodList - Emit the method list for the given /// EmitMethodList - Emit the method list for the given
/// implementation. The return value has type MethodListnfABITy. /// implementation. The return value has type MethodListnfABITy.
llvm::Constant *EmitMethodList(const std::string &Name, llvm::Constant *EmitMethodList(llvm::Twine Name,
const char *Section, const char *Section,
const ConstantVector &Methods); const ConstantVector &Methods);
/// EmitIvarList - Emit the ivar list for the given /// EmitIvarList - Emit the ivar list for the given
@ -1224,7 +1224,7 @@ private:
/// EmitProtocolList - Generate the list of referenced /// EmitProtocolList - Generate the list of referenced
/// protocols. The return value has type ProtocolListPtrTy. /// protocols. The return value has type ProtocolListPtrTy.
llvm::Constant *EmitProtocolList(const std::string &Name, llvm::Constant *EmitProtocolList(llvm::Twine Name,
ObjCProtocolDecl::protocol_iterator begin, ObjCProtocolDecl::protocol_iterator begin,
ObjCProtocolDecl::protocol_iterator end); ObjCProtocolDecl::protocol_iterator end);
@ -1616,8 +1616,6 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
// resolved. Investigate. Its also wasteful to look this up over and over. // resolved. Investigate. Its also wasteful to look this up over and over.
LazySymbols.insert(&CGM.getContext().Idents.get("Protocol")); LazySymbols.insert(&CGM.getContext().Idents.get("Protocol"));
const char *ProtocolName = PD->getNameAsCString();
// Construct method lists. // Construct method lists.
std::vector<llvm::Constant*> InstanceMethods, ClassMethods; std::vector<llvm::Constant*> InstanceMethods, ClassMethods;
std::vector<llvm::Constant*> OptInstanceMethods, OptClassMethods; std::vector<llvm::Constant*> OptInstanceMethods, OptClassMethods;
@ -1647,17 +1645,15 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
Values[0] = EmitProtocolExtension(PD, OptInstanceMethods, OptClassMethods); Values[0] = EmitProtocolExtension(PD, OptInstanceMethods, OptClassMethods);
Values[1] = GetClassName(PD->getIdentifier()); Values[1] = GetClassName(PD->getIdentifier());
Values[2] = Values[2] =
EmitProtocolList("\01L_OBJC_PROTOCOL_REFS_" + PD->getNameAsString(), EmitProtocolList("\01L_OBJC_PROTOCOL_REFS_" + PD->getName(),
PD->protocol_begin(), PD->protocol_begin(),
PD->protocol_end()); PD->protocol_end());
Values[3] = Values[3] =
EmitMethodDescList("\01L_OBJC_PROTOCOL_INSTANCE_METHODS_" EmitMethodDescList("\01L_OBJC_PROTOCOL_INSTANCE_METHODS_" + PD->getName(),
+ PD->getNameAsString(),
"__OBJC,__cat_inst_meth,regular,no_dead_strip", "__OBJC,__cat_inst_meth,regular,no_dead_strip",
InstanceMethods); InstanceMethods);
Values[4] = Values[4] =
EmitMethodDescList("\01L_OBJC_PROTOCOL_CLASS_METHODS_" EmitMethodDescList("\01L_OBJC_PROTOCOL_CLASS_METHODS_" + PD->getName(),
+ PD->getNameAsString(),
"__OBJC,__cat_cls_meth,regular,no_dead_strip", "__OBJC,__cat_cls_meth,regular,no_dead_strip",
ClassMethods); ClassMethods);
llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ProtocolTy, llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ProtocolTy,
@ -1672,7 +1668,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy, false, new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy, false,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Init,
std::string("\01L_OBJC_PROTOCOL_")+ProtocolName); "\01L_OBJC_PROTOCOL_" + PD->getName());
Entry->setSection("__OBJC,__protocol,regular,no_dead_strip"); Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
Entry->setAlignment(4); Entry->setAlignment(4);
// FIXME: Is this necessary? Why only for protocol? // FIXME: Is this necessary? Why only for protocol?
@ -1694,7 +1690,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) {
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy, false, new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy, false,
llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::ExternalLinkage,
0, 0,
"\01L_OBJC_PROTOCOL_" + PD->getNameAsString()); "\01L_OBJC_PROTOCOL_" + PD->getName());
Entry->setSection("__OBJC,__protocol,regular,no_dead_strip"); Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
Entry->setAlignment(4); Entry->setAlignment(4);
// FIXME: Is this necessary? Why only for protocol? // FIXME: Is this necessary? Why only for protocol?
@ -1722,16 +1718,14 @@ CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD,
Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size);
Values[1] = Values[1] =
EmitMethodDescList("\01L_OBJC_PROTOCOL_INSTANCE_METHODS_OPT_" EmitMethodDescList("\01L_OBJC_PROTOCOL_INSTANCE_METHODS_OPT_"
+ PD->getNameAsString(), + PD->getName(),
"__OBJC,__cat_inst_meth,regular,no_dead_strip", "__OBJC,__cat_inst_meth,regular,no_dead_strip",
OptInstanceMethods); OptInstanceMethods);
Values[2] = Values[2] =
EmitMethodDescList("\01L_OBJC_PROTOCOL_CLASS_METHODS_OPT_" EmitMethodDescList("\01L_OBJC_PROTOCOL_CLASS_METHODS_OPT_" + PD->getName(),
+ PD->getNameAsString(),
"__OBJC,__cat_cls_meth,regular,no_dead_strip", "__OBJC,__cat_cls_meth,regular,no_dead_strip",
OptClassMethods); OptClassMethods);
Values[3] = EmitPropertyList("\01L_OBJC_$_PROP_PROTO_LIST_" + Values[3] = EmitPropertyList("\01L_OBJC_$_PROP_PROTO_LIST_" + PD->getName(),
PD->getNameAsString(),
0, PD, ObjCTypes); 0, PD, ObjCTypes);
// Return null if no extension bits are used. // Return null if no extension bits are used.
@ -1743,7 +1737,7 @@ CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD,
llvm::ConstantStruct::get(ObjCTypes.ProtocolExtensionTy, Values); llvm::ConstantStruct::get(ObjCTypes.ProtocolExtensionTy, Values);
// No special section, but goes in llvm.used // No special section, but goes in llvm.used
return CreateMetadataVar("\01L_OBJC_PROTOCOLEXT_" + PD->getNameAsString(), return CreateMetadataVar("\01L_OBJC_PROTOCOLEXT_" + PD->getName(),
Init, Init,
0, 0, true); 0, 0, true);
} }
@ -1756,7 +1750,7 @@ CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD,
}; };
*/ */
llvm::Constant * llvm::Constant *
CGObjCMac::EmitProtocolList(const std::string &Name, CGObjCMac::EmitProtocolList(llvm::Twine Name,
ObjCProtocolDecl::protocol_iterator begin, ObjCProtocolDecl::protocol_iterator begin,
ObjCProtocolDecl::protocol_iterator end) { ObjCProtocolDecl::protocol_iterator end) {
std::vector<llvm::Constant*> ProtocolRefs; std::vector<llvm::Constant*> ProtocolRefs;
@ -1800,7 +1794,7 @@ CGObjCMac::EmitProtocolList(const std::string &Name,
struct _objc_property[prop_count]; struct _objc_property[prop_count];
}; };
*/ */
llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, llvm::Constant *CGObjCCommonMac::EmitPropertyList(llvm::Twine Name,
const Decl *Container, const Decl *Container,
const ObjCContainerDecl *OCD, const ObjCContainerDecl *OCD,
const ObjCCommonTypesHelper &ObjCTypes) { const ObjCCommonTypesHelper &ObjCTypes) {
@ -1854,7 +1848,7 @@ CGObjCMac::GetMethodDescriptionConstant(const ObjCMethodDecl *MD) {
Desc); Desc);
} }
llvm::Constant *CGObjCMac::EmitMethodDescList(const std::string &Name, llvm::Constant *CGObjCMac::EmitMethodDescList(llvm::Twine Name,
const char *Section, const char *Section,
const ConstantVector &Methods) { const ConstantVector &Methods) {
// Return null for empty list. // Return null for empty list.
@ -1894,8 +1888,10 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
const ObjCInterfaceDecl *Interface = OCD->getClassInterface(); const ObjCInterfaceDecl *Interface = OCD->getClassInterface();
const ObjCCategoryDecl *Category = const ObjCCategoryDecl *Category =
Interface->FindCategoryDeclaration(OCD->getIdentifier()); Interface->FindCategoryDeclaration(OCD->getIdentifier());
std::string ExtName(Interface->getNameAsString() + "_" +
OCD->getNameAsString()); llvm::SmallString<256> ExtName;
llvm::raw_svector_ostream(ExtName) << Interface->getName() << '_'
<< OCD->getName();
std::vector<llvm::Constant*> InstanceMethods, ClassMethods; std::vector<llvm::Constant*> InstanceMethods, ClassMethods;
for (ObjCCategoryImplDecl::instmeth_iterator for (ObjCCategoryImplDecl::instmeth_iterator
@ -1914,17 +1910,16 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
Values[1] = GetClassName(Interface->getIdentifier()); Values[1] = GetClassName(Interface->getIdentifier());
LazySymbols.insert(Interface->getIdentifier()); LazySymbols.insert(Interface->getIdentifier());
Values[2] = Values[2] =
EmitMethodList(std::string("\01L_OBJC_CATEGORY_INSTANCE_METHODS_") + EmitMethodList("\01L_OBJC_CATEGORY_INSTANCE_METHODS_" + ExtName.str(),
ExtName,
"__OBJC,__cat_inst_meth,regular,no_dead_strip", "__OBJC,__cat_inst_meth,regular,no_dead_strip",
InstanceMethods); InstanceMethods);
Values[3] = Values[3] =
EmitMethodList(std::string("\01L_OBJC_CATEGORY_CLASS_METHODS_") + ExtName, EmitMethodList("\01L_OBJC_CATEGORY_CLASS_METHODS_" + ExtName.str(),
"__OBJC,__cat_cls_meth,regular,no_dead_strip", "__OBJC,__cat_cls_meth,regular,no_dead_strip",
ClassMethods); ClassMethods);
if (Category) { if (Category) {
Values[4] = Values[4] =
EmitProtocolList(std::string("\01L_OBJC_CATEGORY_PROTOCOLS_") + ExtName, EmitProtocolList("\01L_OBJC_CATEGORY_PROTOCOLS_" + ExtName.str(),
Category->protocol_begin(), Category->protocol_begin(),
Category->protocol_end()); Category->protocol_end());
} else { } else {
@ -1934,7 +1929,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
// If there is no category @interface then there can be no properties. // If there is no category @interface then there can be no properties.
if (Category) { if (Category) {
Values[6] = EmitPropertyList(std::string("\01l_OBJC_$_PROP_LIST_")+ExtName, Values[6] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ExtName.str(),
OCD, Category, ObjCTypes); OCD, Category, ObjCTypes);
} else { } else {
Values[6] = llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy); Values[6] = llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy);
@ -1944,7 +1939,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
Values); Values);
llvm::GlobalVariable *GV = llvm::GlobalVariable *GV =
CreateMetadataVar(std::string("\01L_OBJC_CATEGORY_")+ExtName, Init, CreateMetadataVar("\01L_OBJC_CATEGORY_" + ExtName.str(), Init,
"__OBJC,__category,regular,no_dead_strip", "__OBJC,__category,regular,no_dead_strip",
4, true); 4, true);
DefinedCategories.push_back(GV); DefinedCategories.push_back(GV);
@ -1988,7 +1983,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
ObjCInterfaceDecl *Interface = ObjCInterfaceDecl *Interface =
const_cast<ObjCInterfaceDecl*>(ID->getClassInterface()); const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
llvm::Constant *Protocols = llvm::Constant *Protocols =
EmitProtocolList("\01L_OBJC_CLASS_PROTOCOLS_" + ID->getNameAsString(), EmitProtocolList("\01L_OBJC_CLASS_PROTOCOLS_" + ID->getName(),
Interface->protocol_begin(), Interface->protocol_begin(),
Interface->protocol_end()); Interface->protocol_end());
unsigned Flags = eClassFlags_Factory; unsigned Flags = eClassFlags_Factory;
@ -2046,7 +2041,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
Values[ 5] = llvm::ConstantInt::get(ObjCTypes.LongTy, Size); Values[ 5] = llvm::ConstantInt::get(ObjCTypes.LongTy, Size);
Values[ 6] = EmitIvarList(ID, false); Values[ 6] = EmitIvarList(ID, false);
Values[ 7] = Values[ 7] =
EmitMethodList("\01L_OBJC_INSTANCE_METHODS_" + ID->getNameAsString(), EmitMethodList("\01L_OBJC_INSTANCE_METHODS_" + ID->getName(),
"__OBJC,__inst_meth,regular,no_dead_strip", "__OBJC,__inst_meth,regular,no_dead_strip",
InstanceMethods); InstanceMethods);
// cache is always NULL. // cache is always NULL.
@ -2058,7 +2053,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
Values); Values);
llvm::GlobalVariable *GV = llvm::GlobalVariable *GV =
CreateMetadataVar(std::string("\01L_OBJC_CLASS_")+ClassName, Init, CreateMetadataVar("\01L_OBJC_CLASS_" + ClassName, Init,
"__OBJC,__class,regular,no_dead_strip", "__OBJC,__class,regular,no_dead_strip",
4, true); 4, true);
DefinedClasses.push_back(GV); DefinedClasses.push_back(GV);
@ -2174,7 +2169,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) {
std::vector<llvm::Constant*> Values(3); std::vector<llvm::Constant*> Values(3);
Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size);
Values[1] = BuildIvarLayout(ID, false); Values[1] = BuildIvarLayout(ID, false);
Values[2] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getNameAsString(), Values[2] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getName(),
ID, ID->getClassInterface(), ObjCTypes); ID, ID->getClassInterface(), ObjCTypes);
// Return null if no extension bits are used. // Return null if no extension bits are used.
@ -2183,7 +2178,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) {
llvm::Constant *Init = llvm::Constant *Init =
llvm::ConstantStruct::get(ObjCTypes.ClassExtensionTy, Values); llvm::ConstantStruct::get(ObjCTypes.ClassExtensionTy, Values);
return CreateMetadataVar("\01L_OBJC_CLASSEXT_" + ID->getNameAsString(), return CreateMetadataVar("\01L_OBJC_CLASSEXT_" + ID->getName(),
Init, "__OBJC,__class_ext,regular,no_dead_strip", Init, "__OBJC,__class_ext,regular,no_dead_strip",
4, true); 4, true);
} }
@ -2243,12 +2238,11 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
llvm::GlobalVariable *GV; llvm::GlobalVariable *GV;
if (ForClass) if (ForClass)
GV = CreateMetadataVar("\01L_OBJC_CLASS_VARIABLES_" + ID->getNameAsString(), GV = CreateMetadataVar("\01L_OBJC_CLASS_VARIABLES_" + ID->getName(),
Init, "__OBJC,__class_vars,regular,no_dead_strip", Init, "__OBJC,__class_vars,regular,no_dead_strip",
4, true); 4, true);
else else
GV = CreateMetadataVar("\01L_OBJC_INSTANCE_VARIABLES_" GV = CreateMetadataVar("\01L_OBJC_INSTANCE_VARIABLES_" + ID->getName(),
+ ID->getNameAsString(),
Init, "__OBJC,__instance_vars,regular,no_dead_strip", Init, "__OBJC,__instance_vars,regular,no_dead_strip",
4, true); 4, true);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy); return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy);
@ -2286,7 +2280,7 @@ llvm::Constant *CGObjCMac::GetMethodConstant(const ObjCMethodDecl *MD) {
return llvm::ConstantStruct::get(ObjCTypes.MethodTy, Method); return llvm::ConstantStruct::get(ObjCTypes.MethodTy, Method);
} }
llvm::Constant *CGObjCMac::EmitMethodList(const std::string &Name, llvm::Constant *CGObjCMac::EmitMethodList(llvm::Twine Name,
const char *Section, const char *Section,
const ConstantVector &Methods) { const ConstantVector &Methods) {
// Return null for empty list. // Return null for empty list.
@ -2325,7 +2319,7 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
} }
llvm::GlobalVariable * llvm::GlobalVariable *
CGObjCCommonMac::CreateMetadataVar(const std::string &Name, CGObjCCommonMac::CreateMetadataVar(llvm::Twine Name,
llvm::Constant *Init, llvm::Constant *Init,
const char *Section, const char *Section,
unsigned Align, unsigned Align,
@ -2985,7 +2979,8 @@ llvm::Constant *CGObjCCommonMac::GetClassName(IdentifierInfo *Ident) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_", Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_",
llvm::ConstantArray::get(VMContext, Ident->getName()), llvm::ConstantArray::get(VMContext,
Ident->getNameStart()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3434,7 +3429,8 @@ llvm::Constant *CGObjCCommonMac::GetPropertyName(IdentifierInfo *Ident) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_PROP_NAME_ATTR_", Entry = CreateMetadataVar("\01L_OBJC_PROP_NAME_ATTR_",
llvm::ConstantArray::get(VMContext, Ident->getName()), llvm::ConstantArray::get(VMContext,
Ident->getNameStart()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3506,11 +3502,11 @@ void CGObjCMac::FinishModule() {
llvm::raw_svector_ostream OS(Asm); llvm::raw_svector_ostream OS(Asm);
for (llvm::SetVector<IdentifierInfo*>::iterator I = LazySymbols.begin(), for (llvm::SetVector<IdentifierInfo*>::iterator I = LazySymbols.begin(),
e = LazySymbols.end(); I != e; ++I) e = LazySymbols.end(); I != e; ++I)
OS << "\t.lazy_reference .objc_class_name_" << (*I)->getName() << "\n"; OS << "\t.lazy_reference .objc_class_name_" << (*I)->getNameStr() << "\n";
for (llvm::SetVector<IdentifierInfo*>::iterator I = DefinedSymbols.begin(), for (llvm::SetVector<IdentifierInfo*>::iterator I = DefinedSymbols.begin(),
e = DefinedSymbols.end(); I != e; ++I) e = DefinedSymbols.end(); I != e; ++I)
OS << "\t.objc_class_name_" << (*I)->getName() << "=0\n" OS << "\t.objc_class_name_" << (*I)->getNameStr() << "=0\n"
<< "\t.globl .objc_class_name_" << (*I)->getName() << "\n"; << "\t.globl .objc_class_name_" << (*I)->getNameStr() << "\n";
CGM.getModule().setModuleInlineAsm(OS.str()); CGM.getModule().setModuleInlineAsm(OS.str());
} }
@ -4256,7 +4252,7 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer(
const ObjCInterfaceDecl *OID = ID->getClassInterface(); const ObjCInterfaceDecl *OID = ID->getClassInterface();
assert(OID && "CGObjCNonFragileABIMac::BuildClassRoTInitializer"); assert(OID && "CGObjCNonFragileABIMac::BuildClassRoTInitializer");
Values[ 6] = EmitProtocolList("\01l_OBJC_CLASS_PROTOCOLS_$_" Values[ 6] = EmitProtocolList("\01l_OBJC_CLASS_PROTOCOLS_$_"
+ OID->getNameAsString(), + OID->getName(),
OID->protocol_begin(), OID->protocol_begin(),
OID->protocol_end()); OID->protocol_end());
@ -4269,8 +4265,7 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer(
if (flags & CLS_META) if (flags & CLS_META)
Values[ 9] = llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy); Values[ 9] = llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy);
else else
Values[ 9] = Values[ 9] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getName(),
EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getNameAsString(),
ID, ID->getClassInterface(), ObjCTypes); ID, ID->getClassInterface(), ObjCTypes);
llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassRonfABITy, llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassRonfABITy,
Values); Values);
@ -4532,15 +4527,15 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
const ObjCCategoryDecl *Category = const ObjCCategoryDecl *Category =
Interface->FindCategoryDeclaration(OCD->getIdentifier()); Interface->FindCategoryDeclaration(OCD->getIdentifier());
if (Category) { if (Category) {
std::string ExtName(Interface->getNameAsString() + "_$_" + llvm::SmallString<256> ExtName;
OCD->getNameAsString()); llvm::raw_svector_ostream(ExtName) << Interface->getName() << "_$_"
<< OCD->getName();
Values[4] = EmitProtocolList("\01l_OBJC_CATEGORY_PROTOCOLS_$_" Values[4] = EmitProtocolList("\01l_OBJC_CATEGORY_PROTOCOLS_$_"
+ Interface->getNameAsString() + "_$_" + Interface->getName() + "_$_"
+ Category->getNameAsString(), + Category->getName(),
Category->protocol_begin(), Category->protocol_begin(),
Category->protocol_end()); Category->protocol_end());
Values[5] = Values[5] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ExtName.str(),
EmitPropertyList(std::string("\01l_OBJC_$_PROP_LIST_") + ExtName,
OCD, Category, ObjCTypes); OCD, Category, ObjCTypes);
} else { } else {
Values[4] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListnfABIPtrTy); Values[4] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListnfABIPtrTy);
@ -4593,8 +4588,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetMethodConstant(
/// struct _objc_method method_list[method_count]; /// struct _objc_method method_list[method_count];
/// } /// }
/// ///
llvm::Constant *CGObjCNonFragileABIMac::EmitMethodList( llvm::Constant *CGObjCNonFragileABIMac::EmitMethodList(llvm::Twine Name,
const std::string &Name,
const char *Section, const char *Section,
const ConstantVector &Methods) { const ConstantVector &Methods) {
// Return null for empty list. // Return null for empty list.
@ -4742,7 +4736,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Init,
Prefix + OID->getNameAsString()); Prefix + OID->getName());
GV->setAlignment( GV->setAlignment(
CGM.getTargetData().getPrefTypeAlignment(Init->getType())); CGM.getTargetData().getPrefTypeAlignment(Init->getType()));
GV->setSection("__DATA, __objc_const"); GV->setSection("__DATA, __objc_const");
@ -4763,7 +4757,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef(
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, false, new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, false,
llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::ExternalLinkage,
0, 0,
"\01l_OBJC_PROTOCOL_$_" + PD->getNameAsString()); "\01l_OBJC_PROTOCOL_$_" + PD->getName());
Entry->setSection("__DATA,__datacoal_nt,coalesced"); Entry->setSection("__DATA,__datacoal_nt,coalesced");
} }
@ -4795,8 +4789,6 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
if (Entry && Entry->hasInitializer()) if (Entry && Entry->hasInitializer())
return Entry; return Entry;
const char *ProtocolName = PD->getNameAsCString();
// Construct method lists. // Construct method lists.
std::vector<llvm::Constant*> InstanceMethods, ClassMethods; std::vector<llvm::Constant*> InstanceMethods, ClassMethods;
std::vector<llvm::Constant*> OptInstanceMethods, OptClassMethods; std::vector<llvm::Constant*> OptInstanceMethods, OptClassMethods;
@ -4826,28 +4818,27 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
// isa is NULL // isa is NULL
Values[0] = llvm::Constant::getNullValue(ObjCTypes.ObjectPtrTy); Values[0] = llvm::Constant::getNullValue(ObjCTypes.ObjectPtrTy);
Values[1] = GetClassName(PD->getIdentifier()); Values[1] = GetClassName(PD->getIdentifier());
Values[2] = EmitProtocolList( Values[2] = EmitProtocolList("\01l_OBJC_$_PROTOCOL_REFS_" + PD->getName(),
"\01l_OBJC_$_PROTOCOL_REFS_" + PD->getNameAsString(),
PD->protocol_begin(), PD->protocol_begin(),
PD->protocol_end()); PD->protocol_end());
Values[3] = EmitMethodList("\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_" Values[3] = EmitMethodList("\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_"
+ PD->getNameAsString(), + PD->getName(),
"__DATA, __objc_const", "__DATA, __objc_const",
InstanceMethods); InstanceMethods);
Values[4] = EmitMethodList("\01l_OBJC_$_PROTOCOL_CLASS_METHODS_" Values[4] = EmitMethodList("\01l_OBJC_$_PROTOCOL_CLASS_METHODS_"
+ PD->getNameAsString(), + PD->getName(),
"__DATA, __objc_const", "__DATA, __objc_const",
ClassMethods); ClassMethods);
Values[5] = EmitMethodList("\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_OPT_" Values[5] = EmitMethodList("\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_OPT_"
+ PD->getNameAsString(), + PD->getName(),
"__DATA, __objc_const", "__DATA, __objc_const",
OptInstanceMethods); OptInstanceMethods);
Values[6] = EmitMethodList("\01l_OBJC_$_PROTOCOL_CLASS_METHODS_OPT_" Values[6] = EmitMethodList("\01l_OBJC_$_PROTOCOL_CLASS_METHODS_OPT_"
+ PD->getNameAsString(), + PD->getName(),
"__DATA, __objc_const", "__DATA, __objc_const",
OptClassMethods); OptClassMethods);
Values[7] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + PD->getNameAsString(), Values[7] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + PD->getName(),
0, PD, ObjCTypes); 0, PD, ObjCTypes);
uint32_t Size = uint32_t Size =
CGM.getTargetData().getTypeAllocSize(ObjCTypes.ProtocolnfABITy); CGM.getTargetData().getTypeAllocSize(ObjCTypes.ProtocolnfABITy);
@ -4862,10 +4853,9 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
Entry->setInitializer(Init); Entry->setInitializer(Init);
} else { } else {
Entry = Entry =
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, false, new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy,
llvm::GlobalValue::WeakAnyLinkage, false, llvm::GlobalValue::WeakAnyLinkage, Init,
Init, "\01l_OBJC_PROTOCOL_$_" + PD->getName());
std::string("\01l_OBJC_PROTOCOL_$_")+ProtocolName);
Entry->setAlignment( Entry->setAlignment(
CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABITy)); CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABITy));
Entry->setSection("__DATA,__datacoal_nt,coalesced"); Entry->setSection("__DATA,__datacoal_nt,coalesced");
@ -4875,13 +4865,10 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
// Use this protocol meta-data to build protocol list table in section // Use this protocol meta-data to build protocol list table in section
// __DATA, __objc_protolist // __DATA, __objc_protolist
llvm::GlobalVariable *PTGV = new llvm::GlobalVariable( llvm::GlobalVariable *PTGV =
CGM.getModule(), new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABIPtrTy,
ObjCTypes.ProtocolnfABIPtrTy, false, false, llvm::GlobalValue::WeakAnyLinkage, Entry,
llvm::GlobalValue::WeakAnyLinkage, "\01l_OBJC_LABEL_PROTOCOL_$_" + PD->getName());
Entry,
std::string("\01l_OBJC_LABEL_PROTOCOL_$_")
+ProtocolName);
PTGV->setAlignment( PTGV->setAlignment(
CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABIPtrTy)); CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABIPtrTy));
PTGV->setSection("__DATA, __objc_protolist, coalesced, no_dead_strip"); PTGV->setSection("__DATA, __objc_protolist, coalesced, no_dead_strip");
@ -4899,7 +4886,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
/// @endcode /// @endcode
/// ///
llvm::Constant * llvm::Constant *
CGObjCNonFragileABIMac::EmitProtocolList(const std::string &Name, CGObjCNonFragileABIMac::EmitProtocolList(llvm::Twine Name,
ObjCProtocolDecl::protocol_iterator begin, ObjCProtocolDecl::protocol_iterator begin,
ObjCProtocolDecl::protocol_iterator end) { ObjCProtocolDecl::protocol_iterator end) {
std::vector<llvm::Constant*> ProtocolRefs; std::vector<llvm::Constant*> ProtocolRefs;
@ -4909,10 +4896,12 @@ CGObjCNonFragileABIMac::EmitProtocolList(const std::string &Name,
return llvm::Constant::getNullValue(ObjCTypes.ProtocolListnfABIPtrTy); return llvm::Constant::getNullValue(ObjCTypes.ProtocolListnfABIPtrTy);
// FIXME: We shouldn't need to do this lookup here, should we? // FIXME: We shouldn't need to do this lookup here, should we?
llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true); llvm::SmallString<256> TmpName;
Name.toVector(TmpName);
llvm::GlobalVariable *GV =
CGM.getModule().getGlobalVariable(TmpName.str(), true);
if (GV) if (GV)
return llvm::ConstantExpr::getBitCast(GV, return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListnfABIPtrTy);
ObjCTypes.ProtocolListnfABIPtrTy);
for (; begin != end; ++begin) for (; begin != end; ++begin)
ProtocolRefs.push_back(GetProtocolRef(*begin)); // Implemented??? ProtocolRefs.push_back(GetProtocolRef(*begin)); // Implemented???
@ -5683,8 +5672,8 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, false, new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, false,
llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::ExternalLinkage,
0, 0,
(std::string("OBJC_EHTYPE_$_") + ("OBJC_EHTYPE_$_" +
ID->getIdentifier()->getName())); ID->getIdentifier()->getNameStr()));
} }
// Otherwise we need to either make a new entry or fill in the // Otherwise we need to either make a new entry or fill in the
@ -5715,8 +5704,8 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, false, Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, false,
llvm::GlobalValue::WeakAnyLinkage, llvm::GlobalValue::WeakAnyLinkage,
Init, Init,
(std::string("OBJC_EHTYPE_$_") + ("OBJC_EHTYPE_$_" +
ID->getIdentifier()->getName())); ID->getIdentifier()->getNameStr()));
} }
if (CGM.getLangOptions().getVisibilityMode() == LangOptions::Hidden) if (CGM.getLangOptions().getVisibilityMode() == LangOptions::Hidden)