These attributes are supported by the RISC-V back end:
interrupt ¶This attribute applies to functions.
It indicates that the specified function is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
You can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:
void f (void) __attribute__ ((interrupt ("supervisor")));
Permissible values for this parameter are supervisor,
machine, and rnmi. If there is no parameter, then it
defaults to machine.
riscv_vector_cc ¶This attribute applies to functions.
Use this attribute to force the function to use the vector calling convention variant.
void foo() __attribute__((riscv_vector_cc)); [[riscv::vector_cc]] void foo(); // For C++11 and C23
target (options) ¶This attribute applies to functions.
As discussed in Common Attributes, this attribute allows specification of target-specific compilation options.
The following options are available for the RISC-V target. For the most part, these options mirror the behavior of similar command-line options (see RISC-V Options), but on a per-function basis.
Specifies the architecture version and architectural extensions to use
for this function. The behavior and permissible arguments are the same as
for the -march= command-line option, in addtion, it also support
extension enablement list, a list of extension name and prefixed with +,
like arch=+zba means enable zba extension.
Multiple extension can be enabled by separating them with a comma. For example:
arch=+zba,+zbb.
Specifies the core for which to tune the performance of this function. The behavior and permissible arguments are the same as for the -mtune= command-line option.
Specifies the core for which to tune the performance of this function and also whose architectural features to use. The behavior and valid arguments are the same as for the -mcpu= command-line option.
max-vectorization tells GCC’s vectorizer to treat all vector
loops as being more profitable than the original scalar loops when
optimizing the current function. no-max-vectorization disables
this behavior.
This corresponds to the behavior of the command-line options
-mmax-vectorization and -mno-max-vectorization.
The above target attributes can be specified as follows:
__attribute__((target("attr-string")))
int
f (int a)
{
return a + 5;
}
where attr-string is one of the attribute strings specified above.
Multiple target function attributes can be specified by separating them with a semicolon. For example:
__attribute__((target("arch=+zba,+zbb;tune=rocket")))
int
foo (int a)
{
return a + 5;
}
is valid and compiles function foo with zba
and zbb extensions and tunes it for rocket.