Skip to content

Commit b13373d

Browse files
authored
[SystemZ] Use hasAddressTaken() with verifyNarrowIntegerArgs (NFC). (#131039)
Use hasAddressTaken() in SystemZ instead of doing this computation in isFullyInternal(), and make sure to only do this once per Function.
1 parent cb2ee1e commit b13373d

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10743,22 +10743,6 @@ SDValue SystemZTargetLowering::lowerVECREDUCE_ADD(SDValue Op,
1074310743
DAG.getConstant(OpVT.getVectorNumElements() - 1, DL, MVT::i32));
1074410744
}
1074510745

10746-
// Only consider a function fully internal as long as it has local linkage
10747-
// and is not used in any other way than acting as the called function at
10748-
// call sites.
10749-
bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
10750-
if (!Fn->hasLocalLinkage())
10751-
return false;
10752-
for (const User *U : Fn->users()) {
10753-
if (auto *CB = dyn_cast<CallBase>(U)) {
10754-
if (CB->getCalledFunction() != Fn)
10755-
return false;
10756-
} else
10757-
return false;
10758-
}
10759-
return true;
10760-
}
10761-
1076210746
static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
1076310747
FunctionType *FT = F->getFunctionType();
1076410748
const AttributeList &Attrs = F->getAttributes();
@@ -10777,6 +10761,16 @@ static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
1077710761
OS << ")\n";
1077810762
}
1077910763

10764+
bool SystemZTargetLowering::isInternal(const Function *Fn) const {
10765+
std::map<const Function *, bool>::iterator Itr = IsInternalCache.find(Fn);
10766+
if (Itr == IsInternalCache.end())
10767+
Itr = IsInternalCache
10768+
.insert(std::pair<const Function *, bool>(
10769+
Fn, (Fn->hasLocalLinkage() && !Fn->hasAddressTaken())))
10770+
.first;
10771+
return Itr->second;
10772+
}
10773+
1078010774
void SystemZTargetLowering::
1078110775
verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
1078210776
const Function *F, SDValue Callee) const {
@@ -10789,8 +10783,8 @@ verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
1078910783
const Function *CalleeFn = nullptr;
1079010784
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
1079110785
if ((CalleeFn = dyn_cast<Function>(G->getGlobal())))
10792-
IsInternal = isFullyInternal(CalleeFn);
10793-
if (!verifyNarrowIntegerArgs(Outs, IsInternal)) {
10786+
IsInternal = isInternal(CalleeFn);
10787+
if (!IsInternal && !verifyNarrowIntegerArgs(Outs)) {
1079410788
errs() << "ERROR: Missing extension attribute of passed "
1079510789
<< "value in call to function:\n" << "Callee: ";
1079610790
if (CalleeFn != nullptr)
@@ -10811,7 +10805,7 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
1081110805
if (!EnableIntArgExtCheck)
1081210806
return;
1081310807

10814-
if (!verifyNarrowIntegerArgs(Outs, isFullyInternal(F))) {
10808+
if (!isInternal(F) && !verifyNarrowIntegerArgs(Outs)) {
1081510809
errs() << "ERROR: Missing extension attribute of returned "
1081610810
<< "value from function:\n";
1081710811
printFunctionArgExts(F, errs());
@@ -10821,10 +10815,9 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
1082110815

1082210816
// Verify that narrow integer arguments are extended as required by the ABI.
1082310817
// Return false if an error is found.
10824-
bool SystemZTargetLowering::
10825-
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
10826-
bool IsInternal) const {
10827-
if (IsInternal || !Subtarget.isTargetELF())
10818+
bool SystemZTargetLowering::verifyNarrowIntegerArgs(
10819+
const SmallVectorImpl<ISD::OutputArg> &Outs) const {
10820+
if (!Subtarget.isTargetELF())
1082810821
return true;
1082910822

1083010823
if (EnableIntArgExtCheck.getNumOccurrences()) {

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,17 @@ class SystemZTargetLowering : public TargetLowering {
830830
getTargetMMOFlags(const Instruction &I) const override;
831831
const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
832832

833-
bool isFullyInternal(const Function *Fn) const;
833+
private:
834+
bool isInternal(const Function *Fn) const;
835+
mutable std::map<const Function *, bool> IsInternalCache;
834836
void verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
835837
const Function *F, SDValue Callee) const;
836838
void verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
837839
const Function *F) const;
838-
bool verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
839-
bool IsInternal) const;
840+
bool
841+
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs) const;
842+
843+
public:
840844
};
841845

842846
struct SystemZVectorConstantInfo {

0 commit comments

Comments
 (0)