diff --git a/include/flang/Error/errmsg-common.n b/include/flang/Error/errmsg-common.n index 0b1ee1d1692..d5bb8b55edb 100644 --- a/include/flang/Error/errmsg-common.n +++ b/include/flang/Error/errmsg-common.n @@ -1,5 +1,5 @@ .\"/* -.\" * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +.\" * Copyright (c) 2010-2018, NVIDIA CORPORATION. All rights reserved. .\" * .\" * Licensed under the Apache License, Version 2.0 (the "License"); .\" * you may not use this file except in compliance with the License. @@ -26,3 +26,5 @@ You may specify a directory to use for temporary files with the TMPDIR environme .MS F 703 "only the last -preinclude switch is processed" We have one spot for the preinclude file in the gbl. structure. This is not a user visible switch. +.MS F 704 "Compilation aborted due to previous errors." +Compilation will abort immediately in case of Severe or Fatal error. diff --git a/runtime/flang/type.c b/runtime/flang/type.c index c1e53b6b5e5..83bc1f130f1 100644 --- a/runtime/flang/type.c +++ b/runtime/flang/type.c @@ -1406,7 +1406,9 @@ void ENTF90(INIT_UNL_POLY_DESC, init_unl_poly_desc)(F90_Desc *dd, F90_Desc *sd, } } -void ENTF90(INIT_FROM_DESC, init_from_desc)(void *object, const F90_Desc *desc) +void ENTF90(INIT_FROM_DESC, init_from_desc)(void *object, + const F90_Desc *desc, + int rank) { if (object && desc) { @@ -1414,13 +1416,13 @@ void ENTF90(INIT_FROM_DESC, init_from_desc)(void *object, const F90_Desc *desc) size_t items = 1; size_t index[MAXDIMS]; TYPE_DESC *type_desc = obj_desc->type; - int rank = 0; int j; size_t element_bytes = 0; void *prototype = NULL; if (desc->tag == __DESC) { - rank = desc->rank; + if (desc->rank < rank) + rank = desc->rank; if (rank > 0) { items = desc->lsize; for (j = 0; j < rank; ++j) { diff --git a/tools/flang1/flang1exe/func.c b/tools/flang1/flang1exe/func.c index d99ea7b9d0a..2b23f186316 100644 --- a/tools/flang1/flang1exe/func.c +++ b/tools/flang1/flang1exe/func.c @@ -2658,24 +2658,9 @@ rewrite_func_ast(int func_ast, int func_args, int lhs) rtlRtn = DTY(A_DTYPEG(arg1)) == TY_CHAR ? RTE_date : RTE_datew; goto sub_common; case I_IDATE: - { - TY_KIND arg_ty = TY_NONE; /* args must all be short or int */ - for (i = 0; i < nargs; ++i) { - int arg_ast = ARGT_ARG(func_args, i); - TY_KIND ty = DTY(A_DTYPEG(arg_ast)); - if (i == 0) { - arg_ty = ty; - } else { - assert(arg_ty == ty, - "rewrite_func_ast:idate called with bad arguments", 0, - ERR_Fatal); - } - } - assert(arg_ty == TY_SINT || arg_ty == TY_INT, - "rewrite_func_ast:idate called with bad arguments", 0, ERR_Fatal); - rtlRtn = arg_ty == TY_SINT ? RTE_idate : RTE_jdate; - } is_icall = FALSE; + arg1 = ARGT_ARG(func_args, 0); + rtlRtn = DTY(A_DTYPEG(arg1)) == TY_SINT ? RTE_idate : RTE_jdate; goto sub_common; case I_LASTVAL: rtlRtn = RTE_lastval; diff --git a/tools/flang1/flang1exe/rest.c b/tools/flang1/flang1exe/rest.c index ce03481d805..73564c4cd40 100644 --- a/tools/flang1/flang1exe/rest.c +++ b/tools/flang1/flang1exe/rest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 1994-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1753,6 +1753,17 @@ transform_call(int std, int ast) DESCUSEDP(sptr, 1); NODESCP(sptr, 0); ++newj; + } else if (needdescr) { + int sptrsdsc; + sptr = memsym_of_ast(ele); + get_static_descriptor(sptr); + + sptrsdsc = get_member_descriptor(sptr); + if (sptrsdsc <= NOSYM) { + sptrsdsc = SDSCG(sptr); + } + ARGT_ARG(newargt, newj) = check_member(ele, mk_id(sptrsdsc)); + ++newj; } else { ty = dtype_to_arg(A_DTYPEG(ele)); ARGT_ARG(newargt, newj) = pghpf_type(ty); @@ -2228,7 +2239,7 @@ handle_seq_section(int entry, int arr, int loc, int std, int *retval, topdtype = DTY(topdtype + 1); if (simplewholearray && CONTIGATTRG(arraysptr)) { - *retval = first_element(arr); + *retval = arr; *descr = DESCRG(arraysptr) > NOSYM ? check_member(arrayast, mk_id(DESCRG(arraysptr))) : 0; return; diff --git a/tools/flang1/flang1exe/semant.c b/tools/flang1/flang1exe/semant.c index c5b881d4d91..6c32271839c 100644 --- a/tools/flang1/flang1exe/semant.c +++ b/tools/flang1/flang1exe/semant.c @@ -7570,16 +7570,17 @@ semant1(int rednum, SST *top) * ::= ( ) | */ case BIND_ATTR1: - /* see also FUNC_SUFFIX2 for a copy of this processing */ - np = scn.id.name + SST_CVALG(RHS(2)); + /* see also FUNC_SUFFIX2 for a copy of this processing */ bind_attr.exist = -1; bind_attr.altname = 0; - if (sem_strcmp(np, "c") == 0) { - bind_attr.exist = DA_B(DA_C); - } else + np = scn.id.name + SST_CVALG(RHS(2)); + if (sem_strcmp(np, "c") != 0) { error(4, 3, gbl.lineno, "Illegal BIND -", np); + } else { + bind_attr.exist = DA_B(DA_C); + } break; /* @@ -7593,17 +7594,15 @@ semant1(int rednum, SST *top) bind_attr.exist = -1; bind_attr.altname = 0; + np = scn.id.name + SST_CVALG(RHS(2)); if (sem_strcmp(np, "c") != 0) { error(4, 3, gbl.lineno, "Illegal BIND -", np); } else { - bind_attr.exist = DA_B(DA_C); - np = stb.n_base + CONVAL1G(SST_SYMG(RHS(6))); - if (*np) { - bind_attr.exist |= DA_B(DA_ALIAS); - bind_attr.altname = SST_SYMG(RHS(6)); - } + bind_attr.exist = DA_B(DA_C) | DA_B(DA_ALIAS); + bind_attr.altname = SST_SYMG(RHS(6)); // altname may be "" } + break; /* ------------------------------------------------------------------ */ @@ -12969,6 +12968,7 @@ process_bind(int sptr) int b_type; int b_bitv; int need_altname = 0; + char *np; char *w32_name; int wsptr; @@ -12991,6 +12991,11 @@ process_bind(int sptr) switch (b_type) { case DA_ALIAS: + /* An altname can't be empty. Exit early to use a "normal" mangled + * variant of the primary symbol name. */ + np = stb.n_base + CONVAL1G(bind_attr.altname); + if (!*np) + return; #if defined(TARGET_OSX) /* Win32 and OSX needs altname with underbar for bind only, to match C routines. Do not depend on processing in @@ -12999,7 +13004,7 @@ process_bind(int sptr) */ w32_name = (char *)getitem(0, strlen(SYMNAME(bind_attr.altname)) + 1); w32_name[0] = '_'; - strcpy(&(w32_name[1]), stb.n_base + CONVAL1G(bind_attr.altname)); + strcpy(&(w32_name[1]), np); wsptr = getstring(w32_name, strlen(w32_name)); ALTNAMEP(sptr, wsptr); diff --git a/tools/flang1/flang1exe/semfin.c b/tools/flang1/flang1exe/semfin.c index ffd77a1e06a..a0c497bca42 100644 --- a/tools/flang1/flang1exe/semfin.c +++ b/tools/flang1/flang1exe/semfin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994-2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 1994-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -3549,10 +3549,12 @@ init_derived_type(SPTR sptr, int parent_ast, int wherestd) if (descr_ast > 0) { int func_ast = mk_id(sym_mkfunc_nodesc(mkRteRtnNm(RTE_init_from_desc), DT_NONE)); - int argt = mk_argt(2); - new_ast = mk_func_node(A_CALL, func_ast, 2, argt); + int argt = mk_argt(3); + new_ast = mk_func_node(A_CALL, func_ast, 3, argt); ARGT_ARG(argt, 0) = mk_id(sptr); ARGT_ARG(argt, 1) = descr_ast; + ARGT_ARG(argt, 2) = + mk_unop(OP_VAL, mk_cval(rank_of_sym(sptr), DT_INT4), DT_INT4); } } diff --git a/tools/flang1/flang1exe/semsmp.c b/tools/flang1/flang1exe/semsmp.c index 28fe9e30d46..f1edd36ca43 100644 --- a/tools/flang1/flang1exe/semsmp.c +++ b/tools/flang1/flang1exe/semsmp.c @@ -9486,18 +9486,23 @@ parref_bnd(int ast, int stblk) void set_parref_flag(int sptr, int psptr, int stblk) { - - if (SCG(sptr) && SCG(sptr) == SC_CMBLK) + if (!SCG(sptr)) return; - if (SCG(sptr) && SCG(sptr) == SC_STATIC) + if (STYPEG(sptr) == ST_MEMBER) return; - if (DINITG(sptr) || SAVEG(sptr)) /* save variable can be threadprivate */ + if (SCG(sptr) == SC_CMBLK || SCG(sptr) == SC_STATIC) return; if (SCG(sptr) == SC_EXTERN && ST_ISVAR(sptr)) /* No global vars in uplevel */ return; - if (STYPEG(sptr) == ST_MEMBER) - return; - + if (DINITG(sptr) || SAVEG(sptr)) { + if (SCG(sptr) != SC_LOCAL) { + if (SCG(sptr) == SC_BASED) { + int sym = MIDNUMG(sptr); + if (SCG(sym) != SC_LOCAL) + return; + } + } + } if (!stblk) stblk = get_stblk_uplevel_sptr(); @@ -9549,16 +9554,23 @@ set_parref_flag2(int sptr, int psptr, int std) { int i, stblk, paramct, parsyms, ast, key; LLUplevel *up; - if (SCG(sptr) && SCG(sptr) == SC_CMBLK) + if (!SCG(sptr)) return; - if (SCG(sptr) && SCG(sptr) == SC_STATIC) + if (STYPEG(sptr) == ST_MEMBER) return; - if (DINITG(sptr) || SAVEG(sptr)) /* save variable can be threadprivate */ + if (SCG(sptr) == SC_CMBLK || SCG(sptr) == SC_STATIC) return; if (SCG(sptr) == SC_EXTERN && ST_ISVAR(sptr)) /* No global vars in uplevel */ return; - if (STYPEG(sptr) == ST_MEMBER) - return; + if (DINITG(sptr) || SAVEG(sptr)) { + if (SCG(sptr) != SC_LOCAL) { + if (SCG(sptr) == SC_BASED) { + int sym = MIDNUMG(sptr); + if (SCG(sym) != SC_LOCAL) + return; + } + } + } if (std) { /* use std to trace back to previous A_MP_BMPSCOPE */ int nested = 0; std = STD_PREV(std); diff --git a/tools/flang2/docs/xflag.n b/tools/flang2/docs/xflag.n index 9cc59ceb8f7..77c8dbd4e89 100644 --- a/tools/flang2/docs/xflag.n +++ b/tools/flang2/docs/xflag.n @@ -1284,7 +1284,7 @@ only removes 2% of the operations. .XB 0x40000000 Allow conditional vectorization containing reductions (experimental) .XB 0x80000000 -Enable LLVM vectorization containing SELECT (experimental) +Disable LLVM vectorization containing SELECT .XF "35:" Low-level vectorizer - maximum loop iteration count; 0 means diff --git a/tools/flang2/flang2exe/cgmain.c b/tools/flang2/flang2exe/cgmain.c index fffda71a6c9..fc48cbdbf97 100644 --- a/tools/flang2/flang2exe/cgmain.c +++ b/tools/flang2/flang2exe/cgmain.c @@ -2199,7 +2199,7 @@ locset_to_tbaa_info(LL_Module *module, LL_MDRef omniPtr, int ilix) int bsym, rv; const ILI_OP opc = ILI_OPC(ilix); const ILTY_KIND ty = IL_TYPE(opc); - const int nme = (ty == ILTY_LOAD) ? ILI_OPND(ilix, 2) : ILI_OPND(ilix, 3); + const int nme = ILI_OPND(ilix, (ty == ILTY_LOAD) ? 2 : 3); const int base = basenme_of(nme); if (!base) @@ -2213,10 +2213,11 @@ locset_to_tbaa_info(LL_Module *module, LL_MDRef omniPtr, int ilix) /* do nothing */ break; default: - return LL_MDREF_ctor(LL_MDREF_kind(module->unrefPtr), - LL_MDREF_value(module->unrefPtr)); + return module->unrefPtr; } + if (!strncmp(SYMNAME(bsym), "reshap$r", 8)) + return LL_MDREF_ctor(0, 0); if ((NME_SYM(nme) != bsym) && assumeWillAlias(nme)) return omniPtr; @@ -2295,7 +2296,7 @@ get_tbaa_metadata(LL_Module *module, int ilix, OPERAND *opnd, int isVol) cons_indirect: if (!myPtr) - return LL_MDREF_ctor(0, 0); + return myPtr; a[0] = a[1] = myPtr; a[2] = ll_get_md_i64(module, 0); @@ -3265,6 +3266,28 @@ ll_instr_flags_for_memory_order_and_scope(int ilix) return flags; } +/** + \brief Invalidate cached sincos intrinsics on write to input expression + */ +static bool +sincos_input_uses(int ilix, int nme) +{ + int i; + const ILI_OP opc = ILI_OPC(ilix); + const int noprs = ilis[opc].oprs; + const ILTY_KIND ilty = IL_TYPE(opc); + if (ilty == ILTY_LOAD) + return (ILI_OPND(ilix, 2) == nme); + for (i = 1; i <= noprs; ++i) { + if (IL_ISLINK(opc, i)) { + bool isUse = sincos_input_uses(ILI_OPND(ilix, i), nme); + if (isUse) + return true; + } + } + return false; +} + /** \brief Remove all loads that correspond to a given NME \param key an ILI value @@ -3278,7 +3301,8 @@ sincos_clear_arg_helper(hash_key_t key, hash_data_t data, void *context) const int seek_nme = ((int *)context)[1]; const int ilix = HKEY2INT(key); const int ilix_nme = ILI_OPND(ilix, 2); - if ((ilix == lhs_ili) || ((data == NULL) && (seek_nme == ilix_nme))) + if ((ilix == lhs_ili) || ((data == NULL) && (seek_nme == ilix_nme)) || + sincos_input_uses(ilix, seek_nme)) hashmap_erase(sincos_imap, key, NULL); } diff --git a/tools/flang2/flang2exe/exp_ftn.c b/tools/flang2/flang2exe/exp_ftn.c index 29e55c704e3..eb73dac448d 100644 --- a/tools/flang2/flang2exe/exp_ftn.c +++ b/tools/flang2/flang2exe/exp_ftn.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 1993-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1976,6 +1976,39 @@ add_ptr_subscript(int i, int sub, int ili1, int base, int basesym, int basenm, return ili1; } +static LOGICAL +is_currsub_dummy(int sdsc) +{ + +#ifdef KEEP_ARG_IN_MEM + return TRUE; +#endif + + if (SCG(sdsc) != SC_DUMMY) + return FALSE; + if (!flg.smp) { + if (CONTAINEDG(gbl.currsub)) { + if (INTERNREFG(sdsc)) { + return FALSE; + } + } + return TRUE; + } else if (TASKDUPG(gbl.currsub)) { + return FALSE; + } else if (!gbl.outlined) { + if (CONTAINEDG(gbl.currsub)) { + if (INTERNREFG(sdsc)) { + return FALSE; + } + } else + return TRUE; + } else { + return FALSE; + } + return TRUE; + +} + int get_sdsc_element(int sdsc, int indx, int membase, int membase_nme) { @@ -2035,9 +2068,8 @@ get_sdsc_element(int sdsc, int indx, int membase, int membase_nme) } else { acon = mk_address(sdsc); if (SCG(sdsc) == SC_DUMMY - && (!flg.smp || (flg.smp && is_llvm_local_private(sdsc))) && - !(gbl.internal > 1 && INTERNREFG(sdsc)) - ) { + && is_currsub_dummy(sdsc) + ) { int asym, anme; asym = mk_argasym(sdsc); anme = addnme(NT_VAR, asym, 0, (INT)0); diff --git a/tools/flang2/flang2exe/expsmp.c b/tools/flang2/flang2exe/expsmp.c index 32dc0babe7f..6af47f46dc3 100644 --- a/tools/flang2/flang2exe/expsmp.c +++ b/tools/flang2/flang2exe/expsmp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2015-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -907,7 +907,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm) iltb.callfg = 1; chk_block(ili); } - ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg); + ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP); iltb.callfg = 1; chk_block(ili); @@ -987,7 +987,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm) wr_block(); cr_block(); exp_label(par_label); - ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg); + ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP); iltb.callfg = 1; chk_block(ili); diff --git a/tools/flang2/flang2exe/iliutil.c b/tools/flang2/flang2exe/iliutil.c index 59fc83c2e57..3721d9e5599 100644 --- a/tools/flang2/flang2exe/iliutil.c +++ b/tools/flang2/flang2exe/iliutil.c @@ -12130,6 +12130,9 @@ mem_size(TY_KIND ty) case TY_FLOAT128: msz = MSZ_F16; break; + case TY_128: + msz = MSZ_F16; + break; default: msz = MSZ_UNDEF; } diff --git a/tools/flang2/flang2exe/kmpcutil.c b/tools/flang2/flang2exe/kmpcutil.c index 71931d31bec..d24e65c0543 100644 --- a/tools/flang2/flang2exe/kmpcutil.c +++ b/tools/flang2/flang2exe/kmpcutil.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -522,7 +522,7 @@ KMPC_GENERIC_P_2I(ll_make_kmpc_cancellationpoint, KMPC_API_CANCELLATIONPOINT, /* arglist is 1 containing the uplevel pointer */ int -ll_make_kmpc_fork_call(int sptr, int argc, int *arglist) +ll_make_kmpc_fork_call(int sptr, int argc, int *arglist, RegionType rt) { int argili, args[4], arg_types[] = {DT_CPTR, DT_INT, DT_CPTR, 0}; arg_types[3] = DT_CPTR; @@ -530,7 +530,7 @@ ll_make_kmpc_fork_call(int sptr, int argc, int *arglist) args[2] = ad_icon(argc); args[1] = ad1ili(IL_ACON, get_acon(sptr, 0)); args[0] = *arglist; - return mk_kmpc_api_call(KMPC_API_FORK_CALL, 4, arg_types, args); + return mk_kmpc_api_call(KMPC_API_FORK_CALL, 4, arg_types, args); } /* arglist is 1 containing the uplevel pointer */ diff --git a/tools/flang2/flang2exe/kmpcutil.h b/tools/flang2/flang2exe/kmpcutil.h index ea05521e8f0..43b76a26bb7 100644 --- a/tools/flang2/flang2exe/kmpcutil.h +++ b/tools/flang2/flang2exe/kmpcutil.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,6 +68,11 @@ typedef enum _kmpc_sched_e { KMP_SCH_DEFAULT = KMP_SCH_STATIC } kmpc_sched_e; +typedef enum RegionType { + OPENMP, + OPENACC +} RegionType; + /* Argument type used for handling for loops and scheduling. * All values here are sptrs. */ @@ -102,7 +107,7 @@ typedef struct any_kmpc_struct { extern int ll_make_kmpc_dispatch_next(int, int, int, int, int); extern int ll_make_kmpc_dispatch_init(const loop_args_t *); extern int ll_make_kmpc_dispatch_fini(int); -extern int ll_make_kmpc_fork_call(int, int, int *); +extern int ll_make_kmpc_fork_call(int, int, int *, RegionType); extern int ll_make_kmpc_for_static_init(const loop_args_t *); extern int ll_make_kmpc_for_static_init_args(int, int *); extern int ll_make_kmpc_barrier(void); diff --git a/tools/flang2/flang2exe/ll_ftn.c b/tools/flang2/flang2exe/ll_ftn.c index c8c2e3ba8c2..312846c228a 100644 --- a/tools/flang2/flang2exe/ll_ftn.c +++ b/tools/flang2/flang2exe/ll_ftn.c @@ -211,11 +211,12 @@ ll_process_routine_parameters(int func_sptr) STYPEG(func_sptr) == ST_ENTRY); if (gblsym && !update && is_llvmag_entry(gblsym)) return; - else if (!gblsym && iface) - gblsym = get_llvm_funcptr_ag(func_sptr, (char *)nm); // FIXME castaway - // const? - else if (!gblsym) - gblsym = get_ag(func_sptr); + + if (!gblsym) { + gblsym = iface + ? get_llvm_funcptr_ag(func_sptr, (char *)nm) // FIXME castaway const? + : get_ag(func_sptr); + } if (!update && (abi = ll_proto_get_abi(ll_proto_key(func_sptr))) && abi->nargs) @@ -234,11 +235,12 @@ ll_process_routine_parameters(int func_sptr) t_len = NULL; /* Store return type (if we are overriding get_return_dtype()) */ - if (gbl.arets) { + if (gbl.arets && (!CFUNCG(func_sptr))) { return_dtype = DT_INT; set_ag_return_lltype(gblsym, make_lltype_from_dtype(return_dtype)); - } else + } else { return_dtype = get_return_type(func_sptr); + } sc = SCG(func_sptr); DBGTRACEIN("") @@ -440,7 +442,7 @@ ll_process_routine_parameters(int func_sptr) } add_ag_typename(gblsym, (char *)char_type(return_dtype, 0)); - if (gbl.arets) + if (gbl.arets && (!CFUNCG(func_sptr))) set_ag_lltype(gblsym, make_lltype_from_dtype(DT_INT)); /* If we got this far, then we have established an argdtlist, perhaps it is diff --git a/tools/flang2/flang2exe/ll_structure.h b/tools/flang2/flang2exe/ll_structure.h index cfdef4d8b36..7f121d597fd 100644 --- a/tools/flang2/flang2exe/ll_structure.h +++ b/tools/flang2/flang2exe/ll_structure.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,6 +140,7 @@ typedef enum LL_IRVersion { LL_Version_3_9 = 39, LL_Version_4_0 = 40, LL_Version_5_0 = 50, + LL_Version_6_0 = 60, LL_Version_trunk = 1023 } LL_IRVersion; @@ -151,6 +152,11 @@ typedef enum LL_DWARFVersion { LL_DWARF_Version_4 } LL_DWARFVersion; +/* If flang is built with LLVM from github:flang-compiler/llvm, then one can + define the macro FLANG_LLVM_EXTENSIONS to use the Fortran debug information + extensions added to that LLVM. For now, this is disabled. */ +#undef FLANG_LLVM_EXTENSIONS + /** \brief LLVM IR Feature Vector. @@ -390,7 +396,11 @@ ll_feature_create_dimodule(const LL_IRFeatures *feature) INLINE static bool ll_feature_has_diextensions(const LL_IRFeatures *feature) { +#ifdef FLANG_LLVM_EXTENSIONS + return feature->version >= LL_Version_5_0; +#else return false; +#endif } INLINE static bool @@ -432,7 +442,11 @@ ll_feature_no_file_in_namespace(const LL_IRFeatures *feature) #define ll_feature_from_global_to_md(f) ((f)->version >= LL_Version_4_0) #define ll_feature_use_5_diexpression(f) ((f)->version >= LL_Version_5_0) #define ll_feature_create_dimodule(f) ((f)->version >= LL_Version_5_0) +#ifdef FLANG_LLVM_EXTENSIONS +#define ll_feature_has_diextensions(f) ((f)->version >= LL_Version_5_0) +#else #define ll_feature_has_diextensions(f) (false) +#endif #define ll_feature_no_file_in_namespace(f) ((f)->version >= LL_Version_5_0) #endif diff --git a/tools/flang2/flang2exe/lldebug.c b/tools/flang2/flang2exe/lldebug.c index aa2b7aa0f46..b127737e422 100644 --- a/tools/flang2/flang2exe/lldebug.c +++ b/tools/flang2/flang2exe/lldebug.c @@ -66,7 +66,7 @@ const int DIFLAG_ARTIFICIAL = 1 << 6; const int DIFLAG_ISMAINPGM = 1 << 21; -#if defined(PGI_LLVM_EXTENSIONS) +#if defined(FLANG_LLVM_EXTENSIONS) const int DIFLAG_PURE = 1 << 22; const int DIFLAG_ELEMENTAL = 1 << 23; const int DIFLAG_RECUSIVE = 1 << 24; @@ -2327,7 +2327,7 @@ lldbg_emit_type(LL_DebugInfo *db, int dtype, int sptr, int findex, offset[0] = 0; offset[1] = 0; cu_mdnode = ll_get_md_null(); -#if defined(PGI_LLVM_EXTENSIONS) +#if defined(FLANG_LLVM_EXTENSIONS) if (ll_feature_from_global_to_md(&db->module->ir) && (DTY(dtype) == TY_CHAR)) type_mdnode = lldbg_create_string_type_mdnode( diff --git a/tools/flang2/flang2exe/llutil.c b/tools/flang2/flang2exe/llutil.c index 4160904a881..a33a1e6418e 100644 --- a/tools/flang2/flang2exe/llutil.c +++ b/tools/flang2/flang2exe/llutil.c @@ -455,7 +455,7 @@ layout_struct_body(LL_Module *module, LL_Type *struct_type, int member_sptr, #ifdef POINTERG if (POINTERG(sptr)) { - cur_type = ll_convert_dtype(module, DTYPEG(sptr)); + cur_type = ll_convert_dtype(module, DDTG(DTYPEG(sptr))); cur_type = ll_get_pointer_type(cur_type); cur_size = ll_type_bytes(cur_type); } @@ -1939,7 +1939,7 @@ write_constant_value(int sptr, LL_Type *type, INT conval0, INT conval1, cprintf(d, "%.17le", num); /* Check for `+/-Infinity` and 'NaN' based on the IEEE bit patterns */ if ((num[0] & 0x7ff00000) == 0x7ff00000) /* exponent == 2047 */ - sprintf(d, "0x%08x00000000", num[0]); + sprintf(d, "0x%08x%08x", num[0], num[1]); /* also check for -0 */ else if (num[0] == 0x80000000 && num[1] == 0x00000000) sprintf(d, "-0.00000000e+00"); @@ -1999,6 +1999,21 @@ write_constant_value(int sptr, LL_Type *type, INT conval0, INT conval1, CONVAL2G(CONVAL2G(sptr))); return; + case LL_PTR: + if (sptr) { + num[1] = CONVAL2G(sptr); + num[0] = CONVAL1G(sptr); + } else { + num[1] = conval0; + num[0] = conval1; + } + if (num[0] == 0 && num[1] == 0) { + fprintf(LLVMFIL, "null"); + } else { + ui64toax(num, b, 22, uns, 10); + fprintf(LLVMFIL, "%s", b); + } + return; default: assert(0, "write_constant_value(): unexpected constant ll_type", type->data_type, 4); @@ -3186,8 +3201,19 @@ add_init_const_op(int dtype, OPERAND *cur_op, ISZ_T conval, ISZ_T *repeat_cnt, cur_op->next = make_constsptr_op(conval); cur_op = cur_op->next; break; + case TY_PTR: + /* almost always a null pointer */ + if (DT_ISINT(DTYPEG(conval))) { + cur_op->next = make_constval_op(make_lltype_from_dtype(dtype), + CONVAL2G(conval), CONVAL1G(conval)); + cur_op = cur_op->next; + address += size_of(dtype); + } else { + interr("process_acc_put_dinit: unexpected datatype", dtype, 4); + } + break; default: - interr("cf_data_init: unexpected datatype", dtype, 4); + interr("process_acc_put_dinit: unexpected datatype", dtype, 4); break; } } while (--*repeat_cnt);