forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.h
3017 lines (2671 loc) · 92.6 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 -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* 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/ErrorHandling.h"
#include "llvm-c/Types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @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
*
* @{
*/
typedef enum {
LLVMZExtAttribute = 1<<0,
LLVMSExtAttribute = 1<<1,
LLVMNoReturnAttribute = 1<<2,
LLVMInRegAttribute = 1<<3,
LLVMStructRetAttribute = 1<<4,
LLVMNoUnwindAttribute = 1<<5,
LLVMNoAliasAttribute = 1<<6,
LLVMByValAttribute = 1<<7,
LLVMNestAttribute = 1<<8,
LLVMReadNoneAttribute = 1<<9,
LLVMReadOnlyAttribute = 1<<10,
LLVMNoInlineAttribute = 1<<11,
LLVMAlwaysInlineAttribute = 1<<12,
LLVMOptimizeForSizeAttribute = 1<<13,
LLVMStackProtectAttribute = 1<<14,
LLVMStackProtectReqAttribute = 1<<15,
LLVMAlignment = 31<<16,
LLVMNoCaptureAttribute = 1<<21,
LLVMNoRedZoneAttribute = 1<<22,
LLVMNoImplicitFloatAttribute = 1<<23,
LLVMNakedAttribute = 1<<24,
LLVMInlineHintAttribute = 1<<25,
LLVMStackAlignment = 7<<26,
LLVMReturnsTwice = 1 << 29,
LLVMUWTable = 1 << 30,
LLVMNonLazyBind = 1 << 31
/* FIXME: These attributes are currently not included in the C API as
a temporary measure until the API/ABI impact to the C API is understood
and the path forward agreed upon.
LLVMSanitizeAddressAttribute = 1ULL << 32,
LLVMStackProtectStrongAttribute = 1ULL<<35,
LLVMColdAttribute = 1ULL << 40,
LLVMOptimizeNoneAttribute = 1ULL << 42,
LLVMInAllocaAttribute = 1ULL << 43,
LLVMNonNullAttribute = 1ULL << 44,
LLVMJumpTableAttribute = 1ULL << 45,
LLVMConvergentAttribute = 1ULL << 46,
LLVMSafeStackAttribute = 1ULL << 47,
*/
} LLVMAttribute;
typedef enum {
/* Terminator Instructions */
LLVMRet = 1,
LLVMBr = 2,
LLVMSwitch = 3,
LLVMIndirectBr = 4,
LLVMInvoke = 5,
/* removed 6 due to API changes */
LLVMUnreachable = 7,
/* 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,
/* 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, /**< SIMD 'packed' format, or other vector type */
LLVMMetadataTypeKind, /**< Metadata */
LLVMX86_MMXTypeKind, /**< X86 MMX */
LLVMTokenTypeKind /**< Tokens */
} 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 {
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,
LLVMWebKitJSCallConv = 12,
LLVMAnyRegCallConv = 13,
LLVMX86StdcallCallConv = 64,
LLVMX86FastcallCallConv = 65
} LLVMCallConv;
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 */
} LLVMAtomicRMWBinOp;
typedef enum {
LLVMDSError,
LLVMDSWarning,
LLVMDSRemark,
LLVMDSNote
} LLVMDiagnosticSeverity;
/**
* @}
*/
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);
/**
* Set the yield callback function for this context.
*
* @see LLVMContext::setYieldCallback()
*/
void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
void *OpaqueHandle);
/**
* 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);
/**
* @}
*/
/**
* @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 data layout for a module.
*
* @see Module::getDataLayout()
*/
const char *LLVMGetDataLayout(LLVMModuleRef M);
/**
* Set the data layout for a module.
*
* @see Module::setDataLayout()
*/
void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
/**
* 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);
/**
* 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);
/**
* Set inline assembly for a module.
*
* @see Module::setModuleInlineAsm()
*/
void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
/**
* Obtain the context to which this module is associated.
*
* @see Module::getContext()
*/
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
/**
* Obtain a Type from a module by its registered name.
*/
LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
/**
* 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);
/**
* Add a function to a module under a specified name.
*
* @see llvm::Function::Create()
*/
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
LLVMTypeRef FunctionTy);
/**
* Obtain a Function value from a Module by its name.
*
* The returned value corresponds to a llvm::Function value.
*
* @see llvm::Module::getFunction()
*/
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
/**
* Obtain an iterator to the first Function in a Module.
*
* @see llvm::Module::begin()
*/
LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
/**
* Obtain an iterator to the last Function in a Module.
*
* @see llvm::Module::end()
*/
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
/**
* Advance a Function iterator to the next Function.
*
* Returns NULL if the iterator was already at the end and there are no more
* functions.
*/
LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
/**
* Decrement a Function iterator to the previous Function.
*
* Returns NULL if the iterator was already at the beginning and there are
* no previous functions.
*/
LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
/**
* @}
*/
/**
* @defgroup LLVMCCoreType Types
*
* Types represent the type of a value.
*
* Types are associated with a context instance. The context internally
* deduplicates types so there is only 1 instance of a specific type
* alive at a time. In other words, a unique type is shared among all
* consumers within a context.
*
* A Type in the C API corresponds to llvm::Type.
*
* Types have the following hierarchy:
*
* types:
* integer type
* real type
* function type
* sequence types:
* array type
* pointer type
* vector type
* void type
* label type
* opaque type
*
* @{
*/
/**
* Obtain the enumerated type of a Type instance.
*
* @see llvm::Type:getTypeID()
*/
LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
/**
* Whether the type has a known size.
*
* Things that don't have a size are abstract types, labels, and void.a
*
* @see llvm::Type::isSized()
*/
LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
/**
* Obtain the context to which this type instance is associated.
*
* @see llvm::Type::getContext()
*/
LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
/**
* Dump a representation of a type to stderr.
*
* @see llvm::Type::dump()
*/
void LLVMDumpType(LLVMTypeRef Val);
/**
* Return a string representation of the type. Use
* LLVMDisposeMessage to free the string.
*
* @see llvm::Type::print()
*/
char *LLVMPrintTypeToString(LLVMTypeRef Val);
/**
* @defgroup LLVMCCoreTypeInt Integer Types
*
* Functions in this section operate on integer types.
*
* @{
*/
/**
* Obtain an integer type from a context with specified bit width.
*/
LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
/**
* Obtain an integer type from the global context with a specified bit
* width.
*/
LLVMTypeRef LLVMInt1Type(void);
LLVMTypeRef LLVMInt8Type(void);
LLVMTypeRef LLVMInt16Type(void);
LLVMTypeRef LLVMInt32Type(void);
LLVMTypeRef LLVMInt64Type(void);
LLVMTypeRef LLVMInt128Type(void);
LLVMTypeRef LLVMIntType(unsigned NumBits);
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
/**
* @}
*/
/**
* @defgroup LLVMCCoreTypeFloat Floating Point Types
*
* @{
*/
/**
* Obtain a 16-bit floating point type from a context.
*/
LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
/**
* Obtain a 32-bit floating point type from a context.
*/
LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
/**
* Obtain a 64-bit floating point type from a context.
*/
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
/**
* Obtain a 80-bit floating point type (X87) from a context.
*/
LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
/**
* Obtain a 128-bit floating point type (112-bit mantissa) from a
* context.
*/
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
/**
* Obtain a 128-bit floating point type (two 64-bits) from a context.
*/
LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
/**
* Obtain a floating point type from the global context.
*
* These map to the functions in this group of the same name.
*/
LLVMTypeRef LLVMHalfType(void);
LLVMTypeRef LLVMFloatType(void);
LLVMTypeRef LLVMDoubleType(void);
LLVMTypeRef LLVMX86FP80Type(void);
LLVMTypeRef LLVMFP128Type(void);
LLVMTypeRef LLVMPPCFP128Type(void);
/**
* @}
*/
/**
* @defgroup LLVMCCoreTypeFunction Function Types
*
* @{
*/
/**
* Obtain a function type consisting of a specified signature.
*
* The function is defined as a tuple of a return Type, a list of
* parameter types, and whether the function is variadic.
*/
LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
LLVMTypeRef *ParamTypes, unsigned ParamCount,
LLVMBool IsVarArg);
/**
* Returns whether a function type is variadic.
*/
LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
/**
* Obtain the Type this function Type returns.
*/
LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
/**
* Obtain the number of parameters this function accepts.
*/
unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
/**
* Obtain the types of a function's parameters.
*
* The Dest parameter should point to a pre-allocated array of
* LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
* first LLVMCountParamTypes() entries in the array will be populated
* with LLVMTypeRef instances.
*
* @param FunctionTy The function type to operate on.
* @param Dest Memory address of an array to be filled with result.
*/
void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
/**
* @}
*/
/**
* @defgroup LLVMCCoreTypeStruct Structure Types
*
* These functions relate to LLVMTypeRef instances.
*
* @see llvm::StructType
*
* @{
*/
/**
* Create a new structure type in a context.
*
* A structure is specified by a list of inner elements/types and
* whether these can be packed together.
*
* @see llvm::StructType::create()
*/
LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
unsigned ElementCount, LLVMBool Packed);
/**
* Create a new structure type in the global context.
*
* @see llvm::StructType::create()
*/
LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
LLVMBool Packed);
/**
* Create an empty structure in a context having a specified name.
*
* @see llvm::StructType::create()
*/
LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
/**
* Obtain the name of a structure.
*
* @see llvm::StructType::getName()
*/
const char *LLVMGetStructName(LLVMTypeRef Ty);
/**
* Set the contents of a structure type.
*
* @see llvm::StructType::setBody()
*/
void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
unsigned ElementCount, LLVMBool Packed);
/**
* Get the number of elements defined inside the structure.
*
* @see llvm::StructType::getNumElements()
*/
unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
/**
* Get the elements within a structure.
*
* The function is passed the address of a pre-allocated array of
* LLVMTypeRef at least LLVMCountStructElementTypes() long. After
* invocation, this array will be populated with the structure's
* elements. The objects in the destination array will have a lifetime
* of the structure type itself, which is the lifetime of the context it
* is contained in.
*/
void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
/**
* Get the type of the element at a given index in the structure.
*
* @see llvm::StructType::getTypeAtIndex()
*/
LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
/**
* Determine whether a structure is packed.
*
* @see llvm::StructType::isPacked()
*/
LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
/**
* Determine whether a structure is opaque.
*
* @see llvm::StructType::isOpaque()
*/
LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
/**
* @}
*/
/**
* @defgroup LLVMCCoreTypeSequential Sequential Types
*
* Sequential types represents "arrays" of types. This is a super class
* for array, vector, and pointer types.
*
* @{
*/
/**
* Obtain the type of elements within a sequential type.
*
* This works on array, vector, and pointer types.
*
* @see llvm::SequentialType::getElementType()
*/
LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
/**
* Create a fixed size array type that refers to a specific type.
*
* The created type will exist in the context that its element type
* exists in.
*
* @see llvm::ArrayType::get()
*/
LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
/**
* Obtain the length of an array type.
*
* This only works on types that represent arrays.
*
* @see llvm::ArrayType::getNumElements()
*/
unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
/**
* Create a pointer type that points to a defined type.
*
* The created type will exist in the context that its pointee type
* exists in.
*
* @see llvm::PointerType::get()
*/
LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
/**
* Obtain the address space of a pointer type.
*
* This only works on types that represent pointers.
*
* @see llvm::PointerType::getAddressSpace()
*/
unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
/**
* Create a vector type that contains a defined type and has a specific
* number of elements.
*
* The created type will exist in the context thats its element type
* exists in.
*
* @see llvm::VectorType::get()
*/
LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
/**
* Obtain the number of elements in a vector type.
*