Skip to content

Commit 78c9fe4

Browse files
committed
Add SILFunctionType::isAddressable & ApplySite::isAddressable.
(cherry picked from commit 501abb0)
1 parent da2894b commit 78c9fe4

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

include/swift/AST/LifetimeDependence.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,6 @@ class LifetimeDependenceInfo {
316316
&& scopeLifetimeParamIndices->contains(index);
317317
}
318318

319-
bool checkAddressable(int index) const {
320-
return hasAddressableParamIndices()
321-
&& getAddressableIndices()->contains(index);
322-
}
323-
324319
std::string getString() const;
325320
void Profile(llvm::FoldingSetNodeID &ID) const;
326321
void getConcatenatedData(SmallVectorImpl<bool> &concatenatedData) const;

include/swift/AST/Types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5649,6 +5649,13 @@ class SILFunctionType final
56495649
return getLifetimeDependenceFor(getNumParameters());
56505650
}
56515651

5652+
/// Return true of the specified parameter is addressable based on its type
5653+
/// lowering in 'caller's context. This includes @_addressableForDependencies
5654+
/// parameter types.
5655+
///
5656+
/// Defined in SILType.cpp.
5657+
bool isAddressable(unsigned paramIdx, SILFunction *caller);
5658+
56525659
/// Returns true if the function type stores a Clang type that cannot
56535660
/// be derived from its Swift type. Returns false otherwise, including if
56545661
/// the function type is not @convention(c) or @convention(block).

include/swift/SIL/ApplySite.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ class ApplySite {
641641
return getArgumentParameterInfo(oper).hasOption(SILParameterInfo::Sending);
642642
}
643643

644+
/// Return true if 'operand' is addressable after type substitution in the
645+
/// caller's context.
646+
bool isAddressable(const Operand &operand) const;
647+
644648
static ApplySite getFromOpaqueValue(void *p) { return ApplySite(p); }
645649

646650
friend bool operator==(ApplySite lhs, ApplySite rhs) {

lib/SIL/IR/ApplySite.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ void ApplySite::insertAfterApplication(
4545
llvm_unreachable("covered switch isn't covered");
4646
}
4747

48+
bool ApplySite::isAddressable(const Operand &operand) const {
49+
unsigned calleeArgIndex = getCalleeArgIndex(operand);
50+
assert(calleeArgIndex >= getSubstCalleeConv().getSILArgIndexOfFirstParam());
51+
unsigned paramIdx =
52+
calleeArgIndex - getSubstCalleeConv().getSILArgIndexOfFirstParam();
53+
54+
CanSILFunctionType calleeType = getSubstCalleeType();
55+
return calleeType->isAddressable(paramIdx, getFunction());
56+
}

lib/SIL/IR/SILType.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,29 @@ bool SILFunctionType::isNoReturnFunction(SILModule &M,
706706
return false;
707707
}
708708

709+
bool SILFunctionType::isAddressable(unsigned paramIdx, SILFunction *caller) {
710+
SILParameterInfo paramInfo = getParameters()[paramIdx];
711+
for (auto &depInfo : getLifetimeDependencies()) {
712+
auto *addressableIndices = depInfo.getAddressableIndices();
713+
if (addressableIndices && addressableIndices->contains(paramIdx)) {
714+
return true;
715+
}
716+
auto *condAddressableIndices = depInfo.getConditionallyAddressableIndices();
717+
if (condAddressableIndices && condAddressableIndices->contains(paramIdx)) {
718+
CanType argType = paramInfo.getArgumentType(
719+
caller->getModule(), this, caller->getTypeExpansionContext());
720+
CanType contextType =
721+
argType->hasTypeParameter()
722+
? caller->mapTypeIntoContext(argType)->getCanonicalType()
723+
: argType;
724+
auto &tl = caller->getTypeLowering(contextType);
725+
if (tl.getRecursiveProperties().isAddressableForDependencies())
726+
return true;
727+
}
728+
}
729+
return false;
730+
}
731+
709732
#ifndef NDEBUG
710733
static bool areOnlyAbstractionDifferent(CanType type1, CanType type2) {
711734
assert(type1->isLegalSILType());

0 commit comments

Comments
 (0)