@@ -942,7 +942,7 @@ public class IRBuilder {
942
942
return LLVMSizeOf ( val. asLLVM ( ) )
943
943
}
944
944
945
- // MARK: Vector Instructions
945
+ // MARK: Aggregate Instructions
946
946
947
947
/// Builds an instruction to insert a value into a member field in an
948
948
/// aggregate value.
@@ -958,12 +958,31 @@ public class IRBuilder {
958
958
return LLVMBuildInsertValue ( llvm, aggregate. asLLVM ( ) , element. asLLVM ( ) , UInt32 ( index) , name)
959
959
}
960
960
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
+
961
980
/// Builds a vector insert instruction to nondestructively insert the given
962
981
/// value into the given vector.
963
982
///
964
983
/// - parameter vector: A value of vector type.
965
984
/// - 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.
967
986
/// - parameter name: The name for the newly inserted instruction.
968
987
///
969
988
/// - returns: A value representing a vector that has been updated with
@@ -972,6 +991,18 @@ public class IRBuilder {
972
991
return LLVMBuildInsertElement ( llvm, vector. asLLVM ( ) , element. asLLVM ( ) , index. asLLVM ( ) , name)
973
992
}
974
993
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
+
975
1006
// MARK: Global Variable Instructions
976
1007
977
1008
/// Build a named global of the given type.
0 commit comments