<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Sep 17, 2013, at 10:25 AM, Hal Finkel <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">----- Original Message -----<br><blockquote type="cite">LLVM's internal command line library needs to evolve. We have an<br>immediate need to build LLVM as a library free of static<br>initializers, but before brute-force fixing this problem, I'd like<br>outline the incremental steps that will lead to a desirable long<br>term solution. We want infrastructure in place to provide an<br>evolutionary path.<br><br>In the near term, clients who need llvm-the-library with no static<br>initializers will build with LLVM_NO_STATICINIT. In this mode,<br>existing users of cl::opt will default to being optimized away as<br>constant initializers, and those options will not be available for<br>command line parsing.<br><br>A new option class will need be defined, cl::toolopt. Initially, this<br>will share the implementation and API with cl::opt. The only<br>difference will be that cl::toolopt is immune to LLVM_NO_STATICINIT.<br>Options that are required for tool support can simply be<br>type-renamed to toolopt. Since these are not defined in a library,<br>their static initializers are irrelevant.<br><br>Eventually, we would like to eliminate the special LLVM_NO_STATICINIT<br>build mode. This can be done by making the -Asserts build just as<br>strict. In the meantime, we would like to run as many unit tests as<br>possible with LLVM_NO_STATICINIT builds. This will be solved by<br>gradually moving cl::opt definitions buried within LLVM libraries to<br>to a new pattern that avoids static initialization.<br><br>One easy pattern to follow is to register the option during pass<br>initialization with all the convenient flags and parameters, but<br>refer to a globally defined option storage that enforces the<br>singleton and provides visibility. As long as pass initialization<br>happens before parseCommandLine, usage should be consistent.<br><br>Strawman:<br><br>cl::optval<bool> MyOption; // Just the storage, no initialization.<br><br>MyPass() {<br> // Only registers an option with the same optval once.<br> Option cl::registerOpt(MyOption, cl::init(false), cl::Hidden,<br>                        cl::desc("Descriptive string..."), );<br>}<br></blockquote><br>Sounds good to me.<br><br>Will this make it safe again to use -backend-option in Clang? [Not saying that we *want* to do that, but that's a separate matter].<br><br>Regardless of the answer to that question, it might make sense for multiple target backends to register options with the same name (currently, for example, both the X86 and PPC backends have options to force the use of a base pointer, and they need to have different names), it would be nice if that could be cleaned up as part of this.<br></div></blockquote><div><br></div>The only solution I have for this is to raise both options into the target-independent API. Currently, that means adding it to TargetOptions and moving the flag to CommandLineFlags.h. I feel like the way to improve this is by redesigning TargetOptions to be less ad-hoc. It would be nice to define an option string in one place and allow the option to be overridden as a function attribute or command line -mllvm option. We should probably have a declarative option syntax for this like clang.</div><div><br></div><div>-Andy</div><div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">--<span class="Apple-converted-space"> </span><br>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory</div></blockquote></div><br></body></html>