Skip to content

Commit 4e4752a

Browse files
authored
Merge pull request swiftlang#38024 from augusto2112/remove-emitFieldDescriptors
Remove IRGenModule::emitFieldDescriptors
2 parents 0d4642e + 3f64642 commit 4e4752a

File tree

4 files changed

+12
-62
lines changed

4 files changed

+12
-62
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ void IRGenModule::emitRuntimeRegistration() {
585585
if (SwiftProtocols.empty() && ProtocolConformances.empty() &&
586586
RuntimeResolvableTypes.empty() &&
587587
(!ObjCInterop || (ObjCProtocols.empty() && ObjCClasses.empty() &&
588-
ObjCCategoryDecls.empty())) &&
589-
FieldDescriptors.empty())
588+
ObjCCategoryDecls.empty())))
590589
return;
591590

592591
// Find the entry point.
@@ -748,10 +747,6 @@ void IRGenModule::emitRuntimeRegistration() {
748747
}
749748
}
750749

751-
if (!FieldDescriptors.empty()) {
752-
emitFieldDescriptors();
753-
}
754-
755750
RegIGF.Builder.CreateRetVoid();
756751
}
757752

@@ -3831,58 +3826,6 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() {
38313826
return var;
38323827
}
38333828

3834-
llvm::Constant *IRGenModule::emitFieldDescriptors() {
3835-
std::string sectionName;
3836-
switch (TargetInfo.OutputObjectFormat) {
3837-
case llvm::Triple::MachO:
3838-
sectionName = "__TEXT, __swift5_fieldmd, regular, no_dead_strip";
3839-
break;
3840-
case llvm::Triple::ELF:
3841-
case llvm::Triple::Wasm:
3842-
sectionName = "swift5_fieldmd";
3843-
break;
3844-
case llvm::Triple::XCOFF:
3845-
case llvm::Triple::COFF:
3846-
sectionName = ".sw5flmd$B";
3847-
break;
3848-
case llvm::Triple::GOFF:
3849-
case llvm::Triple::UnknownObjectFormat:
3850-
llvm_unreachable("Don't know how to emit field records table for "
3851-
"the selected object format.");
3852-
}
3853-
3854-
// Do nothing if the list is empty.
3855-
if (FieldDescriptors.empty())
3856-
return nullptr;
3857-
3858-
// Define the global variable for the field record list.
3859-
// We have to do this before defining the initializer since the entries will
3860-
// contain offsets relative to themselves.
3861-
auto arrayTy =
3862-
llvm::ArrayType::get(FieldDescriptorPtrTy, FieldDescriptors.size());
3863-
3864-
// FIXME: This needs to be a linker-local symbol in order for Darwin ld to
3865-
// resolve relocations relative to it.
3866-
auto var = new llvm::GlobalVariable(
3867-
Module, arrayTy,
3868-
/*isConstant*/ true, llvm::GlobalValue::PrivateLinkage,
3869-
/*initializer*/ nullptr, "\x01l_type_metadata_table");
3870-
3871-
SmallVector<llvm::Constant *, 8> elts;
3872-
for (auto *descriptor : FieldDescriptors)
3873-
elts.push_back(
3874-
llvm::ConstantExpr::getBitCast(descriptor, FieldDescriptorPtrTy));
3875-
3876-
var->setInitializer(llvm::ConstantArray::get(arrayTy, elts));
3877-
var->setSection(sectionName);
3878-
var->setAlignment(llvm::MaybeAlign(4));
3879-
3880-
disableAddressSanitizer(*this, var);
3881-
3882-
addUsedGlobal(var);
3883-
return var;
3884-
}
3885-
38863829
/// Fetch a global reference to a reference to the given Objective-C class.
38873830
/// The result is of type ObjCClassPtrTy->getPointerTo().
38883831
Address IRGenModule::getAddrOfObjCClassRef(ClassDecl *theClass) {

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ void IRGenModule::emitFieldDescriptor(const NominalTypeDecl *D) {
14371437

14381438
if (needsFieldDescriptor) {
14391439
FieldTypeMetadataBuilder builder(*this, D);
1440-
FieldDescriptors.push_back(builder.emit());
1440+
builder.emit();
14411441
}
14421442
}
14431443

lib/IRGen/IRGenModule.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,6 @@ class IRGenModule {
11551155
/// categories.
11561156
SmallVector<ExtensionDecl*, 4> ObjCCategoryDecls;
11571157

1158-
/// List of fields descriptors to register in runtime.
1159-
SmallVector<llvm::GlobalVariable *, 4> FieldDescriptors;
1160-
11611158
/// Map of Objective-C protocols and protocol references, bitcast to i8*.
11621159
/// The interesting global variables relating to an ObjC protocol.
11631160
struct ObjCProtocolPair {

test/IRGen/jit_metadata_table.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -use-jit | %FileCheck %s
2+
3+
4+
class A{}
5+
6+
// Check that only one copy of the type metadata table is emitted.
7+
// CHECK: @"\01l_type_metadata_table"
8+
// CHECK-NOT: @"\01l_type_metadata_table.1"
9+
10+

0 commit comments

Comments
 (0)