Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 std::optional<StringRef> 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/Analysis/IRSimilarityIdentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void IRInstructionData::setCalleeName(bool MatchByName) {
}

if (!CI->isIndirectCall() && MatchByName)
CalleeName = CI->getCalledFunction()->getName().str();
CalleeName = CI->getCalledFunctionName()->str();
}

void IRInstructionData::setPHIPredecessors(
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/KernelInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void remarkFlatAddrspaceAccess(OptimizationRemarkEmitter &ORE,
R << "in ";
identifyFunction(R, Caller);
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&Inst)) {
R << ", '" << II->getCalledFunction()->getName() << "' call";
R << ", '" << *II->getCalledFunctionName() << "' call";
} else {
R << ", '" << Inst.getOpcodeName() << "' instruction";
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ReplayInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::unique_ptr<InlineAdvice> ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) {

std::string CallSiteLoc =
formatCallSiteLocation(CB.getDebugLoc(), ReplaySettings.ReplayFormat);
StringRef Callee = CB.getCalledFunction()->getName();
StringRef Callee = *CB.getCalledFunctionName();
std::string Combined = (Callee + CallSiteLoc).str();

// Replay decision, if it has one
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4398,7 +4398,7 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
if (CI->getFunctionType() == NewFn->getFunctionType()) {
// Handle generic mangling change.
assert(
(CI->getCalledFunction()->getName() != NewFn->getName()) &&
(CI->getCalledFunctionName().value_or("") != NewFn->getName()) &&
"Unknown function for CallBase upgrade and isn't just a name change");
CI->setCalledFunction(NewFn);
return;
Expand Down
11 changes: 7 additions & 4 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9036,12 +9036,15 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
auto DescribeCallsite =
[&](OptimizationRemarkAnalysis &R) -> OptimizationRemarkAnalysis & {
R << "call from '" << ore::NV("Caller", MF.getName()) << "' to '";
if (auto *ES = dyn_cast<ExternalSymbolSDNode>(CLI.Callee))
if (auto *ES = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
R << ore::NV("Callee", ES->getSymbol());
else if (CLI.CB && CLI.CB->getCalledFunction())
R << ore::NV("Callee", CLI.CB->getCalledFunction()->getName());
else
} else if (CLI.CB) {
const std::optional<StringRef> CalleeName =
CLI.CB->getCalledFunctionName();
R << ore::NV("Callee", CalleeName.value_or("unknown callee"));
} else {
R << "unknown callee";
}
R << "'";
return R;
};
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,9 @@ bool AMDGPULibCalls::fold_sincos(FPMathOperator *FPOp, IRBuilder<> &B,
fInfo);
const std::string PairName = PartnerInfo.mangle();

StringRef SinName = isSin ? CI->getCalledFunction()->getName() : PairName;
StringRef CosName = isSin ? PairName : CI->getCalledFunction()->getName();
const std::optional<StringRef> CalleeName = CI->getCalledFunctionName();
StringRef SinName = isSin ? *CalleeName : PairName;
StringRef CosName = isSin ? PairName : *CalleeName;
const std::string SinCosPrivateName = SinCosLibFuncPrivate.mangle();
const std::string SinCosGenericName = SinCosLibFuncGeneric.mangle();

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,9 +1638,9 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
return;

// collect information about formal parameter types
std::string DemangledName =
getOclOrSpirvBuiltinDemangledName(CI->getCalledFunction()->getName());
Function *CalledF = CI->getCalledFunction();
std::string DemangledName =
getOclOrSpirvBuiltinDemangledName(CalledF->getName());
SmallVector<Type *, 4> CalledArgTys;
bool HaveTypes = false;
for (unsigned OpIdx = 0; OpIdx < CalledF->arg_size(); ++OpIdx) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ std::string ModuleCallsiteContextGraph::getLabel(const Function *Func,
const Instruction *Call,
unsigned CloneNo) const {
return (Twine(Call->getFunction()->getName()) + " -> " +
cast<CallBase>(Call)->getCalledFunction()->getName())
*cast<CallBase>(Call)->getCalledFunctionName())
.str();
}

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5278,12 +5278,12 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall {

CallBase *CB = dyn_cast<CallBase>(&I);
auto Remark = [&](OptimizationRemark OR) {
const std::optional<StringRef> CalleeName = CB->getCalledFunctionName();
if (auto *C = dyn_cast<ConstantInt>(*SimplifiedValue))
return OR << "Replacing OpenMP runtime call "
<< CB->getCalledFunction()->getName() << " with "
<< ore::NV("FoldedValue", C->getZExtValue()) << ".";
return OR << "Replacing OpenMP runtime call "
<< CB->getCalledFunction()->getName() << ".";
return OR << "Replacing OpenMP runtime call " << *CalleeName
<< " with " << ore::NV("FoldedValue", C->getZExtValue())
<< ".";
return OR << "Replacing OpenMP runtime call " << *CalleeName << ".";
};

if (CB && EnableVerboseRemarks)
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,7 @@ void SampleProfileLoader::findExternalInlineCandidate(
// Samples may not exist for replayed function, if so
// just add the direct GUID and move on
if (!Samples) {
InlinedGUIDs.insert(
Function::getGUID(CB->getCalledFunction()->getName()));
InlinedGUIDs.insert(Function::getGUID(*CB->getCalledFunctionName()));
return;
}
// Otherwise, drop the threshold to import everything that we can
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5458,7 +5458,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {

void dumpInst(Instruction &I) {
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
errs() << "ZZZ call " << CI->getCalledFunction()->getName() << "\n";
errs() << "ZZZ call " << *CI->getCalledFunctionName() << "\n";
} else {
errs() << "ZZZ " << I.getOpcodeName() << "\n";
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ struct MemOp {
}
StringRef getFuncName() {
if (auto MI = asMI())
return MI->getCalledFunction()->getName();
return asCI()->getCalledFunction()->getName();
return *MI->getCalledFunctionName();
return *asCI()->getCalledFunctionName();
}
bool isMemmove() {
if (auto MI = asMI())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ class LowerMatrixIntrinsics {
if (!CI->getCalledFunction())
write("<no called fn>");
else {
StringRef Name = CI->getCalledFunction()->getName();
StringRef Name = *CI->getCalledFunctionName();
if (!Name.starts_with("llvm.matrix")) {
write(Name);
return;
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
// bitcast (i32 (...)* @goo to i32 (i32*, ...)*)(i32* nonnull %i)`,
// as such calls make the `isFunctionVectorizable` raise an
// exception.
if (CI.isNoBuiltin() || !CI.getCalledFunction())
if (CI.isNoBuiltin())
return;

StringRef ScalarName = CI.getCalledFunction()->getName();
const std::optional<StringRef> ScalarName = CI.getCalledFunctionName();

// Nothing to be done if the TLI thinks the function is not
// vectorizable.
if (!TLI.isFunctionVectorizable(ScalarName))
if (!ScalarName.has_value() || !TLI.isFunctionVectorizable(*ScalarName))
return;

SmallVector<std::string, 8> Mappings;
VFABI::getVectorVariantNames(CI, Mappings);
Module *M = CI.getModule();
const SetVector<StringRef> OriginalSetOfMappings(Mappings.begin(),
Mappings.end());

auto AddVariantDecl = [&](const ElementCount &VF, bool Predicate) {
const VecDesc *VD = TLI.getVectorMappingInfo(ScalarName, VF, Predicate);
const VecDesc *VD = TLI.getVectorMappingInfo(*ScalarName, VF, Predicate);
if (VD && !VD->getVectorFnName().empty()) {
std::string MangledName = VD->getVectorFunctionABIVariantString();
if (!OriginalSetOfMappings.count(MangledName)) {
Expand All @@ -106,7 +107,7 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {

// All VFs in the TLI are powers of 2.
ElementCount WidestFixedVF, WidestScalableVF;
TLI.getWidestVF(ScalarName, WidestFixedVF, WidestScalableVF);
TLI.getWidestVF(*ScalarName, WidestFixedVF, WidestScalableVF);

for (bool Predicated : {false, true}) {
for (ElementCount VF = ElementCount::getFixed(2);
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");
std::optional<StringRef> 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
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4041,11 +4041,11 @@ Value *LibCallSimplifier::optimizeFloatingPointLibCall(CallInst *CI,
case LibFunc_cos:
case LibFunc_sin:
case LibFunc_tanh:
if (UnsafeFPShrink && hasFloatVersion(M, CI->getCalledFunction()->getName()))
if (UnsafeFPShrink && hasFloatVersion(M, *CI->getCalledFunctionName()))
return optimizeUnaryDoubleFP(CI, Builder, TLI, true);
return nullptr;
case LibFunc_copysign:
if (hasFloatVersion(M, CI->getCalledFunction()->getName()))
if (hasFloatVersion(M, *CI->getCalledFunctionName()))
return optimizeBinaryDoubleFP(CI, Builder, TLI);
return nullptr;
case LibFunc_fdim:
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,10 @@ bool LoopVectorizationLegality::setupOuterLoopInductions() {
/// {"llvm.phx.abs.i32", "", 4}
/// };
static bool isTLIScalarize(const TargetLibraryInfo &TLI, const CallInst &CI) {
const StringRef ScalarName = CI.getCalledFunction()->getName();
const StringRef ScalarName = *CI.getCalledFunctionName();
bool Scalarize = TLI.isFunctionVectorizable(ScalarName);
// Check that all known VFs are not associated to a vector
// function, i.e. the vector name is emty.
// function, i.e. the vector name is empty.
if (Scalarize) {
ElementCount WidestFixedVF, WidestScalableVF;
TLI.getWidestVF(ScalarName, WidestFixedVF, WidestScalableVF);
Expand Down Expand Up @@ -907,11 +907,10 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
// If the call is a recognized math libary call, it is likely that
// we can vectorize it given loosened floating-point constraints.
LibFunc Func;
const std::optional<StringRef> FuncName = CI->getCalledFunctionName();
bool IsMathLibCall =
TLI && CI->getCalledFunction() &&
CI->getType()->isFloatingPointTy() &&
TLI->getLibFunc(CI->getCalledFunction()->getName(), Func) &&
TLI->hasOptimizedCodeGen(Func);
TLI && FuncName.has_value() && CI->getType()->isFloatingPointTy() &&
TLI->getLibFunc(*FuncName, Func) && TLI->hasOptimizedCodeGen(Func);

if (IsMathLibCall) {
// TODO: Ideally, we should not use clang-specific language here,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ void VPReplicateRecipe::print(raw_ostream &O, const Twine &Indent,
if (auto *CB = dyn_cast<CallBase>(getUnderlyingInstr())) {
O << "call";
printFlags(O);
O << "@" << CB->getCalledFunction()->getName() << "(";
O << "@" << *CB->getCalledFunctionName() << "(";
interleaveComma(make_range(op_begin(), op_begin() + (getNumOperands() - 1)),
O, [&O, &SlotTracker](VPValue *Op) {
Op->printAsOperand(O, SlotTracker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NoFooInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
size_t size() override { return DefaultInlineOrder->size(); }
void push(const std::pair<CallBase *, int> &Elt) override {
// We ignore calles named "foo"
if (Elt.first->getCalledFunction()->getName() == "foo") {
if (*Elt.first->getCalledFunctionName() == "foo") {
DefaultInlineOrder->push(Elt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FooOnlyInlineAdvisor : public InlineAdvisor {
: InlineAdvisor(M, FAM, IC) {}

std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override {
if (CB.getCalledFunction()->getName() == "foo")
if (*CB.getCalledFunctionName() == "foo")
return std::make_unique<InlineAdvice>(this, CB, getCallerORE(CB), true);
return std::make_unique<InlineAdvice>(this, CB, getCallerORE(CB), false);
}
Expand Down
Loading