Skip to content

Commit 08696ee

Browse files
committed
Cloner: set the cloner's builder insertion point to the entry block when creating a new entry block in the cloned function
This allows clients to directly clone specific instructions into the new entry block
1 parent 898b875 commit 08696ee

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/Cloner.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public struct Cloner<Context: MutatingContext> {
6767
if let entryBlock = targetFunction.blocks.first {
6868
return entryBlock
6969
}
70-
return targetFunction.appendNewBlock(context)
70+
let entryBlock = targetFunction.appendNewBlock(context)
71+
bridged.setInsertionBlockIfNotSet(entryBlock.bridged)
72+
return entryBlock
7173
}
7274

7375
public func cloneFunctionBody(from originalFunction: Function, entryBlockArguments: [Value]) {

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ struct BridgedCloner {
15491549
void recordClonedInstruction(BridgedInstruction origInst, BridgedInstruction clonedInst) const;
15501550
void recordFoldedValue(BridgedValue orig, BridgedValue mapped) const;
15511551
BridgedInstruction clone(BridgedInstruction inst) const;
1552+
void setInsertionBlockIfNotSet(BridgedBasicBlock block) const;
15521553
};
15531554

15541555
struct BridgedTypeSubstCloner {

lib/SIL/Utils/SILBridging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ BridgedInstruction BridgedCloner::clone(BridgedInstruction inst) const {
699699
return {cloner->cloneInst(inst.unbridged())->asSILNode()};
700700
}
701701

702+
void BridgedCloner::setInsertionBlockIfNotSet(BridgedBasicBlock block) const {
703+
if (!cloner->getBuilder().hasValidInsertionPoint())
704+
cloner->getBuilder().setInsertionPoint(block.unbridged());
705+
}
706+
702707
BridgedBasicBlock BridgedCloner::getClonedBasicBlock(BridgedBasicBlock originalBasicBlock) const {
703708
return { cloner->getOpBasicBlock(originalBasicBlock.unbridged()) };
704709
}

0 commit comments

Comments
 (0)