From 73e25a571f12d3deaa6f4493a5b4792a9dae39eb Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 24 Sep 2022 22:38:40 +0000 Subject: deploy: 295081130ca1eed6e67dfc035e2df2c9ed49b174 --- src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html | 87 +++++ src/llvm_kaleidoscope_rs/llvm/builder.rs.html | 430 +++++++++++++++------ src/llvm_kaleidoscope_rs/llvm/lljit.rs.html | 234 +++++------ src/llvm_kaleidoscope_rs/llvm/mod.rs.html | 56 ++- src/llvm_kaleidoscope_rs/llvm/module.rs.html | 276 +++++++------ src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html | 36 +- src/llvm_kaleidoscope_rs/llvm/type_.rs.html | 42 +- src/llvm_kaleidoscope_rs/llvm/value.rs.html | 396 +++++++++++++------ 8 files changed, 1005 insertions(+), 552 deletions(-) create mode 100644 src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html (limited to 'src/llvm_kaleidoscope_rs/llvm') diff --git a/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html b/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html new file mode 100644 index 0000000..581b8e2 --- /dev/null +++ b/src/llvm_kaleidoscope_rs/llvm/basic_block.rs.html @@ -0,0 +1,87 @@ +basic_block.rs - source +
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
+
use llvm_sys::{core::LLVMGetBasicBlockParent, prelude::LLVMBasicBlockRef};
+
+use std::marker::PhantomData;
+
+use super::FnValue;
+
+/// Wrapper for a LLVM Basic Block.
+#[derive(Copy, Clone)]
+pub struct BasicBlock<'llvm>(LLVMBasicBlockRef, PhantomData<&'llvm ()>);
+
+impl<'llvm> BasicBlock<'llvm> {
+    /// Create a new BasicBlock instance.
+    ///
+    /// # Panics
+    ///
+    /// Panics if `bb_ref` is a null pointer.
+    pub(super) fn new(bb_ref: LLVMBasicBlockRef) -> BasicBlock<'llvm> {
+        assert!(!bb_ref.is_null());
+        BasicBlock(bb_ref, PhantomData)
+    }
+
+    /// Get the raw LLVM value reference.
+    #[inline]
+    pub(super) fn bb_ref(&self) -> LLVMBasicBlockRef {
+        self.0
+    }
+
+    /// Get the function to which the basic block belongs.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn get_parent(&self) -> FnValue<'llvm> {
+        let value_ref = unsafe { LLVMGetBasicBlockParent(self.bb_ref()) };
+        assert!(!value_ref.is_null());
+
+        FnValue::new(value_ref)
+    }
+}
+
+
+ \ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/builder.rs.html b/src/llvm_kaleidoscope_rs/llvm/builder.rs.html index 9ac539b..934351a 100644 --- a/src/llvm_kaleidoscope_rs/llvm/builder.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/builder.rs.html @@ -1,102 +1,108 @@ -builder.rs - source
  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
+builder.rs - source
+    
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
@@ -187,11 +193,101 @@
 187
 188
 189
-
-use llvm_sys::{
+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
+
use llvm_sys::{
     core::{
-        LLVMBuildFAdd, LLVMBuildFCmp, LLVMBuildFMul, LLVMBuildFSub, LLVMBuildRet, LLVMBuildUIToFP,
-        LLVMCreateBuilderInContext, LLVMDisposeBuilder, LLVMPositionBuilderAtEnd,
+        LLVMAddIncoming, LLVMBuildBr, LLVMBuildCondBr, LLVMBuildFAdd, LLVMBuildFCmp, LLVMBuildFMul,
+        LLVMBuildFSub, LLVMBuildPhi, LLVMBuildRet, LLVMBuildUIToFP, LLVMCreateBuilderInContext,
+        LLVMDisposeBuilder, LLVMGetInsertBlock, LLVMPositionBuilderAtEnd,
     },
     prelude::{LLVMBuilderRef, LLVMValueRef},
     LLVMRealPredicate,
@@ -199,7 +295,7 @@
 
 use std::marker::PhantomData;
 
-use super::{BasicBlock, FnValue, Module, Type, Value};
+use super::{BasicBlock, FnValue, Module, PhiValue, Type, Value};
 
 // Definition of LLVM C API functions using our `repr(transparent)` types.
 extern "C" {
@@ -207,10 +303,10 @@
         arg1: LLVMBuilderRef,
         arg2: Type<'_>,
         Fn: FnValue<'_>,
-        Args: *mut Value<'_>,
+        Args: *mut Value<'_>,
         NumArgs: ::libc::c_uint,
-        Name: *const ::libc::c_char,
-    ) -> LLVMValueRef;
+        Name: *const ::libc::c_char,
+    ) -> LLVMValueRef;
 }
 
 /// Wrapper for a LLVM IR Builder.
