Skip to content

Commit 6061fe6

Browse files
authored
Merge pull request #32774 from gottesmm/pr-8b5227a32670d42e9974d93fbe5509171ea31bd0
[gardening] Extract out a lambda out of a loop and reduce some indentation within it by inverting if statements.
2 parents cee75bd + 068581c commit 6061fe6

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

lib/SILOptimizer/Utils/Generics.cpp

+43-38
Original file line numberDiff line numberDiff line change
@@ -1922,48 +1922,53 @@ prepareCallArguments(ApplySite AI, SILBuilder &Builder,
19221922
SILLocation Loc = AI.getLoc();
19231923
auto substConv = AI.getSubstCalleeConv();
19241924
unsigned ArgIdx = AI.getCalleeArgIndexOfFirstAppliedArg();
1925-
for (auto &Op : AI.getArgumentOperands()) {
1926-
auto handleConversion = [&]() {
1927-
// Rewriting SIL arguments is only for lowered addresses.
1928-
if (!substConv.useLoweredAddresses())
1929-
return false;
19301925

1931-
if (ArgIdx < substConv.getSILArgIndexOfFirstParam()) {
1932-
// Handle result arguments.
1933-
unsigned formalIdx =
1934-
substConv.getIndirectFormalResultIndexForSILArg(ArgIdx);
1935-
if (ReInfo.isFormalResultConverted(formalIdx)) {
1936-
// The result is converted from indirect to direct. We need to insert
1937-
// a store later.
1938-
assert(!StoreResultTo);
1939-
StoreResultTo = Op.get();
1940-
return true;
1941-
}
1942-
} else {
1943-
// Handle arguments for formal parameters.
1944-
unsigned paramIdx = ArgIdx - substConv.getSILArgIndexOfFirstParam();
1945-
if (ReInfo.isParamConverted(paramIdx)) {
1946-
// An argument is converted from indirect to direct. Instead of the
1947-
// address we pass the loaded value.
1948-
auto argConv = substConv.getSILArgumentConvention(ArgIdx);
1949-
SILValue Val;
1950-
if (!argConv.isGuaranteedConvention() || isa<PartialApplyInst>(AI)) {
1951-
Val = Builder.emitLoadValueOperation(Loc, Op.get(),
1952-
LoadOwnershipQualifier::Take);
1953-
} else {
1954-
Val = Builder.emitLoadBorrowOperation(Loc, Op.get());
1955-
if (Val.getOwnershipKind() == ValueOwnershipKind::Guaranteed)
1956-
ArgAtIndexNeedsEndBorrow.push_back(Arguments.size());
1957-
}
1958-
Arguments.push_back(Val);
1959-
return true;
1960-
}
1926+
auto handleConversion = [&](SILValue InputValue) {
1927+
// Rewriting SIL arguments is only for lowered addresses.
1928+
if (!substConv.useLoweredAddresses())
1929+
return false;
1930+
1931+
if (ArgIdx < substConv.getSILArgIndexOfFirstParam()) {
1932+
// Handle result arguments.
1933+
unsigned formalIdx =
1934+
substConv.getIndirectFormalResultIndexForSILArg(ArgIdx);
1935+
if (!ReInfo.isFormalResultConverted(formalIdx)) {
1936+
return false;
19611937
}
1938+
1939+
// The result is converted from indirect to direct. We need to insert
1940+
// a store later.
1941+
assert(!StoreResultTo);
1942+
StoreResultTo = InputValue;
1943+
return true;
1944+
}
1945+
1946+
// Handle arguments for formal parameters.
1947+
unsigned paramIdx = ArgIdx - substConv.getSILArgIndexOfFirstParam();
1948+
if (!ReInfo.isParamConverted(paramIdx)) {
19621949
return false;
1963-
};
1964-
if (!handleConversion())
1965-
Arguments.push_back(Op.get());
1950+
}
1951+
1952+
// An argument is converted from indirect to direct. Instead of the
1953+
// address we pass the loaded value.
1954+
auto argConv = substConv.getSILArgumentConvention(ArgIdx);
1955+
SILValue Val;
1956+
if (!argConv.isGuaranteedConvention() || isa<PartialApplyInst>(AI)) {
1957+
Val = Builder.emitLoadValueOperation(Loc, InputValue,
1958+
LoadOwnershipQualifier::Take);
1959+
} else {
1960+
Val = Builder.emitLoadBorrowOperation(Loc, InputValue);
1961+
if (Val.getOwnershipKind() == ValueOwnershipKind::Guaranteed)
1962+
ArgAtIndexNeedsEndBorrow.push_back(Arguments.size());
1963+
}
1964+
1965+
Arguments.push_back(Val);
1966+
return true;
1967+
};
19661968

1969+
for (auto &Op : AI.getArgumentOperands()) {
1970+
if (!handleConversion(Op.get()))
1971+
Arguments.push_back(Op.get());
19671972
++ArgIdx;
19681973
}
19691974
}

0 commit comments

Comments
 (0)