Don't hardcode the function representation of builtin "once". Make emitLazyGlobalInitializer retrieve the convention from getBuiltinValueDecl.

This commit is contained in:
Kuba Mracek
2018-01-02 23:13:08 -08:00
parent 17fa484f04
commit 0b7bb605cb
8 changed files with 31 additions and 29 deletions

View File

@@ -975,10 +975,12 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
PatternBindingDecl *binding, PatternBindingDecl *binding,
unsigned pbdEntry) { unsigned pbdEntry) {
ASTContext &C = M.getASTContext(); ASTContext &C = M.getASTContext();
Type initType = FunctionType::get( auto *onceBuiltin =
TupleType::getEmpty(C), TupleType::getEmpty(C), cast<FuncDecl>(getBuiltinValueDecl(C, C.getIdentifier("once")));
FunctionType::ExtInfo() auto blockParam = onceBuiltin->getParameterLists()[0]->get(1);
.withRepresentation(FunctionType::Representation::Thin)); 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 initSILType = getLoweredType(initType).castTo<SILFunctionType>();
auto *f = auto *f =

View File

@@ -321,8 +321,8 @@ static SILFunction *getCalleeOfOnceCall(BuiltinInst *BI) {
auto Callee = BI->getOperand(1); auto Callee = BI->getOperand(1);
assert(Callee->getType().castTo<SILFunctionType>()->getRepresentation() assert(Callee->getType().castTo<SILFunctionType>()->getRepresentation()
== SILFunctionTypeRepresentation::Thin && == SILFunctionTypeRepresentation::CFunctionPointer &&
"Expected thin function representation!"); "Expected C function representation!");
if (auto *FR = dyn_cast<FunctionRefInst>(Callee)) if (auto *FR = dyn_cast<FunctionRefInst>(Callee))
return FR->getReferencedFunction(); return FR->getReferencedFunction();

View File

@@ -54,5 +54,5 @@ extension A {
// CHECK: store i64 {{.*}}, i64* getelementptr inbounds ([[INT]], [[INT]]* @_T07globals2g0Sivp, i32 0, i32 0), align 8 // CHECK: store i64 {{.*}}, i64* getelementptr inbounds ([[INT]], [[INT]]* @_T07globals2g0Sivp, i32 0, i32 0), align 8
// FIXME: give these initializers a real mangled name // 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 // CHECK: store i64 5, i64* getelementptr inbounds (%TSi, %TSi* @_T07globals1AV3fooSivpZ, i32 0, i32 0), align 8

View File

@@ -7,7 +7,7 @@
// CHECK: @_T012lazy_globals1ySivp = hidden global %TSi zeroinitializer, align 8 // CHECK: @_T012lazy_globals1ySivp = hidden global %TSi zeroinitializer, align 8
// CHECK: @_T012lazy_globals1zSivp = 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: entry:
// CHECK: store i64 1, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1xSivp, i32 0, i32 0), align 8 // 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 // CHECK: store i64 2, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1ySivp, i32 0, i32 0), align 8

View File

@@ -1,6 +1,6 @@
// RUN: %target-swift-frontend -parse-as-library -emit-silgen -enable-sil-ownership %s | %FileCheck %s // 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: alloc_global @_T012lazy_globals1xSiv
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int
// CHECK: store {{%.*}} to [trivial] [[XADDR]] : $*Int // CHECK: store {{%.*}} to [trivial] [[XADDR]] : $*Int
@@ -8,15 +8,15 @@
// CHECK: sil hidden [global_init] @_T012lazy_globals1xSivau : $@convention(thin) () -> Builtin.RawPointer { // CHECK: sil hidden [global_init] @_T012lazy_globals1xSivau : $@convention(thin) () -> Builtin.RawPointer {
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token0 : $*Builtin.Word // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token0 : $*Builtin.Word
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(thin) () -> () // CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(c) () -> ()
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() // CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
// CHECK: } // CHECK: }
var x: Int = 0 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: alloc_global @_T012lazy_globals3FooV3fooSivpZ
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int
// CHECK: store {{.*}} to [trivial] [[XADDR]] : $*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: sil hidden [global_init] @_T012lazy_globals3FooV3fooSivau : $@convention(thin) () -> Builtin.RawPointer {
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token1 : $*Builtin.Word // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token1 : $*Builtin.Word
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(thin) () -> () // CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(c) () -> ()
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() // CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
@@ -40,7 +40,7 @@ struct Foo {
static var initialized: Int = 57 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: alloc_global @_T012lazy_globals3BarO3barSivpZ
// CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int
// CHECK: store {{.*}} to [trivial] [[XADDR]] : $*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: sil hidden [global_init] @_T012lazy_globals3BarO3barSivau : $@convention(thin) () -> Builtin.RawPointer {
// CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token3 : $*Builtin.Word // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token3 : $*Builtin.Word
// CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer
// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(thin) () -> () // CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(c) () -> ()
// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() // CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $()
// CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int
// CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer
// CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer
@@ -63,13 +63,13 @@ enum Bar {
func f() -> (Int, Int) { return (1, 2) } 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: function_ref @_T012lazy_globals1fSi_SityF : $@convention(thin) () -> (Int, Int)
// CHECK: sil hidden [global_init] @_T012lazy_globals2a1Sivau : $@convention(thin) () -> Builtin.RawPointer // 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: global_addr @_T012lazy_globals2a1Sivp : $*Int
// CHECK: sil hidden [global_init] @_T012lazy_globals2b1Sivau : $@convention(thin) () -> Builtin.RawPointer { // 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 // CHECK: global_addr @_T012lazy_globals2b1Sivp : $*Int
var (a1, b1) = f() var (a1, b1) = f()

View File

@@ -627,7 +627,7 @@ func force_global_observing_property_setter() {
} }
// The property is initialized with "zero". // 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: bb0:
// CHECK-NEXT: alloc_global @_T010properties25global_observing_propertySiv // CHECK-NEXT: alloc_global @_T010properties25global_observing_propertySiv
// CHECK-NEXT: %1 = global_addr @_T010properties25global_observing_propertySivp : $*Int // CHECK-NEXT: %1 = global_addr @_T010properties25global_observing_propertySivp : $*Int

View File

@@ -213,7 +213,7 @@ sil_global private @globalinit_token0 : $Builtin.Word
sil_global @MyConst : $Int32 sil_global @MyConst : $Int32
// globalinit_func0 // globalinit_func0
sil private @globalinit_func0 : $@convention(thin) () -> () { sil private @globalinit_func0 : $@convention(c) () -> () {
bb0: bb0:
%0 = global_addr @MyConst : $*Int32 // user: %3 %0 = global_addr @MyConst : $*Int32 // user: %3
%1 = integer_literal $Builtin.Int32, 0 // user: %2 %1 = integer_literal $Builtin.Int32, 0 // user: %2
@@ -229,8 +229,8 @@ bb0:
%1 = global_addr @globalinit_token0 : $*Builtin.Word // user: %2 %1 = global_addr @globalinit_token0 : $*Builtin.Word // user: %2
%2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer // user: %5 %2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer // user: %5
// function_ref globalinit_func0 // function_ref globalinit_func0
%3 = function_ref @globalinit_func0 : $@convention(thin) () -> () // user: %4 %3 = function_ref @globalinit_func0 : $@convention(c) () -> () // user: %4
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $() %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $()
%6 = global_addr @MyConst : $*Int32 // user: %7 %6 = global_addr @MyConst : $*Int32 // user: %7
%7 = address_to_pointer %6 : $*Int32 to $Builtin.RawPointer // user: %8 %7 = address_to_pointer %6 : $*Int32 to $Builtin.RawPointer // user: %8
return %7 : $Builtin.RawPointer // id: %8 return %7 : $Builtin.RawPointer // id: %8

View File

@@ -25,8 +25,8 @@ sil_global private @globalinit_token0 : $Builtin.Word
// CHECK-NEXT: } // CHECK-NEXT: }
sil_global @_Tv2ch1xSi : $Outer sil_global @_Tv2ch1xSi : $Outer
// CHECK-LABEL: sil private @globalinit_func0 : $@convention(thin) () -> () { // CHECK-LABEL: sil private @globalinit_func0 : $@convention(c) () -> () {
sil private @globalinit_func0 : $@convention(thin) () -> () { sil private @globalinit_func0 : $@convention(c) () -> () {
bb0: bb0:
%0 = global_addr @_Tv2ch1xSi : $*Outer %0 = global_addr @_Tv2ch1xSi : $*Outer
%1 = integer_literal $Builtin.Int32, 2 %1 = integer_literal $Builtin.Int32, 2
@@ -42,7 +42,7 @@ bb0:
// CHECK-NEXT: bb0: // CHECK-NEXT: bb0:
// CHECK-NOT: global_addr @globalinit_token0 // CHECK-NOT: global_addr @globalinit_token0
// CHECK-NEXT: address_to_pointer // 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: global_addr @_Tv2ch1xSi : $*Outer
// CHECK-NEXT: address_to_pointer // CHECK-NEXT: address_to_pointer
// CHECK-NEXT: return // CHECK-NEXT: return
@@ -50,8 +50,8 @@ sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer {
bb0: bb0:
%1 = global_addr @globalinit_token0 : $*Builtin.Word %1 = global_addr @globalinit_token0 : $*Builtin.Word
%2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer %2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer
%3 = function_ref @globalinit_func0 : $@convention(thin) () -> () %3 = function_ref @globalinit_func0 : $@convention(c) () -> ()
%5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $() %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $()
%6 = global_addr @_Tv2ch1xSi : $*Outer %6 = global_addr @_Tv2ch1xSi : $*Outer
%7 = address_to_pointer %6 : $*Outer to $Builtin.RawPointer %7 = address_to_pointer %6 : $*Outer to $Builtin.RawPointer
return %7 : $Builtin.RawPointer return %7 : $Builtin.RawPointer