Skip to content

Commit c791c4a

Browse files
committed
SIL: SILUndef must be aware of the resilience expansion
The ownership kind is Any for trivial types, or Owned otherwise, but whether a type is trivial or not will soon depend on the resilience expansion. This means that a SILModule now uniques two SILUndefs per type instead of one, and serialization uses two distinct sentinel IDs for this purpose as well. For now, the resilience expansion is not actually used here, so this change is NFC, other than changing the module format.
1 parent 18f2d92 commit c791c4a

Some content is hidden

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

43 files changed

+129
-121
lines changed

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/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/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/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/LoadableByAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ void LoadableStorageAllocation::allocateLoadableStorage() {
13171317
SILArgument *LoadableStorageAllocation::replaceArgType(SILBuilder &argBuilder,
13181318
SILArgument *arg,
13191319
SILType newSILType) {
1320-
SILValue undef = SILUndef::get(newSILType, pass.F->getModule());
1320+
SILValue undef = SILUndef::get(newSILType, *pass.F);
13211321
SmallVector<Operand *, 8> useList(arg->use_begin(), arg->use_end());
13221322
for (auto *use : useList) {
13231323
use->set(undef);
@@ -1387,7 +1387,7 @@ void LoadableStorageAllocation::convertIndirectFunctionArgs() {
13871387

13881388
static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
13891389
SILArgument *arg) {
1390-
SILValue undef = SILUndef::get(newSILType, argBuilder.getModule());
1390+
SILValue undef = SILUndef::get(newSILType, argBuilder.getFunction());
13911391
SmallVector<Operand *, 8> useList(arg->use_begin(), arg->use_end());
13921392
for (auto *use : useList) {
13931393
use->set(undef);

lib/ParseSIL/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ bool SILParser::parseGlobalName(Identifier &Name) {
738738
SILValue SILParser::getLocalValue(UnresolvedValueName Name, SILType Type,
739739
SILLocation Loc, SILBuilder &B) {
740740
if (Name.isUndef())
741-
return SILUndef::get(Type, &SILMod);
741+
return SILUndef::get(Type, B.getFunction());
742742

743743
// Check to see if this is already defined.
744744
ValueBase *&Entry = LocalValues[Name.Name];

lib/SIL/Projection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ ProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
11531153
if (Iter != LeafValues.end())
11541154
return Iter->second;
11551155
// Return undef for dead node.
1156-
return SILUndef::get(Node->getType(), Mod);
1156+
return SILUndef::get(Node->getType(), Builder.getFunction());
11571157
}
11581158

11591159
// This is an aggregate node, construct its value from its children

lib/SIL/SILUndef.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@
1515

1616
using namespace swift;
1717

18-
static ValueOwnershipKind getOwnershipKindForUndef(SILType type, SILModule &m) {
19-
if (type.isTrivial(m))
18+
static ValueOwnershipKind getOwnershipKindForUndef(SILType type, const SILFunction &f) {
19+
if (type.isTrivial(f))
2020
return ValueOwnershipKind::Any;
2121
return ValueOwnershipKind::Owned;
2222
}
2323

24-
SILUndef::SILUndef(SILType type, SILModule &m)
24+
SILUndef::SILUndef(SILType type, ValueOwnershipKind ownershipKind)
2525
: ValueBase(ValueKind::SILUndef, type, IsRepresentative::Yes),
26-
ownershipKind(getOwnershipKindForUndef(type, m)) {}
26+
ownershipKind(ownershipKind) {}
2727

28-
SILUndef *SILUndef::get(SILType ty, SILModule &m) {
29-
// Unique these.
30-
SILUndef *&entry = m.UndefValues[ty];
28+
SILUndef *SILUndef::get(SILType ty, SILModule &m, ValueOwnershipKind ownershipKind) {
29+
SILUndef *&entry = m.UndefValues[std::make_pair(ty, unsigned(ownershipKind))];
3130
if (entry == nullptr)
32-
entry = new (m) SILUndef(ty, m);
31+
entry = new (m) SILUndef(ty, ownershipKind);
3332
return entry;
3433
}
34+
35+
SILUndef *SILUndef::get(SILType ty, const SILFunction &f) {
36+
auto ownershipKind = getOwnershipKindForUndef(ty, f);
37+
return SILUndef::get(ty, f.getModule(), ownershipKind);
38+
}

lib/SIL/SILValue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ void ValueBase::replaceAllUsesWith(ValueBase *RHS) {
5353
}
5454

5555
void ValueBase::replaceAllUsesWithUndef() {
56-
SILModule *Mod = getModule();
57-
if (!Mod) {
56+
auto *F = getFunction();
57+
if (!F) {
5858
llvm_unreachable("replaceAllUsesWithUndef can only be used on ValueBase "
59-
"that have access to the parent module.");
59+
"that have access to the parent function.");
6060
}
6161
while (!use_empty()) {
6262
Operand *Op = *use_begin();
63-
Op->set(SILUndef::get(Op->get()->getType(), Mod));
63+
Op->set(SILUndef::get(Op->get()->getType(), *F));
6464
}
6565
}
6666

0 commit comments

Comments
 (0)