@@ -1253,6 +1253,27 @@ public class IRBuilder {
1253
1253
return LLVMSizeOf ( val. asLLVM ( ) )
1254
1254
}
1255
1255
1256
+ /// Builds an expression that returns the difference between two pointer
1257
+ /// values, dividing out the size of the pointed-to objects.
1258
+ ///
1259
+ /// This is intended to implement C-style pointer subtraction. As such, the
1260
+ /// pointers must be appropriately aligned for their element types and
1261
+ /// pointing into the same object.
1262
+ ///
1263
+ /// - parameter lhs: The first pointer (the minuend).
1264
+ /// - parameter rhs: The second pointer (the subtrahend).
1265
+ /// - parameter name: The name for the newly inserted instruction.
1266
+ ///
1267
+ /// - returns: A IRValue representing a 64-bit integer value of the difference
1268
+ /// of the two pointer values modulo the size of the pointed-to objects.
1269
+ public func buildPointerDifference( _ lhs: IRValue , _ rhs: IRValue , name: String = " " ) -> IRValue {
1270
+ precondition (
1271
+ lhs. type is PointerType && rhs. type is PointerType ,
1272
+ " Cannot take pointer diff of \( lhs. type) and \( rhs. type) . "
1273
+ )
1274
+ return LLVMBuildPtrDiff ( llvm, lhs. asLLVM ( ) , rhs. asLLVM ( ) , name)
1275
+ }
1276
+
1256
1277
// MARK: Atomic Instructions
1257
1278
1258
1279
/// Builds a fence instruction that introduces "happens-before" edges between
@@ -1264,6 +1285,7 @@ public class IRBuilder {
1264
1285
/// with other atomics in the same thread. (This is useful for interacting
1265
1286
/// with signal handlers.) Otherwise this fence is atomic with respect to
1266
1287
/// all other code in the system.
1288
+ /// - parameter name: The name for the newly inserted instruction.
1267
1289
///
1268
1290
/// - returns: A value representing `void`.
1269
1291
public func buildFence( ordering: AtomicOrdering , singleThreaded: Bool = false , name: String = " " ) -> IRValue {
0 commit comments