1 /*
2 * Copyright (c) 2018, 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 ILIUTIL_H_
19 #define ILIUTIL_H_
20
21 #include "gbldefs.h"
22 #include "error.h"
23 #include "global.h"
24 #include "symtab.h"
25 #include "ilm.h"
26 #include "ilmtp.h"
27 #include "ili.h"
28 #include "mth.h"
29
30 extern bool share_proc_ili;
31 extern bool share_qjsr_ili;
32
33 #ifdef __cplusplus
CC_ILI_OPND(int ilix,int opn)34 inline CC_RELATION CC_ILI_OPND(int ilix, int opn) {
35 return static_cast<CC_RELATION>(ILI_OPND(ilix, opn));
36 }
DT_ILI_OPND(int ilix,int opn)37 inline DTYPE DT_ILI_OPND(int ilix, int opn) {
38 return static_cast<DTYPE>(ILI_OPND(ilix, opn));
39 }
40 #else
41 #define CC_ILI_OPND ILI_OPND
42 #define DT_ILI_OPND ILI_OPND
43 #endif
44
45 /**
46 \brief ...
47 */
48 ATOMIC_INFO atomic_decode(int encoding);
49
50 #ifdef __cplusplus
GetAtomicDecodeMsz(int encoding)51 inline MSZ GetAtomicDecodeMsz(int encoding) {
52 return static_cast<MSZ>(atomic_decode(encoding).msz);
53 }
54 #else
55 #define GetAtomicDecodeMsz(E) atomic_decode(E).msz
56 #endif
57
58 /**
59 \brief ...
60 */
61 ATOMIC_INFO atomic_info(int ilix);
62
63 /**
64 \brief ...
65 */
66 ISZ_T get_isz_conili(int ili);
67
68 /**
69 \brief ...
70 */
71 bool cc_includes_equality(CC_RELATION cc);
72
73 /**
74 \brief ...
75 */
76 bool ccs_are_complementary(CC_RELATION cc1, CC_RELATION cc2);
77
78 /**
79 \brief ...
80 */
81 bool cmpxchg_is_weak(int ilix);
82
83 /**
84 \brief ...
85 */
86 bool _find_ili(int ilix, int find_this);
87
88 /**
89 \brief ...
90 */
91 bool find_ili(int tree, int it);
92
93 /**
94 \brief ...
95 */
96 bool func_in(int ilix);
97
98 /**
99 \brief ...
100 */
101 bool is_floating_comparison_opcode(ILI_OP opc);
102
103 /**
104 \brief ...
105 */
106 bool is_integer_comparison_opcode(ILI_OP opc);
107
108 /**
109 \brief ...
110 */
111 bool is_llvm_local(int sptr, int funcsptr);
112
113 /**
114 \brief ...
115 */
116 bool is_llvm_local_private(int sptr);
117
118 /**
119 \brief ...
120 */
121 bool is_omp_atomic_ld(int ilix);
122
123 /**
124 \brief ...
125 */
126 bool is_omp_atomic_st(int ilix);
127
128 /**
129 \brief ...
130 */
131 bool is_unsigned_opcode(ILI_OP opc);
132
133 /**
134 \brief ...
135 */
136 bool qjsr_in(int ilix);
137
138 /**
139 \brief ...
140 */
141 CC_RELATION combine_ieee_ccs(CC_RELATION binary_cc, CC_RELATION zero_cc);
142
143 /**
144 \brief ...
145 */
146 CC_RELATION combine_int_ccs(CC_RELATION binary_cc, CC_RELATION zero_cc);
147
148 /**
149 \brief ...
150 */
151 CC_RELATION commute_cc(CC_RELATION cc);
152
153 /**
154 \brief ...
155 */
156 CC_RELATION complement_ieee_cc(CC_RELATION cc);
157
158 /**
159 \brief ...
160 */
161 CC_RELATION complement_int_cc(CC_RELATION cc);
162
163 /**
164 \brief ...
165 */
166 char *dump_msz(MSZ ms);
167
168 /**
169 \brief ...
170 */
171 char *fast_math(char *root, int widthc, int typec, char *oldname);
172
173 /**
174 \brief ...
175 */
176 char *gnr_math(char *root, int widthc, int typec, char *oldname, int masked);
177
178 /**
179 \brief ...
180 */
181 char *make_math(MTH_FN fn, SPTR *fptr, int vectlen, bool mask, DTYPE res_dt, int nargs, int arg1_dt_, ...);
182
183 /**
184 \brief ...
185 */
186 char *make_math_name(MTH_FN fn, int vectlen, bool mask, DTYPE res_dt);
187
188 /**
189 \brief ...
190 */
191 char *make_math_name_vabi(MTH_FN fn, int vectlen, bool mask, DTYPE res_dt);
192
193 /**
194 \brief ...
195 */
196 char *relaxed_math(char *root, int widthc, int typec, char *oldname);
197
198 /**
199 \brief ...
200 */
201 char *scond(int c);
202
203 /**
204 \brief ...
205 */
206 CMPXCHG_MEMORY_ORDER cmpxchg_memory_order(int ilix);
207
208 /**
209 \brief ...
210 */
211 DTYPE ili_get_vect_dtype(int ilix);
212
213 /**
214 \brief ...
215 */
216 ILI_OP ldopc_from_stopc(ILI_OP stopc);
217
218 /**
219 \brief ...
220 */
221 int ad1ili(ILI_OP opc, int opn1);
222
223 /**
224 \brief ...
225 */
226 int ad2func_kint(ILI_OP opc, char *name, int opn1, int opn2);
227
228 /**
229 \brief ...
230 */
231 int ad2ili(ILI_OP opc, int opn1, int opn2);
232
233 /// \brief add ili with three operands
234 int ad3ili(ILI_OP opc, int opn1, int opn2, int opn3);
235
236 /// \brief add ili with four operands
237 int ad4ili(ILI_OP opc, int opn1, int opn2, int opn3, int opn4);
238
239 /// \brief add ili with five operands
240 int ad5ili(ILI_OP opc, int opn1, int opn2, int opn3, int opn4, int opn5);
241
242 /// \brief add ACON ili with specified (integer) constant
243 int ad_aconi(ISZ_T val);
244
245 /// \brief add ACON ili with specified symbol and offset
246 int ad_acon(SPTR sym, ISZ_T val);
247
248 /**
249 \brief Add acon ili of an 64-bit constant whose value consists of m32 (most
250 significant 32 bits) and l32 (least significant 32 bits).
251 */
252 int ad_aconk(INT m32, INT l32);
253
254 /**
255 \brief ...
256 */
257 int ad_cmpxchg(ILI_OP opc, int ilix_val, int ilix_loc, int nme, int stc_atomic_info, int ilix_comparand, int ilix_is_weak, int ilix_success, int ilix_failure);
258
259 /// \brief add CSE ili of an ili
260 int ad_cse(int ilix);
261
262 /**
263 \brief ...
264 */
265 int addili(ILI *ilip);
266
267 /// \brief Add a IL_FREEx with given operand
268 int ad_free(int ilix);
269
270 /// \brief add ICON ili with specified constant value
271 int ad_icon(INT val);
272
273 /// \brief Add kcon ili of an 64-bit constant
274 int ad_kconi(ISZ_T v);
275
276 /**
277 \brief Add KCON ili of an 64-bit constant whose value consists of m32 (most
278 significant 32 bits) and l32 (least significant 32 bits).
279 */
280 int ad_kcon(INT m32, INT l32);
281
282 /// \brief Given a store ILI, generate the equivalent load ILI
283 int ad_load(int stx);
284
285 /**
286 \brief ...
287 */
288 int alt_qjsr(int ilix);
289
290 /**
291 \brief ...
292 */
293 int atomic_encode(MSZ msz, SYNC_SCOPE scope, ATOMIC_ORIGIN origin);
294
295 /**
296 \brief ...
297 */
298 int atomic_encode_rmw(MSZ msz, SYNC_SCOPE scope, ATOMIC_ORIGIN origin, ATOMIC_RMW_OP op);
299
300 /**
301 \brief ...
302 */
303 int atomic_info_index(ILI_OP opc);
304
305 /**
306 \brief ...
307 */
308 int cmpxchg_loc(int ilix);
309
310 /**
311 \brief ...
312 */
313 int compl_br(int ilix, int lbl);
314
315 /**
316 \brief ...
317 */
318 int compute_address(SPTR sptr);
319
320 /**
321 \brief ...
322 */
323 int gencallargs(void);
324
325 /**
326 \brief ...
327 */
328 int genregcallargs(void);
329
330 /**
331 \brief ...
332 */
333 int genretvalue(int ilix, ILI_OP resultopc);
334
335 /**
336 \brief ...
337 */
338 int get_ili_ns(ILI *ilip);
339
340 /**
341 \brief ...
342 */
343 int get_rewr_new_nme(int nmex);
344
345 /**
346 \brief ...
347 */
348 int has_cse(int ilix);
349
350 /**
351 \brief ...
352 */
353 int iadd_const_ili(ISZ_T valconst, int valilix);
354
355 /**
356 \brief ...
357 */
358 int iadd_ili_ili(int leftx, int rightx);
359
360 /**
361 \brief ...
362 */
363 int idiv_ili_const(int valilix, ISZ_T valconst);
364
365 /**
366 \brief ...
367 */
368 int idiv_ili_ili(int leftx, int rightx);
369
370 /**
371 \brief ...
372 */
373 int ikmove(int ilix);
374
375 /**
376 \brief ...
377 */
378 int ili_get_vect_arg_count(int ilix);
379
380 /**
381 \brief ...
382 */
383 int ili_isdeleted(int ili);
384
385 /// \brief return nth operand of ili - skipping past CSE ili if present
386 int ili_opnd(int ilix, int n);
387
388 /**
389 \brief ...
390 */
391 int ili_subscript(int sub);
392
393 /**
394 \brief ...
395 */
396 int ili_throw_label(int ilix);
397
398 /**
399 \brief ...
400 */
401 int ili_traverse(int (*visit_f)(int), int ilix);
402
403 /**
404 \brief ...
405 */
406 int ilstckind(ILI_OP opc, int opnum);
407
408 /**
409 \brief ...
410 */
411 int imax_ili_ili(int leftx, int rightx);
412
413 /**
414 \brief ...
415 */
416 int imin_ili_ili(int leftx, int rightx);
417
418 /**
419 \brief ...
420 */
421 int imul_const_ili(ISZ_T valconst, int valilix);
422
423 /**
424 \brief ...
425 */
426 int imul_ili_ili(int leftx, int rightx);
427
428 /**
429 \brief ...
430 */
431 int is_argili_opcode(ILI_OP opc);
432
433 /**
434 \brief ...
435 */
436 int is_cseili_opcode(ILI_OP opc);
437
438 /**
439 \brief ...
440 */
441 int is_daili_opcode(ILI_OP opc);
442
443 /**
444 \brief ...
445 */
446 int is_dfrili_opcode(ILI_OP opc);
447
448 /**
449 \brief ...
450 */
451 int is_freeili_opcode(ILI_OP opc);
452
453 /**
454 \brief ...
455 */
456 int is_mvili_opcode(ILI_OP opc);
457
458 /**
459 \brief ...
460 */
461 int is_rgdfili_opcode(ILI_OP opc);
462
463 /**
464 \brief ...
465 */
466 int isub_ili_ili(int leftx, int rightx);
467
468 /**
469 \brief ...
470 */
471 int jsrsearch(int ilix);
472
473 /**
474 \brief ...
475 */
476 int kimove(int ilix);
477
478 /**
479 \brief ...
480 */
481 int ll_ad_outlined_func(ILI_OP result_opc, ILI_OP call_opc, char *func_name, int narg, int arg1, int arg2, int arg3);
482
483 /**
484 \brief ...
485 */
486 int mk_address(SPTR sptr);
487
488 /**
489 \brief ...
490 */
491 int mk_charlen_parref_sptr(SPTR sptr);
492
493 /**
494 \brief ...
495 */
496 int mkfunc_avx(char *nmptr, int avxp);
497
498 /**
499 \brief ...
500 */
501 int qjsrsearch(int ilix);
502
503 /**
504 \brief ...
505 */
506 int rewr_ili(int tree, int old, int New);
507
508 /**
509 \brief ...
510 */
511 int rewr_ili_nme(int tree, int oldili, int newili, int oldnme, int newnme, int douse, int dodef);
512
513 /**
514 \brief ...
515 */
516 int save_rewr_count(void);
517
518 /**
519 \brief ...
520 */
521 int sel_aconv(int ili);
522
523 /**
524 \brief ...
525 */
526 int sel_decr(int ili, int isi8);
527
528 /**
529 \brief ...
530 */
531 int sel_icnst(ISZ_T val, int isi8);
532
533 /**
534 \brief ...
535 */
536 int sel_iconv(int ili, int isi8);
537
538 /**
539 \brief ...
540 */
541 int simplified_cmp_ili(int cmp_ili);
542
543 /**
544 \brief ...
545 */
546 int uikmove(int ilix);
547
548 /**
549 \brief ...
550 */
551 MEMORY_ORDER memory_order(int ilix);
552
553 /**
554 \brief ...
555 */
556 MSZ mem_size(TY_KIND ty);
557
558 /**
559 \brief ...
560 */
561 void addcallarg(int ili, int nme, int dtype);
562
563 /**
564 \brief ...
565 */
566 void choose_multiplier_64(int N, DBLUINT64 dd, int prec);
567
568 /**
569 \brief ...
570 */
571 void choose_multiplier(int N, unsigned dd, int prec);
572
573 /**
574 \brief ...
575 */
576 void _ddilitree(int i, int flag);
577
578 /**
579 \brief ...
580 */
581 void ddilitree(int i, int flag);
582
583 /**
584 \brief ...
585 */
586 void dmpilitree(int i);
587
588 /**
589 \brief ...
590 */
591 void dmpili(void);
592
593 /**
594 \brief ...
595 */
596 void dump_atomic_info(FILE *f, ATOMIC_INFO info);
597
598 /**
599 \brief ...
600 */
601 void dump_ili(FILE *f, int i);
602
603 /**
604 \brief ...
605 */
606 void garbage_collect(void (*mark_function)(int));
607
608 /**
609 \brief ...
610 */
611 void ili_cleanup(void);
612
613 /**
614 \brief ...
615 */
616 void ili_init(void);
617
618 /**
619 \brief ...
620 */
621 void ili_unvisit(void);
622
623 /**
624 \brief ...
625 */
626 void ili_visit(int ilix, int v);
627
628 /**
629 \brief ...
630 */
631 void initcallargs(int count);
632
633 /**
634 \brief ...
635 */
636 void inline_mulh(void);
637
638 /**
639 \brief ...
640 */
641 void ldst_msz(DTYPE dtype, ILI_OP *ld, ILI_OP *st, MSZ *siz);
642
643 /**
644 \brief ...
645 */
646 void llmk_math_name(char *buff, int fn, int vectlen, bool mask, DTYPE res_dt);
647
648 /**
649 \brief ...
650 */
651 void prilitree(int i);
652
653 /**
654 \brief ...
655 */
656 void restore_rewr_count(int c);
657
658 /**
659 \brief ...
660 */
661 void rewr_cln_ili(void);
662
663 /**
664 \brief ...
665 */
666 void rewr_these_ili(int oldili, int newili);
667
668 /**
669 \brief ...
670 */
671 void rewr_these_ili_nme(int oldili, int newili, int oldnme, int newnme);
672
673 #endif // ILIUTIL_H_
674