forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCore.h
4265 lines (3773 loc) · 133 KB
/
Core.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
|* *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This header declares the C interface to libLLVMCore.a, which implements *|
|* the LLVM intermediate representation. *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_C_CORE_H
#define LLVM_C_CORE_H
#include "llvm-c/Deprecated.h"
#include "llvm-c/ErrorHandling.h"
#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMC LLVM-C: C interface to LLVM
*
* This module exposes parts of the LLVM library as a C API.
*
* @{
*/
/**
* @defgroup LLVMCTransforms Transforms
*/
/**
* @defgroup LLVMCCore Core
*
* This modules provide an interface to libLLVMCore, which implements
* the LLVM intermediate representation as well as other related types
* and utilities.
*
* Many exotic languages can interoperate with C code but have a harder time
* with C++ due to name mangling. So in addition to C, this interface enables
* tools written in such languages.
*
* @{
*/
/**
* @defgroup LLVMCCoreTypes Types and Enumerations
*
* @{
*/
/// External users depend on the following values being stable. It is not safe
/// to reorder them.
typedef enum {
/* Terminator Instructions */
LLVMRet = 1,
LLVMBr = 2,
LLVMSwitch = 3,
LLVMIndirectBr = 4,
LLVMInvoke = 5,
/* removed 6 due to API changes */
LLVMUnreachable = 7,
LLVMCallBr = 67,
/* Standard Unary Operators */
LLVMFNeg = 66,
/* Standard Binary Operators */
LLVMAdd = 8,
LLVMFAdd = 9,
LLVMSub = 10,
LLVMFSub = 11,
LLVMMul = 12,
LLVMFMul = 13,
LLVMUDiv = 14,
LLVMSDiv = 15,
LLVMFDiv = 16,
LLVMURem = 17,
LLVMSRem = 18,
LLVMFRem = 19,
/* Logical Operators */
LLVMShl = 20,
LLVMLShr = 21,
LLVMAShr = 22,
LLVMAnd = 23,
LLVMOr = 24,
LLVMXor = 25,
/* Memory Operators */
LLVMAlloca = 26,
LLVMLoad = 27,
LLVMStore = 28,
LLVMGetElementPtr = 29,
/* Cast Operators */
LLVMTrunc = 30,
LLVMZExt = 31,
LLVMSExt = 32,
LLVMFPToUI = 33,
LLVMFPToSI = 34,
LLVMUIToFP = 35,
LLVMSIToFP = 36,
LLVMFPTrunc = 37,
LLVMFPExt = 38,
LLVMPtrToInt = 39,
LLVMIntToPtr = 40,
LLVMBitCast = 41,
LLVMAddrSpaceCast = 60,
/* Other Operators */
LLVMICmp = 42,
LLVMFCmp = 43,
LLVMPHI = 44,
LLVMCall = 45,
LLVMSelect = 46,
LLVMUserOp1 = 47,
LLVMUserOp2 = 48,
LLVMVAArg = 49,
LLVMExtractElement = 50,
LLVMInsertElement = 51,
LLVMShuffleVector = 52,
LLVMExtractValue = 53,
LLVMInsertValue = 54,
LLVMFreeze = 68,
/* Atomic operators */
LLVMFence = 55,
LLVMAtomicCmpXchg = 56,
LLVMAtomicRMW = 57,
/* Exception Handling Operators */
LLVMResume = 58,
LLVMLandingPad = 59,
LLVMCleanupRet = 61,
LLVMCatchRet = 62,
LLVMCatchPad = 63,
LLVMCleanupPad = 64,
LLVMCatchSwitch = 65
} LLVMOpcode;
typedef enum {
LLVMVoidTypeKind, /**< type with no size */
LLVMHalfTypeKind, /**< 16 bit floating point type */
LLVMFloatTypeKind, /**< 32 bit floating point type */
LLVMDoubleTypeKind, /**< 64 bit floating point type */
LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
LLVMLabelTypeKind, /**< Labels */
LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
LLVMFunctionTypeKind, /**< Functions */
LLVMStructTypeKind, /**< Structures */
LLVMArrayTypeKind, /**< Arrays */
LLVMPointerTypeKind, /**< Pointers */
LLVMVectorTypeKind, /**< Fixed width SIMD vector type */
LLVMMetadataTypeKind, /**< Metadata */
LLVMX86_MMXTypeKind, /**< X86 MMX */
LLVMTokenTypeKind, /**< Tokens */
LLVMScalableVectorTypeKind, /**< Scalable SIMD vector type */
LLVMBFloatTypeKind, /**< 16 bit brain floating point type */
LLVMX86_AMXTypeKind /**< X86 AMX */
} LLVMTypeKind;
typedef enum {
LLVMExternalLinkage, /**< Externally visible function */
LLVMAvailableExternallyLinkage,
LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
equivalent. */
LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
LLVMWeakODRLinkage, /**< Same, but only replaced by something
equivalent. */
LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
LLVMInternalLinkage, /**< Rename collisions when linking (static
functions) */
LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
LLVMDLLImportLinkage, /**< Obsolete */
LLVMDLLExportLinkage, /**< Obsolete */
LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
LLVMGhostLinkage, /**< Obsolete */
LLVMCommonLinkage, /**< Tentative definitions */
LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
} LLVMLinkage;
typedef enum {
LLVMDefaultVisibility, /**< The GV is visible */
LLVMHiddenVisibility, /**< The GV is hidden */
LLVMProtectedVisibility /**< The GV is protected */
} LLVMVisibility;
typedef enum {
LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
} LLVMUnnamedAddr;
typedef enum {
LLVMDefaultStorageClass = 0,
LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
} LLVMDLLStorageClass;
typedef enum {
LLVMCCallConv = 0,
LLVMFastCallConv = 8,
LLVMColdCallConv = 9,
LLVMGHCCallConv = 10,
LLVMHiPECallConv = 11,
LLVMWebKitJSCallConv = 12,
LLVMAnyRegCallConv = 13,
LLVMPreserveMostCallConv = 14,
LLVMPreserveAllCallConv = 15,
LLVMSwiftCallConv = 16,
LLVMCXXFASTTLSCallConv = 17,
LLVMX86StdcallCallConv = 64,
LLVMX86FastcallCallConv = 65,
LLVMARMAPCSCallConv = 66,
LLVMARMAAPCSCallConv = 67,
LLVMARMAAPCSVFPCallConv = 68,
LLVMMSP430INTRCallConv = 69,
LLVMX86ThisCallCallConv = 70,
LLVMPTXKernelCallConv = 71,
LLVMPTXDeviceCallConv = 72,
LLVMSPIRFUNCCallConv = 75,
LLVMSPIRKERNELCallConv = 76,
LLVMIntelOCLBICallConv = 77,
LLVMX8664SysVCallConv = 78,
LLVMWin64CallConv = 79,
LLVMX86VectorCallCallConv = 80,
LLVMHHVMCallConv = 81,
LLVMHHVMCCallConv = 82,
LLVMX86INTRCallConv = 83,
LLVMAVRINTRCallConv = 84,
LLVMAVRSIGNALCallConv = 85,
LLVMAVRBUILTINCallConv = 86,
LLVMAMDGPUVSCallConv = 87,
LLVMAMDGPUGSCallConv = 88,
LLVMAMDGPUPSCallConv = 89,
LLVMAMDGPUCSCallConv = 90,
LLVMAMDGPUKERNELCallConv = 91,
LLVMX86RegCallCallConv = 92,
LLVMAMDGPUHSCallConv = 93,
LLVMMSP430BUILTINCallConv = 94,
LLVMAMDGPULSCallConv = 95,
LLVMAMDGPUESCallConv = 96
} LLVMCallConv;
typedef enum {
LLVMArgumentValueKind,
LLVMBasicBlockValueKind,
LLVMMemoryUseValueKind,
LLVMMemoryDefValueKind,
LLVMMemoryPhiValueKind,
LLVMFunctionValueKind,
LLVMGlobalAliasValueKind,
LLVMGlobalIFuncValueKind,
LLVMGlobalVariableValueKind,
LLVMBlockAddressValueKind,
LLVMConstantExprValueKind,
LLVMConstantArrayValueKind,
LLVMConstantStructValueKind,
LLVMConstantVectorValueKind,
LLVMUndefValueValueKind,
LLVMConstantAggregateZeroValueKind,
LLVMConstantDataArrayValueKind,
LLVMConstantDataVectorValueKind,
LLVMConstantIntValueKind,
LLVMConstantFPValueKind,
LLVMConstantPointerNullValueKind,
LLVMConstantTokenNoneValueKind,
LLVMMetadataAsValueValueKind,
LLVMInlineAsmValueKind,
LLVMInstructionValueKind,
LLVMPoisonValueValueKind
} LLVMValueKind;
typedef enum {
LLVMIntEQ = 32, /**< equal */
LLVMIntNE, /**< not equal */
LLVMIntUGT, /**< unsigned greater than */
LLVMIntUGE, /**< unsigned greater or equal */
LLVMIntULT, /**< unsigned less than */
LLVMIntULE, /**< unsigned less or equal */
LLVMIntSGT, /**< signed greater than */
LLVMIntSGE, /**< signed greater or equal */
LLVMIntSLT, /**< signed less than */
LLVMIntSLE /**< signed less or equal */
} LLVMIntPredicate;
typedef enum {
LLVMRealPredicateFalse, /**< Always false (always folded) */
LLVMRealOEQ, /**< True if ordered and equal */
LLVMRealOGT, /**< True if ordered and greater than */
LLVMRealOGE, /**< True if ordered and greater than or equal */
LLVMRealOLT, /**< True if ordered and less than */
LLVMRealOLE, /**< True if ordered and less than or equal */
LLVMRealONE, /**< True if ordered and operands are unequal */
LLVMRealORD, /**< True if ordered (no nans) */
LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
LLVMRealUEQ, /**< True if unordered or equal */
LLVMRealUGT, /**< True if unordered or greater than */
LLVMRealUGE, /**< True if unordered, greater than, or equal */
LLVMRealULT, /**< True if unordered or less than */
LLVMRealULE, /**< True if unordered, less than, or equal */
LLVMRealUNE, /**< True if unordered or not equal */
LLVMRealPredicateTrue /**< Always true (always folded) */
} LLVMRealPredicate;
typedef enum {
LLVMLandingPadCatch, /**< A catch clause */
LLVMLandingPadFilter /**< A filter clause */
} LLVMLandingPadClauseTy;
typedef enum {
LLVMNotThreadLocal = 0,
LLVMGeneralDynamicTLSModel,
LLVMLocalDynamicTLSModel,
LLVMInitialExecTLSModel,
LLVMLocalExecTLSModel
} LLVMThreadLocalMode;
typedef enum {
LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
somewhat sane results, lock free. */
LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
operations affecting a specific address,
a consistent ordering exists */
LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
necessary to acquire a lock to access other
memory with normal loads and stores. */
LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
a barrier of the sort necessary to release
a lock. */
LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
Release barrier (for fences and
operations which both read and write
memory). */
LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
for loads and Release
semantics for stores.
Additionally, it guarantees
that a total ordering exists
between all
SequentiallyConsistent
operations. */
} LLVMAtomicOrdering;
typedef enum {
LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
original using a signed comparison and return
the old one */
LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
original using a signed comparison and return
the old one */
LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
original using an unsigned comparison and return
the old one */
LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
original using an unsigned comparison and return
the old one */
LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
old one */
LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
old one */
LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
original using an floating point comparison and
return the old one */
LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
original using an floating point comparison and
return the old one */
} LLVMAtomicRMWBinOp;
typedef enum {
LLVMDSError,
LLVMDSWarning,
LLVMDSRemark,
LLVMDSNote
} LLVMDiagnosticSeverity;
typedef enum {
LLVMInlineAsmDialectATT,
LLVMInlineAsmDialectIntel
} LLVMInlineAsmDialect;
typedef enum {
/**
* Emits an error if two values disagree, otherwise the resulting value is
* that of the operands.
*
* @see Module::ModFlagBehavior::Error
*/
LLVMModuleFlagBehaviorError,
/**
* Emits a warning if two values disagree. The result value will be the
* operand for the flag from the first module being linked.
*
* @see Module::ModFlagBehavior::Warning
*/
LLVMModuleFlagBehaviorWarning,
/**
* Adds a requirement that another module flag be present and have a
* specified value after linking is performed. The value must be a metadata
* pair, where the first element of the pair is the ID of the module flag
* to be restricted, and the second element of the pair is the value the
* module flag should be restricted to. This behavior can be used to
* restrict the allowable results (via triggering of an error) of linking
* IDs with the **Override** behavior.
*
* @see Module::ModFlagBehavior::Require
*/
LLVMModuleFlagBehaviorRequire,
/**
* Uses the specified value, regardless of the behavior or value of the
* other module. If both modules specify **Override**, but the values
* differ, an error will be emitted.
*
* @see Module::ModFlagBehavior::Override
*/
LLVMModuleFlagBehaviorOverride,
/**
* Appends the two values, which are required to be metadata nodes.
*
* @see Module::ModFlagBehavior::Append
*/
LLVMModuleFlagBehaviorAppend,
/**
* Appends the two values, which are required to be metadata
* nodes. However, duplicate entries in the second list are dropped
* during the append operation.
*
* @see Module::ModFlagBehavior::AppendUnique
*/
LLVMModuleFlagBehaviorAppendUnique,
} LLVMModuleFlagBehavior;
/**
* Attribute index are either LLVMAttributeReturnIndex,
* LLVMAttributeFunctionIndex or a parameter number from 1 to N.
*/
enum {
LLVMAttributeReturnIndex = 0U,
// ISO C restricts enumerator values to range of 'int'
// (4294967295 is too large)
// LLVMAttributeFunctionIndex = ~0U,
LLVMAttributeFunctionIndex = -1,
};
typedef unsigned LLVMAttributeIndex;
/**
* @}
*/
void LLVMInitializeCore(LLVMPassRegistryRef R);
/** Deallocate and destroy all ManagedStatic variables.
@see llvm::llvm_shutdown
@see ManagedStatic */
void LLVMShutdown(void);
/*===-- Error handling ----------------------------------------------------===*/
char *LLVMCreateMessage(const char *Message);
void LLVMDisposeMessage(char *Message);
/**
* @defgroup LLVMCCoreContext Contexts
*
* Contexts are execution states for the core LLVM IR system.
*
* Most types are tied to a context instance. Multiple contexts can
* exist simultaneously. A single context is not thread safe. However,
* different contexts can execute on different threads simultaneously.
*
* @{
*/
typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
/**
* Create a new context.
*
* Every call to this function should be paired with a call to
* LLVMContextDispose() or the context will leak memory.
*/
LLVMContextRef LLVMContextCreate(void);
/**
* Obtain the global context instance.
*/
LLVMContextRef LLVMGetGlobalContext(void);
/**
* Set the diagnostic handler for this context.
*/
void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
LLVMDiagnosticHandler Handler,
void *DiagnosticContext);
/**
* Get the diagnostic handler of this context.
*/
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
/**
* Get the diagnostic context of this context.
*/
void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
/**
* Set the yield callback function for this context.
*
* @see LLVMContext::setYieldCallback()
*/
void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
void *OpaqueHandle);
/**
* Retrieve whether the given context is set to discard all value names.
*
* @see LLVMContext::shouldDiscardValueNames()
*/
LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
/**
* Set whether the given context discards all value names.
*
* If true, only the names of GlobalValue objects will be available in the IR.
* This can be used to save memory and runtime, especially in release mode.
*
* @see LLVMContext::setDiscardValueNames()
*/
void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
/**
* Set whether the given context is in opaque pointer mode.
*
* @see LLVMContext::setOpaquePointers()
*/
void LLVMContextSetOpaquePointers(LLVMContextRef C, LLVMBool OpaquePointers);
/**
* Destroy a context instance.
*
* This should be called for every call to LLVMContextCreate() or memory
* will be leaked.
*/
void LLVMContextDispose(LLVMContextRef C);
/**
* Return a string representation of the DiagnosticInfo. Use
* LLVMDisposeMessage to free the string.
*
* @see DiagnosticInfo::print()
*/
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
/**
* Return an enum LLVMDiagnosticSeverity.
*
* @see DiagnosticInfo::getSeverity()
*/
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
unsigned SLen);
unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
/**
* Return an unique id given the name of a enum attribute,
* or 0 if no attribute by that name exists.
*
* See http://llvm.org/docs/LangRef.html#parameter-attributes
* and http://llvm.org/docs/LangRef.html#function-attributes
* for the list of available attributes.
*
* NB: Attribute names and/or id are subject to change without
* going through the C API deprecation cycle.
*/
unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
unsigned LLVMGetLastEnumAttributeKind(void);
/**
* Create an enum attribute.
*/
LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
uint64_t Val);
/**
* Get the unique id corresponding to the enum attribute
* passed as argument.
*/
unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
/**
* Get the enum attribute's value. 0 is returned if none exists.
*/
uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
/**
* Create a type attribute
*/
LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
LLVMTypeRef type_ref);
/**
* Get the type attribute's value.
*/
LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A);
/**
* Create a string attribute.
*/
LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
const char *K, unsigned KLength,
const char *V, unsigned VLength);
/**
* Get the string attribute's kind.
*/
const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
/**
* Get the string attribute's value.
*/
const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
/**
* Check for the different types of attributes.
*/
LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A);
/**
* Obtain a Type from a context by its registered name.
*/
LLVMTypeRef LLVMGetTypeByName2(LLVMContextRef C, const char *Name);
/**
* @}
*/
/**
* @defgroup LLVMCCoreModule Modules
*
* Modules represent the top-level structure in an LLVM program. An LLVM
* module is effectively a translation unit or a collection of
* translation units merged together.
*
* @{
*/
/**
* Create a new, empty module in the global context.
*
* This is equivalent to calling LLVMModuleCreateWithNameInContext with
* LLVMGetGlobalContext() as the context parameter.
*
* Every invocation should be paired with LLVMDisposeModule() or memory
* will be leaked.
*/
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
/**
* Create a new, empty module in a specific context.
*
* Every invocation should be paired with LLVMDisposeModule() or memory
* will be leaked.
*/
LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
LLVMContextRef C);
/**
* Return an exact copy of the specified module.
*/
LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
/**
* Destroy a module instance.
*
* This must be called for every created module or memory will be
* leaked.
*/
void LLVMDisposeModule(LLVMModuleRef M);
/**
* Obtain the identifier of a module.
*
* @param M Module to obtain identifier of
* @param Len Out parameter which holds the length of the returned string.
* @return The identifier of M.
* @see Module::getModuleIdentifier()
*/
const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
/**
* Set the identifier of a module to a string Ident with length Len.
*
* @param M The module to set identifier
* @param Ident The string to set M's identifier to
* @param Len Length of Ident
* @see Module::setModuleIdentifier()
*/
void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
/**
* Obtain the module's original source file name.
*
* @param M Module to obtain the name of
* @param Len Out parameter which holds the length of the returned string
* @return The original source file name of M
* @see Module::getSourceFileName()
*/
const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
/**
* Set the original source file name of a module to a string Name with length
* Len.
*
* @param M The module to set the source file name of
* @param Name The string to set M's source file name to
* @param Len Length of Name
* @see Module::setSourceFileName()
*/
void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
/**
* Obtain the data layout for a module.
*
* @see Module::getDataLayoutStr()
*
* LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
* but match the name of another method on the module. Prefer the use
* of LLVMGetDataLayoutStr, which is not ambiguous.
*/
const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
const char *LLVMGetDataLayout(LLVMModuleRef M);
/**
* Set the data layout for a module.
*
* @see Module::setDataLayout()
*/
void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
/**
* Obtain the target triple for a module.
*
* @see Module::getTargetTriple()
*/
const char *LLVMGetTarget(LLVMModuleRef M);
/**
* Set the target triple for a module.
*
* @see Module::setTargetTriple()
*/
void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
/**
* Returns the module flags as an array of flag-key-value triples. The caller
* is responsible for freeing this array by calling
* \c LLVMDisposeModuleFlagsMetadata.
*
* @see Module::getModuleFlagsMetadata()
*/
LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
/**
* Destroys module flags metadata entries.
*/
void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
/**
* Returns the flag behavior for a module flag entry at a specific index.
*
* @see Module::ModuleFlagEntry::Behavior
*/
LLVMModuleFlagBehavior
LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
unsigned Index);
/**
* Returns the key for a module flag entry at a specific index.
*
* @see Module::ModuleFlagEntry::Key
*/
const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
unsigned Index, size_t *Len);
/**
* Returns the metadata for a module flag entry at a specific index.
*
* @see Module::ModuleFlagEntry::Val
*/
LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
unsigned Index);
/**
* Add a module-level flag to the module-level flags metadata if it doesn't
* already exist.
*
* @see Module::getModuleFlag()
*/
LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
const char *Key, size_t KeyLen);
/**
* Add a module-level flag to the module-level flags metadata if it doesn't
* already exist.
*
* @see Module::addModuleFlag()
*/
void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
const char *Key, size_t KeyLen,
LLVMMetadataRef Val);
/**
* Dump a representation of a module to stderr.
*
* @see Module::dump()
*/
void LLVMDumpModule(LLVMModuleRef M);
/**
* Print a representation of a module to a file. The ErrorMessage needs to be
* disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
*
* @see Module::print()
*/
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
char **ErrorMessage);
/**
* Return a string representation of the module. Use
* LLVMDisposeMessage to free the string.
*
* @see Module::print()
*/
char *LLVMPrintModuleToString(LLVMModuleRef M);
/**
* Get inline assembly for a module.
*
* @see Module::getModuleInlineAsm()
*/
const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
/**
* Set inline assembly for a module.
*
* @see Module::setModuleInlineAsm()
*/
void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
/**
* Append inline assembly to a module.
*
* @see Module::appendModuleInlineAsm()
*/
void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
/**
* Create the specified uniqued inline asm string.
*
* @see InlineAsm::get()
*/
LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
size_t AsmStringSize, char *Constraints,
size_t ConstraintsSize, LLVMBool HasSideEffects,
LLVMBool IsAlignStack,
LLVMInlineAsmDialect Dialect, LLVMBool CanThrow);
/**
* Obtain the context to which this module is associated.
*
* @see Module::getContext()
*/
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
/** Deprecated: Use LLVMGetTypeByName2 instead. */
LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
/**
* Obtain an iterator to the first NamedMDNode in a Module.
*
* @see llvm::Module::named_metadata_begin()
*/
LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
/**
* Obtain an iterator to the last NamedMDNode in a Module.
*
* @see llvm::Module::named_metadata_end()
*/
LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
/**
* Advance a NamedMDNode iterator to the next NamedMDNode.
*
* Returns NULL if the iterator was already at the end and there are no more
* named metadata nodes.
*/
LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
/**
* Decrement a NamedMDNode iterator to the previous NamedMDNode.
*
* Returns NULL if the iterator was already at the beginning and there are
* no previous named metadata nodes.
*/
LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
/**
* Retrieve a NamedMDNode with the given name, returning NULL if no such
* node exists.
*
* @see llvm::Module::getNamedMetadata()
*/
LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
const char *Name, size_t NameLen);
/**
* Retrieve a NamedMDNode with the given name, creating a new node if no such
* node exists.
*
* @see llvm::Module::getOrInsertNamedMetadata()
*/
LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
const char *Name,
size_t NameLen);
/**
* Retrieve the name of a NamedMDNode.
*
* @see llvm::NamedMDNode::getName()
*/
const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
size_t *NameLen);
/**
* Obtain the number of operands for named metadata in a module.
*
* @see llvm::Module::getNamedMetadata()
*/
unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
/**
* Obtain the named metadata operands for a module.
*
* The passed LLVMValueRef pointer should refer to an array of
* LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
* array will be populated with the LLVMValueRef instances. Each
* instance corresponds to a llvm::MDNode.
*
* @see llvm::Module::getNamedMetadata()
* @see llvm::MDNode::getOperand()
*/
void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
LLVMValueRef *Dest);
/**
* Add an operand to named metadata.
*
* @see llvm::Module::getNamedMetadata()
* @see llvm::MDNode::addOperand()
*/
void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
LLVMValueRef Val);
/**
* Return the directory of the debug location for this value, which must be
* an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
*
* @see llvm::Instruction::getDebugLoc()
* @see llvm::GlobalVariable::getDebugInfo()
* @see llvm::Function::getSubprogram()
*/