Adding function debug information#628
Conversation
|
Can one of the admins verify this patch? |
* add new cmake option NMODL_ENABLE_JIT_EVENT_LISTENERS to enable perf & vtune * multiple calls to llvm_map_components_to_libnames doesnt work on linux and hence create list * fix BB5 CI with new llvm installation which has perf & vtune enabled * user perf & vtune listeners iff enabled via cmake option
bfc4299 to
651b257
Compare
| llvm_opt->add_flag("--add-debug-info", | ||
| add_debug_information, | ||
| "Add debug information ({})"_format(add_debug_information))->ignore_case(); |
There was a problem hiding this comment.
Wondering if we should always add debug info (or have it ON)
There was a problem hiding this comment.
We can, yes, then a flag --disable-debug-info can be used to turn it off instead. What do you think?
There was a problem hiding this comment.
👍 : the reason I mentioned to make it ON is that during development we need this all the time. So we don't need to add one more flag to CLI. (at least for now)
There was a problem hiding this comment.
Agree! Will change that!
| /// we may want to handle this properly. | ||
| struct Location { | ||
| /// Line in the file. | ||
| int line; | ||
|
|
||
| /// Column in the file. | ||
| int column; | ||
| }; |
There was a problem hiding this comment.
to understand - once we add proper Token to the CodegenFunction nodes then this won't be needed?
There was a problem hiding this comment.
I am not sure here. So far I pass proper tokens from ProcedureBlock and FunctionBlock, so that the lines are known. But if the node is created artificially (e.g. in the kernel), there is no line/column information.
My idea for that class was to have it as a wrapper around location, so that Token is used on the lexer/parser level, and for code generation a Location wrapper is used (So we separate these two and can add some more functionality to location, such as loc.getNextLocation(), etc. Hence, knowing the location of the function start, we can know roughly locations of the inner AST nodes.) But that's not very defined to me yet - so I made this struct for now:)
There was a problem hiding this comment.
Ok understood. Having bit separation with a wrapper not a bad idea. 👍
| // with listeners on (e.g. -DLLVM_USE_PERF=ON). | ||
| if (benchmark_info) { | ||
| gdb_event_listener = llvm::JITEventListener::createGDBRegistrationListener(); | ||
| #if defined(NMODL_HAVE_JIT_EVENT_LISTENERS) |
There was a problem hiding this comment.
It is actually safe to not use #if since if flag for listeners not set in LLVM build, these will be nullptr. But it is better not to rely on that, I agree!
There was a problem hiding this comment.
But, note that if createPerfJITEventListener() and createIntelJITEventListener() are used but we are not linking to libraries or don't have them then we get undefined reference error. This is why added it.
There was a problem hiding this comment.
I see, that's right!
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
Added debug support to LLVM code generation pipeline. Currently,
only basic support was added:
1. Debug information about functions (name)
2. Debug information about module
**What has been changed and added**
1. A new class `DebugBuilder` was created. It is used as a wrapper
around LLVM's `DIBuilder` and holds important information such as
`LLVMContext`, debug file and compile unit. It also wraps `DIBuilder`'s
functionality into a more suitable API.
2. A temporary `Location` struct has been added. It encapsulates the
location of the source AST construct and reflects `ModToken` on LLVM
code generation level. It is only used if the location of the source NMODL
function is known.
3. LLVM visitor know takes an extra `add_debug_information` flag and
handles debug information creation. Fore readability, `IRBuilder` was
renamed to `ir_builder`.
4. JIT runner is now able to listen for GDB, perf (build LLVM with
`-DLLVM_USE_PERF=ON`) and VTune (build LLVM with
`-DLLVM_USE_INTEL_JITEVENTS=ON`) events.
5. Necessary cmake changes were added to optionally support JIT event
listeners (`-DNMODL_HAVE_JIT_EVENT_LISTENERS`).
**How to generate debug information**
Debug information is attached to every function, procedure or artificially
created kernel (and corresponding wrappers). Debug information is enable
by default, so to turn it off use ` --disable-debug-info` flag. For example,
the given NMODL
```nmodl
1 FUNCTION func(x) {
2 func = x
3 }
4
5 PROCEDURE proc() {}
```
is transformed (running `./bin/nmodl <filename>.mod llvm --ir`) into
```llvm
define double @func(double %x1) !dbg !4 {
; ...
}
define i32 @proc() !dbg !6 {
; ...
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "NMODL-LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "foo", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Version", i32 3}
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !2)
!6 = distinct !DISubprogram(name: "proc", linkageName: "proc", scope: null, file: !1, line: 5, type: !5, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
```
fixes #592 #612
Co-authored-by: Pramod Kumbhar <pramod.s.kumbhar@gmail.com>
This PR introduces debug support to LLVM code generation pipeline. Currently, only basic support was added:
What is supported
What has been changed and added
A new class
DebugBuilderwas created. It is used as a wrapper around LLVM'sDIBuilderand holds important information such asLLVMContext, debug file and compile unit. It also wrapsDIBuilder's functionality into a more suitable API.A temporary
Locationstruct has been added. It encapsulates the location of the source AST construct and reflectsModTokenon LLVM code generation level. It is only used if the location of the source NMODL function is known.LLVM visitor know takes an extra
add_debug_informationflag and handles debug information creation. Fore readability,IRBuilderwas renamed toir_builder.JIT runner is now able to listen for GDB, perf (build LLVM with
-DLLVM_USE_PERF=ON) and VTune (build LLVM with-DLLVM_USE_INTEL_JITEVENTS=ON) events.How to generate debug information
Debug information is attached to every function, procedure or artificially created kernel (and corresponding wrappers). For benchmarking, debug information is enabled by default. Debug information is enable by default, so to turn it off use
--disable-debug-infoflag. For example, the given NMODLis transformed (running
./bin/nmodl <filename>.mod llvm --ir) intofixes #592 #612