[llvm-bugs] [Bug 24513] New: should be able to apply attribute always_inline to ObjC blocks
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Aug 19 17:58:22 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24513
Bug ID: 24513
Summary: should be able to apply attribute always_inline to
ObjC blocks
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: comexk at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Since an ObjC block is essentially a wrapper around a couple of functions, and
those functions can be inlined, I would like to apply the always_inline
attribute to a block expression to do the equivalent of marking (all) those
functions as such. Currently, Clang does not support this:
warning: 'always_inline' attribute only applies to functions
[-Wignored-attributes]
int (^x)() = ^() __attribute__((always_inline)) { return 5; } ;
Admittedly, since blocks are always called through the equivalent of function
pointers, it would be impossible to actually enforce inlining, even at -O0, the
way the attribute normally does. However, when optimization is on and Clang
knows the target of a function pointer call, it does currently seem to honor
the attribute:
// Without the attribute, clang -O3 on my system generates main with 5x
// "callq _block_invoke", and _block_invoke with 15x "callq _foo". With it
// I get 75 calls to foo.
int foo(int);
//__attribute__((always_inline))
int block_invoke(struct block *b) {
return foo(1) + foo(2) + foo(3) + foo(4) + foo(5) +
foo(1) + foo(2) + foo(3) + foo(4) + foo(5) +
foo(1) + foo(2) + foo(3) + foo(4) + foo(5);
}
struct block { int (*invoke)(struct block *); int state; };
int main() {
struct block block = { block_invoke, 42 };
return block.invoke(&block) +
block.invoke(&block) +
block.invoke(&block) +
block.invoke(&block) +
block.invoke(&block);
}
It would make sense to allow this to be taken advantage of with real blocks.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150820/272f36a1/attachment.html>
More information about the llvm-bugs
mailing list