You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `target_clones` attribute is used to create multiple versions of a function. The compiler will emit multiple versions based on the provided arguments.
296
+
297
+
Each `TARGET-CLONES-ATTR-STRING` defines a distinguished version of the function. The `TARGET-CLONES-ATTR-STRING` list must include `default` indicating the translation unit scope build attributes.
298
+
299
+
The syntax of `<TARGET-CLONES-ATTR-STRING>` describes below:
300
+
301
+
```
302
+
TARGET-CLONES-ATTR-STRING := 'arch=' EXTENSIONS
303
+
| 'default'
304
+
305
+
EXTENSIONS := <EXTENSION> ',' <EXTENSIONS>
306
+
| <EXTENSION>
307
+
308
+
EXTENSION := <OP> <EXTENSION-NAME> <VERSION>
309
+
310
+
OP := '+'
311
+
312
+
VERSION := [0-9]+ 'p' [0-9]+
313
+
| [1-9][0-9]*
314
+
|
315
+
316
+
EXTENSION-NAME := Naming rule is defined in RISC-V ISA manual
317
+
```
318
+
319
+
For example, the following `foo` function will have three versions but share the same function signature.
It makes the compiler trigger the [function multi-version](#function-multi-version) when there exist more than one version for the same function signature.
The `target_version` attribute is used to create one version of a function. Functions with the same signature may exist with multiple versions in the same translation unit.
339
+
340
+
Each `TARGET-VERSION-ATTR-STRING` defines a distinguished version of the function. If there is more than one version for the same function, it must have `default` one that indicating the translation unit scope build attributes.
341
+
342
+
The syntax of `<TARGET-VERSION-ATTR-STRING>` describes below:
343
+
344
+
```
345
+
TARGET-VERSION-ATTR-STRING := 'arch=' EXTENSIONS
346
+
| 'default'
347
+
348
+
EXTENSIONS := <EXTENSION> ',' <EXTENSIONS>
349
+
| <EXTENSION>
350
+
351
+
EXTENSION := <OP> <EXTENSION-NAME> <VERSION>
352
+
353
+
OP := '+'
354
+
355
+
VERSION := [0-9]+ 'p' [0-9]+
356
+
| [1-9][0-9]*
357
+
|
358
+
359
+
EXTENSION-NAME := Naming rule is defined in RISC-V ISA manual
360
+
```
361
+
362
+
For example, the following foo function has three versions.
363
+
364
+
```c
365
+
__attribute__((target_version("arch=+v")))
366
+
int foo(int a)
367
+
{
368
+
return a + 5;
369
+
}
370
+
371
+
__attribute__((target_version("arch=+zbb")))
372
+
int foo(int a)
373
+
{
374
+
return a + 5;
375
+
}
376
+
377
+
__attribute__((target_version("default")))
378
+
int foo(int a)
379
+
{
380
+
return a + 5;
381
+
}
382
+
383
+
int bar() {
384
+
// foo will be resolved by ifunc
385
+
return foo(1);
386
+
}
387
+
```
388
+
389
+
It makes the compiler trigger the [function multi-version](#function-multi-version) when there exist more than one version for the same function signature.
390
+
293
391
### riscv_vector_cc
294
392
295
393
Supported Syntaxes:
@@ -604,3 +702,9 @@ statements, including both RISC-V specific and common operand modifiers.
| z | Print `zero` (`x0`) register for immediate 0, typically used with constraints `J`||
606
704
| i | Print `i` if corresponding operand is immediate. ||
705
+
706
+
## Function Multi-version
707
+
708
+
Function multi-versioning(FMV) provides an approach to selecting the appropriate function according to the runtime environment. The final binary may contain all versions of the function, with the compiler generating all supported versions and the runtime selecting the appropriate one.
709
+
710
+
This feature is triggered by `target_version/target_clones` function attribute.
0 commit comments