Gfortran array descriptor update

See also LibgfortranAbiCleanup - when the ABI is changed, the clean up should be done.

In some cases it would be nice to improve gfortran's array descriptors (cf. PR37577).

See also discussion at comp.lang.fortran about base_address, base_address + offset, and base_address + virtual_origin. See also a reasoning why virtual origins are a bad idea.

Due to backward compatibility issues, it should be designed carefully so we don't have to do it that often. Libgfortran backward compatibility can be handled with SymbolVersioning , but a more difficult problem will be existing user code (is it feasible at all?).

Features desirable that aren't available in the current descriptor:

* Support rank 15 arrays (as planned for F 2008)

* Save coarray information. int corank might be enough.

* Save type information for (a) polymorphic data types but also (b) for run-time diagnostic.

* Support TR 29113 "Further Interoperability of Fortran with C", preferably as native format. See PR 37577.

For comparison, see Intel Fortran array descriptor (mixed language programming chapter), Pathscale array descriptor (Appendix D)

The TR 29113 draft as of 2008-11-06 had the following as a test case "to ensure what the TR says is compilable with gcc" - before implementing, check whether this has been approved meanwhile or whether a newer draft is available and check the exact meaning of the elements, the wording below is at least partially not the official one.

typedef struct {
         intptr_t  lower_bound,
                   extent, /* = number of elements in this dimension.  */
                   sm; /* stride multiplier; = pointer difference betwixt two consecutive elements.  */
} CFI_dim_t;


typedef struct {
 void *        base_addr;          /* base address of object                      */
 size_t        elem_len;           /* length of one element, in bytes             */
 int           rank;               /* object rank, 0 .. CF_MAX_RANK               */
 int           type;               /* identifier for type of object               */
 int           attribute;          /* object attribute: 0..2, or -1               */
 int           state;              /* allocation/association state: 0 or 1        */
 void *        fdesc;              /* pointer to corresponding Fortran descriptor */
 CFI_dim_t     dim[CFI_MAX_RANK];  /* dimension triples                           */
} CFI_cdesc_t;

/* Sympolic names for attributes of objects   */

#define CFI_attribute_assumed         0
#define CFI_attribute_allocatable     1
#define CFI_attribute_pointer         2

/* Symbolic names for type identifiers */

#define CFI_type_unknown               0
#define CFI_type_struct              100
#define CFI_type_signed_char           1
#define CFI_type_short                 3
#define CFI_type_int                   5
#define CFI_type_long                  7
#define CFI_type_long_long             9
#define CFI_type_size_t               11
#define CFI_type_int8_t               12
#define CFI_type_int16_t              14
#define CFI_type_int32_t              16
#define CFI_type_int64_t              18
#define CFI_type_int_least8_t         20
#define CFI_type_int_least16_t        22
#define CFI_type_int_least32_t        24
#define CFI_type_int_least64_t        26
#define CFI_type_int_fast8_t          28
#define CFI_type_int_fast16_t         30
#define CFI_type_int_fast32_t         32
#define CFI_type_int_fast64_t         34
#define CFI_type_intmax_t             36
#define CFI_type_intptr_t             37
#define CFI_type_float                38
#define CFI_type_double               39
#define CFI_type_long_double          40
#define CFI_type_float_Complex        41
#define CFI_type_double_Complex       42
#define CFI_type_long_double_Complex  43
#define CFI_type_Bool                 44
#define CFI_type_char                 45

The type is e.g. c_int8_t, c_char, etc., "TYPE" (presumably one should distinguish between sequence, bind(c) and extensible etc.). The Fortran descriptor is needed for character string lengths, flags like contiguous (cf. also F2008's contiguous attribute) or whether a pointer target is a pointer (and thus deallocatable). For Fortran 2008 one presumably needs to information about coarrays (e.g. number of co-ranks, number of contained ranks [for OpenMP/threads one can use the descriptor for co-ranks, for MPI not]). And one might want to store data for CLASS and derived-type length parameters. One should also make fdesc extensible.

None: ArrayDescriptorUpdate (last edited 2009-08-18 12:27:27 by TobiasBurnus)