Skip to content

Commit 5eecfa2

Browse files
committed
Expand structure copy in a unified way.
Currently, the frontend generates the SMOVE ILM for an assignment of a structure & derived type. The ILM is then expanded into loads & stores, or other smove ILI (SMOVE, SMOVEI/SMOVES, XMOVE). What we want to do is expand to a new ILI (GSMOVE) that gives us the addresses, nmes, and dtype of the source & destination. It is then straightforward for other phases, to make target-dependent decisions based on size/alignment of the aggregate. xflag.n: add XBIT(2,0x800000) - expand IM_SMOVE into IL_GSMOVE in exp_rte.c pgifeat.h: - define the macro, USE_GSMOVE, as XBIT(2,0x800000) - minor source cleanup (comments) ilitp.n: Add IL_GSMOVE arlnk arlnk nme nme stc op1 - the source address. op2 - the destination address. nme1 - the names table entry for the source nme2 - the namse table entry for the destination stc - is the dtype of the struct (derived type). expand.h: prototype for exp_remove_gsmove(void) expand.c: add prototypes. exp_rte.c - expand_smove() - gen IL_GSMOVE if USE_GSMOVE is set - add exp_remove_gsmove() - called from rmsmove.c; search the ILI blocks of the function and if a GSMOVE is found, call _exp_smove() to transform the ILI into loads/stores, SMOVEI, SMOVE, ... - add gsmove_chk_block() rmsmove.c - call gsmove_chk_block() if USE_GSMOVE is set
1 parent 2637788 commit 5eecfa2

File tree

10 files changed

+155
-12
lines changed

10 files changed

+155
-12
lines changed

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/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_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/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/flang2/flang2exe/rmsmove.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,18 @@ fixup_nme(int nmex, int msize, int offset, int iter)
9494
return new_nme;
9595
} /* fixup_nme */
9696

97+
void exp_remove_gsmove(void);
9798
void
9899
rm_smove(void)
99100
{
100101
int bihx, iltx, ilix, new_acon;
102+
/*
103+
* First implementation of GSMOVE will be under XBIT(2,0x800000). When this
104+
* is the only method, presumably, the code in exp_remove_gsmove() will be
105+
* moved to the ensuing loop.
106+
*/
107+
if (USE_GSMOVE)
108+
exp_remove_gsmove();
101109
for (bihx = gbl.entbih; bihx; bihx = BIH_NEXT(bihx)) {
102110
LOGICAL have_smove = FALSE;
103111
rdilts(bihx);

tools/flang2/utils/ilitp/aarch64/ilitp.n

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,22 @@ Emitted immediately before an SMOVE operation.
20962096
.AT other null trm dom
20972097
.CG CGonly "rep"
20982098

2099+
.IL GSMOVE arlnk arlnk nme nme stc
2100+
General structure copy.
2101+
A structure store (SMOVE ILM) is expanded into the GSMOVE ILI; a phase, such as
2102+
the ACC CG, needs to have the structure assignment presented as a first-class
2103+
ILI operation.
2104+
After the last phase requiring GSMOVE, GSMOVE will then be expanded into
2105+
lower level ILI which will be dependent on target, alignment, small vs large,
2106+
etc.
2107+
\'op1' is the source address.
2108+
\'op2' is the destination address.
2109+
\'nme1' is the names table entry for source struct.
2110+
\'nme2' is the namse table entry for the destination struct.
2111+
\'stc' is the dtype of the struct.
2112+
.AT other null trm dom
2113+
.CG notCG
2114+
20992115
.IL SMOVE arlnk arlnk arlnk nme
21002116
Structure copy.
21012117
\'op1' is the source address.

tools/flang2/utils/ilitp/ppc64le/ilitp.n

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,22 @@ Emitted immediately before an SMOVE operation.
20922092
.AT other null trm dom
20932093
.CG CGonly "rep"
20942094

2095+
.IL GSMOVE arlnk arlnk nme nme stc
2096+
General structure copy.
2097+
A structure store (SMOVE ILM) is expanded into the GSMOVE ILI; a phase, such as
2098+
the ACC CG, needs to have the structure assignment presented as a first-class
2099+
ILI operation.
2100+
After the last phase requiring GSMOVE, GSMOVE will then be expanded into
2101+
lower level ILI which will be dependent on target, alignment, small vs large,
2102+
etc.
2103+
\'op1' is the source address.
2104+
\'op2' is the destination address.
2105+
\'nme1' is the names table entry for source struct.
2106+
\'nme2' is the namse table entry for the destination struct.
2107+
\'stc' is the dtype of the struct.
2108+
.AT other null trm dom
2109+
.CG notCG
2110+
20952111
.IL SMOVE arlnk arlnk arlnk nme
20962112
Structure copy.
20972113
\'op1' is the source address.

tools/flang2/utils/ilitp/x86_64/ilitp.n

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,22 @@ Emitted immediately before an SMOVE operation.
24172417
.AT other null trm dom
24182418
.CG CGonly "rep"
24192419

2420+
.IL GSMOVE arlnk arlnk nme nme stc
2421+
General structure copy.
2422+
A structure store (SMOVE ILM) is expanded into the GSMOVE ILI; a phase, such as
2423+
the ACC CG, needs to have the structure assignment presented as a first-class
2424+
ILI operation.
2425+
After the last phase requiring GSMOVE, GSMOVE will then be expanded into
2426+
lower level ILI which will be dependent on target, alignment, small vs large,
2427+
etc.
2428+
\'op1' is the source address.
2429+
\'op2' is the destination address.
2430+
\'nme1' is the names table entry for source struct.
2431+
\'nme2' is the namse table entry for the destination struct.
2432+
\'stc' is the dtype of the struct.
2433+
.AT other null trm dom
2434+
.CG notCG
2435+
24202436
.IL SMOVE arlnk arlnk arlnk nme
24212437
Structure copy.
24222438
\'op1' is the source address.

0 commit comments

Comments
 (0)