<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'><div class=WordSection1><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> Matthias Braun [mailto:mbraun@apple.com] <br><b>Sent:</b> Thursday, July 2, 2015 6:51 PM<br><b>To:</b> Jim Grosbach<br><b>Cc:</b> Ethan J. Johnson; llvmdev@cs.uiuc.edu<br><b>Subject:</b> Re: [LLVMdev] Load MachineFunctionPass plugin from library in llc?<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On Jul 2, 2015, at 2:05 PM, Jim Grosbach <<a href="mailto:grosbach@apple.com">grosbach@apple.com</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><br>On Jul 2, 2015, at 1:17 PM, Ethan J. Johnson <<a href="mailto:ejohns48@cs.rochester.edu">ejohns48@cs.rochester.edu</a>> wrote:<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p><div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>Hi all,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>I am working on creating a MachineFunctionPass to perform an analysis on X86 code. After a bit of trouble, I was able to get my pass compiling and running correctly in llc. However, since a machine pass is compiled directly into the code generator, rerunning “make” across the LLVM build tree involves re-linking most of the major libraries and executables. This is a rather intense process, both in terms of CPU usage and memory (some of the bigger binaries, especially clang, use as much as 5 GB peak memory during linking). With a powerful multicore machine and plenty of RAM, this is doable, but still very time-consuming, and seems wastefully repetitive.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>For a front-end pass, I can load the pass from a dynamic shared library using “</span><span style='font-size:11.0pt;font-family:Consolas'>opt –l path_to_library</span><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>”; thus I only need to rebuild the pass itself to test a code change. There does not appear to be such an option in llc for dynamically linking a machine pass as a plugin. Does anyone know of a way to achieve something similar?<o:p></o:p></span></p></div></div></blockquote><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'>There is unfortunately no way to do that currently.<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>At the very least, it would be nice to be able to just re-compile the parts of the LLVM tree I need (perhaps just llc). It seems particularly odd that clang, which is a front-end, would need to be relinked for a code change in a back-end pass. (clang, and some of its related components, are responsible for the lion’s share of the time-consuming CPU/memory-intensive linking phase.)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> <o:p></o:p></span></p></div></div></blockquote><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'>clang the project is the front end, but clang the executable program is the full compiler, including all of optimization, codegen, object emission, etc..<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>FYI, I am using the Autotools (./configure, make) process to build LLVM, but have also successfully built with CMake and would be willing to try suggestions involving either.<o:p></o:p></span></p></div></div></blockquote><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Helvetica",sans-serif'>This, however, can be done, at least w/ CMake+ninja (probably other permutations, too, but that’s the one I use these days). Just do “ninja llc” and it will build just what’s required for llc. Same for any of the other tools.<o:p></o:p></span></p></div></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>Also enabling shared libraries "cmake -DBUILD_SHARED_LIBS=ON" reduces link times dramatically in my experience.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>- Matthias<o:p></o:p></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Thanks for the tips! I will definitely try building just llc, since that is all I need for testing/debugging the pass.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Out of curiosity, what exactly does BUILD_SHARED_LIBS do? Does it move most of the shared code to .so files and create binaries that load them at run time? If I go that route, is there anything special I need to do to make sure the binaries can “find” the shared libraries at run time? (I do not have root access on my development machine, so “make install” to put the shared libs in a standard location isn’t a really good option.)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Ethan Johnson<o:p></o:p></span></p></div></body></html>