Skip to content

Commit a98448b

Browse files
committed
swift Builder: add a few instruction creation functions
1 parent 240fa6d commit a98448b

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,34 @@ public struct Builder {
230230
return notifyNew(apply.getAs(ApplyInst.self))
231231
}
232232

233+
@discardableResult
234+
public func createTryApply(
235+
function: Value,
236+
_ substitutionMap: SubstitutionMap,
237+
arguments: [Value],
238+
normalBlock: BasicBlock,
239+
errorBlock: BasicBlock,
240+
isNonAsync: Bool = false,
241+
specializationInfo: ApplyInst.SpecializationInfo = ApplyInst.SpecializationInfo()
242+
) -> TryApplyInst {
243+
let apply = arguments.withBridgedValues { valuesRef in
244+
bridged.createTryApply(function.bridged, substitutionMap.bridged, valuesRef,
245+
normalBlock.bridged, errorBlock.bridged,
246+
isNonAsync, specializationInfo)
247+
}
248+
return notifyNew(apply.getAs(TryApplyInst.self))
249+
}
250+
251+
@discardableResult
252+
public func createReturn(of value: Value) -> ReturnInst {
253+
return notifyNew(bridged.createReturn(value.bridged).getAs(ReturnInst.self))
254+
}
255+
256+
@discardableResult
257+
public func createThrow(of value: Value) -> ThrowInst {
258+
return notifyNew(bridged.createThrow(value.bridged).getAs(ThrowInst.self))
259+
}
260+
233261
public func createUncheckedEnumData(enum enumVal: Value,
234262
caseIndex: Int,
235263
resultType: Type) -> UncheckedEnumDataInst {
@@ -366,6 +394,16 @@ public struct Builder {
366394
return notifyNew(initExistential.getAs(InitExistentialRefInst.self))
367395
}
368396

397+
public func createInitExistentialMetatype(
398+
metatype: Value,
399+
existentialType: Type,
400+
useConformancesOf: InitExistentialMetatypeInst) -> InitExistentialMetatypeInst {
401+
let initExistential = bridged.createInitExistentialMetatype(metatype.bridged,
402+
existentialType.bridged,
403+
useConformancesOf.bridged)
404+
return notifyNew(initExistential.getAs(InitExistentialMetatypeInst.self))
405+
}
406+
369407
public func createMetatype(of type: Type, representation: Type.MetatypeRepresentation) -> MetatypeInst {
370408
let metatype = bridged.createMetatype(type.bridged, representation)
371409
return notifyNew(metatype.getAs(MetatypeInst.self))

include/swift/SIL/SILBridging.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,14 @@ struct BridgedBuilder{
11331133
BridgedSubstitutionMap subMap,
11341134
BridgedValueArray arguments, bool isNonThrowing, bool isNonAsync,
11351135
BridgedGenericSpecializationInformation specInfo) const;
1136+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createTryApply(BridgedValue function,
1137+
BridgedSubstitutionMap subMap,
1138+
BridgedValueArray arguments,
1139+
BridgedBasicBlock normalBB, BridgedBasicBlock errorBB,
1140+
bool isNonAsync,
1141+
BridgedGenericSpecializationInformation specInfo) const;
1142+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createReturn(BridgedValue op) const;
1143+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createThrow(BridgedValue op) const;
11361144
SWIFT_IMPORT_UNSAFE BridgedInstruction createSwitchEnumInst(BridgedValue enumVal,
11371145
OptionalBridgedBasicBlock defaultBlock,
11381146
const void * _Nullable enumCases, SwiftInt numEnumCases) const;
@@ -1176,6 +1184,9 @@ struct BridgedBuilder{
11761184
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createInitExistentialRef(BridgedValue instance,
11771185
BridgedType type,
11781186
BridgedInstruction useConformancesOf) const;
1187+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createInitExistentialMetatype(BridgedValue metatype,
1188+
BridgedType existentialType,
1189+
BridgedInstruction useConformancesOf) const;
11791190
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createMetatype(BridgedType type,
11801191
BridgedType::MetatypeRepresentation representation) const;
11811192
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndCOWMutation(BridgedValue instance,

include/swift/SIL/SILBridgingImpl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,28 @@ BridgedInstruction BridgedBuilder::createApply(BridgedValue function, BridgedSub
15251525
arguments.getValues(argValues), applyOpts, specInfo.data)};
15261526
}
15271527

1528+
BridgedInstruction BridgedBuilder::createTryApply(BridgedValue function, BridgedSubstitutionMap subMap,
1529+
BridgedValueArray arguments,
1530+
BridgedBasicBlock normalBB, BridgedBasicBlock errorBB,
1531+
bool isNonAsync,
1532+
BridgedGenericSpecializationInformation specInfo) const {
1533+
llvm::SmallVector<swift::SILValue, 16> argValues;
1534+
swift::ApplyOptions applyOpts;
1535+
if (isNonAsync) { applyOpts |= swift::ApplyFlags::DoesNotAwait; }
1536+
1537+
return {unbridged().createTryApply(
1538+
regularLoc(), function.getSILValue(), subMap.unbridged(),
1539+
arguments.getValues(argValues), normalBB.unbridged(), errorBB.unbridged(), applyOpts, specInfo.data)};
1540+
}
1541+
1542+
BridgedInstruction BridgedBuilder::createReturn(BridgedValue op) const {
1543+
return {unbridged().createReturn(regularLoc(), op.getSILValue())};
1544+
}
1545+
1546+
BridgedInstruction BridgedBuilder::createThrow(BridgedValue op) const {
1547+
return {unbridged().createThrow(regularLoc(), op.getSILValue())};
1548+
}
1549+
15281550
BridgedInstruction BridgedBuilder::createUncheckedEnumData(BridgedValue enumVal, SwiftInt caseIdx,
15291551
BridgedType resultType) const {
15301552
swift::SILValue en = enumVal.getSILValue();
@@ -1644,6 +1666,15 @@ BridgedInstruction BridgedBuilder::createInitExistentialRef(BridgedValue instanc
16441666
instance.getSILValue(), src->getConformances())};
16451667
}
16461668

1669+
BridgedInstruction BridgedBuilder::createInitExistentialMetatype(BridgedValue metatype,
1670+
BridgedType existentialType,
1671+
BridgedInstruction useConformancesOf) const {
1672+
auto *src = useConformancesOf.getAs<swift::InitExistentialMetatypeInst>();
1673+
return {unbridged().createInitExistentialMetatype(
1674+
regularLoc(), metatype.getSILValue(), existentialType.unbridged(),
1675+
src->getConformances())};
1676+
}
1677+
16471678
BridgedInstruction BridgedBuilder::createMetatype(BridgedType type,
16481679
BridgedType::MetatypeRepresentation representation) const {
16491680
auto *mt =

0 commit comments

Comments
 (0)