Skip to content

Commit 7b0d10e

Browse files
authored
Merge pull request swiftlang#23004 from slavapestov/sil-resilience-expansion-plumbing
Continue plumbing resilience expansion through SIL type lowering
2 parents 4dc4879 + a9841e8 commit 7b0d10e

39 files changed

+276
-236
lines changed

include/swift/SIL/OptimizationRemark.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct Argument {
5050
Argument(StringRef Key, unsigned long long N);
5151

5252
Argument(StringRef Key, SILFunction *F);
53-
Argument(StringRef Key, SILType *Ty);
53+
Argument(StringRef Key, SILType Ty);
54+
Argument(StringRef Key, CanType Ty);
5455
};
5556

5657
/// Shorthand to insert named-value pairs.

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,10 @@ class SILBuilder {
918918
} \
919919
Copy##Name##ValueInst *createCopy##Name##Value(SILLocation Loc, \
920920
SILValue operand) { \
921+
auto type = getFunction().getLoweredType( \
922+
operand->getType().getASTType().getReferenceStorageReferent()); \
921923
return insert(new (getModule()) \
922-
Copy##Name##ValueInst(getSILDebugLocation(Loc), operand, getModule())); \
924+
Copy##Name##ValueInst(getSILDebugLocation(Loc), operand, type)); \
923925
}
924926
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
925927
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...") \

include/swift/SIL/SILFunction.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class SILModule;
3838
class SILFunctionBuilder;
3939
class SILProfiler;
4040

41+
namespace Lowering {
42+
class TypeLowering;
43+
class AbstractionPattern;
44+
}
45+
4146
enum IsBare_t { IsNotBare, IsBare };
4247
enum IsTransparent_t { IsNotTransparent, IsTransparent };
4348
enum Inline_t { InlineDefault, NoInline, AlwaysInline };
@@ -464,6 +469,19 @@ class SILFunction
464469
: ResilienceExpansion::Maximal);
465470
}
466471

472+
const Lowering::TypeLowering &
473+
getTypeLowering(Lowering::AbstractionPattern orig, Type subst);
474+
475+
const Lowering::TypeLowering &getTypeLowering(Type t) const;
476+
477+
SILType getLoweredType(Lowering::AbstractionPattern orig, Type subst) const;
478+
479+
SILType getLoweredType(Type t) const;
480+
481+
SILType getLoweredLoadableType(Type t) const;
482+
483+
const Lowering::TypeLowering &getTypeLowering(SILType type) const;
484+
467485
/// Returns true if this function has a calling convention that has a self
468486
/// argument.
469487
bool hasSelfParam() const {

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,9 +6328,8 @@ class Copy##Name##ValueInst \
63286328
SingleValueInstruction> { \
63296329
friend class SILBuilder; \
63306330
Copy##Name##ValueInst(SILDebugLocation DebugLoc, SILValue operand, \
6331-
SILModule &M) \
6332-
: UnaryInstructionBase(DebugLoc, operand, \
6333-
operand->getType().getReferentType(M)) {} \
6331+
SILType type) \
6332+
: UnaryInstructionBase(DebugLoc, operand, type) {} \
63346333
};
63356334
#include "swift/AST/ReferenceStorage.def"
63366335

