Skip to content

Commit a96cc53

Browse files
authored
Merge pull request swiftlang#87301 from gottesmm/pr-fd56e8499232cd2e6686191b9453ad1cda0cbca9
[sil] Add support for ApplySite::getCalleeDeclRef.
2 parents 0deb770 + d2ae104 commit a96cc53

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ class ApplySite {
170170
FOREACH_IMPL_RETURN(getCalleeFunction());
171171
}
172172

173+
/// Gets the referenced function by looking through partial apply,
174+
/// convert_function, and thin to thick function until we find a function_ref.
175+
SILDeclRef getCalleeDeclRef() const {
176+
FOREACH_IMPL_RETURN(getCalleeDeclRef());
177+
}
178+
173179
bool isCalleeDynamicallyReplaceable() const {
174180
FOREACH_IMPL_RETURN(isCalleeDynamicallyReplaceable());
175181
}

include/swift/SIL/SILInstruction.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,18 @@ class ApplyInstBase<Impl, Base, false> : public Base {
28022802
/// issues. It is at the bottom of the file.
28032803
SILFunction *getCalleeFunction() const;
28042804

2805+
/// Returns the SILDeclRef for a referenced function after looking through
2806+
/// partial_apply, convert_function, and thin_to_thick_function.
2807+
///
2808+
/// If we do not find something that we know how to handle, we return an empty
2809+
/// SILDeclRef.
2810+
///
2811+
/// This is based off of getCalleeOrigin.
2812+
///
2813+
/// This is defined out of line to work around incomplete definition
2814+
/// issues. It is next to getCalleeFunction at the bottom of the file.
2815+
SILDeclRef getCalleeDeclRef() const;
2816+
28052817
bool isCalleeDynamicallyReplaceable() const;
28062818

28072819
/// Gets the referenced function if the callee is a function_ref instruction.

lib/SIL/IR/SILInstruction.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,31 @@ SILModule &SILInstructionContext::getModule() {
21792179
return storage.get<SILFunction *>()->getModule();
21802180
}
21812181

2182+
template <class Impl, class Base>
2183+
SILDeclRef ApplyInstBase<Impl, Base, false>::getCalleeDeclRef() const {
2184+
SILValue origin = getCalleeOrigin();
2185+
if (!origin)
2186+
return {};
2187+
2188+
if (auto *fri = dyn_cast<FunctionRefInst>(origin))
2189+
return fri->getReferencedFunction()->getDeclRef();
2190+
2191+
if (auto *m = dyn_cast<MethodInst>(origin))
2192+
return m->getMember();
2193+
2194+
return {};
2195+
}
2196+
2197+
template SILDeclRef
2198+
ApplyInstBase<ApplyInst, SingleValueInstruction, false>::getCalleeDeclRef()
2199+
const;
2200+
template SILDeclRef ApplyInstBase<PartialApplyInst, SingleValueInstruction,
2201+
false>::getCalleeDeclRef() const;
2202+
template SILDeclRef ApplyInstBase<BeginApplyInst, MultipleValueInstruction,
2203+
false>::getCalleeDeclRef() const;
2204+
template SILDeclRef
2205+
ApplyInstBase<TryApplyInst, TryApplyInstBase, false>::getCalleeDeclRef() const;
2206+
21822207
#ifndef NDEBUG
21832208

21842209
//---

0 commit comments

Comments
 (0)