Skip to content

Commit 0da2562

Browse files
Merge pull request #42553 from aschwaighofer/irgen_metadata_instantiation_readonly_willreturn
IRGen: Set `readonly` and `willreturn` on meta data instantiation functions
2 parents 5ffdf0b + 4ad42e6 commit 0da2562

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
@@ -2276,7 +2276,8 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
22762276
// materialize the nominal type descriptor and call this thunk.
22772277
auto generateThunkFn = [&IGM,
22782278
checkPrespecialized](IRGenFunction &subIGF) {
2279-
subIGF.CurFn->setDoesNotAccessMemory();
2279+
subIGF.CurFn->setOnlyReadsMemory();
2280+
subIGF.CurFn->setWillReturn();
22802281
subIGF.CurFn->setCallingConv(IGM.SwiftCC);
22812282
IGM.setHasNoFramePointer(subIGF.CurFn);
22822283

@@ -2857,7 +2858,8 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
28572858
? "__swift_instantiateConcreteTypeFromMangledNameAbstract"
28582859
: "__swift_instantiateConcreteTypeFromMangledName";
28592860
auto generateInstantiationFn = [&IGM, request](IRGenFunction &subIGF) {
2860-
subIGF.CurFn->setDoesNotAccessMemory();
2861+
subIGF.CurFn->setOnlyReadsMemory();
2862+
subIGF.CurFn->setWillReturn();
28612863
IGM.setHasNoFramePointer(subIGF.CurFn);
28622864

28632865
auto params = subIGF.collectParameters();
@@ -2960,7 +2962,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
29602962
llvm::ConstantPointerNull::get(IGM.Int8PtrPtrTy)});
29612963
}
29622964
call->setDoesNotThrow();
2963-
call->setDoesNotAccessMemory();
2965+
call->setOnlyReadsMemory();
29642966
call->setCallingConv(IGM.SwiftCC);
29652967

29662968
// Store the result back to the cache. Metadata instantiation should
@@ -2995,7 +2997,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
29952997

29962998
auto call = IGF.Builder.CreateCall(instantiationFn, cache);
29972999
call->setDoesNotThrow();
2998-
call->setDoesNotAccessMemory();
3000+
call->setOnlyReadsMemory();
29993001

30003002
auto response = MetadataResponse::forComplete(call);
30013003

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)