Skip to content

Commit 4ad42e6

Browse files
committed
IRGen: Set readonly and willreturn on meta data instantiation functions
`readonly` (instead of `readnone`) because we want there to be a memory control dependence on potential preceeding availability checks. `willreturn` such that LLVM can remove calls without a use.
1 parent 81d3ad7 commit 4ad42e6

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,8 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
22722272
// materialize the nominal type descriptor and call this thunk.
22732273
auto generateThunkFn = [&IGM,
22742274
checkPrespecialized](IRGenFunction &subIGF) {
2275-
subIGF.CurFn->setDoesNotAccessMemory();
2275+
subIGF.CurFn->setOnlyReadsMemory();
2276+
subIGF.CurFn->setWillReturn();
22762277
subIGF.CurFn->setCallingConv(IGM.SwiftCC);
22772278
IGM.setHasNoFramePointer(subIGF.CurFn);
22782279

@@ -2853,7 +2854,8 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
28532854
? "__swift_instantiateConcreteTypeFromMangledNameAbstract"
28542855
: "__swift_instantiateConcreteTypeFromMangledName";
28552856
auto generateInstantiationFn = [&IGM, request](IRGenFunction &subIGF) {
2856-
subIGF.CurFn->setDoesNotAccessMemory();
2857+
subIGF.CurFn->setOnlyReadsMemory();
2858+
subIGF.CurFn->setWillReturn();
28572859
IGM.setHasNoFramePointer(subIGF.CurFn);
28582860

28592861
auto params = subIGF.collectParameters();
@@ -2956,7 +2958,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
29562958
llvm::ConstantPointerNull::get(IGM.Int8PtrPtrTy)});
29572959
}
29582960
call->setDoesNotThrow();
2959-
call->setDoesNotAccessMemory();
2961+
call->setOnlyReadsMemory();
29602962
call->setCallingConv(IGM.SwiftCC);
29612963

29622964
// Store the result back to the cache. Metadata instantatiation should
@@ -2991,7 +2993,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
29912993

29922994
auto call = IGF.Builder.CreateCall(instantiationFn, cache);
29932995
call->setDoesNotThrow();
2994-
call->setDoesNotAccessMemory();
2996+
call->setOnlyReadsMemory();
29952997

29962998
auto response = MetadataResponse::forComplete(call);
29972999

test/IRGen/default_function_ir_attributes.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func foo() {}
5656

5757
// helper function: __swift_instantiateConcreteTypeFromMangledName
5858
// CHECK-LABEL: define {{.*}} @__swift_instantiateConcreteTypeFromMangledName(
59-
// CHECK-SAME: [[ATTRS_NOINLINE_READNONE_NOUNWIND_NOFRAME:#[0-9]+]]
59+
// CHECK-SAME: [[ATTRS_NOINLINE_READONLY_NOUNWIND_NOFRAME:#[0-9]+]]
6060

6161
func use_metadata() -> Any.Type {
6262
return ((C) -> Int).self
@@ -96,7 +96,7 @@ func test_class_existential_cast_3(value: AnyObject) -> C & CP0 {
9696

9797
// metadata accessor
9898
// CHECK-LABEL: define {{.*}} @"$s30default_function_ir_attributes1CCMa"(
99-
// CHECK-SAME: [[ATTRS_NOINLINE_READNONE_NOUNWIND_NOFRAME]]
99+
// CHECK-SAME: [[ATTRS_NOINLINE_READNONE_NOUNWIND_NOFRAME:#[0-9]+]]
100100

101101
// helper function: dynamic_cast_existential_1_superclass_conditional
102102
// CHECK-LABEL: define {{.*}} @dynamic_cast_existential_1_superclass_conditional(
@@ -164,12 +164,13 @@ func test_computed_key_path_generic_thunks<T: P0 & Hashable>(value: T) -> KeyPat
164164

165165
// helper function: __swift_instantiateGenericMetadata
166166
// CHECK-LABEL: define {{.*}} @__swift_instantiateGenericMetadata(
167-
// CHECK-SAME: [[ATTRS_NOINLINE_READNONE_NOUNWIND_NOFRAME]]
167+
// CHECK-SAME: [[ATTRS_NOINLINE_READONLY_NOUNWIND_NOFRAME]]
168168

169169
// Use the presence of a target-cpu attribute as a litmus for
170170
// whether constructInitialAttributes was called, since it's very
171171
// unlikely that handrolled code generation would think to add one.
172172
// CHECK: attributes [[ATTRS_SIMPLE]] = { [[CUSTOM_ATTRS:.*target-cpu.*]] }{{$}}
173173
// CHECK-DAG: attributes [[ATTRS_NOINLINE_NOUNWIND]] = { noinline nounwind {{.*target-cpu.*}} }
174174
// CHECK-DAG: attributes [[ATTRS_NOINLINE_READNONE_NOUNWIND_NOFRAME]] = { noinline nounwind readnone {{.*}}"frame-pointer"="none"{{.*target-cpu.*}} }
175+
// CHECK-DAG: attributes [[ATTRS_NOINLINE_READONLY_NOUNWIND_NOFRAME]] = { noinline nounwind readonly willreturn {{.*}}"frame-pointer"="none"{{.*target-cpu.*}} }
175176
// CHECK-DAG: attributes [[ATTRS_NOUNWIND]] = { nounwind [[CUSTOM_ATTRS]] }{{$}}

test/IRGen/generic_metatypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,5 @@ func makeGenericMetatypes() {
145145
// CHECK-NOT: call void @llvm.lifetime.end
146146
// CHECK: ret %swift.metadata_response
147147

148-
// CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readnone }
148+
// CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readonly }
149149
// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind "

test/IRGen/generic_metatypes_future.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,5 @@ func makeGenericMetatypes() {
175175
// CHECK-NOT: call void @llvm.lifetime.end
176176
// CHECK: ret %swift.metadata_response
177177

178-
// CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readnone }
178+
// CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readonly }
179179
// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind "

0 commit comments

Comments
 (0)