Skip to content

Commit 182d32f

Browse files
committed
[FLANG] Fix for Stop statements in Fortran emissary API
1 parent 42ce4c6 commit 182d32f

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

offload/DeviceRTL/include/EmissaryIds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef enum {
5353
_FortranAAbort_idx,
5454
_FortranAStopStatementText_idx,
5555
_FortranAioBeginExternalFormattedOutput_idx,
56+
_FortranAStopStatement_idx,
5657
} offload_emis_fortrt_idx;
5758

5859
/// This structure is created by emisExtractArgBuf to make it easier

offload/DeviceRTL/src/EmissaryFortrt.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ uint32_t omp_get_num_threads();
3333
uint32_t omp_get_team_num();
3434
uint32_t omp_get_num_teams();
3535

36+
// All Fortran Runtime Functions pass 4 extra args to assist with
37+
// defered execution and debug. The host variadic wrappers do not use
38+
// these arguments when calling the actual Fortran runtime.
3639
#define _EXTRA_ARGS \
3740
omp_get_thread_num(), omp_get_num_threads(), omp_get_team_num(), \
3841
omp_get_num_teams()
42+
#define _START_ARGS(idx) _PACK_EMIS_IDS(EMIS_ID_FORTRT, idx), _EXTRA_ARGS,
3943

4044
void *_FortranAioBeginExternalListOutput(uint32_t a1, const char *a2,
4145
uint32_t a3) {
@@ -116,15 +120,20 @@ bool _FortranAioOutputLogical(void *cookie, bool barg) {
116120
cookie, barg);
117121
}
118122
void _FortranAAbort() {
119-
_emissary_exec(_PACK_EMIS_IDS(EMIS_ID_FORTRT, _FortranAAbort_idx));
123+
_emissary_exec(_PACK_EMIS_IDS(EMIS_ID_FORTRT, _FortranAAbort_idx),
124+
_EXTRA_ARGS);
120125
// When host service _FortranAAbort finishes, we must die from the device.
121126
__builtin_trap();
122127
}
128+
void _FortranAStopStatement(int32_t a1, bool a2, bool a3) {
129+
_emissary_exec(_PACK_EMIS_IDS(EMIS_ID_FORTRT, _FortranAStopStatement_idx),
130+
_EXTRA_ARGS, a1, a2, a3);
131+
__builtin_trap();
132+
}
123133
void _FortranAStopStatementText(char *errmsg, int64_t a1, bool a2, bool a3) {
124-
// TODO: must use string length from a1 arg
125134
errmsg[a1 - 1] = (char)0;
126135
_emissary_exec(_PACK_EMIS_IDS(EMIS_ID_FORTRT, _FortranAStopStatementText_idx),
127-
errmsg, a1, a2, a3);
136+
_EXTRA_ARGS, errmsg, a1, a2, a3);
128137
__builtin_trap();
129138
}
130139

offload/DeviceRTL/src/exports

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ printf_*
2323
f90print*
2424
fprintf_*
2525

26-
_FortranAio*
26+
_FortranA*
2727
__ockl_dm_alloc
2828
__ockl_dm_dealloc
2929
__asan*

offload/plugins-nextgen/common/src/EmissaryFortrt.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ bool _FortranAioOutputComplex64(void *cookie, double re, double im);
5252
bool _FortranAioOutputLogical(void *cookie, bool truth);
5353
void _FortranAAbort();
5454
void _FortranAStopStatementText(char *errmsg, int64_t a1, bool a2, bool a3);
55+
void _FortranAStopStatement(int32_t a1, bool a2, bool a3);
5556

5657
// Save the cookie because deferred functions have execution reordered.
5758
static void *_list_started_cookie = nullptr;
@@ -212,6 +213,17 @@ extern void V_FortranAStopStatementText(void *fnptr, ...) {
212213
bool b3 = (bool)a3;
213214
_FortranAStopStatementText(errmsg, a1, b2, b3);
214215
}
216+
extern void V_FortranAStopStatement(void *fnptr, ...) {
217+
va_list args;
218+
va_start(args, fnptr);
219+
int32_t a1 = va_arg(args, int32_t);
220+
uint32_t a2 = va_arg(args, uint32_t);
221+
uint32_t a3 = va_arg(args, uint32_t);
222+
va_end(args);
223+
bool b2 = (bool)a2;
224+
bool b3 = (bool)a3;
225+
_FortranAStopStatement(a1, b2, b3);
226+
}
215227
} // end extern "C"
216228

217229
// Static vars used to defer functions to reorder execution by thread and team.
@@ -367,6 +379,11 @@ extern "C" emis_return_t EmissaryFortrt(char *data, emisArgBuf_t *ab) {
367379
fnptr = (void *)V_FortranAStopStatementText;
368380
break;
369381
}
382+
case _FortranAStopStatement_idx: {
383+
defer_for_reorder = false;
384+
fnptr = (void *)V_FortranAStopStatement;
385+
break;
386+
}
370387
case _FortranAio_INVALID:
371388
default: {
372389
defer_for_reorder = false;

0 commit comments

Comments
 (0)