Files
swift-mirror/test/SILOptimizer/mandatory_inlining_inline_always.sil
Arnold Schwaighofer 25a071efc8 Add experimental feature @inline(always)
The intent for `@inline(always)` is to act as an optimization control.
The user can rely on inlining to happen or the compiler will emit an error
message.

Because function values can be dynamic (closures, protocol/class lookup)
this guarantee can only be upheld for direct function references.

In cases where the optimizer can resolve dynamic function values the
attribute shall be respected.

rdar://148608854
2025-09-30 08:36:26 -07:00

154 lines
7.4 KiB
Plaintext

// RUN: env DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib %target-sil-opt -sil-print-types -enable-objc-interop -module-name A -enable-sil-verify-all %s -inline-always-inlining | %FileCheck %s
// guardmalloc is incompatible with ASAN
// REQUIRES: no_asan
import Builtin
import Swift
sil @plus : $@convention(thin) (Int64, Int64) -> Int64
sil @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
// CHECK-LABEL: sil [always_inline] @test_add : $@convention(thin) (Int64) -> Int64 {
sil [always_inline] @test_add : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_box ${ var Int64 }
%1a = project_box %1 : ${ var Int64 }, 0
store %0 to %1a : $*Int64
%3 = function_ref @plus : $@convention(thin) (Int64, Int64) -> Int64
%4 = load %1a : $*Int64
%5 = function_ref @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%6 = metatype $@thin Int64.Type
%7 = integer_literal $Builtin.Int128, 20
%8 = apply %5(%7, %6) : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%9 = apply %3(%4, %8) : $@convention(thin) (Int64, Int64) -> Int64
strong_release %1 : ${ var Int64 }
return %9 : $Int64
}
// CHECK-LABEL: sil @inline_test_add : $@convention(thin) (Int64) -> Int64 {
sil @inline_test_add : $@convention(thin) (Int64) -> Int64 {
// CHECK: [[BB0:.*]]([[VAL0:%.*]] : $Int64):
// CHECK: [[VAL1:%.*]] = alloc_box ${ var Int64 }
// CHECK: [[PB1:%.*]] = project_box [[VAL1]]
// CHECK: store [[VAL0]] to [[PB1]]
// CHECK: [[VAL3:%.*]] = function_ref @plus
// CHECK: [[VAL4:%.*]] = function_ref @plus
// CHECK: [[VAL5:%.*]] = load [[PB1]]
// CHECK: [[VAL6:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL7:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL8:%.*]] = integer_literal $Builtin.Int128, 10
// CHECK: [[VAL9:%.*]] = apply [[VAL6]]([[VAL8]], [[VAL7]])
// CHECK: [[VAL10:%.*]] = apply [[VAL4]]([[VAL5]], [[VAL9]])
// CHECK: [[VAL11:%.*]] = alloc_box ${ var Int64 }
// CHECK: [[PB11:%.*]] = project_box [[VAL11]]
// CHECK: store [[VAL10]] to [[PB11]]
// CHECK: [[VAL13:%.*]] = function_ref @plus
// CHECK: [[VAL14:%.*]] = load [[PB11]]
// CHECK: [[VAL15:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL16:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL17:%.*]] = integer_literal $Builtin.Int128, 20
// CHECK: [[VAL18:%.*]] = apply [[VAL15]]([[VAL17]], [[VAL16]])
// CHECK: [[VAL19:%.*]] = apply [[VAL13]]([[VAL14]], [[VAL18]])
// CHECK: strong_release [[VAL11]]
// CHECK: [[VAL21:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL22:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL23:%.*]] = integer_literal $Builtin.Int128, 30
// CHECK: [[VAL24:%.*]] = apply [[VAL21]]([[VAL23]], [[VAL22]])
// CHECK: [[VAL25:%.*]] = apply [[VAL3]]([[VAL19]], [[VAL24]])
// CHECK: strong_release [[VAL1]]
// CHECK: return [[VAL25]]
bb0(%0 : $Int64):
%1 = alloc_box ${ var Int64 }
%1a = project_box %1 : ${ var Int64 }, 0
store %0 to %1a : $*Int64
%3 = function_ref @plus : $@convention(thin) (Int64, Int64) -> Int64
%4 = function_ref @test_add : $@convention(thin) (Int64) -> Int64
%5 = function_ref @plus : $@convention(thin) (Int64, Int64) -> Int64
%6 = load %1a : $*Int64
%7 = function_ref @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%8 = metatype $@thin Int64.Type
%9 = integer_literal $Builtin.Int128, 10
%10 = apply %7(%9, %8) : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%11 = apply %5(%6, %10) : $@convention(thin) (Int64, Int64) -> Int64
%12 = apply %4(%11) : $@convention(thin) (Int64) -> Int64
%13 = function_ref @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%14 = metatype $@thin Int64.Type
%15 = integer_literal $Builtin.Int128, 30
%16 = apply %13(%15, %14) : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%17 = apply %3(%12, %16) : $@convention(thin) (Int64, Int64) -> Int64
strong_release %1 : ${ var Int64 }
return %17 : $Int64
}
// CHECK-LABEL: sil @inline_twice_test_add : $@convention(thin) (Int64) -> Int64 {
sil @inline_twice_test_add : $@convention(thin) (Int64) -> Int64 {
// CHECK: [[BB0:.*]]([[VAL0:%.*]] : $Int64):
// CHECK: [[VAL1:%.*]] = alloc_box ${ var Int64 }
// CHECK: [[PB1:%.*]] = project_box [[VAL1]]
// CHECK: store [[VAL0]] to [[PB1]]
// CHECK: [[VAL3:%.*]] = function_ref @plus
// CHECK: [[VAL4:%.*]] = function_ref @plus
// CHECK: [[VAL5:%.*]] = load [[PB1]]
// CHECK: [[VAL6:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL7:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL8:%.*]] = integer_literal $Builtin.Int128, 10
// CHECK: [[VAL9:%.*]] = apply [[VAL6]]([[VAL8]], [[VAL7]])
// CHECK: [[VAL10:%.*]] = apply [[VAL4]]([[VAL5]], [[VAL9]])
// CHECK: [[VAL11:%.*]] = alloc_box ${ var Int64 }
// CHECK: [[PB11:%.*]] = project_box [[VAL11]]
// CHECK: store [[VAL10]] to [[PB11]]
// CHECK: [[VAL13:%.*]] = function_ref @plus
// CHECK: [[VAL14:%.*]] = load [[PB11]]
// CHECK: [[VAL15:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL16:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL17:%.*]] = integer_literal $Builtin.Int128, 20
// CHECK: [[VAL18:%.*]] = apply [[VAL15]]([[VAL17]], [[VAL16]])
// CHECK: [[VAL19:%.*]] = apply [[VAL13]]([[VAL14]], [[VAL18]])
// CHECK: strong_release [[VAL11]]
// CHECK: [[VAL21:%.*]] = alloc_box ${ var Int64 }
// CHECK: [[PB21:%.*]] = project_box [[VAL21]]
// CHECK: store [[VAL19]] to [[PB21]]
// CHECK: [[VAL23:%.*]] = function_ref @plus
// CHECK: [[VAL24:%.*]] = load [[PB21]]
// CHECK: [[VAL25:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL26:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL27:%.*]] = integer_literal $Builtin.Int128, 20
// CHECK: [[VAL28:%.*]] = apply [[VAL25]]([[VAL27]], [[VAL26]])
// CHECK: [[VAL29:%.*]] = apply [[VAL23]]([[VAL24]], [[VAL28]])
// CHECK: strong_release [[VAL21]]
// CHECK: [[VAL31:%.*]] = function_ref @fromLiteral
// CHECK: [[VAL32:%.*]] = metatype $@thin Int64.Type
// CHECK: [[VAL33:%.*]] = integer_literal $Builtin.Int128, 30
// CHECK: [[VAL34:%.*]] = apply [[VAL31]]([[VAL33]], [[VAL32]])
// CHECK: [[VAL35:%.*]] = apply [[VAL3]]([[VAL29]], [[VAL34]])
// CHECK: strong_release [[VAL1]]
// CHECK: return [[VAL35]]
bb0(%0 : $Int64):
%1 = alloc_box ${ var Int64 }
%1a = project_box %1 : ${ var Int64 }, 0
store %0 to %1a : $*Int64
%3 = function_ref @plus : $@convention(thin) (Int64, Int64) -> Int64
%4 = function_ref @test_add : $@convention(thin) (Int64) -> Int64
%5 = function_ref @test_add : $@convention(thin) (Int64) -> Int64
%6 = function_ref @plus : $@convention(thin) (Int64, Int64) -> Int64
%7 = load %1a : $*Int64
%8 = function_ref @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%9 = metatype $@thin Int64.Type
%10 = integer_literal $Builtin.Int128, 10
%11 = apply %8(%10, %9) : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%12 = apply %6(%7, %11) : $@convention(thin) (Int64, Int64) -> Int64
%13 = apply %5(%12) : $@convention(thin) (Int64) -> Int64
%14 = apply %4(%13) : $@convention(thin) (Int64) -> Int64
%15 = function_ref @fromLiteral : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%16 = metatype $@thin Int64.Type
%17 = integer_literal $Builtin.Int128, 30
%18 = apply %15(%17, %16) : $@convention(thin) (Builtin.Int128, @thin Int64.Type) -> Int64
%19 = apply %3(%14, %18) : $@convention(thin) (Int64, Int64) -> Int64
strong_release %1 : ${ var Int64 }
return %19 : $Int64
}