forked from dotnet/LLVMSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLVMValueRef.cs
More file actions
1163 lines (820 loc) · 41.4 KB
/
Copy pathLLVMValueRef.cs
File metadata and controls
1163 lines (820 loc) · 41.4 KB
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
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using static LLVMSharp.Interop.LLVMTailCallKind;
namespace LLVMSharp.Interop;
public unsafe partial struct LLVMValueRef(IntPtr handle) : IEquatable<LLVMValueRef>
{
public IntPtr Handle = handle;
public readonly uint Alignment
{
get
{
return ((IsAGlobalValue != null) || (IsAAllocaInst != null) || (IsALoadInst != null) || (IsAStoreInst != null)) ? LLVM.GetAlignment(this) : default;
}
set
{
LLVM.SetAlignment(this, value);
}
}
public readonly LLVMAtomicRMWBinOp AtomicRMWBinOp
{
get
{
return (IsAAtomicRMWInst != null) ? LLVM.GetAtomicRMWBinOp(this) : default;
}
set
{
LLVM.SetAtomicRMWBinOp(this, value);
}
}
public readonly uint BasicBlocksCount => (IsAFunction != null) ? LLVM.CountBasicBlocks(this) : default;
public readonly LLVMValueRef Condition
{
get
{
return (IsABranchInst != null) ? LLVM.GetCondition(this) : default;
}
set
{
LLVM.SetCondition(this, value);
}
}
public readonly ulong ConstIntZExt => (IsAConstantInt != null) ? LLVM.ConstIntGetZExtValue(this) : default;
public readonly long ConstIntSExt => (IsAConstantInt != null) ? LLVM.ConstIntGetSExtValue(this) : default;
public readonly LLVMOpcode ConstOpcode => (IsAConstantExpr != null) ? LLVM.GetConstOpcode(this) : default;
public readonly double ConstRealDouble => (IsAConstantFP != null) ? GetConstRealDouble(out _) : default;
public readonly LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetValueContext(this) : default;
public readonly LLVMDLLStorageClass DLLStorageClass
{
get
{
return (IsAGlobalValue != null) ? LLVM.GetDLLStorageClass(this) : default;
}
set
{
LLVM.SetDLLStorageClass(this, value);
}
}
public readonly LLVMBasicBlockRef EntryBasicBlock => ((IsAFunction != null) && (BasicBlocksCount != 0)) ? LLVM.GetEntryBasicBlock(this) : default;
public readonly LLVMRealPredicate FCmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetFCmpPredicate(this) : default;
public readonly LLVMBasicBlockRef FirstBasicBlock => (IsAFunction != null) ? LLVM.GetFirstBasicBlock(this) : default;
public readonly LLVMValueRef FirstParam => (IsAFunction != null) ? LLVM.GetFirstParam(this) : default;
public readonly LLVMUseRef FirstUse => (Handle != IntPtr.Zero) ? LLVM.GetFirstUse(this) : default;
public readonly uint FunctionCallConv
{
get
{
return (IsAFunction != null) ? LLVM.GetFunctionCallConv(this) : default;
}
set
{
LLVM.SetFunctionCallConv(this, value);
}
}
public readonly string GC
{
get
{
if (IsAFunction == null)
{
return string.Empty;
}
var pName = LLVM.GetGC(this);
if (pName == null)
{
return string.Empty;
}
return SpanExtensions.AsString(pName);
}
set
{
using var marshaledName = new MarshaledString(value.AsSpan());
LLVM.SetGC(this, marshaledName);
}
}
public readonly LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default;
public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0;
public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0;
public readonly bool HasUnnamedAddr
{
get
{
return (IsAGlobalValue != null) && LLVM.HasUnnamedAddr(this) != 0;
}
set
{
LLVM.SetUnnamedAddr(this, value ? 1 : 0);
}
}
public readonly LLVMIntPredicate ICmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetICmpPredicate(this) : default;
public readonly uint IncomingCount => (IsAPHINode != null) ? LLVM.CountIncoming(this) : default;
public readonly LLVMValueRef Initializer
{
get
{
return (IsAGlobalVariable != null) ? LLVM.GetInitializer(this) : default;
}
set
{
LLVM.SetInitializer(this, value);
}
}
public readonly uint InstructionCallConv
{
get
{
return ((IsACallBrInst != null) || (IsACallInst != null) || (IsAInvokeInst != null)) ? LLVM.GetInstructionCallConv(this) : default;
}
set
{
LLVM.SetInstructionCallConv(this, value);
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)] // Justification: causes native allocation
public readonly LLVMValueRef InstructionClone => (Handle != IntPtr.Zero) ? LLVM.InstructionClone(this) : default;
public readonly LLVMOpcode InstructionOpcode => (Handle != IntPtr.Zero) ? LLVM.GetInstructionOpcode(this) : default;
public readonly LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default;
public readonly uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default;
public readonly LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this);
public readonly LLVMValueRef IsAAllocaInst => LLVM.IsAAllocaInst(this);
public readonly LLVMValueRef IsAArgument => LLVM.IsAArgument(this);
public readonly LLVMValueRef IsAAtomicCmpXchgInst => LLVM.IsAAtomicCmpXchgInst(this);
public readonly LLVMValueRef IsAAtomicRMWInst => LLVM.IsAAtomicRMWInst(this);
public readonly LLVMValueRef IsABasicBlock => LLVM.IsABasicBlock(this);
public readonly LLVMValueRef IsABinaryOperator => LLVM.IsABinaryOperator(this);
public readonly LLVMValueRef IsABitCastInst => LLVM.IsABitCastInst(this);
public readonly LLVMValueRef IsABlockAddress => LLVM.IsABlockAddress(this);
public readonly LLVMValueRef IsABranchInst => LLVM.IsABranchInst(this);
public readonly LLVMValueRef IsACallBrInst => LLVM.IsACallBrInst(this);
public readonly LLVMValueRef IsACallInst => LLVM.IsACallInst(this);
public readonly LLVMValueRef IsACastInst => LLVM.IsACastInst(this);
public readonly LLVMValueRef IsACatchPadInst => LLVM.IsACatchPadInst(this);
public readonly LLVMValueRef IsACatchReturnInst => LLVM.IsACatchReturnInst(this);
public readonly LLVMValueRef IsACatchSwitchInst => LLVM.IsACatchSwitchInst(this);
public readonly LLVMValueRef IsACleanupPadInst => LLVM.IsACleanupPadInst(this);
public readonly LLVMValueRef IsACleanupReturnInst => LLVM.IsACleanupReturnInst(this);
public readonly LLVMValueRef IsACmpInst => LLVM.IsACmpInst(this);
public readonly LLVMValueRef IsAConstant => LLVM.IsAConstant(this);
public readonly LLVMValueRef IsAConstantAggregateZero => LLVM.IsAConstantAggregateZero(this);
public readonly LLVMValueRef IsAConstantArray => LLVM.IsAConstantArray(this);
public readonly LLVMValueRef IsAConstantDataArray => LLVM.IsAConstantDataArray(this);
public readonly LLVMValueRef IsAConstantDataSequential => LLVM.IsAConstantDataSequential(this);
public readonly LLVMValueRef IsAConstantDataVector => LLVM.IsAConstantDataVector(this);
public readonly LLVMValueRef IsAConstantExpr => LLVM.IsAConstantExpr(this);
public readonly LLVMValueRef IsAConstantFP => LLVM.IsAConstantFP(this);
public readonly LLVMValueRef IsAConstantInt => LLVM.IsAConstantInt(this);
public readonly LLVMValueRef IsAConstantPointerNull => LLVM.IsAConstantPointerNull(this);
public readonly LLVMValueRef IsAConstantStruct => LLVM.IsAConstantStruct(this);
public readonly LLVMValueRef IsAConstantTokenNone => LLVM.IsAConstantTokenNone(this);
public readonly LLVMValueRef IsAConstantVector => LLVM.IsAConstantVector(this);
public readonly LLVMValueRef IsADbgDeclareInst => LLVM.IsADbgDeclareInst(this);
public readonly LLVMValueRef IsADbgInfoIntrinsic => LLVM.IsADbgInfoIntrinsic(this);
public readonly LLVMValueRef IsADbgLabelInst => LLVM.IsADbgLabelInst(this);
public readonly LLVMValueRef IsADbgVariableIntrinsic => LLVM.IsADbgVariableIntrinsic(this);
public readonly LLVMValueRef IsAExtractElementInst => LLVM.IsAExtractElementInst(this);
public readonly LLVMValueRef IsAExtractValueInst => LLVM.IsAExtractValueInst(this);
public readonly LLVMValueRef IsAFCmpInst => LLVM.IsAFCmpInst(this);
public readonly LLVMValueRef IsAFenceInst => LLVM.IsAFenceInst(this);
public readonly LLVMValueRef IsAFPExtInst => LLVM.IsAFPExtInst(this);
public readonly LLVMValueRef IsAFPToSIInst => LLVM.IsAFPToSIInst(this);
public readonly LLVMValueRef IsAFPToUIInst => LLVM.IsAFPToUIInst(this);
public readonly LLVMValueRef IsAFPTruncInst => LLVM.IsAFPTruncInst(this);
public readonly LLVMValueRef IsAFreezeInst => LLVM.IsAFreezeInst(this);
public readonly LLVMValueRef IsAFuncletPadInst => LLVM.IsAFuncletPadInst(this);
public readonly LLVMValueRef IsAFunction => LLVM.IsAFunction(this);
public readonly LLVMValueRef IsAGetElementPtrInst => LLVM.IsAGetElementPtrInst(this);
public readonly LLVMValueRef IsAGlobalAlias => LLVM.IsAGlobalAlias(this);
public readonly LLVMValueRef IsAGlobalIFunc => LLVM.IsAGlobalIFunc(this);
public readonly LLVMValueRef IsAGlobalObject => LLVM.IsAGlobalObject(this);
public readonly LLVMValueRef IsAGlobalValue => LLVM.IsAGlobalValue(this);
public readonly LLVMValueRef IsAGlobalVariable => LLVM.IsAGlobalVariable(this);
public readonly LLVMValueRef IsAICmpInst => LLVM.IsAICmpInst(this);
public readonly LLVMValueRef IsAIndirectBrInst => LLVM.IsAIndirectBrInst(this);
public readonly LLVMValueRef IsAInlineAsm => LLVM.IsAInlineAsm(this);
public readonly LLVMValueRef IsAInsertElementInst => LLVM.IsAInsertElementInst(this);
public readonly LLVMValueRef IsAInsertValueInst => LLVM.IsAInsertValueInst(this);
public readonly LLVMValueRef IsAInstruction => LLVM.IsAInstruction(this);
public readonly LLVMValueRef IsAIntrinsicInst => LLVM.IsAIntrinsicInst(this);
public readonly LLVMValueRef IsAIntToPtrInst => LLVM.IsAIntToPtrInst(this);
public readonly LLVMValueRef IsAInvokeInst => LLVM.IsAInvokeInst(this);
public readonly LLVMValueRef IsALandingPadInst => LLVM.IsALandingPadInst(this);
public readonly LLVMValueRef IsALoadInst => LLVM.IsALoadInst(this);
public readonly LLVMValueRef IsAMDNode => LLVM.IsAMDNode(this);
public readonly LLVMValueRef IsAMDString => LLVM.IsAMDString(this);
public readonly LLVMValueRef IsAMemCpyInst => LLVM.IsAMemCpyInst(this);
public readonly LLVMValueRef IsAMemIntrinsic => LLVM.IsAMemIntrinsic(this);
public readonly LLVMValueRef IsAMemMoveInst => LLVM.IsAMemMoveInst(this);
public readonly LLVMValueRef IsAMemSetInst => LLVM.IsAMemSetInst(this);
public readonly LLVMValueRef IsAPHINode => LLVM.IsAPHINode(this);
public readonly LLVMValueRef IsAPoisonValue => LLVM.IsAPoisonValue(this);
public readonly LLVMValueRef IsAPtrToIntInst => LLVM.IsAPtrToIntInst(this);
public readonly LLVMValueRef IsAResumeInst => LLVM.IsAResumeInst(this);
public readonly LLVMValueRef IsAReturnInst => LLVM.IsAReturnInst(this);
public readonly LLVMValueRef IsASelectInst => LLVM.IsASelectInst(this);
public readonly LLVMValueRef IsASExtInst => LLVM.IsASExtInst(this);
public readonly LLVMValueRef IsAShuffleVectorInst => LLVM.IsAShuffleVectorInst(this);
public readonly LLVMValueRef IsASIToFPInst => LLVM.IsASIToFPInst(this);
public readonly LLVMValueRef IsAStoreInst => LLVM.IsAStoreInst(this);
public readonly LLVMValueRef IsASwitchInst => LLVM.IsASwitchInst(this);
public readonly LLVMValueRef IsATerminatorInst => (IsAInstruction != null) ? LLVM.IsATerminatorInst(this) : default;
public readonly LLVMValueRef IsATruncInst => LLVM.IsATruncInst(this);
public readonly LLVMValueRef IsAUIToFPInst => LLVM.IsAUIToFPInst(this);
public readonly LLVMValueRef IsAUnaryInstruction => LLVM.IsAUnaryInstruction(this);
public readonly LLVMValueRef IsAUnaryOperator => LLVM.IsAUnaryOperator(this);
public readonly LLVMValueRef IsAUndefValue => LLVM.IsAUndefValue(this);
public readonly LLVMValueRef IsAUnreachableInst => LLVM.IsAUnreachableInst(this);
public readonly LLVMValueRef IsAUser => LLVM.IsAUser(this);
public readonly LLVMValueRef IsAVAArgInst => LLVM.IsAVAArgInst(this);
public readonly LLVMValueRef IsAValueAsMetadata => LLVM.IsAValueAsMetadata(this);
public readonly LLVMValueRef IsAZExtInst => LLVM.IsAZExtInst(this);
public readonly bool IsBasicBlock => (Handle != IntPtr.Zero) && LLVM.ValueIsBasicBlock(this) != 0;
public readonly bool IsCleanup
{
get
{
return (IsALandingPadInst != null) && LLVM.IsCleanup(this) != 0;
}
set
{
LLVM.SetCleanup(this, value ? 1 : 0);
}
}
public readonly bool IsConditional => (IsABranchInst != null) && LLVM.IsConditional(this) != 0;
public readonly bool IsConstant => (Handle != IntPtr.Zero) && LLVM.IsConstant(this) != 0;
public readonly bool IsConstantString => (IsAConstantDataSequential != null) && LLVM.IsConstantString(this) != 0;
public readonly bool IsDeclaration => (IsAGlobalValue != null) && LLVM.IsDeclaration(this) != 0;
public readonly bool IsExternallyInitialized
{
get
{
return (IsAGlobalVariable != null) && LLVM.IsExternallyInitialized(this) != 0;
}
set
{
LLVM.SetExternallyInitialized(this, value ? 1 : 0);
}
}
public readonly bool IsGlobalConstant
{
get
{
return (IsAGlobalVariable != null) && LLVM.IsGlobalConstant(this) != 0;
}
set
{
LLVM.SetGlobalConstant(this, value ? 1 : 0);
}
}
public readonly bool IsNull => (Handle != IntPtr.Zero) && LLVM.IsNull(this) != 0;
public readonly bool IsPoison => (Handle != IntPtr.Zero) && LLVM.IsPoison(this) != 0;
public readonly bool IsTailCall
{
get
{
return (IsACallInst != null) && LLVM.IsTailCall(this) != 0;
}
set
{
LLVM.SetTailCall(this, value ? 1 : 0);
}
}
public readonly bool IsThreadLocal
{
get
{
return (IsAGlobalVariable != null) && LLVM.IsThreadLocal(this) != 0;
}
set
{
LLVM.SetThreadLocal(this, value ? 1 : 0);
}
}
public readonly bool IsUndef => (Handle != IntPtr.Zero) && LLVM.IsUndef(this) != 0;
public readonly LLVMValueKind Kind => (Handle != IntPtr.Zero) ? LLVM.GetValueKind(this) : default;
public readonly LLVMBasicBlockRef LastBasicBlock => (IsAFunction != null) ? LLVM.GetLastBasicBlock(this) : default;
public readonly LLVMValueRef LastParam => (IsAFunction != null) ? LLVM.GetLastParam(this) : default;
public readonly LLVMLinkage Linkage
{
get
{
return (IsAGlobalValue != null) ? LLVM.GetLinkage(this) : default;
}
set
{
LLVM.SetLinkage(this, value);
}
}
public readonly uint MDNodeOperandsCount => (Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) ? LLVM.GetMDNodeNumOperands(this) : default;
public readonly string Name
{
get
{
if (Handle == IntPtr.Zero)
{
return string.Empty;
}
var pStr = LLVM.GetValueName(this);
if (pStr == null)
{
return string.Empty;
}
return SpanExtensions.AsString(pStr);
}
set
{
using var marshaledName = new MarshaledString(value.AsSpan());
LLVM.SetValueName(this, marshaledName);
}
}
public readonly LLVMValueRef NextFunction => (IsAFunction != null) ? LLVM.GetNextFunction(this) : default;
public readonly LLVMValueRef NextGlobal => (IsAGlobalVariable != null) ? LLVM.GetNextGlobal(this) : default;
public readonly LLVMValueRef NextGlobalAlias => (IsAGlobalAlias != null) ? LLVM.GetNextGlobalAlias(this) : default;
public readonly LLVMValueRef NextGlobalIFunc => (IsAGlobalIFunc != null) ? LLVM.GetNextGlobalIFunc(this) : default;
public readonly LLVMValueRef NextInstruction => (IsAInstruction != null) ? LLVM.GetNextInstruction(this) : default;
public readonly LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default;
public readonly LLVMOpcode Opcode => Kind is LLVMValueKind.LLVMInstructionValueKind ? InstructionOpcode : ConstOpcode;
public readonly int OperandCount => ((Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) || (IsAUser != null)) ? LLVM.GetNumOperands(this) : default;
public readonly uint ParamsCount => (IsAFunction != null) ? LLVM.CountParams(this) : default;
public readonly LLVMValueRef ParamParent => (IsAArgument != null) ? LLVM.GetParamParent(this) : default;
public readonly LLVMValueRef PersonalityFn
{
get
{
return HasPersonalityFn ? LLVM.GetPersonalityFn(this) : default;
}
set
{
LLVM.SetPersonalityFn(this, value);
}
}
public readonly LLVMValueRef PreviousGlobal => (IsAGlobalVariable != null) ? LLVM.GetPreviousGlobal(this) : default;
public readonly LLVMValueRef PreviousGlobalAlias => (IsAGlobalAlias != null) ? LLVM.GetPreviousGlobalAlias(this) : default;
public readonly LLVMValueRef PreviousGlobalIFunc => (IsAGlobalIFunc != null) ? LLVM.GetPreviousGlobalIFunc(this) : default;
public readonly LLVMValueRef PreviousInstruction => (IsAInstruction != null) ? LLVM.GetPreviousInstruction(this) : default;
public readonly LLVMValueRef PreviousParam => (IsAArgument != null) ? LLVM.GetPreviousParam(this) : default;
public readonly LLVMValueRef PreviousFunction => (IsAFunction != null) ? LLVM.GetPreviousFunction(this) : default;
public readonly string Section
{
get
{
if (IsAGlobalValue == null)
{
return string.Empty;
}
var pSection = LLVM.GetSection(this);
if (pSection == null)
{
return string.Empty;
}
return SpanExtensions.AsString(pSection);
}
set
{
using var marshaledSection = new MarshaledString(value.AsSpan());
LLVM.SetSection(this, marshaledSection);
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)] // Justification: can throw
public readonly LLVMMetadataRef Subprogram => (IsAFunction != null) ? LLVM.GetSubprogram(this) : default;
public readonly uint SuccessorsCount => (IsAInstruction != null) ? LLVM.GetNumSuccessors(this) : default;
public readonly LLVMBasicBlockRef SwitchDefaultDest => (IsASwitchInst != null) ? LLVM.GetSwitchDefaultDest(this) : default;
public readonly LLVMTailCallKind TailCallKind
{
get
{
return (IsACallInst != null) ? LLVM.GetTailCallKind(this) : LLVMTailCallKindNone;
}
set
{
LLVM.SetTailCallKind(this, value);
}
}
public readonly LLVMThreadLocalMode ThreadLocalMode
{
get
{
return (IsAGlobalVariable != null) ? LLVM.GetThreadLocalMode(this) : default;
}
set
{
LLVM.SetThreadLocalMode(this, value);
}
}
public readonly LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default;
public readonly LLVMValueUsesEnumerable Uses => new LLVMValueUsesEnumerable(this);
public readonly LLVMVisibility Visibility
{
get
{
return (IsAGlobalValue != null) ? LLVM.GetVisibility(this) : default;
}
set
{
LLVM.SetVisibility(this, value);
}
}
public readonly bool Volatile
{
get
{
return ((IsALoadInst != null) || (IsAStoreInst != null) || (IsAAtomicRMWInst != null) || (IsAAtomicCmpXchgInst != null)) && LLVM.GetVolatile(this) != 0;
}
set
{
LLVM.SetVolatile(this, value ? 1 : 0);
}
}
public readonly bool Weak
{
get
{
return (IsAAtomicCmpXchgInst != null) && LLVM.GetWeak(this) != 0;
}
set
{
LLVM.SetWeak(this, value ? 1 : 0);
}
}
public static implicit operator LLVMValueRef(LLVMOpaqueValue* value) => new LLVMValueRef((IntPtr)value);
public static implicit operator LLVMOpaqueValue*(LLVMValueRef value) => (LLVMOpaqueValue*)value.Handle;
public static bool operator ==(LLVMValueRef left, LLVMValueRef right) => left.Handle == right.Handle;
public static bool operator !=(LLVMValueRef left, LLVMValueRef right) => !(left == right);
public static LLVMValueRef CreateConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstAdd(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstAddrSpaceCast(ConstantVal, ToType);
public static LLVMValueRef CreateConstAllOnes(LLVMTypeRef Ty) => LLVM.ConstAllOnes(Ty);
public static LLVMValueRef CreateConstArray(LLVMTypeRef ElementTy, LLVMValueRef[] ConstantVals) => CreateConstArray(ElementTy, ConstantVals.AsSpan());
public static LLVMValueRef CreateConstArray(LLVMTypeRef ElementTy, ReadOnlySpan<LLVMValueRef> ConstantVals)
{
fixed (LLVMValueRef* pConstantVals = ConstantVals)
{
return LLVM.ConstArray(ElementTy, (LLVMOpaqueValue**)pConstantVals, (uint)ConstantVals.Length);
}
}
public static LLVMValueRef CreateConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstBitCast(ConstantVal, ToType);
public static LLVMValueRef CreateConstExtractElement(LLVMValueRef VectorConstant, LLVMValueRef IndexConstant) => LLVM.ConstExtractElement(VectorConstant, IndexConstant);
public static LLVMValueRef CreateConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, LLVMValueRef[] ConstantIndices) => CreateConstGEP2(Ty, ConstantVal, ConstantIndices.AsSpan());
public static LLVMValueRef CreateConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, ReadOnlySpan<LLVMValueRef> ConstantIndices)
{
fixed (LLVMValueRef* pConstantIndices = ConstantIndices)
{
return LLVM.ConstGEP2(Ty, ConstantVal, (LLVMOpaqueValue**)pConstantIndices, (uint)ConstantIndices.Length);
}
}
public static LLVMValueRef CreateConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, LLVMValueRef[] ConstantIndices) => CreateConstInBoundsGEP2(Ty, ConstantVal, ConstantIndices.AsSpan());
public static LLVMValueRef CreateConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, ReadOnlySpan<LLVMValueRef> ConstantIndices)
{
fixed (LLVMValueRef* pConstantIndices = ConstantIndices)
{
return LLVM.ConstInBoundsGEP2(Ty, ConstantVal, (LLVMOpaqueValue**)pConstantIndices, (uint)ConstantIndices.Length);
}
}
public static LLVMValueRef CreateConstInlineAsm(LLVMTypeRef Ty, string AsmString, string Constraints, bool HasSideEffects, bool IsAlignStack) => CreateConstInlineAsm(Ty, AsmString.AsSpan(), Constraints.AsSpan(), HasSideEffects, IsAlignStack);
public static LLVMValueRef CreateConstInlineAsm(LLVMTypeRef Ty, ReadOnlySpan<char> AsmString, ReadOnlySpan<char> Constraints, bool HasSideEffects, bool IsAlignStack)
{
using var marshaledAsmString = new MarshaledString(AsmString);
using var marshaledConstraints = new MarshaledString(Constraints);
return LLVM.ConstInlineAsm(Ty, marshaledAsmString, marshaledConstraints, HasSideEffects ? 1 : 0, IsAlignStack ? 1 : 0);
}
public static LLVMValueRef CreateConstInsertElement(LLVMValueRef VectorConstant, LLVMValueRef ElementValueConstant, LLVMValueRef IndexConstant) => LLVM.ConstInsertElement(VectorConstant, ElementValueConstant, IndexConstant);
public static LLVMValueRef CreateConstInt(LLVMTypeRef IntTy, ulong N, bool SignExtend = false) => LLVM.ConstInt(IntTy, N, SignExtend ? 1 : 0);
public static LLVMValueRef CreateConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, ulong[] Words) => CreateConstIntOfArbitraryPrecision(IntTy, Words.AsSpan());
public static LLVMValueRef CreateConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, ReadOnlySpan<ulong> Words)
{
fixed (ulong* pWords = Words)
{
return LLVM.ConstIntOfArbitraryPrecision(IntTy, (uint)Words.Length, pWords);
}
}
public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, string Text, byte Radix) => CreateConstIntOfString(IntTy, Text.AsSpan(), Radix);
public static LLVMValueRef CreateConstIntOfString(LLVMTypeRef IntTy, ReadOnlySpan<char> Text, byte Radix)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstIntOfString(IntTy, marshaledText, Radix);
}
public static LLVMValueRef CreateConstIntOfStringAndSize(LLVMTypeRef IntTy, string Text, uint SLen, byte Radix) => CreateConstIntOfStringAndSize(IntTy, Text.AsSpan(0, (int)SLen), Radix);
public static LLVMValueRef CreateConstIntOfStringAndSize(LLVMTypeRef IntTy, ReadOnlySpan<char> Text, byte Radix)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstIntOfStringAndSize(IntTy, marshaledText, (uint)marshaledText.Length, Radix);
}
public static LLVMValueRef CreateConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstIntToPtr(ConstantVal, ToType);
public static LLVMValueRef CreateConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstMul(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef[] ConstantVals) => CreateConstNamedStruct(StructTy, ConstantVals.AsSpan());
public static LLVMValueRef CreateConstNamedStruct(LLVMTypeRef StructTy, ReadOnlySpan<LLVMValueRef> ConstantVals)
{
fixed (LLVMValueRef* pConstantVals = ConstantVals)
{
return LLVM.ConstNamedStruct(StructTy, (LLVMOpaqueValue**)pConstantVals, (uint)ConstantVals.Length);
}
}
public static LLVMValueRef CreateConstNeg(LLVMValueRef ConstantVal) => LLVM.ConstNeg(ConstantVal);
public static LLVMValueRef CreateConstNot(LLVMValueRef ConstantVal) => LLVM.ConstNot(ConstantVal);
public static LLVMValueRef CreateConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNSWAdd(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNSWMul(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNSWNeg(LLVMValueRef ConstantVal) => LLVM.ConstNSWNeg(ConstantVal);
public static LLVMValueRef CreateConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNSWSub(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNull(LLVMTypeRef Ty) => LLVM.ConstNull(Ty);
public static LLVMValueRef CreateConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNUWAdd(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNUWMul(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstNUWSub(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstPointerCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstPointerCast(ConstantVal, ToType);
public static LLVMValueRef CreateConstPointerNull(LLVMTypeRef Ty) => LLVM.ConstPointerNull(Ty);
public static LLVMValueRef CreateConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstPtrToInt(ConstantVal, ToType);
public static LLVMValueRef CreateConstReal(LLVMTypeRef RealTy, double N) => LLVM.ConstReal(RealTy, N);
public static LLVMValueRef CreateConstRealOfString(LLVMTypeRef RealTy, string Text) => CreateConstRealOfString(RealTy, Text.AsSpan());
public static LLVMValueRef CreateConstRealOfString(LLVMTypeRef RealTy, ReadOnlySpan<char> Text)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstRealOfString(RealTy, marshaledText);
}
public static LLVMValueRef CreateConstRealOfStringAndSize(LLVMTypeRef RealTy, string Text, uint SLen) => CreateConstRealOfStringAndSize(RealTy, Text.AsSpan(0, (int)SLen));
public static LLVMValueRef CreateConstRealOfStringAndSize(LLVMTypeRef RealTy, ReadOnlySpan<char> Text)
{
using var marshaledText = new MarshaledString(Text);
return LLVM.ConstRealOfStringAndSize(RealTy, marshaledText, (uint)marshaledText.Length);
}
public static LLVMValueRef CreateConstShuffleVector(LLVMValueRef VectorAConstant, LLVMValueRef VectorBConstant, LLVMValueRef MaskConstant) => LLVM.ConstShuffleVector(VectorAConstant, VectorBConstant, MaskConstant);
public static LLVMValueRef CreateConstStruct(LLVMValueRef[] ConstantVals, bool Packed) => CreateConstStruct(ConstantVals.AsSpan(), Packed);
public static LLVMValueRef CreateConstStruct(ReadOnlySpan<LLVMValueRef> ConstantVals, bool Packed)
{
fixed (LLVMValueRef* pConstantVals = ConstantVals)
{
return LLVM.ConstStruct((LLVMOpaqueValue**)pConstantVals, (uint)ConstantVals.Length, Packed ? 1 : 0);
}
}
public static LLVMValueRef CreateConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstSub(LHSConstant, RHSConstant);
public static LLVMValueRef CreateConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstTrunc(ConstantVal, ToType);
public static LLVMValueRef CreateConstTruncOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) => LLVM.ConstTruncOrBitCast(ConstantVal, ToType);
public static LLVMValueRef CreateConstVector(LLVMValueRef[] ScalarConstantVars) => CreateConstVector(ScalarConstantVars.AsSpan());
public static LLVMValueRef CreateConstVector(ReadOnlySpan<LLVMValueRef> ScalarConstantVars)
{
fixed (LLVMValueRef* pScalarConstantVars = ScalarConstantVars)
{
return LLVM.ConstVector((LLVMOpaqueValue**)pScalarConstantVars, (uint)ScalarConstantVars.Length);
}
}
public static LLVMValueRef CreateConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) => LLVM.ConstXor(LHSConstant, RHSConstant);
public static LLVMValueRef CreateMDNode(LLVMValueRef[] Vals) => CreateMDNode(Vals.AsSpan());
public static LLVMValueRef CreateMDNode(ReadOnlySpan<LLVMValueRef> Vals)
{
fixed (LLVMValueRef* pVals = Vals)
{
return LLVM.MDNode((LLVMOpaqueValue**)pVals, (uint)Vals.Length);
}
}
public readonly void AddCase(LLVMValueRef OnVal, LLVMBasicBlockRef Dest) => LLVM.AddCase(this, OnVal, Dest);
public readonly void AddClause(LLVMValueRef ClauseVal) => LLVM.AddClause(this, ClauseVal);
public readonly void AddDestination(LLVMBasicBlockRef Dest) => LLVM.AddDestination(this, Dest);
public readonly void AddIncoming(LLVMValueRef[] IncomingValues, LLVMBasicBlockRef[] IncomingBlocks, uint Count) => AddIncoming(IncomingValues.AsSpan(), IncomingBlocks.AsSpan(), Count);
public readonly void AddIncoming(ReadOnlySpan<LLVMValueRef> IncomingValues, ReadOnlySpan<LLVMBasicBlockRef> IncomingBlocks, uint Count)
{
fixed (LLVMValueRef* pIncomingValues = IncomingValues)
fixed (LLVMBasicBlockRef* pIncomingBlocks = IncomingBlocks)
{
LLVM.AddIncoming(this, (LLVMOpaqueValue**)pIncomingValues, (LLVMOpaqueBasicBlock**)pIncomingBlocks, Count);
}
}
public readonly void AddTargetDependentFunctionAttr(string A, string V) => AddTargetDependentFunctionAttr(A.AsSpan(), V.AsSpan());
public readonly void AddTargetDependentFunctionAttr(ReadOnlySpan<char> A, ReadOnlySpan<char> V)
{
using var marshaledA = new MarshaledString(A);
using var marshaledV = new MarshaledString(V);
LLVM.AddTargetDependentFunctionAttr(this, marshaledA, marshaledV);
}
public readonly LLVMBasicBlockRef AppendBasicBlock(string Name) => AppendBasicBlock(Name.AsSpan());
public readonly LLVMBasicBlockRef AppendBasicBlock(ReadOnlySpan<char> Name)
{
using var marshaledName = new MarshaledString(Name);
return LLVM.AppendBasicBlock(this, marshaledName);
}
public readonly LLVMBasicBlockRef AsBasicBlock() => LLVM.ValueAsBasicBlock(this);
public readonly LLVMMetadataRef AsMetadata() => LLVM.ValueAsMetadata(this);
public readonly void DeleteFunction() => LLVM.DeleteFunction(this);
public readonly void DeleteGlobal() => LLVM.DeleteGlobal(this);
public readonly void Dump() => LLVM.DumpValue(this);
public override readonly bool Equals(object? obj) => (obj is LLVMValueRef other) && Equals(other);
public readonly bool Equals(LLVMValueRef other) => this == other;
public readonly LLVMMetadataRef[] GetAllMetadataOtherThanDebugLoc()
{
if (IsAInstruction == null)
{
return [];
}
nuint metadataCount = 0;
var ptr = LLVM.InstructionGetAllMetadataOtherThanDebugLoc(this, &metadataCount);
LLVMMetadataRef[] metadataArray;
if (metadataCount == 0)
{
metadataArray = [];
}
else
{
metadataArray = new LLVMMetadataRef[metadataCount];
for (uint i = 0; i < metadataCount; i++)
{
metadataArray[i] = LLVM.ValueMetadataEntriesGetMetadata(ptr, i);
}
LLVM.DisposeValueMetadataEntries(ptr);
}
LLVM.DisposeValueMetadataEntries(ptr);
return metadataArray;
}
public readonly string GetAsString(out UIntPtr Length)
{
fixed (UIntPtr* pLength = &Length)
{
var pStr = LLVM.GetAsString(this, pLength);
if (pStr == null)
{
return string.Empty;
}
var span = new ReadOnlySpan<byte>(pStr, (int)Length);
return span.AsString();
}
}
public readonly LLVMBasicBlockRef[] GetBasicBlocks()
{
if (IsAFunction == null)
{
return [];
}
var destination = new LLVMBasicBlockRef[BasicBlocksCount];
GetBasicBlocks(destination);
return destination;
}
public readonly void GetBasicBlocks(Span<LLVMBasicBlockRef> destination)
{
if (IsAFunction == null)
{
return;
}
ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, BasicBlocksCount);
fixed (LLVMBasicBlockRef* pBasicBlocks = destination)
{
LLVM.GetBasicBlocks(this, (LLVMOpaqueBasicBlock**)pBasicBlocks);
}
}
public readonly IEnumerable<LLVMValueRef> GetInstructions()
{
if (IsAFunction != default)
{
return GetBasicBlocks().SelectMany(b => b.Instructions);
}
else if (IsABasicBlock != default)
{
return AsBasicBlock().Instructions;
}
else if (IsAInstruction != default)
{
return [this];
}
else
{
return [];
}
}
public readonly LLVMValueRef[] GetMDNodeOperands()
{
if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind)
{
return [];
}
var destination = new LLVMValueRef[MDNodeOperandsCount];
GetMDNodeOperands(destination);
return destination;
}
public readonly void GetMDNodeOperands(Span<LLVMValueRef> destination)
{
if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind)
{
return;
}
ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, MDNodeOperandsCount);
fixed (LLVMValueRef* pDest = destination)
{
LLVM.GetMDNodeOperands(this, (LLVMOpaqueValue**)pDest);
}
}
public readonly LLVMValueRef[] GetParams()
{
if (IsAFunction == null)
{