-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code_llvm: print source locations #22819
Conversation
src/disasm.cpp
Outdated
#include "debuginfo.h" | ||
|
||
class LineNumberAnnotatedWriter : public AssemblyAnnotationWriter { | ||
DILocation *InstrLoc = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 space indent
src/disasm.cpp
Outdated
@@ -494,4 +721,15 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, | |||
DisInfo.createSymbols(); | |||
} | |||
} | |||
|
|||
extern "C" JL_DLLEXPORT | |||
LLVMDisasmContextRef jl_LLVMCreateDisasm(const char *TripleName, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
src/disasm.cpp
Outdated
|
||
void addSubprogram(const Function *F, DISubprogram *SP) | ||
{ | ||
Subprogram[F] = SP; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 space indent
Supplements the printing of LLVM IR with source location information
I may have gone slightly overboard in fixing Tony's latest review comment, and now print out all available line info. The purpose of this is so that we can see whether it looks right when making changes to the debugging info, and to help with matching up source code with emitted instructions:
|
Can we have a test for that new feature? |
We don't have a good way to unit test these, and it depends on LLVM optimizations and upstream representations, so we've been reluctant to commit too much to the exact representation this function returns ( Line 3 in cdaa5a7
|
LinePrinter.emit_finish(Out); | ||
} | ||
|
||
// print an llvm IR acquired from jl_get_llvmf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get instead of print?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't approve the PR if you request changes... 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think print
(as in -to-string
) is sufficiently clear as a verb, in context here.
// print an llvm IR acquired from jl_get_llvmf | ||
// warning: this takes ownership of, and destroys, f->getParent() | ||
extern "C" JL_DLLEXPORT | ||
const jl_value_t *jl_dump_function_ir(void *f, bool strip_ir_metadata, bool dump_module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe confine the NFC code movements to a separate commit next time, this is kinda annoying to review with GitHub's diff view.
return 0; | ||
} | ||
|
||
// print a native disassembly for the function starting at fptr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
Huh, how did I miss I don't like the current DILineInfoPrinter format though, pretty verbose and the braces are hard to follow. Maybe some indentation and/or structure characters and/or frame numbers, eg. define i64 @julia_sum_61779(%jl_value_t addrspace(10)* dereferenceable(40)) #0 {
top:
; frame 0 (sum @ reduce.jl:363)
; └frame 1 (countnz @ reduce.jl:725)
; └frame 2 (count @ reduce.jl:701)
; └frame 3 (eachindex @ abstractarray.jl:763)
; └frame 4 (indices1 @ abstractarray.jl:73)
; └frame 5 (indices @ abstractarray.jl:66)
%1 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
%2 = bitcast %jl_value_t addrspace(11)* %1 to %jl_value_t addrspace(10)* addrspace(11)*
%3 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %2, i64 3
%4 = bitcast %jl_value_t addrspace(10)* addrspace(11)* %3 to i64 addrspace(11)*
%5 = load i64, i64 addrspace(11)* %4, align 8
; └end frame 5 (indices)
; └end frame 4 (indices1)
; └end frame 3 (eachindex)
%6 = icmp slt i64 %5, 1
br i1 %6, label %L26, label %if.lr.ph
if.lr.ph: ; preds = %top
; reduce.jl:702 (frame 2)
%7 = bitcast %jl_value_t addrspace(11)* %1 to i8* addrspace(11)*
%8 = load i8*, i8* addrspace(11)* %7, align 8 |
That looks nice, although we don't have the nice pretty syntax coloring 😛 OK to merge, and encourage further experimentation in future PRs? |
Supplements the printing of LLVM IR with source location information.
With inspiration from #19342