This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: BB reordering question
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: Archie Cobbs <archie at dellroad dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 31 Jan 2004 10:10:58 +0100
- Subject: Re: BB reordering question
- References: <200401302357.i0UNvd6I003260@arch20m.dellroad.org>
Hello,
> I have a simple question that hopefully has a simple answer...
> I'm using GCC (gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5))
> for x86 to compile machine generated code that looks like this:
>
> function()
> {
> const void *lables[] = { &&label1, &&label2, &&label3, ... };
>
> label1:
> blah blah
> if (blah)
> goto label3;
> blah
> label2:
> blah
> ..
> if (blah)
> goto *labels[i];
> ...
> label3:
> blah
> ...
> ...
> }
>
> At the end of each basic block, control either flows into the next
> basic block, there is a return from the function, or there is a call
> to another non-returning function marked __attribute__((noreturn)).
>
> A requirement states that the labels[] array must be sorted in strictly
> ascending order (all basic blocks are nonempty). But I'd also like to
> enable as many optimizations as possible. So my question is, what is
> the best choice of optimizations that won't reorder any blocks, ever?
>
> I've tried "-O2 -fno-reorder-blocks"; it *almost* works but not quite.
>
> E.g. if the last BB terminates with a call to a noreturn function,
> GCC will still reorder it, presumably so an epilogue is at the end
> of the function in memory (I saw some related (?) mailing list
> comments: http://gcc.gnu.org/ml/gcc-patches/2002-05/msg02293.html).
>
> First, is this a bug, feature, or am I confused about what the
> "-fno-reorder-blocks" flag is supposed to do?
-fno-reorder-blocks switches of basic block reordering pass. It however
has nothing to do with other passes that may change the order of the
blocks.
> Is there some other way for me to get the desired result other than
> disabling optimzation altogether?
No, as far as I am aware of; I believe that even just cleanup_cfg may
reorder the blocks sometimes, and it is run even if optimizations are
disabled completely.
I would just recommend to avoid such hacks (I am not quite sure what
you want to achieve anyway; I can think of only one reason why you might
want to have the array sorted, and it is if you wanted to do binary
search over it, but it does not make any sense me).
Zdenek