@@ -942,7 +942,7 @@ public class IRBuilder {
942942 return LLVMSizeOf ( val. asLLVM ( ) )
943943 }
944944
945- // MARK: Vector Instructions
945+ // MARK: Aggregate Instructions
946946
947947 /// Builds an instruction to insert a value into a member field in an
948948 /// aggregate value.
@@ -958,12 +958,31 @@ public class IRBuilder {
958958 return LLVMBuildInsertValue ( llvm, aggregate. asLLVM ( ) , element. asLLVM ( ) , UInt32 ( index) , name)
959959 }
960960
961+ /// Builds an instruction to extract a value from a member field in an
962+ /// aggregate value.
963+ ///
964+ /// An `extract value` instruction differs from a `get element pointer`
965+ /// instruction because the value being indexed is not a pointer and the first
966+ /// index is unnecessary (as it is assumed to be zero).
967+ ///
968+ /// - parameter aggregate: A value of array or structure type.
969+ /// - parameter index: The index at which at which to extract a value.
970+ /// - parameter name: The name for the newly inserted instruction.
971+ ///
972+ /// - returns: A value representing an aggregate that has been updated with
973+ /// the given value at the given index.
974+ func buildExtractValue( aggregate: IRValue , index: Int , name: String = " " ) -> IRValue {
975+ return LLVMBuildExtractValue ( llvm, aggregate. asLLVM ( ) , UInt32 ( index) , name)
976+ }
977+
978+ // MARK: Vector Instructions
979+
961980 /// Builds a vector insert instruction to nondestructively insert the given
962981 /// value into the given vector.
963982 ///
964983 /// - parameter vector: A value of vector type.
965984 /// - parameter element: The value to insert.
966- /// - parameter index: The index at which at which to insert the value.
985+ /// - parameter index: The index at which to insert the value.
967986 /// - parameter name: The name for the newly inserted instruction.
968987 ///
969988 /// - returns: A value representing a vector that has been updated with
@@ -972,6 +991,18 @@ public class IRBuilder {
972991 return LLVMBuildInsertElement ( llvm, vector. asLLVM ( ) , element. asLLVM ( ) , index. asLLVM ( ) , name)
973992 }
974993
994+ /// Builds an instruction to extract a single scalar element from a vector at
995+ /// a specified index.
996+ ///
997+ /// - parameter vector: A value of vector type.
998+ /// - parameter index: The index at which to insert the value.
999+ /// - parameter name: The name for the newly inserted instruction.
1000+ ///
1001+ /// - returns: A value representing a scalar at the given index.
1002+ public func buildExtractElement( vector: IRValue , index: IRValue , name: String = " " ) -> IRValue {
1003+ return LLVMBuildExtractElement ( llvm, vector. asLLVM ( ) , index. asLLVM ( ) , name)
1004+ }
1005+
9751006 // MARK: Global Variable Instructions
9761007
9771008 /// Build a named global of the given type.
0 commit comments