Skip to content

Commit 4c90833

Browse files
authored
Merge pull request #585 from ThePortlandGroup/nv_stage
Pull 2018-09-12T11-48 Recent NVIDIA Changes
2 parents 53e368b + 23213ad commit 4c90833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1549
-1342
lines changed

include/flang/Error/pgerror.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
#include "universal.h"
2626

27+
#ifndef IN_FLANG2
2728
BEGIN_DECL_WITH_C_LINKAGE
29+
#endif
2830

2931
/** \brief Severity of an error message.
3032
*/
@@ -37,10 +39,18 @@ typedef enum error_severity {
3739
ERR_SEVERITY_SIZE // must be last!
3840
} error_severity;
3941

42+
#ifdef IN_FLANG2
43+
#include "errmsgdf.h"
44+
#endif
45+
4046
/** \brief Error code type
4147
*/
4248
typedef enum error_code error_code_t;
4349

50+
#ifdef IN_FLANG2
51+
#include "error.h"
52+
#endif
53+
4454
#ifdef FE90
4555
void errWithSrc(error_code_t ecode, enum error_severity sev, int eline,
4656
const char *op1, const char *op2, int col, int deduceCol,
@@ -82,6 +92,8 @@ void dassert_err(const char *, int line, const char *exp, const char *txt);
8292
void asrt_failed(const char* file, int line);
8393
#endif
8494

95+
#ifndef IN_FLANG2
8596
END_DECL_WITH_C_LINKAGE
97+
#endif
8698

8799
#endif /* PGERROR_H_ */

lib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
2+
# Copyright (c) 2015-2018, NVIDIA CORPORATION. All rights reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17+
set(LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
18+
1719
add_subdirectory(ADT)
1820
add_subdirectory(ArgParser)
1921
add_subdirectory(scutil)

runtime/flang/ptr.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,61 @@ I8(ptr_assn)(char *pb, F90_Desc *pd, dtype kind, __CLEN_T len, char *tb,
815815
return res;
816816
}
817817

818+
void
819+
ENTF90(TMP_DESC,tmp_desc)(F90_Desc *nd, F90_Desc *od)
820+
{
821+
/* nd is the new, temporary argument descriptor, od is original descriptor */
822+
dtype kind;
823+
__CLEN_T len;
824+
825+
if (nd == NULL || od == NULL) {
826+
__fort_abort("TMP_DESC: invalid descriptor");
827+
} else if (F90_TAG_G(od) == __DESC) {
828+
kind = F90_KIND_G(od);
829+
len = F90_LEN_G(od);
830+
__INT_T gsize;
831+
__INT_T i, rank, flags, lbase;
832+
DECL_F90_DIM_PTR(odd);
833+
DECL_F90_DIM_PTR(ndd);
834+
gsize = 1;
835+
rank = F90_RANK_G(od);
836+
flags = F90_FLAGS_G(od);
837+
lbase = F90_LBASE_G(od);
838+
/* tag, rank, kind, len, flags, gsize, lsize, gbase, lbase */
839+
F90_TAG_P(nd, __DESC);
840+
F90_RANK_P(nd, rank);
841+
F90_KIND_P(nd, F90_KIND_G(od));
842+
F90_LEN_P(nd, F90_LEN_G(od));
843+
F90_LSIZE_P(nd, F90_LSIZE_G(od));
844+
F90_GBASE_P(nd, F90_GBASE_G(od));
845+
846+
SET_DIM_PTRS(odd, od, 0);
847+
SET_DIM_PTRS(ndd, nd, 0);
848+
for (i = 0; i < rank; ++i) {
849+
__INT_T __extent, __myoffset, __stride;
850+
__extent = F90_DPTR_EXTENT_G(odd); /* section extent */
851+
__myoffset = F90_DPTR_LBOUND_G(odd) - 1;
852+
__stride = F90_DPTR_LSTRIDE_G(odd);
853+
F90_DPTR_LBOUND_P(ndd, 1); /* lower bound */
854+
DPTR_UBOUND_P(ndd, __extent); /* upper bound */
855+
F90_DPTR_SSTRIDE_P(ndd, 1); /* placeholders */
856+
F90_DPTR_SOFFSET_P(ndd, 0);
857+
F90_DPTR_LSTRIDE_P(ndd, __stride);
858+
lbase += __myoffset * __stride;
859+
if (__stride != gsize)
860+
flags &= ~__SEQUENTIAL_SECTION;
861+
gsize *= __extent;
862+
++F90_DIM_NAME(odd);
863+
++F90_DIM_NAME(ndd);
864+
}
865+
F90_LBASE_P(nd, lbase);
866+
F90_FLAGS_P(nd, flags);
867+
F90_GSIZE_P(nd, gsize); /* global section size */
868+
} else {
869+
__fort_abort("TMP_DESC: invalid original");
870+
}
871+
}
872+
818873
void *
819874
ENTFTN(PTR_ASSN, ptr_assn)(char *pb, F90_Desc *pd, char *tb, F90_Desc *td,
820875
__INT_T *sectflag)

tools/flang1/flang1exe/dpm_out.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ is_kopy_in_needed(int arg)
12231223
/* only dummies, result variables passed like dummies */
12241224
if (SCG(arg) != SC_DUMMY && !RESULTG(arg))
12251225
return FALSE;
1226-
/* pointer need kopy-in, regardless of type */
1226+
/* pointer needs kopy-in, regardless of type */
12271227
if (POINTERG(arg) || IS_PROC_DUMMYG(arg))
12281228
return TRUE;
12291229
/* other nonarrays need no kopy in */
@@ -2357,6 +2357,28 @@ emit_alnd(int sptr, int memberast, LOGICAL free_flag, LOGICAL for_allocate,
23572357
sptr, typed_alloc, 0 /* no parent AST */, Lbegin);
23582358
}
23592359

2360+
void
2361+
make_temp_descriptor(int sptr_orig, int sptr_tmp, int before_std)
2362+
{
2363+
/* call pgf90_temp_desc(tmp desc, orig desc) */
2364+
SPTR sptr_descr;
2365+
int sptrdescr_arg, ast;
2366+
int nargs = 2;
2367+
int argt = mk_argt(nargs);
2368+
sptr_descr = DESCRG(sptr_tmp);
2369+
sptrdescr_arg = mk_id(sptr_descr);
2370+
ARGT_ARG(argt, 0) = sptrdescr_arg;
2371+
sptr_descr = DESCRG(sptr_orig);
2372+
sptrdescr_arg = mk_id(sptr_descr);
2373+
ARGT_ARG(argt, 1) = sptrdescr_arg;
2374+
2375+
ast =
2376+
mk_func_node(A_CALL,
2377+
mk_id(sym_mkfunc(mkRteRtnNm(RTE_tmp_desc), DT_NONE)),
2378+
nargs, argt);
2379+
(void) add_stmt_before(ast, before_std);
2380+
}
2381+
23602382
void
23612383
init_sdsc_from_dtype(int sptr, DTYPE dtype, int before_std)
23622384
{
@@ -4091,7 +4113,8 @@ set_assumed_bounds(int arg, int entry, int actual)
40914113
}
40924114
/* also, arg is assumed shape, and since !TARGET mark as stride 1 */
40934115
SDSCS1P(arg, 1); /* see comment below regarding these xbits */
4094-
update_shape_info(arg);
4116+
if( XBIT(55,0x80) )
4117+
update_shape_info(arg);
40954118
}
40964119

