<div dir="ltr">I thought that opt was supposed to basically be a way to run a PassManager over some IR? Seems like the new PM should standardize the appropriate things and have them be a natural part of its API.<div><br></div>
<div>-- Sean Silva</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 11, 2014 at 1:42 PM, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@google.com" target="_blank">eliben@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I started some refactoring work on tools/opt/opt.cpp in r201116, but conceptually this is part of a larger effort. I'd like to consult with llvmdev@ about the best way to move this forward.</div>


<div><br></div><div>Background: opt is a very useful swiss-army-knife tool, and its capabilities may be useful to custom tools. However, as it stands now opt is now very modular - almost all its functionality is contained within its main opt.cpp file.</div>


<div><br></div><div>I think this is also the cause of some code duplication that currently exists between different LLVM tools. For example, some code from opt.cpp is duplicated in llc.cpp; the same is true for the logic of adding optimization passes between opt.cpp and Clang (a comment in opt.cpp even admits it "duplicates llvm-gcc behaviour", showing its age :-) A lot of cl::opt definitions are duplicated between different tools and have to be kept in sync for consistency.</div>


<div><br></div><div>What I'd like to see is most of opt's functionality moving outside of opt.cpp to make it reusable in other tools. For example, this could be encapsulated in a class named OptTool, or just a namespace with a bunch of utility functions, as well as cl::opt definitions.</div>


<div><br></div><div>Such a transition can be done in steps: the first step would be to create this OptTool within tools/opt. This would immediately enable building custom opt-based tools by linking in the code from tools/opt, leaving tools/opt/opt.cpp out. A more ambitious step would be to move the functionality to a library (lib/Tools?) - enabling code reuse between different LLVM tools as well as easier use within custom tools.</div>


<div><br></div><div>Any opinions / suggestions welcome. I'll be happy to send out piecemeal patches that implement this refactoring.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Eli</div><div><br>
</div></font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>