1 /*
2 * Copyright (c) 2014-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 LL_STRUCTURE_H_
19 #define LL_STRUCTURE_H_
20
21 /**
22 \file
23 \brief LLVM bridge representation
24 */
25
26 #include "gbldefs.h"
27 #include "global.h"
28 #include "flang/ADT/hash.h"
29 #include <stdio.h>
30
31 /* clang-format off */
32
33 typedef enum LL_Op {
34 LL_ADD, LL_FADD, LL_SUB, LL_FSUB, LL_MUL,
35 LL_FMUL, LL_UDIV, LL_SDIV, LL_UREM, LL_SREM,
36 LL_FDIV, LL_OR, LL_XOR, LL_ASHR, LL_LSHR,
37 LL_SHL, LL_AND, LL_STORE, LL_LOAD, LL_SEXT,
38 LL_ZEXT, LL_TRUNC, LL_SITOFP, LL_UITOFP, LL_FPTOSI,
39 LL_FPTOUI, LL_FPTRUNC, LL_FPEXT, LL_CALL, LL_RET,
40 LL_ICMP, LL_FCMP, LL_BR, LL_UBR, LL_SELECT,
41 LL_GEP, LL_BITCAST, LL_INTTOPTR, LL_PTRTOINT, LL_ALLOCA,
42 LL_TEXTCALL, LL_UNREACHABLE, LL_SWITCH, LL_EXTRACTVALUE, LL_INSERTVALUE,
43 LL_ATOMICRMW, LL_CMPXCHG, LL_ASM, LL_EXTRACTELEM, LL_INSERTELEM,
44 LL_FNEG, LL_NONE
45 } LL_Op;
46
47 /* clang-format on */
48
49 typedef enum LL_ModuleVarType {
50 LL_DEFAULT = 0x1,
51 LL_GLOBAL = 0x1 << 1,
52 LL_SHARED = 0x1 << 2,
53 LL_LOCAL = 0x1 << 3,
54 LL_DEVICE = 0x1 << 4,
55 LL_CONSTANT = 0x1 << 5,
56 } LL_ModuleVarType;
57
58 enum LL_LinkageType {
59 LL_INTERNAL_LINKAGE = 1,
60 LL_COMMON_LINKAGE,
61 LL_EXTERNAL_LINKAGE,
62 LL_WEAK_LINKAGE,
63 LL_NO_LINKAGE
64 };
65
66 typedef enum LL_BaseDataType {
67 LL_NOTYPE = 0,
68 LL_LABEL,
69 LL_METADATA,
70 LL_VOID,
71 LL_I1,
72 LL_I8,
73 LL_I16,
74 LL_I24,
75 LL_I32,
76 LL_I40,
77 LL_I48,
78 LL_I56,
79 LL_I64,
80 LL_I128,
81 LL_I256,
82 LL_HALF, /**< IEEE half precision floating point. */
83 LL_FLOAT, /**< IEEE single precision floating point. */
84 LL_DOUBLE, /**< IEEE double precision floating point. */
85 LL_FP128, /**< IEEE quad precision floating point. */
86 LL_X86_FP80, /**< Intel x87 80-bit floating point. */
87 LL_PPC_FP128, /**< PowerPC style double-double. */
88 LL_X86_MMX, /**< x86 representation of a value held in MMX register. */
89 LL_PTR,
90 LL_ARRAY,
91 LL_VECTOR,
92 LL_STRUCT,
93 LL_FUNCTION
94 } LL_BaseDataType;
95
96 typedef enum LL_AddressSpace { LL_AddrSp_Default = 0 } LL_AddressSpace_t;
97
98 typedef enum LL_AddressSpaceNVVM {
99 LL_AddrSp_NVVM_Generic = 0,
100 LL_AddrSp_NVVM_Global = 1,
101 LL_AddrSp_NVVM_InternalUse = 2,
102 LL_AddrSp_NVVM_Shared = 3,
103 LL_AddrSp_NVVM_Const = 4,
104 LL_AddrSp_NVVM_Local = 5,
105 } LL_AddressSpaceNVVM_t;
106
107 /**
108 \brief Calling conventions.
109 See the LLVM source file include/llvm/IR/CallingConv.h for the complete list.
110 */
111 typedef enum LL_CallConv {
112 LL_CallConv_C = 0, /**< This is the default. */
113 LL_CallConv_Fast = 8,
114 LL_CallConv_Cold = 9,
115
116 /* X86 */
117 LL_CallConv_X86_StdCall = 64,
118 LL_CallConv_X86_FastCall = 65,
119 LL_CallConv_X86_ThisCall = 70,
120 LL_CallConv_X86_VectorCall = 80,
121
122 /* ARM */
123 LL_CallConv_APCS = 66,
124 LL_CallConv_AAPCS = 67,
125 LL_CallConv_AAPCS_VFP = 68,
126
127 /* PTX */
128 LL_CallConv_PTX_Kernel = 71,
129 LL_CallConv_PTX_Device = 72,
130
131 /* SPIR */
132 LL_CallConv_SPIR_FUNC = 75,
133 LL_CallConv_SPIR_KERNEL = 76
134 } LL_CallConv;
135
136 /**
137 \brief Supported LLVM IR versions.
138
139 We can generate LLVM IR for multiple versions of LLVM. The numeric value of
140 these version enumerators must match the x-bits set by the rcfiles.
141
142 The CPU target version is set by -x 249 from rcfiles/llvmrc.
143 */
144 typedef enum LL_IRVersion {
145 LL_Version_3_1 = 31,
146 LL_Version_3_2 = 32,
147 LL_Version_3_4 = 34,
148 LL_Version_3_5 = 35,
149 LL_Version_3_6 = 36,
150 LL_Version_3_7 = 37,
151 LL_Version_3_8 = 38,
152 LL_Version_3_9 = 39,
153 LL_Version_4_0 = 40,
154 LL_Version_5_0 = 50,
155 LL_Version_6_0 = 60,
156 LL_Version_7_0 = 70,
157 LL_Version_8_0 = 80,
158 LL_Version_9_0 = 90,
159 LL_Version_trunk = 1023
160 } LL_IRVersion;
161
162 LL_IRVersion get_llvm_version(void);
163
164 typedef enum LL_DWARFVersion {
165 LL_DWARF_Version_2,
166 LL_DWARF_Version_3,
167 LL_DWARF_Version_4,
168 LL_DWARF_Version_5
169 } LL_DWARFVersion;
170
171 /* If flang is built with LLVM from github:flang-compiler/llvm, then one can
172 define the cmake macro FLANG_LLVM_EXTENSIONS to use the Fortran debug
173 information extensions added to that LLVM. For example, use the command:
174 cmake -DFLANG_LLVM_EXTENSIONS ...
175 */
176
177 /**
178 \brief LLVM IR Feature Vector.
179
180 IR versions are translated to a feature vector that controls the shape of the
181 generated IR. Code generation should always check the feature vector instead
182 of comparing version numbers directly.
183 */
184 typedef struct LL_IRFeatures_ {
185 LL_IRVersion version : 10;
186 LL_DWARFVersion dwarf_version : 4; /**< DWARF Version */
187 unsigned is_nvvm : 1; /**< Targeting NVVM IR for CUDA. */
188 unsigned is_spir : 1; /**< Targeting SPIR for OpenCL. */
189 /** Version number for debug info metadata. Note that the version number
190 sequences are different with/without versioned_dw_tag. */
191 unsigned debug_info_version : 8;
192 } LL_IRFeatures;
193
194 #if HAVE_INLINE
195 /* modern C compilers support 'inline' keyword */
196
197 INLINE static bool
ll_feature_use_addrspacecast(const LL_IRFeatures * feature)198 ll_feature_use_addrspacecast(const LL_IRFeatures *feature)
199 {
200 return feature->version >= LL_Version_3_4;
201 }
202
203 /**
204 \brief Use global aliases to refer to offset globals in metadata
205 */
206 INLINE static bool
ll_feature_debug_info_global_aliases(const LL_IRFeatures * feature)207 ll_feature_debug_info_global_aliases(const LL_IRFeatures *feature)
208 {
209 return feature->version >= LL_Version_3_4;
210 }
211
212 /**
213 \brief Use the pre-3.4 layout for debug info mdnodes
214 */
215 INLINE static bool
ll_feature_debug_info_pre34(const LL_IRFeatures * feature)216 ll_feature_debug_info_pre34(const LL_IRFeatures *feature)
217 {
218 return feature->version < LL_Version_3_4;
219 }
220
221 /**
222 \brief Need NVVM version?
223 */
224 INLINE static bool
ll_feature_emit_nvvmir_version(const LL_IRFeatures * feature)225 ll_feature_emit_nvvmir_version(const LL_IRFeatures *feature)
226 {
227 return feature->version >= LL_Version_3_4;
228 }
229
230 /**
231 \brief Encode LLVMDebugVersion in DW_TAGs in debug info metadata
232 */
233 INLINE static bool
ll_feature_versioned_dw_tag(const LL_IRFeatures * feature)234 ll_feature_versioned_dw_tag(const LL_IRFeatures *feature)
235 {
236 return feature->version <= LL_Version_3_5;
237 }
238
239 INLINE static bool
ll_feature_omit_metadata_type(const LL_IRFeatures * feature)240 ll_feature_omit_metadata_type(const LL_IRFeatures *feature)
241 {
242 return feature->version >= LL_Version_3_6;
243 }
244
245 /**
246 \brief Use specialized <tt> !MDLocation(...) </tt> metadata node syntax.
247 */
248 INLINE static bool
ll_feature_debug_info_mdlocation(const LL_IRFeatures * feature)249 ll_feature_debug_info_mdlocation(const LL_IRFeatures *feature)
250 {
251 return feature->version >= LL_Version_3_6;
252 }
253
254 /**
255 \brief Alias syntax is <tt> [flags] alias \i AliaseeTy \i @Aliasee </tt>
256 instead of <tt> alias [flags] \i AliaseeTy \i @Aliasee </tt>
257 */
258 INLINE static bool
ll_feature_alias_flags_first(const LL_IRFeatures * feature)259 ll_feature_alias_flags_first(const LL_IRFeatures *feature)
260 {
261 return feature->version >= LL_Version_3_7;
262 }
263
264 /**
265 \brief Emit a call instruction with function signature instead of a pointer
266 type (to the called function)
267 */
268 INLINE static bool
ll_feature_emit_func_signature_for_call(const LL_IRFeatures * feature)269 ll_feature_emit_func_signature_for_call(const LL_IRFeatures *feature)
270 {
271 return feature->version >= LL_Version_3_7;
272 }
273
274 /**
275 \brief Local variable has line number and argument number in the same field
276 */
277 INLINE static bool
ll_feature_dbg_local_variable_embeds_argnum(const LL_IRFeatures * feature)278 ll_feature_dbg_local_variable_embeds_argnum(const LL_IRFeatures *feature)
279 {
280 return feature->version < LL_Version_3_7;
281 }
282
283 /**
284 \brief Emit an explicit type on gep and load instructions.
285 */
286 INLINE static bool
ll_feature_explicit_gep_load_type(const LL_IRFeatures * feature)287 ll_feature_explicit_gep_load_type(const LL_IRFeatures *feature)
288 {
289 return feature->version >= LL_Version_3_7;
290 }
291
292 /**
293 Metadata function arguments require full metadata structure:
294 <tt> !{...} </tt>
295 */
296 INLINE static bool
ll_feature_metadata_args_struct(const LL_IRFeatures * feature)297 ll_feature_metadata_args_struct(const LL_IRFeatures *feature)
298 {
299 return feature->version < LL_Version_3_7;
300 }
301
302 /**
303 \brief Use specialized <tt>!MD*(...)</tt> metadata nodes for debug?
304
305 In LLVM 3.7 and later, use specialized debug info formats.
306 */
307 INLINE static bool
ll_feature_use_specialized_mdnodes(const LL_IRFeatures * feature)308 ll_feature_use_specialized_mdnodes(const LL_IRFeatures *feature)
309 {
310 return feature->version >= LL_Version_3_7;
311 }
312
313 /**
314 \brief Need explicit file descriptions instead of references to them
315 */
316 INLINE static bool
ll_feature_debug_info_need_file_descriptions(const LL_IRFeatures * feature)317 ll_feature_debug_info_need_file_descriptions(const LL_IRFeatures *feature)
318 {
319 return feature->version >= LL_Version_3_7;
320 }
321
322 /**
323 \brief Debug intrinsics require an extra argument
324 */
325 INLINE static bool
ll_feature_dbg_declare_needs_expression_md(const LL_IRFeatures * feature)326 ll_feature_dbg_declare_needs_expression_md(const LL_IRFeatures *feature)
327 {
328 return feature->version >= LL_Version_3_7;
329 }
330
331 /**
332 \brief Before LLVM 3.7, personality signatures were on landingpads.
333 \return true iff old style c++ exception personality placement
334
335 With LLVM 3.7, the personality appends to the function definition.
336 */
337 INLINE static bool
ll_feature_eh_personality_on_landingpad(const LL_IRFeatures * feature)338 ll_feature_eh_personality_on_landingpad(const LL_IRFeatures *feature)
339 {
340 return feature->version < LL_Version_3_7;
341 }
342
343 /**
344 \brief Metadata types start with \c DI instead of \c MD
345 */
346 INLINE static bool
ll_feature_debug_info_DI_syntax(const LL_IRFeatures * feature)347 ll_feature_debug_info_DI_syntax(const LL_IRFeatures *feature)
348 {
349 return feature->version >= LL_Version_3_7;
350 }
351
352 /**
353 \brief Debug information: subrange node needs element count instead of
354 index's upper bound. Also -1 is used to show that the range is empty
355 */
356 INLINE static bool
ll_feature_debug_info_subrange_needs_count(const LL_IRFeatures * feature)357 ll_feature_debug_info_subrange_needs_count(const LL_IRFeatures *feature)
358 {
359 return feature->version >= LL_Version_3_7;
360 }
361
362 /**
363 \brief Version 3.8 debug metadata
364 */
365 INLINE static bool
ll_feature_debug_info_ver38(const LL_IRFeatures * feature)366 ll_feature_debug_info_ver38(const LL_IRFeatures *feature)
367 {
368 return feature->version >= LL_Version_3_8;
369 }
370
371 /**
372 \brief Version 7.0 debug metadata
373 */
374 INLINE static bool
ll_feature_debug_info_ver70(const LL_IRFeatures * feature)375 ll_feature_debug_info_ver70(const LL_IRFeatures *feature)
376 {
377 return feature->version >= LL_Version_7_0;
378 }
379
380 /**
381 \brief Version 8.0 debug metadata
382 */
383 INLINE static bool
ll_feature_debug_info_ver80(const LL_IRFeatures * feature)384 ll_feature_debug_info_ver80(const LL_IRFeatures *feature)
385 {
386 return feature->version >= LL_Version_8_0;
387 }
388
389 /**
390 \brief Version 9.0 onwards uses 3 field syntax for constructors
391 and destructors
392 */
393 INLINE static bool
ll_feature_three_argument_ctor_and_dtor(const LL_IRFeatures * feature)394 ll_feature_three_argument_ctor_and_dtor(const LL_IRFeatures *feature)
395 {
396 return feature->version >= LL_Version_9_0;
397 }
398
399 INLINE static bool
ll_feature_use_distinct_metadata(const LL_IRFeatures * feature)400 ll_feature_use_distinct_metadata(const LL_IRFeatures *feature)
401 {
402 return feature->version >= LL_Version_3_8;
403 }
404
405 /**
406 \brief Version 3.9 debug metadata
407 */
408 INLINE static bool
ll_feature_subprogram_not_in_cu(const LL_IRFeatures * feature)409 ll_feature_subprogram_not_in_cu(const LL_IRFeatures *feature)
410 {
411 return feature->version >= LL_Version_3_9;
412 }
413
414 /**
415 \brief Do the debug links point from globals to metadata?
416
417 In LLVM 4.0, the direction of the link was reversed to point from globals to
418 their metadata descriptions rather than the other way around.
419 */
420 INLINE static bool
ll_feature_from_global_to_md(const LL_IRFeatures * feature)421 ll_feature_from_global_to_md(const LL_IRFeatures *feature)
422 {
423 return feature->version >= LL_Version_4_0;
424 }
425
426 /** \brief Use the LLVM 5.0 DIExpression */
427 INLINE static bool
ll_feature_use_5_diexpression(const LL_IRFeatures * feature)428 ll_feature_use_5_diexpression(const LL_IRFeatures *feature)
429 {
430 return feature->version >= LL_Version_5_0;
431 }
432
433 /** \brief Don't bother with \c !DIModule in earlier LLVMs */
434 INLINE static bool
ll_feature_create_dimodule(const LL_IRFeatures * feature)435 ll_feature_create_dimodule(const LL_IRFeatures *feature)
436 {
437 return feature->version >= LL_Version_5_0;
438 }
439
440 /** \brief Use PGI's LLVM debug metadata extensions */
441 INLINE static bool
ll_feature_has_diextensions(const LL_IRFeatures * feature)442 ll_feature_has_diextensions(const LL_IRFeatures *feature)
443 {
444 #ifdef FLANG_LLVM_EXTENSIONS
445 return feature->version >= LL_Version_5_0;
446 #else
447 return false;
448 #endif
449 }
450
451 INLINE static bool
ll_feature_no_file_in_namespace(const LL_IRFeatures * feature)452 ll_feature_no_file_in_namespace(const LL_IRFeatures *feature)
453 {
454 return feature->version >= LL_Version_5_0;
455 }
456
457 #else /* !HAVE_INLINE */
458 /* support a dusty deck C compiler */
459
460 #define ll_feature_use_addrspacecast(f) ((f)->version >= LL_Version_3_4)
461 #define ll_feature_debug_info_global_aliases(f) ((f)->version >= LL_Version_3_4)
462 #define ll_feature_debug_info_pre34(f) ((f)->version < LL_Version_3_4)
463 #define ll_feature_emit_nvvmir_version(f) ((f)->version >= LL_Version_3_4)
464 #define ll_feature_versioned_dw_tag(f) ((f)->version <= LL_Version_3_5)
465 #define ll_feature_omit_metadata_type(f) ((f)->version >= LL_Version_3_6)
466 #define ll_feature_debug_info_mdlocation(f) ((f)->version >= LL_Version_3_6)
467 #define ll_feature_alias_flags_first(f) ((f)->version >= LL_Version_3_7)
468 #define ll_feature_emit_func_signature_for_call(f) \
469 ((f)->version >= LL_Version_3_7)
470 #define ll_feature_dbg_local_variable_embeds_argnum(f) \
471 ((f)->version < LL_Version_3_7)
472 #define ll_feature_explicit_gep_load_type(f) ((f)->version >= LL_Version_3_7)
473 #define ll_feature_metadata_args_struct(f) ((f)->version < LL_Version_3_7)
474 #define ll_feature_use_specialized_mdnodes(f) ((f)->version >= LL_Version_3_7)
475 #define ll_feature_debug_info_need_file_descriptions(f) \
476 ((f)->version >= LL_Version_3_7)
477 #define ll_feature_dbg_declare_needs_expression_md(f) \
478 ((f)->version >= LL_Version_3_7)
479 #define ll_feature_eh_personality_on_landingpad(f) \
480 ((f)->version < LL_Version_3_7)
481 #define ll_feature_debug_info_DI_syntax(f) ((f)->version >= LL_Version_3_7)
482 #define ll_feature_debug_info_subrange_needs_count(f) \
483 ((f)->version >= LL_Version_3_7)
484 #define ll_feature_debug_info_ver38(f) ((f)->version >= LL_Version_3_8)
485 #define ll_feature_debug_info_ver70(f) ((f)->version >= LL_Version_7_0)
486 #define ll_feature_debug_info_ver80(f) ((f)->version >= LL_Version_8_0)
487 #define ll_feature_three_argument_ctor_and_dtor(f) \
488 ((f)->version >= LL_Version_9_0)
489 #define ll_feature_use_distinct_metadata(f) ((f)->version >= LL_Version_3_8)
490 #define ll_feature_subprogram_not_in_cu(f) ((f)->version >= LL_Version_3_9)
491 #define ll_feature_from_global_to_md(f) ((f)->version >= LL_Version_4_0)
492 #define ll_feature_use_5_diexpression(f) ((f)->version >= LL_Version_5_0)
493 #define ll_feature_create_dimodule(f) ((f)->version >= LL_Version_5_0)
494 #ifdef FLANG_LLVM_EXTENSIONS
495 #define ll_feature_has_diextensions(f) ((f)->version >= LL_Version_5_0)
496 #else
497 #define ll_feature_has_diextensions(f) (false)
498 #endif
499 #define ll_feature_no_file_in_namespace(f) ((f)->version >= LL_Version_5_0)
500
501 #endif
502
503 unsigned ll_feature_dwarf_version(const LL_IRFeatures *feature);
504
505 struct LL_Module;
506 struct LL_Object;
507
508 typedef struct LL_Module *LLVMModuleRef;
509
510 /**
511 \brief LL_Type represents an LLVM type.
512
513 These structs are uniqued, so they should never be modified.
514 */
515 typedef const struct LL_Type_ {
516 LLVMModuleRef module;
517 const char *str;
518 enum LL_BaseDataType data_type;
519 unsigned flags;
520
521 /**
522 The sub_types field depends on the value of \c data_type
523 \li \c LL_PTR [0] = pointee
524 \li \c LL_ARRAY [0] = element type, sub_elements = \#elements
525 \li \c LL_VECTOR [0] = lane type, sub_elements = \#lanes
526 \li \c LL_STRUCT [0..sub_elements-1] = members
527 \li \c LL_FUNCTION [0] = return type, [1..sub_elements-1] = argument types
528 */
529 const struct LL_Type_ **sub_types;
530
531 /**
532 For structure types, keep an optional array of the byte-offset of each
533 member of the struct.
534 */
535 unsigned *sub_offsets;
536
537 char *sub_padding;
538 BIGUINT64 sub_elements;
539 int addrspace;
540 } LL_Type;
541
542 /* Flags for LL_Type. */
543 #define LL_TYPE_IS_VARARGS_FUNC 0x01
544 #define LL_TYPE_IS_PACKED_STRUCT 0x02
545 #define LL_TYPE_IS_NAMED_STRUCT 0x04
546
547 /**
548 \brief LLVM Metadata
549
550 Metadata nodes are constant manifestly typed tuples of references to other
551 metadata nodes, metadata strings, or LLVM constants. The values that can be
552 stored in a metadata node are represented as an array of LL_MDRef references.
553
554 Metadata nodes and strings are normally uniqued to save space, but it is
555 possible to create distinct metadata nodes that don't participate in
556 uniquing.
557
558 Metadata can appear as annotations on instructions, or as module-global
559 named metadata.
560
561 LL_MDRef is a compact manifestly typed reference to the kind of data that can
562 be stored in a metadata node. An LL_MDRef can refer to:
563
564 \li A numbered metadata node, or \c NULL.
565 \li A metadata string.
566 \li A constant LLVM value.
567
568 LL_MDRef is passed around by value. It should be treated as an opaque type.
569 It cannot be transferred between different LL_Module instances.
570 */
571 typedef unsigned LL_MDRef;
572
573 #define LL_MDREF_kind(md) ((md) & ((1 << 3) - 1))
574 #define LL_MDREF_value(md) ((md) >> 3)
575 #define LL_MDREF_ctor(k, v) (((v) << 3) | LL_MDREF_kind(k))
576 #define LL_MDREF_INITIALIZER(key, val) LL_MDREF_ctor(key, val)
577 #define LL_MDREF_IS_NULL(md) ((md) == 0)
578
579 /**
580 \brief Bucket list for object to \c !dbg metadata
581
582 Sized to fit in 64 bytes to keep in a cache line (or 2)
583 */
584 typedef struct LL_ObjToDbgList {
585 #define LL_ObjToDbgBucketSize 13
586 struct LL_ObjToDbgList *next; ///< pointer to next bucket
587 LL_MDRef refs[LL_ObjToDbgBucketSize]; ///< bucket contents
588 unsigned used : 4; ///< count of objs in bucket
589 unsigned marks : LL_ObjToDbgBucketSize; ///< marker bits
590 } LL_ObjToDbgList;
591
592 /**
593 \brief Iterator for iterating over a LL_ObjToDbgList
594 */
595 typedef struct LL_ObjToDbgListIter {
596 LL_ObjToDbgList *list;
597 unsigned pos;
598 } LL_ObjToDbgListIter;
599
600 /**
601 \brief Metadata node types
602 */
603 enum LL_MDRef_Kind {
604 MDRef_Node, /**< Value=0 -> null, otherwise MDNode !n */
605 MDRef_String, /**< Value is an index into module->mdstrings. */
606 MDRef_Constant, /**< Value is an index into module->constants. */
607 MDRef_SmallInt1, /**< Valus is an i1 constant (0 or 1). */
608 /** Value is a small unsigned i32 value (within the range of mdref.value). */
609 MDRef_SmallInt32,
610 /** Value is a small unsigned i64 value (within the range of mdref.value). */
611 MDRef_SmallInt64
612 };
613
614 /**
615 \brief Classes for specialized metadata nodes.
616
617 Plain metadata nodes are simply printed as !{ ... }, but starting with LLVM
618 3.6, metadata nodes can be specialized to contain a certain class of data,
619 and they look like: !MDLocation(line: 2900, column:42, ...).
620
621 The metadata node classes should also be used when targeting LLVM < 3.6.
622 They will be used to annotate the emitted plain metadata nodes in comments.
623 */
624 typedef enum LL_MDClass {
625 LL_PlainMDNode, /**< \e not a DIxxx metadata */
626 LL_DICompileUnit,
627 LL_DIFile,
628 LL_DIBasicType,
629 LL_DISubroutineType,
630 LL_DIDerivedType,
631 LL_DICompositeType,
632 LL_DIFortranArrayType,
633 LL_DISubRange,
634 LL_DIFortranSubrange,
635 LL_DIEnumerator,
636 LL_DITemplateTypeParameter,
637 LL_DITemplateValueParameter,
638 LL_DINamespace,
639 LL_DIModule,
640 LL_DIGlobalVariable,
641 LL_DISubprogram,
642 LL_DILexicalBlock,
643 LL_DILexicalBlockFile,
644 LL_DILocation,
645 LL_DILocalVariable,
646 LL_DIExpression,
647 LL_DIObjCProperty,
648 LL_DIImportedEntity,
649 LL_DIGlobalVariableExpression,
650 LL_DIBasicType_string, /* deprecated */
651 LL_DIStringType,
652 LL_DICommonBlock,
653 LL_MDClass_MAX /**< must be last value and < 64 (6 bits) */
654 } LL_MDClass;
655
656 /**
657 The internal representation of metadata nodes shouldn't be needed outside
658 ll_structure.c and ll_write.c.
659 */
660 typedef struct LL_MDNode {
661 unsigned num_elems : 24;
662 LL_MDClass mdclass : 6;
663 unsigned is_distinct : 1;
664 unsigned is_flexible : 1;
665 LL_MDRef elem[];
666 } LL_MDNode;
667
668 typedef enum LL_DW_OP_t {
669 LL_DW_OP_NONE, /**< bogus value */
670 LL_DW_OP_deref,
671 LL_DW_OP_plus,
672 LL_DW_OP_minus,
673 LL_DW_OP_dup,
674 LL_DW_OP_LLVM_fragment,
675 LL_DW_OP_swap,
676 LL_DW_OP_xderef,
677 LL_DW_OP_stack_value,
678 LL_DW_OP_constu,
679 LL_DW_OP_plus_uconst,
680 LL_DW_OP_int,
681 LL_DW_OP_MAX /**< must be last value */
682 } LL_DW_OP_t;
683
684 INLINE static bool
ll_dw_op_ok(LL_DW_OP_t op)685 ll_dw_op_ok(LL_DW_OP_t op)
686 {
687 return (op > LL_DW_OP_NONE) && (op < LL_DW_OP_MAX);
688 }
689
690 /**
691 \brief Named module-level metadata.
692
693 We support a predefined set of well-known metadata names. When adding a new
694 name here, also update get_metadata_name() in ll_write.c.
695 */
696 typedef enum LL_MDName {
697 /** Module flags, defined in the LLVM Language Reference Manual. */
698 MD_llvm_module_flags,
699 /** DWARF compilation unit descriptors, from "Source Level Debugging with
700 LLVM". */
701 MD_llvm_dbg_cu,
702 MD_opencl_kernels, /**< SPIR */
703 MD_nvvm_annotations, /**< CUDA */
704 MD_nvvmir_version, /**< CUDA */
705 MD_NUM_NAMES /**< Must be last. */
706 } LL_MDName;
707
708 typedef struct LL_Value {
709 const char *data;
710 struct LL_Value *storage;
711 LL_Type *type_struct;
712 enum LL_ModuleVarType mvtype;
713 enum LL_LinkageType linkage;
714 int flags;
715 /* FIXME: This doesn't belong in LL_Value, it would be better in LL_Variable.
716 */
717 int dbg_sptr;
718 int align_bytes; /* For variables definition specify alignment in bytes */
719 LL_MDRef dbg_mdnode;
720 } LL_Value;
721
722 #define VAL_IS_GLOBAL_OFFSET 0x1
723 #define VAL_IS_TEXTURE 0x2
724 /* This value is a member of a parameter passed as a struct. */
725 #define VAL_IS_ARGSTRUCT_MEMBER 0x4
726 /* This value is a formal function parameter. */
727 #define VAL_IS_PARAM 0x8
728 /* The flags below are only valid when VAL_IS_PARAM is set. */
729 #define VAL_IS_BYVAL_PARAM 0x10
730 #define VAL_IS_NOALIAS_PARAM 0x20
731 /* the variables appear within the inline asm output list */
732 #define VAL_IS_ASM_OUTPUT 0x40
733 /* the variables appear within the inline asm input list */
734 #define VAL_IS_ASM_INPUT 0x80
735 #define VAL_IS_KERNEL_REF 0x1000
736
737 /**
738 \brief LL_Object represents an object stored in memory.
739
740 An object belongs to an address space, and it always has an address.
741 LL_Object can represent different kinds of objects.
742 */
743 enum LL_ObjectKind {
744 LLObj_Global, /**< A global variable */
745 LLObj_Const, /**< A global constant */
746 LLObj_Alias, /**< An alias referencing part of on other object */
747 LLObj_Local /**< A local variable on the stack */
748 };
749
750 enum LL_ObjectInitStyle {
751 /** Declaration of an object that is initialized in another module. */
752 LLInit_Declaration,
753
754 LLInit_Zero, /**< Object is initialized with all zeros. */
755
756 /** Object is initialized with a constant expression in
757 LL_Object::initializer */
758 LLInit_ConstExpr,
759
760 /** Object's initializer is printed by the provided function pointer. */
761 LLInit_Function
762 };
763
764 /**
765 \brief Ptr to function used to print out the initializer for an LL_Object
766
767 The function should print both the type and the value of the initializer. It
768 should not print a newline after the initializer.
769 */
770 typedef void (*LL_PrintInitializerFunction)(FILE *out,
771 struct LL_Object *object);
772
773 /**
774 \brief Data structure representing an LLVM Object
775
776 Warning: we don't support linkage types yet, that is a drawback in some cases
777 */
778 typedef struct LL_Object {
779
780 /** The address and name of the object. Also encodes the address space. */
781 LL_Value address;
782
783 /** The type of this object, without address space. When targeting LLVM
784 versions with typed pointers, this type should match the pointee type of
785 address above. */
786 LL_Type *type;
787
788 /** Alignment of object in bytes, or 0 to use LLVM's default alignment. */
789 unsigned align_bytes;
790
791 /** Linkage type for this object. The \c linkage field should be removed from
792 LL_Value, in favor of this field here. */
793 enum LL_LinkageType linkage;
794
795 enum LL_ObjectKind kind;
796 enum LL_ObjectInitStyle init_style;
797
798 union {
799 LL_Value *const_expr;
800 LL_PrintInitializerFunction function;
801 } init_data;
802
803 /** Symbol table reference. This value isn't used by ll_structure.c or
804 ll_write.c. It could be used by the init function to locate the data for
805 the object initializer.
806
807 Note that the lifetimes of Fortran symbol table entries are shorter than
808 the lifetime of an LL_Module. */
809 int sptr;
810
811 /** All the global objects in a module are kept in a linked list. */
812 struct LL_Object *next;
813 } LL_Object;
814
815 typedef struct LL_Symbols_ {
816 LL_Value **values;
817 unsigned int num_values;
818 } LL_Symbols;
819
820 typedef struct LL_ManagedMallocs_ {
821 void *storage;
822 struct LL_ManagedMallocs_ *next;
823 } LL_ManagedMallocs;
824
825 typedef struct LL_Instruction_ {
826 enum LL_Op op;
827 char *comment;
828 LL_Value **operands; /* Get off ground by limiting operands */
829 struct LL_Instruction_ *next; /**< Next instruction in basic block */
830 int num_operands;
831 LL_MDRef dbg_line_op; /**< scope debug info attached to instruction */
832 int flags; /**< HACK: use to record this as a within module call */
833 } LL_Instruction;
834
835 #define IN_MODULE_CALL 0x1
836 #define INST_CANCELED 0x2
837 #define INST_VOLATILE 0x4
838 /* This flag is only for getelementptr llvm ir */
839 #define INST_INBOUND 0x8
840
841 typedef struct LL_BasicBlock_ {
842 char *name;
843 LL_Instruction *first;
844 LL_Instruction *last;
845 struct LL_BasicBlock_ *next; /**< Next basic block in function */
846 } LL_BasicBlock;
847
848 typedef struct LL_Function_ {
849 const char *name;
850 LL_Type *return_type;
851 const char *attribute;
852 LL_BasicBlock *first;
853 LL_BasicBlock *last;
854 LL_Value **arguments;
855 unsigned int num_args;
856 struct LL_Function_ *next; /**< Next function in module */
857 struct LL_Symbols_ local_vars;
858 unsigned int num_locals;
859 int launch_bounds, launch_bounds_minctasm;
860 int is_kernel;
861 enum LL_LinkageType linkage;
862 const char *calling_convention;
863
864 /** Linked list of local variables. */
865 LL_Object *first_local, *last_local;
866
867 /** Set of names used for local values in this function. This does not include
868 values which are simply numbered (%1, %2, ...). */
869 hashset_t used_local_names;
870 } LL_Function;
871
872 /* Debug info state associated with a compilation unit. See lldebug.c. */
873 struct LL_DebugInfo;
874 typedef struct LL_DebugInfo LL_DebugInfo;
875
876 struct LL_ABI_Info_;
877
878 /**
879 \brief LLVM Module proxy
880 */
881 typedef struct LL_Module {
882 const char *module_name;
883 const char *target_triple;
884 const char *datalayout_string;
885 LL_IRFeatures ir;
886 LL_DebugInfo *debug_info;
887 LL_Function *first;
888 LL_Function *last;
889 LL_ManagedMallocs *first_malloc;
890 hashset_t anon_types;
891 struct LL_Symbols_ module_vars;
892 struct LL_Symbols_ user_structs;
893 hashmap_t user_structs_byid;
894 hashset_t used_type_names;
895 hashset_t used_global_names;
896 unsigned num_module_vars;
897 unsigned num_user_structs;
898 unsigned written_user_structs;
899 int num_refs;
900 LL_Value **extern_func_refs; /**< reference to external func */
901
902 /** Interned constants: Unmanaged array of managed LL_Values. */
903 LL_Value **constants;
904 unsigned constants_count;
905 unsigned constants_alloc;
906 hashmap_t constants_map;
907
908 /** Interned metadata strings: Unmanaged malloc'ed array of malloced
909 strings. */
910 const char **mdstrings;
911 unsigned mdstrings_count;
912 unsigned mdstrings_alloc;
913 hashmap_t mdstrings_map;
914
915 /** Numbered metadata nodes. <tt> MDNode !1 </tt> is in <tt> mdnodes[0] </tt>
916 and so on. */
917 LL_MDNode **mdnodes;
918 unsigned mdnodes_count;
919 unsigned mdnodes_alloc;
920 hashmap_t mdnodes_map;
921 hashmap_t mdnodes_fwdvars;
922
923 /** Named metadata in the module indexed by <tt>enum LL_MDName</tt>. Array of
924 unmanaged nodes */
925 LL_MDNode *named_mdnodes[MD_NUM_NAMES];
926 LL_MDRef omnipotentPtr;
927 LL_MDRef unrefPtr;
928 LL_MDRef loop_md;
929
930 /** Contents of the special global \c @llvm.used. List of pointers or constant
931 exprs. */
932 LL_Symbols llvm_used;
933 unsigned num_llvm_used;
934
935 hashmap_t global_debug_map; /**< sptr globalVar -> LL_MDRef */
936
937 /** Linked list of objects with global scope in this module. This list only
938 contains objects that haven't been printed yet. The memory of LL_Objects
939 is managed by LL_ManagedMallocs. */
940 LL_Object *first_global;
941 LL_Object *last_global;
942
943 hashmap_t module_debug_map; /**< module name -> LL_MDRef */
944 hashmap_t common_debug_map; /**< "scope_name/common_name" -> LL_MDRef */
945 hashmap_t modvar_debug_map; /**< "mod_name/var_name" -> LL_MDRef */
946
947 } LL_Module;
948
949 /**
950 \brief Map from function (keyed by linker name) to ABI
951 */
952 typedef struct LL_FnProto_ {
953 char *fn_name; /**< Key in map */
954 struct LL_ABI_Info_ *abi; /**< This is used to emit the function signature */
955 unsigned has_defined_body : 1; /**< True if this fn has a body */
956 unsigned is_weak : 1; /**< True if this fn has the attribute weak */
957 /** Only set if this is an intrinsic (has a predefined func decl string) */
958 char *intrinsic_decl_str;
959 /** Maintain a list (easier to read/debug ll output) */
960 struct LL_FnProto_ *next;
961 } LL_FnProto;
962
963 /**
964 \brief Iterate across all entries in the map and callback the handler.
965 */
966 typedef void (*LL_FnProto_Handler)(LL_FnProto *proto);
967
968 /*
969 * Interned constants.
970 *
971 * LL_Values representing LLVM constants can be reused everywhere in a module
972 * to save memory. These interned LL_Values must never be modified since they
973 * are shared.
974 */
975
976 LL_Value *ll_get_const_addrspacecast(LLVMModuleRef, LL_Value *value,
977 LL_Type *type);
978
979 /* Metadata */
980
981 #if HAVE_INLINE
982 /** \brief Get an LL_MDRef representing null. */
983 INLINE static LL_MDRef
ll_get_md_null(void)984 ll_get_md_null(void)
985 {
986 return LL_MDREF_INITIALIZER(MDRef_Node, 0);
987 }
988 #else /* !HAVE_INLINE */
989 #define ll_get_md_null() LL_MDREF_INITIALIZER(MDRef_Node, 0)
990 #endif /* HAVE_INLINE */
991
992 // FIXME
993 void write_mdref(FILE *out, LLVMModuleRef module, LL_MDRef rmdref,
994 int omit_metadata_type);
995 void ll_add_module_debug(hashmap_t map, const char *module_name, LL_MDRef mdnode);
996 LL_MDRef ll_get_module_debug(hashmap_t map, const char *module_name);
997
998 INLINE static LL_ObjToDbgList *
llObjtodbgCreate(void)999 llObjtodbgCreate(void)
1000 {
1001 return (LL_ObjToDbgList *)calloc(sizeof(LL_ObjToDbgList), 1);
1002 }
1003
1004 INLINE static void
llObjtodbgFirst(LL_ObjToDbgList * ods,LL_ObjToDbgListIter * iter)1005 llObjtodbgFirst(LL_ObjToDbgList *ods, LL_ObjToDbgListIter *iter)
1006 {
1007 iter->list = ods;
1008 iter->pos = 0;
1009 }
1010
1011 INLINE static bool
llObjtodbgAtEnd(LL_ObjToDbgListIter * iter)1012 llObjtodbgAtEnd(LL_ObjToDbgListIter *iter)
1013 {
1014 LL_ObjToDbgList *l = iter->list;
1015 return (!l) || ((!l->next) && (iter->pos == l->used));
1016 }
1017
1018 INLINE static void
llObjtodbgNext(LL_ObjToDbgListIter * iter)1019 llObjtodbgNext(LL_ObjToDbgListIter *iter)
1020 {
1021 iter->pos++;
1022 if ((iter->pos == LL_ObjToDbgBucketSize) && iter->list->next) {
1023 iter->list = iter->list->next;
1024 iter->pos = 0;
1025 }
1026 }
1027
1028 INLINE static LL_MDRef
llObjtodbgGet(LL_ObjToDbgListIter * iter)1029 llObjtodbgGet(LL_ObjToDbgListIter *iter)
1030 {
1031 return iter->list->refs[iter->pos];
1032 }
1033
1034 /**
1035 \brief ...
1036 */
1037 ISZ_T ll_type_bytes(LL_Type *type);
1038
1039 /**
1040 \brief ...
1041 */
1042 ISZ_T ll_type_bytes_unchecked(LL_Type *type);
1043
1044 /**
1045 \brief ...
1046 */
1047 bool ll_proto_has_defined_body(const char *fnname);
1048
1049 /**
1050 \brief ...
1051 */
1052 bool ll_proto_is_weak(const char *fnname);
1053
1054 /**
1055 \brief ...
1056 */
1057 const char *ll_create_local_name(LL_Function *function, const char *format,
1058 ...);
1059
1060 /**
1061 \brief ...
1062 */
1063 const char *ll_get_calling_conv_str(enum LL_CallConv cc);
1064
1065 /**
1066 \brief ...
1067 */
1068 const char *ll_get_str_type_for_basic_type(enum LL_BaseDataType type);
1069
1070 /**
1071 \brief ...
1072 */
1073 const char *ll_proto_key(SPTR func_sptr);
1074
1075 /**
1076 \brief ...
1077 */
1078 int ll_get_pointer_addrspace(LL_Type *ptr);
1079
1080 /**
1081 \brief ...
1082 */
1083 int ll_type_is_fp(LL_Type *ty);
1084
1085 /**
1086 \brief ...
1087 */
1088 int ll_type_is_mem_seq(LL_Type *ty);
1089
1090 /**
1091 \brief ...
1092 */
1093 int ll_type_is_pointer_to_function(LL_Type *ty);
1094
1095 /**
1096 \brief ...
1097 */
1098 LL_FnProto *ll_proto_add(const char *fnname, struct LL_ABI_Info_ *abi);
1099
1100 /**
1101 \brief ...
1102 */
1103 LL_FnProto *ll_proto_add_sptr(SPTR func_sptr, struct LL_ABI_Info_ *abi);
1104
1105 /**
1106 \brief ...
1107 */
1108 LL_Function *ll_create_function_from_type(LL_Type *func_type, const char *name);
1109
1110 /**
1111 \brief ...
1112 */
1113 LL_IRVersion get_llvm_version(void);
1114
1115 /**
1116 \brief ...
1117 */
1118 LL_MDRef ll_create_distinct_md_node(LLVMModuleRef module,
1119 enum LL_MDClass mdclass,
1120 const LL_MDRef *elems, unsigned nelems);
1121
1122 /**
1123 \brief ...
1124 */
1125 LL_MDRef ll_create_flexible_md_node(LLVMModuleRef module);
1126
1127 /**
1128 \brief ...
1129 */
1130 LL_MDRef ll_get_global_debug(LLVMModuleRef module, int sptr);
1131
1132 /**
1133 \brief ...
1134 */
1135 LL_MDRef ll_get_md_i1(int value);
1136
1137 /**
1138 \brief ...
1139 */
1140 LL_MDRef ll_get_md_i32(LLVMModuleRef module, int value);
1141
1142 /**
1143 \brief ...
1144 */
1145 LL_MDRef ll_get_md_i64(LLVMModuleRef module, long long value);
1146
1147 /**
1148 \brief ...
1149 */
1150 LL_MDRef ll_get_md_node(LLVMModuleRef module, enum LL_MDClass mdclass,
1151 const LL_MDRef *elems, unsigned nelems);
1152
1153 /**
1154 \brief ...
1155 */
1156 LL_MDRef ll_get_md_rawstring(LLVMModuleRef module, const void *rawstr,
1157 size_t length);
1158
1159 /**
1160 \brief ...
1161 */
1162 LL_MDRef ll_get_md_string(LLVMModuleRef module, const char *str);
1163
1164 /**
1165 \brief ...
1166 */
1167 LL_MDRef ll_get_md_value(LLVMModuleRef module, LL_Value *value);
1168
1169 /**
1170 \brief ...
1171 */
1172 LL_Object *ll_create_global_alias(LL_Value *aliasee_ptr, const char *format,
1173 ...);
1174
1175 /**
1176 \brief ...
1177 */
1178 LL_Object *ll_create_local_object(LL_Function *function, LL_Type *type,
1179 unsigned align_bytes, const char *format,
1180 ...);
1181
1182 /**
1183 \brief ...
1184 */
1185 LL_Type *ll_create_anon_struct_type(LLVMModuleRef module, LL_Type *elements[],
1186 unsigned num_elements, bool is_packed, int addrspace);
1187
1188 /**
1189 \brief ...
1190 */
1191 LL_Type *ll_create_basic_type(LLVMModuleRef module, enum LL_BaseDataType type,
1192 int addrspace);
1193
1194 /**
1195 \brief ...
1196 */
1197 LL_Type *ll_create_function_type(LLVMModuleRef module, LL_Type *args[],
1198 unsigned num_args, int is_varargs);
1199
1200 /**
1201 \brief ...
1202 */
1203 LL_Type *ll_create_int_type_with_addrspace(LLVMModuleRef module, unsigned bits, int addrspace);
1204
1205 /**
1206 \brief ...
1207 */
1208 LL_Type *ll_create_int_type(LLVMModuleRef module, unsigned bits);
1209
1210 /**
1211 \brief ...
1212 */
1213 LL_Type *ll_create_int_type_with_addrspace(LLVMModuleRef module, unsigned bits, int addrspace);
1214
1215 /**
1216 \brief ...
1217 */
1218 LL_Type *ll_create_named_struct_type(LLVMModuleRef module, int id, bool unique,
1219 const char *format, ...);
1220
1221 /**
1222 \brief ...
1223 */
1224 LL_Type *ll_get_addrspace_type(LL_Type *type, int addrspace);
1225
1226 /**
1227 \brief ...
1228 */
1229 LL_Type *ll_get_array_type(LL_Type *type, BIGUINT64 num_elements,
1230 int addrspace);
1231
1232 /**
1233 \brief ...
1234 */
1235 LL_Type *ll_get_pointer_type(LL_Type *type);
1236
1237 /**
1238 \brief ...
1239 */
1240 LL_Type *ll_get_struct_type(LLVMModuleRef module, int struct_id, int required);
1241
1242 /**
1243 \brief ...
1244 */
1245 LL_Type *ll_get_vector_type(LL_Type *type, unsigned num_elements);
1246
1247 /**
1248 \brief ...
1249 */
1250 LL_Type *ll_type_array_elety(LL_Type *ty);
1251
1252 /**
1253 \brief ...
1254 */
1255 LL_Value *ll_create_array_value_from_type(LLVMModuleRef module, LL_Type *type,
1256 const char *data, int addrspace);
1257
1258 /**
1259 \brief ...
1260 */
1261 LL_Value **ll_create_operands(LLVMModuleRef module, int num_operands);
1262
1263 /**
1264 \brief ...
1265 */
1266 LL_Value *ll_create_pointer_value_from_type(LLVMModuleRef module, LL_Type *type,
1267 const char *data, int addrspace);
1268
1269 /**
1270 \brief ...
1271 */
1272 LL_Value *ll_create_pointer_value(LLVMModuleRef module,
1273 enum LL_BaseDataType type, const char *data,
1274 int addrspace);
1275
1276 /**
1277 \brief ...
1278 */
1279 LL_Value *ll_create_value_from_type(LLVMModuleRef module, LL_Type *type,
1280 const char *data);
1281
1282 /**
1283 \brief ...
1284 */
1285 LL_Value *ll_get_const_addrspacecast(LLVMModuleRef module, LL_Value *value,
1286 LL_Type *type);
1287
1288 /**
1289 \brief ...
1290 */
1291 LL_Value *ll_get_const_bitcast(LLVMModuleRef module, LL_Value *value,
1292 LL_Type *type);
1293
1294 /**
1295 \brief ...
1296 */
1297 LL_Value *ll_get_const_gep(LLVMModuleRef module, LL_Value *ptr,
1298 unsigned num_idx, ...);
1299
1300 /**
1301 \brief ...
1302 */
1303 LL_Value *ll_get_const_int(LLVMModuleRef module, unsigned bits,
1304 long long value);
1305
1306 /**
1307 \brief ...
1308 */
1309 LL_Value *ll_get_function_pointer(LLVMModuleRef module, LL_Function *function);
1310
1311 /**
1312 \brief ...
1313 */
1314 LL_Value *ll_get_global_pointer(const char *name, LL_Type *type);
1315
1316 /**
1317 \brief ...
1318 */
1319 LL_Value *ll_named_struct_type_exists(LLVMModuleRef module, int id,
1320 const char *format, ...);
1321
1322 /**
1323 \brief ...
1324 */
1325 LLVMModuleRef ll_create_module(const char *module_name,
1326 const char *target_triple,
1327 enum LL_IRVersion llvm_ir_version);
1328
1329 /**
1330 \brief ...
1331 */
1332 struct LL_ABI_Info_ *ll_proto_get_abi(const char *fnname);
1333
1334 /**
1335 \brief ...
1336 */
1337 LL_Function *ll_create_function(LLVMModuleRef module, const char *name,
1338 LL_Type *return_type, int is_kernel,
1339 int launch_bounds, int launch_bounds_minctasm,
1340 const char *calling_convention,
1341 enum LL_LinkageType linkage);
1342
1343 /**
1344 \brief ...
1345 */
1346 unsigned ll_feature_dwarf_version(const LL_IRFeatures *feature);
1347
1348 /**
1349 \brief ...
1350 */
1351 unsigned ll_reserve_md_node(LLVMModuleRef module);
1352
1353 /**
1354 \brief ...
1355 */
1356 unsigned ll_type_int_bits(LL_Type *type);
1357
1358 /**
1359 \brief ...
1360 */
1361 void ll_add_global_debug(LLVMModuleRef module, int sptr, LL_MDRef mdnode);
1362
1363 /**
1364 \brief ...
1365 */
1366 void ll_append_llvm_used(LLVMModuleRef module, LL_Value *ptr);
1367
1368 /**
1369 \brief ...
1370 */
1371 void ll_create_sym(struct LL_Symbols_ *symbol_table, int index,
1372 LL_Value *new_value);
1373
1374 /**
1375 \brief Deallocate all memory used by function.
1376
1377 Note that this function is called automatically by ll_destroy_module(), so it
1378 should only be called explicitly for functions that are not in the module's
1379 linked list.
1380 */
1381 void ll_destroy_function(LL_Function *function);
1382
1383 /**
1384 \brief ...
1385 */
1386 void ll_destroy_mem(struct LL_ManagedMallocs_ *current);
1387
1388 /**
1389 \brief ...
1390 */
1391 void ll_destroy_module(LLVMModuleRef module);
1392
1393 /**
1394 \brief ...
1395 */
1396 void ll_extend_md_node(LLVMModuleRef module, LL_MDRef flexnode, LL_MDRef elem);
1397
1398 /**
1399 \brief ...
1400 */
1401 void ll_extend_named_md_node(LLVMModuleRef module, enum LL_MDName name,
1402 LL_MDRef elem);
1403
1404 /**
1405 \brief ...
1406 */
1407 void llObjtodbgFree(LL_ObjToDbgList *ods);
1408
1409 /**
1410 \brief ...
1411 */
1412 void llObjtodbgPush(LL_ObjToDbgList *odl, LL_MDRef md);
1413
1414 /**
1415 \brief ...
1416 */
1417 void ll_proto_dump(void);
1418
1419 /**
1420 \brief ...
1421 */
1422 void ll_proto_init(void);
1423
1424 /**
1425 \brief ...
1426 */
1427 void ll_proto_iterate(LL_FnProto_Handler callback);
1428
1429 /**
1430 \brief ...
1431 */
1432 void ll_proto_set_abi(const char *fnname, struct LL_ABI_Info_ *abi);
1433
1434 /**
1435 \brief ...
1436 */
1437 void ll_proto_set_defined_body(const char *fnname, bool has_defined);
1438
1439 /**
1440 \brief ...
1441 */
1442 void ll_proto_set_intrinsic(const char *fnname, const char *intrinsic_decl_str);
1443
1444 /**
1445 \brief ...
1446 */
1447 void ll_proto_set_weak(const char *fnname, bool is_weak);
1448
1449 /**
1450 \brief ...
1451 */
1452 void ll_remove_struct_type(LLVMModuleRef module, int struct_id);
1453
1454 /**
1455 \brief ...
1456 */
1457 void ll_reset_module_types(LLVMModuleRef module);
1458
1459 /**
1460 \brief ...
1461 */
1462 void ll_set_function_argument(LL_Function *function, int index,
1463 LL_Value *argument);
1464
1465 /**
1466 \brief ...
1467 */
1468 void ll_set_function_num_arguments(LL_Function *function, int num_args);
1469
1470 /**
1471 \brief ...
1472 */
1473 void ll_set_md_node(LLVMModuleRef module, unsigned mdNum, LL_MDNode *node);
1474
1475 /**
1476 \brief ...
1477 */
1478 void ll_set_named_md_node(LLVMModuleRef module, enum LL_MDName name,
1479 const LL_MDRef *elems, unsigned nelems);
1480
1481 /**
1482 \brief ...
1483 */
1484 void ll_set_struct_body(LL_Type *ctype, LL_Type *const *elements,
1485 unsigned *const offsets, char *const pads,
1486 unsigned num_elements, int is_packed);
1487
1488 /**
1489 \brief ...
1490 */
1491 void ll_update_md_node(LLVMModuleRef module, LL_MDRef node_to_update,
1492 unsigned elem_index, LL_MDRef elem);
1493
1494
1495 /**
1496 \brief Creates NVVM function
1497 */
1498 LL_Function *ll_create_device_function_from_type(LLVMModuleRef module,
1499 LL_Type *func_type,
1500 const char *name, int, int,
1501 const char *,
1502 enum LL_LinkageType);
1503
1504 #endif
1505
1506 #ifdef OMP_OFFLOAD_LLVM
1507 /**
1508 \brief Create an LL_Function
1509
1510 Must be given its name and full \c LL_FUNCTION type. Note: This does not add
1511 the new function to the module's list of functions.
1512 */
1513 void
1514 ll_set_device_function_arguments(LLVMModuleRef module,
1515 struct LL_Function_ *function,
1516 struct LL_ABI_Info_ *abi);
1517 #endif
1518