Skip to content

Commit 8915f96

Browse files
committed
SIL: Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction)
1 parent 00b4662 commit 8915f96

Some content is hidden

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

61 files changed

+231
-222
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/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;
@@ -7715,7 +7715,8 @@ class DestructureStructInst final
77157715
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}
77167716

77177717
public:
7718-
static DestructureStructInst *create(SILModule &M, SILDebugLocation Loc,
7718+
static DestructureStructInst *create(const SILFunction &F,
7719+
SILDebugLocation Loc,
77197720
SILValue Operand);
77207721
static bool classof(const SILNode *N) {
77217722
return N->getKind() == SILNodeKind::DestructureStructInst;
@@ -7763,7 +7764,8 @@ class DestructureTupleInst final
77637764
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}
77647765

77657766
public:
7766-
static DestructureTupleInst *create(SILModule &M, SILDebugLocation Loc,
7767+
static DestructureTupleInst *create(const SILFunction &F,
7768+
SILDebugLocation Loc,
77677769
SILValue Operand);
77687770
static bool classof(const SILNode *N) {
77697771
return N->getKind() == SILNodeKind::DestructureTupleInst;

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/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/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

lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ static StoreOwnershipQualifier
10391039
getStoreInitOwnership(StructLoweringState &pass, SILType type) {
10401040
if (!pass.F->hasOwnership()) {
10411041
return StoreOwnershipQualifier::Unqualified;
1042-
} else if (type.isTrivial(pass.F->getModule())) {
1042+
} else if (type.isTrivial(*pass.F)) {
10431043
return StoreOwnershipQualifier::Trivial;
10441044
} else {
10451045
return StoreOwnershipQualifier::Init;
@@ -2475,7 +2475,7 @@ void LoadableByAddress::recreateSingleApply(
24752475
LoadOwnershipQualifier ownership;
24762476
if (!F->hasOwnership()) {
24772477
ownership = LoadOwnershipQualifier::Unqualified;
2478-
} else if (newValue->getType().isTrivial(*getModule())) {
2478+
} else if (newValue->getType().isTrivial(*F)) {
24792479
ownership = LoadOwnershipQualifier::Trivial;
24802480
} else {
24812481
assert(oldYields[i].isConsumed() &&

0 commit comments

Comments
 (0)