Skip to content

Commit 1132b07

Browse files
committed
Replace raw #pragma with portable macros
GIB_PRAGMA will emit build-time messages in the same manner as before but safely across Clang and GCC. I had Codex suggest this code, but I did my due diligence and tested and looked into official docs to ensure the solution works and actually makes sense.
1 parent 3f572f4 commit 1132b07

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

gibbon-rts/rts-c/gibbon_rts.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ GibSym gib_read_gensym_counter(void)
145145
#ifdef _GIBBON_POINTER
146146

147147
#ifdef _GIBBON_BUMPALLOC_HEAP
148-
#pragma message "Using bump allocator."
148+
GIB_PRAGMA_MESSAGE("Using bump allocator.")
149149

150150
static __thread char *gib_global_ptr_bumpalloc_heap_ptr = (char *) NULL;
151151
static __thread char *gib_global_ptr_bumpalloc_heap_ptr_end = (char *) NULL;
@@ -512,7 +512,7 @@ GibCursor *gib_array_alloc(GibCursor *arr, size_t size)
512512
exit(1);
513513
}
514514

515-
#pragma GCC unroll 2
515+
GIB_PRAGMA_UNROLL(2)
516516
for (size_t i = 0; i < size; i++){
517517
arr_on_heap[i] = arr[i];
518518
}
@@ -724,7 +724,7 @@ double gib_sum_timing_array(GibVector *times)
724724

725725
#ifdef _GIBBON_BUMPALLOC_LISTS
726726
// #define _GIBBON_DEBUG
727-
#pragma message "Using bump allocator."
727+
GIB_PRAGMA_MESSAGE("Using bump allocator.")
728728

729729
static __thread char *gib_global_list_bumpalloc_heap_ptr = (char *) NULL;
730730
static __thread char *gib_global_list_bumpalloc_heap_ptr_end = (char *) NULL;
@@ -1054,26 +1054,26 @@ void gib_print_gc_config(void) {
10541054
printf("C config\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
10551055

10561056
#if defined _GIBBON_GENGC && _GIBBON_GENGC == 0
1057-
#pragma message "Generational GC is disabled."
1057+
GIB_PRAGMA_MESSAGE("Generational GC is disabled.")
10581058
printf("Generational GC is disabled.\n");
10591059
#else
1060-
#pragma message "Generational GC is enabled."
1060+
GIB_PRAGMA_MESSAGE("Generational GC is enabled.")
10611061
printf("Generational GC is enabled.\n");
10621062
#endif
10631063

10641064
#if defined _GIBBON_EAGER_PROMOTION && _GIBBON_EAGER_PROMOTION == 0
1065-
#pragma message "Eager promotion is disabled."
1065+
GIB_PRAGMA_MESSAGE("Eager promotion is disabled.")
10661066
printf("Eager promotion is disabled.\n");
10671067
#else
1068-
#pragma message "Eager promotion is enabled."
1068+
GIB_PRAGMA_MESSAGE("Eager promotion is enabled.")
10691069
printf("Eager promotion is enabled.\n");
10701070
#endif
10711071

10721072
#if defined _GIBBON_SIMPLE_WRITE_BARRIER && _GIBBON_SIMPLE_WRITE_BARRIER == 0
1073-
#pragma message "Simple write barrier is disabled."
1073+
GIB_PRAGMA_MESSAGE("Simple write barrier is disabled.")
10741074
printf("Simple write barrier is disabled.\n");
10751075
#else
1076-
#pragma message "Simple write barrier is enabled."
1076+
GIB_PRAGMA_MESSAGE("Simple write barrier is enabled.")
10771077
printf("Simple write barrier is enabled.\n");
10781078
#endif
10791079

gibbon-rts/rts-c/gibbon_rts.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
#include <cilk/cilk_api.h>
1616
#endif
1717

18+
#define GIB_PRAGMA(x) _Pragma(#x)
19+
20+
#if defined(__clang__)
21+
#define GIB_PRAGMA_MESSAGE(msg) \
22+
GIB_PRAGMA(clang diagnostic push) \
23+
GIB_PRAGMA(clang diagnostic ignored "-W#pragma-messages") \
24+
GIB_PRAGMA(message msg) \
25+
GIB_PRAGMA(clang diagnostic pop)
26+
#else
27+
#define GIB_PRAGMA_MESSAGE(msg) GIB_PRAGMA(message msg)
28+
#endif
29+
30+
#if defined(__clang__)
31+
#define GIB_PRAGMA_UNROLL(n) GIB_PRAGMA(unroll n)
32+
#elif defined(__GNUC__) && (__GNUC__ >= 8)
33+
#define GIB_PRAGMA_UNROLL(n) GIB_PRAGMA(GCC unroll n)
34+
#else
35+
#define GIB_PRAGMA_UNROLL(n)
36+
#endif
1837
/*
1938
* CPP macros used in the RTS:
2039
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -358,7 +377,7 @@ extern bool gib_global_thread_requested_gc;
358377

359378
extern uint64_t gib_global_num_threads;
360379

361-
INLINE_HEADER GibThreadId gib_get_thread_id()
380+
INLINE_HEADER GibThreadId gib_get_thread_id(void)
362381
{
363382
#ifdef _GIBBON_PARALLEL
364383
return __cilkrts_get_worker_number();
@@ -1083,9 +1102,9 @@ INLINE_HEADER void gib_indirection_barrier(
10831102
{
10841103

10851104
#if defined _GIBBON_SIMPLE_WRITE_BARRIER && _GIBBON_SIMPLE_WRITE_BARRIER == 1
1086-
#pragma message "Simple write barrier is enabled."
1105+
GIB_PRAGMA_MESSAGE("Simple write barrier is enabled.")
10871106
#else
1088-
#pragma message "Simple write barrier is disabled."
1107+
GIB_PRAGMA_MESSAGE("Simple write barrier is disabled.")
10891108
{
10901109
// Optimization: don't create long chains of indirection pointers.
10911110
GibPackedTag pointed_to_tag = *(GibPackedTag *) to;
@@ -1219,12 +1238,12 @@ INLINE_HEADER uint8_t gib_log2(size_t x)
12191238

12201239
// From Chandler Carruth's CppCon 2015 talk.
12211240
INLINE_HEADER void escape(void *p) {
1222-
asm volatile("" : : "g"(p) : "memory");
1241+
__asm__ __volatile__("" : : "g"(p) : "memory");
12231242
}
12241243

12251244
// From Chandler Carruth's CppCon 2015 talk.
1226-
INLINE_HEADER void clobber() {
1227-
asm volatile("" : : : "memory");
1245+
INLINE_HEADER void clobber(void) {
1246+
__asm__ __volatile__("" : : : "memory");
12281247
}
12291248

12301249

0 commit comments

Comments
 (0)