Skip to content

Commit 4e7a342

Browse files
authored
Merge pull request #137 from ThePortlandGroup/nv_stage
Pull 2017-07-13T10-32 Recent NVIDIA Changes
2 parents 936dbbe + dbc5cc8 commit 4e7a342

File tree

14 files changed

+190
-29
lines changed

14 files changed

+190
-29
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ Flang
33

44
Flang is a Fortran compiler targeting LLVM.
55

6+
We have a flang-compiler channel on Slack. Slack is invitation only but anyone can join. Here's the link:
7+
8+
https://join.slack.com/t/flang-compiler/shared_invite/MjExOTEyMzQ3MjIxLTE0OTk4NzQyNzUtODQzZWEyMjkwYw
9+
10+
## Building Flang
11+
12+
We build Flang on Intel x86-64 and OpenPOWER hardware running either Ubuntu or Red Hat.
13+
614
## Prerequisites
715

816
Building LLVM requires fairly modern compiler toolchain and CMake, check [Getting started with LLVM](http://llvm.org/releases/4.0.0/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) and [Building LLVM with CMake][llvm-cmake] for the full list.

tools/flang1/flang1exe/pgifeat.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
#define PG_LM_PLATFORM
4848
#define TARGET_64BIT 1
4949

50-
/*
51-
* 64-bit CPU targets
52-
*/
50+
/*
51+
* 64-bit CPU targets
52+
*/
5353
#define TARGET_PTRSIZE 8
5454

5555
#if !defined(TARGET_WIN)
@@ -59,6 +59,8 @@
5959
#define TARGET_LONGSIZE 4
6060
#endif
6161

62+
/* Uniform structure assigments/moves ILI */
63+
#define USE_GSMOVE XBIT(2,0x800000)
6264

6365
/* ETLS and threadprivate related features */
6466
/* By default, prevent ETLS/TLS threadprivate usage */

tools/flang1/flang1exe/semgnr.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void get_type_rank(SST *, int *, int *);
4949
static ITEM *make_list(SST *, SST *);
5050
static int resolve_operator(int, SST *, SST *);
5151
static int find_operator(int, SST *, SST *, LOGICAL);
52+
static bool queue_generic_tbp_once(SPTR gnr);
5253

5354
/* macros used by the arg scoring routines */
5455
#define UNIT_SZ 3 /**< bits necessary to hold the max *_MATCH value */
@@ -111,19 +112,25 @@ static struct optabstruct {
111112
};
112113
#define OPTABSIZE 29
113114

114-
static int generic_tbp_scope = 0;
115-
116-
static int
117-
queue_generic_tbp_once()
115+
/** \brief Determines if we should (re)generate generic type bound procedure
116+
* (tbp) bindings based on scope. This should only be done once per scope.
117+
*
118+
* \param gnr is the SPTR of the symbol to check or 0 if N/A.
119+
*
120+
* \return true if we should (re)generate generic tbp bindings, else false.
121+
*/
122+
static bool
123+
queue_generic_tbp_once(SPTR gnr)
118124
{
119-
int rslt;
120-
rslt = (generic_tbp_scope != stb.curr_scope);
121-
generic_tbp_scope = stb.curr_scope;
122-
return rslt;
125+
if (GNCNTG(gnr) == 0 || gbl.internal > 1) {
126+
static int generic_tbp_scope = 0;
127+
bool rslt = (generic_tbp_scope != stb.curr_scope);
128+
generic_tbp_scope = stb.curr_scope;
129+
return rslt;
130+
}
131+
return false;
123132
}
124133

125-
#define QUEUE_GENERIC_TBP_ONCE (queue_generic_tbp_once())
126-
127134
void
128135
check_generic(int gnr)
129136
{
@@ -148,7 +155,7 @@ generic_tbp_call(int gnr, SST *stktop, ITEM *list, ITEM *chevlist)
148155
if (DBGBIT(3, 256))
149156
fprintf(gbl.dbgfil, "user generic, call %s\n", SYMNAME(gnr));
150157
#endif
151-
if (GNCNTG(gnr) == 0 && QUEUE_GENERIC_TBP_ONCE) {
158+
if (queue_generic_tbp_once(gnr)) {
152159
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
153160
}
154161

@@ -194,7 +201,7 @@ generic_tbp_func(int gnr, SST *stktop, ITEM *list)
194201
fprintf(gbl.dbgfil, "user generic %s\n", SYMNAME(gnr));
195202
#endif
196203

197-
if (GNCNTG(gnr) == 0 && QUEUE_GENERIC_TBP_ONCE) {
204+
if (queue_generic_tbp_once(gnr)) {
198205
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
199206
}
200207

@@ -352,7 +359,7 @@ find_best_generic(int gnr, ITEM *list, int arg_cnt, int try_device,
352359
if (GNCNTG(sptrgen) == 0 && GTYPEG(sptrgen)) {
353360
continue; /* Could be an overloaded type */
354361
}
355-
if (GNCNTG(sptrgen) == 0 && QUEUE_GENERIC_TBP_ONCE) {
362+
if (queue_generic_tbp_once(sptrgen)) {
356363
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
357364
}
358365
if (GNCNTG(sptrgen) == 0 && !IS_TBP(sptrgen)) {
@@ -840,7 +847,7 @@ defined_operator(int opr, SST *stktop, SST *lop, SST *rop)
840847
if (DBGBIT(3, 256))
841848
fprintf(gbl.dbgfil, "user operator %s\n", SYMNAME(opr));
842849
#endif
843-
if (QUEUE_GENERIC_TBP_ONCE)
850+
if (queue_generic_tbp_once(0))
844851
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
845852
if (STYPEG(opr) != ST_OPERATOR) {
846853
i = findByNameStypeScope(SYMNAME(opr), ST_OPERATOR, stb.curr_scope);
@@ -1068,7 +1075,7 @@ is_intrinsic_opr(int val, SST *stktop, SST *lop, SST *rop, int tkn_alias)
10681075
if (opr) {
10691076
func = resolve_operator(opr, lop, rop);
10701077
if (!func && /*IN_MODULE*/ sem.mod_cnt && sem.which_pass) {
1071-
if (QUEUE_GENERIC_TBP_ONCE)
1078+
if (queue_generic_tbp_once(0))
10721079
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
10731080
func = resolve_operator(opr, lop, rop);
10741081
}
@@ -1357,7 +1364,7 @@ check_defined_io2(char *proc, int silentmode, int chk_dtype)
13571364
continue;
13581365
if (GNCNTG(sptrgen) == 0 && GTYPEG(sptrgen))
13591366
continue;
1360-
if (GNCNTG(sptrgen) == 0 && QUEUE_GENERIC_TBP_ONCE) {
1367+
if (queue_generic_tbp_once(sptrgen)) {
13611368
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
13621369
}
13631370

tools/flang2/docs/xflag.n

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ Fill in BIH_LINENO with line numbers on inlined blocks.
228228
don't use SMOVEI/SMOVES instead of SMOVE in exp_rte.c
229229
.XB 0x400000
230230
F90 pointer optimizations.
231+
.XB 0x800000
232+
Use GSMOVE in exp_rte.c
231233

232234
.XF "3:"
233235
Used to turn on/off various dual-op/dual-inst/pipelined ops.

tools/flang2/flang2exe/exp_ftn.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,6 +3605,8 @@ exp_misc(ILM_OP opc, ILM *ilmp, int curilm)
36053605
}
36063606
}
36073607
mkrtemp_init();
3608+
hostsptr = 0;
3609+
devsptr = 0;
36083610
break;
36093611

36103612
case IM_ENTRY:

tools/flang2/flang2exe/exp_rte.c

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static void cp_byval_mem_arg(int);
5959
static int allochartmp(int lenili);
6060
static int block_str_move(STRDESC *, STRDESC *);
6161
static int getchartmp(int ili);
62+
static void _exp_smove(int, int, int, int, DTYPE);
6263

6364
void arg_is_refd(int); /* FIXME? move from llassem.c? */
6465

@@ -132,6 +133,21 @@ getstrlen64(STRDESC *str)
132133
return il;
133134
}
134135

136+
/*
137+
* Generating GSMOVE ILI is under XBIT(2,0x800000). When the XBIT is not
138+
* set, _exp_smove() will proceed as before; in particular, chk_block() is
139+
* called to add terminal ILI to the block current to the expander. When
140+
* the XBIT is set, the GSMOVE ili are transformed sometime after the expander,
141+
* but we still want the code in _exp_smove() to do the work. However, we
142+
* cannot call chk_block() to add the terminal ILI; we must use 'addilt'.
143+
* So, define and use a function pointer, p_chk_block, which calls either
144+
* chk_block() or a new local addilit routine, gsmove_chk_block(). In this
145+
* case, the current ilt is saved as the file static, gsmove_ilt.
146+
*/
147+
static void (*p_chk_block)(int) = chk_block;
148+
static void gsmove_chk_block(int);
149+
static int gsmove_ilt;
150+
135151
/* aux.curr_entry->flags description:
136152
* Initialized to 0 by exp_end
137153
* NA 0x1 - need to save argument registers (set by exp_end).
@@ -4202,6 +4218,61 @@ expand_smove(int destilm, int srcilm, DTYPE dtype)
42024218
}
42034219
dest_addr = ILI_OF(destilm);
42044220
src_addr = ILI_OF(srcilm);
4221+
if (USE_GSMOVE) {
4222+
int ilix;
4223+
ilix = ad5ili(IL_GSMOVE, src_addr, dest_addr, src_nme, dest_nme, dtype);
4224+
chk_block(ilix);
4225+
}
4226+
else {
4227+
_exp_smove(dest_nme, src_nme, dest_addr, src_addr, dtype);
4228+
}
4229+
}
4230+
4231+
/** \brief Transform the GSMOVE ILI created by expand_smove()
4232+
*/
4233+
void
4234+
exp_remove_gsmove(void)
4235+
{
4236+
int bihx, iltx, ilix;
4237+
p_chk_block = gsmove_chk_block;
4238+
for (bihx = gbl.entbih; bihx; bihx = BIH_NEXT(bihx)) {
4239+
int next_ilt;
4240+
LOGICAL any_gsmove = FALSE;
4241+
rdilts(bihx);
4242+
for (iltx = ILT_NEXT(0); iltx; ) {
4243+
next_ilt = ILT_NEXT(iltx);
4244+
ilix = ILT_ILIP(iltx);
4245+
if (ILI_OPC(ilix) == IL_GSMOVE) {
4246+
int src_addr = ILI_OPND(ilix, 1);
4247+
int dest_addr = ILI_OPND(ilix, 2);
4248+
int src_nme = ILI_OPND(ilix, 3);
4249+
int dest_nme = ILI_OPND(ilix, 4);
4250+
DTYPE dtype = ILI_OPND(ilix, 5);
4251+
any_gsmove = TRUE;
4252+
gsmove_ilt = iltx;
4253+
_exp_smove(dest_nme, src_nme, dest_addr, src_addr, dtype);
4254+
ILT_NEXT(gsmove_ilt) = next_ilt;
4255+
ILT_PREV(next_ilt) = gsmove_ilt;
4256+
delilt(iltx);
4257+
}
4258+
iltx = next_ilt;
4259+
}
4260+
wrilts(bihx);
4261+
if (DBGBIT(10,2) && any_gsmove) {
4262+
fprintf(gbl.dbgfil, "\n***** After remove gsmove *****\n");
4263+
dump_one_block(gbl.dbgfil, bihx, NULL);
4264+
}
4265+
}
4266+
p_chk_block = chk_block;
4267+
}
4268+
4269+
static void
4270+
_exp_smove(int dest_nme, int src_nme, int dest_addr, int src_addr, DTYPE dtype)
4271+
{
4272+
ISZ_T n; /* number of bytes left to copy */
4273+
int i;
4274+
INT offset; /* number of bytes from begin addr */
4275+
42054276
n = size_of(dtype);
42064277
offset = 0;
42074278

@@ -4211,10 +4282,10 @@ expand_smove(int destilm, int srcilm, DTYPE dtype)
42114282
if (n > TEST_BOUND) {
42124283

42134284
if (XBIT(2, 0x200000)) {
4214-
chk_block(ad4ili(IL_SMOVE, src_addr, dest_addr, ad_aconi(n / SMOVE_CHUNK),
4285+
p_chk_block(ad4ili(IL_SMOVE, src_addr, dest_addr, ad_aconi(n / SMOVE_CHUNK),
42154286
dest_nme));
42164287
} else {
4217-
chk_block(ad4ili(IL_SMOVEI, ad2ili(IL_SMOVES, src_addr, src_nme),
4288+
p_chk_block(ad4ili(IL_SMOVEI, ad2ili(IL_SMOVES, src_addr, src_nme),
42184289
dest_addr, n, dest_nme));
42194290
}
42204291
smove_flag = 1; /* structure move in this function */
@@ -4255,7 +4326,7 @@ expand_smove(int destilm, int srcilm, DTYPE dtype)
42554326
ilip = ad4ili(IL_STKR, ilix, ilip, dest_nme, siz);
42564327
else
42574328
ilip = ad4ili(IL_ST, ilix, ilip, dest_nme, siz);
4258-
chk_block(ilip);
4329+
p_chk_block(ilip);
42594330

42604331
offset += skip;
42614332
n -= skip;
@@ -5317,6 +5388,15 @@ exp_reset_argregs(int ir, int fr)
53175388
{
53185389
}
53195390

5391+
/**
5392+
* \brief Create & add an ILT for an ILI when transforming GSMOVE ILI
5393+
*/
5394+
static void
5395+
gsmove_chk_block(int ili)
5396+
{
5397+
gsmove_ilt = addilt(gsmove_ilt, ili);
5398+
}
5399+
53205400
/*------------------------------------------------------------------*/
53215401

53225402
#undef ILM_OPC

tools/flang2/flang2exe/expand.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int efunc(char *);
6868
* Initialize global data structures
6969
*/
7070
void
71-
ds_init()
71+
ds_init(void)
7272
{
7373
int i;
7474
ili_init();
@@ -94,7 +94,7 @@ ds_init()
9494
} /* ds_init */
9595

9696
void
97-
exp_init()
97+
exp_init(void)
9898
{
9999
/*
100100
* Allocate the space necessary to hold the auxiliary information for ILM
@@ -155,7 +155,7 @@ exp_init()
155155
* clean up allocated space when the program isn't compiled
156156
*/
157157
void
158-
exp_cleanup()
158+
exp_cleanup(void)
159159
{
160160
if (rgsetb.stg_base)
161161
EXP_FREE(rgsetb);

tools/flang2/flang2exe/expand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ void exp_qjsr(char *, int, ILM *, int);
267267
void exp_estmt(int);
268268
void exp_label(int);
269269
void expand_smove(int, int, DTYPE);
270+
void exp_remove_gsmove(void);
270271
void exp_load(ILM_OP, ILM *, int);
271272
void exp_store(ILM_OP, ILM *, int);
272273
void exp_misc(ILM_OP, ILM *, int);

tools/flang2/flang2exe/iliutil.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,9 +1363,10 @@ ldst_msz(DTYPE dtype, ILI_OP *ld, ILI_OP *st, MSZ* siz)
13631363
*ld = IL_LDDP;
13641364
*st = IL_STDP;
13651365
break;
1366+
default:
1367+
break;
13661368
}
13671369

1368-
13691370
}
13701371

13711372

tools/flang2/flang2exe/pgifeat.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
#define PG_LM_PLATFORM
4848
#define TARGET_64BIT 1
4949

50-
/*
51-
* 64-bit CPU targets
52-
*/
50+
/*
51+
* 64-bit CPU targets
52+
*/
5353
#define TARGET_PTRSIZE 8
5454

5555
#if !defined(TARGET_WIN)
@@ -59,6 +59,8 @@
5959
#define TARGET_LONGSIZE 4
6060
#endif
6161

62+
/* Uniform structure assigments/moves ILI */
63+
#define USE_GSMOVE XBIT(2,0x800000)
6264

6365
/* ETLS and threadprivate related features */
6466
/* By default, prevent ETLS/TLS threadprivate usage */

0 commit comments

Comments
 (0)