llvm_quick 181.0.0-alpha.7

Rust's wrapper for llvm.
Documentation
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
use std::fmt::{Debug, Formatter};
use std::ops::Deref;

use llvm_sys::core::*;
use llvm_sys::*;

use crate::core::Message;
use crate::type_tag::*;
use crate::*;

pub mod constants;
pub mod function;
pub mod usage;
pub mod user_value;

impl<T: TypeTag> Debug for Value<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.print_to_string().to_str().unwrap())
    }
}

impl<T: TypeTag> Value<T> {
    pub fn to_any(&self) -> &Value<any> {
        self.cast()
    }
}

impl<T: TypeTag> Debug for Argument<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(self.deref(), f)
    }
}

impl<T: TypeTag> Argument<T> {
    pub fn to_any(&self) -> &Argument<any> {
        self.cast()
    }
}

impl<T: TypeTag> Debug for Constant<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(self.deref(), f)
    }
}

impl<T: TypeTag> Constant<T> {
    pub fn to_any(&self) -> &Constant<any> {
        self.cast()
    }
}

impl<T: TypeTag> Debug for GlobalValue<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(self.deref(), f)
    }
}

impl<T: TypeTag> GlobalValue<T> {
    pub fn to_any(&self) -> &GlobalValue<any> {
        self.cast()
    }
}

impl<T: TypeTag> Debug for Instruction<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(self.deref(), f)
    }
}

impl<T: TypeTag> Instruction<T> {
    pub fn to_any(&self) -> &Instruction<any> {
        self.cast()
    }
}

impl<T: TypeTag> Value<T> {
    pub fn get_kind(&self) -> LLVMValueKind {
        unsafe { LLVMGetValueKind(self.as_raw()) }
    }

    /// Obtain the type of a value.
    pub fn get_type(&self) -> &Type<T> {
        unsafe { Type::from_raw(LLVMTypeOf(self.as_raw())) }
    }

    /// Obtain the string name of a value.
    pub fn get_name(&self) -> &[u8] {
        unsafe {
            let mut len = 0;
            let ptr = LLVMGetValueName2(self.as_raw(), &mut len);
            std::slice::from_raw_parts(ptr.cast(), len)
        }
    }

    /// Set the string name of a value.
    pub fn set_name(&self, name: &[u8]) {
        unsafe { LLVMSetValueName2(self.as_raw(), name.as_ptr() as _, name.len()) }
    }

    pub fn dump(&self) {
        unsafe { LLVMDumpValue(self.as_raw()) }
    }

    /// Return a string representation of the value.
    pub fn print_to_string(&self) -> Message {
        unsafe { Message::from_raw(LLVMPrintValueToString(self.as_raw())) }
    }

    pub fn replace_all_uses_with(&self, new: &Self)
    where
        T: InstanceTypeTag,
    {
        unsafe { LLVMReplaceAllUsesWith(self.as_raw(), new.as_raw()) }
    }

    /// Determine whether the specified value instance is constant.
    pub fn is_constant(&self) -> bool {
        unsafe { LLVMIsConstant(self.as_raw()) != 0 }
    }

    /// Determine whether a value instance is undefined.
    pub fn is_undef(&self) -> bool {
        unsafe { LLVMIsUndef(self.as_raw()) != 0 }
    }

    /// Determine whether a value instance is poisonous.
    pub fn is_poison(&self) -> bool {
        unsafe { LLVMIsPoison(self.as_raw()) != 0 }
    }

    pub fn is_a_metadata_node(&self) -> Option<&Value<metadata>> {
        unsafe { Value::from_ptr(LLVMIsAMDNode(self.as_raw())) }
    }

    pub fn is_a_value_as_metadata(&self) -> Option<&Value<metadata>> {
        unsafe { Value::from_ptr(LLVMIsAValueAsMetadata(self.as_raw())) }
    }

    pub fn is_a_metadata_string(&self) -> Option<&Value<metadata>> {
        unsafe { Value::from_ptr(LLVMIsAMDString(self.as_raw())) }
    }
}

impl<T: TypeTag> Value<T> {
    pub fn is_a_argument(&self) -> Option<&Argument<T>> {
        unsafe { Argument::from_ptr(LLVMIsAArgument(self.as_raw())) }
    }

