Skip to content

Commit e93919b

Browse files
committed
Add comments, remove commented code, and other general cleanup
1 parent ae64719 commit e93919b

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,6 @@ struct ConcreteArgumentCopy {
791791
assert(!paramInfo.isIndirectMutating()
792792
&& "A mutated opened existential value can't be replaced");
793793

794-
// if (!paramInfo.isConsumed())
795-
// return None;
796-
797794
SILValue origArg = apply.getArgument(argIdx);
798795
// FIXME_opaque: With SIL opaque values, a formally indirect argument may be
799796
// passed as a SIL object. In this case, generate a copy_value for the new
@@ -817,11 +814,13 @@ struct ConcreteArgumentCopy {
817814
SILBuilderWithScope B(apply.getInstruction(), BuilderCtx);
818815
auto loc = apply.getLoc();
819816
auto *ASI = B.createAllocStack(loc, CEI.ConcreteValue->getType());
820-
817+
// If the type is an address, simple copy it.
821818
if (CEI.ConcreteValue->getType().isAddress()) {
822819
B.createCopyAddr(loc, CEI.ConcreteValue, ASI, IsNotTake,
823820
IsInitialization_t::IsInitialization);
824821
} else {
822+
// Otherwise, we probably got the value from the source of a store
823+
// instruction so, create a store into the temporary argument.
825824
B.createStore(loc, CEI.ConcreteValue, ASI,
826825
StoreOwnershipQualifier::Unqualified);
827826
}
@@ -863,7 +862,6 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
863862
// Create the new set of arguments to apply including their substitutions.
864863
SubstitutionMap NewCallSubs = Apply.getSubstitutionMap();
865864
SmallVector<SILValue, 8> NewArgs;
866-
bool UpdatedArgs = false;
867865
unsigned ArgIdx = 0;
868866
// Push the indirect result arguments.
869867
for (unsigned EndIdx = Apply.getSubstCalleeConv().getSILArgIndexOfFirstParam();
@@ -891,18 +889,19 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
891889

892890
// Ensure that we have a concrete value to propagate.
893891
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.
895895
if (Apply.getArgument(ArgIdx)->getType().isAddress()) {
896896
auto argSub =
897897
ConcreteArgumentCopy::generate(CEI, Apply, ArgIdx, BuilderCtx);
898898
if (argSub) {
899-
UpdatedArgs = true;
900899
concreteArgCopies.push_back(*argSub);
901900
NewArgs.push_back(argSub->tempArg);
902901
}
903902
} else {
903+
// Otherwise, we can just use the value itself.
904904
NewArgs.push_back(CEI.ConcreteValue);
905-
UpdatedArgs = true;
906905
}
907906

908907
// Form a new set of substitutions where the argument is
@@ -926,7 +925,7 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
926925
});
927926
}
928927

929-
if (!UpdatedArgs) {
928+
if (NewArgs.empty()) {
930929
// Remove any new instructions created while attempting to optimize this
931930
// apply. Since the apply was never rewritten, if they aren't removed here,
932931
// they will be removed later as dead when visited by SILCombine, causing

lib/SILOptimizer/Utils/Existential.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ findInitExistentialFromGlobalAddr(GlobalAddrInst *GAI, SILInstruction *Insn) {
6969

7070
/// Returns the instruction that initializes the given stack address. This is
7171
/// currently either a init_existential_addr, unconditional_checked_cast_addr,
72-
/// store, or copy_addr (if the instruction initializing the source of the copy cannot
73-
/// be determined). Returns nullptr if the initializer does not dominate the
74-
/// alloc_stack user \p ASIUser. If the value is copied from another stack
72+
/// store, or copy_addr (if the instruction initializing the source of the copy
73+
/// cannot be determined). Returns nullptr if the initializer does not dominate
74+
/// the alloc_stack user \p ASIUser. If the value is copied from another stack
7575
/// location, \p isCopied is set to true.
7676
///
7777
/// allocStackAddr may either itself be an AllocStackInst or an
@@ -208,9 +208,10 @@ OpenedArchetypeInfo::OpenedArchetypeInfo(Operand &use) {
208208
// <copy|store> %opened to %stack
209209
// <opened_use> %instance
210210
if (auto *initI = getStackInitInst(instance, user, isOpenedValueCopied)) {
211-
if (auto *IEA = dyn_cast<InitExistentialAddrInst>(initI))
212-
// TODO: this case doesn't need to exist beacuse openedVal will never be used
213-
openedVal = IEA;
211+
// init_existential_addr isn't handled here because it isn't considered an
212+
// "opened" archtype. init_existential_addr should be handled by
213+
// ConcreteExistentialInfo.
214+
214215
if (auto *CAI = dyn_cast<CopyAddrInst>(initI))
215216
openedVal = CAI->getSrc();
216217
if (auto *store = dyn_cast<StoreInst>(initI))

0 commit comments

Comments
 (0)