d: Add `@register' attribute to compiler and library.
commit91418c42089cd1cbe71edcd6b2f5b26559819372
authorIain Buclaw <ibuclaw@gdcproject.org>
Thu, 23 Jun 2022 16:24:07 +0000 (23 18:24 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Fri, 24 Jun 2022 18:49:58 +0000 (24 20:49 +0200)
tree6419c5301b4fb08e5b0cac64baddc66f7e3acadf
parent8288cd635fa0bd75a8c5f25c7a90d4a7a4acec81
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.
gcc/d/d-attribs.cc
gcc/d/d-codegen.cc
gcc/d/d-tree.h
gcc/d/decl.cc
gcc/d/expr.cc
gcc/testsuite/gdc.dg/attr_register1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_register2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_register3.d [new file with mode: 0644]
libphobos/libdruntime/gcc/attributes.d