Extended support for native Windows C++ EH outlining

Differential Review: http://reviews.llvm.org/D7886



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231981 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Kaylor
2015-03-11 23:22:06 +00:00
parent fba5b65942
commit 1134ac4a0f
10 changed files with 1483 additions and 314 deletions

View File

@@ -53,24 +53,24 @@ $"\01??_R0H@8" = comdat any
; The function entry should be rewritten like this.
; CHECK: define void @"\01?test@@YAXXZ"() #0 {
; CHECK: entry:
; CHECK: %NumExceptions.020.reg2mem = alloca i32
; CHECK: %i.019.reg2mem = alloca i32
; CHECK: %e = alloca i32, align 4
; CHECK: %ExceptionVal = alloca [10 x i32], align 16
; CHECK: %Data = alloca i64, align 8
; CHECK: %tmpcast = bitcast i64* %Data to %struct.SomeData*
; CHECK: %0 = bitcast [10 x i32]* %ExceptionVal to i8*
; CHECK: call void @llvm.lifetime.start(i64 40, i8* %0) #1
; CHECK: store i64 0, i64* %Data, align 8
; CHECK: %a.reg2mem = alloca i32*
; CHECK: %a = bitcast i64* %Data to i32*
; CHECK: store i32* %a, i32** %a.reg2mem
; CHECK: %b.reg2mem = alloca i32*
; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
; CHECK: store i32* %b, i32** %b.reg2mem
; CHECK: store i32 0, i32* %NumExceptions.020.reg2mem
; CHECK: store i32 0, i32* %i.019.reg2mem
; CHECK: call void (...)* @llvm.frameescape(i32* %e, i32* %NumExceptions.020.reg2mem, [10 x i32]* %ExceptionVal, i32* %i.019.reg2mem, i32** %a.reg2mem, i32** %b.reg2mem)
; CHECK: [[NUMEXCEPTIONS_REGMEM:\%.+]] = alloca i32
; CHECK: [[I_REGMEM:\%.+]] = alloca i32
; CHECK: [[E_PTR:\%.+]] = alloca i32, align 4
; CHECK: [[EXCEPTIONVAL:\%.+]] = alloca [10 x i32], align 16
; CHECK: [[DATA_PTR:\%.+]] = alloca i64, align 8
; CHECK: [[TMPCAST:\%.+]] = bitcast i64* [[DATA_PTR]] to %struct.SomeData*
; CHECK: [[TMP:\%.+]] = bitcast [10 x i32]* [[EXCEPTIONVAL]] to i8*
; CHECK: call void @llvm.lifetime.start(i64 40, i8* [[TMP]])
; CHECK: store i64 0, i64* [[DATA_PTR]], align 8
; CHECK: [[A_REGMEM:\%.+]] = alloca i32*
; CHECK: [[A_PTR:\%.+]] = bitcast i64* [[DATA_PTR]] to i32*
; CHECK: store i32* [[A_PTR]], i32** [[A_REGMEM]]
; CHECK: [[B_PTR:\%.+]] = getelementptr inbounds %struct.SomeData, %struct.SomeData* [[TMPCAST]], i64 0, i32 1
; CHECK: [[B_REGMEM:\%.+]] = alloca i32*
; CHECK: store i32* [[B_PTR]], i32** [[B_REGMEM]]
; CHECK: store i32 0, i32* [[NUMEXCEPTIONS_REGMEM]]
; CHECK: store i32 0, i32* [[I_REGMEM]]
; CHECK: call void (...)* @llvm.frameescape(i32* %e, i32* %NumExceptions.020.reg2mem, [10 x i32]* [[EXCEPTIONVAL]], i32* [[I_REGMEM]], i32** [[A_REGMEM]], i32** [[B_REGMEM]])
; CHECK: br label %for.body
; Function Attrs: uwtable
@@ -88,10 +88,10 @@ entry:
br label %for.body
; CHECK: for.body:
; CHECK-NOT: %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
; CHECK-NOT: %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
; CHECK: %i.019.reload = load i32, i32* %i.019.reg2mem
; CHECK: %NumExceptions.020.reload = load i32, i32* %NumExceptions.020.reg2mem
; CHECK-NOT: phi i32 [ 0, %entry ], [ {{\%NumExceptions.*}}, %try.cont ]
; CHECK-NOT: phi i32 [ 0, %entry ], [ {{\%inc.*}}, %try.cont ]
; CHECK: [[I_RELOAD:\%.+]] = load i32, i32* [[I_REGMEM]]
; CHECK: [[NUMEXCEPTIONS_RELOAD:\%.+]] = load i32, i32* [[NUMEXCEPTIONS_REGMEM]]
for.body: ; preds = %entry, %try.cont
%NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
%i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
@@ -99,14 +99,11 @@ for.body: ; preds = %entry, %try.cont
to label %invoke.cont unwind label %lpad
; CHECK: invoke.cont: ; preds = %for.body
; CHECK-NOT: %1 = load i32, i32* %a, align 8, !tbaa !2
; CHECK-NOT: %add = add nsw i32 %1, %i.019
; CHECK-NOT: store i32 %add, i32* %a, align 8, !tbaa !2
; CHECK: %a.reload3 = load volatile i32*, i32** %a.reg2mem
; CHECK: %1 = load i32, i32* %a.reload3, align 8, !tbaa !2
; CHECK: %add = add nsw i32 %1, %i.019.reload
; CHECK: %a.reload2 = load volatile i32*, i32** %a.reg2mem
; CHECK: store i32 %add, i32* %a.reload2, align 8, !tbaa !2
; CHECK: [[A_RELOAD:\%.+]] = load volatile i32*, i32** [[A_REGMEM]]
; CHECK: [[TMP1:\%.+]] = load i32, i32* [[A_RELOAD]], align 8
; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP1]], [[I_RELOAD]]
; CHECK: [[A_RELOAD1:\%.+]] = load volatile i32*, i32** [[A_REGMEM]]
; CHECK: store i32 [[ADD]], i32* [[A_RELOAD1]], align 8
; CHECK: br label %try.cont
invoke.cont: ; preds = %for.body
%1 = load i32, i32* %a, align 8, !tbaa !2
@@ -114,6 +111,16 @@ invoke.cont: ; preds = %for.body
store i32 %add, i32* %a, align 8, !tbaa !2
br label %try.cont
; CHECK: [[LPAD_LABEL:lpad[0-9]*]]:{{[ ]+}}; preds = %for.body
; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
; CHECK-NOT: extractvalue { i8*, i32 }
; CHECK-NOT: tail call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*))
; CHECK-NOT: icmp eq i32
; CHECK-NOT: br i1
; CHECK: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* %e, i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch" to i8*))
; CHECK: indirectbr i8* [[RECOVER]], [label %try.cont]
lpad: ; preds = %for.body
%2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
@@ -122,6 +129,8 @@ lpad: ; preds = %for.body
%matches = icmp eq i32 %3, %4
br i1 %matches, label %catch, label %eh.resume
; CHECK-NOT: catch:
catch: ; preds = %lpad
%5 = extractvalue { i8*, i32 } %2, 0
%e.i8 = bitcast i32* %e to i8*
@@ -134,32 +143,36 @@ catch: ; preds = %lpad
%cmp1 = icmp eq i32 %tmp8, %i.019
br i1 %cmp1, label %if.then, label %if.else
; CHECK-NOT: if.then:
if.then: ; preds = %catch
%tmp9 = load i32, i32* %b, align 4, !tbaa !8
%add2 = add nsw i32 %tmp9, %i.019
store i32 %add2, i32* %b, align 4, !tbaa !8
br label %if.end
; CHECK-NOT: if.else:
if.else: ; preds = %catch
%tmp10 = load i32, i32* %a, align 8, !tbaa !2
%add4 = add nsw i32 %tmp10, %tmp8
store i32 %add4, i32* %a, align 8, !tbaa !2
br label %if.end
; CHECK-NOT: if.end:
if.end: ; preds = %if.else, %if.then
tail call void @llvm.eh.endcatch() #1
br label %try.cont
; CHECK: try.cont: ; preds = %if.end, %invoke.cont
; CHECK-NOT: %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
; CHECK: %NumExceptions.1 = phi i32 [ %NumExceptions.020.reload, %invoke.cont ], [ %inc, %if.end ]
; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
; CHECK-NOT: %inc5 = add nuw nsw i32 %i.019, 1
; CHECK: %inc5 = add nuw nsw i32 %i.019.reload, 1
; CHECK: %cmp = icmp slt i32 %inc5, 10
; CHECK: store i32 %NumExceptions.1, i32* %NumExceptions.020.reg2mem
; CHECK: store i32 %inc5, i32* %i.019.reg2mem
; CHECK: br i1 %cmp, label %for.body, label %for.end
; CHECK: try.cont:{{[ ]+}}; preds = %[[LPAD_LABEL]], %invoke.cont
; CHECK-NOT: phi i32
; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 [[NUMEXCEPTIONS_RELOAD]])
; CHECK: [[INC:\%.+]] = add nuw nsw i32 [[I_RELOAD]], 1
; CHECK: [[CMP:\%.+]] = icmp slt i32 [[INC]], 10
; CHECK: store i32 [[NUMEXCEPTIONS_RELOAD]], i32* [[NUMEXCEPTIONS_REGMEM]]
; CHECK: store i32 [[INC]], i32* [[I_REGMEM]]
; CHECK: br i1 [[CMP]], label %for.body, label %for.end
try.cont: ; preds = %if.end, %invoke.cont
%NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
@@ -183,44 +196,44 @@ eh.resume: ; preds = %lpad
; The following catch handler should be outlined.
; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
; CHECK: entry:
; CHECK: %e.i84 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
; CHECK: %e = bitcast i8* %e.i84 to i32*
; CHECK: %eh.temp.alloca.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
; CHECK: %eh.temp.alloca = bitcast i8* %eh.temp.alloca.i8 to i32*
; CHECK: %NumExceptions.020.reload = load i32, i32* %eh.temp.alloca
; CHECK: %ExceptionVal.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
; CHECK: %ExceptionVal = bitcast i8* %ExceptionVal.i8 to [10 x i32]*
; CHECK: %eh.temp.alloca1.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 3)
; CHECK: %eh.temp.alloca1 = bitcast i8* %eh.temp.alloca1.i8 to i32*
; CHECK: %i.019.reload = load i32, i32* %eh.temp.alloca1
; CHECK: %eh.temp.alloca2.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 4)
; CHECK: %eh.temp.alloca2 = bitcast i8* %eh.temp.alloca2.i8 to i32**
; CHECK: %a.reload = load i32*, i32** %eh.temp.alloca2
; CHECK: %eh.temp.alloca3.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 5)
; CHECK: %eh.temp.alloca3 = bitcast i8* %eh.temp.alloca3.i8 to i32**
; CHECK: %b.reload = load i32*, i32** %eh.temp.alloca3
; CHECK: %e.i8 = bitcast i32* %e to i8*
; CHECK: %tmp8 = load i32, i32* %e, align 4, !tbaa !7
; CHECK: %idxprom = sext i32 %NumExceptions.020.reload to i64
; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
; CHECK: store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
; CHECK: %inc = add nsw i32 %NumExceptions.020.reload, 1
; CHECK: %cmp1 = icmp eq i32 %tmp8, %i.019.reload
; CHECK: br i1 %cmp1, label %if.then, label %if.else
; CHECK: [[RECOVER_E:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
; CHECK: [[E_PTR:\%.+]] = bitcast i8* [[RECOVER_E]] to i32*
; CHECK: [[RECOVER_EH_TEMP:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
; CHECK: [[EH_TEMP:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to i32*
; CHECK: [[NUMEXCEPTIONS_RELOAD:\%.+]] = load i32, i32* [[EH_TEMP]]
; CHECK: [[RECOVER_EXCEPTIONVAL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
; CHECK: [[EXCEPTIONVAL:\%.+]] = bitcast i8* [[RECOVER_EXCEPTIONVAL]] to [10 x i32]*
; CHECK: [[RECOVER_EH_TEMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 3)
; CHECK: [[EH_TEMP1:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP1]] to i32*
; CHECK: [[I_RELOAD:\%.+]] = load i32, i32* [[EH_TEMP1]]
; CHECK: [[RECOVER_EH_TEMP2:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 4)
; CHECK: [[EH_TEMP2:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP2]] to i32**
; CHECK: [[A_RELOAD:\%.+]] = load i32*, i32** [[EH_TEMP2]]
; CHECK: [[RECOVER_EH_TEMP3:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 5)
; CHECK: [[EH_TEMP3:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP3]] to i32**
; CHECK: [[B_RELOAD:\%.+]] = load i32*, i32** [[EH_TEMP3]]
; CHECK: [[E_I8PTR:\%.+]] = bitcast i32* [[E_PTR]] to i8*
; CHECK: [[TMP:\%.+]] = load i32, i32* [[E_PTR]], align 4
; CHECK: [[IDXPROM:\%.+]] = sext i32 [[NUMEXCEPTIONS_RELOAD]] to i64
; CHECK: [[ARRAYIDX:\%.+]] = getelementptr inbounds [10 x i32], [10 x i32]* [[EXCEPTIONVAL]], i64 0, i64 [[IDXPROM]]
; CHECK: store i32 [[TMP]], i32* [[ARRAYIDX]], align 4
; CHECK: [[INC:\%.+]] = add nsw i32 [[NUMEXCEPTIONS_RELOAD]], 1
; CHECK: [[CMP:\%.+]] = icmp eq i32 [[TMP]], [[I_RELOAD]]
; CHECK: br i1 [[CMP]], label %if.then, label %if.else
;
; CHECK: if.then: ; preds = %entry
; CHECK: %tmp9 = load i32, i32* %b.reload, align 4, !tbaa !8
; CHECK: %add2 = add nsw i32 %tmp9, %i.019.reload
; CHECK: store i32 %add2, i32* %b.reload, align 4, !tbaa !8
; CHECK: if.then:{{[ ]+}}; preds = %entry
; CHECK: [[TMP1:\%.+]] = load i32, i32* [[B_RELOAD]], align 4
; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP1]], [[I_RELOAD]]
; CHECK: store i32 [[ADD]], i32* [[B_RELOAD]], align 4
; CHECK: br label %if.end
;
; CHECK: if.else: ; preds = %entry
; CHECK: %tmp10 = load i32, i32* %a.reload, align 8, !tbaa !2
; CHECK: %add4 = add nsw i32 %tmp10, %tmp8
; CHECK: store i32 %add4, i32* %a.reload, align 8, !tbaa !2
; CHECK: if.else:{{[ ]+}}; preds = %entry
; CHECK: [[TMP2:\%.+]] = load i32, i32* [[A_RELOAD]], align 8
; CHECK: [[ADD2:\%.+]] = add nsw i32 [[TMP2]], [[TMP]]
; CHECK: store i32 [[ADD2]], i32* [[A_RELOAD]], align 8
; CHECK: br label %if.end
;
; CHECK: if.end: ; preds = %if.else, %if.then
; CHECK: if.end:{{[ ]+}}; preds = %if.else, %if.then
; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
; CHECK: }