[28e18d]: Backend / If1opt / if1explode.c Maximize Restore History

Download this file

if1explode.c    383 lines (301 with data), 11.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/**************************************************************************/
/* FILE ************** if1explode.c ************************/
/**************************************************************************/
/* Author: Dave Can */
/* Update: Patrick Miller -- Ansi support (Dec 2000) */
/* Copyright (C) University of California Regents */
/**************************************************************************/
/*
* $Log:
*/
/**************************************************************************/
/* if1explode.c,v
* Revision 12.7 1992/11/04 22:04:57 miller
* Initial revision
*
* Revision 12.7 1992/10/21 18:08:33 miller
* Initial RCS Version by Cann
* */
#include "world.h"
static int efs = 0; /* COUNT OF EXPLODED Foralls */
static int Tefs = 0; /* COUNT OF Foralls */
static int rff = 0; /* COUNT OF RESULTING Forall FRAGEMENTS */
static int maelm = 0; /* COUNT OF MODIFIED AElement NODES */
DYNDECLARE(printinfo, printbuf, printlen, printcount, char, 2000);
#define MAX_HASH 31 /* HASH TABLES FOR FAST INFO LOOKUP */
static PINFO mihash[MAX_HASH];
static PINFO aihash[MAX_HASH];
/**************************************************************************/
/* LOCAL ************** IsExplodeCandidate ************************/
/**************************************************************************/
/* PURPOSE: RETURNS TRUE IF NODE n IS A CANDIDATE FOR EXPLOSION. */
/**************************************************************************/
static int IsExplodeCandidate( n , ReasonP)
PNODE n;
char **ReasonP;
{
register PEDGE i;
switch ( n->type ) {
case IFAElementN:
case IFAElementP:
case IFAElementM:
*ReasonP = "loop is the wrong type";
return( FALSE );
default:
break;
}
/* ARE ALL IMPORTS ONE OF FOUR FROMS: CONSTANTS, SPECIAL AElement NODES, */
/* OR K PORT VALUES. */
for ( i = n->imp; i != NULL; i = i->isucc ) {
if ( IsConst( i ) )
continue;
switch ( i->src->type ) {
case IFSGraph:
case IFAElementN:
case IFAElementM:
case IFAElementP:
break;
default:
*ReasonP = "loop import is the wrong type";
return( FALSE );
}
}
/* ARE ALL USES WITHIN THE SUBGRAPH? */
/* for ( e = n->exp; e != NULL; e = e->esucc )
if ( IsSGraph( e->dst ) )
return( FALSE ); */
return( TRUE );
}
/**************************************************************************/
/* LOCAL ************** BuildFragement ************************/
/**************************************************************************/
/* PURPOSE: REMOVE NODE n FROM Forall f1 AND ENCAPSOLATE IT IN ITS OWN */
/* FORALL NODE. THEN LINK THE NEW Forall TO f1. */
/**************************************************************************/
static PNODE BuildFragement( f1, n )
PNODE f1;
PNODE n;
{
register PNODE gen;
register PNODE body;
register PNODE ret;
register PNODE f2;
register PNODE nn;
register PNODE nnn;
register PEDGE i;
register PEDGE e;
register PEDGE ee;
register PEDGE se;
register PNODE aelm;
register PNODE gat;
register int port;
register PINFO TypeInfo;
f2 = NodeAlloc( ++maxint, IFForall );
CopyPragmas( f1, f2 );
f2->info = f1->info;
f2->gname = f1->gname;
f2->alst = f1->alst;
f2->scnt = f1->scnt;
f2->if1line = f1->if1line;
LinkNode( f1->npred, f2 );
gen = CopyNode( f1->F_GEN );
gen->G_DAD = f2;
gen->gsucc = NULL;
gen->gpred = NULL;
LinkGraph( f2, gen ); /* THIS ASSUMES F_GEN IS THE FIRST GRAPH!!! */
body = NodeAlloc( 0, IFSGraph );
body->G_DAD = f2;
CopyPragmas( f1->F_BODY, body );
LinkGraph( gen, body ); /* THIS ASSUMES F_BODY IS THE SECOND GRAPH!!! */
ret = NodeAlloc( 0, IFSGraph );
ret->G_DAD = f2;
CopyPragmas( f1->F_RET, ret );
LinkGraph( body, ret ); /* THIS ASSUMES F_RET IS THE LAST GRAPH!!! */
nn = CopyNode( n );
LinkNode( body, nn );
for ( i = n->imp; i != NULL; i = i->isucc ) {
if ( IsConst( i ) ) {
CopyEdgeAndReset( i, NULL_NODE, nn );
continue;
}
if ( IsSGraph( i->src ) ) {
CopyEdgeAndReset( i, body, nn );
continue;
}
/* MUST BE A SPECIAL AElement NODE! */
nnn = CopyNode( i->src );
LinkNode( body, nnn );
CopyEdgeAndReset( i->src->imp, body, nnn );
CopyEdgeAndReset( i->src->imp->isucc, body, nnn );
if ( i->src->imp->isucc->isucc != NULL )
CopyEdgeAndReset( i->src->imp->isucc->isucc, body, nnn );
CopyEdgeAndReset( i, nnn, nn );
}
for ( e = n->exp; e != NULL; e = n->exp ) {
/* ALLOCATE AND LINK THE NEW NODE TO NEW BODY AND THREAD THE SYSTEM!! */
port = ++maxint;
ee = CopyEdge( e, nn, body );
ee->iport = port;
LinkExport( nn, ee );
LinkImport( body, ee );
/* LINK THE LOWER BOUND AND COMPONENT VALUE TO THE NEW AGather NODE */
gat = NodeAlloc( ++maxint, IFAGather );
LinkNode( ret, gat );
CopyEdgeAndReset( gen->imp->src->imp, ret, gat );
gat->imp->iport = 1;
ee = EdgeAlloc( ret, port, gat, 2 );
if ( (TypeInfo = mihash[(e->info->label)%MAX_HASH]) == NULL ) {
ee->info = FindInfo( ++maxint, IF_MULTIPLE );
ee->info->A_ELEM = e->info;
mihash[(e->info->label)%MAX_HASH] = ee->info;
}
else
ee->info = TypeInfo;
LinkExport( ret, ee );
LinkImport( gat, ee );
/* LINK THE NEW AGather TO THE NEW RETURN GRAPH */
port = ++maxint;
ee = EdgeAlloc( gat, 1, ret, port );
if ( (TypeInfo = aihash[(e->info->label)%MAX_HASH]) == NULL ) {
TypeInfo = FindInfo( ++maxint, IF_ARRAY );
TypeInfo->A_ELEM = e->info;
ee->info = TypeInfo;
aihash[(e->info->label)%MAX_HASH] = TypeInfo;
}
else
ee->info = TypeInfo;
LinkExport( gat, ee );
LinkImport( ret, ee );
/* LINK THE TWO Foralls */
ee = EdgeAlloc( f2, port, f1, port );
ee->info = TypeInfo;
LinkExport( f2, ee );
LinkImport( f1, ee );
/* BUILD THE NEW AElement NODE---SPECIAL */
aelm = NodeAlloc( ++maxint, IFAElementN );
LinkNode( n->npred, aelm );
/* LINK IN THE CONTROL INDEX */
ee = CopyEdge( f1->F_GEN->imp, f1->F_BODY, aelm );
ee->eport = f1->F_GEN->imp->iport;
ee->iport = 2;
LinkImport( aelm, ee );
LinkExport( f1->F_BODY, ee );
/* LINK IN THE NEW ARRAY SOURCE TO aelm */
ee = EdgeAlloc( f1->F_BODY, port, aelm, 1 );
ee->info = TypeInfo;
LinkExport( f1->F_BODY, ee );
LinkImport( aelm, ee );
/* MOVE n EXPORTS for e->eport TO THE NEW AElement NODE aelm */
for ( ee = e->esucc; ee != NULL; ee = se ) {
se = ee->esucc;
if ( ee->eport != e->eport )
continue;
UnlinkExport( ee );
ee->eport = 1;
LinkExport( aelm, ee );
}
UnlinkExport( e );
e->eport = 1;
LinkExport( aelm, e );
}
/* COPY f1 IMPORTS TO f2 */
for ( i = f1->imp; i != NULL; i = i->isucc ) {
if ( IsExport( f2->F_GEN, i->iport ) || IsExport( f2->F_BODY, i->iport ) )
CopyEdgeAndLink( i, f2, i->iport );
}
/* REMOVE n FROM f1 */
OptRemoveDeadNode( n );
return( f2 );
}
/**************************************************************************/
/* LOCAL ************** ExplodeForalls ************************/
/**************************************************************************/
/* PURPOSE: EXPLODE THE FORALL NODES IN GRAPH g. THIS ROUTINE RETURNS */
/* TRUE IF g IS THE BODY OF AN INNER LOOP. */
/**************************************************************************/
static int ExplodeForalls( g, explodeI )
PNODE g;
int explodeI;
{
register PNODE sg;
register PNODE n;
register PNODE nn;
register PNODE sn;
register PNODE snn;
register PNODE f;
register int in1;
register int nin;
char *Reason;
for ( in1 = FALSE, n = g->G_NODES; n != NULL; n = sn ) {
sn = n->nsucc;
if ( IsCompound( n ) ) {
for ( nin = FALSE, sg = n->C_SUBS; sg != NULL; sg = sg->gsucc )
nin = nin || ExplodeForalls( sg, explodeI );
in1 = in1 || nin;
if ( IsLoop( n ) ) {
in1 = TRUE;
continue;
}
}
if ( !IsForall( n ) )
continue;
++Tefs;
in1 = TRUE;
if ( explodeI && nin )
continue;
/* CHECK IF THE CONTROL IS SUITABLE FOR EXPLOSION: A SINGLE Range NODE */
if ( n->F_GEN->G_NODES->nsucc != NULL ||
n->F_GEN->imp->src->type != IFRangeGenerate )
continue;
efs++;
EncodeIndexing( n->F_BODY, n->F_GEN->imp->iport, &maelm );
for ( nn = n->F_BODY->G_NODES; nn != NULL; nn = snn ) {
snn = nn->nsucc;
if ( !IsExplodeCandidate( nn , &Reason) )
continue;
if (RequestInfo(I_Info1,info)) {
DYNEXPAND(printinfo, printbuf, printlen, printcount, char, printlen+200);
printlen += (SPRINTF(printinfo + printlen,
" Exploding loop %d at line %d, funct %s, file %s\n\n",
nn->ID, nn->line, nn->funct, nn->file), strlen(printinfo + printlen));
}
f = BuildFragement( n, nn ); /* THIS WILL REMOVE nn FROM n->F_BODY */
DecodeIndexing( f->F_BODY );
rff++;
}
DecodeIndexing( n->F_BODY );
OptRemoveDeadNode( n ); /* NEW CANN 2/92 */
}
return( in1 );
}
/**************************************************************************/
/* GLOBAL ************** WriteExplodeInfo ************************/
/**************************************************************************/
/* PURPOSE: WRITE FORALL EXPLOSION INFORMATION TO stderr. */
/**************************************************************************/
void WriteExplodeInfo()
{
FPRINTF( infoptr, "\n\n **** FORALL EXPLOSIONS\n\n%s\n", printinfo);
DYNFREE(printinfo, printbuf, printlen, printcount, char, NULL);
FPRINTF( infoptr, " Exploded Foralls: %d of %d\n", efs,Tefs );
/* FPRINTF( infoptr, " Resulting Forall Fragements: %d\n", rff );
FPRINTF( infoptr, " Modified AElement Nodes: %d\n", maelm ); */
}
/**************************************************************************/
/* GLOBAL ************** If1Explode ************************/
/**************************************************************************/
/* PURPOSE: EXPLODE THE FORALL NODES OF ALL FUNCTION GRAPHS. */
/**************************************************************************/
void If1Explode( explodeI )
int explodeI;
{
register PNODE f;
register int i;
if ( noassoc ) return;
for ( i = 0; i < MAX_HASH; i++ ) {
mihash[i] = NULL;
aihash[i] = NULL;
}
for ( f = glstop->gsucc; f != NULL; f = f->gsucc )
ExplodeForalls( f, explodeI );
}