<div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 24, 2018 at 3:27 AM Jacob Lifshay <<a href="mailto:programmerjake@gmail.com">programmerjake@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 23, 2018, 03:29 Yevgeny Rouban via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"><div>If all threads were bound to a non-null context then there would be no one which initialized the global options. This would result in unset default values. That is why we need the very first thread (that is used to load and initialize LLVM libraries) to have the ThreadOptionContext unset, so the default option values get into the default option storage. Then, I believe, it would be ok to force all threads to have non-null ThreadOptionContexts. In other words we need to identify the library loading thread and the initialization time period while the ThreadOptionContext must be null.</div><div>These are just my thoughts. I have not tried this use model.</div></div></div></blockquote></div></div><div dir="auto">If the global options are not used because every thread has a ThreadOptionContext, wouldn't it work fine to leave the global values uninitialized since nothing is using them? They could be initialized on first use.</div></div></blockquote><div><br></div><div>You are right, but on the first use where can the default values be found?</div><div>It seems I know how to force cl::opt initialization to be in the global context: we have to explicitly set the ThreadOptionContext to nullptr at the beginning of the the cl::opt constructor and restore it at the end - this way all applicators are applied with null context that is the default.</div><div><br></div><div><span style="font-family:monospace,monospace">  template <class... Mods><br>  explicit opt(const Mods &... Ms)<br>      : Option(Optional, NotHidden), Parser(*this) {</span></div><div><span style="font-family:monospace,monospace"><i>    
auto SavedCtx = ContextValues::<span class="gmail-o"></span><span class="gmail-n">ThreadOptionContext</span>;</i></span></div><div><span style="font-family:monospace,monospace"><i>    
<span class="gmail-nf">SetThreadOptionContex(nullptr);</span></i></span>

</div><div><span style="font-family:monospace,monospace">    apply(this, Ms...);</span></div><div><span style="font-family:monospace,monospace">
<i>    
<span class="gmail-nf">SetThreadOptionContex(SavedCtx);</span>



<br></i>    done();<br>  }<br></span></div><div><span style="font-family:monospace,monospace"></span></div><div><br></div><div>
Thanks.<br>-Yevgeny Rouban<br> 

<br></div></div></div></div></div>