flatten function attribute

Guest #1807570
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.
#1807574
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.
Guest #1807660
> 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.
Guest #6276597
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++;
    }
}

Reply

A question of your own? This thread is over 16 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.