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

Download this file

650 lines (517 with data), 21.2 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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/**************************************************************************/
/* FILE ************** opt.c ************************/
/**************************************************************************/
/* Author: Dave Cann */
/* Update: Patrick Miller -- Ansi support (Dec 2000) */
/* Copyright (C) University of California Regents */
/**************************************************************************/
/*
* $Log:
*
* Revision 12.7 1992/11/04 22:04:59 miller
* Initial revision
*
* Revision 12.7 1992/10/21 18:08:39 miller
* Initial RCS Version by Cann
*/
/**************************************************************************/
#include "world.h"
FILE *input = 0; /* IF1 INPUT FILE POINTER */
FILE *output = 0; /* IF1 OUTPUT FILE POINTER */
FILE *infoptr; /* IF1 INFO OUTPUT FILE POINTER */
char infofile[200];
char *program = "if1opt"; /* PROGRAM NAME */
static int norm = TRUE; /* PERFORM GRAPH NORMALIZATION? */
static int fission = TRUE; /* PERFORM RECORD AND ARRAY FISSION? */
static int cascade = TRUE; /* Look for loop test cascades */
static int invar = TRUE; /* PERFORM LOOP INVARIANT REMOVAL? */
int Oinvar = TRUE;
static int cse = TRUE; /* PERFORM CSE? */
static int gcse = TRUE; /* PERFORM GLOBAL CSE? */
int tgcse = TRUE; /* TRY AND FORCE GCSE IMPORVEMENTS? */
static int fold = TRUE; /* PERFORM CONSTANT FOLDING? */
static int dead = TRUE; /* PERFORM DEAD CODE REMOVAL? */
static int InLineExpansion = TRUE; /* PERFORM INLINE EXPANSION? */
int intrinsics = FALSE; /* Fold constants in math intrinsics */
int inlineall = FALSE; /* INLINE EVERYTHING BUT REQUESTS? */
int inter = FALSE; /* INLINE EXPAND IN INTERACTIVE MODE? */
int AggressiveVectors = FALSE; /* Aggressive fusion of vector loops */
int explode = FALSE; /* EXPLODE FORALL NODES? */
static int explodeI = FALSE; /* EXPLODE ONLY INNERMOST FORALL NODES? */
static int strip = TRUE; /* DO RETURN NODE STRIPPING? */
int dope = TRUE; /* PEFORM DOPE VECTOR OPTIMIZATIONS */
int amove = TRUE; /* PERFORM ANTI-MOVEMENT */
int asetl = FALSE; /* REMOVE UNNECESSARY ASetL NODES? */
int ifuse = TRUE; /* PERFORM FORALL FUSION? */
int sfuse = TRUE; /* PERFORM SELECT FUSION? */
int dfuse = TRUE; /* PERFORM FORALL DEPENDENT FUSION? */
int info = FALSE; /* DUMP OPTIMIZATION INFORMATION? */
int sgnok = TRUE; /* ALLOW SIGNED ARITHMETIC CONSTANTS? */
int slfis = TRUE; /* PERFORM STREAM LOOP FISSION? */
int native = FALSE; /* FLAG NODES NOT SUPPORTED IN NATIVE */
int split = TRUE; /* PERFORM FORALL SPLITTING? */
int invert = TRUE; /* PERFORM LOOP INVERSION? */
int vec = FALSE; /* VECTOR MODE? */
int concur = FALSE; /* CONCURRENT MODE? */
int cRay = FALSE; /* COMPILING FOR THE CRAY? */
int alliantfx = FALSE; /* COMPILING FOR THE ALLIANT? */
int agcse = FALSE; /* DO ANTI-GLOBAL CSE? */
int DeBuG = FALSE; /* OPT FOR PROGRAM DEBUGGING? */
int noassoc = FALSE; /* DISABLE ASSOCIATIVE TRANSFORMS */
int normidx = TRUE; /* NORMALIZE ARRAY INDEXING OPERATIONS? */
int fchange = TRUE; /* WAS A FUSION DONE? */
int glue = FALSE; /* ELIMINATE DEAD FUNCTION CALLS? */
int prof = FALSE; /* PROFILE THE OPTIMIZER? */
static char istmp[100]; /* CSU-IF1 OPTIMIZATION STAMP COMMENT STRING */
static char *ofile = NULL; /* NAME OF THE OUTPUT FILE */
/**************************************************************************/
/* LOCAL ************** ParseCommandLine ************************/
/**************************************************************************/
/* PURPOSE: PARSE THE COMMAND LINE argv CONTAINING argc ENTRIES. THE 1ST */
/* ENTRY (argv[0]) IS IGNORED. IF AN ARGUMENT DOES NOT BEGIN */
/* WITH A DASH, IT IS CONSIDERED THE NAME OF A FILE. THE FIRST */
/* ENCOUNTERED FILE IS FOR IF1 INPUT. THE SECOND ENCOUNTERED */
/* FILE IS FOR IF1 OUTPUT. ANY OTHER FILES ON THE COMMAND LINE */
/* CAUSE AN ERROR MESSAGE TO BE PRINTED. */
/* */
/* FILES: */
/* 0: -> IF1 monolith */
/* 1: -> Optimized IF1 */
/* */
/* OPTIONS: */
/* - -> Skip a standard file (in, out, etc..) */
/* -a -> DO ONLY NORMALIZATION AND DEAD CODE REMOVAL */
/* -c -> NO CSE */
/* -d -> NO DEAD CODE REMOVAL */
/* -e -> FLAG NODES ONLY SUPPORTED BY DI */
/* -f -> NO CONSTANT FOLDING */
/* -g -> NO GLOBAL CSE */
/* -j -> Do not do select loop fusion */
/* -i -> GENERATE LISTING OF GATHERED INFO */
/* -i<num> -> Generate more listing of gathered info */
/* -l -> ENABLE SETL REMOVAL */
/* -n -> NO NORMALIZATION */
/* -p<num> -> Apply dynamic patch <num> */
/* -r -> NO RECORD FISSION */
/* -s -> SIGNED CONSTANTS AREN'T ALLOWED */
/* -t -> DO INTERACTIVE EXPANSION */
/* -u -> NO FORALL FUSION */
/* -v -> NO INVARIANT MOVEMENT */
/* -w -> Supress warnings messages */
/* -x -> NO EXPANSION */
/* -y -> NO STREAM LOOP FISSION */
/* -z -> Do not do dependent loop fusion */
/* -A -> COMPILING FOR THE ALLIANT */
/* -AggV -> DO AGGRESSIVE FUSION of VECTOR LOOPS */
/* -C -> COMPILING FOR THE CRAY XMP */
/* -D -> Don't perform dope vector optimizations */
/* -G -> DO ANTI-GLOBAL CSE */
/* -I -> Generate vector information listing */
/* -I<num> -> Generate more vector information listing */
/* -M -> Fold constants in math intrinsics */
/* -N -> DON'T NORMALIZE ARRAY INDEXING */
/* -R -> Compiling for concurrent computation */
/* -S -> NO FORALL SPLITTING */
/* -T -> Explode forall nodes */
/* -U# -> FORALL ITERATION UNROLLING VALUE */
/* -V -> Do not remove invariants in outer level loops */
/* -W -> Do profiling */
/* -X -> Vectorize */
/* -Y -> Allow constant folding and assoc. transforms. */
/* -Z -> Do not perform loop inversion optimization */
/* -1 -> DON'T FORCE GCSE IMPORVEMENTS */
/* -3 -> Turn on debugging */
/* -6 -> Strip return nodes */
/* -8 -> Do not eliminate dead function calls */
/* -9 -> Do not perform anti-movement */
/* -@# -> Assumed iteration count */
/* -+ -> Explode all forall loops */
/* -$ -> Inline all (nonrecursive) functions */
/* -# f -> DON'T INLINE FUNCTION f */
/**************************************************************************/
static void ParseCommandLine( argc, argv )
int argc;
char **argv;
{
register char *c;
register int fmode = 0;
register int idx;
register FILE *fd;
for ( idx = 1; idx < argc; ++idx ) {
if ( *(c = argv[ idx ]) != '-' ) {
switch ( fmode ) {
case 0:
if ( (fd = fopen( c, "r" )) == NULL )
Error2( "CAN'T OPEN", c );
input = fd;
AssignSourceFileName( c );
fmode++;
break;
case 1:
ofile = c;
fmode++;
break;
default:
Error2( "ILLEGAL ARGUMENT", c );
}
continue;
}
switch ( *( ++c ) ) {
/* ------------------------------------------------------------ */
/* Suppress warning messages */
/* ------------------------------------------------------------ */
case 'w':
Warnings = FALSE;
break;
/* ------------------------------------------------------------ */
/* Apply dynamic patch */
/* ------------------------------------------------------------ */
case 'p':
if ( *c ) AddPatch(atoi(c));
break;
case 'W':
prof = TRUE;
break;
case 'x':
InLineExpansion = FALSE;
break;
case '#':
noin[++noincnt] = LowerCase( argv[++idx], FALSE, FALSE );
break;
case '6':
strip = FALSE;
break;
case 'N':
normidx = FALSE;
break;
case 'M':
intrinsics = TRUE;
break;
case '1':
tgcse = FALSE;
break;
case '\0':
fmode++;
break;
case 'S':
split = FALSE;
break;
case 'Z':
invert = FALSE;
break;
case 'V':
Oinvar = FALSE;
break;
case 'e':
native = TRUE;
break;
case 'D':
dope = FALSE;
break;
case 'a':
maxunroll = 0;
fission = FALSE;
invar = FALSE;
Oinvar = FALSE;
cse = FALSE;
gcse = FALSE;
tgcse = FALSE;
fold = FALSE;
strip = FALSE;
dope = FALSE;
ifuse = FALSE;
sfuse = FALSE;
dfuse = FALSE;
split = FALSE;
invert = FALSE;
normidx = FALSE;
break;
case 'Y':
fold = FALSE;
noassoc = TRUE;
break;
case 'y':
slfis = FALSE;
break;
case 'n':
norm = FALSE;
break;
case 'l':
asetl = TRUE;
break;
case 'A':
if ( strcmp(c,"AggV") == 0 ) {
AggressiveVectors = TRUE;
} else {
alliantfx = TRUE;
}
break;
case 'C':
cRay = TRUE;
break;
case 'X':
vec = TRUE;
break;
case 'R':
concur = TRUE;
break;
case 'U':
if ( maxunroll == 0 )
break;
maxunroll = atoi( c + 1 );
if ( maxunroll < 0 )
maxunroll = 0;
break;
case 'r':
fission = FALSE;
break;
case 'v':
invar = FALSE;
break;
case 'c':
cse = FALSE;
break;
case 'G':
agcse = TRUE;
break;
case 'g':
gcse = FALSE;
break;
case 'f':
fold = FALSE;
break;
case '8':
glue = TRUE;
break;
case 'd':
dead = FALSE;
break;
case 'j':
sfuse = FALSE;
break;
case 'u':
ifuse = FALSE;
break;
case 'z':
dfuse = FALSE;
break;
case '3':
DeBuG = TRUE;
break;
case '9':
amove = FALSE;
break;
case '@':
iter = (double) atoi( (c+1) );
break;
case 'i':
info = TRUE;
if ( isdigit((int)(c[1])) ) info=atoi(c+1);
break;
case 'F' :
strcpy (infofile, c+1);
break;
case '+':
explode = TRUE;
explodeI = TRUE;
break;
case 'T':
explode = TRUE;
break;
case '$':
inlineall = TRUE;
break;
case 't':
inter = TRUE;
break;
case 's':
sgnok = FALSE;
break;
default:
Error2( "ILLEGAL ARGUMENT", --c );
}
}
}
/**************************************************************************/
/* GLOBAL ************** main ************************/
/**************************************************************************/
/* PURPOSE: IMPROVE THE QUALITY OF THE IF1 INPUT FILE BY PERFORMING THE */
/* FOLLOWING OPTIMIZATIONS: GRAPH NORMALIZATION, GRAPH EXPANSION,*/
/* INVARIANT REMOVAL, RECORD FISSION, CSE, GLOBAL CSE, CONSTANT */
/* FOLDING, AND DEAD CODE REMOVAL. IF THE INPUT IS NOT DATA FLOW */
/* ORDERED OR CONTAINS NoOp NODES (INSERTED BY THE LLNL UTILITY */
/* if1offset), AN ERROR MESSAGE IS PRINTED AND EXECUTION STOPS. */
/* IF GRAPH NORMALIZATION, LOOP FISSION, AND DEAD CODE REMOVAL */
/* ARE PERFORMED, A 'N' STAMP IS ADDED TO THE OUTPUT. THE 'I' */
/* STAMP IS ADDED TO DOCUMENT OTHER PERFORMED OPTIMIZATIONS. */
/* NOTE, IF THE INPUT FILE NAME IS THE SAME AS THE OUTPUT FILE */
/* NAME, THE CONTENTS OF THE INPUT FILE IS OVERWRITTEN. */
/**************************************************************************/
int main( argc, argv )
int argc;
char **argv;
{
register FILE *fd;
register int i;
register int c;
/* fix by dj raymond 25 nov 2000 */
input = stdin;
output = stdout;
ParseCommandLine( argc, argv );
if ( DeBuG ) {
InLineExpansion = fission = split = fold = vec = concur = FALSE;
inlineall = invert = dfuse = ifuse = gcse = dope = FALSE;
strip = explode = explodeI = cse = invar = FALSE;
maxunroll = 0;
}
if (RequestInfo(I_Info1, info))
if ((infoptr = fopen (infofile, "a")) == NULL)
infoptr = stderr;
StartProfiler();
If1Read();
(void)fclose( input ); /* AS IT MIGHT BE THE SOON TO BE WRITTEN FILE */
StopProfiler( "If1Read" );
if ( !IsStamp( DFORDERED ) )
Error1( "IF1 INPUT IS NOT DFOrdered" );
if ( IsStamp( OFFSETS ) )
Error1( "OFFSETS ASSIGNED---NoOp NODES NOT IMPLEMENTED" );
/* START BY CLEANING EVERYTHING UP! */
StartProfiler();
if ( dead ) If1Clean();
StopProfiler( "If1Clean" );
StartProfiler();
If1Reduce();
StopProfiler( "If1Reduce" );
StartProfiler();
if ( norm ) If1Normalize();
StopProfiler( "If1Normalize" );
/* if ( RequestInfo(I_Info1,info) ) {
FPRINTF( infoptr, "\n****GRAPH NORMALIZATION AND EXPANSION\n" );
If1Count( "BEFORE EXPANSION AFTER NORMALIZATION" );
} */
/* DO IT NOW SO LOOP FUSION DOES NOT UNDO STREAM LOOP FISSION */
if ( norm && dead && native && sgnok )
AddStamp( NORMALIZED, " CSU -> NORMALIZED: native, dead" );
if ( RequestInfo(I_Info1,info) )
FPRINTF( infoptr, "**** SIMPLE OPTIMIZATIONS\n\n" );
StartProfiler();
if ( InLineExpansion ) If1Inline();
CallReorder();
StopProfiler( "If1Inline" );
/* ------------------------------------------------------------ */
/* Give ID numbers to all compound nodes for later reference */
AssignCompoundIDs();
if ( RequestInfo(I_Info1,info) ) {
/*If1Count( "AFTER GRAPH NORMALIZATION AND EXPANSION" );*/
}
/* if ( RequestInfo(I_Info1,info)) {
WriteLoopMap( "BEFORE FUSION OPTIMIZATIONS" );
(void)fputc('\n',infoptr);
} */
/* INITIALIZE DEAD NODE COUNTERS SO NOT TO REFLECT ACTION TAKEN DURING */
/* NORMALIZATION AND GRAPH EXPANSION */
ikcnt = unnec = unused = dscnt = dccnt = agcnt = 0;
/* OK, CLEAN EVERYTHING AGAIN! */
StartProfiler();
if ( dead )
If1Clean();
StopProfiler( "If1Clean" );
/* DO EVERYTHING 6 TIMES */
for ( i = 0; i <= 5; i++ ) {
StartProfiler();
if ( fission ) If1Fission();
StopProfiler( "If1Fission" );
StartProfiler();
if ( split ) If1Split();
StopProfiler( "If1Split" );
StartProfiler();
if ( fold ) If1Fold();
StopProfiler( "If1Fold" );
StartProfiler();
if ( invar ) If1Invar();
StopProfiler( "If1Invar" );
StartProfiler();
if ( vec && i == 2 ) If1Vec();
StopProfiler( "If1Vec" );
StartProfiler();
if ( (vec || concur) && i == 2 ) If1Par();
StopProfiler( "If1Par" );
StartProfiler();
if ( invert && i != 0 ) If1Invert();
StopProfiler( "If1Invert" );
/* DO CSE AND FUSION UNTIL NO MORE CHANGES */
fchange = TRUE;
c = 0;
while ( fchange ) {
c++;
StartProfiler();
If1Cse( cse, strip && (c == 1) && (i == 4) );
StopProfiler( "If1Cse" );
fchange = FALSE;
StartProfiler();
if ( dfuse && i == 4 ) If1DFusion();
StopProfiler( "If1DFusion" );
StartProfiler();
if ( ifuse && i == 4 ) If1IFusion();
StopProfiler( "If1IFusion" );
}
StartProfiler();
if ( gcse ) If1GCse();
StopProfiler( "If1GCse" );
StartProfiler();
if ( dope && i == 1 ) If1Dope();
StopProfiler( "If1Dope" );
StartProfiler();
if ( maxunroll > 0 && i == 2 ) If1Unroll();
StopProfiler( "If1Unroll" );
StartProfiler();
if ( explode && i == 3 ) If1Explode( explodeI );
StopProfiler( "If1Explode" );
/* Test cascadence */
StartProfiler();
if ( cascade ) If1TestCascade();
StopProfiler( "If1TestCascade" );
StartProfiler();
if ( dead ) If1Clean();
StopProfiler( "If1Clean" );
}
if ( RequestInfo(I_Info1,info) ) {
/*WriteLoopMap( "AFTER FUSION OPTIMIZATIONS" );*/
WriteFusionInfo();
WriteReduceInfo();
WriteFissionInfo();
WriteUnrollInfo();
WriteSplitInfo();
/* WriteFoldInfo();
WriteInvarInfo();
WriteCseInfo();
WriteGCseInfo();*/
WriteConcurInfo();
WriteInvertInfo();
WriteDopeInfo();
WriteExplodeInfo();
WriteCleanInfo();
/*If1Count( "AFTER MACHINE INDEPENDENT OPTIMIZATIONS" );*/
}
/*if ( RequestInfo(I_Info1,info) )
WriteLoopMap( "AFTER FUSION OPTIMIZATIONS" );*/
SPRINTF( istmp, " CSU -> IF1 OPTS:%s%s%s%s%s%s%s%s%s%s",
( InLineExpansion)?" inline" : "", ( invar )? " invar" : "",
( fission )? " fiss" : "", ( cse )? " cse" : "",
( ifuse && cse )? " fuse" : "", ( gcse )? " gcse" : "",
( asetl && norm )? " asetl" : "", ( fold )? " fold" : "",
( sgnok )? " sgnok" : "", ( slfis )? " sfiss" : "" );
AddStamp( IF1OPTIMIZED, istmp );
if (RequestInfo(I_Info1, info) && infoptr!=stderr)
fclose (infoptr);
/* OPEN THE OUTPUT FILE AND WRITE THE OPTIMIZED PROGRAM */
if ( ofile != NULL ) {
if ( (fd = fopen( ofile, "w" )) == NULL )
Error2( "CAN'T OPEN", ofile );
output = fd;
}
StartProfiler();
If1Write();
StopProfiler( "If1Write" );
return OK;
}

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

Sign up for the SourceForge newsletter:





No, thanks