Skip to content

Commit 123fee9

Browse files
authored
Merge pull request swiftlang#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

0 commit comments

Comments
 (0)