Files
swift-mirror/lib/SIL/SILUndef.cpp
Slava Pestov c791c4a137 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.
2019-03-12 00:30:35 -04:00

38 lines
1.4 KiB
C++

//===--- SILUndef.cpp -----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILUndef.h"
#include "swift/SIL/SILModule.h"
using namespace swift;
static ValueOwnershipKind getOwnershipKindForUndef(SILType type, const SILFunction &f) {
if (type.isTrivial(f))
return ValueOwnershipKind::Any;
return ValueOwnershipKind::Owned;
}
SILUndef::SILUndef(SILType type, ValueOwnershipKind ownershipKind)
: ValueBase(ValueKind::SILUndef, type, IsRepresentative::Yes),
ownershipKind(ownershipKind) {}
SILUndef *SILUndef::get(SILType ty, SILModule &m, ValueOwnershipKind ownershipKind) {
SILUndef *&entry = m.UndefValues[std::make_pair(ty, unsigned(ownershipKind))];
if (entry == nullptr)
entry = new (m) SILUndef(ty, ownershipKind);
return entry;
}
SILUndef *SILUndef::get(SILType ty, const SILFunction &f) {
auto ownershipKind = getOwnershipKindForUndef(ty, f);
return SILUndef::get(ty, f.getModule(), ownershipKind);
}