EmbDev.net

Forum: ARM programming with GCC/GNU tools flatten function attribute


von Joe (Guest)


Rate this post
useful
not useful
Has anyone had success with __attribute__((flatten)) using yagarto?

I have tried various locations of the attribute tag in the function 
declaration or definition, but it appears the attribute is completely 
ignored.
1
void test_flatten(void) __attribute__((flatten));
2
3
void test_flatten(void){
4
    function1();
5
    function2();
6
}

From what I understand, flatten is supposed to "inline" all calls within 
a function, essentially creating one large "stand-alone" function.  When 
I step through the supposedly flattened code, there are still "bl" 
instructions to function1() and function2() locations.

von Joe D. (jdupre)


Rate this post
useful
not useful
I should add that the docs say "The flatten attribute only works 
reliably in unit-at-a-time mode. ", which should be enabled with 
optimization -O1. But I still get don't get the single monolithic block 
of code I expect, there are still branches to the other functions.

von Rolf Magnus (Guest)


Rate this post
useful
not useful
> From what I understand, flatten is supposed to "inline" all calls within
> a function

... "if possible". Did you define those two functions in the same 
implementation file as your test_flatten function? If they are 
implemented in a different one, they can't be inlined.

von Joe D. (jdupre)


Rate this post
useful
not useful
No.  One of the functions was in a different file.

von Prakash (Guest)


Rate this post
useful
not useful
Hi,

I am using GCC version 9 in Ubuntu 14.04

I have defined two function in the same file and one of the function is 
attributed as "flatten" but But I still did not get the single 
monolithic block of code I expect, there are still branches to the other 
functions.

Why exactly it is not following the flatten attribute concept ?

Here is the code

void __attribute__((flatten)) hot_code();

void do_thing(int input)
{
    int val;
    val = input;
}

void __attribute__((flatten)) hot_code()
{
    int x = 5;
    while (x<10) {
        do_thing(x);
        x++;
    }
}

von Rolf Magnus (Guest)


Rate this post
useful
not useful
Prakash wrote:
> void __attribute__((flatten)) hot_code();
1
void hot_code() __attribute__((flatten));

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.