Skip to content

Commit ffee344

Browse files
committed
add enum
1 parent 6ce0f8e commit ffee344

File tree

8 files changed

+90
-63
lines changed

8 files changed

+90
-63
lines changed

lib/IRGen/GenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14031403
IGF.IGM.getClangASTContext().getObjCEncodingForType(clangTy, encoding);
14041404

14051405
auto globalString = IGF.IGM.getAddrOfGlobalString(
1406-
encoding, IRGenModule::ObjCMethodTypeSectionName);
1406+
encoding, CStringSectionType::ObjCMethodType);
14071407
out.add(globalString);
14081408
return;
14091409
}

lib/IRGen/GenClass.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,8 @@ namespace {
14641464

14651465
// struct category_t {
14661466
// char const *name;
1467-
fields.add(IGM.getAddrOfGlobalString(
1468-
CategoryName, IRGenModule::ObjCClassNameSectionName));
1467+
fields.add(IGM.getAddrOfGlobalString(CategoryName,
1468+
CStringSectionType::ObjCClassName));
14691469
// const class_t *theClass;
14701470
fields.add(getClassMetadataRef());
14711471
// const method_list_t *instanceMethods;
@@ -1504,8 +1504,8 @@ namespace {
15041504
// Class super;
15051505
fields.addNullPointer(IGM.Int8PtrTy);
15061506
// char const *name;
1507-
fields.add(IGM.getAddrOfGlobalString(
1508-
getEntityName(nameBuffer), IRGenModule::ObjCClassNameSectionName));
1507+
fields.add(IGM.getAddrOfGlobalString(getEntityName(nameBuffer),
1508+
CStringSectionType::ObjCClassName));
15091509
// const protocol_list_t *baseProtocols;
15101510
fields.add(buildProtocolList(weakLinkage));
15111511
// const method_list_t *requiredInstanceMethods;
@@ -1727,7 +1727,7 @@ namespace {
17271727

17281728
llvm::SmallString<64> buffer;
17291729
Name = IGM.getAddrOfGlobalString(getClass()->getObjCRuntimeName(buffer),
1730-
IRGenModule::ObjCClassNameSectionName);
1730+
CStringSectionType::ObjCClassName);
17311731
return Name;
17321732
}
17331733

@@ -2091,10 +2091,10 @@ namespace {
20912091
else
20922092
fields.addNullPointer(IGM.PtrTy);
20932093

2094-
fields.add(IGM.getAddrOfGlobalString(
2095-
name, IRGenModule::ObjCMethodNameSectionName));
2096-
fields.add(IGM.getAddrOfGlobalString(
2097-
typeEnc, IRGenModule::ObjCMethodTypeSectionName));
2094+
fields.add(
2095+
IGM.getAddrOfGlobalString(name, CStringSectionType::ObjCMethodName));
2096+
fields.add(IGM.getAddrOfGlobalString(typeEnc,
2097+
CStringSectionType::ObjCMethodType));
20982098

20992099
Size size;
21002100
Alignment alignment;
@@ -2232,9 +2232,9 @@ namespace {
22322232
auto fields = properties.beginStruct();
22332233
fields.add(
22342234
IGM.getAddrOfGlobalString(prop->getObjCPropertyName().str(),
2235-
IRGenModule::ObjCPropertyNameSectionName));
2235+
CStringSectionType::ObjCPropertyName));
22362236
fields.add(IGM.getAddrOfGlobalString(
2237-
propertyAttributes, IRGenModule::ObjCPropertyNameSectionName));
2237+
propertyAttributes, CStringSectionType::ObjCPropertyName));
22382238
fields.finishAndAddTo(properties);
22392239
}
22402240

lib/IRGen/GenConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ llvm::Constant *irgen::emitAddrOfConstantString(IRGenModule &IGM,
7979
case StringLiteralInst::Encoding::Bytes:
8080
case StringLiteralInst::Encoding::UTF8:
8181
case StringLiteralInst::Encoding::UTF8_OSLOG:
82-
return IGM.getAddrOfGlobalString(SLI->getValue(), false, useOSLogEncoding);
82+
return IGM.getAddrOfGlobalString(
83+
SLI->getValue(), useOSLogEncoding ? CStringSectionType::OSLogString
84+
: CStringSectionType::Default);
8385

8486
case StringLiteralInst::Encoding::ObjCSelector:
8587
llvm_unreachable("cannot get the address of an Objective-C selector");

lib/IRGen/GenDecl.cpp

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class ObjCProtocolInitializerVisitor
297297
// protocol. If so, use it.
298298
SmallString<32> buf;
299299
auto protocolName = IGM.getAddrOfGlobalString(
300-
proto->getObjCRuntimeName(buf), IRGenModule::ObjCClassNameSectionName);
300+
proto->getObjCRuntimeName(buf), CStringSectionType::ObjCClassName);
301301

