[cfe-dev] always_inline and noinline attributes

Matthijs Kooijman matthijs at stdin.nl
Wed Jul 23 08:35:32 PDT 2008


Hi Luís,

> I have been thinking about this. Would it be too hard to make this
> rule more flexible, so that for instance the following case would be
> possible:
The following code would be valid when you use the other interpretation, that
an always_inline function is inlined whenever possible.

> const int CONFIG_OPTIMIZED = 1;
> 
> int foo(int x) __attribute__ ((always_inline))
> {
>     if(CONFIG_OPTIMIZED)
>         return foo_optimized(x);
>     else
>         return foo_fast(x);
> }
> 
> Taking the address of foo() would return the address either
> foo_optimized or foo_fast. 
Interesting case. A possible solution would be to mark foo_optimized and
foo_fast as always_inline as well, so that they will be inlined here and the
unused one will be removed by simplifycfg or some other pass.

However, if you really want the address of foo to be replaced with the address
of either foo_optimized or foo_fast, I guess you would need to use some pass
to turn foo into
	int foo (int x) {
		return foo_optmized(x);
	}

and then have some other pass (not sure which, really), to specifically look
for function looking like this and replace all uses of foo with foo_optimized
(possibly also direct calls).

In any case, I don't think that this optimization is directly related to
always_inline or inlining at all. It would be cool to support this
transformation, though there might be a few tricky exception cases to be
handled.

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080723/34836ed5/attachment.sig>


More information about the cfe-dev mailing list