diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-23 18:24:07 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-24 20:49:58 +0200 |
commit | 91418c42089cd1cbe71edcd6b2f5b26559819372 (patch) | |
tree | 6419c5301b4fb08e5b0cac64baddc66f7e3acadf /libphobos | |
parent | 8288cd635fa0bd75a8c5f25c7a90d4a7a4acec81 (diff) | |
download | gcc-91418c42089cd1cbe71edcd6b2f5b26559819372.zip gcc-91418c42089cd1cbe71edcd6b2f5b26559819372.tar.gz gcc-91418c42089cd1cbe71edcd6b2f5b26559819372.tar.bz2 |
d: Add `@register' attribute to compiler and library.
The `@register` attribute specifies that a local or `__gshared` variable
is to be given a register storage-class in the C sense of the term, and
will be placed into a register named `registerName`.
The variable needs to boiled down to a data type that fits the target
register. It also cannot have either thread-local or `extern` storage.
It is an error to take the address of a register variable.
PR d/105413
gcc/d/ChangeLog:
* d-attribs.cc (d_handle_register_attribute): New function.
(d_langhook_attribute_table): Add register attribute.
* d-codegen.cc (d_mark_addressable): Error if taken address of
register variable.
(build_frame_type): Error if register variable has non-local
references.
* d-tree.h (d_mark_addressable): Add complain parameter.
* decl.cc (get_symbol_decl): Mark register varibles DECL_REGISTER.
Error when register variable declared thread-local or extern.
* expr.cc (ExprVisitor::visit (IndexExp *)): Don't complain about
marking register vectors as addressable in an ARRAY_REF.
libphobos/ChangeLog:
* libdruntime/gcc/attributes.d (register): Define.
gcc/testsuite/ChangeLog:
* gdc.dg/attr_register1.d: New test.
* gdc.dg/attr_register2.d: New test.
* gdc.dg/attr_register3.d: New test.
Diffstat (limited to 'libphobos')
-rw-r--r-- | libphobos/libdruntime/gcc/attributes.d | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libphobos/libdruntime/gcc/attributes.d b/libphobos/libdruntime/gcc/attributes.d index 710e8ab..40a18bf 100644 --- a/libphobos/libdruntime/gcc/attributes.d +++ b/libphobos/libdruntime/gcc/attributes.d @@ -302,6 +302,34 @@ auto optimize(A...)(A arguments) } /** + * The `@register` attribute specifies that a local or `__gshared` variable + * is to be given a register storage-class in the C99 sense of the term, and + * will be placed into a register named `registerName`. + * + * The variable needs to boiled down to a data type that fits the target + * register. It also cannot have either thread-local or `extern` storage. + * It is an error to take the address of a register variable. + * + * Example: + * --- + * import gcc.attributes; + * + * @register("ebx") __gshared int ebx = void; + * + * void func() { @register("r10") long r10 = 0x2a; } + * --- + */ +auto register(string registerName) +{ + return attribute("register", registerName); +} + +auto register(A...)(A arguments) +{ + assert(false, "register attribute argument not a string constant"); +} + +/** * The `@restrict` attribute specifies that a function parameter is to be * restrict-qualified in the C99 sense of the term. The parameter needs to * boil down to either a pointer or reference type, such as a D pointer, |