Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an empty StringRef as the sentinel instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, yes, but I think std::optional is a better fit, since using operator* on the return value would fail if no value is present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is the kind of failure you are trying to avoid needing to worry about?

}

/// Return true if the callsite is an indirect call.
bool isIndirectCall() const;

Expand Down