mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILGen: use builtin prepareInitialization instead of zeroInitializer when generating SIL for Builtin.emplace
`zeroInitializer` is blocking optimizations, but it is not needed because the closure of `Builtin.emplace` will initialize the memory anyway. We only need to tell mandatory passes that this memory should be treated as initialized.
This commit is contained in:
@@ -2165,11 +2165,13 @@ static ManagedValue emitBuiltinEmplace(SILGenFunction &SGF,
|
||||
|
||||
auto buffer = dest->getAddressForInPlaceInitialization(SGF, loc);
|
||||
|
||||
// Zero-initialize the buffer.
|
||||
// Aside from providing a modicum of predictability if the memory isn't
|
||||
// actually initialized, this also serves to communicate to DI that the memory
|
||||
// Mark the buffer as initializedto communicate to DI that the memory
|
||||
// is considered initialized from this point.
|
||||
SGF.B.createZeroInitAddr(loc, buffer);
|
||||
auto markInit = getBuiltinValueDecl(Ctx, Ctx.getIdentifier("prepareInitialization"));
|
||||
SGF.B.createBuiltin(loc, markInit->getBaseIdentifier(),
|
||||
SILType::getEmptyTupleType(Ctx),
|
||||
SubstitutionMap(),
|
||||
buffer);
|
||||
|
||||
SILValue bufferPtr = SGF.B.createAddressToPointer(loc, buffer,
|
||||
SILType::getPrimitiveObjectType(SGF.getASTContext().TheRawPointerType),
|
||||
|
||||
@@ -18,7 +18,7 @@ struct Loadable {
|
||||
// CHECK-LABEL: sil {{.*}} @$s{{.*}}_in_place_loadable
|
||||
func emplace_in_place_loadable() -> Loadable {
|
||||
// CHECK: [[TMP:%.*]] = alloc_stack $Loadable
|
||||
// CHECK-NEXT: builtin "zeroInitializer"([[TMP]])
|
||||
// CHECK-NEXT: builtin "prepareInitialization"([[TMP]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[TMP]]
|
||||
// CHECK-NEXT: apply {{.*}}([[PTR]])
|
||||
// CHECK-NEXT: load [take] [[TMP]]
|
||||
@@ -29,7 +29,7 @@ func emplace_in_place_loadable() -> Loadable {
|
||||
// CHECK-LABEL: sil {{.*}} @$s{{.*}}_in_place_ao
|
||||
// CHECK: bb0([[OUT:%.*]] : $*AO):
|
||||
func emplace_in_place_ao() -> AO {
|
||||
// CHECK: builtin "zeroInitializer"([[OUT]])
|
||||
// CHECK: builtin "prepareInitialization"([[OUT]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[OUT]]
|
||||
// CHECK-NEXT: apply [[FN:%.*]]([[PTR]])
|
||||
// CHECK-NEXT: destroy_value [[FN]]
|
||||
@@ -42,7 +42,7 @@ func emplace_in_place_ao() -> AO {
|
||||
// CHECK: bb0([[INOUT:%.*]] : $*Loadable):
|
||||
func emplace_assign_loadable(_ x: inout Loadable) {
|
||||
// CHECK: [[TMP:%.*]] = alloc_stack $Loadable
|
||||
// CHECK-NEXT: builtin "zeroInitializer"([[TMP]])
|
||||
// CHECK-NEXT: builtin "prepareInitialization"([[TMP]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[TMP]]
|
||||
// CHECK-NEXT: apply {{.*}}([[PTR]])
|
||||
// CHECK-NEXT: [[RESULT:%.*]] = load [take] [[TMP]]
|
||||
@@ -57,7 +57,7 @@ func emplace_assign_loadable(_ x: inout Loadable) {
|
||||
// CHECK: bb0([[INOUT:%.*]] : $*AO):
|
||||
func emplace_assign_ao(_ x: inout AO) {
|
||||
// CHECK: [[TMP:%.*]] = alloc_stack $AO
|
||||
// CHECK-NEXT: builtin "zeroInitializer"([[TMP]])
|
||||
// CHECK-NEXT: builtin "prepareInitialization"([[TMP]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[TMP]]
|
||||
// CHECK-NEXT: apply {{.*}}([[PTR]])
|
||||
// CHECK-NEXT: [[WRITE:%.*]] = begin_access [modify] [unknown] [[INOUT]]
|
||||
@@ -70,7 +70,7 @@ func emplace_assign_ao(_ x: inout AO) {
|
||||
// CHECK-LABEL: sil {{.*}} @$s{{.*}}_ignore_loadable
|
||||
func emplace_ignore_loadable() {
|
||||
// CHECK: [[TMP:%.*]] = alloc_stack $Loadable
|
||||
// CHECK-NEXT: builtin "zeroInitializer"([[TMP]])
|
||||
// CHECK-NEXT: builtin "prepareInitialization"([[TMP]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[TMP]]
|
||||
// CHECK-NEXT: apply {{.*}}([[PTR]])
|
||||
// CHECK-NEXT: [[RESULT:%.*]] = load [take] [[TMP]]
|
||||
@@ -83,7 +83,7 @@ func emplace_ignore_loadable() {
|
||||
// CHECK-LABEL: sil {{.*}} @$s{{.*}}_ignore_ao
|
||||
func emplace_ignore_ao() {
|
||||
// CHECK: [[TMP:%.*]] = alloc_stack $AO
|
||||
// CHECK-NEXT: builtin "zeroInitializer"([[TMP]])
|
||||
// CHECK-NEXT: builtin "prepareInitialization"([[TMP]])
|
||||
// CHECK-NEXT: [[PTR:%.*]] = address_to_pointer {{.*}} [[TMP]]
|
||||
// CHECK-NEXT: apply {{.*}}([[PTR]])
|
||||
// CHECK-NEXT: ignored_use [[TMP]]
|
||||
|
||||
Reference in New Issue
Block a user