mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Swift Bridging: use C++ instead of C bridging for the optimizer
This commit is contained in:
@@ -38,25 +38,25 @@ struct BasicBlockSet : IntrusiveSet {
|
||||
|
||||
init(_ context: some Context) {
|
||||
self.context = context._bridged
|
||||
self.bridged = PassContext_allocBasicBlockSet(self.context)
|
||||
self.bridged = self.context.allocBasicBlockSet()
|
||||
}
|
||||
|
||||
func contains(_ block: BasicBlock) -> Bool {
|
||||
BasicBlockSet_contains(bridged, block.bridged) != 0
|
||||
bridged.contains(block.bridged)
|
||||
}
|
||||
|
||||
/// Returns true if `block` was not contained in the set before inserting.
|
||||
@discardableResult
|
||||
mutating func insert(_ block: BasicBlock) -> Bool {
|
||||
BasicBlockSet_insert(bridged, block.bridged) != 0
|
||||
bridged.insert(block.bridged)
|
||||
}
|
||||
|
||||
mutating func erase(_ block: BasicBlock) {
|
||||
BasicBlockSet_erase(bridged, block.bridged)
|
||||
bridged.erase(block.bridged)
|
||||
}
|
||||
|
||||
var description: String {
|
||||
let function = BasicBlockSet_getFunction(bridged).function
|
||||
let function = bridged.getFunction().function
|
||||
let blockNames = function.blocks.enumerated().filter { contains($0.1) }
|
||||
.map { "bb\($0.0)"}
|
||||
return "{" + blockNames.joined(separator: ", ") + "}"
|
||||
@@ -64,7 +64,7 @@ struct BasicBlockSet : IntrusiveSet {
|
||||
|
||||
/// TODO: once we have move-only types, make this a real deinit.
|
||||
mutating func deinitialize() {
|
||||
PassContext_freeBasicBlockSet(context, bridged)
|
||||
context.freeBasicBlockSet(bridged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,25 +83,25 @@ struct ValueSet : IntrusiveSet {
|
||||
|
||||
init(_ context: some Context) {
|
||||
self.context = context._bridged
|
||||
self.bridged = PassContext_allocNodeSet(self.context)
|
||||
self.bridged = self.context.allocNodeSet()
|
||||
}
|
||||
|
||||
func contains(_ value: Value) -> Bool {
|
||||
NodeSet_containsValue(bridged, value.bridged) != 0
|
||||
bridged.containsValue(value.bridged)
|
||||
}
|
||||
|
||||
/// Returns true if `value` was not contained in the set before inserting.
|
||||
@discardableResult
|
||||
mutating func insert(_ value: Value) -> Bool {
|
||||
NodeSet_insertValue(bridged, value.bridged) != 0
|
||||
bridged.insertValue(value.bridged)
|
||||
}
|
||||
|
||||
mutating func erase(_ value: Value) {
|
||||
NodeSet_eraseValue(bridged, value.bridged)
|
||||
bridged.eraseValue(value.bridged)
|
||||
}
|
||||
|
||||
var description: String {
|
||||
let function = NodeSet_getFunction(bridged).function
|
||||
let function = bridged.getFunction().function
|
||||
var d = "{\n"
|
||||
for block in function.blocks {
|
||||
for arg in block.arguments {
|
||||
@@ -123,7 +123,7 @@ struct ValueSet : IntrusiveSet {
|
||||
|
||||
/// TODO: once we have move-only types, make this a real deinit.
|
||||
mutating func deinitialize() {
|
||||
PassContext_freeNodeSet(context, bridged)
|
||||
context.freeNodeSet(bridged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,25 +142,25 @@ struct InstructionSet : IntrusiveSet {
|
||||
|
||||
init(_ context: some Context) {
|
||||
self.context = context._bridged
|
||||
self.bridged = PassContext_allocNodeSet(self.context)
|
||||
self.bridged = self.context.allocNodeSet()
|
||||
}
|
||||
|
||||
func contains(_ inst: Instruction) -> Bool {
|
||||
NodeSet_containsInstruction(bridged, inst.bridged) != 0
|
||||
bridged.containsInstruction(inst.bridged)
|
||||
}
|
||||
|
||||
/// Returns true if `inst` was not contained in the set before inserting.
|
||||
@discardableResult
|
||||
mutating func insert(_ inst: Instruction) -> Bool {
|
||||
NodeSet_insertInstruction(bridged, inst.bridged) != 0
|
||||
bridged.insertInstruction(inst.bridged)
|
||||
}
|
||||
|
||||
mutating func erase(_ inst: Instruction) {
|
||||
NodeSet_eraseInstruction(bridged, inst.bridged)
|
||||
bridged.eraseInstruction(inst.bridged)
|
||||
}
|
||||
|
||||
var description: String {
|
||||
let function = NodeSet_getFunction(bridged).function
|
||||
let function = bridged.getFunction().function
|
||||
var d = "{\n"
|
||||
for inst in function.instructions {
|
||||
if contains(inst) {
|
||||
@@ -173,6 +173,6 @@ struct InstructionSet : IntrusiveSet {
|
||||
|
||||
/// TODO: once we have move-only types, make this a real deinit.
|
||||
mutating func deinitialize() {
|
||||
PassContext_freeNodeSet(context, bridged)
|
||||
context.freeNodeSet(bridged)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user