Russell Wallace via llvm-dev
2016-Apr-06 04:14 UTC
[llvm-dev] JIT compiler - showing generated machine code
When using LLVM as a JIT compiler, you can use module.dump() to show the generated intermediate code, which is good. Is there similarly a programmatic way to show the generated x64 machine code in assembly format? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160406/c7d22dab/attachment.html>
Sanjoy Das via llvm-dev
2016-Apr-06 05:12 UTC
[llvm-dev] JIT compiler - showing generated machine code
I'm not sure if there is a ready-made solution, but you can consider using the MC component of LLVM to easily write yourself a disassembler (easily == 100 to 200 LOC, if I recall correctly). For inspiration, take a look at how "llvm-mc --disassemble" works. -- Sanjoy Russell Wallace via llvm-dev wrote:> When using LLVM as a JIT compiler, you can use module.dump() to show the generated intermediate code, which is good. > > Is there similarly a programmatic way to show the generated x64 machine code in assembly format? > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
David Chisnall via llvm-dev
2016-Apr-06 07:52 UTC
[llvm-dev] JIT compiler - showing generated machine code
On 6 Apr 2016, at 05:14, Russell Wallace via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > When using LLVM as a JIT compiler, you can use module.dump() to show the generated intermediate code, which is good. > > Is there similarly a programmatic way to show the generated x64 machine code in assembly format?If you want to do this solely for debugging, the easiest way is to print it out as hex bytes (“0xhhx”, byte) and then either pipe or redirect that output to llvm-mc. David
Caldarale, Charles R via llvm-dev
2016-Apr-06 12:26 UTC
[llvm-dev] JIT compiler - showing generated machine code
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] > On Behalf Of Sanjoy Das via llvm-dev > Subject: Re: [llvm-dev] JIT compiler - showing generated machine code> Russell Wallace via llvm-dev wrote: > > When using LLVM as a JIT compiler, you can use module.dump() to show the generated > > intermediate code, which is good. > > > > Is there similarly a programmatic way to show the generated x64 machine code in > > assembly format?> I'm not sure if there is a ready-made solution, but you can consider using the MC > component of LLVM to easily write yourself a disassembler (easily == 100 to 200 LOC, > if I recall correctly). For inspiration, take a look at how "llvm-mc --disassemble" > works.After generating code for the module, we use something like this to run an additional pass to display the assembly in the log: legacy::PassManager* pMPasses = new legacy::PassManager(); target_machine->Options.MCOptions.AsmVerbose = true; if (target_machine->addPassesToEmitFile(*pMPasses, *llvm_log, TargetMachine::CGFT_AssemblyFile)) { llvm_log->flush(); delete pMPasses; sysLogger("** could not add emit file pass **"); } else { pMPasses->run(*pMod); delete pMPasses; } We found that setting AsmVerbose early would often display different x86 code than was actually in the final functions. There might well be better ways to do this these days. - Chuck