Function Attributes in LLVM

Hello,

I was wondering if there is a way to add more, maybe target dependant,
function attributes? I think in certain circumstances they are a good
way to give the compiler more information about a function. For example
GCC supports attributes to mark an interrupt function witch is very
useful for some low level targets. As far as I know function attributes
are GCC specific or am I wrong? Is there a Standard-C way to add this
kind of meta information to a function?

Now the LLVM specific questions :): Is there currently a way that
special function attributes are passed to the back end? A solution would
be to add custom function attributes to the LLVM IR but changing a core
system in order to support a feature of a new device seems not to be the
best way IMO. Additionally the front end must be changed too.
I think it would be a pretty nice feature if a target could specify
special function attributes or am I totally missing the point?

Thanks in advance!

BR
Josef

Hello, Josef

useful for some low level targets. As far as I know function attributes
are GCC specific or am I wrong?

That's correct

Is there a Standard-C way to add this
kind of meta information to a function?

Well... You can store function pointers into some array and add any extra information your like.

I think it would be a pretty nice feature if a target could specify
special function attributes or am I totally missing the point?

Look for annotation attribute.

I too have been seeking something like this.

To the best of my understanding, the annotation attributes let you
attach only text attributes, and only at the function scope, but not
to individual basic blocks or instructions. There are intrinsic
functions for the purposes of annotating values, but these cannot be
used to annotate branch or store instructions (as they produce no
value). Additionally, these are only overrided against integer types,
and so one cannot annotate a floating point or aggregate value.

And although one can easily use an auxillary data to hold additional
attributes for basic blocks or instructions, it would be ideal if such
annotations could be de/serialized to bitcode files.

Your input is appreciated,
Nick

Now the LLVM specific questions :): Is there currently a way that
special function attributes are passed to the back end?

One such example is "optsize".
See LLVM Language Reference Manual — LLVM 18.0.0git documentation