1 /*
2  * Copyright (c) 2002-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 /** \file
19  * \brief Definitions and declarations global to Hammer Code Generator
20  */
21 
22 #define GENERATE_AVX    TEST_FEATURE(FEATURE_AVX)
23 #define GENERATE_AVX2   TEST_FEATURE(FEATURE_AVX2)
24 #define GENERATE_AVX3   TEST_FEATURE(FEATURE_AVX512F)
25 #define GENERATE_AVX32  TEST_FEATURE(FEATURE_AVX512VL)
26 #define HAS_FMA3        TEST_FEATURE(FEATURE_FMA3)
27 #define HAS_FMA4        TEST_FEATURE(FEATURE_FMA4)
28 #define HAS_FMA         (HAS_FMA3 || HAS_FMA4)
29 
30 #define XBIT_GENERATE_SCALAR_FMA  (! XBIT(164, 0x40000000) && HAS_FMA)
31 
32 /*-----------------------------------------------
33  * Define an additional assert macro, 'asrt()'
34  *----------------------------------------------*/
35 
36 #if DEBUG
37 #define asrt(c) \
38   if (c)        \
39     ;           \
40   else          \
41   fprintf(stderr, "asrt failed. line %d, file %s\n", __LINE__, __FILE__)
42 #else  /* if ! DEBUG */
43 #define asrt(c)
44 #endif  /* if DEBUG */
45 
46 /*------------------------------------------------------
47  * Define the 3 getitem areas used by the Code Generator
48  *----------------------------------------------------*/
49 
50 /* 'CG_LONGTERM_AREA' is freed just once, at the end of the code
51  * generation for each user function.
52  */
53 #define CG_LONGTERM_AREA  10
54 
55 /* 'CG_MEDTERM_AREA' is freed:
56  * -- immediately before the cgoptim2 phase;
57  * -- at the end of cgoptim2 phase, before cgassem.
58  */
59 #define CG_MEDTERM_AREA  6
60 
61 /* 'CG_SHORTTERM_AREA' is freed:
62  * -- at the end of the linearize/cgoptim1/genaili phase for each block;
63  * -- at certain points during OPT2 register allocation.
64  */
65 #define CG_SHORTTERM_AREA  11
66 
67 /* Timing statistics.
68  */
69 typedef enum {
70   CG_TIMING_START = 0,
71   ALIAS_BUILD,
72   COLLECT_DEF_USE,
73   RD_LOCAL,
74   RD_GLOBAL,
75   RD_UD,
76   CG_TIMING_FINISH
77 } CGTIMING;
78 
79 /* Debug traces.
80  */
81 #undef TRACE0
82 #undef TRACE1
83 #undef TRACE2
84 
85 #if DEBUG
86 #define TRACE0(t, s)              if (t) fprintf(gbl.dbgfil, s)
87 #define TRACE1(t, s, a1)          if (t) fprintf(gbl.dbgfil, s, a1)
88 #define TRACE2(t, s, a1, a2)      if (t) fprintf(gbl.dbgfil, s, a1, a2)
89 #define TRACE3(t, s, a1, a2, a3)  if (t) fprintf(gbl.dbgfil, s, a1, a2, a3)
90 
91 #define CLOCK_START
92 #define CLOCK_FINISH
93 #define CLOCK_DURATION
94 
95 #else  /* if ! DEBUG */
96 #define TRACE0(t, s)
97 #define TRACE1(t, s, a1)
98 #define TRACE2(t, s, a1, a2)
99 #define TRACE3(t, s, a1, a2, a3)
100 #define CLOCK_START
101 #define CLOCK_FINISH
102 #define CLOCK_DURATION
103 #endif  /* if DEBUG */
104 
105 /*===========================================
106  * External functions local to the CG
107  *=========================================*/
108 
109 /*--------
110  * error.c
111  *------*/
112 void  asrt_failed(const char *filename, int line);
113 
114 /*---------
115  * cgmain.c
116  *-------*/
117 void  schedule(void);
118 void  reset_expr_id(void);
119 
120