Skip to content

Commit 7d96100

Browse files
committed
libswift: bridge more functions from SILBuilder
1 parent 7eb3bdd commit 7d96100

File tree

12 files changed

+128
-9
lines changed

12 files changed

+128
-9
lines changed

SwiftCompilerSources/Sources/AST/SubstitutionMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SILBridging
1414

1515
public struct SubstitutionMap {
16-
let bridged: BridgedSubstitutionMap
16+
public let bridged: BridgedSubstitutionMap
1717

1818
public init(_ bridged: BridgedSubstitutionMap) {
1919
self.bridged = bridged

SwiftCompilerSources/Sources/Optimizer/PassManager/PassUtils.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import AST
1314
import SIL
1415
import OptimizerBridging
1516

@@ -115,6 +116,14 @@ struct PassContext {
115116
func fixStackNesting(function: Function) {
116117
PassContext_fixStackNesting(_bridged, function.bridged)
117118
}
119+
120+
func getDeallocRef(for type: Type) -> Function? {
121+
PassContext_getDeallocRef(_bridged, type.bridged).function
122+
}
123+
124+
func getContextSubstitutionMap(for type: Type) -> SubstitutionMap {
125+
SubstitutionMap(PassContext_getContextSubstitutionMap(_bridged, type.bridged))
126+
}
118127
}
119128

120129
struct FunctionPass {

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import AST
1314
import SILBridging
1415

1516
/// A utility to create new instructions at a given insertion point.
@@ -73,4 +74,42 @@ public struct Builder {
7374
let dr = SILBuilder_createDeallocStackRef(bridgedInsPoint, location.bridgedLocation, operand.bridged)
7475
return dr.getAs(DeallocStackRefInst.self)
7576
}
77+
78+
public func createUncheckedRefCast(object: Value, type: Type) -> UncheckedRefCastInst {
79+
notifyInstructionsChanged()
80+
let object = SILBuilder_createUncheckedRefCast(
81+
bridgedInsPoint, location.bridgedLocation, object.bridged, type.bridged)
82+
return object.getAs(UncheckedRefCastInst.self)
83+
}
84+
85+
@discardableResult
86+
public func createSetDeallocating(operand: Value, isAtomic: Bool) -> SetDeallocatingInst {
87+
notifyInstructionsChanged()
88+
let setDeallocating = SILBuilder_createSetDeallocating(
89+
bridgedInsPoint, location.bridgedLocation, operand.bridged, isAtomic)
90+
return setDeallocating.getAs(SetDeallocatingInst.self)
91+
}
92+
93+
public func createFunctionRef(_ function: Function) -> FunctionRefInst {
94+
notifyInstructionsChanged()
95+
let functionRef = SILBuilder_createFunctionRef(
96+
bridgedInsPoint, location.bridgedLocation, function.bridged)
97+
return functionRef.getAs(FunctionRefInst.self)
98+
}
99+
100+
@discardableResult
101+
public func createApply(
102+
function: Value,
103+
_ substitutionMap: SubstitutionMap,
104+
arguments: [Value]
105+
) -> FunctionRefInst {
106+
notifyInstructionsChanged()
107+
let functionRef = arguments.withBridgedValues { valuesRef in
108+
SILBuilder_createApply(
109+
bridgedInsPoint, location.bridgedLocation, function.bridged,
110+
substitutionMap.bridged, valuesRef
111+
)
112+
}
113+
return functionRef.getAs(FunctionRefInst.self)
114+
}
76115
}

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ public func != (lhs: Function, rhs: Function) -> Bool { lhs !== rhs }
5959
extension BridgedFunction {
6060
public var function: Function { obj.getAs(Function.self) }
6161
}
62+
63+
extension OptionalBridgedFunction {
64+
public var function: Function? { obj.getAs(Function.self) }
65+
}

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SILBridging
1414

1515
public struct Type {
16-
var bridged: BridgedType
16+
public let bridged: BridgedType
1717

1818
public var isAddress: Bool { SILType_isAddress(bridged) != 0 }
1919
public var isObject: Bool { !isAddress }

SwiftCompilerSources/Sources/SIL/Utils.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,3 @@ extension Optional where Wrapped == UnsafeMutablePointer<BridgedSwiftObject> {
219219
return nil
220220
}
221221
}
222-

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ extension Value {
2424
}
2525

2626
public var uses: UseList {
27-
return UseList(SILValue_firstUse(bridged))
27+
UseList(SILValue_firstUse(bridged))
2828
}
2929

3030
public var type: Type {
31-
return Type(bridged: SILValue_getType(bridged))
31+
Type(bridged: SILValue_getType(bridged))
3232
}
3333

3434
public var hashable: HashableValue { ObjectIdentifier(self) }
@@ -48,7 +48,7 @@ public func ==(_ lhs: Value, _ rhs: Value) -> Bool {
4848
}
4949

5050
extension BridgedValue {
51-
func getAs<T: AnyObject>(_ valueType: T.Type) -> T { obj.getAs(T.self) }
51+
public func getAs<T: AnyObject>(_ valueType: T.Type) -> T { obj.getAs(T.self) }
5252
}
5353

5454
final class Undef : Value {

include/swift/SIL/SILBridging.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ BridgedInstruction SILBuilder_createIntegerLiteral(BridgedInstruction insertionP
252252
BridgedLocation loc, BridgedType type, SwiftInt value);
253253
BridgedInstruction SILBuilder_createDeallocStackRef(BridgedInstruction insertionPoint,
254254
BridgedLocation loc, BridgedValue operand);
255+
BridgedInstruction SILBuilder_createUncheckedRefCast(BridgedInstruction insertionPoint,
256+
BridgedLocation loc,
257+
BridgedValue op,
258+
BridgedType type);
259+
BridgedInstruction
260+
SILBuilder_createSetDeallocating(BridgedInstruction insertionPoint,
261+
BridgedLocation loc, BridgedValue op,
262+
bool isAtomic);
263+
BridgedInstruction
264+
SILBuilder_createFunctionRef(BridgedInstruction insertionPoint,
265+
BridgedLocation loc, BridgedFunction function);
266+
BridgedInstruction SILBuilder_createApply(BridgedInstruction insertionPoint,
267+
BridgedLocation loc,
268+
BridgedValue function,
269+
BridgedSubstitutionMap subMap,
270+
BridgedValueArray arguments);
255271

256272
SWIFT_END_NULLABILITY_ANNOTATIONS
257273

include/swift/SIL/SILBridgingUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ inline SILType castToSILType(BridgedType type) {
7474
return SILType::getFromOpaqueValue(type.typePtr);
7575
}
7676

77+
inline SubstitutionMap castToSubstitutionMap(BridgedSubstitutionMap subMap) {
78+
return SubstitutionMap::getFromOpaqueValue(subMap.op);
79+
}
80+
7781
template <class I = SILInstruction> I *castToInst(BridgedInstruction inst) {
7882
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
7983
}

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ RCIdentityAnalysis_getFunctionInfo(BridgedRCIdentityAnalysis bridgedAnalysis,
151151
BridgedValue RCIdentityFunctionInfo_getRCIdentityRoot(
152152
BridgedRCIdentityFunctionInfo bridgedInfo, BridgedValue value);
153153

154-
OptionalBridgedFunction PassContext_getDestructor(BridgedPassContext context,
154+
OptionalBridgedFunction PassContext_getDeallocRef(BridgedPassContext context,
155155
BridgedType type);
156156

157+
BridgedSubstitutionMap
158+
PassContext_getContextSubstitutionMap(BridgedPassContext context,
159+
BridgedType bridgedType);
160+
157161
#ifdef __cplusplus
158162
} // extern "C"
159163
#endif

0 commit comments

Comments
 (0)