numba / llvmlite

A lightweight LLVM python binding for writing JIT compilers
https://llvmlite.pydata.org/
BSD 2-Clause "Simplified" License
1.94k stars 322 forks source link

Source code location of IR instruction #1070

Open xuzhaoch opened 4 months ago

xuzhaoch commented 4 months ago

Feature request

I am using IR files to construct data flow for some specific static code check. llvmlite helps me to convert ir file to the data which I can use directly. And I also noticed that at the end of the ir file, there are metadata for every instructions, which can offer the source code location. Is there any function or interface in the llvmlite, that can give the source code location of every instruction?

esc commented 4 months ago

Unfortunately this isn't supported and you will have to parse the file manually.

xuzhaoch commented 4 months ago

Unfortunately this isn't supported and you will have to parse the file manually.

If using llvmlite.binding.parse_bitcode to parse the bc file, can I get these metadata lines? Or the only way is to read the ll file and use regex to extract the corresponding content?

esc commented 3 months ago

Unfortunately this isn't supported and you will have to parse the file manually.

If using llvmlite.binding.parse_bitcode to parse the bc file, can I get these metadata lines? Or the only way is to read the ll file and use regex to extract the corresponding content?

Looking at:

https://llvmlite.readthedocs.io/en/latest/user-guide/binding/modules.html#llvmlite.binding.parse_bitcode

my guess is that the data you are looking for will not be part of the returned ModuleRef. So yes, as far as I can tell, you'll need to use regular expressions.

gmarkall commented 3 months ago

My interpretation of this request is that we could support this by wrapping the getDebugLoc() function (and similar / related APIs as necessary).

I don't think there's availability for anyone to pick this up right now, but I think a contribution that implements support for the required APIs could be considered. However, to provide appropriate expectations: any PR that we could practically review would have to be fairly complete - i.e. include appropriate tests and documentation, and for the changes to be in keeping with the existing codebase - I don't think we have the bandwidth to guide / mentor the development of such a contribution.