@@ -216,6 +216,18 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
216
216
ArrayRef<SILValue> entryArgs,
217
217
bool replaceOriginalFunctionInPlace = false );
218
218
219
+ // / Clone all blocks in this function and all instructions in those
220
+ // / blocks.
221
+ // /
222
+ // / This is used to clone an entire function without mutating the original
223
+ // / function.
224
+ // /
225
+ // / The new function is expected to be completely empty. Clone the entry
226
+ // / blocks arguments here. The cloned arguments become the inputs to the
227
+ // / general SILCloner, which expects the new entry block to be ready to emit
228
+ // / instructions into.
229
+ void cloneFunction (SILFunction *origF);
230
+
219
231
// / The same as clone function body, except the caller can provide a callback
220
232
// / that allows for an entry arg to be assigned to a custom old argument. This
221
233
// / is useful if one re-arranges parameters when converting from inout to out.
@@ -703,32 +715,6 @@ class SILFunctionCloner : public SILClonerWithScopes<SILFunctionCloner> {
703
715
704
716
public:
705
717
SILFunctionCloner (SILFunction *newF) : SILClonerWithScopes(*newF) {}
706
-
707
- // / Clone all blocks in this function and all instructions in those
708
- // / blocks.
709
- // /
710
- // / This is used to clone an entire function without mutating the original
711
- // / function.
712
- // /
713
- // / The new function is expected to be completely empty. Clone the entry
714
- // / blocks arguments here. The cloned arguments become the inputs to the
715
- // / general SILCloner, which expects the new entry block to be ready to emit
716
- // / instructions into.
717
- void cloneFunction (SILFunction *origF) {
718
- SILFunction *newF = &Builder.getFunction ();
719
-
720
- auto *newEntryBB = newF->createBasicBlock ();
721
- newEntryBB->cloneArgumentList (origF->getEntryBlock ());
722
-
723
- // Copy the new entry block arguments into a separate vector purely to
724
- // resolve the type mismatch between SILArgument* and SILValue.
725
- SmallVector<SILValue, 8 > entryArgs;
726
- entryArgs.reserve (newF->getArguments ().size ());
727
- llvm::transform (newF->getArguments (), std::back_inserter (entryArgs),
728
- [](SILArgument *arg) -> SILValue { return arg; });
729
-
730
- SuperTy::cloneFunctionBody (origF, newEntryBB, entryArgs);
731
- }
732
718
};
733
719
734
720
template <typename ImplClass>
@@ -848,6 +834,23 @@ void SILCloner<ImplClass>::cloneFunctionBody(SILFunction *F,
848
834
commonFixUp (F);
849
835
}
850
836
837
+ template <typename ImplClass>
838
+ void SILCloner<ImplClass>::cloneFunction(SILFunction *origF) {
839
+ SILFunction *newF = &Builder.getFunction ();
840
+
841
+ auto *newEntryBB = newF->createBasicBlock ();
842
+ newEntryBB->cloneArgumentList (origF->getEntryBlock ());
843
+
844
+ // Copy the new entry block arguments into a separate vector purely to
845
+ // resolve the type mismatch between SILArgument* and SILValue.
846
+ SmallVector<SILValue, 8 > entryArgs;
847
+ entryArgs.reserve (newF->getArguments ().size ());
848
+ llvm::transform (newF->getArguments (), std::back_inserter (entryArgs),
849
+ [](SILArgument *arg) -> SILValue { return arg; });
850
+
851
+ cloneFunctionBody (origF, newEntryBB, entryArgs);
852
+ }
853
+
851
854
template <typename ImplClass>
852
855
void SILCloner<ImplClass>::cloneFunctionBody(
853
856
SILFunction *F, SILBasicBlock *clonedEntryBB, ArrayRef<SILValue> entryArgs,
0 commit comments