<div dir="ltr">On 26 August 2013 17:39, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr">See EvaluateStaticConstructor in the same file, GlobalOpt.cpp.<div><br></div><div>I really haven't dug into your code because it's quite large, but it seems to me that you should be able to evaluate the code for your test case with the evaluator.  If not, you should debug why and consider extending it.</div>

</div></blockquote><div><br></div><div>I know this one: because it's not a static constructor.</div><div><br></div><div>EvaluateStaticConstructor tries to evaluate the dynamic initializers and bails if it can't handle anything it encounters. This patch is about doing guarded initialization, which can occur anywhere in user-written code after main has begun, and doesn't require the ability to evaluate the entire function.</div>

<div><br></div><div>For a concrete example,</div><div><br></div><div>  bool isInit = false;</div><div>  int i;</div><div>  void foo() {</div><div>    printf("Boo!\n");</div><div>    if (isInit) {</div><div>      isInit = true;</div>

<div>      i = 1;</div><div>    }</div><div>  }</div><div><br></div><div>EvaluateStaticConstructor will bail immediately at the printf because it can't simulate that. Of course, this makes sense for removing dynamic initializers, but not when removing guarded initialization.</div>

<div><br></div><div>I've previously taught the evaluator to carry on when it sees a use of a previously uncomputed value (ie., getVal no longer asserts, and can instead fail). You can grab my implementation from <a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120206/136735.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120206/136735.html</a> . As you can see, I ultimately didn't commit it.</div>

<div><br></div><div>I still want to know whether this pattern is something that actually happens. It doesn't match the guarded initialization we get with function-local statics in the Itanium C++ ABI.</div><div><br></div>

<div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
</div><div class=""><div class="h5"><div class="gmail_extra">On Mon, Aug 26, 2013 at 5:07 PM, Puyan Lotfi <span dir="ltr"><<a href="mailto:plotfi@apple.com" target="_blank">plotfi@apple.com</a>></span> wrote:<br><div class="gmail_quote">


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Reid, I am not entirely clear on which Evaluator class you are referring to. Could you point me to some more information on this?</div>


<div>I wasn’t really trying to special case things too heavily, was more trying to match up modification of a boolean flag with stores to a global to tell if things could just be hoisted.</div><div><br></div><div>Thanks</div>


<span><font color="#888888"><div><br></div><div>-Puyan</div></font></span><div><div><div><br></div><br><div><div>On Aug 26, 2013, at 11:47 AM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:</div>


<br><blockquote type="cite"><div dir="ltr"><div>I'm not really an owner of GlobalOpt, but this seems like a big ugly huge special case, rather than something general that's part of the Evaluator class.  You should be able to emulate stores to isInit in the usual way, since it's internal.  Can you debug why that isn't firing?</div>



<div><br></div>I think it would be much more interesting to try to look at Itanium C++ dynamic initializers and try to fold those away.  This would imply understanding what __cxx_acquire / release mean when -fno-builtin / -ffreestanding aren't set.</div>



<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 26, 2013 at 1:40 AM, Puyan Lotfi <span dir="ltr"><<a href="mailto:plotfi@apple.com" target="_blank">plotfi@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<div style="word-wrap:break-word"><div>All:</div><div><br></div><div>Attached is a patch to GlobalOpt that adds an optimization that takes user written constant initialization code for global variables and hoists the initialization values into the global initializer. This optimization is only done on locally linked globals of integral types (scalars, arrays, and structs) that are constant initialized (and zero initialized prior to transformation). </div>



<div><br></div><div>The idea is to transform the following code:</div><div><br></div><div><div><font face="Courier New">A = internal global i32 0, align 4</font></div><div><font face="Courier New">isInit = internal global i1 false</font></div>



<div><font face="Courier New"><br></font></div><div><font face="Courier New">define i32* foobar() {</font></div><div><font face="Courier New">  %.b = load i1* isInit</font></div><div><font face="Courier New">  %1 = zext i1 %.b to i8</font></div>



<div><font face="Courier New">  %2 = trunc i8 %1 to i1</font></div><div><font face="Courier New">  br i1 %2, BB4, label BB3</font></div><div><font face="Courier New">BB3:</font></div><div><font face="Courier New">  store i32 113, i32* A, align 4</font></div>



<div><font face="Courier New">  store i1 true, i1* isInit</font></div><div><font face="Courier New">  br label %4</font></div><div><font face="Courier New">BB4:</font></div><div><font face="Courier New">  ret i32* A</font></div>



<div><font face="Courier New">}</font></div><div><br></div><div>Into:</div><div><font face="Courier New"><br></font></div><div><font face="Courier New">A = internal global i32 113, align 4</font></div><div><font face="Courier New"><br>



</font></div><div><font face="Courier New">define i32* @_Z8initTestv() {</font></div><div><font face="Courier New">  ret i32* A</font></div><div><font face="Courier New">}</font></div><div><br></div></div><div>Could someone on the list review my changes, provide feedback, and if possible submit my changes?</div>



<div><br></div><div>I also have some test cases I've written but I am still trying to figure out how to add them to llvm/test/Transforms/GlobalOpt (I don't see a lit.local.cfg in that directory as the docs specify). </div>



<div><br></div><div>Thanks</div><span><font color="#888888"><div><br></div><div>-Puyan</div><div><br></div><div><br></div></font></span></div><br><div style="word-wrap:break-word"></div>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>