GNU Compiler Collection (GCC) Internals: Named Address Spaces

Next: Misc, Previous: C++ ABI, Up: Target Macros [Contents][Index]

### 17.29 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: 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`.

Target Hook: 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`.

Target Hook: bool TARGET_ADDR_SPACE_VALID_POINTER_MODE (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 (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, 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 subset, addr_space_t superset)

  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: bool TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID (addr_space_t as)

  Define this to modify the default handling of address 0 for the address space. Return true if 0 should be considered a valid address.

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.

Target Hook: int TARGET_ADDR_SPACE_DEBUG (addr_space_t as)

  Define this to define how the address space is encoded in dwarf. The result is the value to be used with `DW_AT_address_class`.

Target Hook: void TARGET_ADDR_SPACE_DIAGNOSE_USAGE (addr_space_t as, location_t loc)

  Define this hook if the availability of an address space depends on command line options and some diagnostics should be printed when the address space is used. This hook is called during parsing and allows to emit a better diagnostic compared to the case where the address space was not registered with `c_register_addr_space`. as is the address space as registered with `c_register_addr_space`. loc is the location of the address space qualifier token. The default implementation does nothing.

Next: Misc, Previous: C++ ABI, Up: Target Macros [Contents][Index]