xref: /llvm-project/flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 (revision 00ab44ee66dbcf0d32819dbc6e4eefd1b7c48dfa)
1*00ab44eeSKrzysztof Parzyszek!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s --check-prefixes ALL,HOST
2*00ab44eeSKrzysztof Parzyszek!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -fopenmp-is-device %s -o - | FileCheck %s --check-prefixes ALL,DEVICE
37fe8e0a7SKiran Chandramohan
47fe8e0a7SKiran Chandramohan! Check specification valid forms of declare target with functions
57fe8e0a7SKiran Chandramohan! utilising device_type and to clauses as well as the default
67fe8e0a7SKiran Chandramohan! zero clause declare target
77fe8e0a7SKiran Chandramohan
87fe8e0a7SKiran Chandramohan! DEVICE-LABEL: func.func @_QPfunc_t_device()
97fe8e0a7SKiran Chandramohan! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
107fe8e0a7SKiran ChandramohanFUNCTION FUNC_T_DEVICE() RESULT(I)
117fe8e0a7SKiran Chandramohan!$omp declare target to(FUNC_T_DEVICE) device_type(nohost)
127fe8e0a7SKiran Chandramohan    INTEGER :: I
137fe8e0a7SKiran Chandramohan    I = 1
147fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_T_DEVICE
157fe8e0a7SKiran Chandramohan
168840eb3fSShraiysh! DEVICE-LABEL: func.func @_QPfunc_enter_device()
178840eb3fSShraiysh! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (enter)>{{.*}}
188840eb3fSShraiyshFUNCTION FUNC_ENTER_DEVICE() RESULT(I)
198840eb3fSShraiysh!$omp declare target enter(FUNC_ENTER_DEVICE) device_type(nohost)
208840eb3fSShraiysh    INTEGER :: I
218840eb3fSShraiysh    I = 1
228840eb3fSShraiyshEND FUNCTION FUNC_ENTER_DEVICE
238840eb3fSShraiysh
247fe8e0a7SKiran Chandramohan! HOST-LABEL: func.func @_QPfunc_t_host()
257fe8e0a7SKiran Chandramohan! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}
267fe8e0a7SKiran ChandramohanFUNCTION FUNC_T_HOST() RESULT(I)
277fe8e0a7SKiran Chandramohan!$omp declare target to(FUNC_T_HOST) device_type(host)
287fe8e0a7SKiran Chandramohan    INTEGER :: I
297fe8e0a7SKiran Chandramohan    I = 1
307fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_T_HOST
317fe8e0a7SKiran Chandramohan
328840eb3fSShraiysh! HOST-LABEL: func.func @_QPfunc_enter_host()
338840eb3fSShraiysh! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (enter)>{{.*}}
348840eb3fSShraiyshFUNCTION FUNC_ENTER_HOST() RESULT(I)
358840eb3fSShraiysh!$omp declare target enter(FUNC_ENTER_HOST) device_type(host)
368840eb3fSShraiysh    INTEGER :: I
378840eb3fSShraiysh    I = 1
388840eb3fSShraiyshEND FUNCTION FUNC_ENTER_HOST
398840eb3fSShraiysh
407fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPfunc_t_any()
417fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
427fe8e0a7SKiran ChandramohanFUNCTION FUNC_T_ANY() RESULT(I)
437fe8e0a7SKiran Chandramohan!$omp declare target to(FUNC_T_ANY) device_type(any)
447fe8e0a7SKiran Chandramohan    INTEGER :: I
457fe8e0a7SKiran Chandramohan    I = 1
467fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_T_ANY
477fe8e0a7SKiran Chandramohan
488840eb3fSShraiysh! ALL-LABEL: func.func @_QPfunc_enter_any()
498840eb3fSShraiysh! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (enter)>{{.*}}
508840eb3fSShraiyshFUNCTION FUNC_ENTER_ANY() RESULT(I)
518840eb3fSShraiysh!$omp declare target enter(FUNC_ENTER_ANY) device_type(any)
528840eb3fSShraiysh    INTEGER :: I
538840eb3fSShraiysh    I = 1
548840eb3fSShraiyshEND FUNCTION FUNC_ENTER_ANY
558840eb3fSShraiysh
567fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPfunc_default_t_any()
577fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
587fe8e0a7SKiran ChandramohanFUNCTION FUNC_DEFAULT_T_ANY() RESULT(I)
597fe8e0a7SKiran Chandramohan!$omp declare target to(FUNC_DEFAULT_T_ANY)
607fe8e0a7SKiran Chandramohan    INTEGER :: I
617fe8e0a7SKiran Chandramohan    I = 1
627fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_DEFAULT_T_ANY
637fe8e0a7SKiran Chandramohan
648840eb3fSShraiysh! ALL-LABEL: func.func @_QPfunc_default_enter_any()
658840eb3fSShraiysh! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (enter)>{{.*}}
668840eb3fSShraiyshFUNCTION FUNC_DEFAULT_ENTER_ANY() RESULT(I)
678840eb3fSShraiysh!$omp declare target enter(FUNC_DEFAULT_ENTER_ANY)
688840eb3fSShraiysh    INTEGER :: I
698840eb3fSShraiysh    I = 1
708840eb3fSShraiyshEND FUNCTION FUNC_DEFAULT_ENTER_ANY
718840eb3fSShraiysh
727fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPfunc_default_any()
737fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
747fe8e0a7SKiran ChandramohanFUNCTION FUNC_DEFAULT_ANY() RESULT(I)
757fe8e0a7SKiran Chandramohan!$omp declare target
767fe8e0a7SKiran Chandramohan    INTEGER :: I
777fe8e0a7SKiran Chandramohan    I = 1
787fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_DEFAULT_ANY
797fe8e0a7SKiran Chandramohan
807fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPfunc_default_extendedlist()
817fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
827fe8e0a7SKiran ChandramohanFUNCTION FUNC_DEFAULT_EXTENDEDLIST() RESULT(I)
837fe8e0a7SKiran Chandramohan!$omp declare target(FUNC_DEFAULT_EXTENDEDLIST)
847fe8e0a7SKiran Chandramohan    INTEGER :: I
857fe8e0a7SKiran Chandramohan    I = 1
867fe8e0a7SKiran ChandramohanEND FUNCTION FUNC_DEFAULT_EXTENDEDLIST
877fe8e0a7SKiran Chandramohan
887fe8e0a7SKiran Chandramohan!! -----
897fe8e0a7SKiran Chandramohan
907fe8e0a7SKiran Chandramohan! Check specification valid forms of declare target with subroutines
917fe8e0a7SKiran Chandramohan! utilising device_type and to clauses as well as the default
927fe8e0a7SKiran Chandramohan! zero clause declare target
937fe8e0a7SKiran Chandramohan
947fe8e0a7SKiran Chandramohan! DEVICE-LABEL: func.func @_QPsubr_t_device()
957fe8e0a7SKiran Chandramohan! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
967fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_T_DEVICE()
977fe8e0a7SKiran Chandramohan!$omp declare target to(SUBR_T_DEVICE) device_type(nohost)
987fe8e0a7SKiran ChandramohanEND
997fe8e0a7SKiran Chandramohan
1008840eb3fSShraiysh! DEVICE-LABEL: func.func @_QPsubr_enter_device()
1018840eb3fSShraiysh! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (enter)>{{.*}}
1028840eb3fSShraiyshSUBROUTINE SUBR_ENTER_DEVICE()
1038840eb3fSShraiysh!$omp declare target enter(SUBR_ENTER_DEVICE) device_type(nohost)
1048840eb3fSShraiyshEND
1058840eb3fSShraiysh
1067fe8e0a7SKiran Chandramohan! HOST-LABEL: func.func @_QPsubr_t_host()
1077fe8e0a7SKiran Chandramohan! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}
1087fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_T_HOST()
1097fe8e0a7SKiran Chandramohan!$omp declare target to(SUBR_T_HOST) device_type(host)
1107fe8e0a7SKiran ChandramohanEND
1117fe8e0a7SKiran Chandramohan
1128840eb3fSShraiysh! HOST-LABEL: func.func @_QPsubr_enter_host()
1138840eb3fSShraiysh! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (enter)>{{.*}}
1148840eb3fSShraiyshSUBROUTINE SUBR_ENTER_HOST()
1158840eb3fSShraiysh!$omp declare target enter(SUBR_ENTER_HOST) device_type(host)
1168840eb3fSShraiyshEND
1178840eb3fSShraiysh
1187fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPsubr_t_any()
1197fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
1207fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_T_ANY()
1217fe8e0a7SKiran Chandramohan!$omp declare target to(SUBR_T_ANY) device_type(any)
1227fe8e0a7SKiran ChandramohanEND
1237fe8e0a7SKiran Chandramohan
1248840eb3fSShraiysh! ALL-LABEL: func.func @_QPsubr_enter_any()
1258840eb3fSShraiysh! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (enter)>{{.*}}
1268840eb3fSShraiyshSUBROUTINE SUBR_ENTER_ANY()
1278840eb3fSShraiysh!$omp declare target enter(SUBR_ENTER_ANY) device_type(any)
1288840eb3fSShraiyshEND
1298840eb3fSShraiysh
1307fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPsubr_default_t_any()
1317fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
1327fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_DEFAULT_T_ANY()
1337fe8e0a7SKiran Chandramohan!$omp declare target to(SUBR_DEFAULT_T_ANY)
1347fe8e0a7SKiran ChandramohanEND
1357fe8e0a7SKiran Chandramohan
1368840eb3fSShraiysh! ALL-LABEL: func.func @_QPsubr_default_enter_any()
1378840eb3fSShraiysh! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (enter)>{{.*}}
1388840eb3fSShraiyshSUBROUTINE SUBR_DEFAULT_ENTER_ANY()
1398840eb3fSShraiysh!$omp declare target enter(SUBR_DEFAULT_ENTER_ANY)
1408840eb3fSShraiyshEND
1418840eb3fSShraiysh
1427fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPsubr_default_any()
1437fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
1447fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_DEFAULT_ANY()
1457fe8e0a7SKiran Chandramohan!$omp declare target
1467fe8e0a7SKiran ChandramohanEND
1477fe8e0a7SKiran Chandramohan
1487fe8e0a7SKiran Chandramohan! ALL-LABEL: func.func @_QPsubr_default_extendedlist()
1497fe8e0a7SKiran Chandramohan! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}
1507fe8e0a7SKiran ChandramohanSUBROUTINE SUBR_DEFAULT_EXTENDEDLIST()
1517fe8e0a7SKiran Chandramohan!$omp declare target(SUBR_DEFAULT_EXTENDEDLIST)
1527fe8e0a7SKiran ChandramohanEND
1537fe8e0a7SKiran Chandramohan
1547fe8e0a7SKiran Chandramohan!! -----
1557fe8e0a7SKiran Chandramohan
1567fe8e0a7SKiran Chandramohan! DEVICE-LABEL: func.func @_QPrecursive_declare_target
157d9250061SjeanPerier! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}
1587fe8e0a7SKiran ChandramohanRECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET(INCREMENT) RESULT(K)
1597fe8e0a7SKiran Chandramohan!$omp declare target to(RECURSIVE_DECLARE_TARGET) device_type(nohost)
1607fe8e0a7SKiran Chandramohan    INTEGER :: INCREMENT, K
1617fe8e0a7SKiran Chandramohan    IF (INCREMENT == 10) THEN
1627fe8e0a7SKiran Chandramohan        K = INCREMENT
1637fe8e0a7SKiran Chandramohan    ELSE
1647fe8e0a7SKiran Chandramohan        K = RECURSIVE_DECLARE_TARGET(INCREMENT + 1)
1657fe8e0a7SKiran Chandramohan    END IF
1667fe8e0a7SKiran ChandramohanEND FUNCTION RECURSIVE_DECLARE_TARGET
1678840eb3fSShraiysh
1688840eb3fSShraiysh! DEVICE-LABEL: func.func @_QPrecursive_declare_target_enter
169d9250061SjeanPerier! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (enter)>{{.*}}
1708840eb3fSShraiyshRECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET_ENTER(INCREMENT) RESULT(K)
1718840eb3fSShraiysh!$omp declare target enter(RECURSIVE_DECLARE_TARGET_ENTER) device_type(nohost)
1728840eb3fSShraiysh    INTEGER :: INCREMENT, K
1738840eb3fSShraiysh    IF (INCREMENT == 10) THEN
1748840eb3fSShraiysh        K = INCREMENT
1758840eb3fSShraiysh    ELSE
1768840eb3fSShraiysh        K = RECURSIVE_DECLARE_TARGET_ENTER(INCREMENT + 1)
1778840eb3fSShraiysh    END IF
1788840eb3fSShraiyshEND FUNCTION RECURSIVE_DECLARE_TARGET_ENTER
179