Revision 42e827e6e7247224c068a9dce8f6eabd2ab892ba authored by Devin Coughlin on 21 January 2016, 00:12:56 UTC, committed by Devin Coughlin on 21 January 2016, 01:22:15 UTC
1 parent ac1f5a6
Raw File
stack_promotion.ll
; RUN: %swift-llvm-opt -swift-stack-promotion -stack-promotion-limit=100 %s | FileCheck %s

target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-macosx10.9"

%swift.type = type { i64 }
%objc_object = type opaque

; CHECK-LABEL: define void @promote_buffer()
; CHECK: [[B:%.+]] = alloca i8, i32 48, align 8
; CHECK: [[M:%.+]] = call %swift.type* @get_buffer_metadata()
; CHECK: [[BC:%.+]] = bitcast i8* [[B]] to %objc_object*
; CHECK: [[I:%.+]] = call %objc_object* @swift_initStackObject(%swift.type* [[M]], %objc_object* [[BC]])
; CHECK: [[BC2:%.+]] = bitcast %objc_object* [[I]] to i8*
; CHECK: call void @llvm.lifetime.end(i64 -1, i8* [[BC2]])
; CHECK: ret void
define void @promote_buffer() {
entry:
  %0 = call %swift.type* @get_buffer_metadata()
  %1 = call %objc_object* @swift_bufferAllocateOnStack(%swift.type* %0, i64 48, i64 7)
  call void @swift_bufferDeallocateFromStack(%objc_object* %1)
  ret void
}

; CHECK-LABEL: define void @dont_promote_buffer_exceeding_limit()
; CHECK: [[M:%.+]] = call %swift.type* @get_buffer_metadata()
; CHECK: call %objc_object* @swift_bufferAllocate(%swift.type* [[M]], i64 48, i64 7)
; CHECK-NEXT: ret void
define void @dont_promote_buffer_exceeding_limit() {
entry:
  %0 = alloca i8, i32 128, align 8
  %1 = call %swift.type* @get_buffer_metadata()
  %2 = call %objc_object* @swift_bufferAllocateOnStack(%swift.type* %1, i64 48, i64 7)
  call void @swift_bufferDeallocateFromStack(%objc_object* %2)
  ret void
}

declare %swift.type* @get_buffer_metadata()
declare %objc_object* @swift_bufferAllocateOnStack(%swift.type*, i64, i64)
declare void @swift_bufferDeallocateFromStack(%objc_object*)
back to top