Skip to content

Commit 34459b7

Browse files
authored
[OpenMP] Provide big-endian bitfield definitions (llvm#69995)
structs kmp_depend_info.flags and kmp_tasking_flags contain bitfields, which overlay integer flag values. The current bitfield definitions target little-endian machines. On big-endian machines bitfields are laid out in the opposite order, so the current definitions do not work there. There are two ways to fix this: either provide big-endian bitfield definitions, or bit-swap integer flag values. Go with the former, since it's localized to one place and therefore is more maintainable.
1 parent 122c89b commit 34459b7

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

openmp/runtime/src/kmp.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2456,12 +2456,22 @@ typedef struct kmp_depend_info {
24562456
union {
24572457
kmp_uint8 flag; // flag as an unsigned char
24582458
struct { // flag as a set of 8 bits
2459+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2460+
/* Same fields as in the #else branch, but in reverse order */
2461+
unsigned all : 1;
2462+
unsigned unused : 3;
2463+
unsigned set : 1;
2464+
unsigned mtx : 1;
2465+
unsigned out : 1;
2466+
unsigned in : 1;
2467+
#else
24592468
unsigned in : 1;
24602469
unsigned out : 1;
24612470
unsigned mtx : 1;
24622471
unsigned set : 1;
24632472
unsigned unused : 3;
24642473
unsigned all : 1;
2474+
#endif
24652475
} flags;
24662476
};
24672477
} kmp_depend_info_t;
@@ -2611,6 +2621,33 @@ typedef struct kmp_task_stack {
26112621
#endif // BUILD_TIED_TASK_STACK
26122622

26132623
typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
2624+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2625+
/* Same fields as in the #else branch, but in reverse order */
2626+
#if OMPX_TASKGRAPH
2627+
unsigned reserved31 : 6;
2628+
unsigned onced : 1;
2629+
#else
2630+
unsigned reserved31 : 7;
2631+
#endif
2632+
unsigned native : 1;
2633+
unsigned freed : 1;
2634+
unsigned complete : 1;
2635+
unsigned executing : 1;
2636+
unsigned started : 1;
2637+
unsigned team_serial : 1;
2638+
unsigned tasking_ser : 1;
2639+
unsigned task_serial : 1;
2640+
unsigned tasktype : 1;
2641+
unsigned reserved : 8;
2642+
unsigned hidden_helper : 1;
2643+
unsigned detachable : 1;
2644+
unsigned priority_specified : 1;
2645+
unsigned proxy : 1;
2646+
unsigned destructors_thunk : 1;
2647+
unsigned merged_if0 : 1;
2648+
unsigned final : 1;
2649+
unsigned tiedness : 1;
2650+
#else
26142651
/* Compiler flags */ /* Total compiler flags must be 16 bits */
26152652
unsigned tiedness : 1; /* task is either tied (1) or untied (0) */
26162653
unsigned final : 1; /* task is final(1) so execute immediately */
@@ -2646,7 +2683,7 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
26462683
#else
26472684
unsigned reserved31 : 7; /* reserved for library use */
26482685
#endif
2649-
2686+
#endif
26502687
} kmp_tasking_flags_t;
26512688

26522689
typedef struct kmp_target_data {

0 commit comments

Comments
 (0)