[llvm-dev] Inline constant std::function parameter

Eleftherios Ioannidis via llvm-dev llvm-dev at lists.llvm.org
Tue May 29 10:52:58 PDT 2018


Hey LLVM-dev,

I'm trying to inline the following C++ code:

    __attribute__((always_inline)) static void inline compose(const char* s, std::function<void(const char *)> f) {
        std::cout << s << std::endl;
        f(s);
    }
    
    // --------------- Main ---------------
    int main() {
        // Nest three things
        compose("hello world", [](const char *s) {
            compose("hello again", [](const char *s) {
                compose("hello third time", [](const char *s) {
                    return;
                });
            });
        });
    
        return 0;
    }

Here my continuations are of type `std::function<void(const char*)>` and what I wanted from LLVM with the `always_inline` option was to transform it to a single call-site that looks like this:


    // --------------- Main ---------------
    int main() {
        // Nest three things
        std::cout << "hello world" << std::endl;
        std::cout << "hello again" << std::endl;
        std::cout << "hello third time" << std::endl;
        return 0;
    }

However that doesn't seem to be the case, does the inliner not get triggered if the functions are passed as objects (std::function) or am I using the wrong `opt` invokation? 

    OPT=opt-6.0
    OPTFLAGS?=-O3 -always-inline -dot-callgraph

Thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180529/b977e342/attachment-0001.bin>


More information about the llvm-dev mailing list