@@ -225,7 +321,7 @@
     /// # Panics
     ///
     /// Panics if creating the IR Builder fails.
-    pub fn with_ctx(module: &'llvm Module) -> IRBuilder<'llvm> {
+    pub fn with_ctx(module: &'llvm Module) -> IRBuilder<'llvm> {
         let builder = unsafe { LLVMCreateBuilderInContext(module.ctx()) };
         assert!(!builder.is_null());
 
@@ -238,16 +334,28 @@
     /// Position the IR Builder at the end of the given Basic Block.
     pub fn pos_at_end(&self, bb: BasicBlock<'llvm>) {
         unsafe {
-            LLVMPositionBuilderAtEnd(self.builder, bb.0);
+            LLVMPositionBuilderAtEnd(self.builder, bb.bb_ref());
         }
     }
 
+    /// Get the BasicBlock the IRBuilder currently inputs into.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn get_insert_block(&self) -> BasicBlock<'llvm> {
+        let bb_ref = unsafe { LLVMGetInsertBlock(self.builder) };
+        assert!(!bb_ref.is_null());
+
+        BasicBlock::new(bb_ref)
+    }
+
     /// Emit a [fadd](https://llvm.org/docs/LangRef.html#fadd-instruction) instruction.
     ///
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn fadd(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
+    pub fn fadd(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
         debug_assert!(lhs.is_f64(), "fadd: Expected f64 as lhs operand!");
         debug_assert!(rhs.is_f64(), "fadd: Expected f64 as rhs operand!");
 
@@ -267,7 +375,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn fsub(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
+    pub fn fsub(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
         debug_assert!(lhs.is_f64(), "fsub: Expected f64 as lhs operand!");
         debug_assert!(rhs.is_f64(), "fsub: Expected f64 as rhs operand!");
 
@@ -287,7 +395,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn fmul(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
+    pub fn fmul(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
         debug_assert!(lhs.is_f64(), "fmul: Expected f64 as lhs operand!");
         debug_assert!(rhs.is_f64(), "fmul: Expected f64 as rhs operand!");
 
@@ -302,14 +410,14 @@
         Value::new(value_ref)
     }
 
-    /// Emit a [fcmult](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction.
+    /// Emit a [fcmpult](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction.
     ///
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn fcmpult(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
-        debug_assert!(lhs.is_f64(), "fcmplt: Expected f64 as lhs operand!");
-        debug_assert!(rhs.is_f64(), "fcmplt: Expected f64 as rhs operand!");
+    pub fn fcmpult(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
+        debug_assert!(lhs.is_f64(), "fcmpult: Expected f64 as lhs operand!");
+        debug_assert!(rhs.is_f64(), "fcmpult: Expected f64 as rhs operand!");
 
         let value_ref = unsafe {
             LLVMBuildFCmp(
@@ -317,7 +425,28 @@
                 LLVMRealPredicate::LLVMRealULT,
                 lhs.value_ref(),
                 rhs.value_ref(),
-                b"fcmplt\0".as_ptr().cast(),
+                b"fcmpult\0".as_ptr().cast(),
+            )
+        };
+        Value::new(value_ref)
+    }
+
+    /// Emit a [fcmpone](https://llvm.org/docs/LangRef.html#fcmp-instruction) instruction.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn fcmpone(&self, lhs: Value<'llvm>, rhs: Value<'llvm>) -> Value<'llvm> {
+        debug_assert!(lhs.is_f64(), "fcmone: Expected f64 as lhs operand!");
+        debug_assert!(rhs.is_f64(), "fcmone: Expected f64 as rhs operand!");
+
+        let value_ref = unsafe {
+            LLVMBuildFCmp(
+                self.builder,
+                LLVMRealPredicate::LLVMRealONE,
+                lhs.value_ref(),
+                rhs.value_ref(),
+                b"fcmpone\0".as_ptr().cast(),
             )
         };
         Value::new(value_ref)
@@ -328,7 +457,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn uitofp(&self, val: Value<'llvm>, dest_type: Type<'llvm>) -> Value<'llvm> {
+    pub fn uitofp(&self, val: Value<'llvm>, dest_type: Type<'llvm>) -> Value<'llvm> {
         debug_assert!(val.is_int(), "uitofp: Expected integer operand!");
 
         let value_ref = unsafe {
@@ -347,7 +476,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn call(&self, fn_value: FnValue<'llvm>, args: &mut [Value<'llvm>]) -> Value<'llvm> {
+    pub fn call(&self, fn_value: FnValue<'llvm>, args: &mut [Value<'llvm>]) -> Value<'llvm> {
         let value_ref = unsafe {
             LLVMBuildCall2(
                 self.builder,
@@ -370,14 +499,69 @@
         let ret = unsafe { LLVMBuildRet(self.builder, ret.value_ref()) };
         assert!(!ret.is_null());
     }
+
+    /// Emit an unconditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn br(&self, dest: BasicBlock<'llvm>) {
+        let br_ref = unsafe { LLVMBuildBr(self.builder, dest.bb_ref()) };
+        assert!(!br_ref.is_null());
+    }
+
+    /// Emit a conditional [br](https://llvm.org/docs/LangRef.html#br-instruction) instruction.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn cond_br(&self, cond: Value<'llvm>, then: BasicBlock<'llvm>, else_: BasicBlock<'llvm>) {
+        let br_ref = unsafe {
+            LLVMBuildCondBr(
+                self.builder,
+                cond.value_ref(),
+                then.bb_ref(),
+                else_.bb_ref(),
+            )
+        };
+        assert!(!br_ref.is_null());
+    }
+
+    /// Emit a [phi](https://llvm.org/docs/LangRef.html#phi-instruction) instruction.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn phi(
+        &self,
+        phi_type: Type<'llvm>,
+        incoming: &[(Value<'llvm>, BasicBlock<'llvm>)],
+    ) -> PhiValue<'llvm> {
+        let phi_ref =
+            unsafe { LLVMBuildPhi(self.builder, phi_type.type_ref(), b"phi\0".as_ptr().cast()) };
+        assert!(!phi_ref.is_null());
+
+        for (val, bb) in incoming {
+            debug_assert_eq!(
+                val.type_of().kind(),
+                phi_type.kind(),
+                "Type of incoming phi value must be the same as the type used to build the phi node."
+            );
+
+            unsafe {
+                LLVMAddIncoming(phi_ref, &mut val.value_ref() as _, &mut bb.bb_ref() as _, 1);
+            }
+        }
+
+        PhiValue::new(phi_ref)
+    }
 }
 
 impl Drop for IRBuilder<'_> {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe { LLVMDisposeBuilder(self.builder) }
     }
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html index 8abbc19..5a5a376 100644 --- a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html @@ -1,102 +1,108 @@ -lljit.rs - source
  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
+lljit.rs - source
+    
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
@@ -152,8 +158,7 @@
 152
 153
 154
-
-use llvm_sys::orc2::{
+
use llvm_sys::orc2::{
     lljit::{
         LLVMOrcCreateLLJIT, LLVMOrcLLJITAddLLVMIRModuleWithRT, LLVMOrcLLJITGetGlobalPrefix,
         LLVMOrcLLJITGetMainJITDylib, LLVMOrcLLJITLookup, LLVMOrcLLJITRef,
@@ -167,12 +172,12 @@
 use std::marker::PhantomData;
 
 use super::{Error, Module};
-use crate::SmallCStr;
+use crate::SmallCStr;
 
 /// Marker trait to constrain function signatures that can be looked up in the JIT.
 pub trait JitFn {}
 
-impl JitFn for unsafe extern "C" fn() -> f64 {}
+impl JitFn for unsafe extern "C" fn() -> f64 {}
 
 /// Wrapper for a LLVM [LLJIT](https://www.llvm.org/docs/ORCv2.html#lljit-and-lllazyjit).
 pub struct LLJit {
@@ -186,11 +191,11 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer or an error.
-    pub fn new() -> LLJit {
+    pub fn new() -> LLJit {
         let (jit, dylib) = unsafe {
             let mut jit = std::ptr::null_mut();
             let err = LLVMOrcCreateLLJIT(
-                &mut jit as _,
+                &mut jit as _,
                 std::ptr::null_mut(), /* builder: nullptr -> default */
             );
 
@@ -213,7 +218,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer or an error.
-    pub fn add_module(&self, module: Module) -> ResourceTracker<'_> {
+    pub fn add_module(&self, module: Module) -> ResourceTracker<'_> {
         let tsmod = module.into_raw_thread_safe_module();
 
         let rt = unsafe {
@@ -235,13 +240,13 @@
     /// # Panics
     ///
     /// Panics if the symbol is not found in the JIT.
-    pub fn find_symbol<F: JitFn>(&self, sym: &str) -> F {
+    pub fn find_symbol<F: JitFn>(&self, sym: &str) -> F {
         let sym =
             SmallCStr::try_from(sym).expect("Failed to convert 'sym' argument to small C string!");
 
         unsafe {
             let mut addr = 0u64;
-            let err = LLVMOrcLLJITLookup(self.jit, &mut addr as _, sym.as_ptr());
+            let err = LLVMOrcLLJITLookup(self.jit, &mut addr as _, sym.as_ptr());
 
             if let Some(err) = Error::from(err) {
                 panic!("Error: {}", err.as_str());
@@ -261,7 +266,7 @@
         unsafe {
             let mut proc_syms_gen: LLVMOrcDefinitionGeneratorRef = std::ptr::null_mut();
             let err = LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
-                &mut proc_syms_gen as _,
+                &mut proc_syms_gen as _,
                 self.global_prefix(),
                 None,                 /* filter */
                 std::ptr::null_mut(), /* filter ctx */
@@ -276,7 +281,7 @@
     }
 
     /// Return the global prefix character according to the LLJITs data layout.
-    fn global_prefix(&self) -> libc::c_char {
+    fn global_prefix(&self) -> libc::c_char {
         unsafe { LLVMOrcLLJITGetGlobalPrefix(self.jit) }
     }
 }
@@ -288,14 +293,14 @@
 pub struct ResourceTracker<'jit>(LLVMOrcResourceTrackerRef, PhantomData<&'jit ()>);
 
 impl<'jit> ResourceTracker<'jit> {
-    fn new(rt: LLVMOrcResourceTrackerRef) -> ResourceTracker<'jit> {
+    fn new(rt: LLVMOrcResourceTrackerRef) -> ResourceTracker<'jit> {
         assert!(!rt.is_null());
         ResourceTracker(rt, PhantomData)
     }
 }
 
 impl Drop for ResourceTracker<'_> {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe {
             let err = LLVMOrcResourceTrackerRemove(self.0);
 
@@ -307,7 +312,6 @@
         };
     }
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/mod.rs.html b/src/llvm_kaleidoscope_rs/llvm/mod.rs.html index d6eb8b2..3dca9c7 100644 --- a/src/llvm_kaleidoscope_rs/llvm/mod.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/mod.rs.html @@ -1,12 +1,18 @@ -mod.rs - source
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
+mod.rs - source
+    
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -72,12 +78,7 @@
 72
 73
 74
-75
-76
-77
-78
-
-//! Safe wrapper around the LLVM C API.
+
//! Safe wrapper around the LLVM C API.
 //!
 //! References returned from the LLVM API are tied to the `'llvm` lifetime which is bound to the
 //! context where the objects are created in.
@@ -90,7 +91,6 @@
 use llvm_sys::{
     core::LLVMShutdown,
     error::{LLVMDisposeErrorMessage, LLVMErrorRef, LLVMGetErrorMessage},
-    prelude::LLVMBasicBlockRef,
     target::{
         LLVM_InitializeNativeAsmParser, LLVM_InitializeNativeAsmPrinter,
         LLVM_InitializeNativeTarget,
@@ -98,8 +98,8 @@
 };
 
 use std::ffi::CStr;
-use std::marker::PhantomData;
 
+mod basic_block;
 mod builder;
 mod lljit;
 mod module;
@@ -107,25 +107,22 @@
 mod type_;
 mod value;
 
+pub use basic_block::BasicBlock;
 pub use builder::IRBuilder;
 pub use lljit::{LLJit, ResourceTracker};
 pub use module::Module;
 pub use pass_manager::FunctionPassManager;
 pub use type_::Type;
-pub use value::{FnValue, Value};
-
-/// Wrapper for a LLVM Basic Block.
-#[derive(Copy, Clone)]
-pub struct BasicBlock<'llvm>(LLVMBasicBlockRef, PhantomData<&'llvm ()>);
+pub use value::{FnValue, PhiValue, Value};
 
 struct Error<'llvm>(&'llvm mut libc::c_char);
 
 impl<'llvm> Error<'llvm> {
-    fn from(err: LLVMErrorRef) -> Option<Error<'llvm>> {
-        (!err.is_null()).then(|| Error(unsafe { &mut *LLVMGetErrorMessage(err) }))
+    fn from(err: LLVMErrorRef) -> Option<Error<'llvm>> {
+        (!err.is_null()).then(|| Error(unsafe { &mut *LLVMGetErrorMessage(err) }))
     }
 
-    fn as_str(&self) -> &str {
+    fn as_str(&self) -> &str {
         unsafe { CStr::from_ptr(self.0) }
             .to_str()
             .expect("Expected valid UTF8 string from LLVM API")
@@ -133,9 +130,9 @@
 }
 
 impl Drop for Error<'_> {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe {
-            LLVMDisposeErrorMessage(self.0 as *mut libc::c_char);
+            LLVMDisposeErrorMessage(self.0 as *mut libc::c_char);
         }
     }
 }
@@ -155,7 +152,6 @@
         LLVMShutdown();
     };
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/module.rs.html b/src/llvm_kaleidoscope_rs/llvm/module.rs.html index be37a0b..99846f4 100644 --- a/src/llvm_kaleidoscope_rs/llvm/module.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/module.rs.html @@ -1,102 +1,108 @@ -module.rs - source
  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
+module.rs - source
+    
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
@@ -194,11 +200,25 @@
 194
 195
 196
-
-use llvm_sys::{
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+
use llvm_sys::{
     core::{
-        LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMDisposeModule, LLVMDoubleTypeInContext,
-        LLVMDumpModule, LLVMGetNamedFunction, LLVMModuleCreateWithNameInContext,
+        LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMCreateBasicBlockInContext,
+        LLVMDisposeModule, LLVMDoubleTypeInContext, LLVMDumpModule, LLVMGetNamedFunction,
+        LLVMModuleCreateWithNameInContext,
     },
     orc2::{
         LLVMOrcCreateNewThreadSafeContext, LLVMOrcCreateNewThreadSafeModule,
@@ -210,19 +230,18 @@
 };
 
 use std::convert::TryFrom;
-use std::marker::PhantomData;
 
 use super::{BasicBlock, FnValue, Type};
-use crate::SmallCStr;
+use crate::SmallCStr;
 
 // Definition of LLVM C API functions using our `repr(transparent)` types.
 extern "C" {
     fn LLVMFunctionType(
         ReturnType: Type<'_>,
-        ParamTypes: *mut Type<'_>,
+        ParamTypes: *mut Type<'_>,
         ParamCount: ::libc::c_uint,
         IsVarArg: LLVMBool,
-    ) -> LLVMTypeRef;
+    ) -> LLVMTypeRef;
 }
 
 /// Wrapper for a LLVM Module with its own LLVM Context.
@@ -238,7 +257,7 @@
     /// # Panics
     ///
     /// Panics if creating the context or the module fails.
-    pub fn new() -> Self {
+    pub fn new() -> Self {
         let (tsctx, ctx, module) = unsafe {
             // We generate a thread safe context because we are going to jit this IR module and
             // there is no method to create a thread safe context wrapper from an existing context
@@ -260,13 +279,13 @@
 
     /// Get the raw LLVM context reference.
     #[inline]
-    pub(super) fn ctx(&self) -> LLVMContextRef {
+    pub(super) fn ctx(&self) -> LLVMContextRef {
         self.ctx
     }
 
     /// Get the raw LLVM module reference.
     #[inline]
-    pub(super) fn module(&self) -> LLVMModuleRef {
+    pub(super) fn module(&self) -> LLVMModuleRef {
         self.module
     }
 
@@ -275,8 +294,8 @@
     /// If ownership of the raw reference is not transferred (eg to the JIT), memory will be leaked
     /// in case the reference is disposed explicitly with LLVMOrcDisposeThreadSafeModule.
     #[inline]
-    pub(super) fn into_raw_thread_safe_module(mut self) -> LLVMOrcThreadSafeModuleRef {
-        let m = std::mem::replace(&mut self.module, std::ptr::null_mut());
+    pub(super) fn into_raw_thread_safe_module(mut self) -> LLVMOrcThreadSafeModuleRef {
+        let m = std::mem::replace(&mut self.module, std::ptr::null_mut());
 
         // ThreadSafeModule has unique ownership.
         // Takes ownership of module and increments ThreadSafeContext ref count.
@@ -299,7 +318,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn type_f64(&self) -> Type<'llvm> {
+    pub fn type_f64(&self) -> Type<'llvm> {
         let type_ref = unsafe { LLVMDoubleTypeInContext(self.ctx) };
         Type::new(type_ref)
     }
@@ -309,7 +328,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn type_fn(&'llvm self, args: &mut [Type<'llvm>], ret: Type<'llvm>) -> Type<'llvm> {
+    pub fn type_fn(&'llvm self, args: &mut [Type<'llvm>], ret: Type<'llvm>) -> Type<'llvm> {
         let type_ref = unsafe {
             LLVMFunctionType(
                 ret,
@@ -328,7 +347,7 @@
     ///
     /// Panics if LLVM API returns a `null` pointer or `name` could not be converted to a
     /// [`SmallCStr`].
-    pub fn add_fn(&'llvm self, name: &str, fn_type: Type<'llvm>) -> FnValue<'llvm> {
+    pub fn add_fn(&'llvm self, name: &str, fn_type: Type<'llvm>) -> FnValue<'llvm> {
         debug_assert_eq!(
             fn_type.kind(),
             LLVMTypeKind::LLVMFunctionTypeKind,
@@ -348,7 +367,7 @@
     /// # Panics
     ///
     /// Panics if `name` could not be converted to a [`SmallCStr`].
-    pub fn get_fn(&'llvm self, name: &str) -> Option<FnValue<'llvm>> {
+    pub fn get_fn(&'llvm self, name: &str) -> Option<FnValue<'llvm>> {
         let name = SmallCStr::try_from(name)
             .expect("Failed to convert 'name' argument to small C string!");
 
@@ -363,7 +382,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn append_basic_block(&'llvm self, fn_value: FnValue<'llvm>) -> BasicBlock<'llvm> {
+    pub fn append_basic_block(&'llvm self, fn_value: FnValue<'llvm>) -> BasicBlock<'llvm> {
         let block = unsafe {
             LLVMAppendBasicBlockInContext(
                 self.ctx,
@@ -373,12 +392,26 @@
         };
         assert!(!block.is_null());
 
-        BasicBlock(block, PhantomData)
+        BasicBlock::new(block)
+    }
+
+    /// Create a free-standing Basic Block without adding it to a function.
+    /// This can be added to a function at a later point in time with
+    /// [`FnValue::append_basic_block`].
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer.
+    pub fn create_basic_block(&self) -> BasicBlock<'llvm> {
+        let block = unsafe { LLVMCreateBasicBlockInContext(self.ctx, b"block\0".as_ptr().cast()) };
+        assert!(!block.is_null());
+
+        BasicBlock::new(block)
     }
 }
 
 impl Drop for Module {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe {
             // In case we turned the module into a ThreadSafeModule, we must not dispose the module
             // reference because ThreadSafeModule took ownership!
@@ -391,7 +424,6 @@
         }
     }
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html b/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html index ab73029..ebf9b28 100644 --- a/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/pass_manager.rs.html @@ -1,12 +1,18 @@ -pass_manager.rs - source
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
+pass_manager.rs - source
+    
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -73,8 +79,7 @@
 73
 74
 75
-
-use llvm_sys::{
+
use llvm_sys::{
     core::{
         LLVMCreateFunctionPassManagerForModule, LLVMDisposePassManager,
         LLVMInitializeFunctionPassManager, LLVMRunFunctionPassManager,
@@ -105,7 +110,7 @@
     ///
     /// The list of selected optimization passes is taken from the tutorial chapter [LLVM
     /// Optimization Passes](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.html#id3).
-    pub fn with_ctx(module: &'llvm Module) -> FunctionPassManager<'llvm> {
+    pub fn with_ctx(module: &'llvm Module) -> FunctionPassManager<'llvm> {
         let fpm = unsafe {
             // Borrows module reference.
             LLVMCreateFunctionPassManagerForModule(module.module())
@@ -143,13 +148,12 @@
 }
 
 impl Drop for FunctionPassManager<'_> {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe {
             LLVMDisposePassManager(self.fpm);
         }
     }
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/type_.rs.html b/src/llvm_kaleidoscope_rs/llvm/type_.rs.html index 89e332a..98daee4 100644 --- a/src/llvm_kaleidoscope_rs/llvm/type_.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/type_.rs.html @@ -1,12 +1,18 @@ -type_.rs - source
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
+type_.rs - source
+    
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -56,8 +62,7 @@
 56
 57
 58
-
-use llvm_sys::{
+
use llvm_sys::{
     core::{LLVMConstReal, LLVMDumpType, LLVMGetTypeKind},
     prelude::LLVMTypeRef,
     LLVMTypeKind,
@@ -65,7 +70,7 @@
 
 use std::marker::PhantomData;
 
-use super::Value;
+use super::Value;
 
 /// Wrapper for a LLVM Type Reference.
 #[derive(Copy, Clone)]
@@ -78,19 +83,19 @@
     /// # Panics
     ///
     /// Panics if `type_ref` is a null pointer.
-    pub(super) fn new(type_ref: LLVMTypeRef) -> Self {
+    pub(super) fn new(type_ref: LLVMTypeRef) -> Self {
         assert!(!type_ref.is_null());
         Type(type_ref, PhantomData)
     }
 
     /// Get the raw LLVM type reference.
     #[inline]
-    pub(super) fn type_ref(&self) -> LLVMTypeRef {
+    pub(super) fn type_ref(&self) -> LLVMTypeRef {
         self.0
     }
 
     /// Get the LLVM type kind for the given type reference.
-    pub(super) fn kind(&self) -> LLVMTypeKind {
+    pub(super) fn kind(&self) -> LLVMTypeKind {
         unsafe { LLVMGetTypeKind(self.type_ref()) }
     }
 
@@ -104,7 +109,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn const_f64(self, n: f64) -> Value<'llvm> {
+    pub fn const_f64(self, n: f64) -> Value<'llvm> {
         debug_assert_eq!(
             self.kind(),
             LLVMTypeKind::LLVMDoubleTypeKind,
@@ -115,7 +120,6 @@
         Value::new(value_ref)
     }
 }
-
-
- +
+
\ No newline at end of file diff --git a/src/llvm_kaleidoscope_rs/llvm/value.rs.html b/src/llvm_kaleidoscope_rs/llvm/value.rs.html index 950eae0..eaea9c3 100644 --- a/src/llvm_kaleidoscope_rs/llvm/value.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/value.rs.html @@ -1,102 +1,108 @@ -value.rs - source
  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
+value.rs - source
+    
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
@@ -166,12 +172,83 @@
 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
+
#![allow(unused)]
+
 use llvm_sys::{
     analysis::{LLVMVerifierFailureAction, LLVMVerifyFunction},
     core::{
-        LLVMCountBasicBlocks, LLVMCountParams, LLVMDumpValue, LLVMGetParam, LLVMGetReturnType,
-        LLVMGetValueKind, LLVMGetValueName2, LLVMSetValueName2, LLVMTypeOf,
+        LLVMAddIncoming, LLVMAppendExistingBasicBlock, LLVMCountBasicBlocks, LLVMCountParams,
+        LLVMDumpValue, LLVMGetParam, LLVMGetReturnType, LLVMGetValueKind, LLVMGetValueName2,
+        LLVMIsAFunction, LLVMIsAPHINode, LLVMSetValueName2, LLVMTypeOf,
     },
     prelude::LLVMValueRef,
     LLVMTypeKind, LLVMValueKind,
@@ -181,7 +258,8 @@
 use std::marker::PhantomData;
 use std::ops::Deref;
 
-use super::Type;
+use super::BasicBlock;
+use super::Type;
 
 /// Wrapper for a LLVM Value Reference.
 #[derive(Copy, Clone)]
@@ -194,22 +272,34 @@
     /// # Panics
     ///
     /// Panics if `value_ref` is a null pointer.
-    pub(super) fn new(value_ref: LLVMValueRef) -> Self {
+    pub(super) fn new(value_ref: LLVMValueRef) -> Self {
         assert!(!value_ref.is_null());
         Value(value_ref, PhantomData)
     }
 
     /// Get the raw LLVM value reference.
     #[inline]
-    pub(super) fn value_ref(&self) -> LLVMValueRef {
+    pub(super) fn value_ref(&self) -> LLVMValueRef {
         self.0
     }
 
     /// Get the LLVM value kind for the given value reference.
-    pub(super) fn kind(&self) -> LLVMValueKind {
+    pub(super) fn kind(&self) -> LLVMValueKind {
         unsafe { LLVMGetValueKind(self.value_ref()) }
     }
 
+    /// Check if value is `function` type.
+    pub(super) fn is_function(&self) -> bool {
+        let cast = unsafe { LLVMIsAFunction(self.value_ref()) };
+        !cast.is_null()
+    }
+
+    /// Check if value is `phinode` type.
+    pub(super) fn is_phinode(&self) -> bool {
+        let cast = unsafe { LLVMIsAPHINode(self.value_ref()) };
+        !cast.is_null()
+    }
+
     /// Dump the LLVM Value to stdout.
     pub fn dump(&self) {
         unsafe { LLVMDumpValue(self.value_ref()) };
@@ -220,7 +310,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn type_of(&self) -> Type<'llvm> {
+    pub fn type_of(&self) -> Type<'llvm> {
         let type_ref = unsafe { LLVMTypeOf(self.value_ref()) };
         Type::new(type_ref)
     }
@@ -239,10 +329,10 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn get_name(&self) -> &'llvm str {
+    pub fn get_name(&self) -> &'llvm str {
         let name = unsafe {
             let mut len: libc::size_t = 0;
-            let name = LLVMGetValueName2(self.0, &mut len as _);
+            let name = LLVMGetValueName2(self.0, &mut len as _);
             assert!(!name.is_null());
 
             CStr::from_ptr(name)
@@ -254,13 +344,13 @@
     }
 
     /// Check if value is of `f64` type.
-    pub fn is_f64(&self) -> bool {
-        self.type_of().kind() == LLVMTypeKind::LLVMDoubleTypeKind
+    pub fn is_f64(&self) -> bool {
+        self.type_of().kind() == LLVMTypeKind::LLVMDoubleTypeKind
     }
 
     /// Check if value is of integer type.
-    pub fn is_int(&self) -> bool {
-        self.type_of().kind() == LLVMTypeKind::LLVMIntegerTypeKind
+    pub fn is_int(&self) -> bool {
+        self.type_of().kind() == LLVMTypeKind::LLVMIntegerTypeKind
     }
 }
 
@@ -271,7 +361,7 @@
 
 impl<'llvm> Deref for FnValue<'llvm> {
     type Target = Value<'llvm>;
-    fn deref(&self) -> &Self::Target {
+    fn deref(&self) -> &Self::Target {
         &self.0
     }
 }
@@ -282,11 +372,10 @@
     /// # Panics
     ///
     /// Panics if `value_ref` is a null pointer.
-    pub(super) fn new(value_ref: LLVMValueRef) -> Self {
+    pub(super) fn new(value_ref: LLVMValueRef) -> Self {
         let value = Value::new(value_ref);
-        debug_assert_eq!(
-            value.kind(),
-            LLVMValueKind::LLVMFunctionValueKind,
+        debug_assert!(
+            value.is_function(),
             "Expected a fn value when constructing FnValue!"
         );
 
@@ -298,13 +387,13 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn ret_type(&self) -> Type<'llvm> {
+    pub fn ret_type(&self) -> Type<'llvm> {
         let type_ref = unsafe { LLVMGetReturnType(LLVMTypeOf(self.value_ref())) };
         Type::new(type_ref)
     }
 
     /// Get the number of function arguments for the given function value.
-    pub fn args(&self) -> usize {
+    pub fn args(&self) -> usize {
         unsafe { LLVMCountParams(self.value_ref()) as usize }
     }
 
@@ -313,7 +402,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer or indexed out of bounds.
-    pub fn arg(&self, idx: usize) -> Value<'llvm> {
+    pub fn arg(&self, idx: usize) -> Value<'llvm> {
         assert!(idx < self.args());
 
         let value_ref = unsafe { LLVMGetParam(self.value_ref(), idx as libc::c_uint) };
@@ -321,21 +410,74 @@
     }
 
     /// Get the number of Basic Blocks for the given function value.
-    pub fn basic_blocks(&self) -> usize {
+    pub fn basic_blocks(&self) -> usize {
         unsafe { LLVMCountBasicBlocks(self.value_ref()) as usize }
     }
 
+    /// Append a Basic Block to the end of the function value.
+    pub fn append_basic_block(&self, bb: BasicBlock<'llvm>) {
+        unsafe {
+            LLVMAppendExistingBasicBlock(self.value_ref(), bb.bb_ref());
+        }
+    }
+
     /// Verify that the given function is valid.
-    pub fn verify(&self) -> bool {
+    pub fn verify(&self) -> bool {
         unsafe {
             LLVMVerifyFunction(
                 self.value_ref(),
                 LLVMVerifierFailureAction::LLVMPrintMessageAction,
-            ) == 0
+            ) == 0
+        }
+    }
+}
+
+/// Wrapper for a LLVM Value Reference specialized for contexts where phi values are needed.
+#[derive(Copy, Clone)]
+#[repr(transparent)]
+pub struct PhiValue<'llvm>(Value<'llvm>);
+
+impl<'llvm> Deref for PhiValue<'llvm> {
+    type Target = Value<'llvm>;
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+
+impl<'llvm> PhiValue<'llvm> {
+    /// Create a new PhiValue instance.
+    ///
+    /// # Panics
+    ///
+    /// Panics if `value_ref` is a null pointer.
+    pub(super) fn new(value_ref: LLVMValueRef) -> Self {
+        let value = Value::new(value_ref);
+        debug_assert!(
+            value.is_phinode(),
+            "Expected a phinode value when constructing PhiValue!"
+        );
+
+        PhiValue(value)
+    }
+
+    /// Add an incoming value to the end of a PHI list.
+    pub fn add_incoming(&self, ival: Value<'llvm>, ibb: BasicBlock<'llvm>) {
+        debug_assert_eq!(
+            ival.type_of().kind(),
+            self.type_of().kind(),
+            "Type of incoming phi value must be the same as the type used to build the phi node."
+        );
+
+        unsafe {
+            LLVMAddIncoming(
+                self.value_ref(),
+                &mut ival.value_ref() as _,
+                &mut ibb.bb_ref() as _,
+                1,
+            );
         }
     }
 }
-
-
- +
+
\ No newline at end of file -- cgit v1.2.3