<div dir="ltr"><div><div>Hi Abe,<br><br>I don't see why you couldn't make a frontend query in the pass-manager to selectively enable such globals reordering/aligning pass. If this is a discouraged practice noted in docs somewhere and LLVM's goal is to be truly frontend/platform agnostic, please do correct me. AFAIK, Pass Manager selects some optimizations based on Optimization Levels (-O2,-O3,etc), so extending this shouldn't be a challenge.<br><br></div><div>Regards,<br></div>Kevin<br><br></div>Intel WOS<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2016 at 15:36, Abe Skolnik via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br>
<br>
Howdy! ;-)  This is Abe of the Samsung Austin R&D Center`s compilers team.<br>
<br>
As an early part of a project that should help performance on some CPUs, I would like to cause global variables [at least from C and C++ programs] to be grouped together according to their alignment needs, which should help to slightly reduce RAM requirements in some cases.  IMO this should be done at "-O3" and higher levels of optimization [maybe "-O2" and higher?] and at "-Oz" [and maybe also at "-Os"].  This change is likely to break some poorly-written programs which rely on undefined behavior by assuming that consecutively-{declared/defined} global variables are allocated consecutively in RAM, so I propose to allow those programs to go on compiling to code that works as the author expected when there is no strong optimization imperative for either RAM savings or performance.<br>
<br>
My question this time is this: is re-ordering globals at the LLVM level both possible [without massive rewriting of LLVM] and safe?  I don`t know whether or not it`s safe because perhaps some languages -- unlike C and C++ -- _explicitly_ allow programmers to make the assumption that consecutively-written globals at the source-code level map to consecutively-allocated globals at run-time.  If so, and if any such language is using LLVM as a back-end, then changing that behavior at the LLVM level with _any_ optimization flag may break programs that _are_ well-formed according to the rules of their respective source language[s].<br>
<br>
Regards,<br>
<br>
Abe<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>