mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Swift Bridging: use C++ instead of C bridging for the optimizer
This commit is contained in:
@@ -17,7 +17,7 @@ struct AliasAnalysis {
|
||||
let bridged: BridgedAliasAnalysis
|
||||
|
||||
func mayRead(_ inst: Instruction, fromAddress: Value) -> Bool {
|
||||
switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, fromAddress.bridged) {
|
||||
switch bridged.getMemBehavior(inst.bridged, fromAddress.bridged) {
|
||||
case .MayRead, .MayReadWrite, .MayHaveSideEffects:
|
||||
return true
|
||||
default:
|
||||
@@ -26,7 +26,7 @@ struct AliasAnalysis {
|
||||
}
|
||||
|
||||
func mayWrite(_ inst: Instruction, toAddress: Value) -> Bool {
|
||||
switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, toAddress.bridged) {
|
||||
switch bridged.getMemBehavior(inst.bridged, toAddress.bridged) {
|
||||
case .MayWrite, .MayReadWrite, .MayHaveSideEffects:
|
||||
return true
|
||||
default:
|
||||
@@ -35,7 +35,7 @@ struct AliasAnalysis {
|
||||
}
|
||||
|
||||
func mayReadOrWrite(_ inst: Instruction, address: Value) -> Bool {
|
||||
switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, address.bridged) {
|
||||
switch bridged.getMemBehavior(inst.bridged, address.bridged) {
|
||||
case .MayRead, .MayWrite, .MayReadWrite, .MayHaveSideEffects:
|
||||
return true
|
||||
default:
|
||||
@@ -61,7 +61,7 @@ struct AliasAnalysis {
|
||||
}
|
||||
|
||||
static func register() {
|
||||
AliasAnalysis_register(
|
||||
BridgedAliasAnalysis.registerAnalysis(
|
||||
// getMemEffectsFn
|
||||
{ (bridgedCtxt: BridgedPassContext, bridgedVal: BridgedValue, bridgedInst: BridgedInstruction) -> swift.MemoryBehavior in
|
||||
let context = FunctionPassContext(_bridged: bridgedCtxt)
|
||||
|
||||
@@ -17,7 +17,7 @@ public struct CalleeAnalysis {
|
||||
let bridged: BridgedCalleeAnalysis
|
||||
|
||||
static func register() {
|
||||
CalleeAnalysis_register(
|
||||
BridgedCalleeAnalysis.registerAnalysis(
|
||||
// isDeinitBarrierFn:
|
||||
{ (inst : BridgedInstruction, bca: BridgedCalleeAnalysis) -> Bool in
|
||||
return inst.instruction.isDeinitBarrier(bca.analysis)
|
||||
@@ -33,19 +33,19 @@ public struct CalleeAnalysis {
|
||||
}
|
||||
|
||||
public func getCallees(callee: Value) -> FunctionArray? {
|
||||
let bridgedFuncs = CalleeAnalysis_getCallees(bridged, callee.bridged)
|
||||
if bridgedFuncs.incomplete != 0 {
|
||||
let bridgedFuncs = bridged.getCallees(callee.bridged)
|
||||
if bridgedFuncs.isIncomplete() {
|
||||
return nil
|
||||
}
|
||||
return FunctionArray(bridged: bridgedFuncs)
|
||||
}
|
||||
|
||||
public func getIncompleteCallees(callee: Value) -> FunctionArray {
|
||||
return FunctionArray(bridged: CalleeAnalysis_getCallees(bridged, callee.bridged))
|
||||
return FunctionArray(bridged: bridged.getCallees(callee.bridged))
|
||||
}
|
||||
|
||||
public func getDestructor(ofExactType type: Type) -> Function? {
|
||||
let destructors = FunctionArray(bridged: CalleeAnalysis_getDestructors(bridged, type.bridged, /*isExactType*/ 1))
|
||||
let destructors = FunctionArray(bridged: bridged.getDestructors(type.bridged, /*isExactType*/ true))
|
||||
if destructors.count == 1 {
|
||||
return destructors[0]
|
||||
}
|
||||
@@ -53,8 +53,8 @@ public struct CalleeAnalysis {
|
||||
}
|
||||
|
||||
public func getDestructors(of type: Type) -> FunctionArray? {
|
||||
let bridgedDtors = CalleeAnalysis_getDestructors(bridged, type.bridged, /*isExactType*/ 0)
|
||||
if bridgedDtors.incomplete != 0 {
|
||||
let bridgedDtors = bridged.getDestructors(type.bridged, /*isExactType*/ false)
|
||||
if bridgedDtors.isIncomplete() {
|
||||
return nil
|
||||
}
|
||||
return FunctionArray(bridged: bridgedDtors)
|
||||
@@ -123,13 +123,13 @@ extension Instruction {
|
||||
}
|
||||
|
||||
public struct FunctionArray : RandomAccessCollection, FormattedLikeArray {
|
||||
fileprivate let bridged: BridgedCalleeList
|
||||
fileprivate let bridged: swift.CalleeList
|
||||
|
||||
public var startIndex: Int { 0 }
|
||||
public var endIndex: Int { BridgedFunctionArray_size(bridged) }
|
||||
public var endIndex: Int { Int(bridged.getCount()) }
|
||||
|
||||
public subscript(_ index: Int) -> Function {
|
||||
return BridgedFunctionArray_get(bridged, index).function
|
||||
return BridgedCalleeAnalysis.getCallee(bridged, index).function
|
||||
}
|
||||
}
|
||||
// Bridging utilities
|
||||
|
||||
@@ -17,6 +17,6 @@ public struct DeadEndBlocksAnalysis {
|
||||
let bridged: BridgedDeadEndBlocksAnalysis
|
||||
|
||||
public func isDeadEnd(_ block: BasicBlock) -> Bool {
|
||||
return DeadEndBlocksAnalysis_isDeadEnd(bridged, block.bridged) != 0
|
||||
return bridged.isDeadEnd(block.bridged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public struct DominatorTree {
|
||||
|
||||
extension BasicBlock {
|
||||
func dominates(_ other: BasicBlock, _ domTree: DominatorTree) -> Bool {
|
||||
DominatorTree_dominates(domTree.bridged, self.bridged, other.bridged) != 0
|
||||
domTree.bridged.dominates(self.bridged, other.bridged)
|
||||
}
|
||||
|
||||
func strictlyDominates(_ other: BasicBlock, _ domTree: DominatorTree) -> Bool {
|
||||
|
||||
@@ -19,7 +19,7 @@ public struct PostDominatorTree {
|
||||
|
||||
extension BasicBlock {
|
||||
func postDominates(_ other: BasicBlock, _ pdomTree: PostDominatorTree) -> Bool {
|
||||
PostDominatorTree_postDominates(pdomTree.bridged, self.bridged, other.bridged) != 0
|
||||
pdomTree.bridged.postDominates(self.bridged, other.bridged)
|
||||
}
|
||||
|
||||
func strictlyPostDominates(_ other: BasicBlock, _ pdomTree: PostDominatorTree) -> Bool {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,22 +27,22 @@ import SIL
|
||||
struct Stack<Element> : CollectionLikeSequence {
|
||||
|
||||
private let bridgedContext: BridgedPassContext
|
||||
private var firstSlab = BridgedSlab(data: nil)
|
||||
private var lastSlab = BridgedSlab(data: nil)
|
||||
private var firstSlab = BridgedPassContext.Slab(nil)
|
||||
private var lastSlab = BridgedPassContext.Slab(nil)
|
||||
private var endIndex: Int = 0
|
||||
|
||||
private static var slabCapacity: Int {
|
||||
BridgedSlabCapacity / MemoryLayout<Element>.stride
|
||||
BridgedPassContext.Slab.getCapacity() / MemoryLayout<Element>.stride
|
||||
}
|
||||
|
||||
private static func bind(_ slab: BridgedSlab) -> UnsafeMutablePointer<Element> {
|
||||
return slab.data!.bindMemory(to: Element.self, capacity: Stack.slabCapacity)
|
||||
private static func bind(_ slab: BridgedPassContext.Slab) -> UnsafeMutablePointer<Element> {
|
||||
return UnsafeMutableRawPointer(slab.data!).bindMemory(to: Element.self, capacity: Stack.slabCapacity)
|
||||
}
|
||||
|
||||
struct Iterator : IteratorProtocol {
|
||||
var slab: BridgedSlab
|
||||
var slab: BridgedPassContext.Slab
|
||||
var index: Int
|
||||
let lastSlab: BridgedSlab
|
||||
let lastSlab: BridgedPassContext.Slab
|
||||
let endIndex: Int
|
||||
|
||||
mutating func next() -> Element? {
|
||||
@@ -52,7 +52,7 @@ struct Stack<Element> : CollectionLikeSequence {
|
||||
index += 1
|
||||
|
||||
if index >= end && slab.data != lastSlab.data {
|
||||
slab = PassContext_getNextSlab(slab)
|
||||
slab = slab.getNext()
|
||||
index = 0
|
||||
}
|
||||
return elem
|
||||
@@ -77,11 +77,11 @@ struct Stack<Element> : CollectionLikeSequence {
|
||||
|
||||
mutating func push(_ element: Element) {
|
||||
if endIndex >= Stack.slabCapacity {
|
||||
lastSlab = PassContext_allocSlab(bridgedContext, lastSlab)
|
||||
lastSlab = bridgedContext.allocSlab(lastSlab)
|
||||
endIndex = 0
|
||||
} else if firstSlab.data == nil {
|
||||
assert(endIndex == 0)
|
||||
firstSlab = PassContext_allocSlab(bridgedContext, lastSlab)
|
||||
firstSlab = bridgedContext.allocSlab(lastSlab)
|
||||
lastSlab = firstSlab
|
||||
}
|
||||
(Stack.bind(lastSlab) + endIndex).initialize(to: element)
|
||||
@@ -109,12 +109,12 @@ struct Stack<Element> : CollectionLikeSequence {
|
||||
|
||||
if endIndex == 0 {
|
||||
if lastSlab.data == firstSlab.data {
|
||||
_ = PassContext_freeSlab(bridgedContext, lastSlab)
|
||||
_ = bridgedContext.freeSlab(lastSlab)
|
||||
firstSlab.data = nil
|
||||
lastSlab.data = nil
|
||||
endIndex = 0
|
||||
} else {
|
||||
lastSlab = PassContext_freeSlab(bridgedContext, lastSlab)
|
||||
lastSlab = bridgedContext.freeSlab(lastSlab)
|
||||
endIndex = Stack.slabCapacity
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ extension Context {
|
||||
// The calleeAnalysis is not specific to a function and therefore can be provided in
|
||||
// all contexts.
|
||||
var calleeAnalysis: CalleeAnalysis {
|
||||
let bridgeCA = PassContext_getCalleeAnalysis(_bridged)
|
||||
let bridgeCA = _bridged.getCalleeAnalysis()
|
||||
return CalleeAnalysis(bridged: bridgeCA)
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ protocol MutatingContext : Context {
|
||||
}
|
||||
|
||||
extension MutatingContext {
|
||||
func notifyInvalidatedStackNesting() { PassContext_notifyInvalidatedStackNesting(_bridged) }
|
||||
var needFixStackNesting: Bool { PassContext_getNeedFixStackNesting(_bridged) }
|
||||
func notifyInvalidatedStackNesting() { _bridged.notifyInvalidatedStackNesting() }
|
||||
var needFixStackNesting: Bool { _bridged.getNeedFixStackNesting() }
|
||||
|
||||
/// Splits the basic block, which contains `inst`, before `inst` and returns the
|
||||
/// new block.
|
||||
@@ -46,7 +46,7 @@ extension MutatingContext {
|
||||
/// instructions _before_ `inst` remain in the original block.
|
||||
func splitBlock(at inst: Instruction) -> BasicBlock {
|
||||
notifyBranchesChanged()
|
||||
return PassContext_splitBlock(inst.bridged).block
|
||||
return _bridged.splitBlock(inst.bridged).block
|
||||
}
|
||||
|
||||
func erase(instruction: Instruction) {
|
||||
@@ -58,7 +58,7 @@ extension MutatingContext {
|
||||
}
|
||||
notifyInstructionsChanged()
|
||||
|
||||
PassContext_eraseInstruction(_bridged, instruction.bridged)
|
||||
_bridged.eraseInstruction(instruction.bridged)
|
||||
}
|
||||
|
||||
func erase(instructionIncludingDebugUses inst: Instruction) {
|
||||
@@ -72,25 +72,25 @@ extension MutatingContext {
|
||||
}
|
||||
|
||||
func tryDeleteDeadClosure(closure: SingleValueInstruction) -> Bool {
|
||||
PassContext_tryDeleteDeadClosure(_bridged, closure.bridged)
|
||||
_bridged.tryDeleteDeadClosure(closure.bridged)
|
||||
}
|
||||
|
||||
func getContextSubstitutionMap(for type: Type) -> SubstitutionMap {
|
||||
SubstitutionMap(PassContext_getContextSubstitutionMap(_bridged, type.bridged))
|
||||
SubstitutionMap(_bridged.getContextSubstitutionMap(type.bridged))
|
||||
}
|
||||
|
||||
// Private utilities
|
||||
|
||||
fileprivate func notifyInstructionsChanged() {
|
||||
PassContext_notifyChanges(_bridged, instructionsChanged)
|
||||
_bridged.asNotificationHandler().notifyChanges(.instructionsChanged)
|
||||
}
|
||||
|
||||
fileprivate func notifyCallsChanged() {
|
||||
PassContext_notifyChanges(_bridged, callsChanged)
|
||||
_bridged.asNotificationHandler().notifyChanges(.callsChanged)
|
||||
}
|
||||
|
||||
fileprivate func notifyBranchesChanged() {
|
||||
PassContext_notifyChanges(_bridged, branchesChanged)
|
||||
_bridged.asNotificationHandler().notifyChanges(.branchesChanged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ struct FunctionPassContext : MutatingContext {
|
||||
|
||||
func continueWithNextSubpassRun(for inst: Instruction? = nil) -> Bool {
|
||||
let bridgedInst = OptionalBridgedInstruction(inst?.bridged.obj)
|
||||
return PassContext_continueWithNextSubpassRun(_bridged, bridgedInst) != 0
|
||||
return _bridged.continueWithNextSubpassRun(bridgedInst)
|
||||
}
|
||||
|
||||
func createSimplifyContext(preserveDebugInfo: Bool, notifyInstructionChanged: @escaping (Instruction) -> ()) -> SimplifyContext {
|
||||
@@ -111,33 +111,33 @@ struct FunctionPassContext : MutatingContext {
|
||||
}
|
||||
|
||||
var aliasAnalysis: AliasAnalysis {
|
||||
let bridgedAA = PassContext_getAliasAnalysis(_bridged)
|
||||
let bridgedAA = _bridged.getAliasAnalysis()
|
||||
return AliasAnalysis(bridged: bridgedAA)
|
||||
}
|
||||
|
||||
var deadEndBlocks: DeadEndBlocksAnalysis {
|
||||
let bridgeDEA = PassContext_getDeadEndBlocksAnalysis(_bridged)
|
||||
let bridgeDEA = _bridged.getDeadEndBlocksAnalysis()
|
||||
return DeadEndBlocksAnalysis(bridged: bridgeDEA)
|
||||
}
|
||||
|
||||
var dominatorTree: DominatorTree {
|
||||
let bridgedDT = PassContext_getDomTree(_bridged)
|
||||
let bridgedDT = _bridged.getDomTree()
|
||||
return DominatorTree(bridged: bridgedDT)
|
||||
}
|
||||
|
||||
var postDominatorTree: PostDominatorTree {
|
||||
let bridgedPDT = PassContext_getPostDomTree(_bridged)
|
||||
let bridgedPDT = _bridged.getPostDomTree()
|
||||
return PostDominatorTree(bridged: bridgedPDT)
|
||||
}
|
||||
|
||||
func loadFunction(name: StaticString) -> Function? {
|
||||
return name.withUTF8Buffer { (nameBuffer: UnsafeBufferPointer<UInt8>) in
|
||||
PassContext_loadFunction(_bridged, llvm.StringRef(nameBuffer.baseAddress, nameBuffer.count)).function
|
||||
_bridged.loadFunction(llvm.StringRef(nameBuffer.baseAddress, nameBuffer.count)).function
|
||||
}
|
||||
}
|
||||
|
||||
func erase(block: BasicBlock) {
|
||||
PassContext_eraseBlock(_bridged, block.bridged)
|
||||
_bridged.eraseBlock(block.bridged)
|
||||
}
|
||||
|
||||
func modifyEffects(in function: Function, _ body: (inout FunctionEffects) -> ()) {
|
||||
@@ -146,7 +146,7 @@ struct FunctionPassContext : MutatingContext {
|
||||
}
|
||||
|
||||
fileprivate func notifyEffectsChanged() {
|
||||
PassContext_notifyChanges(_bridged, effectsChanged)
|
||||
_bridged.asNotificationHandler().notifyChanges(.effectsChanged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,23 +164,23 @@ extension Builder {
|
||||
/// Creates a builder which inserts _before_ `insPnt`, using a custom `location`.
|
||||
init(before insPnt: Instruction, location: Location, _ context: some MutatingContext) {
|
||||
self.init(insertAt: .before(insPnt), location: location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
|
||||
/// Creates a builder which inserts _before_ `insPnt`, using the location of `insPnt`.
|
||||
init(before insPnt: Instruction, _ context: some MutatingContext) {
|
||||
self.init(insertAt: .before(insPnt), location: insPnt.location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
|
||||
/// Creates a builder which inserts _after_ `insPnt`, using a custom `location`.
|
||||
init(after insPnt: Instruction, location: Location, _ context: some MutatingContext) {
|
||||
if let nextInst = insPnt.next {
|
||||
self.init(insertAt: .before(nextInst), location: location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
} else {
|
||||
self.init(insertAt: .atEndOf(insPnt.parentBlock), location: location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,14 +192,14 @@ extension Builder {
|
||||
/// Creates a builder which inserts at the end of `block`, using a custom `location`.
|
||||
init(atEndOf block: BasicBlock, location: Location, _ context: some MutatingContext) {
|
||||
self.init(insertAt: .atEndOf(block), location: location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
|
||||
/// Creates a builder which inserts at the begin of `block`, using a custom `location`.
|
||||
init(atBeginOf block: BasicBlock, location: Location, _ context: some MutatingContext) {
|
||||
let firstInst = block.instructions.first!
|
||||
self.init(insertAt: .before(firstInst), location: location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
|
||||
/// Creates a builder which inserts at the begin of `block`, using the location of the first
|
||||
@@ -207,7 +207,7 @@ extension Builder {
|
||||
init(atBeginOf block: BasicBlock, _ context: some MutatingContext) {
|
||||
let firstInst = block.instructions.first!
|
||||
self.init(insertAt: .before(firstInst), location: firstInst.location,
|
||||
context.notifyInstructionChanged, context._bridged)
|
||||
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ extension Builder {
|
||||
|
||||
extension Undef {
|
||||
static func get(type: Type, _ context: some MutatingContext) -> Undef {
|
||||
SILUndef_get(type.bridged, context._bridged).value as! Undef
|
||||
context._bridged.getSILUndef(type.bridged).value as! Undef
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ extension BasicBlock {
|
||||
extension AllocRefInstBase {
|
||||
func setIsStackAllocatable(_ context: some MutatingContext) {
|
||||
context.notifyInstructionsChanged()
|
||||
AllocRefInstBase_setIsStackAllocatable(bridged)
|
||||
bridged.AllocRefInstBase_setIsStackAllocatable()
|
||||
context.notifyInstructionChanged(self)
|
||||
}
|
||||
}
|
||||
@@ -294,7 +294,7 @@ extension RefCountingInst {
|
||||
extension TermInst {
|
||||
func replaceBranchTarget(from fromBlock: BasicBlock, to toBlock: BasicBlock, _ context: some MutatingContext) {
|
||||
context.notifyBranchesChanged()
|
||||
TermInst_replaceBranchTarget(bridged, fromBlock.bridged, toBlock.bridged)
|
||||
bridged.TermInst_replaceBranchTarget(fromBlock.bridged, toBlock.bridged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,6 @@ extension Function {
|
||||
}
|
||||
|
||||
func fixStackNesting(_ context: FunctionPassContext) {
|
||||
PassContext_fixStackNesting(context._bridged, bridged)
|
||||
context._bridged.fixStackNesting(bridged)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ struct ModulePassContext : Context {
|
||||
|
||||
mutating func next() -> Function? {
|
||||
if let f = currentFunction {
|
||||
currentFunction = PassContext_nextFunctionInModule(f.bridged).function
|
||||
currentFunction = BridgedPassContext.getNextFunctionInModule(f.bridged).function
|
||||
return f
|
||||
}
|
||||
return nil
|
||||
@@ -36,14 +36,14 @@ struct ModulePassContext : Context {
|
||||
}
|
||||
|
||||
struct VTableArray : BridgedRandomAccessCollection {
|
||||
fileprivate let bridged: BridgedVTableArray
|
||||
fileprivate let bridged: BridgedPassContext.VTableArray
|
||||
|
||||
var startIndex: Int { return 0 }
|
||||
var endIndex: Int { return bridged.count }
|
||||
|
||||
subscript(_ index: Int) -> VTable {
|
||||
assert(index >= startIndex && index < endIndex)
|
||||
return VTable(bridged: bridged.vTables![index])
|
||||
return VTable(bridged: BridgedVTable(vTable: bridged.base![index]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ struct ModulePassContext : Context {
|
||||
|
||||
mutating func next() -> WitnessTable? {
|
||||
if let t = currentTable {
|
||||
currentTable = PassContext_nextWitnessTableInModule(t.bridged).witnessTable
|
||||
currentTable = BridgedPassContext.getNextWitnessTableInModule(t.bridged).witnessTable
|
||||
return t
|
||||
}
|
||||
return nil
|
||||
@@ -68,7 +68,7 @@ struct ModulePassContext : Context {
|
||||
|
||||
mutating func next() -> DefaultWitnessTable? {
|
||||
if let t = currentTable {
|
||||
currentTable = PassContext_nextDefaultWitnessTableInModule(t.bridged).defaultWitnessTable
|
||||
currentTable = BridgedPassContext.getNextDefaultWitnessTableInModule(t.bridged).defaultWitnessTable
|
||||
return t
|
||||
}
|
||||
return nil
|
||||
@@ -76,19 +76,19 @@ struct ModulePassContext : Context {
|
||||
}
|
||||
|
||||
var functions: FunctionList {
|
||||
FunctionList(first: PassContext_firstFunctionInModule(_bridged).function)
|
||||
FunctionList(first: _bridged.getFirstFunctionInModule().function)
|
||||
}
|
||||
|
||||
var vTables: VTableArray {
|
||||
VTableArray(bridged: PassContext_getVTables(_bridged))
|
||||
VTableArray(bridged: _bridged.getVTables())
|
||||
}
|
||||
|
||||
var witnessTables: WitnessTableList {
|
||||
WitnessTableList(first: PassContext_firstWitnessTableInModule(_bridged).witnessTable)
|
||||
WitnessTableList(first: _bridged.getFirstWitnessTableInModule().witnessTable)
|
||||
}
|
||||
|
||||
var defaultWitnessTables: DefaultWitnessTableList {
|
||||
DefaultWitnessTableList(first: PassContext_firstDefaultWitnessTableInModule(_bridged).defaultWitnessTable)
|
||||
DefaultWitnessTableList(first: _bridged.getFirstDefaultWitnessTableInModule().defaultWitnessTable)
|
||||
}
|
||||
|
||||
/// Run a closure with a `PassContext` for a function, which allows to modify that function.
|
||||
@@ -96,8 +96,8 @@ struct ModulePassContext : Context {
|
||||
/// Only a single `transform` can be alive at the same time, i.e. it's not allowed to nest
|
||||
/// calls to `transform`.
|
||||
func transform(function: Function, _ runOnFunction: (FunctionPassContext) -> ()) {
|
||||
PassContext_beginTransformFunction(function.bridged, _bridged)
|
||||
_bridged.beginTransformFunction(function.bridged)
|
||||
runOnFunction(FunctionPassContext(_bridged: _bridged))
|
||||
PassContext_endTransformFunction(_bridged);
|
||||
_bridged.endTransformFunction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ struct Options {
|
||||
let _bridged: BridgedPassContext
|
||||
|
||||
var enableStackProtection: Bool {
|
||||
SILOptions_enableStackProtection(_bridged) != 0
|
||||
_bridged.enableStackProtection()
|
||||
}
|
||||
|
||||
var enableMoveInoutStackProtection: Bool {
|
||||
SILOptions_enableMoveInoutStackProtection(_bridged) != 0
|
||||
_bridged.enableMoveInoutStackProtection()
|
||||
}
|
||||
|
||||
func enableSimplification(for inst: Instruction) -> Bool {
|
||||
SILOptions_enableSimplificationFor(inst.bridged)
|
||||
_bridged.enableSimplificationFor(inst.bridged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public struct Builder {
|
||||
|
||||
let insertAt: InsertionPoint
|
||||
let location: Location
|
||||
private let passContext: BridgedPassContext
|
||||
private let notificationHandler: BridgedChangeNotificationHandler
|
||||
private let notifyNewInstruction: (Instruction) -> ()
|
||||
|
||||
private var bridged: BridgedBuilder {
|
||||
@@ -40,12 +40,12 @@ public struct Builder {
|
||||
}
|
||||
|
||||
private func notifyNew<I: Instruction>(_ instruction: I) -> I {
|
||||
PassContext_notifyChanges(passContext, instructionsChanged)
|
||||
notificationHandler.notifyChanges(.instructionsChanged)
|
||||
if instruction is FullApplySite {
|
||||
PassContext_notifyChanges(passContext, callsChanged)
|
||||
notificationHandler.notifyChanges(.callsChanged)
|
||||
}
|
||||
if instruction is TermInst {
|
||||
PassContext_notifyChanges(passContext, branchesChanged)
|
||||
notificationHandler.notifyChanges(.branchesChanged)
|
||||
}
|
||||
notifyNewInstruction(instruction)
|
||||
return instruction
|
||||
@@ -53,11 +53,11 @@ public struct Builder {
|
||||
|
||||
public init(insertAt: InsertionPoint, location: Location,
|
||||
_ notifyNewInstruction: @escaping (Instruction) -> (),
|
||||
_ passContext: BridgedPassContext) {
|
||||
_ notificationHandler: BridgedChangeNotificationHandler) {
|
||||
self.insertAt = insertAt
|
||||
self.location = location;
|
||||
self.notifyNewInstruction = notifyNewInstruction
|
||||
self.passContext = passContext
|
||||
self.notificationHandler = notificationHandler
|
||||
}
|
||||
|
||||
public func createBuiltinBinaryFunction(name: String,
|
||||
|
||||
Reference in New Issue
Block a user