Re: [cfe-users] C++ lambdas more expensive than blocks?

2016-10-24 Thread Benjamin Kramer via cfe-users
Yes, std::function is a fairly inefficient class. It's useful for
storing a lambda but not so much for passing it around. You can pass
around lambdas as a template argument (requires all callees to be
templates) or as a function pointer if there are no captures. If you
have captures a helper class such as llvm::function_ref[1] might come
in handy, which acts like a function pointer but also allows captures
to be passed around.

[1] 
https://github.com/llvm-mirror/llvm/blob/master/include/llvm/ADT/STLExtras.h#L80

On Mon, Oct 24, 2016 at 8:32 PM, Jens Alfke via cfe-users
 wrote:
> I’ve started using C++11 lambdas in my code. A few of them are in 
> performance-sensitive areas, so I was looking at (optimized) assembly code of 
> some of my methods to see what goes on under the hood.
>
> I don’t entirely understand the code, but the code on the calling side (i.e. 
> the part that creates the lambda and passes it as a function parameter) it 
> looks larger and slower than similar code using Clang blocks. It looks as 
> though there’s overhead in converting the lambda itself into a std::function 
> object … especially because I see a call to a std::function method that makes 
> a heap allocation. :'( The equivalent block-based code just fills out a small 
> struct on the stack and passes its address.
>
> Is there a more efficient way to pass a lambda to a function in C++? As far 
> as I can tell, a lambda is of an anonymous type that can’t be named*, so the 
> only way to pass it as a parameter is to wrap it in a std::function, which is 
> comparatively expensive.
>
> (My code has to be cross-platform, but I’m thinking of writing some macros 
> that can expand into either lambda or block expressions, depending on the 
> compiler. That way it’ll at least be more efficient when built with Clang.)
>
> —Jens
>
> PS: This is with Xcode 8, clang-800.0.38
>
> * Ironically, my copy of the Tao Te Ching just arrived from Amazon while I 
> was writing this email, and it starts right off with the famous statement 
> “The way you can go isn’t the true way. The name you can say isn’t the true 
> name.”
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] C++ lambdas more expensive than blocks?

2016-10-25 Thread Benjamin Kramer via cfe-users
Copying function_ref will work, it's independent of the rest of LLVM
and works with all C++11 compilers. I also expect common C++ libraries
to have an equivalent class, but I haven't checked.

On Tue, Oct 25, 2016 at 3:33 AM, Jens Alfke  wrote:
>
> On Oct 24, 2016, at 12:00 PM, Benjamin Kramer  wrote:
>
> a helper class such as llvm::function_ref[1] might come
> in handy, which acts like a function pointer but also allows captures
> to be passed around.
>
>
> Thanks. Is that class something I can just copy-and-paste into my code? Will
> it work with other compilers like GCC or MSVC?
> (Sorry if these are naive questions; I’m not knowledgeable enough about
> templates to be able to understand that source code.)
>
> —Jens
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] How to use clang-tidy plugin.

2017-01-19 Thread Benjamin Kramer via cfe-users
I don't think I ever added the build rules to build clang-tidy as a
plugin for use outside of libclang. You can use it via libclang and
the python bindings currently. Adding the necessary build rules isn't
easy because you'd have to avoid linking clang symbols into both the
plugin and the actual clang binary, the current cmake layout doesn't
really support that :(

On Tue, Jan 17, 2017 at 4:12 PM, Alfred Zien via cfe-users
 wrote:
> Hi! I need to use clang-tidy as a clang plugin, but can't figure out how to 
> do it.
>
> I see ClangTidyPlugin.cpp file, and there is ClangTidyPlugin target, but when 
> I run `make clangTidyPlugin` it produces only libclangTidyPlugin.a, no any 
> dynamic library. Am I doing something wrong? Is it even possible?
>
> Thanks for any help.
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] How to use clang-tidy plugin.

2017-01-20 Thread Benjamin Kramer via cfe-users
Using ASTMatchers in a plugin should work as long as clang doesn't use
them. The problems arise when both the plugin and clang define the
same symbols. But with the current cmake build it's not possible to
just link ASTMatchers, it will drag all dependencies of ASTMatchers
along and cause linker errors.

On Fri, Jan 20, 2017 at 9:44 AM, Alfred Zien  wrote:
> Thanks for clarifying! Based on this, as I understand, we can't use any other 
> library (for example ASTMatchers) in plugin that clang doesn't use?
>
>> On 19 Jan 2017, at 19:44, Benjamin Kramer  wrote:
>>
>> I don't think I ever added the build rules to build clang-tidy as a
>> plugin for use outside of libclang. You can use it via libclang and
>> the python bindings currently. Adding the necessary build rules isn't
>> easy because you'd have to avoid linking clang symbols into both the
>> plugin and the actual clang binary, the current cmake layout doesn't
>> really support that :(
>>
>> On Tue, Jan 17, 2017 at 4:12 PM, Alfred Zien via cfe-users
>>  wrote:
>>> Hi! I need to use clang-tidy as a clang plugin, but can't figure out how to 
>>> do it.
>>>
>>> I see ClangTidyPlugin.cpp file, and there is ClangTidyPlugin target, but 
>>> when I run `make clangTidyPlugin` it produces only libclangTidyPlugin.a, no 
>>> any dynamic library. Am I doing something wrong? Is it even possible?
>>>
>>> Thanks for any help.
>>> ___
>>> cfe-users mailing list
>>> cfe-users@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users