@@ -1090,11 +1090,14 @@ public class IRBuilder {
10901090 ///
10911091 /// - parameter type: The sized type used to determine the amount of stack
10921092 /// memory to allocate.
1093+ /// - parameter alignment: The alignment of the access.
10931094 /// - parameter name: The name for the newly inserted instruction.
10941095 ///
10951096 /// - returns: A value representing `void`.
1096- public func buildAlloca( type: IRType , name: String = " " ) -> IRValue {
1097- return LLVMBuildAlloca ( llvm, type. asLLVM ( ) , name)
1097+ public func buildAlloca( type: IRType , alignment: Int = 0 , name: String = " " ) -> IRValue {
1098+ let allocaInst = LLVMBuildAlloca ( llvm, type. asLLVM ( ) , name) !
1099+ LLVMSetAlignment ( allocaInst, UInt32 ( alignment) )
1100+ return allocaInst
10981101 }
10991102
11001103 /// Builds a store instruction that stores the first value into the location
@@ -1105,13 +1108,15 @@ public class IRBuilder {
11051108 /// - parameter ordering: The ordering effect of the fence for this store,
11061109 /// if any. Defaults to a nonatomic store.
11071110 /// - parameter volatile: Whether this is a store to a volatile memory location.
1111+ /// - parameter alignment: The alignment of the access.
11081112 ///
11091113 /// - returns: A value representing `void`.
11101114 @discardableResult
1111- public func buildStore( _ val: IRValue , to ptr: IRValue , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false ) -> IRValue {
1115+ public func buildStore( _ val: IRValue , to ptr: IRValue , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false , alignment : Int = 0 ) -> IRValue {
11121116 let storeInst = LLVMBuildStore ( llvm, val. asLLVM ( ) , ptr. asLLVM ( ) ) !
11131117 LLVMSetOrdering ( storeInst, ordering. llvm)
11141118 LLVMSetVolatile ( storeInst, volatile. llvm)
1119+ LLVMSetAlignment ( storeInst, UInt32 ( alignment) )
11151120 return storeInst
11161121 }
11171122
@@ -1122,14 +1127,16 @@ public class IRBuilder {
11221127 /// - parameter ordering: The ordering effect of the fence for this load,
11231128 /// if any. Defaults to a nonatomic load.
11241129 /// - parameter volatile: Whether this is a load from a volatile memory location.
1130+ /// - parameter alignment: The alignment of the access.
11251131 /// - parameter name: The name for the newly inserted instruction.
11261132 ///
11271133 /// - returns: A value representing the result of a load from the given
11281134 /// pointer value.
1129- public func buildLoad( _ ptr: IRValue , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false , name: String = " " ) -> IRValue {
1135+ public func buildLoad( _ ptr: IRValue , ordering: AtomicOrdering = . notAtomic, volatile: Bool = false , alignment : Int = 0 , name: String = " " ) -> IRValue {
11301136 let loadInst = LLVMBuildLoad ( llvm, ptr. asLLVM ( ) , name) !
11311137 LLVMSetOrdering ( loadInst, ordering. llvm)
11321138 LLVMSetVolatile ( loadInst, volatile. llvm)
1139+ LLVMSetAlignment ( loadInst, UInt32 ( alignment) )
11331140 return loadInst
11341141 }
11351142
0 commit comments