1 /*
2  * Copyright (c) 2018-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 CGMAIN_H_
19 #define CGMAIN_H_
20 
21 #include "gbldefs.h"
22 #include "global.h"
23 #include "symtab.h"
24 #include "ili.h"
25 #include "cgllvm.h"
26 #include "ll_structure.h"
27 
28 /**
29    \brief ...
30  */
31 bool currsub_is_sret(void);
32 
33 /**
34    \brief ...
35  */
36 bool is_cg_llvm_init(void);
37 
38 /**
39    \brief ...
40  */
41 bool ll_check_struct_return(DTYPE dtype);
42 
43 /**
44    \brief ...
45  */
46 bool strict_match(LL_Type *ty1, LL_Type *ty2);
47 
48 /**
49    \brief ...
50  */
51 char *dtype_struct_name(DTYPE dtype);
52 
53 /**
54    \brief ...
55  */
56 char *gen_llvm_vconstant(const char *ctype, int sptr, DTYPE tdtype, int flags);
57 
58 /**
59    \brief ...
60  */
61 char *get_label_name(int sptr);
62 
63 /**
64    \brief ...
65  */
66 char *get_llvm_mips_sname(SPTR sptr);
67 
68 /**
69    \brief ...
70  */
71 char *get_llvm_sname(SPTR sptr);
72 
73 /**
74    \brief ...
75  */
76 char *match_names(MATCH_Kind match_val);
77 
78 /**
79    \brief ...
80  */
81 const char *char_type(DTYPE dtype, SPTR sptr);
82 
83 /**
84    \brief ...
85  */
86 DTYPE msz_dtype(MSZ msz);
87 
88 /**
89    \brief ...
90  */
91 INSTR_LIST *llvm_info_last_instr(void);
92 
93 /**
94    \brief ...
95  */
96 INSTR_LIST *mk_store_instr(OPERAND *val, OPERAND *addr);
97 
98 /**
99    \brief ...
100  */
101 DTYPE cg_get_type(int n, TY_KIND v1, int v2);
102 
103 /**
104    \brief Find the (virtual) function pointer in a JSRA call
105    \param ilix  the first argument of the \c IL_JSRA
106  */
107 SPTR find_pointer_to_function(int ilix);
108 
109 /**
110    \brief ...
111  */
112 int match_llvm_types(LL_Type *ty1, LL_Type *ty2);
113 
114 /**
115    \brief ...
116  */
117 int need_ptr(int sptr, int sc, DTYPE sdtype);
118 
119 /**
120    \brief ...
121  */
122 LL_Type *maybe_fixup_x86_abi_return(LL_Type *sig);
123 
124 /**
125    \brief ...
126  */
127 OPERAND *gen_address_operand(int addr_op, int nme, bool lda,
128                              LL_Type *llt_expected, MSZ msz);
129 
130 /**
131    \brief ...
132  */
133 OPERAND *gen_call_as_llvm_instr(int sptr, int ilix);
134 
135 /**
136    \brief ...
137  */
138 OPERAND *gen_call_to_builtin(int ilix, char *fname, OPERAND *params,
139                              LL_Type *return_ll_type, INSTR_LIST *Call_Instr,
140                              LL_InstrName i_name);
141 
142 /**
143    \brief ...
144  */
145 OPERAND *gen_llvm_expr(int ilix, LL_Type *expected_type);
146 
147 /**
148    \brief ...
149  */
150 OPERAND *mk_alloca_instr(LL_Type *ptrTy);
151 
152 /**
153    \brief ...
154  */
155 TMPS *gen_extract_insert(LL_InstrName i_name, LL_Type *struct_type, TMPS *tmp,
156                          LL_Type *tmp_type, TMPS *tmp2, LL_Type *tmp2_type,
157                          int index);
158 
159 /**
160    \brief ...
161  */
162 void build_routine_and_parameter_entries(SPTR func_sptr, LL_ABI_Info *abi,
163                                          LL_Module *module);
164 
165 /**
166    \brief ...
167  */
168 void cg_fetch_clen_parampos(SPTR *len, int *param, SPTR sptr);
169 
170 /**
171    \brief ...
172  */
173 void cg_llvm_end(void);
174 
175 /**
176    \brief ...
177  */
178 void cg_llvm_fnend(void);
179 
180 /**
181    \brief ...
182  */
183 void cg_llvm_init(void);
184 
185 /**
186    \brief ...
187  */
188 void clear_deletable_flags(int ilix);
189 
190 /**
191    \brief ...
192  */
193 void dump_type_for_debug(LL_Type *ll_type);
194 
195 /**
196    \brief ...
197  */
198 void llvm_ctor_add(const char *name);
199 
200 /**
201    \brief ...
202  */
203 void llvm_ctor_add_with_priority(const char *name, int priority);
204 
205 /**
206    \brief ...
207  */
208 void llvm_dtor_add(const char *name);
209 
210 /**
211    \brief ...
212  */
213 void llvm_dtor_add_with_priority(const char *name, int priority);
214 
215 /**
216    \brief ...
217  */
218 void llvmResetSname(int sptr);
219 
220 /**
221    \brief ...
222  */
223 void llvm_write_ctors(void);
224 
225 /**
226    \brief ...
227  */
228 void print_personality(void);
229 
230 /**
231    \brief ...
232  */
233 void print_tmp_name(TMPS *t);
234 
235 /**
236    \brief ...
237  */
238 void process_formal_arguments(LL_ABI_Info *abi);
239 
240 /**
241    \brief ...
242  */
243 void process_global_lifetime_debug(void);
244 
245 /**
246    \brief ...
247  */
248 void process_sptr(SPTR sptr);
249 
250 /**
251    \brief ...
252  */
253 void reset_expr_id(void);
254 
255 /**
256    \brief ...
257  */
258 void schedule(void);
259 
260 /**
261    \brief ...
262  */
263 void set_llvm_sptr_name(OPERAND *operand);
264 
265 /**
266    \brief ...
267  */
268 void update_external_function_declarations(const char *name, char *decl,
269                                            unsigned flags);
270 
271 /**
272    \brief ...
273  */
274 void write_external_function_declarations(int first_time);
275 
276 bool is_vector_x86_mmx(LL_Type *);
277 
278 /**
279    \brief Process common block symbols, adding debug info for it's variables
280    \param sptr  A symbol
281  */
282 void add_debug_cmnblk_variables(LL_DebugInfo *db, SPTR sptr);
283 
284 /**
285    \brief Check if sptr is the mindum of an array and the array has descriptor
286    \param sptr  A symbol
287  */
288 bool ftn_array_need_debug_info(SPTR sptr);
289 
290 #endif
291