1 /*
2  * Copyright (c) 1993-2019, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef GLOBAL_H_
19 #define GLOBAL_H_
20 
21 /**
22    \file
23    \brief FTN global variables and flags.
24  */
25 
26 #include "universal.h"
27 #include <stdio.h>
28 
29 /* An index into the symbol table. */
30 typedef enum SPTR {
31   NME_NULL = -1,
32   SPTR_NULL = 0,
33   SPTR_MAX = 67108864 /* Maximum allowed value */
34 } SPTR;
35 
36 #ifdef __cplusplus
37 // Enable symbol table traversals to work.
38 static inline void operator++(SPTR &s)
39 {
40   s = SPTR(s + 1);
41 }
42 #endif
43 
44 #ifdef UTILSYMTAB
45 typedef int RUTYPE;
46 #endif
47 
48 typedef struct {
49   int maxsev;      /* maximum error severity for this compile */
50   int lineno;      /* current source line number */
51   int findex;      /* current file index */
52   char *src_file;  /* name of main input source file */
53   char *curr_file; /* name of current input source file */
54   char *module;    /* object module name */
55   FILE *srcfil;    /* file pointer for source input file */
56   FILE *cppfil;    /* file pointer for preprocessor output */
57   FILE *dbgfil;    /* file pointer for debug file */
58   FILE *ilmfil;    /* file pointer for (temporary) ILM file */
59   FILE *objfil;    /* file pointer for output object file */
60   FILE *asmfil;    /* file pointer for output assembly file */
61   FILE *stbfil;    /* file pointer for symbols and datatype for llvm compiler */
62   int eof_flag;
63   char *ompaccfilename;	/** pointer to the device file name for openmp gpu offload */
64   FILE *ompaccfile;	/** file pointer for device code */
65   SPTR ompoutlinedfunc;
66   SPTR currsub;    /* symtab ptr to current subprogram */
67   SPTR caller;     /* symtab ptr to current caller (for bottom-up inlining) */
68   int cgr_index;   /* call graph index to current subprogram */
69   bool arets;      ///< set to true if any entry contains an alternate return
70   RUTYPE rutype;   /* RU_PROG, RU_SUBR, RU_FUNC, or RU_BDATA */
71   int funcline;    /* line number of header statement */
72   SPTR cmblks;     ///< pointer to list of common blocks
73   SPTR externs;    ///< pointer to list of external functions
74   SPTR consts;     ///< pointer to list of referenced constants
75   SPTR entries;  ///< list of entry symbols
76   SPTR statics;   ///< list of "static" variables
77   SPTR bssvars;   ///< list of uninitialized "static" variables
78   SPTR locals;    ///< pointer to list of local variables
79   SPTR basevars; ///< pointer to list of base symbols used for global offsets
80   SPTR asgnlbls; ///< pointer to list of labels appearing in assign stmts
81   int vfrets;    /* nonzero if variable format (<>) items present */
82   ISZ_T caddr;   /* current available address in code space */
83   ISZ_T locaddr; /* current available address for local variables,
84                   * (positive offset from $local)  */
85   ISZ_T saddr;   /* current available address for static variables,
86                   * (positive offsets from $static.  */
87   ISZ_T
88   bss_addr;    /* current available address for static uninitialized variables,
89                 * (positive offsets from .BSS)  */
90   ISZ_T paddr; /* current available address for private variables */
91   int prvt_sym_sz;  /* symbol representing size of private area */
92   int stk_sym_sz;   /* symbol representing size of stack area */
93   int autobj;       /* list of automatic data objects; the st field
94                      * AUTOBJ is used to link together the objects; NOSYM
95                      * terminates the list.
96                      */
97   INT silibcnt;     /* number of scheduled ILI blocks */
98   char *loc_arasgn; /* pointer to list of ARASGN's for local cmnblk */
99   char datetime[21];
100   int entbih;           /* entry bih of a function, set by expander/optimizer
101                          * to communicate with other modules.
102                          */
103   int func_count;       /* function counter, current # of function being
104                          * compiled, incremented by assem_init */
105   char *file_name;      /* full pathname of input file; -file may override */
106   int ftn_true;         /* value of .TRUE.; -1 (default) or 1 (-x 125 8) */
107   bool has_program;  /* true if a fortran 'program' has been seen */
108   bool in_include;   /* set to true if source is from an include file */
109   bool nowarn;       /* if TRUE, don't issue warning & informational errors*/
110   int internal;         /* internal subprogram state:
111                          * 0 - current subprogram does not contain internal
112                          *     subprograms.
113                          * 1 - current subprogram contains internal subprograms
114                          *     (current subprogram is the 'host' subprogram).
115                          * >1 - current subprogram is an internal subprogram.
116                          */
117   SPTR outersub;        /* symtab ptr to containing subprogram */
118   SPTR threadprivate;   /* pointer to list of symbols created for each thread-
119                          * private common block.  Each symbol will represent
120                          * a vector of pointers used to locate a thread's
121                          * copy of the common block.
122                          */
123   bool nofperror;    /* if TRUE, error.c:fperror() does not report errors */
124   int fperror_status;   /* error status of a floating point operation
125                          * performed by scutil.
126                          */
127   FILE *ipafil;         /* propagated ipa information */
128   FILE *ipofil;         /* newly generated ipa information */
129   FILE *dependfil;      /* make dependency information */
130   int multiversion;     /* if we're compiling multiple versions of a subprogram
131                          */
132   int numversions;      /* if we're compiling multiple versions of a subprogram
133                          */
134   int numcontained;     /* after compiling a host subprogram, how many
135                          * contained subprograms are there left to compile */
136   int multi_func_count; /* used when compiling multiple versions */
137   int pgfi_avail;
138   int ec_avail; /* Profile edge count info is available */
139   char *fn;     /* name of file being compiled passed from the FE */
140   int cuda_constructor;
141   int cudaemu; /* emulating CUDA device code */
142   int pcast;      /* bitmask for PCAST features */
143 #ifdef PGF90
144   SPTR typedescs; /* list of type descriptors */
145 #endif
146   bool denorm; /* enforce denorm for the current subprogram */
147   int outlined;   /* is outlined function .*/
148   int usekmpc;    /* use KMPC runtime. turned on for -ta=multicore for llvm. */
149 #if defined(OMP_OFFLOAD_PGI) || defined(OMP_OFFLOAD_LLVM)
150   bool ompaccel_intarget;  /* set when expander is in the openmp target construct */
151   bool ompaccel_isdevice;  /* set when generating code for openmp target device */
152   SPTR teamPrivateArgs;    /* keeps sptr that holds team private array */
153 #endif
154 } GBL;
155 
156 #undef MAXCPUS
157 #define MAXCPUS 256
158 
159 /* mask values for gbl.pcast */
160 #define PCAST_CODE 1
161 
162 extern GBL gbl;
163 #define GBL_CURRFUNC gbl.currsub
164 #define TPNVERSION 25
165 
166 typedef struct {
167   bool asmcode;
168   bool list;
169   bool object;
170   bool xref;
171   bool code;
172   bool include;
173   bool debug;
174   int opt;
175   bool depchk;
176   bool depwarn;
177   bool dclchk;
178   bool locchk;
179   bool onetrip;
180   bool save;
181   int inform;
182   UINT xoff;
183   UINT xon;
184   bool ucase;
185   char **idir;
186   bool dlines;
187   int extend_source;
188   bool i4;
189   bool line;
190   bool symbol;
191   int profile;
192   bool standard;
193   int dbg[96];
194   bool dalign; /* TRUE if doubles are double word aligned */
195   int astype;     /* target dependent value to support multiple asm's */
196   bool recursive;
197   int ieee;
198   int inliner;
199   int autoinline;
200   int vect;
201   int endian;
202   int terse;
203   int dollar;   /* defines the char to which '$' is translated */
204   int x[251];   /* x flags */
205   bool quad; /* quad align "unconstrained objects" if sizeof >= 16 */
206   int anno;
207   bool qa; /* TRUE => -qa appeared on command line */
208   bool es;
209   bool p;
210   char **def;
211   char *stdinc; /* NULL => use std include; 1 ==> do not look in
212                  * std dir; o.w., use value as the std dir */
213   bool smp;  /* TRUE => allow smp directives */
214   LOGICAL omptarget;  /* TRUE => allow OpenMP Offload directives */
215   int errorlimit;
216   bool trans_inv; /* global equiv to -Mx,7,0x10000 */
217   int tpcount;
218   int tpvalue[TPNVERSION]; /* target processor(s), for unified binary */
219 } FLG;
220 
221 extern FLG flg;
222 
223 #define IEEE_CMP (flg.ieee || !XBIT(15, 0x8000000))
224 
225 #endif // GLOBAL_H_
226