Skip to content

Commit ba9f520

Browse files
committed
OSSA: simplify-cfg support for trivial block arguments.
Enable most simplify-cfg optimizations as long as the block arguments have trivial types. Enable most simplify CFG unit tests cases. This massively reduces the size of the CFG during OSSA passes. Test cases that aren't supported in OSSA yet have been moved to a separate test file for disabled OSSA tests, Full simplify-cfg support is currently blocked on OSSA utilities which I haven't checked in yet.
1 parent b908b9f commit ba9f520

13 files changed

+4640
-103
lines changed

include/swift/SILOptimizer/Utils/InstOptUtils.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,15 @@ SILValue getConcreteValueOfExistentialBoxAddr(SILValue addr,
273273
/// - a type of the return value is a subclass of the expected return type.
274274
/// - actual return type and expected return type differ in optionality.
275275
/// - both types are tuple-types and some of the elements need to be casted.
276+
///
277+
/// \p usePoints is required when \p value has guaranteed ownership. It must be
278+
/// the last users of the returned, casted value. A usePoint cannot be a
279+
/// BranchInst (a phi is never the last guaranteed user). \p builder's current
280+
/// insertion point must dominate all \p usePoints.
276281
std::pair<SILValue, bool /* changedCFG */>
277282
castValueToABICompatibleType(SILBuilder *builder, SILLocation Loc,
278-
SILValue value, SILType srcTy, SILType destTy);
283+
SILValue value, SILType srcTy, SILType destTy,
284+
ArrayRef<SILInstruction *> usePoints);
279285
/// Peek through trivial Enum initialization, typically for pointless
280286
/// Optionals.
281287
///

lib/SIL/IR/SILFunctionType.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4319,6 +4319,9 @@ TypeConverter::getLoweredFormalTypes(SILDeclRef constant,
43194319
// match exactly.
43204320
// TODO: More sophisticated param and return ABI compatibility rules could
43214321
// diverge.
4322+
//
4323+
// Note: all cases recognized here must be handled in the SILOptimizer's
4324+
// castValueToABICompatibleType().
43224325
static bool areABICompatibleParamsOrReturns(SILType a, SILType b,
43234326
SILFunction *inFunction) {
43244327
// Address parameters are all ABI-compatible, though the referenced

lib/SILGen/SILGenThunk.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
260260
auto flagIndex = convention.completionHandlerFlagParamIndex();
261261

262262
FuncDecl *resumeIntrinsic;
263-
Type replacementTypes[] = {resumeType};
264263

265264
SILBasicBlock *returnBB = nullptr;
266265
if (errorIndex) {

0 commit comments

Comments
 (0)