Skip to content

Commit cd0e4a9

Browse files
committed
Add ordering and volatility to memory access insts
1 parent b19eae9 commit cd0e4a9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Sources/LLVM/IRBuilder.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,25 +1094,40 @@ public class IRBuilder {
10941094
return LLVMBuildAlloca(llvm, type.asLLVM(), name)
10951095
}
10961096

1097-
/// Build a store instruction that stores the first value into the location
1097+
/// Builds a store instruction that stores the first value into the location
10981098
/// given in the second value.
10991099
///
1100+
/// - parameter val: The source value.
1101+
/// - parameter ptr: The destination pointer to store into.
1102+
/// - parameter ordering: The ordering effect of the fence for this store,
1103+
/// if any. Defaults to a nonatomic store.
1104+
/// - parameter volatile: Whether this is a store to a volatile memory location.
1105+
///
11001106
/// - returns: A value representing `void`.
11011107
@discardableResult
1102-
public func buildStore(_ val: IRValue, to ptr: IRValue) -> IRValue {
1103-
return LLVMBuildStore(llvm, val.asLLVM(), ptr.asLLVM())
1108+
public func buildStore(_ val: IRValue, to ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false) -> IRValue {
1109+
let storeInst = LLVMBuildStore(llvm, val.asLLVM(), ptr.asLLVM())!
1110+
LLVMSetOrdering(storeInst, ordering.llvm)
1111+
LLVMSetVolatile(storeInst, volatile.llvm)
1112+
return storeInst
11041113
}
11051114

11061115
/// Builds a load instruction that loads a value from the location in the
11071116
/// given value.
11081117
///
11091118
/// - parameter ptr: The pointer value to load from.
1119+
/// - parameter ordering: The ordering effect of the fence for this load,
1120+
/// if any. Defaults to a nonatomic load.
1121+
/// - parameter volatile: Whether this is a load from a volatile memory location.
11101122
/// - parameter name: The name for the newly inserted instruction.
11111123
///
11121124
/// - returns: A value representing the result of a load from the given
11131125
/// pointer value.
1114-
public func buildLoad(_ ptr: IRValue, name: String = "") -> IRValue {
1115-
return LLVMBuildLoad(llvm, ptr.asLLVM(), name)
1126+
public func buildLoad(_ ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, name: String = "") -> IRValue {
1127+
let loadInst = LLVMBuildLoad(llvm, ptr.asLLVM(), name)!
1128+
LLVMSetOrdering(loadInst, ordering.llvm)
1129+
LLVMSetVolatile(loadInst, volatile.llvm)
1130+
return loadInst
11161131
}
11171132

11181133
/// Builds a `GEP` (Get Element Pointer) instruction with a resultant value

0 commit comments

Comments
 (0)