@@ -1090,14 +1090,36 @@ extension IRBuilder {
1090
1090
///
1091
1091
/// - returns: A value representing the result of a load from the given
1092
1092
/// pointer value.
1093
+ @available ( * , deprecated, message: " Use buildLoad(type:ptr:ordering:volatile:alignment:name) instead " )
1093
1094
public func buildLoad( _ ptr: IRValue , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false , alignment: Alignment = . zero, name: String = " " ) -> IRInstruction {
1094
1095
let loadInst = LLVMBuildLoad ( llvm, ptr. asLLVM ( ) , name) !
1095
1096
LLVMSetOrdering ( loadInst, ordering. llvm)
1096
1097
LLVMSetVolatile ( loadInst, volatile. llvm)
1097
1098
LLVMSetAlignment ( loadInst, alignment. rawValue)
1098
1099
return loadInst
1099
1100
}
1100
-
1101
+
1102
+ /// Build a load instruction that loads a value from the location in the
1103
+ /// given value.
1104
+ ///
1105
+ /// - parameter ptr: The pointer value to load from.
1106
+ /// - parameter type: The type of value loaded from the given pointer.
1107
+ /// - parameter ordering: The ordering effect of the fence for this load,
1108
+ /// if any. Defaults to a nonatomic load.
1109
+ /// - parameter volatile: Whether this is a load from a volatile memory location.
1110
+ /// - parameter alignment: The alignment of the access.
1111
+ /// - parameter name: The name for the newly inserted instruction.
1112
+ ///
1113
+ /// - returns: A value representing the result of a load from the given
1114
+ /// pointer value.
1115
+ public func buildLoad( _ ptr: IRValue , type: IRType , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false , alignment: Alignment = . zero, name: String = " " ) -> IRInstruction {
1116
+ let loadInst = LLVMBuildLoad2 ( llvm, type. asLLVM ( ) , ptr. asLLVM ( ) , name) !
1117
+ LLVMSetOrdering ( loadInst, ordering. llvm)
1118
+ LLVMSetVolatile ( loadInst, volatile. llvm)
1119
+ LLVMSetAlignment ( loadInst, alignment. rawValue)
1120
+ return loadInst
1121
+ }
1122
+
1101
1123
/// Build a `GEP` (Get Element Pointer) instruction with a resultant value
1102
1124
/// that is undefined if the address is outside the actual underlying
1103
1125
/// allocated object and not the address one-past-the-end.
@@ -1113,12 +1135,36 @@ extension IRBuilder {
1113
1135
///
1114
1136
/// - returns: A value representing the address of a subelement of the given
1115
1137
/// aggregate data structure value.
1138
+ @available ( * , deprecated, message: " Use buildInBoundsGEP(type:ptr:indices:name) instead " )
1116
1139
public func buildInBoundsGEP( _ ptr: IRValue , indices: [ IRValue ] , name: String = " " ) -> IRValue {
1117
1140
var vals = indices. map { $0. asLLVM ( ) as Optional }
1118
1141
return vals. withUnsafeMutableBufferPointer { buf in
1119
1142
return LLVMBuildInBoundsGEP ( llvm, ptr. asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) , name)
1120
1143
}
1121
1144
}
1145
+
1146
+ /// Build a `GEP` (Get Element Pointer) instruction with a resultant value
1147
+ /// that is undefined if the address is outside the actual underlying
1148
+ /// allocated object and not the address one-past-the-end.
1149
+ ///
1150
+ /// The `GEP` instruction is often the source of confusion. LLVM [provides a
1151
+ /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions
1152
+ /// around its semantics and correct usage.
1153
+ ///
1154
+ /// - parameter ptr: The base address for the index calculation.
1155
+ /// - parameter type: The type used to calculate pointer offsets.
1156
+ /// - parameter indices: A list of indices that indicate which of the elements
1157
+ /// of the aggregate object are indexed.
1158
+ /// - parameter name: The name for the newly inserted instruction.
1159
+ ///
1160
+ /// - returns: A value representing the address of a subelement of the given
1161
+ /// aggregate data structure value.
1162
+ public func buildInBoundsGEP( _ ptr: IRValue , type: IRType , indices: [ IRValue ] , name: String = " " ) -> IRValue {
1163
+ var vals = indices. map { $0. asLLVM ( ) as Optional }
1164
+ return vals. withUnsafeMutableBufferPointer { buf in
1165
+ return LLVMBuildInBoundsGEP2 ( llvm, type. asLLVM ( ) , ptr. asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) , name)
1166
+ }
1167
+ }
1122
1168
1123
1169
/// Build a GEP (Get Element Pointer) instruction.
1124
1170
///
@@ -1133,13 +1179,35 @@ extension IRBuilder {
1133
1179
///
1134
1180
/// - returns: A value representing the address of a subelement of the given
1135
1181
/// aggregate data structure value.
1182
+ @available ( * , deprecated, message: " Use buildGEP(type:ptr:indices:name) instead " )
1136
1183
public func buildGEP( _ ptr: IRValue , indices: [ IRValue ] , name: String = " " ) -> IRValue {
1137
1184
var vals = indices. map { $0. asLLVM ( ) as Optional }
1138
1185
return vals. withUnsafeMutableBufferPointer { buf in
1139
1186
return LLVMBuildGEP ( llvm, ptr. asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) , name)
1140
1187
}
1141
1188
}
1142
1189
1190
+ /// Build a GEP (Get Element Pointer) instruction.
1191
+ ///
1192
+ /// The `GEP` instruction is often the source of confusion. LLVM [provides a
1193
+ /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions
1194
+ /// around its semantics and correct usage.
1195
+ ///
1196
+ /// - parameter ptr: The base address for the index calculation.
1197
+ /// - parameter type: The type used to calculate pointer offsets.
1198
+ /// - parameter indices: A list of indices that indicate which of the elements
1199
+ /// of the aggregate object are indexed.
1200
+ /// - parameter name: The name for the newly inserted instruction.
1201
+ ///
1202
+ /// - returns: A value representing the address of a subelement of the given
1203
+ /// aggregate data structure value.
1204
+ public func buildGEP( _ ptr: IRValue , type: IRType , indices: [ IRValue ] , name: String = " " ) -> IRValue {
1205
+ var vals = indices. map { $0. asLLVM ( ) as Optional }
1206
+ return vals. withUnsafeMutableBufferPointer { buf in
1207
+ return LLVMBuildGEP2 ( llvm, type. asLLVM ( ) , ptr. asLLVM ( ) , buf. baseAddress, UInt32 ( buf. count) , name)
1208
+ }
1209
+ }
1210
+
1143
1211
/// Build a GEP (Get Element Pointer) instruction suitable for indexing into
1144
1212
/// a struct.
1145
1213
///
@@ -1149,10 +1217,25 @@ extension IRBuilder {
1149
1217
///
1150
1218
/// - returns: A value representing the address of a subelement of the given
1151
1219
/// struct value.
1220
+ @available ( * , deprecated, message: " Use buildStructGEP(type:ptr:index:name) instead " )
1152
1221
public func buildStructGEP( _ ptr: IRValue , index: Int , name: String = " " ) -> IRValue {
1153
1222
return LLVMBuildStructGEP ( llvm, ptr. asLLVM ( ) , UInt32 ( index) , name)
1154
1223
}
1155
1224
1225
+ /// Build a GEP (Get Element Pointer) instruction suitable for indexing into
1226
+ /// a struct of a given type.
1227
+ ///
1228
+ /// - parameter ptr: The base address for the index calculation.
1229
+ /// - parameter type: The type of the struct to index into.
1230
+ /// - parameter index: The offset from the base for the index calculation.
1231
+ /// - parameter name: The name for the newly inserted instruction.
1232
+ ///
1233
+ /// - returns: A value representing the address of a subelement of the given
1234
+ /// struct value.
1235
+ public func buildStructGEP( _ ptr: IRValue , type: IRType , index: Int , name: String = " " ) -> IRValue {
1236
+ return LLVMBuildStructGEP2 ( llvm, type. asLLVM ( ) , ptr. asLLVM ( ) , UInt32 ( index) , name)
1237
+ }
1238
+
1156
1239
/// Build an ExtractValue instruction to retrieve an indexed value from a
1157
1240
/// struct or array value.
1158
1241
///
0 commit comments