40974120
for (i = 0; i < r; ++i) {
@@ -4106,14 +4129,22 @@ set_assumed_bounds(int arg, int entry, int actual)
41064129
ast1 = mk_isz_cval(1, astb.bnd.dtype);
41074130
if (A_TYPEG(tmp_lb) == A_CNST) {
41084131
sav = tmp_lb;
4109-
} else if (XBIT(54, 2) || (XBIT(58, 0x400000) && TARGETG(arg))) {
4110-
/* lower bound assignment */
4111-
/* lb = <global lower bound> */
4112-
ast_gbl = get_global_lower(newdsc, i);
4132+
} else if ((XBIT(58, 0x400000) && TARGETG(arg)) &&
4133+
tmp_lb == ast1 && A_TYPEG(tmp_lb) == A_ID) {
4134+
/*
4135+
FIX ME: setting the descriptor bounds to 1 here does not work since
4136+
there can be other references (such as loop bounds) which use the
4137+
symbolic lower bounds for each dimension.
4138+
ast1 = mk_isz_cval(1, astb.bnd.dtype);
4139+
sav = AD_LWAST(ad, i) = AD_LWBD(ad, i) = ast1;
4140+
*/
4141+
4142+
/* so we just assign the symbolic lower bound ID to 1 */
4143+
ast1 = mk_isz_cval(1, astb.bnd.dtype);
41134144
sav = ast1;
41144145
ast2 = mk_stmt(A_ASN, 0);
41154146
A_DESTP(ast2, tmp_lb);
4116-
A_SRCP(ast2, ast_gbl);
4147+
A_SRCP(ast2, ast1);
41174148
std = add_stmt_after(ast2, std);
41184149
} else if (tmp_lb != ast1) {
41194150
/* output lower bound assignment */

tools/flang1/flang1exe/extern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void copy_surrogate_to_bnds_vars(DTYPE, int, DTYPE, int, int);
7272
void copy_desc_to_bnds_vars(int sptrdest, int desc, int memdesc, int std);
7373
void emit_fl(void); /* dpm_out.c */
7474
void init_sdsc_from_dtype(int sptr, DTYPE, int before_std); /* dpm_out.c */
75+
void make_temp_descriptor(int, int, int); /* dpm_out.c */
7576
int init_sdsc(int sptr, DTYPE dtype, int before_std, int parent_sptr); /* semutil2.c */
7677
void ipa_restore_dtb(char *line); /* dpm_out.c */
7778
void transform_call(int, int);

tools/flang1/flang1exe/outconv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ _ptrassign(int astx)
23872387
_ptrassign_copy(DESC_HDR_FLAGS, ptrsdx, tgtsdx, ptrsdtype);
23882388
_ptrassign_copy(DESC_HDR_LSIZE, ptrsdx, tgtsdx, ptrsdtype);
23892389
_ptrassign_copy(DESC_HDR_GSIZE, ptrsdx, tgtsdx, ptrsdtype);
2390-
if (ASSUMSHPG(tgtsptr)) {
2390+
if (ASSUMSHPG(tgtsptr) && !XBIT(58, 0x400000)) {
23912391
_ptrassign_set(DESC_HDR_LBASE, ptrsdx, 1, ptrsdtype);
23922392
} else {
23932393
_ptrassign_copy(DESC_HDR_LBASE, ptrsdx, tgtsdx, ptrsdtype);
@@ -2402,7 +2402,7 @@ _ptrassign(int astx)
24022402
rank = ADD_NUMDIM(DTYPEG(ptrsptr));
24032403
for (i = 0; i < rank; ++i) {
24042404
int lb;
2405-
if (!ASSUMSHPG(tgtsptr)) {
2405+
if (!ASSUMSHPG(tgtsptr) || XBIT(58, 0x400000)) {
24062406
_ptrassign_copy(get_global_lower_index(i), ptrsdx, tgtsdx, ptrsdtype);
24072407
} else {
24082408
/* for assumed-shape arguments, use the declared bounds */
@@ -2413,7 +2413,7 @@ _ptrassign(int astx)
24132413
_ptrassign_set(get_section_stride_index(i), ptrsdx, 0, ptrsdtype);
24142414
_ptrassign_set(get_section_offset_index(i), ptrsdx, 0, ptrsdtype);
24152415
_ptrassign_copy(get_multiplier_index(i), ptrsdx, tgtsdx, ptrsdtype);
2416-
if (ASSUMSHPG(tgtsptr)) {
2416+
if (ASSUMSHPG(tgtsptr) && !XBIT(58, 0x400000)) {
24172417
/* adjust the LBASE */
24182418
int a;
24192419
a = mk_binop(OP_MUL,

tools/flang1/flang1exe/rest.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ transform_call(int std, int ast)
18761876
break;
18771877
}
18781878
}
1879+
18791880
if (is_ent &&
18801881
(
18811882
#if DEBUG
@@ -1975,6 +1976,46 @@ transform_call(int std, int ast)
19751976
DESCUSEDP(sptr, 1);
19761977
NODESCP(sptr, 0);
19771978

1979+
/* Fix for assumed-shape arrays arguments where callee has the
1980+
* argument marked as target (originally discovered at customer).
1981+
* In this case the whole array is sent, but the callee code
1982+
* still needs to use the address calculation method such that
1983+
* the lower bound is folded into the lbase field of the descriptor
1984+
* to make zero-based offsets work (so-called; in practice
1985+
* usually 1-based with Fortran).
1986+
* [see exp_ftn.c: compute_sdsc_subscr() & add_ptr_subscript()]
1987+
*
1988+
* Since a new section descriptor has not been generated in this
1989+
* case where we send the whole array as an argument we need to
1990+
* create a new, temporary, argument array descriptor which
1991+
* translates bounds to zero-based (per the Fortran standard with
1992+
* assumed-shape arguments) and adjusts the lbase field.
1993+
*
1994+
* NB: The new runtime routine, pgf90_tmp_desc(), used to create the
1995+
* argument desriptor is similar to a pointer assignment (which
1996+
* makes the ptr_assn() call), and which follows the same rules
1997+
* of zero-based array bounds and lbase calculation. Also, this type
1998+
* of lbase fixup can also be found in runtime routines like
1999+
* ptr_fix_assumeshp(), where a whole array, instead of a section,
2000+
* is identified.
2001+
*/
2002+
if(XBIT(58,0x400000)&&ASSUMSHPG(inface_arg)&&TARGETG(inface_arg))
2003+
{
2004+
char nd[50]; /* new, substitute, descriptor for this arg */
2005+
static int ndctr = 0;
2006+
DTYPE dtype = DTYPEG(sptr);
2007+
SPTR sptrtmp, sptrdesc;
2008+
sprintf(nd, "ndesc%d_%d", A_SPTRG(ele), ndctr++);
2009+
sptrtmp = sym_get_array(nd, "", DDTG(dtype),
2010+
SHD_NDIM(A_SHAPEG(ele)));
2011+
get_static_descriptor(sptrtmp); /* add sdsc to sptrtmp; necessary */
2012+
get_all_descriptors(sptrtmp); /* add desc & bounds in dtype */
2013+
/* generate the runtime call pgf90_tmp_desc) */
2014+
make_temp_descriptor(sptr, sptrtmp, std);
2015+
sptrdesc = DESCRG(sptrtmp);
2016+
ARGT_ARG(newargt, newj) = check_member(ele, mk_id(sptrdesc));
2017+
}
2018+
else
19782019
ARGT_ARG(newargt, newj) = descr;
19792020
++newj;
19802021
s = memsym_of_ast(descr);
@@ -2027,6 +2068,35 @@ transform_call(int std, int ast)
20272068
++newi;
20282069
if (needdescr) {
20292070
int s;
2071+
/* situation where we are sending the whole array using
2072+
* subscript notation, e.g. x(:,:), but semantically
2073+
* equivalent to the above A_ID case of 'x'. We know that
2074+
* the whole array is being passed when the descriptor
2075+
* generated from the call to transform_section_arg()
2076+
* above (descr) is unchanged from the sptr descriptor.
2077+
*/
2078+
if(XBIT(58,0x400000) && ASSUMSHPG(inface_arg) &&
2079+
TARGETG(inface_arg) && A_SPTRG(descr) &&
2080+
(DESCRG(sptr) == A_SPTRG(descr)) )
2081+
{
2082+
char nsd[50]; /* new, substitute, descriptor for this arg */
2083+
static int nsdctr = 0;
2084+
DTYPE dtype = DTYPEG(sptr);
2085+
SPTR sptrtmp, sptrdesc;
2086+
/* In this case ele is an A_SUBSCR, so need to use its A_LOP */
2087+
int lop_ele = A_LOPG(ele);
2088+
2089+
sprintf(nsd, "n2desc%d_%d", A_SPTRG(lop_ele), nsdctr++);
2090+
sptrtmp = sym_get_array(nsd, "", DDTG(dtype),
2091+
SHD_NDIM(A_SHAPEG(lop_ele)));
2092+
get_static_descriptor(sptrtmp); /* add sdsc to sptrtmp; necessary */
2093+
get_all_descriptors(sptrtmp); /* add desc & bounds in dtype */
2094+
/* generate the runtime call pgf90_tmp_desc) */
2095+
make_temp_descriptor(sptr, sptrtmp, std);
2096+
sptrdesc = DESCRG(sptrtmp);
2097+
ARGT_ARG(newargt, newj) = check_member(lop_ele, mk_id(sptrdesc));
2098+
}
2099+
else
20302100
ARGT_ARG(newargt, newj) = descr;
20312101
++newj;
20322102
s = memsym_of_ast(descr);
@@ -2400,10 +2470,12 @@ handle_seq_section(int entry, int arr, int loc, int std, int *retval,
24002470
if (!arrayalign)
24012471
is_seq_pointer = TRUE;
24022472
}
2473+
if (TARGETG(arraysptr) && XBIT(58,0x400000))
2474+
is_seq_pointer = TRUE;
24032475
/* for F90, an assumed-shape dummy array looks like
24042476
* a sequential pointer, if copy-ins are removed */
24052477
if (XBIT(57, 0x10000) && ASSUMSHPG(arraysptr) && SDSCS1G(arraysptr) &&
2406-
!XBIT(54, 2) && !(XBIT(58, 0x400000) && TARGETG(arraysptr)))
2478+
!XBIT(54, 2))
24072479
is_seq_pointer = TRUE;
24082480
break;
24092481
case A_SUBSCR:
@@ -3680,7 +3752,7 @@ stride_1_section(int entry, int arr_ast, int pos, int std)
36803752
return FALSE; /* leftmost triplet is not stride 1 */
36813753
}
36823754
sptr = memsym_of_ast(arr_ast);
3683-
if (POINTERG(sptr)) {
3755+
if (POINTERG(sptr) || (TARGETG(sptr) && XBIT(58,0x400000))) {
36843756
/*
36853757
* Is this a stride-1 pointer array section? If the corresponding
36863758
* dummy is assumed-shape, we cannot omit the copy arg calls. The

0 commit comments

Comments
 (0)