[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions during SIL

inlining, generic/closure specialization, and devirtualization optimization passes.

SILFunction::canBeInlinedIntoCaller now exlicitly requires a caller's SerializedKind_t arg.
isAnySerialized() is added as a convenience function that checks if [serialized] or [serialized_for_pkg].

Resolves rdar://128704752
This commit is contained in:
Ellie Shin
2024-05-23 16:14:15 -07:00
parent 67e9df028e
commit 4ecfc96578
25 changed files with 123 additions and 178 deletions

View File

@@ -874,10 +874,8 @@ public:
void setLinkage(SILLinkage linkage) { Linkage = unsigned(linkage); }
/// Checks if this (callee) function body can be inlined into the caller
/// by comparing their SerializedKind_t values.
/// by comparing their `SerializedKind_t` values.
///
/// If the \p assumeFragileCaller is true, the caller must be serialized,
/// in which case the callee needs to be serialized also to be inlined.
/// If both callee and caller are `not_serialized`, the callee can be inlined
/// into the caller during SIL inlining passes even if it (and the caller)
/// might contain private symbols. If this callee is `serialized_for_pkg`,
@@ -894,21 +892,13 @@ public:
/// ```
///
/// \p callerSerializedKind The caller's SerializedKind.
/// \p assumeFragileCaller True if the call site of this function already
/// knows that the caller is serialized.
bool canBeInlinedIntoCaller(
std::optional<SerializedKind_t> callerSerializedKind = std::nullopt,
bool assumeFragileCaller = true) const;
bool canBeInlinedIntoCaller(SerializedKind_t callerSerializedKind) const;
/// Returns true if this function can be referenced from a fragile function
/// body.
/// \p callerSerializedKind The caller's SerializedKind. Used to be passed to
/// \c canBeInlinedIntoCaller.
/// \p assumeFragileCaller Default to true since this function must be called
// if the caller is [serialized].
bool hasValidLinkageForFragileRef(
std::optional<SerializedKind_t> callerSerializedKind = std::nullopt,
bool assumeFragileCaller = true) const;
bool hasValidLinkageForFragileRef(SerializedKind_t callerSerializedKind) const;
/// Get's the effective linkage which is used to derive the llvm linkage.
/// Usually this is the same as getLinkage(), except in one case: if this
@@ -1165,11 +1155,9 @@ public:
bool isSerialized() const {
return SerializedKind_t(SerializedKind) == IsSerialized;
}
bool isSerializedForPackage() const {
return SerializedKind_t(SerializedKind) == IsSerializedForPackage;
}
bool isNotSerialized() const {
return SerializedKind_t(SerializedKind) == IsNotSerialized;
bool isAnySerialized() const {
return SerializedKind_t(SerializedKind) == IsSerialized ||
SerializedKind_t(SerializedKind) == IsSerializedForPackage;
}
/// Get this function's serialized attribute.