include/swift/SIL/SILModule.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,10 @@ class SILModule {
598598

599599
/// Can value operations (copies and destroys) on the given lowered type
600600
/// be performed in this module?
601-
bool isTypeABIAccessible(SILType type);
601+
// FIXME: Expansion
602+
bool isTypeABIAccessible(SILType type,
603+
ResilienceExpansion forExpansion
604+
= ResilienceExpansion::Minimal);
602605

603606
/// Can type metadata for the given formal type be fetched in
604607
/// the given module?

include/swift/SIL/SILType.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,6 @@ class SILType {
477477
/// representation. Class existentials do not always qualify.
478478
bool isHeapObjectReferenceType() const;
479479

480-
/// Return the SILType corresponding to the underlying type of the given
481-
/// metatype type.
482-
///
483-
/// *NOTE* Only call on SILTypes for metatype types.
484-
SILType getMetatypeInstanceType(SILModule& M) const;
485-
486480
/// Returns true if this SILType is an aggregate that contains \p Ty
487481
bool aggregateContainsRecord(SILType Ty, SILModule &SILMod) const;
488482

@@ -501,10 +495,6 @@ class SILType {
501495

502496
/// Returns true if this is the AnyObject SILType;
503497
bool isAnyObject() const { return getASTType()->isAnyObject(); }
504-
505-
/// Returns the underlying referent SILType of an @sil_unowned or @sil_weak
506-
/// Type.
507-
SILType getReferentType(SILModule &M) const;
508498

509499
/// Returns a SILType with any archetypes mapped out of context.
510500
SILType mapTypeOutOfContext() const;

include/swift/SIL/TypeLowering.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,16 @@ class TypeConverter {
769769
ResilienceExpansion::Minimal);
770770

771771
// Returns the lowered SIL type for a Swift type.
772-
SILType getLoweredType(Type t) {
773-
return getTypeLowering(t, ResilienceExpansion::Minimal).getLoweredType();
772+
SILType getLoweredType(Type t, ResilienceExpansion forExpansion
773+
= ResilienceExpansion::Minimal) {
774+
return getTypeLowering(t, forExpansion).getLoweredType();
774775
}
775776

776777
// Returns the lowered SIL type for a Swift type.
777-
SILType getLoweredType(AbstractionPattern origType, Type substType) {
778-
return getTypeLowering(origType, substType, ResilienceExpansion::Minimal)
778+
SILType getLoweredType(AbstractionPattern origType, Type substType,
779+
ResilienceExpansion forExpansion =
780+
ResilienceExpansion::Minimal) {
781+
return getTypeLowering(origType, substType, forExpansion)
779782
.getLoweredType();
780783
}
781784

include/swift/SILOptimizer/Utils/Devirtualize.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Emitter;
4444
/// \p Subs a container to be used for storing the set of subclasses
4545
void getAllSubclasses(ClassHierarchyAnalysis *CHA,
4646
ClassDecl *CD,
47-
SILType ClassType,
47+
CanType ClassType,
4848
SILModule &M,
4949
ClassHierarchyAnalysis::ClassList &Subs);
5050

@@ -69,18 +69,19 @@ ApplySite tryDevirtualizeApply(ApplySite AI,
6969
ClassHierarchyAnalysis *CHA,
7070
OptRemark::Emitter *ORE = nullptr);
7171
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
72-
bool isNominalTypeWithUnboundGenericParameters(SILType Ty, SILModule &M);
73-
bool canDevirtualizeClassMethod(FullApplySite AI, SILType ClassInstanceType,
72+
bool canDevirtualizeClassMethod(FullApplySite AI, ClassDecl *CD,
7473
OptRemark::Emitter *ORE = nullptr,
7574
bool isEffectivelyFinalMethod = false);
76-
SILFunction *getTargetClassMethod(SILModule &M, SILType ClassOrMetatypeType,
75+
SILFunction *getTargetClassMethod(SILModule &M, ClassDecl *CD,
7776
MethodInst *MI);
77+
CanType getSelfInstanceType(CanType ClassOrMetatypeType);
7878

7979
/// Devirtualize the given apply site, which is known to be devirtualizable.
8080
///
8181
/// The caller must call deleteDevirtualizedApply on the original apply site.
8282
FullApplySite devirtualizeClassMethod(FullApplySite AI,
8383
SILValue ClassInstance,
84+
ClassDecl *CD,
8485
OptRemark::Emitter *ORE);
8586

8687
/// Attempt to devirtualize the given apply site, which is known to be
@@ -89,7 +90,9 @@ FullApplySite devirtualizeClassMethod(FullApplySite AI,
8990
/// If this succeeds, the caller must call deleteDevirtualizedApply on
9091
/// the original apply site.
9192
FullApplySite
92-
tryDevirtualizeClassMethod(FullApplySite AI, SILValue ClassInstance,
93+
tryDevirtualizeClassMethod(FullApplySite AI,
94+
SILValue ClassInstance,
95+
ClassDecl *CD,
9396
OptRemark::Emitter *ORE,
9497
bool isEffectivelyFinalMethod = false);
9598

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,6 @@ bool simplifyUsers(SingleValueInstruction *I);
522522
/// without a significant increase to code size.
523523
bool shouldExpand(SILModule &Module, SILType Ty);
524524

525-
/// Check if a given type is a simple type, i.e. a builtin
526-
/// integer or floating point type or a struct/tuple whose members
527-
/// are of simple types.
528-
bool isSimpleType(SILType SILTy, SILModule& Module);
529-
530525
/// Check if the value of V is computed by means of a simple initialization.
531526
/// Store the actual SILValue into \p Val and the reversed list of instructions
532527
/// initializing it in \p Insns.

lib/IRGen/GenType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ llvm::PointerType *IRGenModule::getStoragePointerTypeForLowered(CanType T) {
14561456
}
14571457

14581458
llvm::Type *IRGenModule::getStorageTypeForUnlowered(Type subst) {
1459-
return getStorageType(getSILTypes().getLoweredType(subst));
1459+
return getStorageType(getLoweredType(subst));
14601460
}
14611461

14621462
llvm::Type *IRGenModule::getStorageType(SILType T) {
@@ -1486,7 +1486,7 @@ IRGenModule::getTypeInfoForUnlowered(AbstractionPattern orig, Type subst) {
14861486
/// have yet undergone SIL type lowering.
14871487
const TypeInfo &
14881488
IRGenModule::getTypeInfoForUnlowered(AbstractionPattern orig, CanType subst) {
1489-
return getTypeInfo(getSILTypes().getLoweredType(orig, subst));
1489+
return getTypeInfo(getLoweredType(orig, subst));
14901490
}
14911491

14921492
/// Get the fragile type information for the given type, which is known

0 commit comments

Comments
 (0)