Issue 230530.1: Data Sharing Attribute

Author: Jakub Jelinek
Champion: Jakub Jelinek
Date submitted: 2023-05-30
Date revised:
Date closed:
Type: Enhancement
Status: Open
DWARF Version: 6


OpenMP/OpenACC allows sharing, mapping or privatization of variables in OpenMP/OpenACC constructs. It can be useful to let the debugger know when is that happening and which kind of privatization.

Dumb example:

void foo (int *g) {
int a = 42, b = 16, c, d, e = 16, f;
#pragma omp parallel shared(a) firstprivate (b) private (c)
  c = 0;
  #pragma omp atomic
  #pragma omp for firstprivate (e) lastprivate (e) private (d)
  for (f = 0; f < 16; f++)
  d = b + c + f;
  g[d] = e;
  if (f == 15)
    e = 8;
#pragma omp target map(tofrom: a)
  a += e;

Here, a is explicitly shared in the parallel region (all threads operate on the same variable), e is implicitly shared there, c is privatized (each thread gets a distinct copy of the variable, for e.g. C++ default constructed), b is firstprivatized (like privatization, but each copy is initialized from the original variable; for e.g. C++ copy constructed) and on the worksharing loop d is privatized (each thread on that construct only has a private copy) and e is also privatized, initialized from the original at the start and value from last iteration copied back. f is implicitly privatized in that loop. And in the offloading region a is explicitly mapped to the other device and value copied back at the end, while e is implicitly firstprivatized. Only firstprivate+lastprivate is allowed on the same variable in one construct, other data sharing states

Proposed Changes

Add in Table 2.2:

DW_AT_data_sharing   Data sharing or mapping (OpenMP or OpenACC)

Insert before 2.11 Artificial Entries and renumber:

2.11 Data Sharing or Mapping of Declarations

OpenMP or OpenACC allow privatization, sharing or mapping of declarations or their parts inside the body of certain constructs.

The data sharing attribute or mapping of a declaration is represented by DW_AT_data_sharing attribute on a local copy of the declaration's debugging information entry, whose value is a bitwise or of constants drawn from the set of codes listed in Table 2.XX.

Table 2.XX Data sharing or mapping attributes


DW_AT_DATA_SHARING_implicit is bitwise ORed into the value if the data sharing or mapping has been determined implicitly (predetermined or implicitly determined) and should be clear if it has been specified explicitly.

In Table 7.5 add

DW_AT_data_sharing ‡    0x94    constant

Insert before 7.12 Source Languages and renumber:

7.12 Data Sharing Codes

The encodings of the constants used in the DW_AT_data_sharing attribute are given in Table 7.XX.

Table 7.XX: Data Sharing encodings

Data Sharing name               Value
DW_AT_DATA_SHARING_none         0x00
DW_AT_DATA_SHARING_shared       0x01
DW_AT_DATA_SHARING_private      0x02
DW_AT_DATA_SHARING_firstprivate 0x04
DW_AT_DATA_SHARING_lastprivate  0x08
DW_AT_DATA_SHARING_reduction    0x10
DW_AT_DATA_SHARING_mapped       0x20
DW_AT_DATA_SHARING_implicit     0x40

The value DW_AT_DATA_SHARING_none is equivalent to the absence of the DW_AT_data_sharing attribute.

Appendix A.

Add DW_AT_data_sharing to DW_TAG_variable.