On Feb 19, 2013, at 7:46 AM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:> On 2/19/2013 12:31 AM, Bill Wendling wrote: >> >> Yeah, that was in the one that I committed. I basically want something like this: >> >> define void @foo() "no-builtin" { >> call void @printf() >> } >> >> And then the `call' to printf would check for the "no-builtin" attribute on `@foo' to determine if it can convert it to `puts'. Having the attribute on the declaration of `printf' doesn't help us here. And I'm not sure if having it on the call would be beneficial either. > > Having the attribute on the prototype of printf would tell us that calls to printf cannot be converted to calls to anything else. Isn't that what you want?No, it isn't because that isn't sufficient. Besides the example I gave in the other email to this thread, consider things like: void foo() { auto fp = printf; fp("xyz\n"); } With -fno-builtin-printf, we can't optimize the call to printf, even though it only becomes apparent after (trivial) devirtualization. -Chris> > If you want to prevent the optimizations on foo that take advantage of the knowledge about certain known functions, then we should use a different attribute for that, or else things can get really confusing. > > -Krzysztof > > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 2/19/2013 12:26 PM, Chris Lattner wrote:> > void foo() { > auto fp = printf; > fp("xyz\n"); > } > > With -fno-builtin-printf, we can't optimize the call to printf, even though it only becomes apparent after (trivial) devirtualization.Ha. Good example. What would you expect to happen in this case? --- a.cpp --- (with -fno-builtin-printf) pointer fptr; void foo(bool x) { bar(x); } void set(bool x) { if (x) fptr = printf; else fptr = vprintf; } ------------- --- b.cpp --- (no restrictions) extern pointer fptr; void bar(bool x) { set(x); va_list ap = ... (*fptr)("haha", ap); } ------------- Also, with the options reversed. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
On Feb 19, 2013, at 11:08 AM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:> On 2/19/2013 12:26 PM, Chris Lattner wrote: >> >> void foo() { >> auto fp = printf; >> fp("xyz\n"); >> } >> >> With -fno-builtin-printf, we can't optimize the call to printf, even though it only becomes apparent after (trivial) devirtualization. > > Ha. Good example. > What would you expect to happen in this case? > > --- a.cpp --- (with -fno-builtin-printf) > pointer fptr; > void foo(bool x) { > bar(x); > } > void set(bool x) { > if (x) fptr = printf; > else fptr = vprintf; > } > ------------- > > --- b.cpp --- (no restrictions) > extern pointer fptr; > void bar(bool x) { > set(x); > va_list ap = ... > (*fptr)("haha", ap); > } > --------------fno-builtin applies to the code in foo and set.> Also, with the options reversed.Then -fno-builtin would apply to the code in bar. -Chris