<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Diego,<div><br></div><div>That is probably your best option for dumping textual assembly directly, but unless you need local symbol names and enhanced disassembly notes there is a better option: Dump object files from the JIT and disassemble them. Dumping object files has two advantages over assembly: (1) it avoids redundant codegen, so is much faster, and (2) the bits you're dumping are *exactly* the bits flowing into the JIT linker: there is no chance of getting misleading assembly due to a compiler misconfiguration or persistent state bug.</div><div><br></div><div>One way to dump object files, which works for both LLJIT and custom stacks, is to attach a dummy ObjectCache (see <a href="https://github.com/llvm/llvm-project/blob/master/llvm/examples/LLJITExamples/LLJITWithObjectCache/LLJITWithObjectCache.cpp">https://github.com/llvm/llvm-project/blob/master/llvm/examples/LLJITExamples/LLJITWithObjectCache/LLJITWithObjectCache.cpp</a>) and dump the ObjBuffers that are passed in to the cache to disk. You can just return 'nullptr' from your dummy cache's getObject method, since you are not really using it as a cache.</div><div><br></div><div>Alternatively, If you are writing a custom ORC stack there is a second option: You can insert an ObjectTransformLayer between your IRCompileLayer and ObjectLinkingLayer and use that to dump the buffers to disk.</div><div><br></div><div>I hope this helps!</div><div><br></div><div>-- Lang.</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 15, 2019 at 3:44 PM Caballero, Diego via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_9176325693401393302WordSection1">
<p class="MsoNormal">Hi all,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is there a way to dump the generated assembly from OrcJit? I found this thread about MCJIT but nothing specific about OrcJit:
<a href="http://lists.llvm.org/pipermail/llvm-dev/2014-June/074145.html" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2014-June/074145.html</a><u></u><u></u></p>
<p class="MsoNormal">I’m also aware of the alternative approach below, but I’m not sure if the output will be the same as the assembly generated by OrcJit. Probably not.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> std::string outStr;<u></u><u></u></p>
<p class="MsoNormal"> {<u></u><u></u></p>
<p class="MsoNormal"> llvm::legacy::PassManager pm;<u></u><u></u></p>
<p class="MsoNormal"> llvm::raw_string_ostream stream(outStr);<u></u><u></u></p>
<p class="MsoNormal"> llvm::buffer_ostream pstream(stream);<u></u><u></u></p>
<p class="MsoNormal"> targetMachine->addPassesToEmitFile(pm, pstream, nullptr,<u></u><u></u></p>
<p class="MsoNormal"> llvm::TargetMachine::CGFT_AssemblyFile);<u></u><u></u></p>
<p class="MsoNormal"> pm.run(*m);<u></u><u></u></p>
<p class="MsoNormal"> }<u></u><u></u></p>
<p class="MsoNormal"> llvm::errs() << "Assembly:\n" << outStr << "\n";<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks!<u></u><u></u></p>
<p class="MsoNormal">Diego<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>