<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 21, 2009, at 4:12 PM, Douglas Gregor wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Oct 21, 2009, at 2:10 PM, Tanya Lattner wrote:<br><br><blockquote type="cite">Hi. I'd like to get a review of my patch that takes const arrays and structs (unions, classes, etc) and creates a global instead of storing it to the stack (treating it like a static const, for performance reasons).<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Please let me know if you have questions.<br></blockquote><br>Index: lib/CodeGen/CGDecl.cpp<br>===================================================================<br>--- lib/CodeGen/CGDecl.cpp<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 84777)<br>+++ lib/CodeGen/CGDecl.cpp<span class="Apple-tab-span" style="white-space:pre">        </span>(working copy)<br>@@ -316,6 +316,14 @@<br>   llvm::Value *DeclPtr;<br>   if (Ty->isConstantSizeType()) {<br>     if (!Target.useGlobalsForAutomaticVariables()) {<br>+<br>+      // All constant structs and arrays should be global.<br>+      if (Ty.isConstant(getContext())<br>+          && (isa<ArrayType>(Ty) || isa<RecordType>(Ty))) {<br>+        EmitStaticBlockVarDecl(D);<br>+        return;<br>+      }<br>+<br><br>This looks too aggressive. There are more conditions that need to be checked before we can perform this optimization, e.g.,<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>(1) Is the initializer constant?<br><span class="Apple-tab-span" style="white-space:pre">  </span>(2) In C++, is the type/element type of the array a POD?<br><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div><div>Ok, made these changes.</div><br><blockquote type="cite"><div>There are probably other conditions; for example, we might not want to perform this optimization if the address of the variable is ever taken.<br><br></div></blockquote><div><br></div><div>Ok, I don't understand why address taken should matter if it is declared const. Am I missing something?</div><div><br></div><div>Thanks,</div><div>Tanya</div></div><br></body></html>