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

Download this file

381 lines (297 with data), 10.9 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
/**************************************************************************/
/* FILE ************** if1invert.c ************************/
/**************************************************************************/
/* Author: Dave Cann */
/* Update: Patrick Miller -- Ansi support (Dec 2000) */
/* Copyright (C) University of California Regents */
/**************************************************************************/
/*
* $Log:
*/
/**************************************************************************/
/* if1invert.c,v
* Revision 12.7 1992/11/04 22:04:58 miller
* Initial revision
*
* Revision 12.7 1992/10/21 18:08:35 miller
* Initial RCS Version by Cann
* */
#include "world.h"
static int invcnt = 0; /* COUNT OF INVERTED LOOPS */
static int Tcnt = 0; /* COUNT OF LOOPS */
DYNDECLARE(printinfo,printbuf,printlen,printcount,char,2000);
/**************************************************************************/
/* GLOBAL ************** WriteInvertInfo ************************/
/**************************************************************************/
/* PURPOSE: WRITE LOOP INVERTION INFORMATION TO stderr. */
/**************************************************************************/
void WriteInvertInfo()
{
FPRINTF( infoptr, "\n\n **** LOOP INVERSION\n\n%s\n", printinfo);
FPRINTF( infoptr, " Inverted Loops: %d of %d\n", invcnt,Tcnt );
}
/**************************************************************************/
/* LOCAL ************** WireSelectSubgraph ************************/
/**************************************************************************/
/* PURPOSE: WIRE sg TO f AND f TO sg USING s AS THE PARENT. */
/**************************************************************************/
static void WireSelectSubgraph( s, sg, f )
PNODE s;
PNODE sg;
PNODE f;
{
register PEDGE i;
register PEDGE e;
for ( i = s->imp; i != NULL; i = i->isucc ) {
e = CopyEdge( i, sg, f );
e->eport = e->iport;
LinkExport( sg, e );
LinkImport( f, e );
}
for ( i = f->F_RET->imp; i != NULL; i = i->isucc ) {
e = CopyEdge( i, f, sg );
e->eport = e->iport;
LinkExport( f, e );
LinkImport( sg, e );
}
}
/**************************************************************************/
/* LOCAL ************** FixForallBody ************************/
/**************************************************************************/
/* PURPOSE: REPLACE s WITH THE NODE LIST OF sg AND WIRE THE NEW NODES */
/* INTO FORALL f. */
/**************************************************************************/
static void FixForallBody( s, f, sg )
PNODE s;
PNODE f;
PNODE sg;
{
register PEDGE e;
register PEDGE i;
register PEDGE se;
register PEDGE si;
register PNODE n;
register PNODE sn;
for ( e = s->exp; e != NULL; e = se ) {
se = e->esucc;
UnlinkExport( e );
if ( (i = FindImport( sg, e->eport )) == NULL )
Error2( "FixForallBody", "FindImport FAILURE ON ALT IMPORT SEARCH" );
if ( IsConst( i ) )
ChangeToConst( e, i );
else {
e->eport = i->eport;
LinkExport( i->src, e );
}
}
for ( i = sg->imp; i != NULL; i = si ) {
si = i->isucc;
UnlinkExport( i );
UnlinkImport( i );
/* free( i ); */
}
for ( e = sg->exp; e != NULL; e = se ) {
se = e->esucc;
UnlinkExport( e );
if ( (i = FindImport( s, e->eport )) == NULL )
Error2( "FixForallBody", "FindImport FAILURE ON Select IMPORT SEARCH" );
if ( IsConst( i ) )
ChangeToConst( e, i );
else {
e->eport = i->eport;
LinkExport( i->src, e );
}
}
for ( i = s->imp; i != NULL; i = si ) {
si = i->isucc;
UnlinkExport( i );
UnlinkImport( i );
/* free( i ); */
}
/* BUG FIX CANN: 7/7/91 */
/* UnlinkNode( s ); */
/* LinkNodeLists( f->F_BODY, sg ); */
for ( n = sg->G_NODES; n != NULL; n = sn ) {
sn = n->nsucc;
UnlinkNode( n );
LinkNode( s->npred, n );
}
UnlinkNode( s );
}
/**************************************************************************/
/* LOCAL ************** GetFirstNoOp ************************/
/**************************************************************************/
/* PURPOSE: RETURN THE FIRST NoOp NODE IN GRAPH g. */
/**************************************************************************/
static PNODE GetFirstNoOp( g )
PNODE g;
{
register PNODE n;
for ( n = g->G_NODES; n != NULL; n = n->nsucc )
if ( n->type == IFNoOp )
return( n );
Error2( "GetFirstNoOp", "NoOp NOT FOUND" );
return NULL;
}
/**************************************************************************/
/* LOCAL ************** DoTheInversion ************************/
/**************************************************************************/
/* PURPOSE: DO THE LOOP INVERSION FOR f WITH SELECT NODE s. */
/**************************************************************************/
static void DoTheInversion( f, s )
PNODE f;
PNODE s;
{
register PNODE fa;
register PNODE fc;
register PNODE a;
register PNODE c;
register PEDGE i;
/* CHANGE THE SELECT TYPE TO AVOID COPYING s WHEN COPYING f */
s->type = IFNoOp;
/* MAKE COPIES OF f */
fa = CopyNode( f ); NewCompoundID(fa);
fc = CopyNode( f ); NewCompoundID(fc);
FixForallBody( GetFirstNoOp( fa->F_BODY ), fa, s->S_ALT );
FixForallBody( GetFirstNoOp( fc->F_BODY ), fc, s->S_CONS );
/* CONVERT f INTO A Select NODE; THE ASSUMED SUBGRAPH ORDER IS S_TEST, */
/* S_ALT, AND S_CONS. */
f->type = IFSelect;
CopyPragmas( s, f );
f->C_ALST = s->C_ALST;
f->gsucc = NULL;
f->gpred = NULL;
if ( (i = FindImport( s, s->S_TEST->imp->eport )) == NULL )
Error2( "DoTheInversion", "FindImport FAILURE" );
if ( IsConst( i ) )
Error2( "DoTheInversion", "FindImport FOUND CONSTANT" );
LinkGraph( f, s->S_TEST );
f->S_TEST->G_DAD = f;
f->S_TEST->imp->eport = i->eport;
a = NodeAlloc( 0, IFSGraph );
LinkGraph( f->S_TEST, a );
a->G_DAD = f;
LinkNode( a, fa );
c = NodeAlloc( 0, IFSGraph );
LinkGraph( f->S_ALT, c );
c->G_DAD = f;
LinkNode( c, fc );
WireSelectSubgraph( f, a, fa );
WireSelectSubgraph( f, c, fc );
}
/**************************************************************************/
/* LOCAL ************** InvertLoops ************************/
/**************************************************************************/
/* PURPOSE: INVERT CANDIDATE LOOPS IN GRAPH g. */
/* */
/* for i in 1,10 */
/* returns array of if ( G ) then a + 1 else b[i] end if end for */
/* */
/* BECOMES if ( G ) then for i in 1,10 returns array of a+1 end for */
/* else for i in 1,10 returns array of b[i] end for end if */
/**************************************************************************/
static void InvertLoops( g )
PNODE g;
{
register PNODE n;
register PNODE sg;
register PNODE nn;
register PEDGE i;
register PEDGE e;
for ( n = g->G_NODES; n != NULL; n = n->nsucc ) {
if ( IsCompound( n ) )
for ( sg = n->C_SUBS; sg != NULL; sg = sg->gsucc )
InvertLoops( sg );
if ( !IsForall( n ) )
continue;
++Tcnt;
/* IS nn A RangeGenerate NODE AND THE ONLY NODE IN THE GENERATOR */
nn = n->F_GEN->G_NODES;
if ( nn == NULL || nn->nsucc != NULL ||
nn->type != IFRangeGenerate )
continue;
/* FIND THE FIRST SELECT HAVING AN INVARIANT TEST */
for ( nn = n->F_BODY->G_NODES; nn != NULL; nn = nn->nsucc ) {
if ( !IsSelect( nn ) )
continue;
/* IS THE SELECT TEST INVARIANT TO n */
i = nn->S_TEST->imp;
if ( IsConst( i ) || !IsSGraph( i->src ) ||
(i = FindImport( nn, i->eport )) == NULL || IsConst( i ) ||
!IsSGraph( i->src ) || !IsImport( n, i->eport ) )
continue;
break;
}
if ( nn == NULL )
continue;
/* RETURN FANOUT NOT ALLOWED! */
for ( i = n->F_RET->imp; i != NULL; i = i->isucc )
if ( i->esucc != NULL )
break;
if ( i != NULL )
continue;
/* MAKE SURE INVERSION WILL NOT BLOCK BUILD-IN-PLACE ANALYSIS AND */
/* INTRODUCE COPYING: f := for ...; c := addh(f,v); d := addl(f,v); */
/* e := f || ...; */
for ( i = n->F_RET->imp; i != NULL; i = i->isucc ) {
switch ( i->src->type ) {
case IFAGather:
goto MoveOn;
case IFReduce:
case IFRedLeft:
case IFRedRight:
case IFRedTree:
if ( i->src->imp->CoNsT[0] == REDUCE_CATENATE )
goto MoveOn;
break;
default:
break;
}
continue;
MoveOn:
for ( e = n->exp; e != NULL; e = e->esucc ) {
if ( e->eport != i->iport )
continue;
if ( e->dst->type == IFAAddH )
if ( e->iport == 1 )
break;
if ( e->dst->type == IFAAddL )
if ( e->iport == 1 )
break;
if ( e->dst->type == IFACatenate )
break;
}
if ( e != NULL )
break;
}
if ( i != NULL )
continue;
/* IS n AN INNER LOOP? */
if ( !IsInnerLoop( n->F_BODY ) )
continue;
/* OK, DO IT! */
if (RequestInfo(I_Info1, info)) {
DYNEXPAND(printinfo,printbuf,printlen,printcount,char,printlen+300);
printlen += (SPRINTF(printinfo + printlen,
" Inverting loop %d at line %d, funct %s, file %s\n",
n->ID, n->line, n->funct, n->file), strlen(printinfo + printlen));
printlen += (SPRINTF(printinfo + printlen,
" with loop %d at line %d, funct %s, file %s\n\n",
nn->ID, nn->line, nn->funct, nn->file), strlen(printinfo + printlen));
}
DoTheInversion( n, nn );
invcnt++;
Tcnt++;
}
}
/**************************************************************************/
/* GLOBAL ************** If1Invert ************************/
/**************************************************************************/
/* PURPOSE: INVERT CANDIDATE LOOPS IN ALL FUNCTION GRAPHS. */
/**************************************************************************/
void If1Invert()
{
register PNODE f;
for ( f = glstop->gsucc; f != NULL; f = f->gsucc )
InvertLoops( f );
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks