mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
48 lines
1.7 KiB
C++
48 lines
1.7 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.isAddress()) {
|
|
// If we have an address only type and we are supposed to use
|
|
// lowered addresses, return Owned. Otherwise addresses are any.
|
|
if (type.isAddressOnly(f) && f.getConventions().useLoweredAddresses()) {
|
|
return ValueOwnershipKind::Owned;
|
|
}
|
|
return ValueOwnershipKind::Any;
|
|
}
|
|
|
|
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);
|
|
}
|