/
main.c
1564 lines (1424 loc) · 42.2 KB
/
main.c
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1994-2018, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/** \file main.c
\brief main program and initialization routines for fortran front-end
*/
#include "gbldefs.h"
#include <stdbool.h>
#include "flang/ArgParser/arg_parser.h"
#include "error.h"
#if !defined(TARGET_WIN)
#include <unistd.h>
#endif
#include <time.h>
#include "global.h"
#include "symtab.h"
#include "dtypeutl.h"
#include "version.h"
#include "inliner.h"
#include "interf.h"
#include "semant.h"
#include "dinit.h"
#include "ast.h"
#include "lower.h"
#include "dbg_out.h"
#include "ccffinfo.h"
#include "x86.h"
#include "direct.h"
#include "optimize.h"
#include "transfrm.h"
#include "extern.h"
#include "commopt.h"
#include "scan.h"
#include "hlvect.h"
#define IPA_ENABLED 0
#define IPA_NO_ASM 0
#define IPA_COLLECTION_ENABLED 0
#define IPA_INHERIT_ENABLED 0
#define IPA_FUTURE_INHERIT_DISABLED 0
#define IPA_REPORT_ENABLED 0
/* static prototypes */
static void reptime(void);
static void add_debuglist(char *phasearg, char *dumparg);
static void do_debug(char *phase);
static void cleanup(void);
static void init(int argc, char *argv[]);
static void datastructure_reinit(void);
static void set_ipa_export_file(char *name);
static void set_ipa_import_mode(void);
static void set_ipa_import_offset(char *offset);
static void set_debug(LOGICAL value);
static void set_debug_symbol(LOGICAL value);
static void set_debug_line(LOGICAL value);
static void do_set_tp(char *tp);
static void fini(void);
static void mkDwfInfoFilename(void);
/* ******************************************************************** */
/* Below are definitions/static variables required by main function */
static int saveoptflag;
static int savevectflag;
static int savex8flag;
static int saverecursive;
static LOGICAL has_accel_code = FALSE;
static action_map_t *phase_dump_map;
#if DEBUG
static int debugfunconly = -1;
#endif
static LOGICAL ipa_import_mode = FALSE;
static char *ipa_export_file = NULL;
static BIGUINT ipa_import_offset = 0;
static char *who[] = {"init", "parser", "bblock", "vectorize", "optimize",
"schedule", "assemble", "xref", "unroll"};
#define _N_WHO (sizeof(who) / sizeof(char *))
static INT xtimes[_N_WHO];
static LOGICAL postprocessing = TRUE;
/* Feature names for Fortran front-end */
#if defined(TARGET_LINUX_X8664)
static char *feature = "flang";
static char *os = "lin";
static char *accel = NULL;
#elif defined(TARGET_WIN_X8664)
static char *feature2 = "pgi-f95-win64";
static char *feature = "pgfortran";
static char *os = "win";
static char *accel = NULL;
#elif defined(TARGET_OSX_X8664)
static char *feature2 = "pgi-f95-osx64";
static char *feature = "pgfortran";
static char *os = "osx";
static char *accel = NULL;
#elif defined(OSF86)
static char *feature = "pgi-f95-osf32";
static char *os = NULL;
static char *accel = NULL;
#elif defined(TARGET_LLVM_POWER)
static char *feature2 = "pgi-f95-power";
static char *feature = "pgfortran";
static char *os = "lin";
static char *accel = NULL;
#else
static char *feature2 = "pgi-f95";
static char *feature = "pgfortran";
static char *os = "lin";
static char *accel = NULL;
#endif
/** Product name in debug output
*/
#define DNAME "F90"
#if DEBUG
static int dodebug = 0;
#define TR(str) \
if (dodebug) { \
fprintf(gbl.dbgfil, str); \
fflush(gbl.dbgfil); \
}
#define TR1(str) \
if (DBGBIT(0, 512)) \
dump_stg_stat(str)
#define DUMP(a) do_debug(a)
#else
#define TR(str)
#define TR1(str)
#define DUMP(a)
#endif /* DEBUG */
#define NO_FLEXLM
/** \brief Fortran front-end main entry
\param argc number of command-line arguments
\pram argv array of command-line argument strings
*/
int
main(int argc, char *argv[])
{
int savescope, savecurrmod = 0;
getcpu();
init(argc, argv); /* initialize */
if (gbl.fn == NULL)
gbl.fn = gbl.src_file;
#if DEBUG
if (debugfunconly > 0)
dodebug = 0;
#endif
saveoptflag = flg.opt;
savevectflag = flg.vect;
savex8flag = flg.x[8];
saverecursive = flg.recursive;
if (IPA_INHERIT_ENABLED && (flg.opt >= 2 || IPA_COLLECTION_ENABLED)) {
ipa_init();
}
gbl.findex = addfile(gbl.fn, NULL, 0, 0, 0, 1, 0);
if (ipa_export_file && ipa_import_mode) {
ipa_import_open(ipa_export_file, ipa_import_offset);
}
if (IPA_ENABLED && ipa_export_file && !ipa_import_mode) {
/* export the program unit for IPA recompilation */
ipa_export_open(ipa_export_file);
}
if (gbl.srcfil == NULL) {
if (!ipa_import_mode) {
finish();
}
}
do { /* loop once for each user program unit */
#if DEBUG
if (debugfunconly > 0) {
if (debugfunconly == gbl.func_count + 1)
dodebug = 1;
else
dodebug = 0;
}
#endif
reinit();
errini();
if (ipa_export_file && ipa_import_mode && gbl.func_count == 0) {
ipa_import_highpoint();
}
if (IPA_ENABLED && ipa_export_file && !ipa_import_mode &&
gbl.func_count == 0) {
ipa_export_highpoint();
}
xtimes[0] += getcpu();
if (ipa_export_file && ipa_import_mode) {
ipa_import();
if (gbl.eof_flag & 2)
break;
} else {
TR(DNAME " PARSER begins\n")
parser(); /* parse and do semantic analysis */
set_tag();
}
gbl.func_count++;
ccff_open_unit_f90();
if (gbl.internal <= 1) {
gbl.outersub = 0;
gbl.outerentries = 0;
}
savescope = stb.curr_scope;
if (gbl.currsub) {
if (SCOPEG(gbl.currsub)) {
stb.curr_scope = SCOPEG(gbl.currsub);
if (STYPEG(stb.curr_scope) != ST_ALIAS ||
SYMLKG(stb.curr_scope) != gbl.currsub) {
stb.curr_scope = gbl.currsub;
}
} else {
stb.curr_scope = gbl.currsub;
}
}
TR1("- after semant");
xtimes[1] += getcpu();
DUMP("parser");
if (gbl.rutype == RU_BDATA) {
/* a module? */
if (has_cuda_data())
has_accel_code = TRUE;
}
if (gbl.currsub == 0) {
if (IPA_ENABLED && ipa_export_file && !ipa_import_mode) {
/* export the program unit for IPA recompilation */
ipa_export_endmodule();
}
continue; /* end of a module */
}
if (CUDAG(gbl.currsub) & (CUDA_GLOBAL | CUDA_DEVICE)) {
/* remember that this routine needs a constructor */
has_accel_code = TRUE;
}
savecurrmod = gbl.currmod;
#if DEBUG
if (DBGBIT(5, 1))
symdmp(gbl.dbgfil, DBGBIT(5, 8));
if (DBGBIT(5, 2))
dump_std();
if (DBGBIT(5, 16))
dmp_dtype();
#endif
if (IPA_ENABLED && ipa_export_file && !ipa_import_mode) {
/* export the program unit for IPA recompilation */
ipa_export();
}
#if DEBUG
if (DBGBIT(4, 256))
dump_ast();
#endif
if (IPA_INHERIT_ENABLED && gbl.rutype != RU_BDATA) {
int func;
ipa_startfunc(gbl.currsub);
ipa_header1(gbl.currsub);
ipa_header2(gbl.currsub);
}
postprocessing = FALSE;
if (gbl.maxsev < 3 && !DBGBIT(2, 4)) {
postprocessing = TRUE;
flg.ipa |= 0x20;
if (XBIT(57, 0x2000) && !flg.inliner) {
/* try to eliminate unused common blocks here */
eliminate_unused_variables(1);
DUMP("staticunused");
}
/* by default, generate data initialization inline. */
if (gbl.rutype != RU_BDATA) {
direct_rou_load(gbl.currsub);
if (flg.opt > 1 && !XBIT(47, 0x40000000)) {
if (sem.stats.allocs > 800 && sem.stats.nodes > 1000) {
direct_rou_setopt(gbl.currsub, 1);
/*
* Also, inhibit sectfloat() which is enabled with
* -fast or -O2 or greater.
*/
flg.x[70] &= (~0x400);
}
}
ili_lpprg_init();
TR(DNAME " BBLOCK begins\n");
has_accel_code |= bblock();
TR1("- after bblock");
DUMP("bblock");
if (flg.inliner) {
TR(DNAME " INLINER begins\n");
#if DEBUG
if (flg.x[29] == 0 || flg.x[29] == gbl.func_count)
#endif
inliner();
DUMP("inliner");
TR1("- after inliner");
}
if (flg.opt >= 2 && XBIT(50, 0x40)) {
unconditional_branches();
DUMP("unconditional");
}
if (flg.opt >= 2 && !XBIT(47, 0x20)) {
TR(DNAME " OPTIMIZE_ALLOC begins\n");
optimize_alloc();
DUMP("optalloc");
TR1("- after optimize_alloc");
}
if (IPA_ENABLED) {
ipasave();
if (IPA_NO_ASM) {
ipasave_endfunc();
direct_rou_end();
continue;
}
}
if (IPA_INHERIT_ENABLED && !IPA_FUTURE_INHERIT_DISABLED) {
if (!IPA_ENABLED) {
fill_ipasym();
}
ipa();
DUMP("ipa");
if (IPA_Vestigial) {
ipasave_endfunc();
if (gbl.internal == 1) {
ipa_set_vestigial_host(); /* interf.c */
save_host_state(0x2 + (ipa_import_mode ? 0x20 : 0));
gbl.outersub = gbl.currsub;
gbl.outerentries = gbl.entries;
}
(void)summary(FALSE, FALSE);
continue;
}
}
/* infer array alignments */
TR(DNAME " PROCESS_ALIGN begins\n");
trans_process_align();
TR1("- after process_align");
DUMP("process-align");
if (flg.opt >= 2) {
if (XBIT(53, 2)) {
points_to_anal();
DUMP("pointsto");
}
pstride_analysis();
DUMP("pstride");
}
if (!XBIT(49, 1)) {
TR(DNAME " TRANSFORMER begins\n");
transform();
DUMP("transform");
TR1("- after transform");
forall_init();
if (!XBIT(49, 0x20)) {
if (flg.opt >= 2 && !XBIT(47, 0x02)) {
TR(DNAME " COMMUNICATIONS pre-OPTIMIZER begins\n");
comm_optimize_pre();
DUMP("comm-analyze-pre");
TR1("- after comm pre-optimizer");
}
TR(DNAME " COMMUNICATIONS ANALYZER begins\n");
comm_analyze();
DUMP("comm-analyze");
TR1("- after comm_analyze");
TR(DNAME " CALL ANALYZER begins\n");
call_analyze();
DUMP("call-analyze");
TR1("- after call_analyze");
if (flg.opt >= 2 && !XBIT(47, 0x01)) {
TR(DNAME " COMMUNICATIONS post-OPTIMIZER begins\n");
comm_optimize_post();
DUMP("comm-optimize-post");
TR1("- after comm post-optimizer");
}
if (flg.opt >= 2 && !XBIT(47, 0x08)) {
TR(DNAME " COMMUNICATIONS hoisting begins\n");
comm_invar();
DUMP("comm-invar");
TR1("- after comm_invar");
}
TR(DNAME " COMMUNICATIONS GENERATOR begins\n");
comm_generator();
DUMP("comm-generator");
TR1("- after comm_generator");
}
TR(DNAME " CONVERT_FORALL begins\n");
convert_forall();
DUMP("convert-forall");
TR1("- after convert_forall");
TR(DNAME " CONVERT_OUTPUT begins\n");
convert_output();
TR1("- after convert_output");
DUMP("convert-output");
}
if (XBIT(70, 0x400) || XBIT(47, 0x400000)
) {
optimize(1);
DUMP("optimize0");
TR1("- after optimize0");
}
if (XBIT(70, 0x400)) {
sectfloat();
DUMP("sectfloat");
}
if (XBIT(47, 0x400000) || flg.opt >= 2 || XBIT(163, 1)
) {
sectinline();
DUMP("sectinline");
}
if (XBIT(70, 0x18)) {
linearize_arrays();
DUMP("linearize");
}
if (!XBIT(70, 0x40)) {
DUMP("bredundss");
redundss();
DUMP("redundss");
}
if (flg.opt >= 2 && !XBIT(47, 0x1000)) {
TR(DNAME " OPTIMIZER begins\n");
optimize(0);
DUMP("optimize");
TR1("- after optimize");
}
if (IPA_ENABLED) {
ipasave_endfunc();
}
if (IPA_REPORT_ENABLED) {
ipa_report();
}
direct_rou_end();
if (flg.opt >= 2 && XBIT(53, 2)) {
fini_points_to_all();
}
} else { /* gbl.rutype == RU_BDATA */
direct_rou_load(gbl.currsub);
if (IPA_ENABLED) {
ipasave();
}
merge_commons();
if (XBIT(55, 2)) {
cleanup();
goto skip_compile;
}
/* block data must be transformed so that common blocks
* get handled -- lfm
*/
/* infer array alignments */
TR("Blkdata -- " DNAME " PROCESS_ALIGN begins\n");
trans_process_align();
DUMP("process-align");
TR1("- after process_align");
if (!XBIT(49, 1)) {
TR("Blkdata -- " DNAME " TRANSFORMER begins\n");
transform();
DUMP("transform");
TR1("- after transform");
}
}
#if DEBUG
if (XBIT(57, 0x100)) {
renumber_lines();
}
#endif
if (XBIT(57, 0x2000)) {
DUMP("bunused");
eliminate_unused_variables(2);
DUMP("unused");
}
DUMP("before-output");
lower(0);
if (gbl.internal == 1) {
save_host_state(0x2 + (ipa_import_mode ? 0x20 : 0));
}
DUMP("output");
if (gbl.rutype != RU_BDATA && flg.opt >= 2 && XBIT(53, 2)) {
fini_pstride_analysis();
}
#if DEBUG
if (DBGBIT(5, 4))
symdmp(gbl.dbgfil, DBGBIT(5, 8));
if (DBGBIT(5, 16))
dmp_dtype();
#endif
} else { /* if( gbl.maxsev < 3 && !DBGBIT(2, 4) ) */
if (gbl.internal == 1) {
save_host_state(0x2);
}
} /* if( gbl.maxsev < 3 && !DBGBIT(2, 4) ) */
if (flg.xref) {
xref(); /* write cross reference map */
xtimes[7] += getcpu();
}
skip_compile:
(void)summary(FALSE, FALSE);
errini();
if (gbl.internal == 1) {
gbl.outersub = gbl.currsub;
gbl.outerentries = gbl.entries;
}
stb.curr_scope = savescope;
ccff_close_unit_f90();
} while (!gbl.eof_flag);
finish(); /* finish does not return */
return 0; /* never reached */
}
/* ************************************************************** */
/*
* static structures/variables used in command line processing/init() function:
*/
#define __ATOI(s, p, l, r) _atoi(s, p, l)
static char *objectfile;
static char *outfile_name;
LOGICAL fpp_ = FALSE;
static LOGICAL no_specified;
static int preproc = -1; /* not specified */
/* ***************************************************************** */
/*
* Various types of AST dumpers, wrapper functions
*/
static void
dump_stds(void)
{
dstds(0, 0);
}
static void
dump_sstds(void)
{
dsstds(0, 0);
}
static void
dump_stdps(void)
{
dstdps(0, 0);
}
/** \brief Dump symbols
*/
static void
dump_symbols(void)
{
dsyms(0, 0);
}
/** \brief Dump all symbols
*/
static void
dump_all_symbols(void)
{
dsyms(1, 0);
}
/** \brief Dump symbols from current source file
*/
static void
dump_current_symbols(void)
{
dsyms(stb.firstosym, 0);
}
/** \brief Yet another symbol table dumper
*/
static void
dump_old_symbols(void)
{
symdmp(gbl.dbgfil, 0);
}
/** \brief Dump memory area
*/
static void
report_area(void)
{
reportarea(0);
}
static char *current_phase;
/** \brief Dump stg statistics
*/
static void
dump_stg_stats(void)
{
dump_stg_stat(current_phase);
}
/**
* \brief Initialize Fortran frontend at the beginning of compilation.
*/
static void
init(int argc, char *argv[])
{
int argindex;
char *argstring;
int indice, next;
char *sourcefile;
char *stboutfile;
int nosuffixcheck = 0;
char *listfile;
char *cppfile;
char *tempfile;
char *asmfile;
int i;
int def_count = 0; /* number of -def switches */
int idir_count = 0; /* number of -idir switches */
INT qval1;
INT qval2;
int val_follows;
LOGICAL dbgflg;
char *dbgfile = NULL;
LOGICAL errflg;
FILE *fd;
int exlib_flag = 0;
char *file_suffix;
int copy_curr_file = 1;
static struct {
char *nm; /* name, 0 = end of list */
int form; /* 0 = fixed, 1 = form */
int fpp; /* 0 = don't preprocess, 1 = preprocess */
} suffixes[] = {
{".hpf", 0, 0}, {".f", 0, 0}, {".F", 0, 1}, {".f90", 1, 0},
{".F90", 1, 1}, {".f95", 1, 0}, {".F95", 1, 1}, {".for", 0, 0},
{".fpp", 0, 1}, {0, 0, 0},
};
char *followval;
int followindex;
time_t now;
flg.freeform = -1;
file_suffix = ".f90"; /* default suffix for source files */
/*
* initialize error and symbol table modules in case error messages are
* issued:
*/
errini();
gbl.curr_file = NULL;
gbl.fn = NULL;
sym_init();
interf_init();
BZERO(&sem, SEM, 1);
/* fill in date and time */
time(&now);
strftime(gbl.datetime, sizeof gbl.datetime, "%m/%d/%Y %H:%M:%S",
localtime(&now));
dbgflg = FALSE;
errflg = FALSE;
sourcefile = NULL;
listfile = NULL;
cppfile = NULL;
objectfile = NULL;
asmfile = NULL;
outfile_name = NULL;
gbl.ipaname = NULL;
argindex = 0;
stboutfile = NULL;
flg.x[79] = 16; /* Hardwire XBIT(79,16): CSE DP loads for a distance of 16 */
flg.x[27] = -1; /* overlap not set */
if (argc < 2)
goto empty_cl;
char *tp; /* Target architecture */
char *omptp = NULL; /* OpenMP Target architecture */
int vect_val; /* Vectorizer settings */
char *modexport_val; /* Modexport file name */
char *modindex_val; /* Modindex file name */
char **module_dirs; /* Null-terminated list of module directories */
bool arg_preproc; /* Argument to turn preprocessor on and off */
bool arg_freeform; /* Argument to force free-form source */
bool arg_extend; /* Argument to force line extension */
bool arg_reentrant; /* Argument to enable generating reentrant code */
/* Create a datastructure of various dump actions and their names */
action_map_t *dump_map; /* Deallocated after arguments are parsed */
create_action_map(&dump_map);
add_action(dump_map, "ast", dump_ast);
add_action(dump_map, "dtype", dumpdts);
add_action(dump_map, "std", dump_stds);
add_action(dump_map, "sstd", dump_sstds);
add_action(dump_map, "stdp", dump_stdps);
add_action(dump_map, "sym", dump_symbols);
add_action(dump_map, "syms", dump_symbols);
add_action(dump_map, "symtab", dump_symbols);
add_action(dump_map, "allsym", dump_all_symbols);
add_action(dump_map, "stats", dump_stg_stats);
add_action(dump_map, "area", report_area);
add_action(dump_map, "olddtype", dmp_dtype);
add_action(dump_map, "odtype", dmp_dtype);
add_action(dump_map, "oldsym", dump_old_symbols);
add_action(dump_map, "osym", dump_current_symbols);
add_action(dump_map, "hsym", dump_current_symbols);
add_action(dump_map, "hsyms", dump_current_symbols);
add_action(dump_map, "common", dcommons);
add_action(dump_map, "commons", dcommons);
add_action(dump_map, "nast", dumpasts);
add_action(dump_map, "stdtree", dumpstdtrees);
add_action(dump_map, "stdtrees", dumpstdtrees);
add_action(dump_map, "shape", dumpshapes);
add_action(dump_map, "aux", dumplists);
/* Initialize the map that will be used by dump handler later */
create_action_map(&phase_dump_map);
arg_parser_t *arg_parser;
create_arg_parser(&arg_parser, true);
/* Register two ways for supplying source file argument */
register_filename_arg(arg_parser, &sourcefile);
register_string_arg(arg_parser, "src", &sourcefile, NULL);
/* Output file (.ilm) */
register_combined_bool_string_arg(arg_parser, "output", (bool *)&(flg.output),
&outfile_name);
/* Other files to input or output */
register_string_arg(arg_parser, "stbfile", &stboutfile, NULL);
register_string_arg(arg_parser, "modexport", &modexport_val, NULL);
register_string_arg(arg_parser, "modindex", &modindex_val, NULL);
register_string_arg(arg_parser, "qfile", &dbgfile, NULL);
/* Optimization level */
register_integer_arg(arg_parser, "opt", &(flg.opt), 1);
/* Allocate space for command line macro definitions */
flg.def = (char **)getitem(8, argc * sizeof(char *));
flg.undef = (char **)getitem(8, argc * sizeof(char *));
flg.idir = (char **)getitem(8, argc * sizeof(char *));
module_dirs = (char **)getitem(8, argc * sizeof(char *));
/* Command line macro definitions */
register_string_list_arg(arg_parser, "def", flg.def);
register_string_list_arg(arg_parser, "undef", flg.undef);
register_string_list_arg(arg_parser, "idir", flg.idir);
register_string_list_arg(arg_parser, "moddir", module_dirs);
/* x flags */
register_xflag_arg(arg_parser, "x", flg.x,
(sizeof(flg.x) / sizeof(flg.x[0])));
register_yflag_arg(arg_parser, "y", flg.x);
/* Debug flags */
register_qflag_arg(arg_parser, "q", flg.dbg,
(sizeof(flg.dbg) / sizeof(flg.dbg[0])));
register_action_map_arg(arg_parser, "qq", phase_dump_map, dump_map);
/* Other flags */
register_boolean_arg(arg_parser, "mp", (bool *)&(flg.smp), false);
register_string_arg(arg_parser, "fopenmp-targets", &omptp, NULL);
register_boolean_arg(arg_parser, "preprocess", &arg_preproc, true);
register_boolean_arg(arg_parser, "reentrant", &arg_reentrant, false);
register_integer_arg(arg_parser, "terse", &(flg.terse), 1);
register_inform_level_arg(arg_parser, "inform",
(inform_level_t *)&(flg.inform), LV_Inform);
register_boolean_arg(arg_parser, "hpf", (bool *)&(flg.hpf), true);
register_boolean_arg(arg_parser, "static", (bool *)&(flg.doprelink), true);
register_boolean_arg(arg_parser, "quad", (bool *)&(flg.quad), true);
register_boolean_arg(arg_parser, "freeform", &arg_freeform, false);
register_string_arg(arg_parser, "tp", &tp, NULL);
register_string_arg(arg_parser, "stdinc", &(flg.stdinc), (char *)1);
register_integer_arg(arg_parser, "vect", &(vect_val), 0);
register_boolean_arg(arg_parser, "standard", (bool *)&(flg.standard), false);
register_boolean_arg(arg_parser, "save", (bool *)&(flg.save), false);
register_boolean_arg(arg_parser, "extend", &arg_extend, false);
register_boolean_arg(arg_parser, "recursive", (bool *)&(flg.recursive),
false);
register_string_arg(arg_parser, "cmdline", &(flg.cmdline), NULL);
register_boolean_arg(arg_parser, "es", (bool *)&(flg.es), false);
register_boolean_arg(arg_parser, "pp", (bool *)&(flg.p), false);
/* Set values form command line arguments */
parse_arguments(arg_parser, argc, argv);
/* Direct debug output */
if (was_value_set(arg_parser, &(flg.dbg)) ||
was_value_set(arg_parser, phase_dump_map)) {
#if DEBUG
dodebug = 1;
#endif
if (dbgfile) {
gbl.dbgfil = fopen(dbgfile, "w");
if (gbl.dbgfil == NULL)
errfatal(5);
} else if ((flg.dbg[0] & 1) || sourcefile == NULL) {
gbl.dbgfil = stderr;
} else {
if (ipa_import_mode) {
tempfile = mkfname(sourcefile, file_suffix, ".qdbh");
} else {
tempfile = mkfname(sourcefile, file_suffix, ".qdbf");
if ((gbl.dbgfil = fopen(tempfile, "w")) == NULL)
errfatal(5);
}
}
}
/* Set preporocessor and Fortran source form
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* FIXME this logic needs to be moved to where those values are consumed
*/
if (was_value_set(arg_parser, &arg_preproc)) {
/* If the argument was present on command line set the value, otherwise
* keep "undefined" -1 */
preproc = arg_preproc;
}
if (was_value_set(arg_parser, &arg_freeform)) {
/* If the argument was present on command line set the value, otherwise
* keep "undefined" -1 */
flg.freeform = arg_freeform;
}
/* Enable reentrant code */
if (was_value_set(arg_parser, &arg_reentrant)) {
if (arg_reentrant) {
flg.x[7] |= 0x2; /* inhibit terminal func optz. */
flg.recursive = TRUE; /* no static locals */
} else {
flg.x[7] &= ~(0x2);
flg.recursive = FALSE;
}
}
/* Free memory */
destroy_arg_parser(&arg_parser);
destroy_action_map(&dump_map);
/* Now do some postprocessing
* ^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
/* Check optimization level */
if (flg.opt > 4) {
fprintf(stderr, "%s-W-Opt levels greater than 4 are not supported\n", version.lang);
}
/* -nostatic postprocessing */
if (!flg.doprelink)
flg.ipa |= 0x50; /* don't defer initialization, issue errors */
/* Postprocess target architecture */
do_set_tp(tp);
#ifdef OMP_OFFLOAD_LLVM
if(omptp != NULL)
flg.omptarget = TRUE;
#endif
/* Vectorizer settings */
flg.vect |= vect_val;
if (flg.vect & 0x10)
flg.x[19] &= ~0x10;
if (flg.vect & 0x20)
flg.x[19] &= ~8;
set_yflag(34, 0x30);
/* modexport file name */
mod_combined_name(modexport_val);
/* modindex file name */
mod_combined_index(modindex_val);
/* Extend source file lines */
if (arg_extend)
flg.extend_source = 132;
/* Set module directory linked list
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* FIXME this is bad, have different implementations for different string
* lists, that needs to stop.
*/
char **module_dir = module_dirs;
while (module_dir && *module_dir) {
moddir_list *mdl;
NEW(mdl, moddir_list, 1);
mdl->module_directory = *module_dir;
mdl->next = NULL;
if (module_directory_list == NULL) {
module_directory_list = mdl;
} else {
moddir_list *link;
for (link = module_directory_list; link->next; link = link->next)
;
link->next = mdl;
}
++module_dir;
}
flg.genilm = TRUE;
/* set -x 49 0x400000, F90-style output */
set_xflag(49, 0x400000);
/* set -x 58 0x10000, handle all pointers */
set_xflag(58, 0x10000);
gbl.is_f90 = TRUE;
/* set -x 58 0x40, and reset hpf flag, no static-init */
set_xflag(58, 0x40);
flg.defaulthpf = flg.hpf = FALSE;
flg.defaultsequence = flg.sequence = TRUE;
/* set -x 58 0x20000, allocate temps only as big as needed */
set_xflag(58, 0x20000);
if (XBIT(25, 0xf0)) {
fprintf(stderr, "%s-I-Beta Release Optimizations Activated\n", version.lang);
}
if (flg.x[27] == -1)
flg.x[27] = 4; /* default/max overlap of 4 */
if (flg.es && !flg.p)
flg.x[123] |= 0x100;
empty_cl:
if (sourcefile == NULL) {
if (flg.ipa & 0x0a) {
/* for IPA propagation or when generating static$init, no sourcefile */
sourcefile = "pghpf.prelink.f";
gbl.src_file = (char *)malloc(strlen(sourcefile) + 1);
strcpy(gbl.src_file, sourcefile);
gbl.srcfil = NULL;
copy_curr_file = 0;
} else {
gbl.src_file = sourcefile = "STDIN.f";
gbl.srcfil = stdin;
}
goto do_curr_file;
}
if (errflg)
finish();
if (ipa_import_mode) {
char *s;
if (!sourcefile) {
gbl.src_file = (char *)malloc(strlen(sourcefile) + 1);
strcpy(gbl.src_file, sourcefile);
basenam(gbl.src_file, "", sourcefile);
} else {
sourcefile = "STDIN.f";
gbl.src_file = (char *)malloc(strlen(sourcefile) + 1);
strcpy(gbl.src_file, sourcefile);
}
file_suffix = "";
for (s = gbl.src_file; *s; ++s) {
if (*s == '.')
file_suffix = s;
}
} else {
if (!nosuffixcheck) {
/* open sourcefile */
for (i = 0; suffixes[i].nm; ++i) {
int lsuf, lsrc;
lsuf = strlen(suffixes[i].nm);
lsrc = strlen(sourcefile);
if (lsuf >= lsrc)
continue;
if (strcmp(sourcefile + (lsrc - lsuf), suffixes[i].nm))
continue;
gbl.src_file = mkfname(sourcefile, suffixes[i].nm, suffixes[i].nm);
if ((gbl.srcfil = fopen(gbl.src_file, "r")) != NULL) {
/* fill in flg.freeform, file_suffix, fpp_, gbl.src_file */
if (flg.freeform == -1)
flg.freeform = suffixes[i].form;
file_suffix = suffixes[i].nm;