Hi Eric! On Apr 29, 2013, at 6:10 AM, Eric Christopher <[email protected]> wrote:
> Looks like it's working around the return value load/alloca eliding in
> the code generator? I definitely like a more general way of
> approaching the problem.
It’s possible that I misunderstood you (let me know) but I don’t think that’s
an accurate description. Here’s how I would describe it:
If there is
1) only a single, simple return stmt in the function,
2) and cleanup code,
3) prevent the the ret instruction from getting a debug location that is
“above” the debug location of the clean code. If there is no cleanup code,
however, we still want the return instruction to get the debug location from
the elided alloca.
I agree that it looks like a rather specialized solution, but it’s also a
rather special problem.
> I wonder if we can either localize this fix into EmitFunctionEpilog
> (couldn't come up with one) or if this has applicability in the > 1
> return statement condition. Open questions, this is a bit of a finicky
> and complicated area as you've no doubt realized. :)
No doubt :-)
I believe that we cannot localize the patch into EmitFunctionEpilog: If there
is cleanup code, we (I?) want the cleanup code to get the line number of the
return statement, because it will be the first breakpoint opportunity in the
function, and we must keep it, because the user might want to inspect the value
of arguments that will get cleaned up. We can only do this in FinishFunction.
In the case of multiple returns the problem with the cleanup code being the
first breakpoint in the function should not exist, because there should be some
other statement with a debug location before any return statement.
> One other comment on the patch:
>
> + if (CGDebugInfo *DI = getDebugInfo()) {
> DI->EmitLocation(Builder, EndLoc);
> + EndLocL = Builder.getCurrentDebugLocation();
> + if ((NStopPoints == 1) && !FnRetTy->isVoidType()) {
> + DI->EmitLocation(Builder, FirstStopPoint);
> + EmitRetDbgLoc = false;
>
> Do we need the two locations emitted here?
We don’t, of course :-)
> or the check for VoidType?
Removed together with RetDbgLoc.
I took the opportunity to cleanup and document the patch some more. It now
accurately detects whether the single return expression could be evaluated to a
constant expression. I also made the test case more comprehensive.
thanks,
Adrian
PS: To help visualizing the effects, I attached the output of a script that
interleaves the source lines and the disassembler output based in the line
table. (I ran it on the testcase).
0002-Ensure-that-the-line-table-for-functions-with-cleanu.patch
Description: Binary data
[92mtest.o:[0m
[92m(__TEXT,__text) section[0m
[92m-[AppDelegate testNoSideEffect:]:[0m
arc-linetable.m:[91m50[0m [94m- (int)testNoSideEffect:(NSString
*)foo {[0m // ['is_stmt']
0000000000000000 pushq %rbp
0000000000000001 movq %rsp, %rbp
0000000000000004 subq $0x20, %rsp
0000000000000008 leaq 0xffffffffffffffe8(%rbp), %rax
000000000000000c movq %rdi, 0xfffffffffffffff8(%rbp)
0000000000000010 movq %rsi, 0xfffffffffffffff0(%rbp)
0000000000000014 movq $0x0, 0xffffffffffffffe8(%rbp)
000000000000001c movq %rax, %rdi
000000000000001f movq %rdx, %rsi
0000000000000022 callq 0x27
0000000000000027 movabsq $0x0, %rsi
0000000000000031 leaq 0xffffffffffffffe8(%rbp), %rax
0000000000000035 movl $0x1, 0xffffffffffffffe4(%rbp)
arc-linetable.m:[91m52[0m [94m return 1; // Return
expression[0m // ['is_stmt', 'prologue_end']
000000000000003c movq %rax, %rdi
000000000000003f callq 0x44
0000000000000044 movl $0x1, %eax
arc-linetable.m:[91m54[0m [94m} // Cleanup + Ret[0m
// ['is_stmt']
0000000000000049 addq $0x20, %rsp
000000000000004d popq %rbp
000000000000004e ret
000000000000004f nop
[92m-[AppDelegate testNoCleanup]:[0m
arc-linetable.m:[91m56[0m [94m- (int)testNoCleanup {[0m //
['is_stmt']
0000000000000050 pushq %rbp
0000000000000051 movq %rsp, %rbp
0000000000000054 movl $0x1, %eax
0000000000000059 movq %rdi, 0xfffffffffffffff8(%rbp)
000000000000005d movq %rsi, 0xfffffffffffffff0(%rbp)
arc-linetable.m:[91m58[0m [94m return 1;[0m // ['is_stmt',
'prologue_end']
0000000000000061 popq %rbp
0000000000000062 ret
0000000000000063 nopw %cs:(%rax,%rax)
[92m-[AppDelegate testSideEffect:]:[0m
arc-linetable.m:[91m61[0m [94m- (int)testSideEffect:(NSString
*)foo {[0m // ['is_stmt']
0000000000000070 pushq %rbp
0000000000000071 movq %rsp, %rbp
0000000000000074 subq $0x40, %rsp
0000000000000078 leaq 0xffffffffffffffe8(%rbp), %rax
000000000000007c movq %rdi, 0xfffffffffffffff8(%rbp)
0000000000000080 movq %rsi, 0xfffffffffffffff0(%rbp)
0000000000000084 movq $0x0, 0xffffffffffffffe8(%rbp)
000000000000008c movq %rax, %rdi
000000000000008f movq %rdx, %rsi
0000000000000092 callq 0x97
0000000000000097 movabsq $0x0, %rsi
00000000000000a1 leaq 0xffffffffffffffe8(%rbp), %rax
arc-linetable.m:[91m63[0m [94m return [self testNoSideEffect
:foo];[0m // ['is_stmt', 'prologue_end']
00000000000000a5 movq 0xfffffffffffffff8(%rbp), %rdx
00000000000000a9 movq 0xffffffffffffffe8(%rbp), %rdi
00000000000000ad movq 0xa0c(%rip), %rcx
00000000000000b4 movq %rdi, 0xffffffffffffffd8(%rbp)
00000000000000b8 movq %rdx, %rdi
00000000000000bb movq %rsi, 0xffffffffffffffd0(%rbp)
00000000000000bf movq %rcx, %rsi
00000000000000c2 movq 0xffffffffffffffd8(%rbp), %rdx
00000000000000c6 movq %rax, 0xffffffffffffffc8(%rbp)
00000000000000ca callq 0xcf
00000000000000cf movl $0x1, 0xffffffffffffffe4(%rbp)
arc-linetable.m:[91m65[0m [94m}[0m // ['is_stmt']
00000000000000d6 movq 0xffffffffffffffc8(%rbp), %rcx
00000000000000da movq %rcx, %rdi
00000000000000dd movq 0xffffffffffffffd0(%rbp), %rsi
00000000000000e1 movl %eax, 0xffffffffffffffc4(%rbp)
00000000000000e4 callq 0xe9
00000000000000e9 movl 0xffffffffffffffc4(%rbp), %eax
00000000000000ec addq $0x40, %rsp
00000000000000f0 popq %rbp
00000000000000f1 ret
00000000000000f2 nopw %cs:(%rax,%rax)
[92m-[AppDelegate testMultiline:]:[0m
arc-linetable.m:[91m67[0m [94m- (int)testMultiline:(NSString
*)foo {[0m // ['is_stmt']
0000000000000100 pushq %rbp
0000000000000101 movq %rsp, %rbp
0000000000000104 subq $0x40, %rsp
0000000000000108 leaq 0xffffffffffffffe8(%rbp), %rax
000000000000010c movq %rdi, 0xfffffffffffffff8(%rbp)
0000000000000110 movq %rsi, 0xfffffffffffffff0(%rbp)
0000000000000114 movq $0x0, 0xffffffffffffffe8(%rbp)
000000000000011c movq %rax, %rdi
000000000000011f movq %rdx, %rsi
0000000000000122 callq 0x127
0000000000000127 movabsq $0x0, %rsi
0000000000000131 leaq 0xffffffffffffffe8(%rbp), %rax
arc-linetable.m:[91m69[0m [94m int r = [self testSideEffect
:foo];[0m // ['is_stmt', 'prologue_end']
0000000000000135 movq 0xfffffffffffffff8(%rbp), %rdx
0000000000000139 movq 0xffffffffffffffe8(%rbp), %rdi
000000000000013d movq 0x984(%rip), %rcx
0000000000000144 movq %rdi, 0xffffffffffffffd8(%rbp)
0000000000000148 movq %rdx, %rdi
000000000000014b movq %rsi, 0xffffffffffffffd0(%rbp)
000000000000014f movq %rcx, %rsi
0000000000000152 movq 0xffffffffffffffd8(%rbp), %rdx
0000000000000156 movq %rax, 0xffffffffffffffc8(%rbp)
000000000000015a callq 0x15f
000000000000015f movl %eax, 0xffffffffffffffe4(%rbp)
arc-linetable.m:[91m71[0m [94m return r;[0m // ['is_stmt']
0000000000000162 movl 0xffffffffffffffe4(%rbp), %eax
0000000000000165 movl $0x1, 0xffffffffffffffe0(%rbp)
arc-linetable.m:[91m73[0m [94m}[0m // ['is_stmt']
000000000000016c movq 0xffffffffffffffc8(%rbp), %rcx
0000000000000170 movq %rcx, %rdi
0000000000000173 movq 0xffffffffffffffd0(%rbp), %rsi
0000000000000177 movl %eax, 0xffffffffffffffc4(%rbp)
000000000000017a callq 0x17f
000000000000017f movl 0xffffffffffffffc4(%rbp), %eax
0000000000000182 addq $0x40, %rsp
0000000000000186 popq %rbp
0000000000000187 ret
0000000000000188 nopl (%rax,%rax)
[92m-[AppDelegate testVoid:]:[0m
arc-linetable.m:[91m75[0m [94m- (void)testVoid:(NSString *)foo
{[0m // ['is_stmt']
0000000000000190 pushq %rbp
0000000000000191 movq %rsp, %rbp
0000000000000194 subq $0x20, %rsp
0000000000000198 leaq 0xffffffffffffffe8(%rbp), %rax
000000000000019c movq %rdi, 0xfffffffffffffff8(%rbp)
00000000000001a0 movq %rsi, 0xfffffffffffffff0(%rbp)
00000000000001a4 movq $0x0, 0xffffffffffffffe8(%rbp)
00000000000001ac movq %rax, %rdi
00000000000001af movq %rdx, %rsi
00000000000001b2 callq 0x1b7
00000000000001b7 movabsq $0x0, %rsi
00000000000001c1 leaq 0xffffffffffffffe8(%rbp), %rax
00000000000001c5 movl $0x1, 0xffffffffffffffe4(%rbp)
arc-linetable.m:[91m77[0m [94m return;[0m // ['is_stmt',
'prologue_end']
00000000000001cc movq %rax, %rdi
00000000000001cf callq 0x1d4
arc-linetable.m:[91m79[0m [94m}[0m // ['is_stmt']
00000000000001d4 addq $0x20, %rsp
00000000000001d8 popq %rbp
00000000000001d9 ret
00000000000001da nopw (%rax,%rax)
[92m-[AppDelegate testVoidNoReturn:]:[0m
arc-linetable.m:[91m81[0m [94m- (void)testVoidNoReturn:(NSString
*)foo {[0m // ['is_stmt']
00000000000001e0 pushq %rbp
00000000000001e1 movq %rsp, %rbp
00000000000001e4 subq $0x30, %rsp
00000000000001e8 leaq 0xffffffffffffffe8(%rbp), %rax
00000000000001ec movq %rdi, 0xfffffffffffffff8(%rbp)
00000000000001f0 movq %rsi, 0xfffffffffffffff0(%rbp)
00000000000001f4 movq $0x0, 0xffffffffffffffe8(%rbp)
00000000000001fc movq %rax, %rdi
00000000000001ff movq %rdx, %rsi
0000000000000202 callq 0x207
0000000000000207 movabsq $0x0, %rsi
0000000000000211 leaq 0xffffffffffffffe8(%rbp), %rax
arc-linetable.m:[91m83[0m [94m [self testVoid :foo];[0m //
['is_stmt', 'prologue_end']
0000000000000215 movq 0xfffffffffffffff8(%rbp), %rdx
0000000000000219 movq 0xffffffffffffffe8(%rbp), %rdi
000000000000021d movq 0x8ac(%rip), %rcx
0000000000000224 movq %rdi, 0xffffffffffffffe0(%rbp)
0000000000000228 movq %rdx, %rdi
000000000000022b movq %rsi, 0xffffffffffffffd8(%rbp)
000000000000022f movq %rcx, %rsi
0000000000000232 movq 0xffffffffffffffe0(%rbp), %rdx
0000000000000236 movq %rax, 0xffffffffffffffd0(%rbp)
000000000000023a callq 0x23f
arc-linetable.m:[91m85[0m [94m}[0m // ['is_stmt']
000000000000023f movq 0xffffffffffffffd0(%rbp), %rax
0000000000000243 movq %rax, %rdi
0000000000000246 movq 0xffffffffffffffd8(%rbp), %rsi
000000000000024a callq 0x24f
000000000000024f addq $0x30, %rsp
0000000000000253 popq %rbp
0000000000000254 ret
0000000000000255 nopw %cs:(%rax,%rax)
[92m-[AppDelegate testNoCleanupSideEffect]:[0m
arc-linetable.m:[91m87[0m [94m- (int)testNoCleanupSideEffect
{[0m // ['is_stmt']
0000000000000260 pushq %rbp
0000000000000261 movq %rsp, %rbp
0000000000000264 subq $0x20, %rsp
0000000000000268 movl $0x1, %eax
000000000000026d leaq 0x87c(%rip), %rcx
0000000000000274 movq %rdi, 0xfffffffffffffff8(%rbp)
0000000000000278 movq %rsi, 0xfffffffffffffff0(%rbp)
arc-linetable.m:[91m89[0m [94m [self testVoid :@"foo"];[0m //
['is_stmt', 'prologue_end']
000000000000027c movq 0xfffffffffffffff8(%rbp), %rsi
0000000000000280 movq 0x849(%rip), %rdi
0000000000000287 movq %rdi, 0xffffffffffffffe8(%rbp)
000000000000028b movq %rsi, %rdi
000000000000028e movq 0xffffffffffffffe8(%rbp), %rsi
0000000000000292 movq %rcx, %rdx
0000000000000295 movl %eax, 0xffffffffffffffe4(%rbp)
0000000000000298 callq 0x29d
arc-linetable.m:[91m91[0m [94m return 1;[0m // ['is_stmt']
000000000000029d movl 0xffffffffffffffe4(%rbp), %eax
00000000000002a0 addq $0x20, %rsp
00000000000002a4 popq %rbp
00000000000002a5 ret
00000000000002a6 nopw %cs:(%rax,%rax)
[92m_main:[0m
arc-linetable.m:[91m98[0m [94mint main(int argc, const char**
argv) {[0m // ['is_stmt']
00000000000002b0 pushq %rbp
00000000000002b1 movq %rsp, %rbp
00000000000002b4 subq $0x40, %rsp
00000000000002b8 movabsq $0x0, %rax
00000000000002c2 leaq 0xffffffffffffffe8(%rbp), %rcx
00000000000002c6 leaq 0x823(%rip), %rdx
00000000000002cd leaq (%rip), %r8
00000000000002d4 movl $0x0, 0xfffffffffffffffc(%rbp)
00000000000002db movl %edi, 0xfffffffffffffff8(%rbp)
00000000000002de movq %rsi, 0xfffffffffffffff0(%rbp)
arc-linetable.m:[91m99[0m [94m AppDelegate *o = [[AppDelegate
alloc] init];[0m // ['is_stmt', 'prologue_end']
00000000000002e2 movq 0x9e7(%rip), %rsi
00000000000002e9 movq %rsi, %rdi
00000000000002ec movq %r8, %rsi
00000000000002ef movq %rcx, 0xffffffffffffffd8(%rbp)
00000000000002f3 movq %rdx, 0xffffffffffffffd0(%rbp)
00000000000002f7 movq %rax, 0xffffffffffffffc8(%rbp)
00000000000002fb callq *(%rip)
0000000000000301 movq 0x7d0(%rip), %rsi
0000000000000308 movq %rax, %rdi
000000000000030b callq 0x310
0000000000000310 movq %rax, 0xffffffffffffffe8(%rbp)
arc-linetable.m:[91m100[0m [94m return [o testMultiline
:@"foo"];[0m // ['is_stmt']
0000000000000314 movq 0xffffffffffffffe8(%rbp), %rax
0000000000000318 movq 0x7c1(%rip), %rsi
000000000000031f movq %rax, %rdi
0000000000000322 movq 0xffffffffffffffd0(%rbp), %rdx
0000000000000326 callq 0x32b
000000000000032b movl %eax, 0xfffffffffffffffc(%rbp)
000000000000032e movl $0x1, 0xffffffffffffffe4(%rbp)
arc-linetable.m:[91m101[0m [94m}[0m // ['is_stmt']
0000000000000335 movq 0xffffffffffffffd8(%rbp), %rcx
0000000000000339 movq %rcx, %rdi
000000000000033c movq 0xffffffffffffffc8(%rbp), %rsi
0000000000000340 callq 0x345
0000000000000345 movl 0xfffffffffffffffc(%rbp), %eax
0000000000000348 addq $0x40, %rsp
000000000000034c popq %rbp
000000000000034d ret
[92m[0m
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
