Skip to content

Commit 9514b34

Browse files
committed
SwiftCompilerSources: add some context APIs
* `Context.moduleIsSerialized` * `Context.getBuiltinIntegerType` * `Instruction.move(before:)`
1 parent 0bd6034 commit 9514b34

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ extension Context {
4343
}
4444
}
4545

46+
var moduleIsSerialized: Bool { _bridged.moduleIsSerialized() }
47+
4648
func lookupDeinit(ofNominal: NominalTypeDecl) -> Function? {
4749
_bridged.lookUpNominalDeinitFunction(ofNominal.bridged).function
4850
}
51+
52+
func getBuiltinIntegerType(bitWidth: Int) -> Type { _bridged.getBuiltinIntegerType(bitWidth).type }
4953
}
5054

5155
/// A context which allows mutation of a function's SIL.
@@ -494,6 +498,11 @@ extension Instruction {
494498
bridged.setOperand(index, value.bridged)
495499
context.notifyInstructionChanged(self)
496500
}
501+
502+
func move(before otherInstruction: Instruction, _ context: some MutatingContext) {
503+
BridgedPassContext.moveInstructionBefore(bridged, otherInstruction.bridged)
504+
context.notifyInstructionsChanged()
505+
}
497506
}
498507

499508
extension BuiltinInst {

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public struct TupleElementArray : RandomAccessCollection, FormattedLikeArray {
251251
}
252252

253253
extension BridgedType {
254-
var type: Type { Type(bridged: self) }
254+
public var type: Type { Type(bridged: self) }
255255
var typeOrNil: Type? { isNull() ? nil : type }
256256
}
257257

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct BridgedPassContext {
173173
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedChangeNotificationHandler asNotificationHandler() const;
174174
BRIDGED_INLINE SILStage getSILStage() const;
175175
BRIDGED_INLINE bool hadError() const;
176+
BRIDGED_INLINE bool moduleIsSerialized() const;
176177

177178
// Analysis
178179

@@ -200,6 +201,7 @@ struct BridgedPassContext {
200201
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock createBlockAfter(BridgedBasicBlock bridgedBlock) const;
201202
BRIDGED_INLINE void eraseInstruction(BridgedInstruction inst) const;
202203
BRIDGED_INLINE void eraseBlock(BridgedBasicBlock block) const;
204+
static BRIDGED_INLINE void moveInstructionBefore(BridgedInstruction inst, BridgedInstruction beforeInst);
203205
bool tryOptimizeApplyOfPartialApply(BridgedInstruction closure) const;
204206
bool tryDeleteDeadClosure(BridgedInstruction closure, bool needKeepArgsAlive) const;
205207
SWIFT_IMPORT_UNSAFE DevirtResult tryDevirtualizeApply(BridgedInstruction apply, bool isMandatory) const;
@@ -275,6 +277,7 @@ struct BridgedPassContext {
275277
SWIFT_IMPORT_UNSAFE OptionalBridgedFunction lookupStdlibFunction(BridgedStringRef name) const;
276278
SWIFT_IMPORT_UNSAFE OptionalBridgedFunction lookUpNominalDeinitFunction(BridgedNominalTypeDecl nominal) const;
277279
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap(BridgedType type) const;
280+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getBuiltinIntegerType(SwiftInt bitWidth) const;
278281

279282
// Passmanager housekeeping
280283

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ bool BridgedPassContext::hadError() const {
145145
return invocation->getPassManager()->getModule()->getASTContext().hadError();
146146
}
147147

148+
bool BridgedPassContext::moduleIsSerialized() const {
149+
return invocation->getPassManager()->getModule()->isSerialized();
150+
}
151+
148152
BridgedAliasAnalysis BridgedPassContext::getAliasAnalysis() const {
149153
return {invocation->getPassManager()->getAnalysis<swift::AliasAnalysis>(invocation->getFunction())};
150154
}
@@ -206,6 +210,10 @@ void BridgedPassContext::eraseBlock(BridgedBasicBlock block) const {
206210
block.unbridged()->eraseFromParent();
207211
}
208212

213+
void BridgedPassContext::moveInstructionBefore(BridgedInstruction inst, BridgedInstruction beforeInst) {
214+
swift::SILBasicBlock::moveInstruction(inst.unbridged(), beforeInst.unbridged());
215+
}
216+
209217
BridgedValue BridgedPassContext::getSILUndef(BridgedType type) const {
210218
return {swift::SILUndef::get(type.unbridged(), *invocation->getFunction())};
211219
}
@@ -363,6 +371,11 @@ BridgedSubstitutionMap BridgedPassContext::getContextSubstitutionMap(BridgedType
363371
return ty.getASTType()->getContextSubstitutionMap(mod, ntd);
364372
}
365373

374+
BridgedType BridgedPassContext::getBuiltinIntegerType(SwiftInt bitWidth) const {
375+
auto &ctxt = invocation->getPassManager()->getModule()->getASTContext();
376+
return swift::SILType::getBuiltinIntegerType(bitWidth, ctxt);
377+
}
378+
366379
void BridgedPassContext::beginTransformFunction(BridgedFunction function) const {
367380
invocation->beginTransformFunction(function.getFunction());
368381
}

0 commit comments

Comments
 (0)