Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 3 additions & 4 deletions llvm/include/llvm/Analysis/VectorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class VFDatabase {
/// a vector Function ABI.
static void getVFABIMappings(const CallInst &CI,
SmallVectorImpl<VFInfo> &Mappings) {
if (!CI.getCalledFunction())
const auto ScalarName = CI.getCalledFunctionName();
if (!ScalarName.has_value())
return;

const StringRef ScalarName = CI.getCalledFunction()->getName();

SmallVector<std::string, 8> ListOfStrings;
// The check for the vector-function-abi-variant attribute is done when
// retrieving the vector variant names here.
Expand All @@ -59,7 +58,7 @@ class VFDatabase {
// ensuring that the variant described in the attribute has a
// corresponding definition or declaration of the vector
// function in the Module M.
if (Shape && (Shape->ScalarName == ScalarName)) {
if (Shape && (Shape->ScalarName == *ScalarName)) {
assert(CI.getModule()->getFunction(Shape->VectorName) &&
"Vector function is missing.");
Mappings.push_back(*Shape);
Expand Down
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
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ static void trackInlinedStores(Function::iterator Start, Function::iterator End,
const CallBase &CB) {
LLVM_DEBUG(errs() << "trackInlinedStores into "
<< Start->getParent()->getName() << " from "
<< CB.getCalledFunction()->getName() << "\n");
<< *CB.getCalledFunctionName() << "\n");
const DataLayout &DL = CB.getDataLayout();
at::trackAssignments(Start, End, collectEscapedLocals(DL, CB), DL);
}
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ class LibCallsShrinkWrap : public InstVisitor<LibCallsShrinkWrap> {
bool perform() {
bool Changed = false;
for (auto &CI : WorkList) {
LLVM_DEBUG(dbgs() << "CDCE calls: " << CI->getCalledFunction()->getName()
<< "\n");
auto CalleeName = CI->getCalledFunctionName();
assert(CalleeName.has_value() &&
"perform() should apply to a non-empty callee");

LLVM_DEBUG(dbgs() << "CDCE calls: " << *CalleeName << "\n");
if (perform(CI)) {
Changed = true;
LLVM_DEBUG(dbgs() << "Transformed\n");
Expand Down Expand Up @@ -487,7 +490,6 @@ void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
bool LibCallsShrinkWrap::perform(CallInst *CI) {
LibFunc Func;
Function *Callee = CI->getCalledFunction();
assert(Callee && "perform() should apply to a non-empty callee");
TLI.getLibFunc(*Callee, Func);
assert(Func && "perform() is not expecting an empty function");

Expand Down