Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)

Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
This commit is contained in:
Akira Hatanaka
2024-06-18 09:06:09 -07:00
committed by GitHub
parent 13bf2ec540
commit d92f181ace
35 changed files with 136 additions and 90 deletions

View File

@@ -4117,7 +4117,9 @@ inline bool isIndirectFormalParameter(ParameterConvention conv) {
}
llvm_unreachable("covered switch isn't covered?!");
}
inline bool isConsumedParameter(ParameterConvention conv) {
template <bool InCallee>
bool isConsumedParameter(ParameterConvention conv) {
switch (conv) {
case ParameterConvention::Indirect_In:
case ParameterConvention::Direct_Owned:
@@ -4136,10 +4138,19 @@ inline bool isConsumedParameter(ParameterConvention conv) {
llvm_unreachable("bad convention kind");
}
inline bool isConsumedParameterInCallee(ParameterConvention conv) {
return isConsumedParameter<true>(conv);
}
inline bool isConsumedParameterInCaller(ParameterConvention conv) {
return isConsumedParameter<false>(conv);
}
/// Returns true if conv is a guaranteed parameter. This may look unnecessary
/// but this will allow code to generalize to handle Indirect_Guaranteed
/// parameters when they are added.
inline bool isGuaranteedParameter(ParameterConvention conv) {
template <bool InCallee>
bool isGuaranteedParameter(ParameterConvention conv) {
switch (conv) {
case ParameterConvention::Direct_Guaranteed:
case ParameterConvention::Indirect_In_Guaranteed:
@@ -4158,6 +4169,14 @@ inline bool isGuaranteedParameter(ParameterConvention conv) {
llvm_unreachable("bad convention kind");
}
inline bool isGuaranteedParameterInCallee(ParameterConvention conv) {
return isGuaranteedParameter<true>(conv);
}
inline bool isGuaranteedParameterInCaller(ParameterConvention conv) {
return isGuaranteedParameter<false>(conv);
}
inline bool isMutatingParameter(ParameterConvention conv) {
switch (conv) {
case ParameterConvention::Indirect_Inout:
@@ -4285,14 +4304,22 @@ public:
/// True if this parameter is consumed by the callee, either
/// indirectly or directly.
bool isConsumed() const {
return isConsumedParameter(getConvention());
bool isConsumedInCallee() const {
return isConsumedParameterInCallee(getConvention());
}
bool isConsumedInCaller() const {
return isConsumedParameterInCaller(getConvention());
}
/// Returns true if this parameter is guaranteed, either indirectly or
/// directly.
bool isGuaranteed() const {
return isGuaranteedParameter(getConvention());
bool isGuaranteedInCallee() const {
return isGuaranteedParameterInCallee(getConvention());
}
bool isGuaranteedInCaller() const {
return isGuaranteedParameterInCaller(getConvention());
}
bool hasOption(Flag flag) const { return options.contains(flag); }