New calling convention preserve_none (#76868)
The new experimental calling convention preserve_none is the opposite
side of existing preserve_all. It tries to preserve as few general
registers as possible. So all general registers are caller saved
registers. It can also uses more general registers to pass arguments.
This attribute doesn't impact floating-point registers. Floating-point
registers still follow the c calling convention.
Currently preserve_none is supported on X86-64 only. It changes the c
calling convention in following fields:
* RSP and RBP are the only preserved general registers, all other
general registers are caller saved registers.
* We can use [RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15, RAX]
to pass arguments.
It can improve the performance of hot tailcall chain, because many
callee saved registers' save/restore instructions can be removed if the
tail functions are using preserve_none. In my experiment in protocol
buffer, the parsing functions are improved by 3% to 10%.
2024-02-05 13:28:43 -08:00
// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify
2024-06-26 18:54:41 -04:00
// RUN: %clang_cc1 %s -fsyntax-only -triple aarch64-unknown-unknown -verify
New calling convention preserve_none (#76868)
The new experimental calling convention preserve_none is the opposite
side of existing preserve_all. It tries to preserve as few general
registers as possible. So all general registers are caller saved
registers. It can also uses more general registers to pass arguments.
This attribute doesn't impact floating-point registers. Floating-point
registers still follow the c calling convention.
Currently preserve_none is supported on X86-64 only. It changes the c
calling convention in following fields:
* RSP and RBP are the only preserved general registers, all other
general registers are caller saved registers.
* We can use [RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15, RAX]
to pass arguments.
It can improve the performance of hot tailcall chain, because many
callee saved registers' save/restore instructions can be removed if the
tail functions are using preserve_none. In my experiment in protocol
buffer, the parsing functions are improved by 3% to 10%.
2024-02-05 13:28:43 -08:00
typedef void typedef_fun_t ( int ) ;
void __attribute__ ( ( preserve_none ) ) boo ( void * ptr ) {
}
void __attribute__ ( ( preserve_none ( 1 ) ) ) boo1 ( void * ptr ) { // expected-error {{'preserve_none' attribute takes no arguments}}
}
void ( __attribute__ ( ( preserve_none ) ) * pboo1 ) ( void * ) = boo ;
void ( __attribute__ ( ( cdecl ) ) * pboo2 ) ( void * ) = boo ; // expected-error {{incompatible function pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_none))'}}
void ( * pboo3 ) ( void * ) = boo ; // expected-error {{incompatible function pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_none))'}}
typedef_fun_t typedef_fun_boo ; // expected-note {{previous declaration is here}}
void __attribute__ ( ( preserve_none ) ) typedef_fun_boo ( int x ) { } // expected-error {{function declared 'preserve_none' here was previously declared without calling convention}}
struct type_test_boo { } __attribute__ ( ( preserve_none ) ) ; // expected-warning {{'preserve_none' attribute only applies to functions and function pointers}}