Skip to content

Commit

Permalink
Add intrinsic support for atomic store and load.
Browse files Browse the repository at this point in the history
Also add `void` intrinsic type.
  • Loading branch information
lucteo committed Dec 2, 2024
1 parent 734e7be commit 708cd66
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/CodeGen/LLVM/ConcreteTypeLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct ConcreteTypeLayout {
self.init(size: 8, alignment: 8)
case .float128:
self.init(size: 16, alignment: 8)
case .void:
notLLVMRepresentable(^t) // Cannot be used in a type layout.

Check warning on line 75 in Sources/CodeGen/LLVM/ConcreteTypeLayout.swift

View check run for this annotation

Codecov / codecov/patch

Sources/CodeGen/LLVM/ConcreteTypeLayout.swift#L75

Added line #L75 was not covered by tests
case .module:
notLLVMRepresentable(^t)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodeGen/LLVM/TypeLowering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ extension IR.Program {
return SwiftyLLVM.FloatingPointType.fp128(in: &module)
case .ptr:
return module.ptr
case .void:
return SwiftyLLVM.VoidType(in: &module)

Check warning on line 78 in Sources/CodeGen/LLVM/TypeLowering.swift

View check run for this annotation

Codecov / codecov/patch

Sources/CodeGen/LLVM/TypeLowering.swift#L78

Added line #L78 was not covered by tests
case .module:
notLLVMRepresentable(t)
}
Expand Down
36 changes: 36 additions & 0 deletions Sources/FrontEnd/NativeInstruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public enum NativeInstruction: Hashable {
// Corresponding LLVM instruction: get_elementptr_inbounds.
case advancedByBytes(byteOffset: BuiltinType)

case atomic_store_relaxed(BuiltinType)

case atomic_store_release(BuiltinType)

case atomic_store_seqcst(BuiltinType)

case atomic_load_relaxed(BuiltinType)

case atomic_load_acquire(BuiltinType)

case atomic_load_seqcst(BuiltinType)

/// The parameters of a floating-point LLVM instruction.
public struct MathFlags: OptionSet, Hashable {

Expand Down Expand Up @@ -238,6 +250,18 @@ extension NativeInstruction {
return .init(to: ^t)
case .advancedByBytes(let byteOffset):
return .init(.builtin(.ptr), ^byteOffset, to: .builtin(.ptr))
case .atomic_store_relaxed(let t):
return .init(.builtin(.ptr), ^t, to: .builtin(.void))

Check warning on line 254 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L254

Added line #L254 was not covered by tests
case .atomic_store_release(let t):
return .init(.builtin(.ptr), ^t, to: .builtin(.void))

Check warning on line 256 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L256

Added line #L256 was not covered by tests
case .atomic_store_seqcst(let t):
return .init(.builtin(.ptr), ^t, to: .builtin(.void))

Check warning on line 258 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L258

Added line #L258 was not covered by tests
case .atomic_load_relaxed(let t):
return .init(.builtin(.ptr), to: ^t)

Check warning on line 260 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L260

Added line #L260 was not covered by tests
case .atomic_load_acquire(let t):
return .init(.builtin(.ptr), to: ^t)

Check warning on line 262 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L262

Added line #L262 was not covered by tests
case .atomic_load_seqcst(let t):
return .init(.builtin(.ptr), to: ^t)

Check warning on line 264 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L264

Added line #L264 was not covered by tests
}
}

Expand Down Expand Up @@ -331,6 +355,18 @@ extension NativeInstruction: CustomStringConvertible {
return "zeroinitializer_\(t)"
case .advancedByBytes(let t):
return "advanced_by_bytes_\(t)"
case .atomic_store_relaxed(let t):
return "atomic_store_relaxed_\(t)"

Check warning on line 359 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L359

Added line #L359 was not covered by tests
case .atomic_store_release(let t):
return "atomic_store_release_\(t)"

Check warning on line 361 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L361

Added line #L361 was not covered by tests
case .atomic_store_seqcst(let t):
return "atomic_store_seqcst_\(t)"

Check warning on line 363 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L363

Added line #L363 was not covered by tests
case .atomic_load_relaxed(let t):
return "atomic_load_relaxed_\(t)"

Check warning on line 365 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L365

Added line #L365 was not covered by tests
case .atomic_load_acquire(let t):
return "atomic_load_acquire_\(t)"

Check warning on line 367 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L367

Added line #L367 was not covered by tests
case .atomic_load_seqcst(let t):
return "atomic_load_seqcst_\(t)"

Check warning on line 369 in Sources/FrontEnd/NativeInstruction.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/NativeInstruction.swift#L369

Added line #L369 was not covered by tests
}
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/FrontEnd/Types/BuiltinType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public enum BuiltinType: TypeProtocol {
/// A built-in opaque pointer.
case ptr

/// A built-in void type.
case void

/// The type of the built-in module.
case module

Expand Down Expand Up @@ -63,6 +66,8 @@ extension BuiltinType: CustomStringConvertible {
return "float128"
case .ptr:
return "ptr"
case .void:
return "void"

Check warning on line 70 in Sources/FrontEnd/Types/BuiltinType.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/Types/BuiltinType.swift#L70

Added line #L70 was not covered by tests
case .module:
return "Builtin"
}
Expand All @@ -86,6 +91,8 @@ extension BuiltinType: LosslessStringConvertible {
self = .float128
case "ptr":
self = .ptr
case "void":
self = .void

Check warning on line 95 in Sources/FrontEnd/Types/BuiltinType.swift

View check run for this annotation

Codecov / codecov/patch

Sources/FrontEnd/Types/BuiltinType.swift#L95

Added line #L95 was not covered by tests
case "Builtin":
self = .module

Expand Down
2 changes: 2 additions & 0 deletions Sources/IR/Mangling/Demangler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct Demangler {
demangled = takeBuiltinFloatType(from: &stream)
case .builtinPointerType:
demangled = .type(.builtin(.ptr))
case .builtinVoidType:
demangled = .type(.builtin(.void))

Check warning on line 46 in Sources/IR/Mangling/Demangler.swift

View check run for this annotation

Codecov / codecov/patch

Sources/IR/Mangling/Demangler.swift#L46

Added line #L46 was not covered by tests
case .builtinModuleType:
demangled = .type(.builtin(.module))
case .builtinWordType:
Expand Down
2 changes: 2 additions & 0 deletions Sources/IR/Mangling/Mangler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ struct Mangler {
append(integer: 128, to: &output)
case .ptr:
append(operator: .builtinPointerType, to: &output)
case .void:
append(operator: .builtinVoidType, to: &output)

Check warning on line 564 in Sources/IR/Mangling/Mangler.swift

View check run for this annotation

Codecov / codecov/patch

Sources/IR/Mangling/Mangler.swift#L564

Added line #L564 was not covered by tests
case .module:
append(operator: .builtinModuleType, to: &output)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/IR/Mangling/ManglingOperator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public enum ManglingOperator: String {

case builtinPointerType = "bpT"

case builtinVoidType = "bvT"

case builtinModuleType = "bmT"

case builtinWordType = "bwT"
Expand Down

0 comments on commit 708cd66

Please sign in to comment.