mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Don't hardcode the function representation of builtin "once". Make emitLazyGlobalInitializer retrieve the convention from getBuiltinValueDecl.
This commit is contained in:
@@ -975,10 +975,12 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
|
||||
PatternBindingDecl *binding,
|
||||
unsigned pbdEntry) {
|
||||
ASTContext &C = M.getASTContext();
|
||||
Type initType = FunctionType::get(
|
||||
TupleType::getEmpty(C), TupleType::getEmpty(C),
|
||||
FunctionType::ExtInfo()
|
||||
.withRepresentation(FunctionType::Representation::Thin));
|
||||
auto *onceBuiltin =
|
||||
cast<FuncDecl>(getBuiltinValueDecl(C, C.getIdentifier("once")));
|
||||
auto blockParam = onceBuiltin->getParameterLists()[0]->get(1);
|
||||
auto *type = blockParam->getType()->castTo<FunctionType>();
|
||||
Type initType = FunctionType::get(TupleType::getEmpty(C),
|
||||
TupleType::getEmpty(C), type->getExtInfo());
|
||||
auto initSILType = getLoweredType(initType).castTo<SILFunctionType>();
|
||||
|
||||
auto *f =
|
||||
|
||||
@@ -321,8 +321,8 @@ static SILFunction *getCalleeOfOnceCall(BuiltinInst *BI) {
|
||||
|
||||
auto Callee = BI->getOperand(1);
|
||||
assert(Callee->getType().castTo<SILFunctionType>()->getRepresentation()
|
||||
== SILFunctionTypeRepresentation::Thin &&
|
||||
"Expected thin function representation!");
|
||||
== SILFunctionTypeRepresentation::CFunctionPointer &&
|
||||
"Expected C function representation!");
|
||||
|
||||
if (auto *FR = dyn_cast<FunctionRefInst>(Callee))
|
||||
return FR->getReferencedFunction();
|
||||
|
||||
@@ -54,5 +54,5 @@ extension A {
|
||||
// CHECK: store i64 {{.*}}, i64* getelementptr inbounds ([[INT]], [[INT]]* @_T07globals2g0Sivp, i32 0, i32 0), align 8
|
||||
|
||||
// FIXME: give these initializers a real mangled name
|
||||
// CHECK: define internal swiftcc void @globalinit_{{.*}}func0() {{.*}} {
|
||||
// CHECK: define internal void @globalinit_{{.*}}func0() {{.*}} {
|
||||
// CHECK: store i64 5, i64* getelementptr inbounds (%TSi, %TSi* @_T07globals1AV3fooSivpZ, i32 0, i32 0), align 8
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// CHECK: @_T012lazy_globals1ySivp = hidden global %TSi zeroinitializer, align 8
|
||||
// CHECK: @_T012lazy_globals1zSivp = hidden global %TSi zeroinitializer, align 8
|
||||
|
||||
// CHECK: define internal swiftcc void @globalinit_[[T]]_func0() {{.*}} {
|
||||
// CHECK: define internal void @globalinit_[[T]]_func0() {{.*}} {
|
||||
// CHECK: entry:
|
||||
// CHECK: store i64 1, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1xSivp, i32 0, i32 0), align 8
|
||||
// CHECK: store i64 2, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1ySivp, i32 0, i32 0), align 8
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// RUN: %target-swift-frontend -parse-as-library -emit-silgen -enable-sil-ownership %s | %FileCheck %s
|
||||
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func0 : $@convention(thin) () -> () {
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func0 : $@convention(c) () -> () {
|
||||
// CHECK: alloc_global @_T012lazy_globals1xSiv
|
||||
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int
|
||||
// CHECK: store {{%.*}} to [trivial] [[XADDR]] : $*Int
|
||||
@@ -8,15 +8,15 @@
|
||||
// CHECK: sil hidden [global_init] @_T012lazy_globals1xSivau : $@convention(thin) () -> Builtin.RawPointer {
|
||||
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token0 : $*Builtin.Word
|
||||
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(thin) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $()
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(c) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
|
||||
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int
|
||||
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
|
||||
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
|
||||
// CHECK: }
|
||||
var x: Int = 0
|
||||
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func1 : $@convention(thin) () -> () {
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func1 : $@convention(c) () -> () {
|
||||
// CHECK: alloc_global @_T012lazy_globals3FooV3fooSivpZ
|
||||
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int
|
||||
// CHECK: store {{.*}} to [trivial] [[XADDR]] : $*Int
|
||||
@@ -26,8 +26,8 @@ struct Foo {
|
||||
// CHECK: sil hidden [global_init] @_T012lazy_globals3FooV3fooSivau : $@convention(thin) () -> Builtin.RawPointer {
|
||||
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token1 : $*Builtin.Word
|
||||
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(thin) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $()
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(c) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
|
||||
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int
|
||||
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
|
||||
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
|
||||
@@ -40,7 +40,7 @@ struct Foo {
|
||||
static var initialized: Int = 57
|
||||
}
|
||||
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func3 : $@convention(thin) () -> () {
|
||||
// CHECK: sil private @globalinit_[[T:.*]]_func3 : $@convention(c) () -> () {
|
||||
// CHECK: alloc_global @_T012lazy_globals3BarO3barSivpZ
|
||||
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int
|
||||
// CHECK: store {{.*}} to [trivial] [[XADDR]] : $*Int
|
||||
@@ -50,8 +50,8 @@ enum Bar {
|
||||
// CHECK: sil hidden [global_init] @_T012lazy_globals3BarO3barSivau : $@convention(thin) () -> Builtin.RawPointer {
|
||||
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token3 : $*Builtin.Word
|
||||
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(thin) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $()
|
||||
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(c) () -> ()
|
||||
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
|
||||
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int
|
||||
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
|
||||
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
|
||||
@@ -63,13 +63,13 @@ enum Bar {
|
||||
|
||||
func f() -> (Int, Int) { return (1, 2) }
|
||||
|
||||
// CHECK: sil private @globalinit_[[T]]_func4 : $@convention(thin) () -> () {
|
||||
// CHECK: sil private @globalinit_[[T]]_func4 : $@convention(c) () -> () {
|
||||
// CHECK: function_ref @_T012lazy_globals1fSi_SityF : $@convention(thin) () -> (Int, Int)
|
||||
// CHECK: sil hidden [global_init] @_T012lazy_globals2a1Sivau : $@convention(thin) () -> Builtin.RawPointer
|
||||
// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(thin) () -> ()
|
||||
// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(c) () -> ()
|
||||
// CHECK: global_addr @_T012lazy_globals2a1Sivp : $*Int
|
||||
// CHECK: sil hidden [global_init] @_T012lazy_globals2b1Sivau : $@convention(thin) () -> Builtin.RawPointer {
|
||||
// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(thin) () -> ()
|
||||
// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(c) () -> ()
|
||||
// CHECK: global_addr @_T012lazy_globals2b1Sivp : $*Int
|
||||
var (a1, b1) = f()
|
||||
|
||||
|
||||
@@ -627,7 +627,7 @@ func force_global_observing_property_setter() {
|
||||
}
|
||||
|
||||
// The property is initialized with "zero".
|
||||
// CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(thin) () -> () {
|
||||
// CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(c) () -> () {
|
||||
// CHECK: bb0:
|
||||
// CHECK-NEXT: alloc_global @_T010properties25global_observing_propertySiv
|
||||
// CHECK-NEXT: %1 = global_addr @_T010properties25global_observing_propertySivp : $*Int
|
||||
|
||||
@@ -213,7 +213,7 @@ sil_global private @globalinit_token0 : $Builtin.Word
|
||||
sil_global @MyConst : $Int32
|
||||
|
||||
// globalinit_func0
|
||||
sil private @globalinit_func0 : $@convention(thin) () -> () {
|
||||
sil private @globalinit_func0 : $@convention(c) () -> () {
|
||||
bb0:
|
||||
%0 = global_addr @MyConst : $*Int32 // user: %3
|
||||
%1 = integer_literal $Builtin.Int32, 0 // user: %2
|
||||
@@ -229,8 +229,8 @@ bb0:
|
||||
%1 = global_addr @globalinit_token0 : $*Builtin.Word // user: %2
|
||||
%2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer // user: %5
|
||||
// function_ref globalinit_func0
|
||||
%3 = function_ref @globalinit_func0 : $@convention(thin) () -> () // user: %4
|
||||
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $()
|
||||
%3 = function_ref @globalinit_func0 : $@convention(c) () -> () // user: %4
|
||||
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $()
|
||||
%6 = global_addr @MyConst : $*Int32 // user: %7
|
||||
%7 = address_to_pointer %6 : $*Int32 to $Builtin.RawPointer // user: %8
|
||||
return %7 : $Builtin.RawPointer // id: %8
|
||||
|
||||
@@ -25,8 +25,8 @@ sil_global private @globalinit_token0 : $Builtin.Word
|
||||
// CHECK-NEXT: }
|
||||
sil_global @_Tv2ch1xSi : $Outer
|
||||
|
||||
// CHECK-LABEL: sil private @globalinit_func0 : $@convention(thin) () -> () {
|
||||
sil private @globalinit_func0 : $@convention(thin) () -> () {
|
||||
// CHECK-LABEL: sil private @globalinit_func0 : $@convention(c) () -> () {
|
||||
sil private @globalinit_func0 : $@convention(c) () -> () {
|
||||
bb0:
|
||||
%0 = global_addr @_Tv2ch1xSi : $*Outer
|
||||
%1 = integer_literal $Builtin.Int32, 2
|
||||
@@ -42,7 +42,7 @@ bb0:
|
||||
// CHECK-NEXT: bb0:
|
||||
// CHECK-NOT: global_addr @globalinit_token0
|
||||
// CHECK-NEXT: address_to_pointer
|
||||
// CHECK: function_ref @globalinit_func0 : $@convention(thin) () -> ()
|
||||
// CHECK: function_ref @globalinit_func0 : $@convention(c) () -> ()
|
||||
// CHECK-NEXT: global_addr @_Tv2ch1xSi : $*Outer
|
||||
// CHECK-NEXT: address_to_pointer
|
||||
// CHECK-NEXT: return
|
||||
@@ -50,8 +50,8 @@ sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer {
|
||||
bb0:
|
||||
%1 = global_addr @globalinit_token0 : $*Builtin.Word
|
||||
%2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer
|
||||
%3 = function_ref @globalinit_func0 : $@convention(thin) () -> ()
|
||||
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $()
|
||||
%3 = function_ref @globalinit_func0 : $@convention(c) () -> ()
|
||||
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $()
|
||||
%6 = global_addr @_Tv2ch1xSi : $*Outer
|
||||
%7 = address_to_pointer %6 : $*Outer to $Builtin.RawPointer
|
||||
return %7 : $Builtin.RawPointer
|
||||
|
||||
Reference in New Issue
Block a user