You are right. My changes would not work (the test I had was too simple).<div><br></div><div>So I should probably hook that up with the GC. Sounds fun!</div><div><br></div><div>Thanks Jeffrey for the explanations.</div><div>
<br></div><div>Nicolas<br><br><div class="gmail_quote">On Tue, Aug 24, 2010 at 4:08 AM, Jeffrey Yasskin <span dir="ltr"><<a href="mailto:jyasskin@google.com">jyasskin@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Mon, Aug 23, 2010 at 9:37 PM, nicolas geoffray<br>
<div class="im"><<a href="mailto:nicolas.geoffray@gmail.com">nicolas.geoffray@gmail.com</a>> wrote:<br>
><br>
><br>
</div><div class="im">> On Mon, Aug 23, 2010 at 8:57 PM, Jeffrey Yasskin <<a href="mailto:jyasskin@google.com">jyasskin@google.com</a>><br>
> wrote:<br>
>><br>
>> I'm not sure processDebugLoc does what you need it to, even with your<br>
>> changes. It only records an address when the DebugLoc changes, and<br>
>> that's not guaranteed to happen exactly on the call<br>
>> MachineInstruction. (Unless you've done something to ensure it does?)<br>
><br>
> Each call instruction and only call instructions have metadata associated to<br>
> it. So I am sure emitting the debug location after emitting the call<br>
> instructions work for my case.<br>
<br>
</div>A CallInst in the IR expands to several MachineInstructions, all of<br>
which have the same DebugLoc (and which may be rearranged/interleaved<br>
with other DebugLoc'ed MIs by the SelectionDAG (ScheduleDAG?)). For<br>
example, the following IR:<br>
<br>
@.str = private constant [12 x i8] c"Hello World\00" ; <[12 x i8]*> [#uses=1]<br>
<br>
define i32 @main() nounwind {<br>
entry:<br>
%call = tail call i32 @puts(i8* getelementptr inbounds ([12 x i8]*<br>
@.str, i32 0, i32 0)) nounwind, !dbg !6 ; <i32> [#uses=0]<br>
ret i32 0, !dbg !8<br>
}<br>
<br>
declare i32 @puts(i8* nocapture) nounwind<br>
<br>
!llvm.dbg.sp = !{!0}<br>
<br>
!0 = metadata !{i32 524334, i32 0, metadata !1, metadata !"main",<br>
metadata !"main", metadata !"main", metadata !1, i32 2, metadata !3,<br>
i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false, null} ; [<br>
DW_TAG_subprogram ]<br>
!1 = metadata !{i32 524329, metadata !"test.c", metadata<br>
!"/Users/jyasskin/tmp", metadata !2} ; [ DW_TAG_file_type ]<br>
!2 = metadata !{i32 524305, i32 0, i32 12, metadata !"test.c",<br>
metadata !"/Users/jyasskin/tmp", metadata !"clang 2.8", i1 true, i1<br>
true, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]<br>
!3 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1,<br>
i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [<br>
DW_TAG_subroutine_type ]<br>
!4 = metadata !{metadata !5}<br>
!5 = metadata !{i32 524324, metadata !1, metadata !"int", metadata !1,<br>
i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]<br>
!6 = metadata !{i32 3, i32 3, metadata !7, null}<br>
!7 = metadata !{i32 524299, metadata !0, i32 2, i32 12} ; [<br>
DW_TAG_lexical_block ]<br>
!8 = metadata !{i32 4, i32 1, metadata !7, null}<br>
<br>
<br>
Produces the following MachineFunction:<br>
<br>
BB#0: derived from LLVM BB %entry<br>
%ESP<def> = SUB32ri8 %ESP, 12, %EFLAGS<imp-def,dead>; dbg:test.c:3:3<br>
MOV32mi %ESP, 1, %reg0, 0, %reg0, <ga:@.str>; mem:ST4[Stack] dbg:test.c:3:3<br>
CALLpcrel32 <ga:@puts>, %EAX<imp-def,dead>, %ESP<imp-use>, ...; dbg:test.c:3:3<br>
%EAX<def> = MOV32r0 %EFLAGS<imp-def,dead><br>
%ESP<def> = ADD32ri8 %ESP, 12, %EFLAGS<imp-def,dead>; dbg:test.c:4:1<br>
RET %EAX<imp-use,kill>; dbg:test.c:4:1<br>
<br>
and saves addresses in processDebugLoc at the following MachineInstructions:<br>
<br>
%ESP<def> = SUB32ri8 %ESP, 12, %EFLAGS<imp-def,dead>; dbg:test.c:3:3<br>
%ESP<def> = ADD32ri8 %ESP, 12, %EFLAGS<imp-def,dead>; dbg:test.c:4:1<br>
<br>
That is, not the call instruction. So, I'm not sure why this is<br>
working for you...<br>
<div class="im"><br>
>> Do you have a unit test that shows this works in all cases?<br>
><br>
> Not sure about the "all cases", but at least it is working as intended for<br>
> me and these hooks (emitting before or after) were already present before my<br>
> changes.<br>
><br>
>><br>
>> Mapping return addresses to metadata seems like more of a job for the<br>
>> GC system, but that's not implemented for the JIT, so I can't very<br>
>> well say to use it instead. :-/<br>
><br>
> Indeed, doing it in the GC system would also work, but the changes would be<br>
> way less straightforward than this simple change in the JITemitter.<br>
> Nicolas<br>
</div><div><div></div><div class="h5">> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
</div></div></blockquote></div><br></div>