简体   繁体   English

为什么没有-O3 GCC优化内联这个功能?

[英]Why didn't -O3 GCC Optimization inline this function?

In GCC compiler, whenever -O3 is flagged, the compiler optimizes mainly by Loop Unrolling and Function Inlining. 在GCC编译器中,每当标记-O3时,编译器主要通过循环展开和函数内联进行优化。

However, when I compiled an application that has the following function, it didn't do Function Inlining. 但是,当我编译具有以下功能的应用程序时,它没有执行函数内联。 From gprofing and gconving I could notice that this function (comp_t_delay) was not called from the main function unit of this application. 从gprofing和gconving我可以注意到这个函数(comp_t_delay)没有从这个应用程序的主功能单元调用。 However, it was called from a function, called by a function, called by the main function. 但是,它是由函数调用的函数调用的,由main函数调用。

Here is the code of comp_t_delay(int in,int ip) that I want to know why the GCC didn't optimize it using -O3 (any help is appreciated!): 这是comp_t_delay(int in,int ip)的代码,我想知道为什么GCC没有使用-O3优化它(任何帮助都很感激!):

static float
comp_t_delay(int in,int ip)
{

    int sb, sib,dx, dy;
    t_type_ptr st, sit;
    float d_ssi;

    d_ssi = 0.;

    sb = net[in].node_block[0];
    st = block[sb].type;

    sib = net[in].node_block[ip];
    sit = block[sib].type;

    assert(st != NULL);
    assert(sit != NULL);

    dx = abs(block[sib].x - block[sb].x);
    dy = abs(block[sib].y - block[sb].y);

    if(st == T_IO)
    {
        if(sit == T_IO)
        d_ssi = de_io[dx][dy];
        else
        d_ssi = de_iof[dx][dy];
    }
    else
    {
        if(sit == T_IO)
        d_ssi = de_fio[dx][dy];
        else
        d_ssi = de_fb[dx][dy];
    }
    if(d_ssi < 0)
    {
        printf
        ("Error1\n");
        exit(1);
    }

    if(d_ssi < 0.)
    {
        printf
        ("Error2\n");
        exit(1);
    }

    return (d_ssi);
}

It most probably didn't inline it because it is too long. 它很可能没有内联它,因为它太长了。 Long functions, when inlined, can actually cause the code to run slower - for example you get the CPU registers bloated by more variables. 内联时,长函数实际上可能导致代码运行速度变慢 - 例如,CPU寄存器会因更多变量而膨胀。 In this particular case gcc decided it will be faster not to inline the function. 在这种特殊情况下,gcc决定不更新内联函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM