Skip to content

Commit 58d1a06

Browse files
authored
Merge pull request #112 from ThePortlandGroup/nv_stage
Pull 2017-06-27T16-27 Recent NVIDIA Changes
2 parents 9b6ac08 + cf5414d commit 58d1a06

File tree

12 files changed

+210
-112
lines changed

12 files changed

+210
-112
lines changed

tools/flang1/flang1exe/dtypeutl.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,15 +3866,21 @@ array_element_dtype(DTYPE dtype)
38663866
LOGICAL
38673867
is_dtype_runtime_length_char(DTYPE dtype)
38683868
{
3869-
switch (dtype) {
3870-
case DT_ASSCHAR:
3871-
case DT_DEFERCHAR:
3872-
case DT_ASSNCHAR:
3873-
case DT_DEFERNCHAR:
3874-
return TRUE;
3875-
default:
3876-
return FALSE;
3877-
}
3869+
if (is_array_dtype(dtype))
3870+
dtype = array_element_dtype(dtype);
3871+
return dtype > DT_NONE &&
3872+
DT_ISCHAR(dtype) &&
3873+
string_length(dtype) == 0;
3874+
}
3875+
3876+
LOGICAL
3877+
is_dtype_unlimited_polymorphic(DTYPE dtype)
3878+
{
3879+
if (is_array_dtype(dtype))
3880+
dtype = array_element_dtype(dtype);
3881+
return dtype > DT_NONE &&
3882+
DTY(dtype) == TY_DERIVED &&
3883+
UNLPOLYG(DTY(dtype + 3 /*tag*/));
38783884
}
38793885

38803886
/** \brief Test if a data type index corresponds with a procedure pointer
@@ -4012,3 +4018,20 @@ is_unresolved_parameterized_dtype(DTYPE dtype)
40124018
}
40134019
return FALSE;
40144020
}
4021+
4022+
/* Correct TYPE IS(CHARACTER(LEN=*)) to TYPE IS(CHARACTER(LEN=:))
4023+
* so that semant3 can create a pointer or allocatable for construct
4024+
* association.
4025+
*/
4026+
DTYPE
4027+
change_assumed_char_to_deferred(DTYPE dtype)
4028+
{
4029+
switch (dtype) {
4030+
case DT_ASSCHAR:
4031+
return DT_DEFERCHAR;
4032+
case DT_ASSNCHAR:
4033+
return DT_DEFERNCHAR;
4034+
default:
4035+
return dtype;
4036+
}
4037+
}

tools/flang1/flang1exe/dtypeutl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ DTYPE get_iso_c_ptr(void);
9898
LOGICAL is_array_dtype(DTYPE dtype);
9999
DTYPE array_element_dtype(DTYPE dtype);
100100
LOGICAL is_dtype_runtime_length_char(DTYPE dtype);
101+
LOGICAL is_dtype_unlimited_polymorphic(DTYPE dtype);
101102
LOGICAL is_procedure_ptr_dtype(DTYPE dtype);
102103
DTYPE proc_ptr_result_dtype(DTYPE dtype);
103104
void set_proc_ptr_result_dtype(DTYPE ptr_dtype, DTYPE result_dtype);
@@ -109,3 +110,4 @@ SPTR get_struct_tag_sptr(DTYPE dtype);
109110
SPTR get_struct_members(DTYPE dtype);
110111
SPTR get_struct_initialization_tree(DTYPE dtype);
111112
LOGICAL is_unresolved_parameterized_dtype(DTYPE dtype);
113+
DTYPE change_assumed_char_to_deferred(DTYPE);

tools/flang1/flang1exe/func.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ check_pointer_type(int past, int tast, int stmt, LOGICAL is_sourced_allocation)
14921492

14931493
if (!is_sourced_allocation && POINTERG(psptr) && UNLPOLYG(DTY(dt1 + 3)) &&
14941494
UNLPOLYG(DTY(dt2 + 3)) && SDSCG(psptr) && SDSCG(tsptr)) {
1495-
/* init unlimited polymorophic descriptor for pointer.
1495+
/* init unlimited polymorphic descriptor for pointer.
14961496
* We do not have to do this for the sourced allocation case since
14971497
* the sourced allocation case is handled in semant3.c with the
14981498
* ALLOCATE productions.
@@ -1511,12 +1511,7 @@ check_pointer_type(int past, int tast, int stmt, LOGICAL is_sourced_allocation)
15111511
tsdsc = SDSCG(tsptr);
15121512
}
15131513
assert(tsdsc > NOSYM, "no descriptor for tsptr", tsptr, 3);
1514-
if (XBIT(68, 0x1)) {
1515-
fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
1516-
1517-
} else
1518-
fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
1519-
1514+
fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
15201515
dest_sdsc_ast = check_member(past, mk_id(psdsc));
15211516
src_sdsc_ast = check_member(tast, mk_id(tsdsc));
15221517

@@ -1685,8 +1680,8 @@ check_alloc_ptr_type(int psptr, int stmt, DTYPE dt1, int flag, LOGICAL after,
16851680
}
16861681
stmt = gen_set_type(desc1_ast, type2_ast, stmt, !after, intrin_type);
16871682
if (no_alloc_ptr) {
1688-
int astnew = mk_assn_stmt(tagdesc, mk_isz_cval((intrin_type) ?
1689-
__TAGPOLY : __TAGDESC, DT_INT), 0);
1683+
int tag = mk_isz_cval(intrin_type ? __TAGPOLY : __TAGDESC, DT_INT);
1684+
int astnew = mk_assn_stmt(tagdesc, tag, 0);
16901685
stmt = add_stmt_before(astnew, stmt);
16911686
}
16921687
}

tools/flang1/flang1exe/rest.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ transform_call(int std, int ast)
14861486
*/
14871487
/* Also execute this code if the interface arg
14881488
* does not need a descriptor, but the actual arg is
1489-
* allocatable. That way, the type gets added the actual's
1489+
* allocatable. That way, the type gets added to the actual's
14901490
* descriptor.
14911491
*/
14921492
if (!needdescr && !CLASSG(sptr) && DTY(DTYPEG(sptr)) == TY_DERIVED) {
@@ -1504,6 +1504,17 @@ transform_call(int std, int ast)
15041504
}
15051505
} else {
15061506
check_alloc_ptr_type(sptr, std, 0, unl_poly ? 2 : 1, 0, 0, 0);
1507+
if (unl_poly) {
1508+
int descr_length_ast =
1509+
symbol_descriptor_length_ast(sptr, 0 /*no AST*/);
1510+
if (descr_length_ast > 0) {
1511+
int length_ast = get_value_length_ast(DT_NONE, 0, sptr,
1512+
DTYPEG(sptr), 0);
1513+
if (length_ast > 0)
1514+
add_stmt_before(mk_assn_stmt(descr_length_ast, length_ast,
1515+
astb.bnd.dtype), std);
1516+
}
1517+
}
15071518
}
15081519
}
15091520
dty = DTYPEG(sptr);

tools/flang1/flang1exe/rte.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ extern int get_byte_len_indx(void);
198198
extern void set_descriptor_sc(int sc);
199199
extern int get_desc_rank(int);
200200
extern int get_kind(int);
201-
extern int get_byte_len(int);
202201
extern int get_gbase(int);
203202
extern int get_gbase2(int);
204203
extern int get_desc_tag(int);

tools/flang1/flang1exe/semant3.c

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5513,20 +5513,14 @@ convert_to_block_forall(int old_forall_ast)
55135513
static void
55145514
gen_init_unl_poly_desc(int dest_sdsc_ast, int src_sdsc_ast)
55155515
{
5516-
int fsptr, argt, val, ast;
5517-
if (XBIT(68, 0x1)) {
5518-
fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
5519-
5520-
} else
5521-
fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
5522-
5523-
argt = mk_argt(3);
5516+
int fsptr = sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_unl_poly_desc), DT_NONE);
5517+
int argt = mk_argt(3);
5518+
int val = mk_cval1(43, DT_INT);
5519+
int ast = mk_id(fsptr);
55245520
ARGT_ARG(argt, 0) = dest_sdsc_ast;
55255521
ARGT_ARG(argt, 1) = src_sdsc_ast;
5526-
val = mk_cval1(43, DT_INT);
55275522
val = mk_unop(OP_VAL, val, DT_INT);
55285523
ARGT_ARG(argt, 2) = val;
5529-
ast = mk_id(fsptr);
55305524
ast = mk_func_node(A_CALL, ast, 3, argt);
55315525
add_stmt(ast);
55325526
}
@@ -5665,15 +5659,6 @@ is_associatable_variable_sst(SST *rhs)
56655659
return FALSE;
56665660
}
56675661

