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 BIH_H_
19 #define BIH_H_
20 
21 #include "symtab.h"
22 
23 /**
24    \file
25    \brief BIH data structures and definitions
26  */
27 
28 typedef struct {
29   SPTR label;
30   int lineno;
31   union {
32     UINT all;
33     struct {
34       unsigned rd : 1;        /* memory resident -- currently always 1 */
35       unsigned ft : 1;        /* falls thru */
36       unsigned en : 1;        /* is a subprogram/function entry */
37       unsigned ex : 1;        /* contains an external call */
38       unsigned xt : 1;        /* is an exit from the subprogram/function*/
39       unsigned pl : 1;        /* is pipelinable */
40       unsigned ztrp : 1;      /* is the head of a zero-trip loop */
41       unsigned smove : 1;     /* i386: block contains struct move
42                                * i860 (temporary): unsafe to use func
43                                * return registers
44                                */
45       unsigned nobla : 1;     /* loop count inst can't be used */
46       unsigned nomerge : 1;   /* don't merge this block */
47       unsigned qjsr : 1;      /* used only by the optimizer */
48       unsigned head : 1;      /* bih is the head of a loop */
49       unsigned tail : 1;      /* bih is the tail of a loop */
50       unsigned innermost : 1; /* bih is the head of an innermost loop*/
51       unsigned mexits : 1;    /* bih is the head of a loop with > 1 exit*/
52       unsigned ozcr : 1;      /* bih is optimizer pro-/epi- logue (temp) */
53 
54       unsigned par : 1;       /* bih belongs to a parallel region */
55       unsigned cs : 1;        /* bih is a critical section */
56       unsigned streg : 1;     /* block contains stores of globally assigned
57                                * registers into their assigned variables;
58                                * set and cleared by the optimizer.  Flag
59                                * is set irrespective of target; actual use
60                                * is target-dependent.
61                                */
62       unsigned vpar : 1;      /* bih belongs to an auto-parallelized loop --
63                                * NOT YET SET
64                                */
65       unsigned nodepchk2 : 1; /* nodepchk fixup - used by llvm bridge */
66       unsigned nodepchk : 1;  /* nodepchk - use by llvm bridge */
67       unsigned enlab : 1;     /* this bih contains entry debug label */
68       unsigned parloop : 1;   /* bih is the head of a parallel loop; the loop
69                                * is parallelized by vpar() or is specified by
70                                * the user as a PDO.
71                                */
72 
73       unsigned parsect : 1;   /* bih belongs to a parallel section */
74       unsigned ujres : 1;     /* bih contains ujresidual start & count info */
75       unsigned simd : 1;       /* bih contains simd code */
76 
77       unsigned ldvol : 1; /* bih contains a load from volatile space */
78       unsigned stvol : 1; /* bih contains a store to volatile space */
79       unsigned last : 1;  /* lexically last bih, usually same as xt */
80       unsigned gasm : 1;  /* contains GASM */
81     } bits;
82   } flags;
83   union {
84     UINT all;
85     struct {
86       unsigned paraln : 1; /* parallelized loop split up so that the
87                             * alignment of arrays on all lcpus is the
88                             * same as if executed serially.
89                             */
90       unsigned invif : 1;  /* Used to mark a block as either created
91                             * during invarif (a factor block) or as
92                             * legal to apply the invarif optimization.
93                             */
94       unsigned noinvif : 1;
95       unsigned combst : 1; /* Block contains combined stores generated by
96                             * llvect.
97                             */
98 
99       unsigned deletable : 1; /* This block is deletable */
100       unsigned mark : 1;
101       unsigned task : 1;       /* bih belongs to a task */
102       unsigned resid : 1;      /* bih is the head of a residual loop */
103 
104       unsigned vcand : 1;      /* bih is the head of a vector candidate loop */
105       unsigned accel : 1;      /* bih is head of an accelerator region */
106       unsigned endaccel : 1;   /* bih is tail of an accelerator region */
107       unsigned midiom : 1;     /* bih is head of a mem-idiom collapsed loop */
108       unsigned accdata : 1;    /* bih is head of an accelerator data region */
109       unsigned endaccdata : 1; /* bih is tail of an accelerator data region */
110       unsigned mark2 : 1;      /* bih is reachable and not dead, if set */
111       unsigned mark3 : 1;
112 
113       unsigned kernel : 1;     /* bih is head of a cuda kernel */
114       unsigned endkernel : 1;  /* bih is tail of a cuda kernel */
115       unsigned useful : 1;     /* bih contains useful work */
116       unsigned guardee : 1;    /* is guarded by a size-zero test */
117       unsigned guarder : 1;    /* zero-size check block */
118       unsigned samelpcnt : 1;  /* this block and its innermost loops have
119                                   same loop bound and zero-size was removed
120                                   from its inner loops this block will have
121                                   zero-size check.
122                                 */
123       unsigned rpct : 1;       /* block contains RPCT altcode or the RPCT
124                                 *   no-conflict loop */
125       unsigned rpct_confl : 1; /* block contains the RPCT conflict loop */
126       unsigned rt_guarded : 1; /* block contains runtime guarded loop */
127       unsigned doconc : 1;     /* bih is the head of a do concurrent loop */
128     } bits;
129   } flags2;
130   int lpcntFrom;  /* When a loop count temp is created, record the induction
131                    * variable (its nme) from which the count is created */
132   int rgset;      /* set of regs live for block. Also,*/
133                   /*     used in hlvect to link bih's */
134   int assn;       /* index to rat applicable to block */
135   int prev;       /* previous lexical block */
136   int next;       /* next lexical block */
137   int first;      /* first ilt in block */
138   int last;       /* last ilt in block */
139   int findex;     /* FIH index */
140   int ftag;       /* tag used with findex for pfo, etc. */
141   double blkCnt;  /* block execution count (offset of blkCnt must be a
142                    * multiple of 8.
143                    */
144   UINT aveLpCnt;  /* average loop count */
145   UINT padding;   /* to make a total of 8 bytes  */
146   int branchfreq; /* percent (0<=.<=100) branch taken frequency */
147   /****** BIH size must be a multiple of 8 : bihutil.c */
148 } BIH;
149 
150 typedef struct {
151   STG_MEMBERS(BIH);
152   int stg_max;
153   char callfg;    /* call flag */
154   char parfg;     /* parallel region flag */
155   char csfg;      /* critical section flag */
156   char parsectfg; /* parallel section flag */
157   char ldvol;     /* Volatile load flag */
158   char stvol;     /* Volatile store flag */
159   char qjsrfg;    /* QJSR flag */
160   char gasm;      /* contains gasm */
161   char taskfg;    /* task flag */
162 } BIHB;
163 
164 #define BIH_LABEL(i) bihb.stg_base[i].label
165 #define BIH_LINENO(i) bihb.stg_base[i].lineno
166 #define BIH_FLAGS(i) bihb.stg_base[i].flags.all
167 #define BIH_RD(i) bihb.stg_base[i].flags.bits.rd
168 #define BIH_FT(i) bihb.stg_base[i].flags.bits.ft
169 #define BIH_EN(i) bihb.stg_base[i].flags.bits.en
170 #define BIH_EX(i) bihb.stg_base[i].flags.bits.ex
171 #define BIH_XT(i) bihb.stg_base[i].flags.bits.xt
172 #define BIH_LAST(i) bihb.stg_base[i].flags.bits.last
173 #define BIH_PL(i) bihb.stg_base[i].flags.bits.pl
174 #define BIH_ZTRP(i) bihb.stg_base[i].flags.bits.ztrp
175 #define BIH_GUARDEE(i) bihb.stg_base[i].flags2.bits.guardee
176 #define BIH_GUARDER(i) bihb.stg_base[i].flags2.bits.guarder
177 #define BIH_SAMELPCNT(i) bihb.stg_base[i].flags2.bits.samelpcnt
178 #define BIH_SMOVE(i) bihb.stg_base[i].flags.bits.smove
179 #define BIH_NOBLA(i) bihb.stg_base[i].flags.bits.nobla
180 #define BIH_NOMERGE(i) bihb.stg_base[i].flags.bits.nomerge
181 #define BIH_QJSR(i) bihb.stg_base[i].flags.bits.qjsr
182 #define BIH_HEAD(i) bihb.stg_base[i].flags.bits.head
183 #define BIH_TAIL(i) bihb.stg_base[i].flags.bits.tail
184 #define BIH_INNERMOST(i) bihb.stg_base[i].flags.bits.innermost
185 #define BIH_MEXITS(i) bihb.stg_base[i].flags.bits.mexits
186 #define BIH_OZCR(i) bihb.stg_base[i].flags.bits.ozcr
187 #define BIH_PAR(i) bihb.stg_base[i].flags.bits.par
188 #define BIH_CS(i) bihb.stg_base[i].flags.bits.cs
189 #define BIH_STREG(i) bihb.stg_base[i].flags.bits.streg
190 #define BIH_VPAR(i) bihb.stg_base[i].flags.bits.vpar
191 #define BIH_NODEPCHK(i) bihb.stg_base[i].flags.bits.nodepchk
192 #define BIH_NODEPCHK2(i) bihb.stg_base[i].flags.bits.nodepchk2
193 #define BIH_MARK(i) bihb.stg_base[i].flags2.bits.mark
194 #define BIH_MARK2(i) bihb.stg_base[i].flags2.bits.mark2
195 #define BIH_MARK3(i) bihb.stg_base[i].flags2.bits.mark3
196 #define BIH_USEFUL(i) bihb.stg_base[i].flags2.bits.useful
197 
198 #define BIH_ENLAB(i) bihb.stg_base[i].flags.bits.enlab
199 #define BIH_PARLOOP(i) bihb.stg_base[i].flags.bits.parloop
200 #define BIH_PARSECT(i) bihb.stg_base[i].flags.bits.parsect
201 #define BIH_UJRES(i) bihb.stg_base[i].flags.bits.ujres
202 #define BIH_SIMD(i) bihb.stg_base[i].flags.bits.simd
203 #define BIH_LDVOL(i) bihb.stg_base[i].flags.bits.ldvol
204 #define BIH_STVOL(i) bihb.stg_base[i].flags.bits.stvol
205 #define BIH_ASM(i) bihb.stg_base[i].flags.bits.gasm
206 
207 #define BIH_FLAGS2(i) bihb.stg_base[i].flags2.all
208 #define BIH_PARALN(i) bihb.stg_base[i].flags2.bits.paraln
209 #define BIH_INVIF(i) bihb.stg_base[i].flags2.bits.invif
210 #define BIH_NOINVIF(i) bihb.stg_base[i].flags2.bits.noinvif
211 #define BIH_COMBST(i) bihb.stg_base[i].flags2.bits.combst
212 
213 #define BIH_DELETABLE(i) bihb.stg_base[i].flags2.bits.deletable
214 
215 #define BIH_TASK(i) bihb.stg_base[i].flags2.bits.task
216 #define BIH_RESID(i) bihb.stg_base[i].flags2.bits.resid
217 #define BIH_VCAND(i) bihb.stg_base[i].flags2.bits.vcand
218 #define BIH_ACCEL(i) bihb.stg_base[i].flags2.bits.accel
219 #define BIH_ENDACCEL(i) bihb.stg_base[i].flags2.bits.endaccel
220 #define BIH_KERNEL(i) bihb.stg_base[i].flags2.bits.kernel
221 #define BIH_ENDKERNEL(i) bihb.stg_base[i].flags2.bits.endkernel
222 #define BIH_ACCDATA(i) bihb.stg_base[i].flags2.bits.accdata
223 #define BIH_ENDACCDATA(i) bihb.stg_base[i].flags2.bits.endaccdata
224 #define BIH_MIDIOM(i) bihb.stg_base[i].flags2.bits.midiom
225 #define BIH_RPCT(i) bihb.stg_base[i].flags2.bits.rpct
226 #define BIH_RPCT_CONFL(i) bihb.stg_base[i].flags2.bits.rpct_confl
227 #define BIH_RT_GUARDED(i) bihb.stg_base[i].flags2.bits.rt_guarded
228 #define BIH_DOCONC(i) bihb.stg_base[i].flags2.bits.doconc
229 
230 #define BIH_ASSN(i) bihb.stg_base[i].assn
231 #define BIH_LPCNTFROM(i) bihb.stg_base[i].lpcntFrom
232 #define BIH_RGSET(i) bihb.stg_base[i].rgset
233 #define BIH_ILTFIRST(i) bihb.stg_base[i].first
234 #define BIH_ILTLAST(i) bihb.stg_base[i].last
235 #define BIH_PREV(i) bihb.stg_base[i].prev
236 #define BIH_NEXT(i) bihb.stg_base[i].next
237 #define BIH_FINDEX(i) bihb.stg_base[i].findex
238 #define BIH_FTAG(i) bihb.stg_base[i].ftag
239 #define BIH_BLKCNT(i) bihb.stg_base[i].blkCnt
240 #define BIH_AVLPCNT(i) bihb.stg_base[i].aveLpCnt
241 
242 #define EXEC_COUNT double
243 #define UNKNOWN_EXEC_CNT -1.0
244 
245 /***** External Data Declarations *****/
246 
247 extern BIHB bihb;
248 
249 #include "bihutil.h"
250 
251 #endif /* BIH_H_ */
252