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: unassignedclangb...@nondot.org
          Reporter: com...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to