@@ -791,9 +791,6 @@ struct ConcreteArgumentCopy {
791
791
assert (!paramInfo.isIndirectMutating ()
792
792
&& " A mutated opened existential value can't be replaced" );
793
793
794
- // if (!paramInfo.isConsumed())
795
- // return None;
796
-
797
794
SILValue origArg = apply.getArgument (argIdx);
798
795
// FIXME_opaque: With SIL opaque values, a formally indirect argument may be
799
796
// passed as a SIL object. In this case, generate a copy_value for the new
@@ -817,11 +814,13 @@ struct ConcreteArgumentCopy {
817
814
SILBuilderWithScope B (apply.getInstruction (), BuilderCtx);
818
815
auto loc = apply.getLoc ();
819
816
auto *ASI = B.createAllocStack (loc, CEI.ConcreteValue ->getType ());
820
-
817
+ // If the type is an address, simple copy it.
821
818
if (CEI.ConcreteValue ->getType ().isAddress ()) {
822
819
B.createCopyAddr (loc, CEI.ConcreteValue , ASI, IsNotTake,
823
820
IsInitialization_t::IsInitialization);
824
821
} else {
822
+ // Otherwise, we probably got the value from the source of a store
823
+ // instruction so, create a store into the temporary argument.
825
824
B.createStore (loc, CEI.ConcreteValue , ASI,
826
825
StoreOwnershipQualifier::Unqualified);
827
826
}
@@ -863,7 +862,6 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
863
862
// Create the new set of arguments to apply including their substitutions.
864
863
SubstitutionMap NewCallSubs = Apply.getSubstitutionMap ();
865
864
SmallVector<SILValue, 8 > NewArgs;
866
- bool UpdatedArgs = false ;
867
865
unsigned ArgIdx = 0 ;
868
866
// Push the indirect result arguments.
869
867
for (unsigned EndIdx = Apply.getSubstCalleeConv ().getSILArgIndexOfFirstParam ();
@@ -891,18 +889,19 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
891
889
892
890
// Ensure that we have a concrete value to propagate.
893
891
assert (CEI.ConcreteValue );
894
-
892
+
893
+ // If the parameter is expecting a pointer, then we need to create a
894
+ // alloc_stack to store the temporary value.
895
895
if (Apply.getArgument (ArgIdx)->getType ().isAddress ()) {
896
896
auto argSub =
897
897
ConcreteArgumentCopy::generate (CEI, Apply, ArgIdx, BuilderCtx);
898
898
if (argSub) {
899
- UpdatedArgs = true ;
900
899
concreteArgCopies.push_back (*argSub);
901
900
NewArgs.push_back (argSub->tempArg );
902
901
}
903
902
} else {
903
+ // Otherwise, we can just use the value itself.
904
904
NewArgs.push_back (CEI.ConcreteValue );
905
- UpdatedArgs = true ;
906
905
}
907
906
908
907
// Form a new set of substitutions where the argument is
@@ -926,7 +925,7 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
926
925
});
927
926
}
928
927
929
- if (!UpdatedArgs ) {
928
+ if (NewArgs. empty () ) {
930
929
// Remove any new instructions created while attempting to optimize this
931
930
// apply. Since the apply was never rewritten, if they aren't removed here,
932
931
// they will be removed later as dead when visited by SILCombine, causing
0 commit comments