Skip to content

Commit cb30e32

Browse files
committed
[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.
1 parent caf3018 commit cb30e32

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
@@ -10200,22 +10200,6 @@ SDValue SystemZTargetLowering::lowerVECREDUCE_ADD(SDValue Op,
1020010200
DAG.getConstant(OpVT.getVectorNumElements() - 1, DL, MVT::i32));
1020110201
}
1020210202

10203-
// Only consider a function fully internal as long as it has local linkage
10204-
// and is not used in any other way than acting as the called function at
10205-
// call sites.
10206-
bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
10207-
if (!Fn->hasLocalLinkage())
10208-
return false;
10209-
for (const User *U : Fn->users()) {
10210-
if (auto *CB = dyn_cast<CallBase>(U)) {
10211-
if (CB->getCalledFunction() != Fn)
10212-
return false;
10213-
} else
10214-
return false;
10215-
}
10216-
return true;
10217-
}
10218-
1021910203
static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
1022010204
FunctionType *FT = F->getFunctionType();
1022110205
const AttributeList &Attrs = F->getAttributes();
@@ -10234,6 +10218,16 @@ static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
1023410218
OS << ")\n";
1023510219
}
1023610220

10221+
bool SystemZTargetLowering::isInternal(const Function *Fn) const {
10222+
std::map<const Function *, bool>::iterator Itr = IsInternalCache.find(Fn);
10223+
if (Itr == IsInternalCache.end())
10224+
Itr = IsInternalCache
10225+
.insert(std::pair<const Function *, bool>(
10226+
Fn, (Fn->hasLocalLinkage() && !Fn->hasAddressTaken())))
10227+
.first;
10228+
return Itr->second;
10229+
}
10230+
1023710231
void SystemZTargetLowering::
1023810232
verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
1023910233
const Function *F, SDValue Callee) const {
@@ -10246,8 +10240,8 @@ verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
1024610240
const Function *CalleeFn = nullptr;
1024710241
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
1024810242
if ((CalleeFn = dyn_cast<Function>(G->getGlobal())))
10249-
IsInternal = isFullyInternal(CalleeFn);
10250-
if (!verifyNarrowIntegerArgs(Outs, IsInternal)) {
10243+
IsInternal = isInternal(CalleeFn);
10244+
if (!IsInternal && !verifyNarrowIntegerArgs(Outs)) {
1025110245
errs() << "ERROR: Missing extension attribute of passed "
1025210246
<< "value in call to function:\n" << "Callee: ";
1025310247
if (CalleeFn != nullptr)
@@ -10268,7 +10262,7 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
1026810262
if (!EnableIntArgExtCheck)
1026910263
return;
1027010264

10271-
if (!verifyNarrowIntegerArgs(Outs, isFullyInternal(F))) {
10265+
if (!isInternal(F) && !verifyNarrowIntegerArgs(Outs)) {
1027210266
errs() << "ERROR: Missing extension attribute of returned "
1027310267
<< "value from function:\n";
1027410268
printFunctionArgExts(F, errs());
@@ -10278,10 +10272,9 @@ verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
1027810272

1027910273
// Verify that narrow integer arguments are extended as required by the ABI.
1028010274
// Return false if an error is found.
10281-
bool SystemZTargetLowering::
10282-
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
10283-
bool IsInternal) const {
10284-
if (IsInternal || !Subtarget.isTargetELF())
10275+
bool SystemZTargetLowering::verifyNarrowIntegerArgs(
10276+
const SmallVectorImpl<ISD::OutputArg> &Outs) const {
10277+
if (!Subtarget.isTargetELF())
1028510278
return true;
1028610279

1028710280
if (EnableIntArgExtCheck.getNumOccurrences()) {

llvm/lib/Target/SystemZ/SystemZISelLowering.h

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

818-
bool isFullyInternal(const Function *Fn) const;
818+
private:
819+
bool isInternal(const Function *Fn) const;
820+
mutable std::map<const Function *, bool> IsInternalCache;
819821
void verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
820822
const Function *F, SDValue Callee) const;
821823
void verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
822824
const Function *F) const;
823-
bool verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
824-
bool IsInternal) const;
825+
bool
826+
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs) const;
827+
828+
public:
825829
};
826830

827831
struct SystemZVectorConstantInfo {

0 commit comments

Comments
 (0)