@@ -1015,6 +1015,44 @@ extension Constant where Repr == Struct {
1015
1015
return LLVMConstExtractValue ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1016
1016
}
1017
1017
}
1018
+
1019
+ /// Build a constant `GEP` (Get Element Pointer) instruction with a resultant
1020
+ /// value that is undefined if the address is outside the actual underlying
1021
+ /// allocated object and not the address one-past-the-end.
1022
+ ///
1023
+ /// The `GEP` instruction is often the source of confusion. LLVM [provides a
1024
+ /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions
1025
+ /// around its semantics and correct usage.
1026
+ ///
1027
+ /// - parameter indices: A list of indices that indicate which of the elements
1028
+ /// of the aggregate object are indexed.
1029
+ ///
1030
+ /// - returns: A value representing the address of a subelement of the given
1031
+ /// aggregate data structure value.
1032
+ public func getElementPointer( indices: [ IRValue ] ) -> IRValue {
1033
+ var indices = indices. map ( { $0. asLLVM ( ) as LLVMValueRef ? } )
1034
+ return indices. withUnsafeMutableBufferPointer { buf in
1035
+ return LLVMConstGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1036
+ }
1037
+ }
1038
+
1039
+ /// Build a GEP (Get Element Pointer) instruction.
1040
+ ///
1041
+ /// The `GEP` instruction is often the source of confusion. LLVM [provides a
1042
+ /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions
1043
+ /// around its semantics and correct usage.
1044
+ ///
1045
+ /// - parameter indices: A list of indices that indicate which of the elements
1046
+ /// of the aggregate object are indexed.
1047
+ ///
1048
+ /// - returns: A value representing the address of a subelement of the given
1049
+ /// aggregate data structure value.
1050
+ public func inBoundsGetElementPointer( indices: [ IRValue ] ) -> IRValue {
1051
+ var indices = indices. map ( { $0. asLLVM ( ) as LLVMValueRef ? } )
1052
+ return indices. withUnsafeMutableBufferPointer { buf in
1053
+ return LLVMConstInBoundsGEP ( asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) )
1054
+ }
1055
+ }
1018
1056
}
1019
1057
1020
1058
// MARK: Vector Operations
0 commit comments