Skip to content

Commit 123fee9

Browse files
authored
Merge pull request #23228 from slavapestov/type-lowering-is-trivial
Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction)
2 parents 7302b6f + 568816a commit 123fee9

File tree

103 files changed

+496
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+496
-429
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,8 +3538,7 @@ class SILResultInfo {
35383538
}
35393539

35403540
ValueOwnershipKind
3541-
getOwnershipKind(SILModule &,
3542-
CanGenericSignature sig) const; // in SILType.cpp
3541+
getOwnershipKind(SILFunction &) const; // in SILType.cpp
35433542

35443543
bool operator==(SILResultInfo rhs) const {
35453544
return TypeAndConvention == rhs.TypeAndConvention;

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ LinearLifetimeError valueHasLinearLifetime(
147147
SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr);
148148

149149
/// Returns true if v is an address or trivial.
150-
bool isValueAddressOrTrivial(SILValue v, SILModule &m);
150+
bool isValueAddressOrTrivial(SILValue v);
151151

152152
/// These operations forward both owned and guaranteed ownership.
153153
bool isOwnershipForwardingValueKind(SILNodeKind kind);

include/swift/SIL/Projection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class ProjectionPath {
602602

603603
/// Return true if the given projection paths in \p CPaths does not cover
604604
/// all the fields with non-trivial semantics, false otherwise.
605-
static bool hasUncoveredNonTrivials(SILType B, SILModule *Mod,
605+
static bool hasUncoveredNonTrivials(SILType B, const SILFunction &F,
606606
ProjectionPathSet &CPaths);
607607

608608
/// Returns true if the two paths have a non-empty symmetric

include/swift/SIL/SILBuilder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class SILBuilder {
671671
return createLoad(Loc, LV, LoadOwnershipQualifier::Unqualified);
672672
}
673673

674-
if (LV->getType().isTrivial(getModule())) {
674+
if (LV->getType().isTrivial(getFunction())) {
675675
return createLoad(Loc, LV, LoadOwnershipQualifier::Trivial);
676676
}
677677
return createLoad(Loc, LV, Qualifier);
@@ -764,7 +764,7 @@ class SILBuilder {
764764
return createStore(Loc, Src, DestAddr,
765765
StoreOwnershipQualifier::Unqualified);
766766
}
767-
if (Src->getType().isTrivial(getModule())) {
767+
if (Src->getType().isTrivial(getFunction())) {
768768
return createStore(Loc, Src, DestAddr, StoreOwnershipQualifier::Trivial);
769769
}
770770
return createStore(Loc, Src, DestAddr, Qualifier);
@@ -1095,7 +1095,7 @@ class SILBuilder {
10951095
}
10961096

10971097
CopyValueInst *createCopyValue(SILLocation Loc, SILValue operand) {
1098-
assert(!operand->getType().isTrivial(getModule()) &&
1098+
assert(!operand->getType().isTrivial(getFunction()) &&
10991099
"Should not be passing trivial values to this api. Use instead "
11001100
"emitCopyValueOperation");
11011101
return insert(new (getModule())
@@ -1104,7 +1104,7 @@ class SILBuilder {
11041104

11051105
DestroyValueInst *createDestroyValue(SILLocation Loc, SILValue operand) {
11061106
assert(isLoadableOrOpaque(operand->getType()));
1107-
assert(!operand->getType().isTrivial(getModule()) &&
1107+
assert(!operand->getType().isTrivial(getFunction()) &&
11081108
"Should not be passing trivial values to this api. Use instead "
11091109
"emitDestroyValueOperation");
11101110
return insert(new (getModule())
@@ -1398,13 +1398,13 @@ class SILBuilder {
13981398
DestructureStructInst *createDestructureStruct(SILLocation Loc,
13991399
SILValue Operand) {
14001400
return insert(DestructureStructInst::create(
1401-
getModule(), getSILDebugLocation(Loc), Operand));
1401+
getFunction(), getSILDebugLocation(Loc), Operand));
14021402
}
14031403

14041404
DestructureTupleInst *createDestructureTuple(SILLocation Loc,
14051405
SILValue Operand) {
14061406
return insert(DestructureTupleInst::create(
1407-
getModule(), getSILDebugLocation(Loc), Operand));
1407+
getFunction(), getSILDebugLocation(Loc), Operand));
14081408
}
14091409

14101410
MultipleValueInstruction *emitDestructureValueOperation(SILLocation loc,

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ SILCloner<ImplClass>::getMappedValue(SILValue Value) {
526526
if (auto *U = dyn_cast<SILUndef>(Value)) {
527527
auto type = getOpType(U->getType());
528528
ValueBase *undef =
529-
(type == U->getType() ? U : SILUndef::get(type, Builder.getModule()));
529+
(type == U->getType() ? U : SILUndef::get(type, Builder.getFunction()));
530530
return SILValue(undef);
531531
}
532532

include/swift/SIL/SILInstruction.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4700,14 +4700,14 @@ class StructInst final : public InstructionBaseWithTrailingOperands<
47004700
/// Search the operands of this struct for a unique non-trivial field. If we
47014701
/// find it, return it. Otherwise return SILValue().
47024702
SILValue getUniqueNonTrivialFieldValue() {
4703-
SILModule &Mod = getModule();
4703+
auto *F = getFunction();
47044704
ArrayRef<Operand> Ops = getAllOperands();
47054705

47064706
Optional<unsigned> Index;
47074707
// For each operand...
47084708
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
47094709
// If the operand is not trivial...
4710-
if (!Ops[i].get()->getType().isTrivial(Mod)) {
4710+
if (!Ops[i].get()->getType().isTrivial(*F)) {
47114711
// And we have not found an Index yet, set index to i and continue.
47124712
if (!Index.hasValue()) {
47134713
Index = i;
@@ -4993,14 +4993,14 @@ class TupleInst final : public InstructionBaseWithTrailingOperands<
49934993
/// Search the operands of this tuple for a unique non-trivial elt. If we find
49944994
/// it, return it. Otherwise return SILValue().
49954995
SILValue getUniqueNonTrivialElt() {
4996-
SILModule &Mod = getModule();
4996+
auto *F = getFunction();
49974997
ArrayRef<Operand> Ops = getAllOperands();
49984998

49994999
Optional<unsigned> Index;
50005000
// For each operand...
50015001
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
50025002
// If the operand is not trivial...
5003-
if (!Ops[i].get()->getType().isTrivial(Mod)) {
5003+
if (!Ops[i].get()->getType().isTrivial(*F)) {
50045004
// And we have not found an Index yet, set index to i and continue.
50055005
if (!Index.hasValue()) {
50065006
Index = i;
@@ -7724,7 +7724,8 @@ class DestructureStructInst final
77247724
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}
77257725

77267726
public:
7727-
static DestructureStructInst *create(SILModule &M, SILDebugLocation Loc,
7727+
static DestructureStructInst *create(const SILFunction &F,
7728+
SILDebugLocation Loc,
77287729
SILValue Operand);
77297730
static bool classof(const SILNode *N) {
77307731
return N->getKind() == SILNodeKind::DestructureStructInst;
@@ -7772,7 +7773,8 @@ class DestructureTupleInst final
77727773
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}
77737774

77747775
public:
7775-
static DestructureTupleInst *create(SILModule &M, SILDebugLocation Loc,
7776+
static DestructureTupleInst *create(const SILFunction &F,
7777+
SILDebugLocation Loc,
77767778
SILValue Operand);
77777779
static bool classof(const SILNode *N) {
77787780
return N->getKind() == SILNodeKind::DestructureTupleInst;

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class SILModule {
221221
llvm::DenseMap<Identifier, BuiltinInfo> BuiltinIDCache;
222222

223223
/// This is the set of undef values we've created, for uniquing purposes.
224-
llvm::DenseMap<SILType, SILUndef *> UndefValues;
224+
llvm::DenseMap<std::pair<SILType, unsigned>, SILUndef *> UndefValues;
225225

226226
/// The stage of processing this module is at.
227227
SILStage Stage;

include/swift/SIL/SILType.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,8 @@ class SILType {
284284
/// \p F into account (see isLoadable(SILFunction)).
285285
bool isAddressOnly(const SILFunction &F) const;
286286

287-
/// True if the type, or the referenced type of an address type, is trivial.
288-
bool isTrivial(SILModule &M) const;
289-
290-
/// Like isTrivial(SILModule), but takes the resilience expansion of
291-
/// \p F into account (see isLoadable(SILFunction)).
287+
/// True if the type, or the referenced type of an address type, is trivial,
288+
/// meaning it is loadable and can be trivially copied, moved or detroyed.
292289
bool isTrivial(const SILFunction &F) const;
293290

294291
/// True if the type, or the referenced type of an address type, is known to

include/swift/SIL/SILUndef.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ class SILModule;
2525
class SILUndef : public ValueBase {
2626
ValueOwnershipKind ownershipKind;
2727

28-
SILUndef(SILType type, SILModule &m);
28+
SILUndef(SILType type, ValueOwnershipKind ownershipKind);
2929

3030
public:
3131
void operator=(const SILArgument &) = delete;
3232
void operator delete(void *, size_t) SWIFT_DELETE_OPERATOR_DELETED;
3333

34-
static SILUndef *get(SILType ty, SILModule &m);
35-
static SILUndef *get(SILType ty, SILModule *m) { return get(ty, *m); }
34+
static SILUndef *get(SILType ty, SILModule &m, ValueOwnershipKind ownershipKind);
35+
static SILUndef *get(SILType ty, const SILFunction &f);
3636

3737
template <class OwnerTy>
38-
static SILUndef *getSentinelValue(SILType type, SILModule &m, OwnerTy owner) {
39-
return new (*owner) SILUndef(type, m);
38+
static SILUndef *getSentinelValue(SILType type, OwnerTy owner) {
39+
// Ownership kind isn't used here, the value just needs to have a unique
40+
// address.
41+
return new (*owner) SILUndef(type, ValueOwnershipKind::Any);
4042
}
4143

4244
ValueOwnershipKind getOwnershipKind() const { return ownershipKind; }

include/swift/SIL/SILValue.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct ValueOwnershipKind {
137137

138138
ValueOwnershipKind(innerty NewValue) : Value(NewValue) {}
139139
explicit ValueOwnershipKind(unsigned NewValue) : Value(innerty(NewValue)) {}
140-
ValueOwnershipKind(SILModule &M, SILType Type,
140+
ValueOwnershipKind(const SILFunction &F, SILType Type,
141141
SILArgumentConvention Convention);
142142

143143
/// Parse Value into a ValueOwnershipKind.
@@ -157,7 +157,7 @@ struct ValueOwnershipKind {
157157
/// ownership kind, and a subobject of type Proj is being projected from the
158158
/// aggregate, return Trivial if Proj has trivial type and the aggregate's
159159
/// ownership kind otherwise.
160-
ValueOwnershipKind getProjectedOwnershipKind(SILModule &M,
160+
ValueOwnershipKind getProjectedOwnershipKind(const SILFunction &F,
161161
SILType Proj) const;
162162

163163
/// Return the lifetime constraint semantics for this
@@ -374,8 +374,7 @@ class SILValue {
374374
ValueOwnershipKind getOwnershipKind() const;
375375

376376
/// Verify that this SILValue and its uses respects ownership invariants.
377-
void verifyOwnership(SILModule &Mod,
378-
DeadEndBlocks *DEBlocks = nullptr) const;
377+
void verifyOwnership(DeadEndBlocks *DEBlocks = nullptr) const;
379378
};
380379

381380
/// A map from a ValueOwnershipKind that an operand can accept to a

include/swift/SIL/TypeSubstCloner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
267267
void visitCopyValueInst(CopyValueInst *Copy) {
268268
// If the substituted type is trivial, ignore the copy.
269269
SILType copyTy = getOpType(Copy->getType());
270-
if (copyTy.isTrivial(Copy->getModule())) {
270+
if (copyTy.isTrivial(*Copy->getFunction())) {
271271
recordFoldedValue(SILValue(Copy), getOpValue(Copy->getOperand()));
272272
return;
273273
}
@@ -277,7 +277,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
277277
void visitDestroyValueInst(DestroyValueInst *Destroy) {
278278
// If the substituted type is trivial, ignore the destroy.
279279
SILType destroyTy = getOpType(Destroy->getOperand()->getType());
280-
if (destroyTy.isTrivial(Destroy->getModule())) {
280+
if (destroyTy.isTrivial(*Destroy->getFunction())) {
281281
return;
282282
}
283283
super::visitDestroyValueInst(Destroy);

include/swift/SILOptimizer/Utils/GenericCloner.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ class GenericCloner
4949

5050
GenericCloner(SILOptFunctionBuilder &FuncBuilder,
5151
SILFunction *F,
52-
IsSerialized_t Serialized,
5352
const ReabstractionInfo &ReInfo,
5453
SubstitutionMap ParamSubs,
5554
StringRef NewName,
5655
CloneCollector::CallbackType Callback)
57-
: SuperTy(*initCloned(FuncBuilder, F, Serialized, ReInfo, NewName), *F,
56+
: SuperTy(*initCloned(FuncBuilder, F, ReInfo, NewName), *F,
5857
ParamSubs), FuncBuilder(FuncBuilder), ReInfo(ReInfo), Callback(Callback) {
5958
assert(F->getDebugScope()->Parent != getCloned()->getDebugScope()->Parent);
6059
}
@@ -64,13 +63,12 @@ class GenericCloner
6463
static SILFunction *
6564
cloneFunction(SILOptFunctionBuilder &FuncBuilder,
6665
SILFunction *F,
67-
IsSerialized_t Serialized,
6866
const ReabstractionInfo &ReInfo,
6967
SubstitutionMap ParamSubs,
7068
StringRef NewName,
7169
CloneCollector::CallbackType Callback =nullptr) {
7270
// Clone and specialize the function.
73-
GenericCloner SC(FuncBuilder, F, Serialized, ReInfo, ParamSubs,
71+
GenericCloner SC(FuncBuilder, F, ReInfo, ParamSubs,
7472
NewName, Callback);
7573
SC.populateCloned();
7674
return SC.getCloned();
@@ -96,7 +94,6 @@ class GenericCloner
9694
private:
9795
static SILFunction *initCloned(SILOptFunctionBuilder &FuncBuilder,
9896
SILFunction *Orig,
99-
IsSerialized_t Serialized,
10097
const ReabstractionInfo &ReInfo,
10198
StringRef NewName);
10299
/// Clone the body of the function into the empty function that was created

include/swift/SILOptimizer/Utils/Generics.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class ReabstractionInfo {
114114
// It uses interface types.
115115
SubstitutionMap CallerInterfaceSubs;
116116

117+
// Is the generated specialization going to be serialized?
118+
IsSerialized_t Serialized;
119+
117120
// Create a new substituted type with the updated signature.
118121
CanSILFunctionType createSubstitutedType(SILFunction *OrigF,
119122
SubstitutionMap SubstMap,
@@ -139,6 +142,7 @@ class ReabstractionInfo {
139142
/// invalid type.
140143
ReabstractionInfo(ApplySite Apply, SILFunction *Callee,
141144
SubstitutionMap ParamSubs,
145+
IsSerialized_t Serialized,
142146
bool ConvertIndirectToDirect = true,
143147
OptRemark::Emitter *ORE = nullptr);
144148

@@ -147,6 +151,10 @@ class ReabstractionInfo {
147151
/// conformances or same concrete type requirements.
148152
ReabstractionInfo(SILFunction *Callee, ArrayRef<Requirement> Requirements);
149153

154+
IsSerialized_t isSerialized() const {
155+
return Serialized;
156+
}
157+
150158
/// Returns true if the \p ParamIdx'th (non-result) formal parameter is
151159
/// converted from indirect to direct.
152160
bool isParamConverted(unsigned ParamIdx) const {
@@ -263,7 +271,6 @@ class GenericFuncSpecializer {
263271
SILModule &M;
264272
SILFunction *GenericFunc;
265273
SubstitutionMap ParamSubs;
266-
IsSerialized_t Serialized;
267274
const ReabstractionInfo &ReInfo;
268275

269276
SubstitutionMap ContextSubs;
@@ -273,7 +280,6 @@ class GenericFuncSpecializer {
273280
GenericFuncSpecializer(SILOptFunctionBuilder &FuncBuilder,
274281
SILFunction *GenericFunc,
275282
SubstitutionMap ParamSubs,
276-
IsSerialized_t Serialized,
277283
const ReabstractionInfo &ReInfo);
278284

279285
/// If we already have this specialization, reuse it.

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,20 +551,20 @@ bool calleesAreStaticallyKnowable(SILModule &M, SILDeclRef Decl);
551551
// can be derived e.g.:
552552
// - from a constructor or
553553
// - from a successful outcome of a checked_cast_br [exact] instruction.
554-
SILValue getInstanceWithExactDynamicType(SILValue S, SILModule &M,
554+
SILValue getInstanceWithExactDynamicType(SILValue S,
555555
ClassHierarchyAnalysis *CHA);
556556

557557
/// Try to determine the exact dynamic type of an object.
558558
/// returns the exact dynamic type of the object, or an empty type if the exact
559559
/// type could not be determined.
560-
SILType getExactDynamicType(SILValue S, SILModule &M,
560+
SILType getExactDynamicType(SILValue S,
561561
ClassHierarchyAnalysis *CHA,
562562
bool ForUnderlyingObject = false);
563563

564564
/// Try to statically determine the exact dynamic type of the underlying object.
565565
/// returns the exact dynamic type of the underlying object, or an empty SILType
566566
/// if the exact type could not be determined.
567-
SILType getExactDynamicTypeOfUnderlyingObject(SILValue S, SILModule &M,
567+
SILType getExactDynamicTypeOfUnderlyingObject(SILValue S,
568568
ClassHierarchyAnalysis *CHA);
569569

570570
/// Utility class for cloning init values into the static initializer of a

include/swift/SILOptimizer/Utils/SILSSAUpdater.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ class SILSSAUpdater {
5151
// If not null updated with inserted 'phi' nodes (SILArgument).
5252
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs;
5353

54-
SILModule &M;
55-
5654
// Not copyable.
5755
void operator=(const SILSSAUpdater &) = delete;
5856
SILSSAUpdater(const SILSSAUpdater &) = delete;
5957

6058
public:
6159
explicit SILSSAUpdater(
62-
SILModule &M,
6360
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs = nullptr);
6461
~SILSSAUpdater();
6562

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 476; // Last change: prebuilt module cache
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 477; // SILUndef serialized with ownership kind
5656

5757
using DeclIDField = BCFixed<31>;
5858

lib/IRGen/GenOpaque.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/IRGenOptions.h"
2727
#include "swift/ABI/MetadataValues.h"
2828
#include "swift/IRGen/ValueWitness.h"
29+
#include "swift/SIL/TypeLowering.h"
2930

3031
#include "Callee.h"
3132
#include "Explosion.h"
@@ -719,7 +720,7 @@ void irgen::emitDestroyArrayCall(IRGenFunction &IGF,
719720
Address object,
720721
llvm::Value *count) {
721722
// If T is a trivial/POD type, nothing needs to be done.
722-
if (T.getObjectType().isTrivial(IGF.getSILModule()))
723+
if (IGF.IGM.getTypeLowering(T).isTrivial())
723724
return;
724725

725726
auto metadata = IGF.emitTypeMetadataRefForLayout(T);
@@ -994,7 +995,7 @@ void irgen::emitDestroyCall(IRGenFunction &IGF,
994995
SILType T,
995996
Address object) {
996997
// If T is a trivial/POD type, nothing needs to be done.
997-
if (T.getObjectType().isTrivial(IGF.getSILModule()))
998+
if (IGF.IGM.getTypeLowering(T).isTrivial())
998999
return;
9991000
llvm::Value *metadata;
10001001
auto fn = IGF.emitValueWitnessFunctionRef(T, metadata,

0 commit comments

Comments
 (0)