[llvm] Add CallBase::getCalledFunctionName (PR #127038)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 16 06:26:19 PST 2025


================
@@ -1345,6 +1345,16 @@ class CallBase : public Instruction {
     return nullptr;
   }
 
+  /// Shortcut to retrieving the name of the called function.
+  /// Returns std::nullopt, if the function cannot be found.
+  std::optional<StringRef> getCalledFunctionName() const {
+    Function *F = getCalledFunction();
+    if (F)
+      return F->getName();
+
+    return std::nullopt;
----------------
nikic wrote:

Can we use an empty StringRef as the sentinel instead?

https://github.com/llvm/llvm-project/pull/127038


More information about the llvm-commits mailing list