    pub fn is_a_basic_block(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsABasicBlock(self.as_raw())) }
    }

    pub fn is_a_inline_asm(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAInlineAsm(self.as_raw())) }
    }

    pub fn is_a_user(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAUser(self.as_raw())) }
    }

    pub fn is_a_constant(&self) -> Option<&Constant<T>> {
        unsafe { Constant::from_ptr(LLVMIsAConstant(self.as_raw())) }
    }

    pub fn is_a_block_address(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsABlockAddress(self.as_raw())) }
    }

    pub fn is_a_constant_aggregate_zero(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantAggregateZero(self.as_raw())) }
    }

    pub fn is_a_constant_array(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantArray(self.as_raw())) }
    }

    pub fn is_a_constant_data_sequential(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantDataSequential(self.as_raw())) }
    }

    pub fn is_a_constant_data_array(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantDataArray(self.as_raw())) }
    }

    pub fn is_a_constant_data_vector(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantDataVector(self.as_raw())) }
    }

    pub fn is_a_constant_expr(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantExpr(self.as_raw())) }
    }

    pub fn is_a_constant_fp(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantFP(self.as_raw())) }
    }

    pub fn is_a_constant_int(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantInt(self.as_raw())) }
    }

    pub fn is_a_constant_pointer_null(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantPointerNull(self.as_raw())) }
    }

    pub fn is_a_constant_struct(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantStruct(self.as_raw())) }
    }

    pub fn is_a_constant_token_none(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantTokenNone(self.as_raw())) }
    }

    pub fn is_a_constant_vector(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAConstantVector(self.as_raw())) }
    }

    pub fn is_a_global_value(&self) -> Option<&GlobalValue<any>> {
        unsafe { GlobalValue::from_ptr(LLVMIsAGlobalValue(self.as_raw())) }
    }

    pub fn is_a_global_alias(&self) -> Option<&GlobalAlias<any>> {
        unsafe { GlobalAlias::from_ptr(LLVMIsAGlobalAlias(self.as_raw())) }
    }

    pub fn is_a_global_i_func(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAGlobalIFunc(self.as_raw())) }
    }

    pub fn is_a_global_object(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAGlobalObject(self.as_raw())) }
    }

    pub fn is_a_function(&self) -> Option<&Function<T>>
    where
        T: FunTypeTag,
    {
        unsafe { Function::from_ptr(LLVMIsAFunction(self.as_raw())) }
    }

    pub fn is_a_global_variable(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAGlobalVariable(self.as_raw())) }
    }

    pub fn is_a_undef_value(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAUndefValue(self.as_raw())) }
    }

    pub fn is_a_poison_value(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAPoisonValue(self.as_raw())) }
    }

    pub fn is_a_instruction(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAInstruction(self.as_raw())) }
    }

    pub fn is_a_unary_operator(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAUnaryOperator(self.as_raw())) }
    }

    pub fn is_a_binary_operator(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsABinaryOperator(self.as_raw())) }
    }

    pub fn is_a_call_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACallInst(self.as_raw())) }
    }

    pub fn is_a_intrinsic_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAIntrinsicInst(self.as_raw())) }
    }

    pub fn is_a_dbg_info_intrinsic(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsADbgInfoIntrinsic(self.as_raw())) }
    }

    pub fn is_a_dbg_variable_intrinsic(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsADbgVariableIntrinsic(self.as_raw())) }
    }

    pub fn is_a_dbg_declare_inst(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsADbgDeclareInst(self.as_raw())) }
    }

    pub fn is_a_dbg_label_inst(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsADbgLabelInst(self.as_raw())) }
    }

    pub fn is_a_mem_intrinsic(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAMemIntrinsic(self.as_raw())) }
    }

    pub fn is_a_mem_cpy_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAMemCpyInst(self.as_raw())) }
    }

    pub fn is_a_mem_move_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAMemMoveInst(self.as_raw())) }
    }

    pub fn is_a_mem_set_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAMemSetInst(self.as_raw())) }
    }

    pub fn is_a_cmp_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACmpInst(self.as_raw())) }
    }

    pub fn is_a_f_cmp_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFCmpInst(self.as_raw())) }
    }

    pub fn is_a_i_cmp_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAICmpInst(self.as_raw())) }
    }

    pub fn is_a_extract_element_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAExtractElementInst(self.as_raw())) }
    }

    pub fn is_a_get_element_ptr_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAGetElementPtrInst(self.as_raw())) }
    }

    pub fn is_a_insert_element_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAInsertElementInst(self.as_raw())) }
    }

    pub fn is_a_insert_value_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAInsertValueInst(self.as_raw())) }
    }

    pub fn is_a_landing_pad_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsALandingPadInst(self.as_raw())) }
    }

    pub fn is_a_phi_node(&self) -> Option<&Value<T>> {
        unsafe { Value::from_ptr(LLVMIsAPHINode(self.as_raw())) }
    }

    pub fn is_a_select_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsASelectInst(self.as_raw())) }
    }

    pub fn is_a_shuffle_vector_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAShuffleVectorInst(self.as_raw())) }
    }

    pub fn is_a_store_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAStoreInst(self.as_raw())) }
    }

    pub fn is_a_branch_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsABranchInst(self.as_raw())) }
    }

    pub fn is_a_indirect_br_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAIndirectBrInst(self.as_raw())) }
    }

    pub fn is_a_invoke_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAInvokeInst(self.as_raw())) }
    }

    pub fn is_a_return_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAReturnInst(self.as_raw())) }
    }

    pub fn is_a_switch_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsASwitchInst(self.as_raw())) }
    }

    pub fn is_a_unreachable_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAUnreachableInst(self.as_raw())) }
    }

    pub fn is_a_resume_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAResumeInst(self.as_raw())) }
    }

    pub fn is_a_cleanup_return_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACleanupReturnInst(self.as_raw())) }
    }

    pub fn is_a_catch_return_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACatchReturnInst(self.as_raw())) }
    }

    pub fn is_a_catch_switch_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACatchSwitchInst(self.as_raw())) }
    }

    pub fn is_a_call_br_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACallBrInst(self.as_raw())) }
    }

    pub fn is_a_funclet_pad_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFuncletPadInst(self.as_raw())) }
    }

    pub fn is_a_catch_pad_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACatchPadInst(self.as_raw())) }
    }

    pub fn is_a_cleanup_pad_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACleanupPadInst(self.as_raw())) }
    }

    pub fn is_a_unary_instruction(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAUnaryInstruction(self.as_raw())) }
    }

    pub fn is_a_alloca_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAAllocaInst(self.as_raw())) }
    }

    pub fn is_a_cast_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsACastInst(self.as_raw())) }
    }

    pub fn is_a_addr_space_cast_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAAddrSpaceCastInst(self.as_raw())) }
    }

    pub fn is_a_bit_cast_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsABitCastInst(self.as_raw())) }
    }

    pub fn is_a_fp_ext_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFPExtInst(self.as_raw())) }
    }

    pub fn is_a_fp_to_si_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFPToSIInst(self.as_raw())) }
    }

    pub fn is_a_fp_to_ui_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFPToUIInst(self.as_raw())) }
    }

    pub fn is_a_fp_trunc_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFPTruncInst(self.as_raw())) }
    }

    pub fn is_a_int_to_ptr_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAIntToPtrInst(self.as_raw())) }
    }

    pub fn is_a_ptr_to_int_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAPtrToIntInst(self.as_raw())) }
    }

    pub fn is_a_s_ext_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsASExtInst(self.as_raw())) }
    }

    pub fn is_a_si_to_fp_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsASIToFPInst(self.as_raw())) }
    }

    pub fn is_a_trunc_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsATruncInst(self.as_raw())) }
    }

    pub fn is_a_ui_to_fp_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAUIToFPInst(self.as_raw())) }
    }

    pub fn is_a_z_ext_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAZExtInst(self.as_raw())) }
    }

    pub fn is_a_extract_value_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAExtractValueInst(self.as_raw())) }
    }

    pub fn is_a_load_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsALoadInst(self.as_raw())) }
    }

    pub fn is_a_va_arg_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAVAArgInst(self.as_raw())) }
    }

    pub fn is_a_freeze_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFreezeInst(self.as_raw())) }
    }

    pub fn is_a_atomic_cmp_xchg_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAAtomicCmpXchgInst(self.as_raw())) }
    }

    pub fn is_a_atomic_rmw_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAAtomicRMWInst(self.as_raw())) }
    }

    pub fn is_a_fence_inst(&self) -> Option<&Instruction<T>> {
        unsafe { Instruction::from_ptr(LLVMIsAFenceInst(self.as_raw())) }
    }
}

impl<T: TypeTag> Value<T> {
    pub fn get_num_indices(&self) -> u32 {
        unsafe { LLVMGetNumIndices(self.as_raw()) }
    }

    pub fn get_indices(&self) -> &[u32] {
        unsafe {
            let ptr = LLVMGetIndices(self.as_raw());
            std::slice::from_raw_parts(ptr, self.get_num_indices() as _)
        }
    }
}