<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 17, 2016 at 2:15 AM, Bernard Ogden via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-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">Hello,<br>
<br>
I'm pretty much a clang newbie, looking for some advice.<br>
<br>
I'm considering looking at a small size optimization that goes like this:<br>
* Compiler discovers that main's argv argument is unused<br>
* Compiler emits object with information that can be used by library and/or linker to avoid inclusion of argv-handling code<br>
<br>
One of my colleagues suggest emitting a dummy function that just returns. The library can then put its argv-handling code in an identically-named weak function and the linker won't include it if the dummy function exists. I like this solution as it works for any library without needing any extra special technology.<br></blockquote><div><br></div><div>It could be marginally better to have the library provide a weak _Main_noargv() entry point that computes argc and argv then calls main(), and have the compiler emit _Main_noargv as an alias to main if main doesn't use its argc and argv. But either way, sure.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As the optimization is language-specific it seems it should happen in clang rather than LLVM, perhaps by adding a function to the AST. This implies manipulating the AST after it has been constructed which, IIUC, is not an especially supported way to do things.<br>
<br>
Is such an approach possible/sane, and would it be acceptable to upstream?<br></blockquote><div><br></div><div>Not by manipulating the AST, no, for a couple of reasons:</div><div>1) You may not know that argc and argv are unused until you perform some optimizations</div><div>2) It doesn't make sense to model this in the AST as it's a property of the lowering to machine code, not a property of the source program</div><div><br></div><div>If you really want to do this in clang (per the above, I don't think that's a good idea), you should do it in clang's IR generation pass rather than modifying the AST. But I'd suggest you instead look at teaching LLVM to do this (maybe in dead argument elimination), and from Clang just inform the relevant LLVM pass that it can do this transformation.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Does clang have any recognised approaches to this kind of compiler/library collusion?<br>
<br>
Thanks in advance,<br>
<br>
Bernie<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>