From cb30e322150270ba30e1d22ab34f32eeb4176c17 Mon Sep 17 00:00:00 2001 From: Jonas Paulsson Date: Wed, 12 Mar 2025 12:28:01 -0600 Subject: [PATCH] [SystemZ] Use Function::hasAddressTaken() with verifyNarrowIntegerArgs() (NFC). Use hasAddressTaken() in SystemZ instead of doing this computation in isFullyInternal(), and make sure to only do this once per Function. --- .../Target/SystemZ/SystemZISelLowering.cpp | 39 ++++++++----------- llvm/lib/Target/SystemZ/SystemZISelLowering.h | 10 +++-- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp index 1e0c303a2e4da..8e61e6bcda57e 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -10200,22 +10200,6 @@ SDValue SystemZTargetLowering::lowerVECREDUCE_ADD(SDValue Op, DAG.getConstant(OpVT.getVectorNumElements() - 1, DL, MVT::i32)); } -// Only consider a function fully internal as long as it has local linkage -// and is not used in any other way than acting as the called function at -// call sites. -bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const { - if (!Fn->hasLocalLinkage()) - return false; - for (const User *U : Fn->users()) { - if (auto *CB = dyn_cast(U)) { - if (CB->getCalledFunction() != Fn) - return false; - } else - return false; - } - return true; -} - static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) { FunctionType *FT = F->getFunctionType(); const AttributeList &Attrs = F->getAttributes(); @@ -10234,6 +10218,16 @@ static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) { OS << ")\n"; } +bool SystemZTargetLowering::isInternal(const Function *Fn) const { + std::map::iterator Itr = IsInternalCache.find(Fn); + if (Itr == IsInternalCache.end()) + Itr = IsInternalCache + .insert(std::pair( + Fn, (Fn->hasLocalLinkage() && !Fn->hasAddressTaken()))) + .first; + return Itr->second; +} + void SystemZTargetLowering:: verifyNarrowIntegerArgs_Call(const SmallVectorImpl &Outs, const Function *F, SDValue Callee) const { @@ -10246,8 +10240,8 @@ verifyNarrowIntegerArgs_Call(const SmallVectorImpl &Outs, const Function *CalleeFn = nullptr; if (auto *G = dyn_cast(Callee)) if ((CalleeFn = dyn_cast(G->getGlobal()))) - IsInternal = isFullyInternal(CalleeFn); - if (!verifyNarrowIntegerArgs(Outs, IsInternal)) { + IsInternal = isInternal(CalleeFn); + if (!IsInternal && !verifyNarrowIntegerArgs(Outs)) { errs() << "ERROR: Missing extension attribute of passed " << "value in call to function:\n" << "Callee: "; if (CalleeFn != nullptr) @@ -10268,7 +10262,7 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl &Outs, if (!EnableIntArgExtCheck) return; - if (!verifyNarrowIntegerArgs(Outs, isFullyInternal(F))) { + if (!isInternal(F) && !verifyNarrowIntegerArgs(Outs)) { errs() << "ERROR: Missing extension attribute of returned " << "value from function:\n"; printFunctionArgExts(F, errs()); @@ -10278,10 +10272,9 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl &Outs, // Verify that narrow integer arguments are extended as required by the ABI. // Return false if an error is found. -bool SystemZTargetLowering:: -verifyNarrowIntegerArgs(const SmallVectorImpl &Outs, - bool IsInternal) const { - if (IsInternal || !Subtarget.isTargetELF()) +bool SystemZTargetLowering::verifyNarrowIntegerArgs( + const SmallVectorImpl &Outs) const { + if (!Subtarget.isTargetELF()) return true; if (EnableIntArgExtCheck.getNumOccurrences()) { diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.h b/llvm/lib/Target/SystemZ/SystemZISelLowering.h index 839a550012444..971a948c3c857 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.h +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.h @@ -815,13 +815,17 @@ class SystemZTargetLowering : public TargetLowering { getTargetMMOFlags(const Instruction &I) const override; const TargetRegisterClass *getRepRegClassFor(MVT VT) const override; - bool isFullyInternal(const Function *Fn) const; +private: + bool isInternal(const Function *Fn) const; + mutable std::map IsInternalCache; void verifyNarrowIntegerArgs_Call(const SmallVectorImpl &Outs, const Function *F, SDValue Callee) const; void verifyNarrowIntegerArgs_Ret(const SmallVectorImpl &Outs, const Function *F) const; - bool verifyNarrowIntegerArgs(const SmallVectorImpl &Outs, - bool IsInternal) const; + bool + verifyNarrowIntegerArgs(const SmallVectorImpl &Outs) const; + +public: }; struct SystemZVectorConstantInfo {