Getting the original high-level code

Dear All

Is there is a way I can get the original hogh level code (e.g c++ code) of an IR function within MCJIT?

There’s nothing built into LLVM and Clang for going backwards through the lowering chain (MC->IR, IR->C++, etc). I think some third parties have built some pieces of this, but of course it is rather lossy.

Hi Marwa,

There’s no generic way to de-compile IR, but if the IR has debug info attached you may be able to find the path to the original source file.

  • Lang.

Thanks a million!

You might want to specify the context. Are you compiling high level code to LLVM IR to MachineInstr to MC and then wanting to map an MC instruction back to a source level instruction? Or are you disassembling a binary program to the MC IR and then wanting to reconstruct the source code? The answer to your question depends on which of these you are trying to do. Regards, John Criswell

I’ve compiled high level to IR and I want to get the original source code (Not to generate high level code) of a given IR function or part of function like a loop for example.

From what I understand, this is probably pretty difficult. I have a student (Ethan) who needs to use LLVM IR analysis information from a MachineFunctionPass, and that is proving to be problematic as the code generator will insert new instructions not visible at the LLVM IR level. I suspect that, at best, you can locate the basic block that corresponds to the code you are analyzing, but you will probably need to use debug information after that to get anything more accurate. As an FYI, I’ve suggested a GSoC project to encode high-level analysis information (e.g, call graph, points-to results) into the MachineInstr IR during code generation. If that would be useful to others, I’d like to know. Regards, John Criswell