2015-04-24 07:22:33 +08:00
|
|
|
; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
; This test case is also intended to be run manually as a complete functional
|
|
|
|
; test. It should link, print something, and exit zero rather than crashing.
|
|
|
|
; It is the hypothetical lowering of a C source program that looks like:
|
|
|
|
;
|
|
|
|
; int safe_div(int *n, int *d) {
|
|
|
|
; int r;
|
|
|
|
; __try {
|
|
|
|
; __try {
|
|
|
|
; r = *n / *d;
|
|
|
|
; } __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) {
|
|
|
|
; puts("EXCEPTION_ACCESS_VIOLATION");
|
|
|
|
; r = -1;
|
|
|
|
; }
|
|
|
|
; } __except(GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
|
|
|
|
; puts("EXCEPTION_INT_DIVIDE_BY_ZERO");
|
|
|
|
; r = -2;
|
|
|
|
; }
|
|
|
|
; return r;
|
|
|
|
; }
|
|
|
|
|
|
|
|
@str1 = internal constant [27 x i8] c"EXCEPTION_ACCESS_VIOLATION\00"
|
|
|
|
@str2 = internal constant [29 x i8] c"EXCEPTION_INT_DIVIDE_BY_ZERO\00"
|
|
|
|
|
2015-06-18 04:52:32 +08:00
|
|
|
define i32 @safe_div(i32* %n, i32* %d) personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
|
2015-01-14 09:05:27 +08:00
|
|
|
entry:
|
|
|
|
%r = alloca i32, align 4
|
|
|
|
invoke void @try_body(i32* %r, i32* %n, i32* %d)
|
2015-10-10 07:05:54 +08:00
|
|
|
to label %__try.cont unwind label %lpad0
|
|
|
|
|
|
|
|
lpad0:
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
%cs0 = catchswitch within none [label %handler0] unwind label %lpad1
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
handler0:
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
%p0 = catchpad within %cs0 [i8* bitcast (i32 (i8*, i8*)* @safe_div_filt0 to i8*)]
|
2015-12-16 05:27:27 +08:00
|
|
|
call void @puts(i8* getelementptr ([27 x i8], [27 x i8]* @str1, i32 0, i32 0)) [ "funclet"(token %p0) ]
|
2015-01-14 09:05:27 +08:00
|
|
|
store i32 -1, i32* %r, align 4
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
catchret from %p0 to label %__try.cont
|
2015-10-10 07:05:54 +08:00
|
|
|
|
|
|
|
lpad1:
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
%cs1 = catchswitch within none [label %handler1] unwind to caller
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
handler1:
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
%p1 = catchpad within %cs1 [i8* bitcast (i32 (i8*, i8*)* @safe_div_filt1 to i8*)]
|
2015-12-16 05:27:27 +08:00
|
|
|
call void @puts(i8* getelementptr ([29 x i8], [29 x i8]* @str2, i32 0, i32 0)) [ "funclet"(token %p1) ]
|
2015-01-14 09:05:27 +08:00
|
|
|
store i32 -2, i32* %r, align 4
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
catchret from %p1 to label %__try.cont
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
__try.cont:
|
2015-02-28 05:17:42 +08:00
|
|
|
%safe_ret = load i32, i32* %r, align 4
|
2015-01-14 09:05:27 +08:00
|
|
|
ret i32 %safe_ret
|
|
|
|
}
|
|
|
|
|
|
|
|
; Normal path code
|
|
|
|
|
|
|
|
; CHECK: {{^}}safe_div:
|
|
|
|
; CHECK: .seh_proc safe_div
|
|
|
|
; CHECK: .seh_handler __C_specific_handler, @unwind, @except
|
|
|
|
; CHECK: .Ltmp0:
|
2015-10-10 07:05:54 +08:00
|
|
|
; CHECK: leaq [[rloc:.*\(%rbp\)]], %rcx
|
2015-01-14 09:05:27 +08:00
|
|
|
; CHECK: callq try_body
|
|
|
|
; CHECK-NEXT: .Ltmp1
|
2015-04-22 02:23:57 +08:00
|
|
|
; CHECK: [[cont_bb:\.LBB0_[0-9]+]]:
|
2015-01-14 09:05:27 +08:00
|
|
|
; CHECK: movl [[rloc]], %eax
|
|
|
|
; CHECK: retq
|
|
|
|
|
|
|
|
; Landing pad code
|
|
|
|
|
2016-04-08 05:29:39 +08:00
|
|
|
; CHECK: [[handler1:\.LBB0_[0-9]+]]: # %handler1
|
2015-01-14 09:05:27 +08:00
|
|
|
; CHECK: callq puts
|
2016-04-08 05:29:39 +08:00
|
|
|
; CHECK: movl $-2, [[rloc]]
|
2015-04-22 02:23:57 +08:00
|
|
|
; CHECK: jmp [[cont_bb]]
|
2015-01-14 09:05:27 +08:00
|
|
|
|
2016-04-08 05:29:39 +08:00
|
|
|
; CHECK: [[handler0:\.LBB0_[0-9]+]]: # %handler0
|
2015-01-14 09:05:27 +08:00
|
|
|
; CHECK: callq puts
|
2016-04-08 05:29:39 +08:00
|
|
|
; CHECK: movl $-1, [[rloc]]
|
2015-04-22 02:23:57 +08:00
|
|
|
; CHECK: jmp [[cont_bb]]
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
; CHECK: .seh_handlerdata
|
2015-12-16 07:40:58 +08:00
|
|
|
; CHECK-NEXT: .Lsafe_div$parent_frame_offset
|
2015-10-10 07:05:54 +08:00
|
|
|
; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16
|
|
|
|
; CHECK-NEXT: .Llsda_begin0:
|
|
|
|
; CHECK-NEXT: .long .Ltmp0@IMGREL+1
|
2015-04-22 02:23:57 +08:00
|
|
|
; CHECK-NEXT: .long .Ltmp1@IMGREL+1
|
|
|
|
; CHECK-NEXT: .long safe_div_filt0@IMGREL
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
; CHECK-NEXT: .long [[handler0]]@IMGREL
|
2015-10-10 07:05:54 +08:00
|
|
|
; CHECK-NEXT: .long .Ltmp0@IMGREL+1
|
2015-04-22 02:23:57 +08:00
|
|
|
; CHECK-NEXT: .long .Ltmp1@IMGREL+1
|
|
|
|
; CHECK-NEXT: .long safe_div_filt1@IMGREL
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 13:38:55 +08:00
|
|
|
; CHECK-NEXT: .long [[handler1]]@IMGREL
|
2015-10-10 07:05:54 +08:00
|
|
|
; CHECK-NEXT: .Llsda_end0:
|
2015-01-14 09:05:27 +08:00
|
|
|
; CHECK: .text
|
|
|
|
; CHECK: .seh_endproc
|
|
|
|
|
|
|
|
define void @try_body(i32* %r, i32* %n, i32* %d) {
|
|
|
|
entry:
|
2015-02-28 05:17:42 +08:00
|
|
|
%0 = load i32, i32* %n, align 4
|
|
|
|
%1 = load i32, i32* %d, align 4
|
2015-01-14 09:05:27 +08:00
|
|
|
%div = sdiv i32 %0, %1
|
|
|
|
store i32 %div, i32* %r, align 4
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; The prototype of these filter functions is:
|
|
|
|
; int filter(EXCEPTION_POINTERS *eh_ptrs, void *rbp);
|
|
|
|
|
|
|
|
; The definition of EXCEPTION_POINTERS is:
|
|
|
|
; typedef struct _EXCEPTION_POINTERS {
|
|
|
|
; EXCEPTION_RECORD *ExceptionRecord;
|
|
|
|
; CONTEXT *ContextRecord;
|
|
|
|
; } EXCEPTION_POINTERS;
|
|
|
|
|
|
|
|
; The definition of EXCEPTION_RECORD is:
|
|
|
|
; typedef struct _EXCEPTION_RECORD {
|
|
|
|
; DWORD ExceptionCode;
|
|
|
|
; ...
|
|
|
|
; } EXCEPTION_RECORD;
|
|
|
|
|
|
|
|
; The exception code can be retreived with two loads, one for the record
|
|
|
|
; pointer and one for the code. The values of local variables can be
|
|
|
|
; accessed via rbp, but that would require additional not yet implemented LLVM
|
|
|
|
; support.
|
|
|
|
|
|
|
|
define i32 @safe_div_filt0(i8* %eh_ptrs, i8* %rbp) {
|
|
|
|
%eh_ptrs_c = bitcast i8* %eh_ptrs to i32**
|
2015-02-28 05:17:42 +08:00
|
|
|
%eh_rec = load i32*, i32** %eh_ptrs_c
|
|
|
|
%eh_code = load i32, i32* %eh_rec
|
2015-01-14 09:05:27 +08:00
|
|
|
; EXCEPTION_ACCESS_VIOLATION = 0xC0000005
|
|
|
|
%cmp = icmp eq i32 %eh_code, 3221225477
|
|
|
|
%filt.res = zext i1 %cmp to i32
|
|
|
|
ret i32 %filt.res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @safe_div_filt1(i8* %eh_ptrs, i8* %rbp) {
|
|
|
|
%eh_ptrs_c = bitcast i8* %eh_ptrs to i32**
|
2015-02-28 05:17:42 +08:00
|
|
|
%eh_rec = load i32*, i32** %eh_ptrs_c
|
|
|
|
%eh_code = load i32, i32* %eh_rec
|
2015-01-14 09:05:27 +08:00
|
|
|
; EXCEPTION_INT_DIVIDE_BY_ZERO = 0xC0000094
|
|
|
|
%cmp = icmp eq i32 %eh_code, 3221225620
|
|
|
|
%filt.res = zext i1 %cmp to i32
|
|
|
|
ret i32 %filt.res
|
|
|
|
}
|
|
|
|
|
|
|
|
@str_result = internal constant [21 x i8] c"safe_div result: %d\0A\00"
|
|
|
|
|
|
|
|
define i32 @main() {
|
|
|
|
%d.addr = alloca i32, align 4
|
|
|
|
%n.addr = alloca i32, align 4
|
|
|
|
|
|
|
|
store i32 10, i32* %n.addr, align 4
|
|
|
|
store i32 2, i32* %d.addr, align 4
|
|
|
|
%r1 = call i32 @safe_div(i32* %n.addr, i32* %d.addr)
|
[opaque pointer type] Add textual IR support for explicit type parameter to the call instruction
See r230786 and r230794 for similar changes to gep and load
respectively.
Call is a bit different because it often doesn't have a single explicit
type - usually the type is deduced from the arguments, and just the
return type is explicit. In those cases there's no need to change the
IR.
When that's not the case, the IR usually contains the pointer type of
the first operand - but since typed pointers are going away, that
representation is insufficient so I'm just stripping the "pointerness"
of the explicit type away.
This does make the IR a bit weird - it /sort of/ reads like the type of
the first operand: "call void () %x(" but %x is actually of type "void
()*" and will eventually be just of type "ptr". But this seems not too
bad and I don't think it would benefit from repeating the type
("void (), void () * %x(" and then eventually "void (), ptr %x(") as has
been done with gep and load.
This also has a side benefit: since the explicit type is no longer a
pointer, there's no ambiguity between an explicit type and a function
that returns a function pointer. Previously this case needed an explicit
type (eg: a function returning a void() function was written as
"call void () () * @x(" rather than "call void () * @x(" because of the
ambiguity between a function returning a pointer to a void() function
and a function returning void).
No ambiguity means even function pointer return types can just be
written alone, without writing the whole function's type.
This leaves /only/ the varargs case where the explicit type is required.
Given the special type syntax in call instructions, the regex-fu used
for migration was a bit more involved in its own unique way (as every
one of these is) so here it is. Use it in conjunction with the apply.sh
script and associated find/xargs commands I've provided in rr230786 to
migrate your out of tree tests. Do let me know if any of this doesn't
cover your cases & we can iterate on a more general script/regexes to
help others with out of tree tests.
About 9 test cases couldn't be automatically migrated - half of those
were functions returning function pointers, where I just had to manually
delete the function argument types now that we didn't need an explicit
function type there. The other half were typedefs of function types used
in calls - just had to manually drop the * from those.
import fileinput
import sys
import re
pat = re.compile(r'((?:=|:|^|\s)call\s(?:[^@]*?))(\s*$|\s*(?:(?:\[\[[a-zA-Z0-9_]+\]\]|[@%](?:(")?[\\\?@a-zA-Z0-9_.]*?(?(3)"|)|{{.*}}))(?:\(|$)|undef|inttoptr|bitcast|null|asm).*$)')
addrspace_end = re.compile(r"addrspace\(\d+\)\s*\*$")
func_end = re.compile("(?:void.*|\)\s*)\*$")
def conv(match, line):
if not match or re.search(addrspace_end, match.group(1)) or not re.search(func_end, match.group(1)):
return line
return line[:match.start()] + match.group(1)[:match.group(1).rfind('*')].rstrip() + match.group(2) + line[match.end():]
for line in sys.stdin:
sys.stdout.write(conv(re.search(pat, line), line))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
call void (i8*, ...) @printf(i8* getelementptr ([21 x i8], [21 x i8]* @str_result, i32 0, i32 0), i32 %r1)
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
store i32 10, i32* %n.addr, align 4
|
|
|
|
store i32 0, i32* %d.addr, align 4
|
|
|
|
%r2 = call i32 @safe_div(i32* %n.addr, i32* %d.addr)
|
[opaque pointer type] Add textual IR support for explicit type parameter to the call instruction
See r230786 and r230794 for similar changes to gep and load
respectively.
Call is a bit different because it often doesn't have a single explicit
type - usually the type is deduced from the arguments, and just the
return type is explicit. In those cases there's no need to change the
IR.
When that's not the case, the IR usually contains the pointer type of
the first operand - but since typed pointers are going away, that
representation is insufficient so I'm just stripping the "pointerness"
of the explicit type away.
This does make the IR a bit weird - it /sort of/ reads like the type of
the first operand: "call void () %x(" but %x is actually of type "void
()*" and will eventually be just of type "ptr". But this seems not too
bad and I don't think it would benefit from repeating the type
("void (), void () * %x(" and then eventually "void (), ptr %x(") as has
been done with gep and load.
This also has a side benefit: since the explicit type is no longer a
pointer, there's no ambiguity between an explicit type and a function
that returns a function pointer. Previously this case needed an explicit
type (eg: a function returning a void() function was written as
"call void () () * @x(" rather than "call void () * @x(" because of the
ambiguity between a function returning a pointer to a void() function
and a function returning void).
No ambiguity means even function pointer return types can just be
written alone, without writing the whole function's type.
This leaves /only/ the varargs case where the explicit type is required.
Given the special type syntax in call instructions, the regex-fu used
for migration was a bit more involved in its own unique way (as every
one of these is) so here it is. Use it in conjunction with the apply.sh
script and associated find/xargs commands I've provided in rr230786 to
migrate your out of tree tests. Do let me know if any of this doesn't
cover your cases & we can iterate on a more general script/regexes to
help others with out of tree tests.
About 9 test cases couldn't be automatically migrated - half of those
were functions returning function pointers, where I just had to manually
delete the function argument types now that we didn't need an explicit
function type there. The other half were typedefs of function types used
in calls - just had to manually drop the * from those.
import fileinput
import sys
import re
pat = re.compile(r'((?:=|:|^|\s)call\s(?:[^@]*?))(\s*$|\s*(?:(?:\[\[[a-zA-Z0-9_]+\]\]|[@%](?:(")?[\\\?@a-zA-Z0-9_.]*?(?(3)"|)|{{.*}}))(?:\(|$)|undef|inttoptr|bitcast|null|asm).*$)')
addrspace_end = re.compile(r"addrspace\(\d+\)\s*\*$")
func_end = re.compile("(?:void.*|\)\s*)\*$")
def conv(match, line):
if not match or re.search(addrspace_end, match.group(1)) or not re.search(func_end, match.group(1)):
return line
return line[:match.start()] + match.group(1)[:match.group(1).rfind('*')].rstrip() + match.group(2) + line[match.end():]
for line in sys.stdin:
sys.stdout.write(conv(re.search(pat, line), line))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
call void (i8*, ...) @printf(i8* getelementptr ([21 x i8], [21 x i8]* @str_result, i32 0, i32 0), i32 %r2)
|
2015-01-14 09:05:27 +08:00
|
|
|
|
|
|
|
%r3 = call i32 @safe_div(i32* %n.addr, i32* null)
|
[opaque pointer type] Add textual IR support for explicit type parameter to the call instruction
See r230786 and r230794 for similar changes to gep and load
respectively.
Call is a bit different because it often doesn't have a single explicit
type - usually the type is deduced from the arguments, and just the
return type is explicit. In those cases there's no need to change the
IR.
When that's not the case, the IR usually contains the pointer type of
the first operand - but since typed pointers are going away, that
representation is insufficient so I'm just stripping the "pointerness"
of the explicit type away.
This does make the IR a bit weird - it /sort of/ reads like the type of
the first operand: "call void () %x(" but %x is actually of type "void
()*" and will eventually be just of type "ptr". But this seems not too
bad and I don't think it would benefit from repeating the type
("void (), void () * %x(" and then eventually "void (), ptr %x(") as has
been done with gep and load.
This also has a side benefit: since the explicit type is no longer a
pointer, there's no ambiguity between an explicit type and a function
that returns a function pointer. Previously this case needed an explicit
type (eg: a function returning a void() function was written as
"call void () () * @x(" rather than "call void () * @x(" because of the
ambiguity between a function returning a pointer to a void() function
and a function returning void).
No ambiguity means even function pointer return types can just be
written alone, without writing the whole function's type.
This leaves /only/ the varargs case where the explicit type is required.
Given the special type syntax in call instructions, the regex-fu used
for migration was a bit more involved in its own unique way (as every
one of these is) so here it is. Use it in conjunction with the apply.sh
script and associated find/xargs commands I've provided in rr230786 to
migrate your out of tree tests. Do let me know if any of this doesn't
cover your cases & we can iterate on a more general script/regexes to
help others with out of tree tests.
About 9 test cases couldn't be automatically migrated - half of those
were functions returning function pointers, where I just had to manually
delete the function argument types now that we didn't need an explicit
function type there. The other half were typedefs of function types used
in calls - just had to manually drop the * from those.
import fileinput
import sys
import re
pat = re.compile(r'((?:=|:|^|\s)call\s(?:[^@]*?))(\s*$|\s*(?:(?:\[\[[a-zA-Z0-9_]+\]\]|[@%](?:(")?[\\\?@a-zA-Z0-9_.]*?(?(3)"|)|{{.*}}))(?:\(|$)|undef|inttoptr|bitcast|null|asm).*$)')
addrspace_end = re.compile(r"addrspace\(\d+\)\s*\*$")
func_end = re.compile("(?:void.*|\)\s*)\*$")
def conv(match, line):
if not match or re.search(addrspace_end, match.group(1)) or not re.search(func_end, match.group(1)):
return line
return line[:match.start()] + match.group(1)[:match.group(1).rfind('*')].rstrip() + match.group(2) + line[match.end():]
for line in sys.stdin:
sys.stdout.write(conv(re.search(pat, line), line))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
call void (i8*, ...) @printf(i8* getelementptr ([21 x i8], [21 x i8]* @str_result, i32 0, i32 0), i32 %r3)
|
2015-01-14 09:05:27 +08:00
|
|
|
ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @__C_specific_handler(...)
|
|
|
|
declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
|
|
|
|
declare void @puts(i8*)
|
|
|
|
declare void @printf(i8*, ...)
|
|
|
|
declare void @abort()
|