302302
auto existing = Builder.CreateCall(objc_getProtocol, protocolName);
303303
auto isNull = Builder.CreateICmpEQ(existing,
@@ -4240,10 +4240,10 @@ static TypeEntityReference
42404240
getObjCClassByNameReference(IRGenModule &IGM, ClassDecl *cls) {
42414241
auto kind = TypeReferenceKind::DirectObjCClassName;
42424242
SmallString<64> objcRuntimeNameBuffer;
4243-
auto ref = IGM.getAddrOfGlobalString(
4244-
cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4245-
/*willBeRelativelyAddressed=*/true,
4246-
/*useOSLogSection=*/false, IRGenModule::ObjCClassNameSectionName);
4243+
auto ref =
4244+
IGM.getAddrOfGlobalString(cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4245+
CStringSectionType::ObjCClassName,
4246+
/*willBeRelativelyAddressed=*/true);
42474247

42484248
return TypeEntityReference(kind, ref);
42494249
}
@@ -4800,9 +4800,9 @@ void IRGenModule::emitAccessibleFunction(StringRef sectionName,
48004800

48014801
// -- Field: Name (record name)
48024802
{
4803-
llvm::Constant *name =
4804-
getAddrOfGlobalString(func.getFunctionName(),
4805-
/*willBeRelativelyAddressed=*/true);
4803+
llvm::Constant *name = getAddrOfGlobalString(
4804+
func.getFunctionName(), CStringSectionType::Default,
4805+
/*willBeRelativelyAddressed=*/true);
48064806
fields.addRelativeAddress(name);
48074807
}
48084808

@@ -6016,12 +6016,6 @@ Address IRGenFunction::createAlloca(llvm::Type *type,
60166016
return Address(alloca, type, alignment);
60176017
}
60186018

6019-
llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
6020-
const char *sectionName) {
6021-
return getAddrOfGlobalString(data, /*willBeRelativelyAddressed=*/false,
6022-
/*useOSLogSection=*/false, sectionName);
6023-
}
6024-
60256019
/// Get or create a global string constant.
60266020
///
60276021
/// \returns an i8* with a null terminator; note that embedded nulls
@@ -6030,15 +6024,35 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
60306024
/// FIXME: willBeRelativelyAddressed is only needed to work around an ld64 bug
60316025
/// resolving relative references to coalesceable symbols.
60326026
/// It should be removed when fixed. rdar://problem/22674524
6033-
llvm::Constant *IRGenModule::getAddrOfGlobalString(
6034-
StringRef data, bool willBeRelativelyAddressed, bool useOSLogSection,
6035-
StringRef sectionName) {
6036-
useOSLogSection = useOSLogSection &&
6037-
TargetInfo.OutputObjectFormat == llvm::Triple::MachO;
6027+
llvm::Constant *
6028+
IRGenModule::getAddrOfGlobalString(StringRef data, CStringSectionType type,
6029+
bool willBeRelativelyAddressed) {
6030+
if (TargetInfo.OutputObjectFormat != llvm::Triple::MachO)
6031+
type = CStringSectionType::Default;
6032+
StringRef sectionName;
6033+
switch (type) {
6034+
case CStringSectionType::Default:
6035+
sectionName = "";
6036+
break;
6037+
case CStringSectionType::ObjCClassName:
6038+
sectionName = ObjCClassNameSectionName;
6039+
break;
6040+
case CStringSectionType::ObjCMethodName:
6041+
sectionName = ObjCMethodNameSectionName;
6042+
break;
6043+
case CStringSectionType::ObjCMethodType:
6044+
sectionName = ObjCMethodTypeSectionName;
6045+
break;
6046+
case CStringSectionType::ObjCPropertyName:
6047+
sectionName = ObjCPropertyNameSectionName;
6048+
break;
6049+
case CStringSectionType::OSLogString:
6050+
sectionName = OSLogStringSectionName;
6051+
break;
6052+
}
60386053

60396054
// Check whether this string already exists.
6040-
auto &entry = useOSLogSection ? GlobalOSLogStrings[data] :
6041-
GlobalStrings[data];
6055+
auto &entry = GlobalStrings[type][data];
60426056

60436057
if (entry.second) {
60446058
// FIXME: Clear unnamed_addr if the global will be relative referenced
@@ -6060,9 +6074,6 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(
60606074
(llvm::Twine(".nul") + llvm::Twine(i)).toVector(name);
60616075
}
60626076

6063-
sectionName =
6064-
useOSLogSection ? "__TEXT,__oslogstring,cstring_literals" : sectionName;
6065-
60666077
entry = createStringConstant(data, willBeRelativelyAddressed,
60676078
sectionName, name);
60686079
return entry.second;
@@ -6074,9 +6085,11 @@ IRGenModule::getAddrOfGlobalIdentifierString(StringRef data,
60746085
if (Lexer::identifierMustAlwaysBeEscaped(data)) {
60756086
llvm::SmallString<256> name;
60766087
Mangle::Mangler::appendRawIdentifierForRuntime(data, name);
6077-
return getAddrOfGlobalString(name, willBeRelativelyAddressed);
6088+
return getAddrOfGlobalString(name, CStringSectionType::Default,
6089+
willBeRelativelyAddressed);
60786090
}
6079-
return getAddrOfGlobalString(data, willBeRelativelyAddressed);
6091+
return getAddrOfGlobalString(data, CStringSectionType::Default,
6092+
willBeRelativelyAddressed);
60806093
}
60816094

60826095
/// Get or create a global UTF-16 string constant.

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
11431143
// null otherwise.
11441144
if (!pattern->getObjCString().empty()) {
11451145
auto objcString = getAddrOfGlobalString(pattern->getObjCString(),
1146+
CStringSectionType::Default,
11461147
/*relatively addressed*/ true);
11471148
fields.addRelativeAddress(objcString);
11481149
} else {

lib/IRGen/GenMeta.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ namespace {
845845
IRGenMangler mangler(IGM.Context);
846846
auto mangledName = mangler.mangleAnonymousDescriptorName(Name);
847847
auto mangledNameConstant =
848-
IGM.getAddrOfGlobalString(mangledName,
849-
/*willBeRelativelyAddressed*/ true);
848+
IGM.getAddrOfGlobalString(mangledName, CStringSectionType::Default,
849+
/*willBeRelativelyAddressed*/ true);
850850
B.addRelativeAddress(mangledNameConstant);
851851
}
852852

@@ -1277,6 +1277,7 @@ namespace {
12771277
llvm::Constant *global = nullptr;
12781278
if (!AssociatedTypeNames.empty()) {
12791279
global = IGM.getAddrOfGlobalString(AssociatedTypeNames,
1280+
CStringSectionType::Default,
12801281
/*willBeRelativelyAddressed=*/true);
12811282
}
12821283
B.addRelativeAddressOrNull(global);
@@ -1515,9 +1516,10 @@ namespace {
15151516
name.pop_back();
15161517
assert(name.back() == '\0');
15171518
}
1518-
1519-
auto nameStr = IGM.getAddrOfGlobalString(name,
1520-
/*willBeRelativelyAddressed*/ true);
1519+
1520+
auto nameStr =
1521+
IGM.getAddrOfGlobalString(name, CStringSectionType::Default,
1522+
/*willBeRelativelyAddressed*/ true);
15211523
B.addRelativeAddress(nameStr);
15221524
}
15231525

lib/IRGen/GenObjC.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ static llvm::Constant *getObjCEncodingForTypes(IRGenModule &IGM,
13191319
encodingString += fixedParamsString;
13201320
encodingString += paramsString;
13211321
return IGM.getAddrOfGlobalString(encodingString,
1322-
IRGenModule::ObjCMethodTypeSectionName);
1322+
CStringSectionType::ObjCMethodType);
13231323
}
13241324

13251325
static llvm::Constant *
@@ -1330,19 +1330,19 @@ getObjectEncodingFromClangNode(IRGenModule &IGM, Decl *d,
13301330
auto clangDecl = d->getClangNode().castAsDecl();
13311331
auto &clangASTContext = IGM.getClangASTContext();
13321332
std::string typeStr;
1333-
const char *sectionName;
1333+
CStringSectionType sectionType;
13341334
if (auto objcMethodDecl = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
13351335
typeStr = clangASTContext.getObjCEncodingForMethodDecl(
13361336
objcMethodDecl, useExtendedEncoding /*extended*/);
1337-
sectionName = IRGenModule::ObjCMethodTypeSectionName;
1337+
sectionType = CStringSectionType::ObjCMethodType;
13381338
}
13391339
if (auto objcPropertyDecl = dyn_cast<clang::ObjCPropertyDecl>(clangDecl)) {
13401340
typeStr = clangASTContext.getObjCEncodingForPropertyDecl(objcPropertyDecl,
13411341
nullptr);
1342-
sectionName = IRGenModule::ObjCPropertyNameSectionName;
1342+
sectionType = CStringSectionType::ObjCPropertyName;
13431343
}
13441344
if (!typeStr.empty()) {
1345-
return IGM.getAddrOfGlobalString(typeStr.c_str(), sectionName);
1345+
return IGM.getAddrOfGlobalString(typeStr.c_str(), sectionType);
13461346
}
13471347
}
13481348
return nullptr;
@@ -1439,7 +1439,7 @@ irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM, VarDecl *property) {
14391439
TypeStr += "@0:";
14401440
TypeStr += llvm::itostr(PtrSize.getValue());
14411441
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1442-
TypeStr.c_str(), IRGenModule::ObjCMethodTypeSectionName);
1442+
TypeStr.c_str(), CStringSectionType::ObjCMethodType);
14431443
descriptor.silFunction = nullptr;
14441444
descriptor.impl = getObjCGetterPointer(IGM, property, descriptor.silFunction);
14451445
return descriptor;
@@ -1517,7 +1517,7 @@ irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
15171517
clangASTContext.getObjCEncodingForType(clangType, TypeStr);
15181518
TypeStr += llvm::itostr(ParmOffset);
15191519
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1520-
TypeStr.c_str(), IRGenModule::ObjCMethodTypeSectionName);
1520+
TypeStr.c_str(), CStringSectionType::ObjCMethodType);
15211521
descriptor.silFunction = nullptr;
15221522
descriptor.impl = getObjCSetterPointer(IGM, property, descriptor.silFunction);
15231523
return descriptor;
@@ -1623,8 +1623,8 @@ void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
16231623
auto ptrSize = IGM.getPointerSize().getValue();
16241624
llvm::SmallString<8> signature;
16251625
signature = "v" + llvm::itostr(ptrSize * 2) + "@0:" + llvm::itostr(ptrSize);
1626-
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1627-
signature, IRGenModule::ObjCMethodTypeSectionName);
1626+
descriptor.typeEncoding =
1627+
IGM.getAddrOfGlobalString(signature, CStringSectionType::ObjCMethodType);
16281628

