@@ -332,19 +332,26 @@ static void
332
332
computeNewArgInterfaceTypes (SILFunction *F,
333
333
IndicesSet &PromotableIndices,
334
334
SmallVectorImpl<SILParameterInfo> &OutTys) {
335
- auto Parameters = F->getLoweredFunctionType ()->getParameters ();
335
+ auto FunctionTy = F->getLoweredFunctionType ();
336
+ auto Parameters = FunctionTy->getParameters ();
337
+ auto NumIndirectResults = FunctionTy->getNumIndirectResults ();
336
338
337
339
DEBUG (llvm::dbgs () << " Preparing New Args!\n " );
338
340
339
341
// For each parameter in the old function...
340
342
for (unsigned Index : indices (Parameters)) {
341
343
auto ¶m = Parameters[Index];
342
344
345
+ // The PromotableIndices index is expressed as the argument index (num
346
+ // indirect result + param index). Add back the num indirect results to get
347
+ // the arg index when working with PromotableIndices.
348
+ unsigned ArgIndex = Index + NumIndirectResults;
349
+
343
350
DEBUG (llvm::dbgs () << " Index: " << Index << " ; PromotableIndices: "
344
- << (PromotableIndices.count (Index )?" yes" :" no" )
351
+ << (PromotableIndices.count (ArgIndex )?" yes" :" no" )
345
352
<< " Param: " ; param.dump ());
346
353
347
- if (!PromotableIndices.count (Index )) {
354
+ if (!PromotableIndices.count (ArgIndex )) {
348
355
OutTys.push_back (param);
349
356
continue ;
350
357
}
@@ -377,8 +384,14 @@ static std::string getSpecializedName(SILFunction *F,
377
384
CanSILFunctionType FTy = F->getLoweredFunctionType ();
378
385
379
386
ArrayRef<SILParameterInfo> Parameters = FTy->getParameters ();
387
+ auto NumIndirectResults = FTy->getNumIndirectResults ();
388
+
380
389
for (unsigned Index : indices (Parameters)) {
381
- if (!PromotableIndices.count (Index))
390
+ // The PromotableIndices index is expressed as the argument index (num
391
+ // indirect result + param index). Add back the num indirect results to get
392
+ // the arg index when working with PromotableIndices.
393
+ unsigned ArgIndex = Index + NumIndirectResults;
394
+ if (!PromotableIndices.count (ArgIndex))
382
395
continue ;
383
396
FSSM.setArgumentBoxToValue (Index);
384
397
}
@@ -747,11 +760,6 @@ examineAllocBoxInst(AllocBoxInst *ABI, ReachabilityInfo &RI,
747
760
if (signatureHasDependentTypes (*CalleeTy))
748
761
return false ;
749
762
750
- // The code currently does not handle indirect results correctly.
751
- // Conservatively, bail
752
- if (CalleeTy->hasIndirectResults ())
753
- return false ;
754
-
755
763
auto closureType = PAI->getType ().castTo <SILFunctionType>();
756
764
757
765
// Calculate the index into the closure's argument list of the captured
@@ -912,19 +920,20 @@ processPartialApplyInst(PartialApplyInst *PAI, IndicesSet &PromotableIndices,
912
920
913
921
// Populate the argument list for a new partial_apply instruction, taking into
914
922
// consideration any captures.
915
- auto CalleePInfo =
916
- PAI-> getCallee ()-> getType (). castTo <SILFunctionType>() ->getParameters ();
917
- auto PInfo = PAI-> getType (). castTo <SILFunctionType>()-> getParameters ();
918
- unsigned FirstIndex = PInfo. size ();
923
+ auto CalleeFunctionTy = PAI-> getCallee ()-> getType (). castTo <SILFunctionType>();
924
+ auto CalleePInfo = CalleeFunctionTy ->getParameters ();
925
+ unsigned FirstIndex =
926
+ PAI-> getType (). castTo <SILFunctionType>()-> getNumSILArguments ();
919
927
unsigned OpNo = 1 , OpCount = PAI->getNumOperands ();
920
928
SmallVector<SILValue, 16 > Args;
929
+ auto NumIndirectResults = CalleeFunctionTy->getNumIndirectResults ();
921
930
while (OpNo != OpCount) {
922
931
unsigned Index = OpNo - 1 + FirstIndex;
923
932
if (PromotableIndices.count (Index)) {
924
933
SILValue BoxValue = PAI->getOperand (OpNo);
925
934
AllocBoxInst *ABI = cast<AllocBoxInst>(BoxValue);
926
935
927
- SILParameterInfo CPInfo = CalleePInfo[Index];
936
+ SILParameterInfo CPInfo = CalleePInfo[Index - NumIndirectResults ];
928
937
assert (CPInfo.getSILType () == BoxValue->getType () &&
929
938
" SILType of parameter info does not match type of parameter" );
930
939
// Cleanup the captured argument.
0 commit comments