@@ -411,6 +411,8 @@ void OpaqueStorageAllocation::allocateOpaqueStorage() {
411
411
void OpaqueStorageAllocation::convertIndirectFunctionArgs () {
412
412
// Insert temporary argument loads at the top of the function.
413
413
SILBuilder argBuilder (pass.F ->getEntryBlock ()->begin ());
414
+ argBuilder.setSILConventions (
415
+ SILModuleConventions::getLoweredAddressConventions ());
414
416
415
417
auto fnConv = pass.F ->getConventions ();
416
418
unsigned argIdx = fnConv.getSILArgIndexOfFirstParam ();
@@ -572,6 +574,8 @@ void OpaqueStorageAllocation::allocateForValue(SILValue value,
572
574
}
573
575
574
576
SILBuilder allocBuilder (pass.F ->begin ()->begin ());
577
+ allocBuilder.setSILConventions (
578
+ SILModuleConventions::getLoweredAddressConventions ());
575
579
AllocStackInst *allocInstr =
576
580
allocBuilder.createAllocStack (getLocForValue (value), value->getType ());
577
581
@@ -580,6 +584,8 @@ void OpaqueStorageAllocation::allocateForValue(SILValue value,
580
584
// Insert stack deallocations.
581
585
for (TermInst *termInst : pass.returnInsts ) {
582
586
SILBuilder deallocBuilder (termInst);
587
+ deallocBuilder.setSILConventions (
588
+ SILModuleConventions::getLoweredAddressConventions ());
583
589
deallocBuilder.createDeallocStack (allocInstr->getLoc (), allocInstr);
584
590
}
585
591
}
@@ -713,7 +719,10 @@ class ApplyRewriter {
713
719
714
720
public:
715
721
ApplyRewriter (SILInstruction *origCall, AddressLoweringState &pass)
716
- : pass(pass), apply(origCall), argBuilder(origCall) {}
722
+ : pass(pass), apply(origCall), argBuilder(origCall) {
723
+ argBuilder.setSILConventions (
724
+ SILModuleConventions::getLoweredAddressConventions ());
725
+ }
717
726
718
727
void rewriteParameters ();
719
728
void rewriteIndirectParameter (Operand *operand);
@@ -755,6 +764,8 @@ static void insertStackDeallocationAtCall(AllocStackInst *allocInst,
755
764
switch (applyInst->getKind ()) {
756
765
case ValueKind::ApplyInst: {
757
766
SILBuilder deallocBuilder (&*std::next (lastUse->getIterator ()));
767
+ deallocBuilder.setSILConventions (
768
+ SILModuleConventions::getLoweredAddressConventions ());
758
769
deallocBuilder.createDeallocStack (allocInst->getLoc (), allocInst);
759
770
break ;
760
771
}
@@ -824,11 +835,14 @@ void ApplyRewriter::canonicalizeResults(
824
835
SILInstruction *result = directResultValues[resultIdx];
825
836
if (!result) {
826
837
SILBuilder resultBuilder (std::next (SILBasicBlock::iterator (applyInst)));
838
+ resultBuilder.setSILConventions (
839
+ SILModuleConventions::getLoweredAddressConventions ());
827
840
result = resultBuilder.createTupleExtract (applyInst->getLoc (),
828
841
applyInst, resultIdx);
829
842
directResultValues[resultIdx] = result;
830
843
}
831
844
SILBuilder B (destroyInst);
845
+ B.setSILConventions (SILModuleConventions::getLoweredAddressConventions ());
832
846
auto &TL = pass.F ->getModule ().getTypeLowering (result->getType ());
833
847
TL.emitDestroyValue (B, destroyInst->getLoc (), result);
834
848
}
@@ -860,6 +874,8 @@ SILValue ApplyRewriter::materializeIndirectResultAddress(
860
874
// TODO: Find the try_apply's result block.
861
875
// Build results outside-in to next stack allocations.
862
876
SILBuilder resultBuilder (std::next (SILBasicBlock::iterator (origCallInst)));
877
+ resultBuilder.setSILConventions (
878
+ SILModuleConventions::getLoweredAddressConventions ());
863
879
// This is a formally indirect argument, but is loadable.
864
880
loadInst = resultBuilder.createLoad (loc, allocInst,
865
881
LoadOwnershipQualifier::Unqualified);
@@ -907,6 +923,8 @@ void ApplyRewriter::convertApplyWithIndirectResults() {
907
923
// Prepare to emit a new call instruction.
908
924
SILLocation loc = origCallInst->getLoc ();
909
925
SILBuilder callBuilder (origCallInst);
926
+ callBuilder.setSILConventions (
927
+ SILModuleConventions::getLoweredAddressConventions ());
910
928
911
929
// The new call instruction's SIL calling convention.
912
930
SILFunctionConventions loweredCalleeConv (
@@ -966,9 +984,7 @@ void ApplyRewriter::convertApplyWithIndirectResults() {
966
984
case ValueKind::ApplyInst:
967
985
newCallInst = callBuilder.createApply (
968
986
loc, apply.getCallee (), apply.getSubstitutions (), newCallArgs,
969
- cast<ApplyInst>(origCallInst)->isNonThrowing (),
970
- nullptr ,
971
- SILModuleConventions::getLoweredAddressConventions ());
987
+ cast<ApplyInst>(origCallInst)->isNonThrowing (), nullptr );
972
988
break ;
973
989
case ValueKind::TryApplyInst:
974
990
// TODO: insert dealloc in the catch block.
@@ -984,6 +1000,9 @@ void ApplyRewriter::convertApplyWithIndirectResults() {
984
1000
// TODO: handle bbargs from try_apply.
985
1001
SILBuilder resultBuilder (
986
1002
std::next (SILBasicBlock::iterator (origCallInst)));
1003
+ resultBuilder.setSILConventions (
1004
+ SILModuleConventions::getLoweredAddressConventions ());
1005
+
987
1006
SmallVector<Operand*, 8 > origUses (origCallInst->getUses ());
988
1007
for (Operand *operand : origUses) {
989
1008
auto *extractInst = dyn_cast<TupleExtractInst>(operand->getUser ());
@@ -1057,6 +1076,7 @@ void ReturnRewriter::rewriteReturn(ReturnInst *returnInst) {
1057
1076
break ;
1058
1077
}
1059
1078
SILBuilder B (insertPt);
1079
+ B.setSILConventions (SILModuleConventions::getLoweredAddressConventions ());
1060
1080
1061
1081
// Gather direct function results.
1062
1082
unsigned numOrigDirectResults =
@@ -1152,7 +1172,9 @@ class AddressOnlyUseRewriter
1152
1172
1153
1173
public:
1154
1174
explicit AddressOnlyUseRewriter (AddressLoweringState &pass)
1155
- : pass(pass), B(*pass.F), addrMat(pass, B) {}
1175
+ : pass(pass), B(*pass.F), addrMat(pass, B) {
1176
+ B.setSILConventions (SILModuleConventions::getLoweredAddressConventions ());
1177
+ }
1156
1178
1157
1179
void visitOperand (Operand *operand) {
1158
1180
currOper = operand;
@@ -1288,7 +1310,9 @@ class AddressOnlyDefRewriter
1288
1310
1289
1311
public:
1290
1312
explicit AddressOnlyDefRewriter (AddressLoweringState &pass)
1291
- : pass(pass), B(*pass.F), addrMat(pass, B) {}
1313
+ : pass(pass), B(*pass.F), addrMat(pass, B) {
1314
+ B.setSILConventions (SILModuleConventions::getLoweredAddressConventions ());
1315
+ }
1292
1316
1293
1317
void visitInst (SILInstruction *inst) { visit (inst); }
1294
1318
0 commit comments