16291629
/// The third element is the method implementation pointer.
16301630
descriptor.impl = llvm::ConstantExpr::getBitCast(objcImpl, IGM.Int8PtrTy);

lib/IRGen/IRGenModule.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,15 @@ struct AccessibleFunction {
669669
llvm::Constant *address);
670670
};
671671

672+
enum class CStringSectionType {
673+
Default,
674+
ObjCClassName,
675+
ObjCMethodName,
676+
ObjCMethodType,
677+
ObjCPropertyName,
678+
OSLogString,
679+
};
680+
672681
/// IRGenModule - Primary class for emitting IR for global declarations.
673682
///
674683
class IRGenModule {
@@ -1203,12 +1212,10 @@ class IRGenModule {
12031212
std::pair<llvm::GlobalVariable *, llvm::Constant *> createStringConstant(
12041213
StringRef Str, bool willBeRelativelyAddressed = false,
12051214
StringRef sectionName = "", StringRef name = "");
1206-
llvm::Constant *getAddrOfGlobalString(StringRef utf8,
1207-
bool willBeRelativelyAddressed = false,
1208-
bool useOSLogSection = false,
1209-
StringRef sectionName = "");
1210-
llvm::Constant *getAddrOfGlobalString(StringRef utf8,
1211-
const char *sectionName);
1215+
llvm::Constant *getAddrOfGlobalString(
1216+
StringRef utf8,
1217+
CStringSectionType sectionType = CStringSectionType::Default,
1218+
bool willBeRelativelyAddressed = false);
12121219
llvm::Constant *getAddrOfGlobalUTF16String(StringRef utf8);
12131220
llvm::Constant *
12141221
getAddrOfGlobalIdentifierString(StringRef utf8,
@@ -1332,10 +1339,10 @@ class IRGenModule {
13321339
llvm::DenseMap<LinkEntity, llvm::Constant*> GlobalGOTEquivalents;
13331340
llvm::DenseMap<LinkEntity, llvm::Function*> GlobalFuncs;
13341341
llvm::DenseSet<const clang::Decl *> GlobalClangDecls;
1335-
llvm::StringMap<std::pair<llvm::GlobalVariable*, llvm::Constant*>>
1336-
GlobalStrings;
1337-
llvm::StringMap<std::pair<llvm::GlobalVariable*, llvm::Constant*>>
1338-
GlobalOSLogStrings;
1342+
llvm::DenseMap<
1343+
CStringSectionType,
1344+
llvm::StringMap<std::pair<llvm::GlobalVariable *, llvm::Constant *>>>
1345+
GlobalStrings;
13391346
llvm::StringMap<llvm::Constant*> GlobalUTF16Strings;
13401347
llvm::StringMap<std::pair<llvm::GlobalVariable*, llvm::Constant*>>
13411348
StringsForTypeRef;
@@ -1554,6 +1561,8 @@ class IRGenModule {
15541561
"__TEXT,__objc_methtype,cstring_literals";
15551562
static constexpr const char ObjCPropertyNameSectionName[] =
15561563
"__TEXT,__objc_methname,cstring_literals";
1564+
static constexpr const char OSLogStringSectionName[] =
1565+
"__TEXT,__oslogstring,cstring_literals";
15571566

15581567
/// Returns the special builtin types that should be emitted in the stdlib
15591568
/// module.

0 commit comments

Comments
 (0)