5668-
/* Build an AST that references the byte length field in a descriptor.
5669-
*/
5670-
static int
5671-
get_descriptor_length_ast(int descriptor_ast)
5672-
{
5673-
int subs = mk_isz_cval(get_byte_len_indx(), astb.bnd.dtype);
5674-
return mk_subscr(descriptor_ast, &subs, 1, astb.bnd.dtype);
5675-
}
5676-
56775662
/* Implement an association for one of these constructs:
56785663
*
56795664
* ASSOCIATE(a => variable)
@@ -5712,6 +5697,7 @@ construct_association(int lhs_sptr, SST *rhs, int stmt_dtype, LOGICAL is_class)
57125697
LOGICAL is_lhs_unl_poly;
57135698
int rhs_descriptor_ast = 0;
57145699
LOGICAL does_lhs_need_runtime_type;
5700+
int lhs_length_ast;
57155701

57165702
if (!(rhs_ast = SST_ASTG(rhs))) {
57175703
mkexpr(rhs);
@@ -5727,16 +5713,19 @@ construct_association(int lhs_sptr, SST *rhs, int stmt_dtype, LOGICAL is_class)
57275713
}
57285714

57295715
lhs_dtype = stmt_dtype > 0 ? stmt_dtype : rhs_dtype;
5730-
lhs_element_dtype = lhs_dtype;
57315716
if (is_array_dtype(lhs_dtype)) {
57325717
int rank = get_ast_rank(rhs_ast);
57335718
is_array = rank > 0;
57345719
if (is_array) {
5735-
lhs_element_dtype = DTY(lhs_dtype + 1);
5720+
lhs_element_dtype = array_element_dtype(lhs_dtype);
5721+
lhs_element_dtype = change_assumed_char_to_deferred(lhs_element_dtype);
57365722
lhs_dtype = get_array_dtype(rank, lhs_element_dtype);
57375723
ADD_DEFER(lhs_dtype) = TRUE;
57385724
ADD_NOBOUNDS(lhs_dtype) = TRUE;
57395725
}
5726+
} else {
5727+
lhs_dtype = change_assumed_char_to_deferred(lhs_dtype);
5728+
lhs_element_dtype = lhs_dtype;
57405729
}
57415730
is_lhs_runtime_length_char = is_dtype_runtime_length_char(lhs_dtype);
57425731

@@ -5875,7 +5864,8 @@ construct_association(int lhs_sptr, SST *rhs, int stmt_dtype, LOGICAL is_class)
58755864
}
58765865

58775866
/* For TYPE IS statements with intrinsic types, set the LHS type
5878-
* directly. */
5867+
* directly.
5868+
*/
58795869
if (SDSCG(lhs_sptr) > NOSYM && stmt_dtype && !is_class &&
58805870
DTY(lhs_element_dtype) != TY_DERIVED) {
58815871
int args = mk_argt(2);
@@ -5888,30 +5878,17 @@ construct_association(int lhs_sptr, SST *rhs, int stmt_dtype, LOGICAL is_class)
58885878
/* Generate code to initialize, when necessary, the byte length field
58895879
* in the left-hand side's descriptor, if it exists.
58905880
*/
5891-
if (SDSCG(lhs_sptr) > NOSYM) {
5892-
int dest_len_ast = 0;
5893-
if (is_lhs_runtime_length_char) {
5894-
dest_len_ast = get_byte_len(SDSCG(lhs_sptr));
5895-
} else if (is_lhs_unl_poly || is_array) {
5896-
dest_len_ast = get_descriptor_length_ast(mk_id(SDSCG(lhs_sptr)));
5897-
}
5898-
if (dest_len_ast) {
5899-
int len_ast = 0;
5900-
if (is_dtype_runtime_length_char(rhs_dtype)) {
5901-
len_ast = string_expr_length(rhs_ast);
5902-
} else if (stmt_dtype && !is_class /* TYPE IS(stmt_dtype) */ &&
5903-
!is_lhs_runtime_length_char) {
5904-
len_ast = size_ast(lhs_sptr, lhs_element_dtype);
5905-
} else if (rhs_descriptor_ast &&
5906-
is_array_dtype(A_DTYPEG(rhs_descriptor_ast))) {
5907-
len_ast = get_descriptor_length_ast(rhs_descriptor_ast);
5908-
}
5909-
if (len_ast) {
5910-
int assignment_ast =
5911-
mk_assn_stmt(dest_len_ast, len_ast, astb.bnd.dtype);
5912-
add_stmt(assignment_ast);
5913-
}
5914-
}
5881+
lhs_length_ast = symbol_descriptor_length_ast(lhs_sptr, 0 /*no AST*/);
5882+
if (lhs_length_ast > 0) {
5883+
SPTR size_sptr = stmt_dtype > DT_NONE &&
5884+
!is_class /* TYPE IS */ &&
5885+
!is_lhs_runtime_length_char ? lhs_sptr
5886+
: NOSYM;
5887+
int rhs_length_ast = get_value_length_ast(rhs_dtype, rhs_ast, size_sptr,
5888+
lhs_element_dtype,
5889+
rhs_descriptor_ast);
5890+
if (rhs_length_ast > 0)
5891+
add_stmt(mk_assn_stmt(lhs_length_ast, rhs_length_ast, astb.bnd.dtype));
59155892
}
59165893

59175894
return lhs_sptr;

tools/flang1/flang1exe/semfin.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,19 @@ add_class_arg_descr_arg(int func_sptr, int arg_sptr, int new_arg_position)
266266
/* add type descriptor argument */
267267
static int tmp = 0;
268268
int new_arg_sptr = getccsym_sc('O', tmp++, ST_VAR, SC_DUMMY);
269+
DTYPE dtype = get_array_dtype(1, astb.bnd.dtype);
270+
ADD_LWBD(dtype, 0) = 0;
271+
ADD_LWAST(dtype, 0) = astb.bnd.one;
272+
ADD_NUMELM(dtype) = ADD_UPBD(dtype, 0) = ADD_UPAST(dtype, 0) =
273+
mk_isz_cval(get_descriptor_len(0), astb.bnd.dtype);
269274
CLASSP(new_arg_sptr, 1);
270-
DTYPEP(new_arg_sptr, stb.user.dt_int);
275+
DTYPEP(new_arg_sptr, dtype);
271276
inject_arg(func_sptr, new_arg_sptr, new_arg_position);
272277
PARENTP(arg_sptr, new_arg_sptr);
273278
/*OPTARGP(new_arg_sptr, TRUE);*/ /* FS#17571 */
274279
return TRUE;
275-
} else if (!SDSCG(arg_sptr)) {
280+
}
281+
if (!SDSCG(arg_sptr)) {
276282
/* FS#19541 - create normal descr dummy now */
277283
int descr_sptr = sym_get_arg_sec(arg_sptr);
278284
SDSCP(arg_sptr, descr_sptr);

tools/flang1/flang1exe/semutil.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,8 +3785,9 @@ add_ptr_assign(int dest, int src, int std)
37853785
DTYPEP(memsym_of_ast(dest), dtype);
37863786
}
37873787

3788-
if (dtype == DT_DEFERCHAR || dtype == DT_DEFERNCHAR ||
3789-
(UNLPOLYG(tag) && DTY(A_DTYPEG(src)) == TY_CHAR)) {
3788+
if ((dtype == DT_DEFERCHAR || dtype == DT_DEFERNCHAR ||
3789+
(UNLPOLYG(tag) && DTY(A_DTYPEG(src)) == TY_CHAR)) &&
3790+
!is_dtype_unlimited_polymorphic(A_DTYPEG(src))) {
37903791
int dest_len_ast = get_len_of_deferchar_ast(dest);
37913792
int src_len_ast, cvlen;
37923793
if (A_TYPEG(src) == A_INTR && A_OPTYPEG(src) == I_NULL)

tools/flang1/flang1exe/semutil2.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10900,7 +10900,7 @@ get_dtype_init_template(DTYPE dtype)
1090010900
SPTR tag_sptr = get_struct_tag_sptr(element_dtype);
1090110901
int init_ict = get_struct_initialization_tree(element_dtype);
1090210902
ACL *aclp, *tmpl_aclp;
10903-
SPTR sptr;
10903+
SPTR sptr = NOSYM;
1090410904
char namebuf[128];
1090510905
int sc = SC_STATIC;
1090610906
const char prefix[] = "_dtInit";
@@ -10909,9 +10909,11 @@ get_dtype_init_template(DTYPE dtype)
1090910909
"get_dtype_init_template: element dtype not derived",
1091010910
dtype, ERR_Fatal);
1091110911
aclp = get_getitem_p(init_ict);
10912-
assert(eq_dtype(DDTG(aclp->dtype), element_dtype),
10913-
"get_dtype_init_template: element dtype mismatch",
10914-
dtype, ERR_Fatal);
10912+
if (aclp) {
10913+
assert(eq_dtype(DDTG(aclp->dtype), element_dtype),
10914+
"get_dtype_init_template: element dtype mismatch",
10915+
dtype, ERR_Fatal);
10916+
}
1091510917

1091610918
if (is_unresolved_parameterized_dtype(element_dtype))
1091710919
return NOSYM;
@@ -10928,21 +10930,23 @@ get_dtype_init_template(DTYPE dtype)
1092810930
namebuf[sizeof namebuf - 1] = '\0'; /* Windows snprintf bug workaround */
1092910931

1093010932
/* no existing initialization template yet for this derived type; build one */
10931-
if (sc == SC_EXTERN) {
10932-
sptr = mk_external_var(namebuf, element_dtype);
10933-
} else {
10934-
sptr = getccssym_sc(prefix, (int) element_dtype, ST_VAR, sc);
10935-
DTYPEP(sptr, element_dtype);
10936-
}
10937-
DCLDP(sptr, TRUE);
10938-
INITIALIZERP(sptr, TRUE);
10939-
10940-
tmpl_aclp = GET_ACL(15);
10941-
*tmpl_aclp = *aclp;
10942-
tmpl_aclp->sptr = sptr;
10943-
dinit((VAR *)NULL, tmpl_aclp);
10944-
if (tag_sptr > NOSYM)
10945-
TYPDEF_INITP(tag_sptr, sptr);
10933+
if (aclp) {
10934+
if (sc == SC_EXTERN) {
10935+
sptr = mk_external_var(namebuf, element_dtype);
10936+
} else {
10937+
sptr = getccssym_sc(prefix, (int) element_dtype, ST_VAR, sc);
10938+
DTYPEP(sptr, element_dtype);
10939+
}
10940+
DCLDP(sptr, TRUE);
10941+
INITIALIZERP(sptr, TRUE);
10942+
10943+
tmpl_aclp = GET_ACL(15);
10944+
*tmpl_aclp = *aclp;
10945+
tmpl_aclp->sptr = sptr;
10946+
dinit((VAR *)NULL, tmpl_aclp);
10947+
if (tag_sptr > NOSYM)
10948+
TYPDEF_INITP(tag_sptr, sptr);
10949+
}
1094610950
return sptr;
1094710951
}
1094810952

0 commit comments

Comments
 (0)