Avatar
swiftc -O -emit-ir recursive-inlining.swift | cat
5:54 AM
define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr #0 { entry: %2 = load %swift.type*, %swift.type** @"$ss23_ContiguousArrayStorageCyypGML", align 8 %3 = icmp eq %swift.type* %2, null br i1 %3, label %cacheIsNull.i, label %"$ss23_ContiguousArrayStorageCyypGMa.exit" cacheIsNull.i: ; preds = %entry %4 = tail call swiftcc %swift.metadata_response @"$ss23_ContiguousArrayStorageCMa"(i64 0, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sypN", i64 0, i32 1)) #5 %5 = extractvalue %swift.metadata_response %4, 0 %6 = extractvalue %swift.metadata_response %4, 1 %7 = icmp eq i64 %6, 0 br i1 %7, label %is_complete.i, label %"$ss23_ContiguousArrayStorageCyypGMa.exit" is_complete.i: ; preds = %cacheIsNull.i store atomic %swift.type* %5, %swift.type** @"$ss23_ContiguousArrayStorageCyypGML" release, align 8 br label %"$ss23_ContiguousArrayStorageCyypGMa.exit" "$ss23_ContiguousArrayStorageCyypGMa.exit": ; preds = %entry, %cacheIsNull.i, %is_complete.i
5:55 AM
↓続き %8 = phi %swift.type* [ %2, %entry ], [ %5, %is_complete.i ], [ %5, %cacheIsNull.i ] %9 = tail call noalias %swift.refcounted* @swift_allocObject(%swift.type* %8, i64 64, i64 7) #1 %10 = getelementptr inbounds %swift.refcounted, %swift.refcounted* %9, i64 1 %11 = bitcast %swift.refcounted* %10 to <2 x i64>* store <2 x i64> <i64 1, i64 2>, <2 x i64>* %11, align 8 %12 = bitcast %swift.refcounted* %9 to %swift.bridge* %13 = getelementptr inbounds %swift.refcounted, %swift.refcounted* %9, i64 2 %14 = tail call swiftcc i64 @"$s4main9factorial2ofS2i_tF"(i64 5) %15 = getelementptr inbounds %swift.refcounted, %swift.refcounted* %9, i64 3, i32 1 %16 = bitcast i64* %15 to %swift.type** store %swift.type* @"$sSiN", %swift.type** %16, align 8 %._value = bitcast %swift.refcounted* %13 to i64* store i64 %14, i64* %._value, align 8 tail call swiftcc void @"$ss5print_9separator10terminatoryypd_S2StF"(%swift.bridge* %12, i64 32, %swift.bridge* inttoptr (i64 -2233785415175766016 to %swift.bridge*), i64 10, %swift.bridge* inttoptr (i64 -2233785415175766016 to %swift.bridge*)) tail call void @swift_release(%swift.refcounted* %9) #1 ret i32 0 }
5:55 AM
%14 = tail call swiftcc i64 @"$s4main9factorial2ofS2i_tF"(i64 5) だし、インライン展開されてる感じはない?
5:59 AM
@inline(__always) 付けたけど結果変わらなかった。 @inline(__always) func factorial(of n: Int) -> Int { if n <= 1 { return 1 } else { return n * factorial(of: n - 1) } } print(factorial(of: 5))