Next: , Previous: C++ ABI, Up: Target Macros


17.30 Adding support for named address spaces

The draft technical report of the ISO/IEC JTC1 S22 WG14 N1275 standards committee, Programming Languages - C - Extensions to support embedded processors, specifies a syntax for embedded processors to specify alternate address spaces. You can configure a GCC port to support section 5.1 of the draft report to add support for address spaces other than the default address space. These address spaces are new keywords that are similar to the volatile and const type attributes.

Pointers to named address spaces can have a different size than pointers to the generic address space.

For example, the SPU port uses the __ea address space to refer to memory in the host processor, rather than memory local to the SPU processor. Access to memory in the __ea address space involves issuing DMA operations to move data between the host processor and the local processor memory address space. Pointers in the __ea address space are either 32 bits or 64 bits based on the -mea32 or -mea64 switches (native SPU pointers are always 32 bits).

Internally, address spaces are represented as a small integer in the range 0 to 15 with address space 0 being reserved for the generic address space.

To register a named address space qualifier keyword with the C front end, the target may call the c_register_addr_space routine. For example, the SPU port uses the following to declare __ea as the keyword for named address space #1:

     #define ADDR_SPACE_EA 1
     c_register_addr_space ("__ea", ADDR_SPACE_EA);
— Target Hook: enum machine_mode TARGET_ADDR_SPACE_POINTER_MODE (addr_space_t address_space)

Define this to return the machine mode to use for pointers to address_space if the target supports named address spaces. The default version of this hook returns ptr_mode for the generic address space only.

— Target Hook: enum machine_mode TARGET_ADDR_SPACE_ADDRESS_MODE (addr_space_t address_space)

Define this to return the machine mode to use for addresses in address_space if the target supports named address spaces. The default version of this hook returns Pmode for the generic address space only.

— Target Hook: bool TARGET_ADDR_SPACE_VALID_POINTER_MODE (enum machine_mode mode, addr_space_t as)

Define this to return nonzero if the port can handle pointers with machine mode mode to address space as. This target hook is the same as the TARGET_VALID_POINTER_MODE target hook, except that it includes explicit named address space support. The default version of this hook returns true for the modes returned by either the TARGET_ADDR_SPACE_POINTER_MODE or TARGET_ADDR_SPACE_ADDRESS_MODE target hooks for the given address space.

— Target Hook: bool TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P (enum machine_mode mode, rtx exp, bool strict, addr_space_t as)

Define this to return true if exp is a valid address for mode mode in the named address space as. The strict parameter says whether strict addressing is in effect after reload has finished. This target hook is the same as the TARGET_LEGITIMATE_ADDRESS_P target hook, except that it includes explicit named address space support.

— Target Hook: rtx TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS (rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)

Define this to modify an invalid address x to be a valid address with mode mode in the named address space as. This target hook is the same as the TARGET_LEGITIMIZE_ADDRESS target hook, except that it includes explicit named address space support.

— Target Hook: bool TARGET_ADDR_SPACE_SUBSET_P (addr_space_t superset, addr_space_t subset)

Define this to return whether the subset named address space is contained within the superset named address space. Pointers to a named address space that is a subset of another named address space will be converted automatically without a cast if used together in arithmetic operations. Pointers to a superset address space can be converted to pointers to a subset address space via explicit casts.

— Target Hook: rtx TARGET_ADDR_SPACE_CONVERT (rtx op, tree from_type, tree to_type)

Define this to convert the pointer expression represented by the RTL op with type from_type that points to a named address space to a new pointer expression with type to_type that points to a different named address space. When this hook it called, it is guaranteed that one of the two address spaces is a subset of the other, as determined by the TARGET_ADDR_SPACE_SUBSET_P target hook.